解决非4字节对齐的HGImage保存BMP出错的问题
This commit is contained in:
parent
5e2ada3e39
commit
9395fb94f7
|
@ -2793,7 +2793,10 @@ static inline void SetBit(HGByte* data, HGUInt index, HGByte value)
|
|||
assert(0 == value || 1 == value);
|
||||
HGUInt byteIndex = index / 8;
|
||||
HGUInt bitIndex = index % 8;
|
||||
data[byteIndex] |= (value << (7 - bitIndex));
|
||||
if (1 == value)
|
||||
data[byteIndex] |= (1 << (7 - bitIndex));
|
||||
else
|
||||
data[byteIndex] &= ~(1 << (7 - bitIndex));
|
||||
}
|
||||
|
||||
static HGResult CopyImageWithBinary(HGImageImpl *srcImageImpl, HGImageImpl *destImageImpl)
|
||||
|
|
|
@ -258,6 +258,37 @@ HGResult HGAPI HGImgFmt_SaveBmpImage(HGImage image, const HGBmpSaveInfo* info, c
|
|||
uint32_t type = imgInfo.type;
|
||||
uint32_t origin = imgInfo.origin;
|
||||
|
||||
HGUInt bpp = 0;
|
||||
if (HGBASE_IMGTYPE_BINARY == type)
|
||||
bpp = 1;
|
||||
else if (HGBASE_IMGTYPE_GRAY == type)
|
||||
bpp = 8;
|
||||
else if (HGBASE_IMGTYPE_BGR == type || HGBASE_IMGTYPE_RGB == type)
|
||||
bpp = 24;
|
||||
else if (HGBASE_IMGTYPE_BGRA == type || HGBASE_IMGTYPE_RGBA == type)
|
||||
bpp = 32;
|
||||
assert(0 != bpp);
|
||||
HGUInt stdWidthStep = ((width * bpp + 31) & ~31) >> 3;
|
||||
|
||||
if (widthStep != stdWidthStep)
|
||||
{
|
||||
HGImage imgTemp = NULL;
|
||||
|
||||
HGImageRoi imageRoi;
|
||||
HGBase_GetImageROI(image, &imageRoi);
|
||||
HGBase_ResetImageROI(image);
|
||||
HGResult ret = HGBase_CloneImage(image, 0, 0, &imgTemp);
|
||||
HGBase_SetImageROI(image, &imageRoi);
|
||||
if (HGBASE_ERR_OK != ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = HGImgFmt_SaveBmpImage(imgTemp, info, fileName);
|
||||
HGBase_DestroyImage(imgTemp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
FILE* file = fopen(fileName, "wb");
|
||||
if (NULL == file)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue