计算机组织与结构实验MMX实验报告_第1页
计算机组织与结构实验MMX实验报告_第2页
计算机组织与结构实验MMX实验报告_第3页
计算机组织与结构实验MMX实验报告_第4页
计算机组织与结构实验MMX实验报告_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

计算机组织与结构实验报告姓 名:徐杨 学 号:班 级:软件74【实验题目】使用MMX指令,完成图片的淡入淡出效果,并与不使用MMX的普通淡入淡出进行比较【实验分析】图片是由一个个像素组成,对照片的每个像素逐一处理,就可达到渐变效果,常用的渐变公式为:Pixel_C= (Pixel_A- Pixel_B)*fade+Pixel_B等价的公式为Pixel_C=Pixel_A*fade+Pixel_B*(1-fade);其中fade为渐变因子,当fade从1到0逐渐改变时,就可产生渐变效果。MMX指令是为高速处理多媒体数据而设计的一组汇编指令,它提供了8个64位寄存器【实验代码】本实验中在 visual C+ 6.0 平台上编写MFC应用程序,通过比较采用C+内联汇编方式调用的MMX指令和调用API对图片像素逐个处理方法的处理效率,学习体会提高数据处理速度的方法。主要代码如下:(1) 未使用MMX 技术的代码如下,本程序采用的是像素描点的方法,一共225针,分十次扫描完毕实现的淡入淡出效果:/ MMX1View.cpp : implementation of the CMMX1View class/#include stdafx.h#include MMX1.h#include MMX1Doc.h#include MMX1View.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CMMX1ViewIMPLEMENT_DYNCREATE(CMMX1View, CView)BEGIN_MESSAGE_MAP(CMMX1View, CView)/AFX_MSG_MAP(CMMX1View)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!/AFX_MSG_MAP/ Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CMMX1View construction/destructionCMMX1View:CMMX1View()/ TODO: add construction code hereHBITMAP hBitmap=(HBITMAP)LoadImage(NULL,_T(1.bmp),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);this-m_Bitmap.Attach(hBitmap);BITMAP BM;this-m_Bitmap.GetBitmap(&BM);/目标图像 HBITMAP tarhBitmap=(HBITMAP)LoadImage(NULL,_T(4.bmp),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE); this-m_tarBitmap.Attach(tarhBitmap);BITMAP BM2;this-m_tarBitmap.GetBitmap(&BM2);/this-m_newptr=new BYTEBM.bmWidth*BM.bmHeight*3;this-m_newptr2=new BYTEBM.bmWidth*BM.bmHeight*3;/BYTE* temp=(BYTE*)BM.bmBits;BYTE* temp2=(BYTE*)BM2.bmBits;/if(this-m_newptr=NULL)return ;BYTE *pSrc=NULL;BYTE *pDes=NULL;BYTE *pSrc2=NULL;BYTE *pDes2=NULL; for(int h=0;hBM.bmHeight;h+) for(int w=0;wm_newptr+w*3+h*BM.bmWidthBytes;/按位复制memcpy(pDes,pSrc,3);pSrc2=temp2+w*3+h*BM.bmWidthBytes;pDes2=this-m_newptr2+w*3+h*BM.bmWidthBytes;/按位复制memcpy(pDes2,pSrc2,3); this-m_BM.bmBitsPixel=BM.bmBitsPixel;this-m_BM.bmHeight=BM.bmHeight;this-m_BM.bmPlanes=BM.bmPlanes;this-m_BM.bmType=BM.bmType;this-m_BM.bmWidth=BM.bmWidth;this-m_BM.bmWidthBytes=BM.bmWidthBytes; CMMX1View:CMMX1View()BOOL CMMX1View:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CMMX1View drawingvoid CMMX1View:OnDraw(CDC* pDC)CMMX1Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data hereBITMAP BM;this-m_Bitmap.GetBitmap(&BM);BITMAP BM2;this-m_tarBitmap.GetBitmap(&BM2); CDC MemDC;MemDC.CreateCompatibleDC(NULL);/BYTE *pSrc=NULL;BYTE *pDes=NULL;BYTE *pSrc2=NULL;BYTE *pDes2=NULL;CString count;for(int fade=0;fade=250;fade+=10)for(int h=0;hBM.bmHeight;h+)/Ax+(1-x)B=(A-B)x+B for(int w=0;w1 w/3 pSrc=(BYTE*)BM.bmBits+w*3+h*BM.bmWidthBytes;pSrc2=(BYTE*)BM2.bmBits+w*3+h*BM2.bmWidthBytes;int blue=(int)*pSrc;int green=(int)*(pSrc+1);int red=(int)*(pSrc+2);int tarblue=(int)*pSrc2;int targreen=(int)*(pSrc2+1);int tarred=(int)*(pSrc2+2);int realblue=(blue-tarblue)*(float)fade/255.0)+tarblue;int realred=(red-tarred)*(float)fade/255.0)+tarred;int realgreen=(green-targreen)*(float)fade/255.0)+targreen; pDC-SetPixel(w,BM.bmHeight-h,RGB(realred,realgreen,realblue); count.Format(%d,fade);pDC-TextOut(800,100,count);/ CMMX1View printingBOOL CMMX1View:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CMMX1View:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CMMX1View:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CMMX1View diagnostics#ifdef _DEBUGvoid CMMX1View:AssertValid() constCView:AssertValid();void CMMX1View:Dump(CDumpContext& dc) constCView:Dump(dc);CMMX1Doc* CMMX1View:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CMMX1Doc);return (CMMX1Doc*)m_pDocument;#endif /_DEBUG/(2)使用MMX技术的代码如下 / MMX3View.cpp : implementation of the CMMX3View class/#include stdafx.h#include MMX3.h#include MMX3Doc.h#include MMX3View.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CMMX3ViewIMPLEMENT_DYNCREATE(CMMX3View, CView)BEGIN_MESSAGE_MAP(CMMX3View, CView)/AFX_MSG_MAP(CMMX3View)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!/AFX_MSG_MAP/ Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView:OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView:OnFilePrintPreview)END_MESSAGE_MAP()/ CMMX3View construction/destructionCMMX3View:CMMX3View()/ TODO: add construction code hereHBITMAP hBitmap=(HBITMAP)LoadImage(NULL,_T(1.bmp),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);this-m_bitmap.Attach(hBitmap);/HBITMAP tarhBitmap=(HBITMAP)LoadImage(NULL,_T(4.bmp),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE); this-m_tarbitmap.Attach(tarhBitmap);/BITMAP BM;this-m_bitmap.GetBitmap(&BM);BITMAP BM2;this-m_tarbitmap.GetBitmap(&BM2);/this-m_newptr=new BYTEBM.bmWidth*BM.bmHeight*3;this-m_newptr2=new BYTEBM.bmWidth*BM.bmHeight*3;/ BYTE* temp=(BYTE*)BM.bmBits;BYTE* temp2=(BYTE*)BM2.bmBits;/if(this-m_newptr=NULL)return ;BYTE *pSrc=NULL;BYTE *pDes=NULL;BYTE *pSrc2=NULL;BYTE *pDes2=NULL; for(int h=0;hBM.bmHeight;h+) for(int w=0;wm_newptr+w*3+h*BM.bmWidthBytes;/按位复制memcpy(pDes,pSrc,3);pSrc2=temp2+w*3+h*BM.bmWidthBytes;pDes2=this-m_newptr2+w*3+h*BM.bmWidthBytes;/按位复制memcpy(pDes2,pSrc2,3); this-m_tarptr=new BYTEBM.bmWidth*BM.bmHeight*3;CMMX3View:CMMX3View()BOOL CMMX3View:PreCreateWindow(CREATESTRUCT& cs)/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn CView:PreCreateWindow(cs);/ CMMX3View drawingvoid CMMX3View:OnDraw(CDC* pDC)CMMX3Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data here/BITMAP BM;this-m_bitmap.GetBitmap(&BM);/BYTE temp4=0,0,0,0; /写图像BYTE* pSrc=this-m_tarptr;CString count;/120出问题for(int i=0;im_newptr,this-m_newptr2,(int)BM.bmWidth,(int)BM.bmHeight,i);for(int h=0;hBM.bmHeight;h+) for(int w=0;w1 w/3 /pSrc=(BYTE*)this-m_tarptr+w*3+h*BM.bmWidthBytes; pSrc=(BYTE*)this-m_tarptr+w*3+h*BM.bmWidthBytes; / int blue=(int)*pSrc;/int green=(int)*(pSrc+1);/int red=(int)*(pSrc+2); pDC-SetPixel(w,BM.bmHeight-h,RGB(*(pSrc+2),*(pSrc+1),*pSrc); count.Format(%d,i);pDC-TextOut(800,100,count);/ CMMX3View printingBOOL CMMX3View:OnPreparePrinting(CPrintInfo* pInfo)/ default preparationreturn DoPreparePrinting(pInfo);void CMMX3View:OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add extra initialization before printingvoid CMMX3View:OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)/ TODO: add cleanup after printing/ CMMX3View diagnostics#ifdef _DEBUGvoid CMMX3View:AssertValid() constCView:AssertValid();void CMMX3View:Dump(CDumpContext& dc) constCView:Dump(dc);CMMX3Doc* CMMX3View:GetDocument() / non-debug version is inlineASSERT(m_pDocument-IsKindOf(RUNTIME_CLASS(CMMX3Doc);return (CMMX3Doc*)m_pDocument;#endif /_DEBUG/ CMMX3View message handlers/DEL void CMMX3View:HandlePtr()/DEL /DEL /DEL /DEL void CMMX3View:Handle(BYTE *pSrc, BYTE *pSrc2, BYTE *pDes, int w, int h)/DEL /DEL /DEL /DEL void CMMX3View:HANDLE(BYTE *pSrc, BYTE *pSrc2, BYTE *&pDes, int w, int h)/DEL /DEL w=w*3*h/4;/DEL _asm/DEL /DEL mov ecx,0/DEL mov eax,w/DEL /DEL /DEL /DEL BYTE CMMX3View:HANDLE(BYTE *pSrc, BYTE *pSrc2, int w, int h,int i) /* BYTE *target=this-m_tarptr;w=w*3*h/4;_int16 fade4=i*256,i*256,i*256,i*256;_int16 temp;/ecx 计数器 esi 源地址 edi 目的图像地址 ebx 新生成地址_asmmov ebx,target/目的地址mov ecx,w /像素总数mov esi,pSrc/第一幅图像地址mov edi,pSrc2/第二幅图像地址pxor mm7,mm7/清空MM7浮点寄存器,为位扩展准备操作数 movq mm3,fade/mm3调整像素比例 back:/ movd mm0,esi/源操作数 / movq temp,mm0/调试断点 movd mm1,edi/目的操作数 /movq temp,mm1/调试断点 punpcklbw mm0,mm7/源拓展 punpcklbw mm1,mm7/目的拓展 psubw mm0,mm1/原操作减去目的操作 pmulhw mm0,mm3/乘以比例 paddw mm0,mm1/加上目的操作数 packuswb mm0,mm7/压缩包 /movd temp,mm0/调试断点 movd ebx,mm0/图像送回 add esi,4/ add edi,4/ add ebx,4/loop back / emms/ return 1;*/ BYTE *target=this-m_tarptr;w=w*3*h/4;_int16 fade4=i,i,i,i;/_int16 temp4;_int16 defade4=(255-i),(255-i),(255-i),(255-i);/ecx 计数器 esi 源地址 edi 目的图像地址 ebx 新生成地址_asmmov ebx,target/目的地址mov ecx,w /像素总数mov esi,pSrc/第一幅图像地址mov edi,pSrc2/第二幅图像地址pxor mm7,mm7/清空MM7浮点寄存器,为位扩展准备操作数 movq mm3,fade/mm3调整像素比例movq mm4,defade back:/ movd mm0,esi/源操作数 / movq temp,mm0/调试断点 movd mm1,edi/目的操作数 /movq

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论