📄 imagemanager.cpp
字号:
//===========================================================================================
// (林)葛府家橇飘
// 累己磊 : 辫肯荐
// 汲疙 : Image Manager 努饭胶
// 颇老 : cpp 颇老
//===========================================================================================
#include "AEE.h"
#include "AEEFile.h" // AEEFile Services
#include "ImageManager.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ImageManager::ImageManager()
{
int i;
for( i = 0; i < 20; ++i )
{
cimg[i] = NULL;
bimg[i] = NULL;
}
for( i = 0; i < 30; ++i )
uimg[i] = NULL;
for( i = 0; i < 4; ++i )
mimg[i] = NULL;
m_pIShell = NULL;
m_pIDisplay = NULL;
}
ImageManager::~ImageManager()
{
}
//////////////////////////////////////////////////////////////////////
// 捞固瘤努饭胶 檬扁拳 窃荐
//////////////////////////////////////////////////////////////////////
void ImageManager::Init_CImg( IShell* pIShell, IDisplay* pIDisplay )
{
m_pIShell = pIShell;
m_pIDisplay = pIDisplay;
}
void ImageManager::FreeAllImg()
{
int i;
for( i = 0; i < 30; ++i )
K_Release( &uimg[i] );
for( i = 0; i < 21; ++i )
{
K_Release( &cimg[i] );
K_Release( &rcimg[i] );
}
for( i = 0; i < 26; ++i )
{
K_Release( &bimg[i] );
K_Release( &rbimg[i] );
}
for( i = 0; i < 6; ++i )
K_Release( &mimg[i] );
}
void ImageManager::FreeCimg()
{
int i;
for( i = 0; i < 21 ; ++i)
{
K_Release( &cimg[i] );
K_Release( &rcimg[i] );
}
}
void ImageManager::FreeBimg()
{
int i;
for( i = 0; i < 26 ; ++i)
{
K_Release( &bimg[i]) ;
K_Release( &rbimg[i]) ;
}
}
void ImageManager::FreeUimg()
{
int i;
for( i = 0; i < 30 ; ++i)
{
K_Release( &uimg[i] );
}
}
//////////////////////////////////////////////////////////////////////
// 捞固瘤 肺爹窃荐
// offset : 府家胶 捞抚 (ex, IDB_TITLE)
// dir=0 : Nomal , dir=1 : MIRROR
//////////////////////////////////////////////////////////////////////
KImage* ImageManager::LoadImg( const char *resFile, uint32 offset, int form )
{
//捞固瘤颇老 肺爹包访
IFileMgr *pFilemgr;
IFile *pFile;
FileInfo fileinfo;
byte *temp;
byte imgInfo[65];
AEEImageInfo imageInfo;
// BITMAPINFOHEADER *bih;
byte* pOutData;
byte* pSrcData;
//叼内爹包访
byte *pBmp = NULL;
KImage *kbm;
boolean bVal = TRUE;
rleInfo rInfo = {0};
int uIdx;
int tOffset;
byte iData;
byte iDataCnt;
byte uClrCnt;
//力绢函荐
int i, j;
//谅快馆傈 函荐
byte *pTempBmp = NULL, *pMirBmp = NULL;
uint32 iWidth, iHeight;
int bmWidth, bmHeight;
int minWcnt = 0, maxWcnt = 0;
int dataLen, widthCnt=0;
//-----捞固瘤颇老 肺爹-------------------------------------------------
ISHELL_CreateInstance(m_pIShell, AEECLSID_FILEMGR, (void **)&pFilemgr);
pFile = IFILEMGR_OpenFile(pFilemgr, resFile, _OFM_READ);
IFILE_GetInfo(pFile, &fileinfo);
IFILE_Seek(pFile, _SEEK_START, offset);
IFILE_Read(pFile, imgInfo, 65);
MEMCPY(&rInfo, imgInfo+54, 11);
temp = (byte *) MALLOC(rInfo.imageSize2+rInfo.paletteCnt*4);
IFILE_Read(pFile, temp, rInfo.imageSize2+rInfo.paletteCnt*4);
IFILE_Release(pFile);
IFILEMGR_Release(pFilemgr);
//------------------------------------------------------------------------
//-----叼内爹-------------------------------------------------------------
pBmp = (byte *) MALLOC(rInfo.imageSize+1);
MEMCPY(pBmp, imgInfo, 54); // 捞固瘤庆歹
MEMCPY(pBmp+54, temp, rInfo.paletteCnt*4); // 迫饭飘 墨款飘 父怒
tOffset = rInfo.paletteCnt*4;
uClrCnt = 0x01 << rInfo.clrBit;
uIdx = 1078;
for( i = 0; i < (int) rInfo.imageSize2; i++)
{
iData = *(temp+tOffset+i);
if (iData >= uClrCnt)
{
iDataCnt = iData >> rInfo.clrBit;
iData = ((byte) (iData << (8-rInfo.clrBit))) >> (8-rInfo.clrBit);
for(j=0; j < iDataCnt; j++)
{
pBmp[uIdx++] = iData;
}
}
else
{
iDataCnt = *(temp+tOffset+i+1);
for(j=0; j < iDataCnt; j++)
{
pBmp[uIdx++] = iData;
}
i++;
}
}
// ------------------------------------------------------------
// ----- 扁夯沥焊 ---------------------------------------------
/* 迄俊辑 欢唱匙
bih = (BITMAPINFOHEADER *)(pBmp + 14);
iWidth = ( ( bih->biWidth + 3 ) / 4 ) * 4;
iHeight = ( ( bih->biHeight + 3 ) / 4 ) * 4;
*/
bmWidth = pBmp[18];
bmHeight = pBmp[22];
if( bmHeight%4 != 0 )
iHeight = ( (bmHeight/4)+1 ) * 4;
else
iHeight = bmHeight;
if( bmWidth%4 != 0 )
iWidth = ( (bmWidth/4)+1 ) * 4;
else
iWidth = bmWidth;
// iWidth = (( bih->biWidth/4)+1)*4;
// iHeight = ((bih->biHeight/4)+1)*4;
// ------------------------------------------------------------
// ----- 捞固瘤 馆傈 ------------------------------------------
if( form > 3 ) // 馆傈牢 巴甸
{
dataLen = rInfo.imageSize - 1078;
dataLen = dataLen - (dataLen % iWidth);
pMirBmp = (byte*)MALLOC(dataLen);
minWcnt = bmWidth - 1;
maxWcnt = iWidth - 1;
for( i = 0; i < dataLen; i++ )
{
if( minWcnt >= 0 )
{
pMirBmp[i] = pBmp[1078 + minWcnt + widthCnt];
--minWcnt;
}
else
{
if( maxWcnt - bmWidth >= 0 )
{
pMirBmp[i] = pBmp[1078 + maxWcnt + widthCnt];
--maxWcnt;
}
}
if( i % iWidth == iWidth - 1 )
{
minWcnt = bmWidth - 1;
maxWcnt = iWidth - 1;
widthCnt += iWidth;
}
}
for( i=0; i< dataLen; i++ )
{
pBmp[1078+i] = pMirBmp[i];
}
FREE(pMirBmp);
}
// ---------------------------------------------------------------
// ----- 雀傈阑 救窍绰 捞固瘤 -----------------------------------
kbm = (KImage *) MALLOC(sizeof(KImage));
if( form%4 == 0 )
{
kbm->image = CONVERTBMP(pBmp, &imageInfo, &bVal);
kbm->fWidth = imageInfo.cx;
kbm->fHeight = imageInfo.cy;
kbm->bVal = bVal;
if (bVal) FREE(pBmp);
FREE(temp);
return kbm;
}
// ---------------------------------------------------------------
// ----- 雀傈窍绰 捞固瘤 贸府 ------------------------------------
if( form%2 ) // 啊肺 技肺 荤捞令啊 官偿锭
{
// 臭捞蔼阑 4官捞飘 沥纺茄 蔼阑 敬促.
pTempBmp = (byte*)MALLOC( 1078 + iHeight * bmWidth );
}
else // 救官偿锭
{
pTempBmp = (byte*)MALLOC( 1078 + iWidth * bmHeight );
}
MEMCPY( pTempBmp, pBmp, 1078 );
pOutData = pTempBmp + 1078;
pSrcData = pBmp + 1078;
switch(form)
{
case IMG_90:
case IMG_MIRROR90:
for ( i = 0 ; i < bmWidth ; i ++ )
{
for ( j = 0 ; j < bmHeight ; j++ )
{
pOutData[iHeight * i + j] = pSrcData[iWidth * j + (bmWidth - i - 1)];
}
}
break;
case IMG_180:
case IMG_MIRROR180:
for ( i = 0 ; i < bmHeight ; i++ )
{
for ( j = 0 ; j < bmWidth ; j++ )
{
pOutData[iWidth * ( bmHeight - i - 1) + bmWidth - j - 1] = pSrcData[i * iWidth + j];
}
}
break;
case IMG_270:
case IMG_MIRROR270:
for ( i = 0 ; i < bmWidth ; i ++ )
{
for ( j = 0 ; j < bmHeight ; j++ )
{
pOutData[iHeight * i + j] = pSrcData[iWidth * ( bmHeight - j -1 ) + i];
}
}
break;
}
// --------------------------------------------------------------------------------
if( form%2 )
{
// 90档客 270档绰 啊肺, 技肺 沥焊甫 辑肺 官层霖促.
*(pTempBmp + 18) = *(pBmp + 22);
*(pTempBmp + 22) = *(pBmp + 18);
}
kbm->image = CONVERTBMP(pTempBmp, &imageInfo, &bVal);
kbm->fWidth = imageInfo.cx;
kbm->fHeight = imageInfo.cy;
kbm->bVal = bVal;
if(bVal)
FREE(pTempBmp);
FREE(pBmp);
FREE(temp);
return kbm;
}
//////////////////////////////////////////////////////////////////////
// 捞固瘤秦力 窃荐
//////////////////////////////////////////////////////////////////////
void ImageManager::K_Release(KImage **kImage)
{
if(*kImage != NULL)
{
if((*kImage)->image != NULL)
{
if((*kImage)->bVal)
{
SYSFREE((*kImage)->image);
}
else
{
FREE((*kImage)->image);
}
(*kImage)->image = NULL;
}
FREE(*kImage);
*kImage = NULL;
}
}
//////////////////////////////////////////////////////////////////////
// Image Draw窃荐(捞固瘤 烹眉肺 谎覆)
// x,y: LCD惑俊 谎副 困摹
//////////////////////////////////////////////////////////////////////
void ImageManager::K_Draw( int x, int y, KImage* image, ImgPos ipos, AEERasterOp dwRopCode )
{
switch(ipos)
{
case IMLEFT:
IDISPLAY_BitBlt(m_pIDisplay, x, y, image->fWidth, image->fHeight, image->image, 0, 0, dwRopCode);
break;
case IMTOPCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(image->fWidth/2), y, image->fWidth, image->fHeight, image->image, 0, 0, dwRopCode);
break;
case IMRIGHT:
IDISPLAY_BitBlt(m_pIDisplay, x-image->fWidth, y, image->fWidth, image->fHeight, image->image, 0, 0, dwRopCode);
break;
case IMDOWNCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(image->fWidth/2), y-image->fHeight, image->fWidth, image->fHeight, image->image, 0, 0, dwRopCode);
break;
case IMCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(image->fWidth/2), y-(image->fHeight/2), image->fWidth, image->fHeight, image->image, 0, 0, dwRopCode);
break;
}
}
//////////////////////////////////////////////////////////////////////
// Image Draw窃荐(捞固瘤 荤捞令肺 肋扼辑 谎覆)
// x,y: LCD惑俊 谎副 困摹
// stx,sty: Image 矫累痢
// wd,hg: 诚厚, 臭捞
//////////////////////////////////////////////////////////////////////
void ImageManager::K_SizeDraw( int x, int y, KImage *image, int stx, int sty, int wd, int hg, ImgPos ipos, AEERasterOp dwRopCode )
{
switch(ipos)
{
case IMLEFT:
IDISPLAY_BitBlt(m_pIDisplay, x, y, wd, hg, image->image, stx, sty, dwRopCode);
break;
case IMTOPCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(wd/2), y, wd, hg, image->image, stx, sty, dwRopCode);
break;
case IMRIGHT:
IDISPLAY_BitBlt(m_pIDisplay, x-wd, y, wd, hg, image->image, stx, sty, dwRopCode);
break;
case IMDOWNCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(wd/2), y-hg, wd, hg, image->image, stx, sty, dwRopCode);
break;
case IMCENTER:
IDISPLAY_BitBlt(m_pIDisplay, x-(wd/2), y-(hg/2), wd, hg, image->image, stx, sty, dwRopCode);
break;
}
}
//////////////////////////////////////////////////////////////////////
// 捞固瘤 承捞 , 臭捞甫 府畔
//////////////////////////////////////////////////////////////////////
int ImageManager::GetImgWidth( KImage *image )
{
return image->fWidth;
}
int ImageManager::GetImgHeight( KImage *image )
{
return image->fHeight;
}
//////////////////////////////////////////////////////////////////////
// 鞍篮 农扁狼 橇饭烙捞 糠栏肺 嘿绢乐绰 弊覆捞绢具凳
// FWidth : 橇饭烙狼 诚厚
// FHeight : 橇饭烙狼 臭捞
// AniCnt : 橇饭烙 肮荐
// onetime : TRUE,茄锅 犁积窍绊 场巢 FLASE,拌加 犁积
//////////////////////////////////////////////////////////////////////
//KAnimation* ImageManager::K_AniCreat( int FWidth, int FHeight, int FCount, KImage *image, boolean onetime )
//{
// KAnimation * aniimg;
// aniimg = (KAnimation *) MALLOC(sizeof(KAnimation));
//
// aniimg->FWidth = FWidth;
// aniimg->FHeight = FHeight;
// aniimg->AniCnt = 0;
// aniimg->FCount = FCount;
// aniimg->image = image;
// aniimg->onetime = onetime;
//
// return aniimg;
//}
//
//
////------皋牢鸥捞赣俊 捞窃荐甫 火涝----------------------------------------
//void ImageManager::K_Animation( int x, int y, KAnimation *aniimg, AEERasterOp dwRopCode )
//{
//
// if(aniimg->AniCnt >= aniimg->FCount)
// {
// if(aniimg->onetime)
// return;
// else
// aniimg->AniCnt = 0;
// }
//
// IDISPLAY_BitBlt(m_pIDisplay, x, y, aniimg->FWidth, aniimg->FHeight, aniimg->image->image, aniimg->AniCnt*aniimg->FWidth, 0, dwRopCode );
// aniimg->AniCnt++;
//}
//
////-----局聪备炼眉 皋葛府 秦力 窃荐-----------------------------------------
//void ImageManager::K_AniDestroy( KAnimation **kbmani)
//{
// if(*kbmani != NULL)
// {
// FREE(*kbmani);
// *kbmani = NULL;
// }
//}
/*
//////////////////////////////////////////////////////////////////////
// BMP Loading
//////////////////////////////////////////////////////////////////////
IImage* ImageManager::BMP_Load( char *pszResFile, int t)
{
IImage* bmpimg;
bmpimg = ISHELL_LoadResImage(m_pIShell, pszResFile, t);
return bmpimg;
}
//////////////////////////////////////////////////////////////////////
// BMP Loading
//////////////////////////////////////////////////////////////////////
void ImageManager::BMP_Release(IImage** iimage)
{
if(*iimage)
{
IIMAGE_Release(*iimage);
*iimage = NULL;
}
}
//////////////////////////////////////////////////////////////////////
// BMP Draw
// x,y: LCD惑俊 谎副 困摹
// stx,sty: Image 矫累痢
// wd,hg: 诚厚, 臭捞
//////////////////////////////////////////////////////////////////////
void ImageManager::BMP_Draw( int x, int y, IImage* bmpimg, int stx, int sty, int wd, int hg, AEERasterOp dwRopCode )
{
IIMAGE_SetParm(bmpimg, IPARM_OFFSET, stx, sty );
IIMAGE_SetParm(bmpimg, IPARM_SIZE, wd, hg );
IIMAGE_SetParm(bmpimg, IPARM_ROP, dwRopCode, 0);
IIMAGE_Draw(bmpimg, x, y );
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -