?? image.c
字號:
/*===========================================================================
FILE: image.c
===========================================================================*/
/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h" // Module interface definitions
#include "AEEAppGen.h" // Applet interface definitions
#include "AEEShell.h" // Shell interface definitions
#include "AEEImage.h"
#include "AEE.h"
#include "image.bid"
#include "AEEDisp.h"
#include "image_res.h"
#include "AEEStdlib.h"
//定義采樣頻率,隔sample取一
//the explanation of the sampleX and sampleY
//sampleX and sampleY are integer number, 100 stand for 1:1 ; 50 stand for 1:0.5 ;300 stand for 1:3
typedef struct _IMAGE
{
AEEApplet a;
IBitmap * m_pBitmap; //原位圖指針
IBitmap * m_pBitmap_OBJ;//目標位圖指針
IBitmap * m_pBitmap_OBJ_OBJ;//第二個目標位圖
IBitmap * pbmScreen;//屏幕顯示指針
//int16 x;
//int16 y;
//AEEBitmapInfo pinfo;
NativeColor pColor; //象素點的顏色
uint16 i;//循環變量,要足夠大,即65536>原位圖文件的長和寬
uint16 j;
uint32 timer1;//用來記錄loadbitmap的時間
uint32 timer2;//用來記錄顯示源位圖的時間
// uint32 timer3;//用來記錄縮放并顯示的時間
AECHAR timer_char1[32];
AECHAR timer_char2[32];
// AECHAR timer_char3[32]={0};
AEEBitmapInfo bi;
// uint16 new_x;
// uint16 new_y;
} MyImage;
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean image_HandleEvent(IApplet * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static int Bitmap_LoadResources(MyImage *pMe);
static int Bitmap_sampling(MyImage *pMe,uint16 sampleX, uint16 sampleY);
/*===============================================================================
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_IMAGE){
if(AEEApplet_New(sizeof(MyImage), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)image_HandleEvent,NULL)
== TRUE)
{
// Add your code here .....
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
/*===========================================================================
FUNCTION image_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 image_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 image_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
MyImage *pMe = (MyImage *)pi;
int i;
// uint32 time;
// AECHAR fmt[]={'%','d',0};
// AECHAR score_name[32]={0};
switch (eCode)
{
case EVT_APP_START:
// pMe->timer_char1[32]=0;
// pMe->timer_char2[32]={0};
for(i=0;i<32;i++)
{
pMe->timer_char1[i]=0;
pMe->timer_char2[i]=0;
}
IDISPLAY_Update(pMe->a.m_pIDisplay);
return(TRUE);
case EVT_APP_STOP:
//Free the memory
if (pMe->m_pBitmap) {
IBITMAP_Release(pMe->m_pBitmap);
pMe->m_pBitmap=NULL;
}
if (pMe->m_pBitmap_OBJ) {
IBITMAP_Release(pMe->m_pBitmap_OBJ);
pMe->m_pBitmap_OBJ=NULL;
}
IBITMAP_Release(pMe->m_pBitmap_OBJ_OBJ);
pMe->m_pBitmap_OBJ_OBJ=NULL;
}
if (pMe->pbmScreen) {
IBITMAP_Release(pMe->pbmScreen);
pMe->pbmScreen=NULL;
}
return TRUE;
case EVT_KEY:
switch(wParam) {
case AVK_1 :
//取樣函數
//sampling(pMe,pMe->m_pBitmap,pMe->m_pBitmap_OBJ,sampleX,sampleY);
//////////////////////////////////////////////////////////////////////////
Bitmap_LoadResources(pMe);
// Bitmap_sampling(pMe,50,50);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
//按下2,以另外的一個比例縮放
case AVK_2 :
Bitmap_sampling(pMe,50,50);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return TRUE;
case AVK_3:
//time=ISHELL_GetTimeMS(pMe->a.m_pIShell);
//WSPRINTF(score_name,32,fmt,time);
IDISPLAY_DrawText(pMe->a.m_pIDisplay,AEE_FONT_NORMAL,pMe->timer_char1,-1,20,20,NULL,NULL);
IDISPLAY_DrawText(pMe->a.m_pIDisplay,AEE_FONT_NORMAL,pMe->timer_char2,-1,20,50,NULL,NULL);
IDISPLAY_Update(pMe->a.m_pIDisplay);
default:
break;
}
break;
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION Bitmap_LoadResources
===========================================================================*/
#define CHECK_ERROR(e) nErr = (e); \
if (SUCCESS != nErr) { \
goto Error; \
}
#define CHECK_NULL(e) if (NULL == (e)) { \
nErr = EFAILED; \
goto Error; \
}
//////////////////////////////////////////////////////////////////////////
//FUNCTION BITMAP_LOADRESOURCES
//////////////////////////////////////////////////////////////////////////
static int Bitmap_LoadResources(MyImage *pMe)//, uint16 sampleX, uint16 sampleY)
{
IBitmap *pbmDib = NULL;
IBitmap *pbmDdb = NULL;
// AEEBitmapInfo bi;
int nErr;
//顯示時間
uint32 time1;
uint32 time2;
AECHAR fmt[]={'%','d',0};
// AECHAR score_name[32]={0};
time1=ISHELL_GetTimeMS(pMe->a.m_pIShell);
// CHECK_ERROR(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_IMAGE, (void**)&pMe->pISprite));
CHECK_NULL(pMe->pbmScreen = IDISPLAY_GetDestination(pMe->a.m_pIDisplay));
// load the res by the name of the file
// CHECK_NULL(pbmDib = ISHELL_LoadBitmap(pMe->a.m_pIShell, "lina.bmp")); //.bmpstage
// load the res by the ID of the Resource
CHECK_NULL(pbmDib=ISHELL_LoadResBitmap(pMe->a.m_pIShell,IMAGE_RES_FILE,IM_LINA));
CHECK_ERROR(IBITMAP_GetInfo(pbmDib, &pMe->bi, sizeof(pMe->bi)));
CHECK_ERROR(IBITMAP_CreateCompatibleBitmap(pMe->pbmScreen, &pMe->m_pBitmap, (uint16)pMe->bi.cx, (uint16)pMe->bi.cy));
CHECK_ERROR(IBITMAP_BltIn(pMe->m_pBitmap, 0, 0, (uint16)pMe->bi.cx, (uint16)pMe->bi.cy, pbmDib, 0, 0, AEE_RO_COPY));
//to display the original bitmap::pMe->m_pBitmap
IDISPLAY_BitBlt(pMe->a.m_pIDisplay,0,0,(uint16)(pMe->bi.cx),(uint16)(pMe->bi.cy),pMe->m_pBitmap,0,0,AEE_RO_COPY);
//計算timer1的值,并保存在數組中
time2=ISHELL_GetTimeMS(pMe->a.m_pIShell);
pMe->timer1 = time2 - time1;
WSPRINTF(pMe->timer_char1,32,fmt,pMe->timer1);//pMe->timer1);
//////////////////////////////////////////////////////////////////////////
IBITMAP_Release(pbmDib);
pbmDib = NULL;
Error:
if (pbmDib) {
IBITMAP_Release(pbmDib);
}
if (pbmDdb) {
IBITMAP_Release(pbmDdb);
}
return nErr;
}
//////////////////////////////////////////////////////////////////////////
//FUNCTION SAMPLING
//////////////////////////////////////////////////////////////////////////
static int Bitmap_sampling(MyImage * pMe,uint16 sampleX, uint16 sampleY)
{
uint16 new_x;
uint16 new_y;
int nErr;
uint32 time1;
uint32 time2;
AECHAR fmt[]={'%','d',0};
new_x=0;
new_y=0;
//記錄起始時間
time1=ISHELL_GetTimeMS(pMe->a.m_pIShell);
//創建目標位圖的兼容位圖pMe->m_pBitmap_OBJ,對X軸按照要求變換,而Y坐標不變
CHECK_ERROR(IBITMAP_CreateCompatibleBitmap(pMe->pbmScreen, &pMe->m_pBitmap_OBJ, (uint16)((uint16)(pMe->bi.cx)*sampleX/100), (uint16)((uint16)pMe->bi.cy)));
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//對X軸按照要求變換
for(pMe->j=0;pMe->j<=(uint16)pMe->bi.cy;pMe->j++)//Y軸不變
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -