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

📄 gufuyang.c

📁 用BREW 完成查看图片
💻 C
字号:
/*===========================================================================

FILE: gufuyang.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          
#include "AEEAppGen.h"          
#include "AEEShell.h"           

#include "gufuyang.bid"

#include "AEEStdlib.h"
#define EDGEX 14
#define EDGEY 20
#define WIDTH 100
#define HEIGHT 100


typedef struct _gufuyang {
	AEEApplet      a ;	      
    AEEDeviceInfo  DeviceInfo; 
    IDisplay      *pIDisplay;  
    IShell        *pIShell;    

	IBitmap		  *pScreen;
	IBitmap		  *pBitmap;
	IBitmap		  *pImage;
	AEEBitmapInfo Info;

	uint32		  unByte;

	int			  x;
	int			  y;
} gufuyang;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static  boolean gufuyang_HandleEvent(gufuyang* pMe, AEEEvent eCode, 
                                             uint16 wParam, uint32 dwParam);
boolean gufuyang_InitAppData(gufuyang* pMe);
void    gufuyang_FreeAppData(gufuyang* pMe);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */


int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
{
	*ppObj = NULL;

	if( ClsId == AEECLSID_GUFUYANG )
	{
	
		if( AEEApplet_New(sizeof(gufuyang),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)gufuyang_HandleEvent,
                          (PFNFREEAPPDATA)gufuyang_FreeAppData) ) 
                          
		{
			
			if(gufuyang_InitAppData((gufuyang*)*ppObj))
			{
				
				return(AEE_SUCCESS);
			}
			else
			{
				
				IAPPLET_Release((IApplet*)*ppObj);
				return EFAILED;
			}

        } 

    }

	return(EFAILED);
}


void f_showString (IDisplay *pIDisplay, AECHAR *pBuffer, int x, int y)
{
	IDISPLAY_DrawText(pIDisplay,
					AEE_FONT_BOLD,
					pBuffer,
					-1,
					x, y,
					NULL,
					IDF_ALIGN_LEFT);
}


void f_showImage (gufuyang *pMe, int x, int y)
{
	IDISPLAY_BitBlt (pMe->pIDisplay,
					x, y,
					pMe->Info.cx, pMe->Info.cy,
					pMe->pBitmap,
					0, 0,
					AEE_RO_COPY);
}

void Larger (gufuyang *pMe)
{
	IBitmap *pBitmap;
	IBitmap *pScreen;
	IDIB * pDib;
	IDIB * pResDib;
	int i=0; 
	int j=0;
	int src1, src2;
	int des1, des2, des3, des4;
	int picWidth;
	int picHeight;
	int picNewWidth;
	int picNewHeight;

	picWidth = pMe->Info.cx;
	picHeight = pMe->Info.cy;

	picNewWidth = picWidth * 2;
	picNewHeight = picHeight * 2;

	pScreen = IDISPLAY_GetDestination (pMe->pIDisplay);

	if (ENOMEMORY == IBITMAP_CreateCompatibleBitmap (pScreen, &pBitmap, (uint16)picNewWidth,
									(uint16)picHeight))
	{
		return ;
	}

	IBITMAP_Release (pScreen);

	//====对pbm中的位图,创建其IDIB接口,并由指针pDib指向 =====
	IBITMAP_QueryInterface(pMe->pBitmap, AEECLSID_DIB, (void**)&pResDib);

	//====对pbm中的位图,创建其IDIB接口,并由指针pDib指向 =====
	IBITMAP_QueryInterface(pBitmap, AEECLSID_DIB, (void**)&pDib);



	if (pDib->nDepth == 16)
	{
		for (i = 0; i < picHeight; ++i)
		{
			for (j = 0; j < picWidth; ++j)
			{
				src1 = pResDib->nPitch * i + j * 2;
				src2 = pResDib->nPitch * i + j * 2 + 1;
               
	            des1 = pDib->nPitch * i + 2 * (j * 2);
				des2 = pDib->nPitch * i + 2 * (j * 2 + 1);
				des3 = pDib->nPitch * i + 2 * (j * 2) + 1;
				des4 = pDib->nPitch * i + 2 * (j * 2 + 1) + 1;
								
			    pDib->pBmp[des1] = pResDib->pBmp[src1];
				pDib->pBmp[des3] = pResDib->pBmp[src2];
				pDib->pBmp[des2] = pResDib->pBmp[src1];
				pDib->pBmp[des4] = pResDib->pBmp[src2];
			}

			DBGPRINTF("ccc cx %d",i);
		}
	}


	//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
	IDISPLAY_BitBlt(pMe->pIDisplay,0,30,picNewWidth,picNewHeight,pBitmap,0,0,AEE_RO_COPY);

	//=====更新屏幕,显示 ======
	IDISPLAY_Update(pMe->pIDisplay);


	//=======保存放大后的图片指针 ========
	IBITMAP_Release (pMe->pBitmap);
	pMe->pBitmap = pBitmap ;
	IBITMAP_GetInfo(pMe->pBitmap, &(pMe->Info), sizeof(pMe->Info));

	//====释放IDIB接口=========
	IDIB_Release(pDib);
	IDIB_Release(pResDib);
}




void Smaller (gufuyang *pMe)
{
	IBitmap *pBitmap;
	IBitmap *pScreen;
	IDIB * pDib;
	IDIB * pResDib;
	int i=0; 
	int j=0;
	int src1, src2;
	int des1, des2;
	int picWidth;
	int picHeight;
	int picNewWidth;
	int picNewHeight;

	picWidth = pMe->Info.cx;
	picHeight = pMe->Info.cy;

	picNewWidth = picWidth / 2;
	picNewHeight = picHeight;

	pScreen = IDISPLAY_GetDestination (pMe->pIDisplay);

	if (ENOMEMORY == IBITMAP_CreateCompatibleBitmap (pScreen, &pBitmap, (uint16)picNewWidth,
									(uint16)picHeight))
	{
		return ;
	}

	IBITMAP_Release (pScreen);

	//====对pbm中的位图,创建其IDIB接口,并由指针pDib指向 =====
	IBITMAP_QueryInterface(pMe->pBitmap, AEECLSID_DIB, (void**)&pResDib);

	//====对pbm中的位图,创建其IDIB接口,并由指针pDib指向 =====
	IBITMAP_QueryInterface(pBitmap, AEECLSID_DIB, (void**)&pDib);

	

	if (pDib->nDepth == 16)
	{
		for (i = 0; i < picNewHeight; ++i)
		{
			for (j = 0; j < picNewWidth; ++j)
			{
				src1 = pResDib->nPitch * i + j * 4;
				src2 = pResDib->nPitch * i + j * 4 + 1;
               
	            des1 = pDib->nPitch * i + j * 2;
				des2 = pDib->nPitch * i + j * 2 + 1;
								
			    pDib->pBmp[des1] = pResDib->pBmp[src1];
				pDib->pBmp[des2] = pResDib->pBmp[src2];
			}

			DBGPRINTF("ccc cx %d",i);
		}
	}

	//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
	IDISPLAY_BitBlt(pMe->pIDisplay,0,30,picNewWidth,picNewHeight,pBitmap,0,0,AEE_RO_COPY);

	//=====更新屏幕,显示 ======
	IDISPLAY_Update(pMe->pIDisplay);

	//=======保存缩小后的图片指针 ========
	IBITMAP_Release (pMe->pBitmap);
	pMe->pBitmap = pBitmap ;
	IBITMAP_GetInfo(pMe->pBitmap, &(pMe->Info), sizeof(pMe->Info));

	//====释放IDIB接口=========
	IDIB_Release(pDib);
	IDIB_Release(pResDib);
}






