📄 mimage.cpp
字号:
void CMImage::flip(boolean bVertical) {
/*
// bVertical : 敲赋 规氢捞 荐流牢瘤狼 咯何.
*/
int i, toI, j, toJ;
int x, y;
// uint8 col;
toI = ta_.x + ta_.dx / (bVertical?1:2);
toJ = ta_.y + ta_.dy / (bVertical?2:1);
for ( i = ta_.x; i < toI; ++i ) {
for ( j = ta_.y; j < toJ; ++j ) {
if ( bVertical ) {
x = i;
y = (ta_.dy+ta_.y)-j-1;
} else {
x = (ta_.dx+ta_.x)-i-1;
y = j;
}
swapPixel(i, j, x, y);
}
}
}
#ifdef FREE_ROTATE
void CMImage::rotate(int angle) {
}
#else
void CMImage::rotate(ANGLE_TYPE at) {
/*
// at : 雀傈 矫懦 阿档. enum 屈捞促.
*/
#ifdef DEBUG_CODE_ENABLED
if ( !isBmpPalletteIn_ ) {
DBGPRINTF("[MImage class]-[rotate func] : No pallette.");
return;
}
#endif
int i,j;
if ( at == ANGLE_90_DEGREE_CW || at == ANGLE_90_DEGREE_CCW ) {
// 货 滚欺啊 鞘夸窍促.
int index = 0;
CMBinary *pTrgBinary;
// CMBinary *pSrc;
byte *trg;
int newSize;
int originW, originH;
// rotate 饶 历厘瞪 货 滚欺甫 父电促.
// width_ 客 height_ 啊 官差霸 登绰 巴阑 绊妨窍咯 拌魂.
originW = width_;
originH = height_;
newSize = (height_ + (height_ % 4 != 0 ? height_ % 4 : 0 ) ) * width_;
// 迫饭飘客 庆歹狼 农扁父怒 歹 且寸
newSize += BMP_HEADER_SIZE + colorCount_*4;
pTrgBinary = new CMBinary(newSize);
trg = pTrgBinary->getData();
// 扁粮狼 庆歹甫 货 滚欺俊 汗荤.
MEMCPY( trg, pBinary_->getData(), BMP_HEADER_SIZE + colorCount_*4);
// 呈厚客 臭捞甫 官操绢 货 滚欺俊 扁废茄促.
CMTool::IntToBytesLittleEndian(height_, trg+18, 4);
CMTool::IntToBytesLittleEndian(width_, trg+22, 4);
byte *cols;
cols = (byte *)MALLOC(sizeof(byte) * width_ * height_);
// 侨伎 蔼甸阑 急屈 硅凯俊 固府 历厘茄促.
for ( i = 0; i < height_; ++i ) {
for ( j = 0; j < width_; ++j ) {
cols[index] = getPixel(j,i);
index++;
}
}
// 扁粮狼 单捞磐甫 秦力窍绊 货 滚欺甫 角力 捞固瘤 单捞磐俊 措涝
delete pBinary_;
pBinary_ = pTrgBinary;
processHeader();
// 困狼 processHeader 俊 狼秦 啊肺客 技肺啊 函版等 痢捞 馆康登菌栏骨肺 固府 历厘秦 初篮 originW, originH甫 荤侩
for ( i = 0; i < originH; ++i ) {
for ( j = 0; j < originW; ++j ) {
if ( at == ANGLE_90_DEGREE_CW ) {
setPixel(i, j, cols[j + (originH-i-1)*originW]);
} else {
setPixel(i, j, cols[(originW-j-1) + i*originW]);
}
}
}
FREE(cols);
} else {
// 180档 雀傈. 肺抛捞飘 傈狼 荤捞令客 饶狼 荤捞令啊 鞍促.
int toI = ( height_ >> 1 ) + ( height_ % 2 );
int toJ = width_;
for ( i = 0; i < toI; ++i ) {
for ( j = 0; j < toJ; ++j ) {
swapPixel(j, i, (width_-j-1), (height_-i-1) );
}
if ( i == toI-1 )
toJ = toJ >> 1;
}
}
}
#endif // #ifdef FREE_ROTATE
void CMImage::setTranformArea(int x,int y, int w, int h) {
#ifdef DEBUG_CODE_ENABLED
if ( x < 0 || y < 0 || x + w >= getWidth() || y + h >= getHeight() ) {
DBGPRINTF("[MImage class]-[setTransformArea func] : Out of image size.");
return;
}
#endif
ta_.x = x;
ta_.y = y;
ta_.dx = w;
ta_.dy = h;
}
void CMImage::convert() {
#ifdef DEBUG_CODE_ENABLED
// pllette甫 器窃茄 捞固瘤甫 拘绵沁阑锭绰 钱绢霖促......
if ( !isBmpPalletteIn_ ) {
DBGPRINTF("[MImage class]-[convert func] : The MImage without pallette can not be converted.");
return;
}
#endif
AEEImageInfo ImageInfo;
bmp_ = CONVERTBMP(pBinary_->getData(), &ImageInfo, &isReallocated_);
freeCache();
if ( isReallocated_ ) {
delete pBinary_;
pBinary_ = NULL;
}
isConverted_ = true;
}
void *CMImage::getBmp() {
return bmp_;
}
uint16 CMImage::getWidth() {
/*
// return value : 捞固瘤狼 呈厚
*/
#ifdef DEBUG_CODE_ENABLED
if ( !isBmpPalletteIn_ ) {
DBGPRINTF("[MImage class]-[getWidth func] : no Pallette");
return 0;
}
#endif
return width_;
}
uint16 CMImage::getHeight() {
/*
// return value : 捞固瘤狼 臭捞
*/
if ( !isBmpPalletteIn_ ) {
DBGPRINTF("[MImage class]-[getHeight func] : no Pallette");
return 0;
}
return height_;
}
boolean CMImage::isConverted() {
return isConverted_;
}
byte *CMImage::createBmpHeader(CMBinary *body, CMBinary *header) {
/*
typedef PACKED struct tagBITMAPFILEHEADER {
WORD bfType; 0
DWORD bfSize; 2 o
WORD bfReserved1; 6
WORD bfReserved2; 8
DWORD bfOffBits; 10 o
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
typedef PACKED struct tagBITMAPINFOHEADER {
DWORD biSize; 14
LONG biWidth; 18 o
LONG biHeight; 22 o
WORD biPlanes; 26
WORD biBitCount; 28 o
DWORD biCompression; 30
DWORD biSizeImage; 34
LONG biXPelsPerMeter; 38
LONG biYPelsPerMeter; 42
DWORD biClrUsed; 46 o
DWORD biClrImportant; 50 o
} BITMAPINFOHEADER, *PBITMAPINFOHEADER; */
byte *buf = (byte *)MALLOC(BMP_HEADER_SIZE);
byte *b = body->getData();
byte *h = header->getData();
uint16 usedColCnt;
usedColCnt = h[1] == 0?256:h[1];
// bitmap file type "BM"
buf[0] = 0x42;
buf[1] = 0x4d;
CMTool::IntToBytesLittleEndian(body->getSize() + header->getSize()-6, buf+2, 4);// bitmap file size
CMTool::IntToBytesLittleEndian(0, buf+6, 4); // reserved
CMTool::IntToBytesLittleEndian(usedColCnt*4 + BMP_HEADER_SIZE, buf+10, 4); // real data offset
CMTool::IntToBytesLittleEndian(40, buf+14, 4); //BITMAPINFOHEADER Size
CMTool::IntToBytesLittleEndian(b[0]+b[1]*256, buf+18, 4);
CMTool::IntToBytesLittleEndian(b[2]+b[3]*256, buf+22, 4);
CMTool::IntToBytesLittleEndian(1, buf+26, 2);
CMTool::IntToBytesLittleEndian(h[0], buf+28, 2);
CMTool::IntToBytesLittleEndian(0, buf+30, 16);
CMTool::IntToBytesLittleEndian(usedColCnt, buf+46, 4);
CMTool::IntToBytesLittleEndian(usedColCnt, buf+50, 4);
return buf;
}
void CMImage::processHeader() {
byte *Pallette;
Pallette = pBinary_->getData();
body_ = Pallette + CMTool::BytesToIntLittleEndian(Pallette+10, 4);
width_ = CMTool::BytesToIntLittleEndian(Pallette+18, 4);
height_ = CMTool::BytesToIntLittleEndian(Pallette+22, 4);
colorDepth_ = CMTool::BytesToIntLittleEndian(Pallette+28, 4);
colorCount_ = CMTool::BytesToIntLittleEndian(Pallette+50, 4);
// Full 迫饭飘 荤侩矫
if ( colorCount_ == 0 ) {
colorCount_ = 256;
}
#ifdef USE_MODULE_DYNAMIC_CACHE
// cache allocation
if ( cache_ ) {
FREE(cache_);
}
cache_ = (uint8 *)(MALLOC(sizeof(uint8)*7));
#endif
CACHE_pixelPerByte_ = getPixelPerByte(colorDepth_);
CACHE_shiftNo_ = getShiftNo(colorDepth_);
CACHE_mask_ = getMask(colorDepth_);
CACHE_pixelALine_ = 4*CACHE_pixelPerByte_;
CACHE_pixelALineLeft_ = width_%CACHE_pixelALine_;
ta_.x = 0;
ta_.y = 0;
ta_.dx = width_;
ta_.dy = height_;
}
int CMImage::getPixelIndex(int x, int y) {
/*
// x : x 谅钎
// y : y 谅钎
// return value : memory俊 x,y 谅钎狼 侨伎捞 困摹茄 offset
*/
y = height_-y-1;
return ( x + y*width_
+ y * ( CACHE_pixelALineLeft_ ==0 ? 0 : ( CACHE_pixelALine_ - CACHE_pixelALineLeft_ ) )
);
}
uint8 CMImage::getPixelPerByte(uint8 nBit) {
if ( nBit == 8 )
return 1;
else if ( nBit == 4 )
return 2;
else if ( nBit == 2 )
return 4;
else if ( nBit == 1 )
return 8;
return 0;
}
uint8 CMImage::getShiftNo(uint8 nBit ) {
if ( nBit == 8 )
return 0;
else if ( nBit == 4 )
return 1;
else if ( nBit == 2 )
return 2;
else if ( nBit == 1 )
return 3;
return 0;
}
uint8 CMImage::getMask(uint8 nBit) {
if ( nBit == 8 )
return 0xff;
else if ( nBit == 4 )
return 0x0f;
else if ( nBit == 2 )
return 0x03;
else if ( nBit == 1 )
return 0x01;
return 0xff;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -