⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.c

📁 brew平台图像处理源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  /*===========================================================================

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;
		  }
		  if (pMe->m_pBitmap_OBJ_OBJ) {
		  	  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 + -