static boolean gufuyang_HandleEvent(gufuyang* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  

    switch (eCode) 
	{
        // App is told it is starting up
        case EVT_APP_START:                        
		    // Add your code here...
			{
				AECHAR s1[30] = L"1 - make it larger";
				AECHAR s2[30] = L"2 - make it smaller";
				IDISPLAY_DrawText(pMe->pIDisplay,AEE_FONT_NORMAL,s1,-1,10,20,NULL,NULL);
				IDISPLAY_DrawText(pMe->pIDisplay,AEE_FONT_NORMAL,s2,-1,10,40,NULL,NULL);
			}

            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);
        case EVT_APP_MESSAGE:
		    // Add your code here...

      		return(TRUE);
        case EVT_KEY:
		    // Add your code here...
			switch (wParam)
			{
			case AVK_1:
				IDISPLAY_ClearScreen (pMe->pIDisplay);
				Larger (pMe);
				break;
			case AVK_2:
				IDISPLAY_ClearScreen (pMe->pIDisplay);
				Smaller (pMe);
				break;
		
			case AVK_LEFT://左移
				IDISPLAY_ClearScreen (pMe->pIDisplay);
				
				if (pMe->Info.cx - pMe->x >= 128)
				{
					pMe->x += 5;
				}
				//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
				IDISPLAY_BitBlt(pMe->pIDisplay, 0, 30, pMe->Info.cx, 
								pMe->Info.cy, pMe->pBitmap, pMe->x, pMe->y, AEE_RO_COPY);

				//=====更新屏幕,显示 ======
				IDISPLAY_Update(pMe->pIDisplay);
				break;
			case AVK_RIGHT://右移
				IDISPLAY_ClearScreen (pMe->pIDisplay);
				
				if (pMe->x >= 5)
				{
					pMe->x -= 5;
				}
				//=====将pbm缓冲区中处理完的位图传输到屏幕显示缓冲区 ===
				IDISPLAY_BitBlt(pMe->pIDisplay, 0, 30, pMe->Info.cx, 
								pMe->Info.cy, pMe->pBitmap, pMe->x, pMe->y, AEE_RO_COPY);

				//=====更新屏幕,显示 ======
				IDISPLAY_Update(pMe->pIDisplay);
				break;
			default:
				break;
			}

      		return(TRUE);
        default:
            break;
   }

   return FALSE;
}


// this function is called when your application is starting up
boolean gufuyang_InitAppData(gufuyang* pMe)
{
    pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
    ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);
    pMe->pIDisplay = pMe->a.m_pIDisplay;
    pMe->pIShell   = pMe->a.m_pIShell;

	pMe->x = 0;
	pMe->y = 0;

    // Insert your code here for initializing or allocating resources...
	//默认16位图
	            pMe->unByte = 16;
               

		    // Add your code here...
			//开始时清屏
		
			IDISPLAY_Update(pMe->pIDisplay);
	//BMP文件的初始化
	pMe->pScreen = IDISPLAY_GetDestination(pMe->pIDisplay);
	pMe->pImage = ISHELL_LoadBitmap(pMe->pIShell, "sea256.bmp");
	if (NULL == pMe->pImage)
	{
		IBITMAP_Release(pMe->pScreen);
		pMe->pScreen = NULL;
	}

	IBITMAP_GetInfo(pMe->pImage, &(pMe->Info), sizeof(pMe->Info));
	IBITMAP_CreateCompatibleBitmap(pMe->pScreen,
									&(pMe->pBitmap),
									(uint16)pMe->Info.cx, (uint16)pMe->Info.cy);

	IBITMAP_Release(pMe->pScreen);
	pMe->pScreen = NULL;
	if (NULL == pMe->pBitmap)
	{
		IBITMAP_Release(pMe->pImage);
		pMe->pImage = NULL;
	}
	IBITMAP_BltIn(pMe->pBitmap,
				0, 0,
				pMe->Info.cx, pMe->Info.cy,
				pMe->pImage,
				0, 0,
				AEE_RO_COPY);
	IBITMAP_Release(pMe->pImage);
	pMe->pImage = NULL;


    return TRUE;
}

// this function is called when your application is exiting
void gufuyang_FreeAppData(gufuyang* pMe)
{
    
	IBITMAP_Release(pMe->pBitmap);
	pMe->pBitmap = NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -