计算机组织与结构实验MMX实验报告.docx
- 文档编号:2353520
- 上传时间:2023-05-03
- 格式:DOCX
- 页数:21
- 大小:286.89KB
计算机组织与结构实验MMX实验报告.docx
《计算机组织与结构实验MMX实验报告.docx》由会员分享,可在线阅读,更多相关《计算机组织与结构实验MMX实验报告.docx(21页珍藏版)》请在冰点文库上搜索。
计算机组织与结构实验MMX实验报告
计算机组织与结构实验报告
姓名:
徐杨
学号:
07161081
班级:
软件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位寄存器
【实验代码】
本实验中在visualC++6.0平台上编写MFC应用程序,通过比较采用C++内联汇编方式调用的MMX指令和调用API对图片像素逐个处理方法的处理效率,学习体会提高数据处理速度的方法。
主要代码如下:
(1)未使用MMX技术的代码如下,本程序采用的是像素描点的方法,一共225针,分十次扫描完毕
实现的淡入淡出效果:
//MMX1View.cpp:
implementationoftheCMMX1Viewclass
//
#include"stdafx.h"
#include"MMX1.h"
#include"MMX1Doc.h"
#include"MMX1View.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CMMX1View
IMPLEMENT_DYNCREATE(CMMX1View,CView)
BEGIN_MESSAGE_MAP(CMMX1View,CView)
//{{AFX_MSG_MAP(CMMX1View)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!
//}}AFX_MSG_MAP
//Standardprintingcommands
ON_COMMAND(ID_,CView:
:
On)
ON_COMMAND(ID_,CView:
:
On)
ON_COMMAND(ID_,CView:
:
On)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CMMX1Viewconstruction/destruction
CMMX1View:
:
CMMX1View()
{
//TODO:
addconstructioncodehere
HBITMAP
hBitmap=(HBITMAP)LoadImage(NULL,_T("1.bmp"),IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE);
this->m_Bitmap.Attach(hBitmap);
BITMAPBM;
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);
BITMAPBM2;
this->m_tarBitmap.GetBitmap(&BM2);
//////////////////////////////////////////////////////////////////////
this->m_newptr=newBYTE[BM.bmWidth*BM.bmHeight*3];
this->m_newptr2=newBYTE[BM.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(inth=0;h { for(intw=0;w { pSrc=temp+w*3+h*BM.bmWidthBytes; pDes=this->m_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() { } BOOLCMMX1View: : PreCreateWindow(CREATESTRUCT&cs) { //TODO: ModifytheWindowclassorstylesherebymodifying //theCREATESTRUCTcs returnCView: : PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// //CMMX1Viewdrawing voidCMMX1View: : OnDraw(CDC*pDC) { CMMX1Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere BITMAPBM; this->m_Bitmap.GetBitmap(&BM); BITMAPBM2; this->m_tarBitmap.GetBitmap(&BM2); CDCMemDC; MemDC.CreateCompatibleDC(NULL); ///////////////////////////////////////// BYTE*pSrc=NULL; BYTE*pDes=NULL; BYTE*pSrc2=NULL; BYTE*pDes2=NULL; CStringcount; for(intfade=0;fade<=250;fade+=10) { for(inth=0;h { //Ax+(1-x)B=(A-B)x+B for(intw=0;w { pSrc=(BYTE*)BM.bmBits+w*3+h*BM.bmWidthBytes; pSrc2=(BYTE*)BM2.bmBits+w*3+h*BM2.bmWidthBytes; intblue=(int)*pSrc; intgreen=(int)*(pSrc+1); intred=(int)*(pSrc+2); inttarblue=(int)*pSrc2; inttargreen=(int)*(pSrc2+1); inttarred=(int)*(pSrc2+2); intrealblue=(blue-tarblue)*((float)fade/255.0)+tarblue; intrealred=(red-tarred)*((float)fade/255.0)+tarred; intrealgreen=(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); }// } ///////////////////////////////////////////////////////////////////////////// //CMMX1Viewprinting BOOLCMMX1View: : OnPreparePrinting(CPrintInfo*pInfo) { //defaultpreparation returnDoPreparePrinting(pInfo); } voidCMMX1View: : OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/) { //TODO: addextrainitializationbeforeprinting } voidCMMX1View: : OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/) { //TODO: addcleanupafterprinting } ///////////////////////////////////////////////////////////////////////////// //CMMX1Viewdiagnostics #ifdef_DEBUG voidCMMX1View: : AssertValid()const { CView: : AssertValid(); } voidCMMX1View: : Dump(CDumpContext&dc)const { CView: : Dump(dc); } CMMX1Doc*CMMX1View: : GetDocument()//non-debugversionisinline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMMX1Doc))); return(CMMX1Doc*)m_pDocument; } #endif//_DEBUG ///////////////////////////////////////////////////////////////////////////// (2)使用MMX技术的代码如下 //MMX3View.cpp: implementationoftheCMMX3Viewclass // #include"stdafx.h" #include"MMX3.h" #include"MMX3Doc.h" #include"MMX3View.h" #ifdef_DEBUG #definenewDEBUG_NEW #undefTHIS_FILE staticcharTHIS_FILE[]=__FILE__; #endif ///////////////////////////////////////////////////////////////////////////// //CMMX3View IMPLEMENT_DYNCREATE(CMMX3View,CView) BEGIN_MESSAGE_MAP(CMMX3View,CView) //{{AFX_MSG_MAP(CMMX3View) //NOTE-theClassWizardwilladdandremovemappingmacroshere. //DONOTEDITwhatyouseeintheseblocksofgeneratedcode! //}}AFX_MSG_MAP //Standardprintingcommands ON_COMMAND(ID_,CView: : On) ON_COMMAND(ID_,CView: : On) ON_COMMAND(ID_,CView: : On) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// //CMMX3Viewconstruction/destruction CMMX3View: : CMMX3View() { //TODO: addconstructioncodehere HBITMAP 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);// BITMAPBM; this->m_bitmap.GetBitmap(&BM); BITMAPBM2; this->m_tarbitmap.GetBitmap(&BM2);// this->m_newptr=newBYTE[BM.bmWidth*BM.bmHeight*3]; this->m_newptr2=newBYTE[BM.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(inth=0;h { for(intw=0;w { pSrc=temp+w*3+h*BM.bmWidthBytes; pDes=this->m_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=newBYTE[BM.bmWidth*BM.bmHeight*3]; } CMMX3View: : ~CMMX3View() { } BOOLCMMX3View: : PreCreateWindow(CREATESTRUCT&cs) { //TODO: ModifytheWindowclassorstylesherebymodifying //theCREATESTRUCTcs returnCView: : PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// //CMMX3Viewdrawing voidCMMX3View: : OnDraw(CDC*pDC) { CMMX3Doc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO: adddrawcodefornativedatahere ////////////////////////////////////////////// BITMAPBM; this->m_bitmap.GetBitmap(&BM); ////////////////////////////////////// //BYTEtemp[4]={0,0,0,0}; //////////////////////////////////////////////写图像 BYTE*pSrc=this->m_tarptr; CStringcount;//120出问题 for(inti=0;i<250;i+=10) { HANDLE(this->m_newptr,this->m_newptr2,(int)BM.bmWidth,(int)BM.bmHeight,i); for(inth=0;h { for(intw=0;w { //pSrc=(BYTE*)this->m_tarptr+w*3+h*BM.bmWidthBytes; pSrc=(BYTE*)this->m_tarptr+w*3+h*BM.bmWidthBytes; //intblue=(int)*pSrc; //intgreen=(int)*(pSrc+1); //intred=(int)*(pSrc+2); pDC->SetPixel(w,BM.bmHeight-h,RGB(*(pSrc+2),*(pSrc+1),*pSrc)); } } count.Format("%d",i); pDC->TextOut(800,100,count); } ////////////////////////////////////////////// } ///////////////////////////////////////////////////////////////////////////// //CMMX3Viewprinting BOOLCMMX3View: : OnPreparePrinting(CPrintInfo*pInfo) { //defaultpreparation returnDoPreparePrinting(pInfo); } voidCMMX3View: : OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/) { //TODO: addextrainitializationbeforeprinting } voidCMMX3View: : OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/) { //TODO: addcleanupafterprinting } ///////////////////////////////////////////////////////////////////////////// //CMMX3Viewdiagnostics #ifdef_DEBUG voidCMMX3View: : AssertValid()const { CView: : AssertValid(); } voidCMMX3View: : Dump(CDumpContext&dc)const { CView: : Dump(dc); } CMMX3Doc*CMMX3View: : GetDocument()//non-debugversionisinline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMMX3Doc))); return(CMMX3Doc*)m_pDocument; } #endif//_DEBUG ///////////////////////////////////////////////////////////////////////////// //CMMX3Viewmessagehandlers //DELvoidCMMX3View: : HandlePtr() //DEL{ //DEL
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 组织 结构 实验 MMX 报告