📄 imageapp.c
字号:
/*===========================================================================
FILE: imageapp.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 "imageapp.bid"
/*---------------------------------------------------------
Struct definition
----------------------------------------------------------*/
typedef struct _up_type{
AEEApplet a;
/*for image display*/
IImage *m_pIImage;
IMemAStream *m_pIMemAStream;
/*device info*/
AEERect m_Rect;
}CUpApp;
static const unsigned char icon_test[] =
{
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00,
0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x13,
0x00, 0x00, 0x00, 0x10, 0x04, 0x03, 0x00, 0x00, 0x00, 0x06,
0xea, 0x59, 0x51, 0x00, 0x00, 0x00, 0x1e, 0x50, 0x4c, 0x54,
0x45, 0x00, 0x24, 0x00, 0xff, 0xb6, 0xff, 0xff, 0x6d, 0xaa,
0xff, 0x00, 0xaa, 0xdb, 0x24, 0xaa, 0xb6, 0x24, 0xaa, 0x6d,
0x24, 0x55, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0x24, 0xe8, 0xc0, 0x10, 0x00, 0x00, 0x00, 0x01, 0x74,
0x52, 0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0x66, 0x00, 0x00,
0x00, 0x01, 0x62, 0x4b, 0x47, 0x44, 0x08, 0x86, 0xde, 0x95,
0x7a, 0x00, 0x00, 0x00, 0x67, 0x49, 0x44, 0x41, 0x54, 0x78,
0x9c, 0x63, 0x60, 0x40, 0x06, 0x1d, 0x1d, 0x0c, 0x1c, 0x1d,
0x0d, 0x20, 0x16, 0x87, 0x92, 0x69, 0x43, 0x93, 0x92, 0x06,
0x88, 0xd9, 0x34, 0x53, 0x39, 0x42, 0x53, 0xc4, 0x09, 0x28,
0xcc, 0xa1, 0x39, 0x51, 0xc9, 0x74, 0xa2, 0xb1, 0x6b, 0x06,
0x88, 0x29, 0x64, 0x64, 0x2c, 0x0c, 0x61, 0x2a, 0x2a, 0x1b,
0x1b, 0x1b, 0x9b, 0x80, 0x99, 0x4a, 0xc6, 0x20, 0x66, 0x28,
0x90, 0xc9, 0xd0, 0x02, 0x62, 0xba, 0x86, 0x81, 0x4c, 0xe3,
0x70, 0x86, 0x09, 0x82, 0x85, 0x21, 0x82, 0x20, 0x61, 0x98,
0x20, 0x50, 0x18, 0x26, 0x08, 0x14, 0x86, 0x0b, 0x32, 0x30,
0xb4, 0x35, 0xc0, 0x99, 0x1c, 0x60, 0x12, 0x00, 0x69, 0x26,
0x18, 0xf3, 0xb7, 0x4e, 0x95, 0xc1, 0x00, 0x00, 0x00, 0x00,
0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
static const unsigned char icon_wbmp[] = { 0,0,20,14,
0xff,0xff,0xf0,0xff,0xff,0xf0,0xfe,0xff,0xf0,0xfe,
0x7f,0xf0,0xfe,0x3f,0xf0,0xfe,0x1f,0xf0,0xfe,0x0f,
0xf0,0xfe,0x1f,0xf0,0xfe,0x3f,0xf0,0xfe,0x7f,0xf0,
0xfe,0xff,0xf0,0xff,0xff,0xf0,0xff,0xff,0xf0,0xff,
0xff,0xf0};
/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean imageapp_HandleEvent(CUpApp * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static boolean up_InitAppData( CUpApp* pApp );
static void up_FreeAppData( CUpApp* pApp );
static boolean up_image_decode(CUpApp* pApp,byte *pbuf, uint32 buf_size,
PFNIMAGEINFO decode_end,void * pDecdata,
PFNNOTIFY pfn, void * pUser);
static void up_imageready(CUpApp* pApp, IImage * po, AEEImageInfo * pi,int nErr);
/*===============================================================================
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)
{
CUpApp *pApp;
*ppObj = NULL;
if(ClsId == AEECLSID_IMAGEAPP){
if(AEEApplet_New(sizeof(CUpApp), ClsId, pIShell,po,(IApplet**)ppObj,
(AEEHANDLER)imageapp_HandleEvent,(PFNFREEAPPDATA)up_FreeAppData)
== TRUE)
{
// Add your code here .....
pApp=(CUpApp *)*ppObj;
if (!up_InitAppData( pApp ) )
{
IAPPLET_Release( (IApplet*) pApp );
*ppObj = NULL;
return EFAILED;
}
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
/*===========================================================================
FUNCTION imageapp_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 imageapp_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 imageapp_HandleEvent(CUpApp * pApp, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
return up_image_decode(pApp,(byte *)icon_test, sizeof(icon_test),
(PFNIMAGEINFO)up_imageready,(void *)pApp,
NULL,NULL);
case EVT_APP_STOP:
// Add your code here .....
return TRUE;
default:
break;
}
return FALSE;
}
static boolean up_InitAppData( CUpApp* pApp )
{
/*get the device information*/
AEEDeviceInfo deviceInfo; // Device Information
ISHELL_GetDeviceInfo(pApp->a.m_pIShell, &deviceInfo);
SETAEERECT(&pApp->m_Rect,
0,
0,
deviceInfo.cxScreen,
deviceInfo.cyScreen);
return TRUE;
}
static void up_FreeAppData( CUpApp* pApp )
{
if(NULL!=pApp->m_pIImage)
{
IIMAGE_Release(pApp->m_pIImage);
}
if(NULL!=pApp->m_pIMemAStream)
{
IMEMASTREAM_Release(pApp->m_pIMemAStream);
}
}
/*image decoding routine
pbuf------->the pointer of input image data
buf_size--->the size of input image data
decode_end-->notify user when decoding is completed.
pDecdata---->the pointer for user data with decode_end notify.
pfn--------->the pointer for user to free the pbuf
pUser------->the pointer for user data with free function.
*/
static boolean up_image_decode(CUpApp* pApp,byte *pbuf, uint32 buf_size,
PFNIMAGEINFO decode_end,void * pDecdata,
PFNNOTIFY pfn, void * pUser)
{
if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_PNG, (void**)(&pApp->m_pIImage))!= SUCCESS)
{
return FALSE;
}
if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_MEMASTREAM, (void**)(&pApp->m_pIMemAStream))!= SUCCESS)
{
IIMAGE_Release(pApp->m_pIImage);
pApp->m_pIImage=NULL;
return FALSE;
}
IIMAGE_Notify(pApp->m_pIImage, (PFNIMAGEINFO)decode_end, (void * )pDecdata);
IMEMASTREAM_SetEx( (IMemAStream * )pApp->m_pIMemAStream,
(byte *)pbuf,
buf_size,
0,
(PFNNOTIFY)pfn, //free user data
(void *)pUser //user data
);
IIMAGE_SetStream (pApp->m_pIImage, (IAStream *)pApp->m_pIMemAStream);
return TRUE;
}
void up_imageready(CUpApp* pApp, IImage * po, AEEImageInfo * pi,int nErr)
{
if(SUCCESS==nErr&&po==pApp->m_pIImage)
IIMAGE_Draw(po,(pApp->m_Rect.dx-pi->cx)/2,(pApp->m_Rect.dy-pi->cy)/2);
IDISPLAY_Update(pApp->a.m_pIDisplay);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -