📄 bitmapsave.c
字号:
/*
@NOTO:
*/
#include "AEEModGen.h"
#include "AEEAppGen.h"
#include "AEEShell.h"
#include "AEEStdlib.h"
#include "AEEFile.h"
#include "AEE.h"
#include "BitmapSave.h"
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;
}
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);
}
int SaveScreen24(IBitmap *pIBitmap,IDisplay *pIdisp, const char *filename)
{
IDIB *pDib = NULL;
const char *BMPFLAG = "BM";
int index = 0;
int byteswriten = 0;
BitmapFileHeader_Type FileHeader;
BitmapInfoHeader_Type InfoHeader;
U16 *pSrc = NULL;
stRGB *pTemp = NULL;
U32 col = 0;
U32 row = 0;
U32 SrcP = 0;
U32 DstP = 0;
U32 Size = 0;
MEMSET(&FileHeader,0, sizeof(BitmapFileHeader_Type));
MEMSET(&InfoHeader,0, sizeof(BitmapInfoHeader_Type));
if(NULL!=pIBitmap)
{
IFile *pIFile = NULL;
pDib = (IDIB *)pIBitmap;
FileHeader.bfOffBits = 2 + sizeof(BitmapFileHeader_Type) + sizeof(BitmapInfoHeader_Type) + pDib->cntRGB *sizeof(U32);
FileHeader.bfSize = FileHeader.bfOffBits + pDib->cy*pDib->cx*3;
InfoHeader.biSize = sizeof(BitmapInfoHeader_Type);
InfoHeader.biWidth = pDib->cx;
InfoHeader.biHeight = pDib->cy;
InfoHeader.biBitCount = pDib->nDepth + 8;
InfoHeader.biXPelsPerMeter = 0;
InfoHeader.biYPelsPerMeter = 0;
InfoHeader.biClrUsed = pDib->cntRGB;
InfoHeader.biPlanes = 1;
InfoHeader.biSizeImage = pDib->cy*pDib->cx*3;
if(NULL != (pIFile = UpStoOpenFile(filename,_OFM_CREATE)))
{
byteswriten = UpStoWriteFile(pIFile, index, BMPFLAG,STRLEN(BMPFLAG));
index += byteswriten;
byteswriten = UpStoWriteFile(pIFile, index, &FileHeader,sizeof(BitmapFileHeader_Type));
index += byteswriten;
byteswriten = UpStoWriteFile(pIFile, index, &InfoHeader,sizeof(BitmapInfoHeader_Type));
index += byteswriten;
if(pDib->cntRGB > 0)
{
//write the palette size.
byteswriten = UpStoWriteFile(pIFile, index, pDib->pRGB,pDib->cntRGB *sizeof(U32));
index += byteswriten;
}
pSrc = (U16 *)pDib->pBmp;
//stRGB *pTemp = NULL;
//stRGB *pDest = NULL;
col = pDib->cx;
row = pDib->cy;
SrcP = 4 - ( col * 2 )%4;
DstP = 4 - ( col * 3 )%4;
if(SrcP == 4)
{
SrcP = 0;
}
if(DstP == 4)
{
DstP = 0;
}
Size = ( DstP + col * 3 ) * row;
pTemp = ( stRGB* )MALLOC( Size );
if( pTemp )
{
U16 * pSrcRow = ( U16* )( (( U8* )pSrc) + ( row - 1 ) * ( col * 2 ) );
stRGB * pDstRow = pTemp;
int i,j;
for( j = row - 1; j >= 0; j -- )
{
pSrcRow = ( U16* )( (U8 *)pDib->pBmp + j*(2*col + SrcP) );
//mobile use this...
//pSrcRow = ( U16* )( (U8 *)pDib->pBmp + j*(2*col) );
//------------------
//pSrcRow = (U16*)( ( U8* )pSrcRow - SrcP );
for( i = 0; i < col; i ++ )
{
rgb565ToRgb888( pDstRow + i, pSrcRow + i );
}
//pDstRow += ( col * 3 + DstP );
//pSrcRow -= ( col * 2 + SrcP );
pDstRow += col;
pDstRow = (stRGB*)( ( U8* )pDstRow + DstP );
}
byteswriten = UpStoWriteFile( pIFile, index, pTemp, Size );
}
FREEIF(pTemp);
//BUF TO FILE
UpStoCloseFile(pIFile);
if(pIBitmap != NULL)
{
IBITMAP_Release(pIBitmap);
pIBitmap = NULL;
}
return 0;
}
if(pIBitmap != NULL)
{
IBITMAP_Release(pIBitmap);
pIBitmap = NULL;
}
}
return 1;
}
//#define MYRGB(r,g,b) ((uint32)(((uint8)(r)|((uint16)((uint8)(g))<<8))|(((uint16)(uint8)(b))<<16)))
void rgb565ToRgb888(stRGB * pDest,U16 * pSrc)
{
U8 r = (U8)((*pSrc) & 0x001F);
U8 g = (U8)(((*pSrc) & 0x07E0) >> 5);
U8 b = (U8)(((*pSrc) & 0xF800) >> 11);
pDest->r = r*0xff/0x1f;
pDest->g = g*0xff/0x3f;
pDest->b = b*0xff/0x1f;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -