?? pic.c
字號:
/*===========================================================================
FILE: PicApp.c
SERVICES: Reference User Application
GENERAL DESCRIPTION: User App Main Control Program
INITIALIZATION AND SEQUENCING REQUIREMENTS:
BREW must be initialized.
(c) COPYRIGHT 2003,2004 Hisense Incorporated.
All Rights Reserved.
Hisense Proprietary
===========================================================================*/
/*===============================================================================
$DateTime: 2003/12/19 16:00:00 $
$Author: whb $
$Change: 000001 $
EDIT HISTORY FOR FILE
This section contains comments describing changes made to the module.
Notice that changes are listed in reverse chronological order.
when who what, where, why
---------- --- ---------------------------------------------------------
12/19/2003 whb Initial Version
=============================================================================== */
/*===============================================================================
INCLUDES DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"
#include "AEEAppGen.h"
#include "AEEShell.h"
#include "AEEStdlib.h"
#include "pic.bid" //save app id
#include "AEENet.h"
#include "AEEFile.h"
#include "string.h"
//#include "PicApp_res.h" //necessary resource
//...
/*===============================================================================
Macro definitions
=============================================================================== */
#define GLASS_WIDTH 60
#define GLASS_HEIGHT 60
#define GLASS_COLOR 0x07FF
#define RGB565TORGB555(rgb565) \
(rgb565 & 0x001f) | \
((rgb565 & 0x07E0) >>1) | \
((rgb565 & 0xf800) >> 1)
/*===============================================================================
structure definitions
=============================================================================== */
typedef struct _PicApp_type
{
AEEApplet a;
AEERect m_nClntAreaRect;
AEERect m_nSoftkeyAreaRect;
uint16 m_nScrWidth;
uint16 m_nScrHeight;
uint16 m_nLineHeight; //Normal font
uint16 m_nLargeLineHeight; //Larege font
uint16 m_x;
uint16 m_y;
}CPicApp;
typedef unsigned char U8; /* unsigned 8 bit integer */
typedef unsigned short U16; /* unsigned 16 bit integer */
typedef unsigned long U32; /* unsigned 32 bit integer */
typedef signed char S8; /* signed 8 bit integer */
typedef signed short S16; /* signed 16 bit integer */
typedef signed long S32; /* signed 32 bit integer */
#pragma pack(push)
#pragma pack(1)
typedef struct tagBITMAPFILEHEADER_
{
U32 bfSize;
U32 bfRsv;
U32 bfOffBits;
}BitmapFileHeader_Type;
#pragma pack(pop)
#pragma pack(push)
#pragma pack(1)
typedef struct tagBITMAPINFOHEADER_
{
U32 biSize;
U32 biWidth;
U32 biHeight;
U16 biPlanes;
U16 biBitCount;
U32 biCompression;
U32 biSizeImage;
U32 biXPelsPerMeter;
U32 biYPelsPerMeter;
U32 biClrUsed;
U32 biClrImportant;
}BitmapInfoHeader_Type;
#pragma pack(pop)
typedef struct tagRGBQUAD_
{
U8 rgbBlue;
U8 rgbGreen;
U8 rgbRed;
U8 rgbReserved;
}RGBQUAD_Type;
typedef struct tagIF_
{
U8 header1;
U8 header2;
U8 width;
U8 height;
}BMP_IF_Type;
/*===============================================================================
Function Prototypes
=============================================================================== */
static boolean PicApp_HandleEvent(CPicApp * pApp,
AEEEvent eCode,
uint16 wParam,
uint32 dwParam);
static boolean PicApp_InitAppData(CPicApp * pApp);
static void PicApp_FreeAppData(CPicApp * pApp);
static void PicApp_ReleaseObj(void ** ppObj);
static boolean PicApp_Start(CPicApp * pApp);
static boolean PicApp_DrawBMP(IDisplay *pIdisp, U8 *imagedata,int x, int y);
static int PicApp_SaveScreen(IDisplay *pIdisp, const char *filename);
static boolean PicApp_DrawRect(IDisplay *pIdisp, const AEERect *pRect,U16 transpCLR);
static boolean PicApp_HandleKey(CPicApp * pApp, uint16 w, uint32 dw);
/*===========================================================================
STATIC/LOCAL DATA
===========================================================================*/
/* GENERATED BY binary2c.pl */
unsigned char bmpimage[500*1024];
IFile* UpStoOpenFile(const char *fname, OpenFileMode mode)
{
IFileMgr* pIFileMgr = NULL;
IFile* pIFile = NULL;
if(!fname)
{
return NULL;
}
if(SUCCESS != ISHELL_CreateInstance(((AEEApplet *)GETAPPINSTANCE())->m_pIShell,AEECLSID_FILEMGR, (void**)(&pIFileMgr)) )
{
return NULL;
}
pIFile = IFILEMGR_OpenFile(pIFileMgr,(const char *)fname,mode);
IFILEMGR_Release(pIFileMgr);
pIFileMgr = NULL;
return pIFile;
}
/* read the data with the size of len from the file fname to buf
if SUCCESS, return the size read
Otherwise, return 0
*/
int UpStoReadFile(IFile *pIFile, unsigned long ofs, void* buf, unsigned long len)
{
int bytesRead = 0;
if(!pIFile || !buf)
{
return 0;
}
if(SUCCESS != IFILE_Seek(pIFile,_SEEK_START,ofs))
{
return 0;
}
bytesRead = IFILE_Read(pIFile,buf,len);
return bytesRead;
}
int UpStoWriteFile(IFile *pIFile, unsigned long ofs, const void* buf, unsigned long len)
{
int bytesWritten = 0;
if(NULL == pIFile|| NULL == buf)
{
return 0;
}
if(SUCCESS != IFILE_Seek(pIFile,_SEEK_START,ofs))
{
return 0;
}
bytesWritten = IFILE_Write(pIFile,buf,len);
return bytesWritten;
}
void UpStoCloseFile(IFile* pIFile)
{
IFILE_Release(pIFile);
}
unsigned long UpStoGetFileSize(const char *filename)
{
FileInfo nInfo;
IFileMgr* pIFileMgr = NULL;
if(NULL == filename)
return 0;
if(SUCCESS != ISHELL_CreateInstance(((AEEApplet *)GETAPPINSTANCE())->m_pIShell,AEECLSID_FILEMGR, (void**)(&pIFileMgr)) )
{
return NULL;
}
/*Note: the last parameter is a true pointer, instead of a virtual pointer, because some info will be pass to it*/
if(SUCCESS != IFILEMGR_GetInfo(pIFileMgr,filename, &nInfo))
{
IFILEMGR_Release(pIFileMgr);
pIFileMgr = NULL;
return 0;
}
IFILEMGR_Release(pIFileMgr);
pIFileMgr = NULL;
return nInfo.dwSize;
}
/*===========================================================================
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)
{
CPicApp *pApp;
*ppObj = NULL;
if(ClsId == AEECLSID_PIC)
{
if(AEEApplet_New( sizeof(CPicApp),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)PicApp_HandleEvent,
(PFNFREEAPPDATA)PicApp_FreeAppData)
== TRUE)
{
pApp=(CPicApp *)*ppObj;
if (!PicApp_InitAppData( pApp ) )
{
IAPPLET_Release( (IApplet*) pApp );
*ppObj = NULL;
return EFAILED;
}
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
/*===========================================================================
FUNCTION PicApp_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 PicApp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -