Compare commits

..

2 Commits

Author SHA1 Message Date
luoliangyi f9f6209309 解决TGA格式保存失败的问题 2024-05-24 12:53:52 +08:00
luoliangyi e8137e650c 提交freeimage库 2024-05-24 11:10:52 +08:00
10 changed files with 1248 additions and 32 deletions

View File

@ -221,6 +221,7 @@ SOURCES += \
../../../modules/imgfmt/HGPng.cpp \
../../../modules/imgfmt/HGPnm.cpp \
../../../modules/imgfmt/HGTiff.cpp \
../../../modules/imgfmt/dllmain.cpp \
../../../utility/HGString.cpp
HEADERS += \

View File

@ -3089,6 +3089,7 @@ static HGResult CopyImageWithBinary(HGImageImpl *srcImageImpl, HGImageImpl *dest
pDestEx[(destImageImpl->m_left + j) * 4] = (0 == value) ? 0 : 255;
pDestEx[(destImageImpl->m_left + j) * 4 + 1] = (0 == value) ? 0 : 255;
pDestEx[(destImageImpl->m_left + j) * 4 + 2] = (0 == value) ? 0 : 255;
pDestEx[(destImageImpl->m_left + j) * 4 + 3] = 255;
}
}
}
@ -3283,6 +3284,8 @@ HGResult HGAPI HGBase_CopyImage(HGImage image, HGImage destImage)
while (pEx < pExEnd)
{
pDestEx[0] = pDestEx[1] = pDestEx[2] = *pEx;
if (HGBASE_IMGTYPE_RGBA == destType || HGBASE_IMGTYPE_BGRA == destType)
pDestEx[3] = 255;
++pEx;
pDestEx += destChannels;
}
@ -3348,6 +3351,8 @@ HGResult HGAPI HGBase_CopyImage(HGImage image, HGImage destImage)
pDestEx[0] = pEx[0];
pDestEx[1] = pEx[1];
pDestEx[2] = pEx[2];
if (HGBASE_IMGTYPE_RGBA == destType || HGBASE_IMGTYPE_BGRA == destType)
pDestEx[3] = 255;
pEx += channels;
pDestEx += destChannels;
@ -3377,6 +3382,13 @@ HGResult HGAPI HGBase_CopyImage(HGImage image, HGImage destImage)
pDestEx[2] = pEx[0];
pDestEx[1] = pEx[1];
pDestEx[0] = pEx[2];
if (HGBASE_IMGTYPE_RGBA == destType || HGBASE_IMGTYPE_BGRA == destType)
{
if (HGBASE_IMGTYPE_RGBA == type || HGBASE_IMGTYPE_BGRA == type)
pDestEx[3] = pEx[3];
else
pDestEx[3] = 255;
}
pEx += channels;
pDestEx += destChannels;

View File

@ -21,12 +21,7 @@ static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin
assert(NULL != dib);
assert(NULL != image);
BYTE *data = FreeImage_GetBits(dib);
HGUInt width = FreeImage_GetWidth(dib);
HGUInt height = FreeImage_GetHeight(dib);
HGUInt bpp = FreeImage_GetBPP(dib);
HGUInt pitch = FreeImage_GetPitch(dib);
if (0 == imgType)
{
imgType = HGBASE_IMGTYPE_RGB;
@ -44,10 +39,10 @@ static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin
}
HGImageInfo imgInfo;
imgInfo.width = width;
imgInfo.height = height;
imgInfo.width = FreeImage_GetWidth(dib);
imgInfo.height = FreeImage_GetHeight(dib);
imgInfo.type = 0;
imgInfo.widthStep = pitch;
imgInfo.widthStep = FreeImage_GetPitch(dib);
imgInfo.origin = HGBASE_IMGORIGIN_BOTTOM;
if (1 == bpp)
@ -61,7 +56,7 @@ static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin
if (0 != imgInfo.type)
{
HGResult ret = HGBase_CreateImageFromData(data, &imgInfo, NULL, imgType, imgOrigin, image);
HGResult ret = HGBase_CreateImageFromData(FreeImage_GetBits(dib), &imgInfo, NULL, imgType, imgOrigin, image);
if (HGBASE_ERR_OK == ret)
{
HGBase_SetImageDpi(*image, (HGUInt)((double)FreeImage_GetDotsPerMeterX(dib) / 39.3700787 + 0.5),
@ -77,17 +72,14 @@ static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin
return HGBASE_ERR_FAIL;
}
data = FreeImage_GetBits(dib2);
width = FreeImage_GetWidth(dib2);
height = FreeImage_GetHeight(dib2);
pitch = FreeImage_GetPitch(dib2);
HGImageInfo imgInfo2;
imgInfo2.width = FreeImage_GetWidth(dib2);
imgInfo2.height = FreeImage_GetHeight(dib2);
imgInfo2.type = HGBASE_IMGTYPE_BGRA;
imgInfo2.widthStep = FreeImage_GetPitch(dib2);
imgInfo2.origin = HGBASE_IMGORIGIN_BOTTOM;
imgInfo.width = width;
imgInfo.height = height;
imgInfo.type = HGBASE_IMGTYPE_BGRA;
imgInfo.widthStep = pitch;
imgInfo.origin = HGBASE_IMGORIGIN_BOTTOM;
HGResult ret = HGBase_CreateImageFromData(data, &imgInfo, NULL, imgType, imgOrigin, image);
HGResult ret = HGBase_CreateImageFromData(FreeImage_GetBits(dib2), &imgInfo2, NULL, imgType, imgOrigin, image);
if (HGBASE_ERR_OK == ret)
{
HGBase_SetImageDpi(*image, (HGUInt)((double)FreeImage_GetDotsPerMeterX(dib2) / 39.3700787 + 0.5),
@ -98,19 +90,29 @@ static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin
return ret;
}
static HGResult HGImageToFIBITMAP(HGImage image, FIBITMAP **dib)
static HGResult HGImageToFIBITMAP(HGImage image, FREE_IMAGE_FORMAT fif, FIBITMAP **dib)
{
assert(NULL != image);
assert(NULL != dib);
HGImage image2 = NULL;
HGImage image2 = image;
HGImageInfo imgInfo;
HGBase_GetImageInfo(image, &imgInfo);
if (HGBASE_IMGTYPE_RGB == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type)
HGBase_GetImageInfo(image2, &imgInfo);
if ((HGBASE_IMGTYPE_RGB == imgInfo.type) || (HGBASE_IMGTYPE_RGBA == imgInfo.type)
|| (HGBASE_IMGTYPE_BINARY == imgInfo.type && FIF_TARGA == fif))
{
HGResult ret = HGBase_CloneImage(image, (HGBASE_IMGTYPE_RGB == imgInfo.type ? HGBASE_IMGTYPE_BGR : HGBASE_IMGTYPE_BGRA),
imgInfo.origin, &image2);
HGUInt type = HGBASE_IMGTYPE_BGR;
if (HGBASE_IMGTYPE_RGBA == imgInfo.type)
type = HGBASE_IMGTYPE_BGRA;
else if (HGBASE_IMGTYPE_BINARY == imgInfo.type && FIF_TARGA == fif)
type = HGBASE_IMGTYPE_GRAY;
HGImageRoi imageRoi;
HGBase_GetImageROI(image, &imageRoi);
HGBase_ResetImageROI(image);
HGResult ret = HGBase_CloneImage(image, type, imgInfo.origin, &image2);
HGBase_SetImageROI(image, &imageRoi);
if (HGBASE_ERR_OK != ret)
{
return ret;
@ -118,10 +120,6 @@ static HGResult HGImageToFIBITMAP(HGImage image, FIBITMAP **dib)
HGBase_GetImageInfo(image2, &imgInfo);
}
else
{
image2 = image;
}
HGByte *data = NULL;
HGBase_GetImageData(image2, &data);
@ -138,7 +136,7 @@ static HGResult HGImageToFIBITMAP(HGImage image, FIBITMAP **dib)
else
assert(HGBASE_IMGTYPE_BINARY == imgInfo.type);
*dib = FreeImage_ConvertFromRawBits(data, imgInfo.width, imgInfo.height, imgInfo.widthStep,
*dib = FreeImage_ConvertFromRawBitsEx(TRUE, data, FIT_BITMAP, imgInfo.width, imgInfo.height, imgInfo.widthStep,
bpp, 0, 0, 0, (HGBASE_IMGORIGIN_TOP == imgInfo.origin));
if (NULL != *dib)
{
@ -253,7 +251,7 @@ static HGResult SaveFIImage(HGImage image, const HGImgFmtSaveInfo* info, const H
}
FIBITMAP *dib = NULL;
HGResult ret = HGImageToFIBITMAP(image, &dib);
HGResult ret = HGImageToFIBITMAP(image, fif, &dib);
if (HGBASE_ERR_OK != ret)
{
return ret;

View File

@ -0,0 +1,42 @@
#include "../base/HGDef.h"
#if defined(HG_CMP_MSC)
#include "FreeImage.h"
#endif
#if defined(HG_CMP_MSC)
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
FreeImage_Initialise();
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
FreeImage_DeInitialise();
break;
}
return TRUE;
}
#else
void __attribute__((constructor)) global_load(void);
void __attribute__((destructor)) global_unload(void);
void global_load(void)
{
}
void global_unload(void)
{
}
#endif

BIN
third_party/freeimage/FreeImage3180.zip vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.