From 9395fb94f753cf8928e64aadcd75806ec6e2f774 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 27 May 2022 21:02:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=9D=9E4=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E7=9A=84HGImage=E4=BF=9D=E5=AD=98BMP?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/base/HGImage.cpp | 5 ++++- modules/imgfmt/HGBmp.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/base/HGImage.cpp b/modules/base/HGImage.cpp index 285525c0..e721ada3 100644 --- a/modules/base/HGImage.cpp +++ b/modules/base/HGImage.cpp @@ -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) diff --git a/modules/imgfmt/HGBmp.cpp b/modules/imgfmt/HGBmp.cpp index f107681f..0f5b7871 100644 --- a/modules/imgfmt/HGBmp.cpp +++ b/modules/imgfmt/HGBmp.cpp @@ -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) {