📄 exam5.c
字号:
/*===========================================================================
FILE: exam5.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEBitmap.h"
#include "AEEGraphics.h"
#include "AEEStdlib.h"
#include "exam5.bid"
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _exam5 {
AEEApplet a ; // First element of this structure must be AEEApplet
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
IDisplay *dis;
IShell *she;
IBitmap *pIBitmap; // 指向位图的指针
AEEBitmapInfo info; // 保存位图信息的结构体变量
} exam5;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean exam5_HandleEvent(exam5* pMe, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
boolean exam5_InitAppData(exam5* pMe);
void exam5_FreeAppData(exam5* pMe);
void ConventPic(exam5* pMe);
void show_bmp(exam5* pMe);
void bian(exam5 * pMe,int flag);
void big(exam5 * pMe);
void small(exam5 *pMe);
/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to IDisplay_InitAppData().
This is done as follows: InitAppData() is called to initialize AppletData
instance. It is app developers responsibility to fill-in app data initialization
code of InitAppData(). App developer is also responsible to release memory
allocated for data contained in AppletData -- this can be done in
IDisplay_FreeAppData().
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell object.
pIModule: pin]: Contains pointer to the IModule object to the current module to which
this app belongs
ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
successful
EFAILED: If the app does not need to be loaded or if errors occurred in
AEEApplet_New(). If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
*ppObj = NULL;
if( ClsId == AEECLSID_EXAM5 )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(exam5),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)exam5_HandleEvent,
(PFNFREEAPPDATA)exam5_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
{
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(exam5_InitAppData((exam5*)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean exam5_HandleEvent(exam5* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
IDISPLAY_ClearScreen(pMe->dis);
IDISPLAY_Update(pMe->dis);
show_bmp(pMe);
return(TRUE);
// App is told it is exiting
case EVT_APP_STOP:
// Add your code here...
return(TRUE);
// App is being suspended
case EVT_APP_SUSPEND:
// Add your code here...
return(TRUE);
// App is being resumed
case EVT_APP_RESUME:
// Add your code here...
return(TRUE);
// An SMS message has arrived for this app. Message is in the dwParam above as (char *)
// sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
// Add your code here...
return(TRUE);
// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
case EVT_KEY:
switch(wParam)
{
case AVK_1:
IDISPLAY_BitBlt(pMe->dis,0,0,pMe->info.cx,pMe->info.cy,pMe->pIBitmap,0,0,AEE_RO_TRANSPARENT );
IDISPLAY_Update(pMe->dis); break;
case AVK_2: ConventPic(pMe); break;
case AVK_3: big(pMe); break;
case AVK_4: small(pMe); break;
}
return(TRUE);
// If nothing fits up to this point then we'll just break out
default:
break;
}
return FALSE;
}
// this function is called when your application is starting up
boolean exam5_InitAppData(exam5* pMe)
{
// Get the device information for this handset.
// Reference all the data by looking at the pMe->DeviceInfo structure
// Check the API reference guide for all the handy device info you can get
pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
// Insert your code here for initializing or allocating resources...
pMe->dis = pMe->a.m_pIDisplay;
pMe->she = pMe->a.m_pIShell;
// if there have been no failures up to this point then return success
return TRUE;
}
// this function is called when your application is exiting
void exam5_FreeAppData(exam5* pMe)
{
IBITMAP_Release(pMe->pIBitmap);
}
void show_bmp(exam5* pMe)
{
IBitmap *screen_buf;
IBitmap *dev_buf;
IBitmap *init_buf;
// NativeColor color; // 存放颜色的变量
screen_buf = IDISPLAY_GetDestination(pMe->dis);
init_buf = ISHELL_LoadBitmap(pMe->she,"oo.bmp");
if(init_buf == NULL) IBITMAP_Release(screen_buf);
IBITMAP_GetInfo(init_buf,&pMe->info,sizeof(pMe->info));
IBITMAP_CreateCompatibleBitmap(screen_buf,&dev_buf,(uint16)pMe->info.cx,(uint16)pMe->info.cy);
IBITMAP_Release(screen_buf);
if(dev_buf == NULL)
IBITMAP_Release(dev_buf);
IBITMAP_BltIn(dev_buf,0,0,pMe->info.cx,pMe->info.cy,init_buf,0,0,AEE_RO_COPY);
pMe->pIBitmap = dev_buf;
IBITMAP_Release(init_buf);
// IBITMAP_GetPixel(pMe->pIBitmap,50,40,&color);
// IBITMAP_SetTransparencyColor(pMe->pIBitmap,color);
//更新显示
return;
}
void ConventPic(exam5 * pMe)
{
IBitmap *pbm = pMe->pIBitmap;
IDIB * pDib;
int i=0;
int j=0;
int src1,des1, src2,des2, src3,des3; //反转过程中原、目标像素点在数组pBmp中的坐标
byte byTemp1, byTemp2, byTemp3; //反转过程中交换原、目标像素点时使用的临时变量
int picWidth; //图片的宽度(像素)
int picHeight; //图片的高度(像素)
AEEBitmapInfo info; //存放图片的信息
IBITMAP_GetInfo(pbm, &info, sizeof(info)); //获取图片的信息
picWidth = info.cx; //从info中得到图片的宽度和高度
picHeight = info.cy;
//====对pbm中的位图,创建其IDIB接口,并由指针pDib指向 =====
IBITMAP_QueryInterface(pbm,AEECLSID_DIB,(void**)&pDib);
//====将pDib中的nDepth、nPitch等信息输出到输出窗口以便察看=====
DBGPRINTF("ccc pDib->nDepth %d",pDib->nDepth);
DBGPRINTF("ccc pDib->nPitch %d",pDib->nPitch);
//===== 位图的颜色是8位的===============
if (pDib->nDepth ==8)
{
for (i=0; i<pDib->cy; i++)
{
for (j=0; j< pDib->cx / 2; j++)
{
src1 = pDib->nPitch*i+j; //计算左边像素点在pBmp中的地址
des1 = pDib->nPitch*i+(pDib->cx-1-j); //计算右边像素点在pBmp中的地址
byTemp1 = pDib->pBmp[src1]; //交换左右对应两个像素点的值
pDib->pBmp[src1] = pDib->pBmp[des1];
pDib->pBmp[des1] = byTemp1;
}
}
}
//===== 位图的颜色是16位的===============
if (pDib->nDepth ==16) //计算方法类似8位,但每像素占2字节
{
for (i=0; i<picHeight; i++)
{
for (j=0; j<picWidth / 2; j++)
{
src1 = pDib->nPitch*i+j*2;
src2 = pDib->nPitch*i+j*2+1;
des1 = pDib->nPitch*i+(picWidth-1-j)*2;
des2 = pDib->nPitch*i+(picWidth-1-j)*2+1;
byTemp1 = pDib->pBmp[src1];
byTemp2 = pDib->pBmp[src2];
pDib->pBmp[src1] = pDib->pBmp[des1];
pDib->pBmp[src2] = pDib->pBmp[des2];
pDib->pBmp[des1] = byTemp1;
pDib->pBmp[des2] = byTemp2;
}
}
}
//===== 位图的颜色是24位的===============
if (pDib->nDepth ==24) //计算方法类似8位,但每像素占3字节
{
for (i=0; i<picHeight; i++)
{
for (j=0; j<picWidth / 2; j++)
{
src1 = pDib->nPitch*i+j*3;
src2 = pDib->nPitch*i+j*3+1;
src3 = pDib->nPitch*i+j*3+2;
des1 = pDib->nPitch*i+(picWidth-1-j)*3;
des2 = pDib->nPitch*i+(picWidth-1-j)*3+1;
des3 = pDib->nPitch*i+(picWidth-1-j)*3+2;
byTemp1 = pDib->pBmp[src1];
byTemp2 = pDib->pBmp[src2];
byTemp3 = pDib->pBmp[src3];
pDib->pBmp[src1] = pDib->pBmp[des1];
pDib->pBmp[src2] = pDib->pBmp[des2];
pDib->pBmp[src3] = pDib->pBmp[des3];
pDib->pBmp[des1] = byTemp1;
pDib->pBmp[des2] = byTemp2;
pDib->pBmp[des3] = byTemp3;
}
}
}
//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
IDISPLAY_BitBlt(pMe->dis,0,0,info.cx,info.cy,pbm,0,0,AEE_RO_COPY);
//=====更新屏幕,显示 ======
IDISPLAY_Update(pMe->dis);
//=======保存反转后的图片指针 ========
pMe->pIBitmap = pbm ;
//====释放IDIB接口=========
IDIB_Release(pDib);
}
void bian(exam5 * pMe, int flag)
{
IBitmap * old_ibp = pMe->pIBitmap;
IBitmap *now_ibp;
IDIB * psrc ; // 指向原位图的IDIB 指针
IDIB * pdes; // 指向放大后的指针
int x;
int y;
int i,j,des1;
int src1,src2,count=0;
AEEBitmapInfo info; // 获得信息
IBITMAP_GetInfo(old_ibp,&info,sizeof(info)); // 获得原位图的信息
x = info.cx;
y = info.cy;
if(flag)
IBITMAP_CreateCompatibleBitmap(old_ibp,&now_ibp,(short)(x*2),(short)(y));
else
IBITMAP_CreateCompatibleBitmap(old_ibp,&now_ibp,(short)(x/2),(short)(y));
IBITMAP_QueryInterface(old_ibp,AEECLSID_DIB,(void **)&psrc);
IBITMAP_QueryInterface(now_ibp,AEECLSID_DIB,(void **)&pdes);
IDISPLAY_ClearScreen(pMe->dis);
if(flag)
{
//===== 位图的颜色是16位的===============
for (i=0; i< psrc->cy; i++)
{
for (j=0; j< psrc->cx; j++)
{
src1 = psrc->nPitch*i+j*2;
src2 = psrc->nPitch*i+j*2+1;
des1 = pdes->nPitch*i +j*4;
pdes->pBmp[des1] = psrc->pBmp[src1];
pdes->pBmp[des1+1] = psrc->pBmp[src2];
pdes->pBmp[des1+2] = psrc->pBmp[src1];
pdes->pBmp[des1+3] = psrc->pBmp[src2];
}
}
}
else
{
for (i=0; i< psrc->cy; i++)
{
for (j=0; j< psrc->cx; j+=2)
{
src1 = psrc->nPitch*i+j*2;
src2 = psrc->nPitch*i+j*2+1;
des1 = pdes->nPitch*i +count%(pdes->cx)*2;
pdes->pBmp[des1] = psrc->pBmp[src1];
pdes->pBmp[des1+1] = psrc->pBmp[src2];
count++;
}
}
}
IBITMAP_Release(old_ibp);
IBITMAP_GetInfo(now_ibp,&info,sizeof(info)); // 获得原位图的信息
//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
IDISPLAY_BitBlt(pMe->dis,0,0,info.cx,info.cy,now_ibp,0,0,AEE_RO_COPY);
//=====更新屏幕,显示 ======
IDISPLAY_Update(pMe->dis);
//=======保存反转后的图片指针 ========
pMe->pIBitmap = now_ibp ;
//====释放IDIB接口=========
IDIB_Release(psrc);
IDIB_Release(pdes);
}
void big(exam5 *pMe)
{
bian(pMe,1);
}
void small(exam5 * pMe)
{
bian(pMe,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -