实现PCX和RAS格式的加载和保存
This commit is contained in:
parent
4335c62c3d
commit
d2a6a648f7
|
@ -29,6 +29,7 @@ CONFIG(release, debug|release) {
|
|||
win32 {
|
||||
|
||||
DEFINES += ZIP_STATIC
|
||||
DEFINES -= UNICODE _UNICODE
|
||||
MY_OS = windows
|
||||
TARGET = $${OEM_PREFIX}ImgFmt
|
||||
|
||||
|
@ -64,6 +65,7 @@ win32 {
|
|||
INCLUDEPATH += $$PWD/../../../third_party/giflib/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/mupdf/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/pdflib/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/cximage/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/freeimage/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libzip/$${MY_OS}/include
|
||||
INCLUDEPATH += $$PWD/../../../third_party/tinyxml2/$${MY_OS}/include
|
||||
|
@ -74,6 +76,8 @@ win32 {
|
|||
LIBS += $$PWD/../../../third_party/libtiff/$${MY_OS}/lib/$${MY_ARCH}/tiff.lib
|
||||
LIBS += $$PWD/../../../third_party/giflib/$${MY_OS}/lib/$${MY_ARCH}/giflib.lib
|
||||
LIBS += $$PWD/../../../third_party/libzip/$${MY_OS}/lib/$${MY_ARCH}/zip.lib
|
||||
LIBS += $$PWD/../../../third_party/cximage/$${MY_OS}/lib/$${MY_ARCH}/cximage.lib
|
||||
LIBS += $$PWD/../../../third_party/cximage/$${MY_OS}/lib/$${MY_ARCH}/jasper.lib
|
||||
LIBS += $$PWD/../../../third_party/freeimage/$${MY_OS}/lib/$${MY_ARCH}/FreeImage.lib
|
||||
}
|
||||
|
||||
|
|
|
@ -10,155 +10,26 @@
|
|||
#include "../base/HGInc.h"
|
||||
#include <string>
|
||||
#if defined(HG_CMP_MSC)
|
||||
#include "ximage.h"
|
||||
#include "FreeImage.h"
|
||||
#endif
|
||||
|
||||
// -----------------FREEIMAGE---------------------
|
||||
// -----------------CXIMAGE---------------------
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
static HGResult FBITMAPToHGImage(FIBITMAP *dib, HGUInt imgType, HGUInt imgOrigin, HGImage *image)
|
||||
{
|
||||
assert(NULL != dib);
|
||||
assert(NULL != image);
|
||||
|
||||
HGUInt bpp = FreeImage_GetBPP(dib);
|
||||
if (0 == imgType)
|
||||
{
|
||||
imgType = HGBASE_IMGTYPE_RGB;
|
||||
if (1 == bpp)
|
||||
imgType = HGBASE_IMGTYPE_BINARY;
|
||||
else if (8 == bpp)
|
||||
imgType = HGBASE_IMGTYPE_GRAY;
|
||||
else if (32 == bpp)
|
||||
imgType = HGBASE_IMGTYPE_RGBA;
|
||||
}
|
||||
|
||||
if (0 == imgOrigin)
|
||||
{
|
||||
imgOrigin = HGBASE_IMGORIGIN_TOP;
|
||||
}
|
||||
|
||||
HGImageInfo imgInfo;
|
||||
imgInfo.width = FreeImage_GetWidth(dib);
|
||||
imgInfo.height = FreeImage_GetHeight(dib);
|
||||
imgInfo.type = 0;
|
||||
imgInfo.widthStep = FreeImage_GetPitch(dib);
|
||||
imgInfo.origin = HGBASE_IMGORIGIN_BOTTOM;
|
||||
|
||||
if (1 == bpp)
|
||||
imgInfo.type = HGBASE_IMGTYPE_BINARY;
|
||||
else if (8 == bpp)
|
||||
imgInfo.type = HGBASE_IMGTYPE_GRAY;
|
||||
else if (24 == bpp)
|
||||
imgInfo.type = HGBASE_IMGTYPE_BGR;
|
||||
else if (32 == bpp)
|
||||
imgInfo.type = HGBASE_IMGTYPE_BGRA;
|
||||
|
||||
if (0 != imgInfo.type)
|
||||
{
|
||||
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),
|
||||
(HGUInt)((double)FreeImage_GetDotsPerMeterY(dib) / 39.3700787 + 0.5));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
FIBITMAP *dib2 = FreeImage_ConvertTo32Bits(dib);
|
||||
if (NULL == dib2)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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),
|
||||
(HGUInt)((double)FreeImage_GetDotsPerMeterY(dib2) / 39.3700787 + 0.5));
|
||||
}
|
||||
|
||||
FreeImage_Unload(dib2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static HGResult HGImageToFIBITMAP(HGImage image, FREE_IMAGE_FORMAT fif, FIBITMAP **dib)
|
||||
{
|
||||
assert(NULL != image);
|
||||
assert(NULL != dib);
|
||||
|
||||
HGImage image2 = image;
|
||||
HGImageInfo imgInfo;
|
||||
HGBase_GetImageInfo(image2, &imgInfo);
|
||||
|
||||
if ((HGBASE_IMGTYPE_RGB == imgInfo.type) || (HGBASE_IMGTYPE_RGBA == imgInfo.type)
|
||||
|| (HGBASE_IMGTYPE_BINARY == imgInfo.type && FIF_TARGA == fif))
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
HGBase_GetImageInfo(image2, &imgInfo);
|
||||
}
|
||||
|
||||
HGByte *data = NULL;
|
||||
HGBase_GetImageData(image2, &data);
|
||||
HGUInt xDpi, yDpi;
|
||||
HGBase_GetImageDpi(image2, &xDpi, &yDpi);
|
||||
|
||||
unsigned int bpp = 1;
|
||||
if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
||||
bpp = 8;
|
||||
else if (HGBASE_IMGTYPE_BGR == imgInfo.type)
|
||||
bpp = 24;
|
||||
else if (HGBASE_IMGTYPE_BGRA == imgInfo.type)
|
||||
bpp = 32;
|
||||
else
|
||||
assert(HGBASE_IMGTYPE_BINARY == imgInfo.type);
|
||||
|
||||
*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)
|
||||
{
|
||||
FreeImage_SetDotsPerMeterX(*dib, (uint32_t)((double)xDpi * 39.3700787 + 0.5));
|
||||
FreeImage_SetDotsPerMeterY(*dib, (uint32_t)((double)yDpi * 39.3700787 + 0.5));
|
||||
}
|
||||
|
||||
if (image2 != image)
|
||||
{
|
||||
HGBase_DestroyImage(image2);
|
||||
}
|
||||
|
||||
return (NULL != *dib ? HGBASE_ERR_OK : HGBASE_ERR_FAIL);
|
||||
}
|
||||
|
||||
static HGResult CheckFIFile(const HGChar* fileName, FREE_IMAGE_FORMAT fif, HGBool* isTrue)
|
||||
static HGResult CheckCxFile(const HGChar* fileName, HGUInt fmt, HGBool* isTrue)
|
||||
{
|
||||
if (NULL == fileName || NULL == isTrue)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
FREE_IMAGE_FORMAT fif = FIF_TARGA;
|
||||
if (CXIMAGE_FORMAT_PCX == fmt)
|
||||
fif = FIF_PCX;
|
||||
else if (CXIMAGE_FORMAT_RAS == fmt)
|
||||
fif = FIF_RAS;
|
||||
|
||||
if (!FreeImage_Validate(fif, fileName))
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
|
@ -168,7 +39,7 @@ static HGResult CheckFIFile(const HGChar* fileName, FREE_IMAGE_FORMAT fif, HGBoo
|
|||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
static HGResult LoadFIImage(const HGChar* fileName, FREE_IMAGE_FORMAT fif, HGImgFmtLoadInfo* info,
|
||||
static HGResult LoadCxImage(const HGChar* fileName, HGUInt fmt, HGImgFmtLoadInfo* info,
|
||||
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
|
||||
{
|
||||
if (NULL == fileName)
|
||||
|
@ -207,66 +78,226 @@ static HGResult LoadFIImage(const HGChar* fileName, FREE_IMAGE_FORMAT fif, HGImg
|
|||
return HGBASE_ERR_FILENOTEXIST;
|
||||
}
|
||||
|
||||
FIBITMAP *dib = FreeImage_Load(fif, fileName);
|
||||
if (NULL == dib)
|
||||
HGBool isTrue = HGFALSE;
|
||||
CheckCxFile(fileName, fmt, &isTrue);
|
||||
if (!isTrue)
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
CxImage cxImage(fileName, fmt);
|
||||
if (!cxImage.IsValid())
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL != info)
|
||||
{
|
||||
info->width = FreeImage_GetWidth(dib);
|
||||
info->height = FreeImage_GetHeight(dib);
|
||||
info->bpp = FreeImage_GetBPP(dib);
|
||||
info->xDpi = (HGUInt)((double)FreeImage_GetDotsPerMeterX(dib) / 39.3700787 + 0.5);
|
||||
info->yDpi = (HGUInt)((double)FreeImage_GetDotsPerMeterY(dib) / 39.3700787 + 0.5);
|
||||
info->width = cxImage.GetWidth();
|
||||
info->height = cxImage.GetHeight();
|
||||
info->bpp = cxImage.GetBpp();
|
||||
info->xDpi = cxImage.GetXDPI();
|
||||
info->yDpi = cxImage.GetYDPI();
|
||||
}
|
||||
|
||||
if (NULL != image)
|
||||
{
|
||||
HGResult ret = FBITMAPToHGImage(dib, imgType, imgOrigin, image);
|
||||
HGUInt bpp = cxImage.GetBpp();
|
||||
if (0 == imgType)
|
||||
{
|
||||
imgType = HGBASE_IMGTYPE_RGB;
|
||||
|
||||
if (1 == bpp || 4 == bpp || 8 == bpp)
|
||||
{
|
||||
RGBQUAD *colourTable = cxImage.GetPalette();
|
||||
uint32_t colors = cxImage.GetPaletteSize() / sizeof(RGBQUAD);
|
||||
|
||||
bool bGray = true;
|
||||
bool bBinary = true;
|
||||
for (uint32_t i = 0; i < colors; ++i)
|
||||
{
|
||||
HGByte red = colourTable[i].rgbRed;
|
||||
HGByte green = colourTable[i].rgbGreen;
|
||||
HGByte blue = colourTable[i].rgbBlue;
|
||||
|
||||
if (red != green || red != blue || green != blue)
|
||||
{
|
||||
bGray = false;
|
||||
bBinary = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (red != 0 && red != 255)
|
||||
{
|
||||
bBinary = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bBinary)
|
||||
imgType = HGBASE_IMGTYPE_BINARY;
|
||||
else if (bGray)
|
||||
imgType = HGBASE_IMGTYPE_GRAY;
|
||||
}
|
||||
else if (32 == bpp)
|
||||
{
|
||||
imgType = HGBASE_IMGTYPE_RGBA;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == imgOrigin)
|
||||
{
|
||||
imgOrigin = HGBASE_IMGORIGIN_TOP;
|
||||
}
|
||||
|
||||
cxImage.IncreaseBpp(24);
|
||||
|
||||
HGImageInfo imageInfo;
|
||||
imageInfo.width = cxImage.GetWidth();
|
||||
imageInfo.height = cxImage.GetHeight();
|
||||
imageInfo.type = HGBASE_IMGTYPE_BGR;
|
||||
imageInfo.widthStep = cxImage.GetEffWidth();
|
||||
imageInfo.origin = HGBASE_IMGORIGIN_BOTTOM;
|
||||
|
||||
HGImage image2 = NULL;
|
||||
HGResult ret = HGBase_CreateImageWithData(cxImage.GetBits(), &imageInfo, &image2);
|
||||
if (HGBASE_ERR_OK != ret)
|
||||
{
|
||||
FreeImage_Unload(dib);
|
||||
return ret;
|
||||
}
|
||||
|
||||
HGBase_SetImageDpi(image2, cxImage.GetXDPI(), cxImage.GetYDPI());
|
||||
ret = HGBase_CloneImage(image2, imgType, imgOrigin, image);
|
||||
HGBase_DestroyImage(image2);
|
||||
if (HGBASE_ERR_OK != ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (CXIMAGE_FORMAT_PCX == fmt)
|
||||
{
|
||||
if (1 == bpp)
|
||||
HGBase_ReverseImage(*image, *image);
|
||||
}
|
||||
}
|
||||
|
||||
FreeImage_Unload(dib);
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
|
||||
static HGResult SaveFIImage(HGImage image, const HGImgFmtSaveInfo* info, const HGChar* fileName, FREE_IMAGE_FORMAT fif)
|
||||
static HGResult SaveCxImage(HGImage image, const HGImgFmtSaveInfo* info, const HGChar* fileName, HGUInt fmt)
|
||||
{
|
||||
if (NULL == image || NULL == fileName)
|
||||
{
|
||||
return HGBASE_ERR_INVALIDARG;
|
||||
}
|
||||
|
||||
if (!FreeImage_FIFSupportsWriting(fif))
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
if (NULL != info)
|
||||
{
|
||||
// 检查合法性
|
||||
}
|
||||
|
||||
FIBITMAP *dib = NULL;
|
||||
HGResult ret = HGImageToFIBITMAP(image, fif, &dib);
|
||||
HGImageInfo imgInfo;
|
||||
HGBase_GetImageInfo(image, &imgInfo);
|
||||
|
||||
unsigned int bpp = 1;
|
||||
if (HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
||||
bpp = 8;
|
||||
else if (HGBASE_IMGTYPE_RGB == imgInfo.type || HGBASE_IMGTYPE_BGR == imgInfo.type)
|
||||
bpp = 24;
|
||||
else if (HGBASE_IMGTYPE_RGBA == imgInfo.type || HGBASE_IMGTYPE_BGRA == imgInfo.type)
|
||||
bpp = 32;
|
||||
else
|
||||
assert(HGBASE_IMGTYPE_BINARY == imgInfo.type);
|
||||
|
||||
CxImage cxImage;
|
||||
cxImage.Create(imgInfo.width, imgInfo.height, bpp, 0);
|
||||
if (!cxImage.IsValid())
|
||||
{
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
bpp = cxImage.GetBpp();
|
||||
if (1 == bpp)
|
||||
{
|
||||
RGBQUAD colorTable[2];
|
||||
colorTable[0].rgbRed = 0;
|
||||
colorTable[0].rgbGreen = 0;
|
||||
colorTable[0].rgbBlue = 0;
|
||||
colorTable[1].rgbRed = 255;
|
||||
colorTable[1].rgbGreen = 255;
|
||||
colorTable[1].rgbBlue = 255;
|
||||
cxImage.SetPalette(colorTable, 2);
|
||||
}
|
||||
else if (8 == bpp)
|
||||
{
|
||||
RGBQUAD colorTable[256];
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
colorTable[i].rgbRed = i;
|
||||
colorTable[i].rgbGreen = i;
|
||||
colorTable[i].rgbBlue = i;
|
||||
}
|
||||
cxImage.SetPalette(colorTable, 256);
|
||||
}
|
||||
|
||||
HGUInt type = HGBASE_IMGTYPE_BINARY;
|
||||
if (8 == bpp)
|
||||
type = HGBASE_IMGTYPE_GRAY;
|
||||
else if (24 == bpp)
|
||||
type = HGBASE_IMGTYPE_BGR;
|
||||
else if (32 == bpp)
|
||||
type = HGBASE_IMGTYPE_BGRA;
|
||||
else
|
||||
assert(1 == bpp);
|
||||
|
||||
HGImageInfo imgInfoDest;
|
||||
imgInfoDest.width = cxImage.GetWidth();
|
||||
imgInfoDest.height = cxImage.GetHeight();
|
||||
imgInfoDest.type = type;
|
||||
imgInfoDest.widthStep = cxImage.GetEffWidth();
|
||||
imgInfoDest.origin = HGBASE_IMGORIGIN_BOTTOM;
|
||||
|
||||
HGImage imageDest = NULL;
|
||||
HGResult ret = HGBase_CreateImageWithData(cxImage.GetBits(), &imgInfoDest, &imageDest);
|
||||
if (HGBASE_ERR_OK != ret)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!FreeImage_Save(fif, dib, fileName))
|
||||
HGImageRoi imageRoi;
|
||||
HGBase_GetImageROI(image, &imageRoi);
|
||||
HGBase_ResetImageROI(image);
|
||||
HGBase_CopyImage(image, imageDest);
|
||||
HGBase_SetImageROI(image, &imageRoi);
|
||||
HGBase_DestroyImage(imageDest);
|
||||
|
||||
HGUInt xDpi, yDpi;
|
||||
HGBase_GetImageDpi(image, &xDpi, &yDpi);
|
||||
cxImage.SetXDPI(xDpi);
|
||||
cxImage.SetYDPI(yDpi);
|
||||
|
||||
if (CXIMAGE_FORMAT_TGA == fmt)
|
||||
{
|
||||
if (1 == bpp)
|
||||
cxImage.IncreaseBpp(8);
|
||||
}
|
||||
else if (CXIMAGE_FORMAT_PCX == fmt)
|
||||
{
|
||||
if (24 == bpp || 32 == bpp)
|
||||
cxImage.DecreaseBpp(8, true);
|
||||
else if (1 == bpp)
|
||||
cxImage.Negative();
|
||||
}
|
||||
else if (CXIMAGE_FORMAT_RAS == fmt)
|
||||
{
|
||||
if (1 == bpp)
|
||||
cxImage.IncreaseBpp(24);
|
||||
}
|
||||
|
||||
if (!cxImage.Save(fileName, fmt))
|
||||
{
|
||||
FreeImage_Unload(dib);
|
||||
return HGBASE_ERR_FAIL;
|
||||
}
|
||||
|
||||
FreeImage_Unload(dib);
|
||||
return HGBASE_ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
@ -274,7 +305,7 @@ static HGResult SaveFIImage(HGImage image, const HGImgFmtSaveInfo* info, const H
|
|||
static HGResult CheckTgaFile(const HGChar* fileName, HGBool* isTga)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return CheckFIFile(fileName, FIF_TARGA, isTga);
|
||||
return CheckCxFile(fileName, CXIMAGE_FORMAT_TGA, isTga);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -284,7 +315,7 @@ static HGResult LoadTgaImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return LoadFIImage(fileName, FIF_TARGA, info, imgType, imgOrigin, image);
|
||||
return LoadCxImage(fileName, CXIMAGE_FORMAT_TGA, info, imgType, imgOrigin, image);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -293,7 +324,7 @@ static HGResult LoadTgaImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
static HGResult SaveTgaImage(HGImage image, const HGImgFmtSaveInfo* info, const HGChar* fileName)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return SaveFIImage(image, info, fileName, FIF_TARGA);
|
||||
return SaveCxImage(image, info, fileName, CXIMAGE_FORMAT_TGA);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -302,7 +333,7 @@ static HGResult SaveTgaImage(HGImage image, const HGImgFmtSaveInfo* info, const
|
|||
static HGResult CheckPcxFile(const HGChar* fileName, HGBool* isPcx)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return CheckFIFile(fileName, FIF_PCX, isPcx);
|
||||
return CheckCxFile(fileName, CXIMAGE_FORMAT_PCX, isPcx);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -312,7 +343,7 @@ static HGResult LoadPcxImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return LoadFIImage(fileName, FIF_PCX, info, imgType, imgOrigin, image);
|
||||
return LoadCxImage(fileName, CXIMAGE_FORMAT_PCX, info, imgType, imgOrigin, image);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -321,7 +352,7 @@ static HGResult LoadPcxImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
static HGResult SavePcxImage(HGImage image, const HGImgFmtSaveInfo* info, const HGChar* fileName)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return SaveFIImage(image, info, fileName, FIF_PCX);
|
||||
return SaveCxImage(image, info, fileName, CXIMAGE_FORMAT_PCX);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -330,7 +361,7 @@ static HGResult SavePcxImage(HGImage image, const HGImgFmtSaveInfo* info, const
|
|||
static HGResult CheckRasFile(const HGChar* fileName, HGBool* isRas)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return CheckFIFile(fileName, FIF_RAS, isRas);
|
||||
return CheckCxFile(fileName, CXIMAGE_FORMAT_RAS, isRas);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -340,7 +371,7 @@ static HGResult LoadRasImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
HGUInt imgType, HGUInt imgOrigin, HGImage* image)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return LoadFIImage(fileName, FIF_RAS, info, imgType, imgOrigin, image);
|
||||
return LoadCxImage(fileName, CXIMAGE_FORMAT_RAS, info, imgType, imgOrigin, image);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
|
@ -349,13 +380,13 @@ static HGResult LoadRasImage(const HGChar* fileName, HGImgFmtLoadInfo* info,
|
|||
static HGResult SaveRasImage(HGImage image, const HGImgFmtSaveInfo* info, const HGChar* fileName)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
return SaveFIImage(image, info, fileName, FIF_RAS);
|
||||
return SaveCxImage(image, info, fileName, CXIMAGE_FORMAT_RAS);
|
||||
#else
|
||||
return HGBASE_ERR_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------FREEIMAGE---------------------
|
||||
// -----------------CXIMAGE---------------------
|
||||
|
||||
struct HGImgFmtReaderImpl
|
||||
{
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* File: xfile.h
|
||||
* Purpose: General Purpose File Class
|
||||
*/
|
||||
/*
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
|
||||
|
||||
CxFile (c) 11/May/2002 Davide Pizzolato - www.xdp.it
|
||||
CxFile version 2.00 23/Aug/2002
|
||||
CxFile version 2.10 16/Dec/2007
|
||||
|
||||
Special thanks to Chris Shearer Cooper for new features, enhancements and bugfixes
|
||||
|
||||
Covered code is provided under this license on an "as is" basis, without warranty
|
||||
of any kind, either expressed or implied, including, without limitation, warranties
|
||||
that the covered code is free of defects, merchantable, fit for a particular purpose
|
||||
or non-infringing. The entire risk as to the quality and performance of the covered
|
||||
code is with you. Should any covered code prove defective in any respect, you (not
|
||||
the initial developer or any other contributor) assume the cost of any necessary
|
||||
servicing, repair or correction. This disclaimer of warranty constitutes an essential
|
||||
part of this license. No use of any covered code is authorized hereunder except under
|
||||
this disclaimer.
|
||||
|
||||
Permission is hereby granted to use, copy, modify, and distribute this
|
||||
source code, or portions hereof, for any purpose, including commercial applications,
|
||||
freely and without fee, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
--------------------------------------------------------------------------------
|
||||
*/
|
||||
#if !defined(__xfile_h)
|
||||
#define __xfile_h
|
||||
|
||||
#if defined (WIN32) || defined (_WIN32_WCE)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ximadef.h"
|
||||
|
||||
class DLL_EXP CxFile
|
||||
{
|
||||
public:
|
||||
CxFile(void) { };
|
||||
virtual ~CxFile() { };
|
||||
|
||||
virtual bool Close() = 0;
|
||||
virtual size_t Read(void *buffer, size_t size, size_t count) = 0;
|
||||
virtual size_t Write(const void *buffer, size_t size, size_t count) = 0;
|
||||
virtual bool Seek(int32_t offset, int32_t origin) = 0;
|
||||
virtual int32_t Tell() = 0;
|
||||
virtual int32_t Size() = 0;
|
||||
virtual bool Flush() = 0;
|
||||
virtual bool Eof() = 0;
|
||||
virtual int32_t Error() = 0;
|
||||
virtual bool PutC(uint8_t c)
|
||||
{
|
||||
// Default implementation
|
||||
size_t nWrote = Write(&c, 1, 1);
|
||||
return (bool)(nWrote == 1);
|
||||
}
|
||||
virtual int32_t GetC() = 0;
|
||||
virtual char * GetS(char *string, int32_t n) = 0;
|
||||
virtual int32_t Scanf(const char *format, void* output) = 0;
|
||||
};
|
||||
|
||||
#endif //__xfile_h
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* File: ximabmp.h
|
||||
* Purpose: BMP Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
|
||||
*
|
||||
* original CImageBMP and CImageIterator implementation are:
|
||||
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
|
||||
*
|
||||
* ==========================================================
|
||||
*/
|
||||
|
||||
#if !defined(__ximaBMP_h)
|
||||
#define __ximaBMP_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
const int32_t RLE_COMMAND = 0;
|
||||
const int32_t RLE_ENDOFLINE = 0;
|
||||
const int32_t RLE_ENDOFBITMAP = 1;
|
||||
const int32_t RLE_DELTA = 2;
|
||||
|
||||
#if !defined(BI_RLE8)
|
||||
#define BI_RLE8 1L
|
||||
#endif
|
||||
#if !defined(BI_RLE4)
|
||||
#define BI_RLE4 2L
|
||||
#endif
|
||||
|
||||
#if CXIMAGE_SUPPORT_BMP
|
||||
|
||||
class CxImageBMP: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {};
|
||||
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
protected:
|
||||
bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib);
|
||||
};
|
||||
|
||||
#define BFT_ICON 0x4349 /* 'IC' */
|
||||
#define BFT_BITMAP 0x4d42 /* 'BM' */
|
||||
#define BFT_CURSOR 0x5450 /* 'PT' */
|
||||
|
||||
#ifndef WIDTHBYTES
|
||||
#define WIDTHBYTES(i) ((unsigned)((i+31)&(~31))/8) /* ULONG aligned ! */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define DibWidthBytesN(lpbi, n) (uint32_t)WIDTHBYTES((uint32_t)(lpbi)->biWidth * (uint32_t)(n))
|
||||
#define DibWidthBytes(lpbi) DibWidthBytesN(lpbi, (lpbi)->biBitCount)
|
||||
|
||||
#define DibSizeImage(lpbi) ((lpbi)->biSizeImage == 0 \
|
||||
? ((uint32_t)(uint32_t)DibWidthBytes(lpbi) * (uint32_t)(uint32_t)(lpbi)->biHeight) \
|
||||
: (lpbi)->biSizeImage)
|
||||
|
||||
#define DibNumColors(lpbi) ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
|
||||
? (int32_t)(1 << (int32_t)(lpbi)->biBitCount) \
|
||||
: (int32_t)(lpbi)->biClrUsed)
|
||||
|
||||
#define FixBitmapInfo(lpbi) if ((lpbi)->biSizeImage == 0) \
|
||||
(lpbi)->biSizeImage = DibSizeImage(lpbi); \
|
||||
if ((lpbi)->biClrUsed == 0) \
|
||||
(lpbi)->biClrUsed = DibNumColors(lpbi); \
|
||||
|
||||
#endif
|
|
@ -0,0 +1,59 @@
|
|||
#if !defined(__ximaCFG_h)
|
||||
#define __ximaCFG_h
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CxImage supported features
|
||||
#define CXIMAGE_SUPPORT_ALPHA 1
|
||||
#define CXIMAGE_SUPPORT_SELECTION 1
|
||||
#define CXIMAGE_SUPPORT_TRANSFORMATION 1
|
||||
#define CXIMAGE_SUPPORT_DSP 1
|
||||
#define CXIMAGE_SUPPORT_LAYERS 1
|
||||
#define CXIMAGE_SUPPORT_INTERPOLATION 1
|
||||
|
||||
#define CXIMAGE_SUPPORT_DECODE 1
|
||||
#define CXIMAGE_SUPPORT_ENCODE 1 //<vho><T.Peck>
|
||||
#define CXIMAGE_SUPPORT_WINDOWS 1
|
||||
#define CXIMAGE_SUPPORT_EXIF 1
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CxImage supported formats
|
||||
#define CXIMAGE_SUPPORT_BMP 0
|
||||
#define CXIMAGE_SUPPORT_GIF 0
|
||||
#define CXIMAGE_SUPPORT_JPG 0
|
||||
#define CXIMAGE_SUPPORT_PNG 0
|
||||
#define CXIMAGE_SUPPORT_ICO 0
|
||||
#define CXIMAGE_SUPPORT_TIF 0
|
||||
#define CXIMAGE_SUPPORT_TGA 1
|
||||
#define CXIMAGE_SUPPORT_PCX 1
|
||||
#define CXIMAGE_SUPPORT_WBMP 0
|
||||
#define CXIMAGE_SUPPORT_WMF 0
|
||||
|
||||
#define CXIMAGE_SUPPORT_JP2 0
|
||||
#define CXIMAGE_SUPPORT_JPC 0
|
||||
#define CXIMAGE_SUPPORT_PGX 0
|
||||
#define CXIMAGE_SUPPORT_PNM 0
|
||||
#define CXIMAGE_SUPPORT_RAS 1
|
||||
|
||||
#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm
|
||||
|
||||
#define CXIMAGE_SUPPORT_MNG 0
|
||||
#define CXIMAGE_SUPPORT_SKA 0
|
||||
#define CXIMAGE_SUPPORT_RAW 0
|
||||
#define CXIMAGE_SUPPORT_PSD 0
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define CXIMAGE_MAX_MEMORY 268435456
|
||||
|
||||
#define CXIMAGE_DEFAULT_DPI 96
|
||||
|
||||
#define CXIMAGE_ERR_NOFILE "null file handler"
|
||||
#define CXIMAGE_ERR_NOIMAGE "null image!!!"
|
||||
|
||||
#define CXIMAGE_SUPPORT_EXCEPTION_HANDLING 1
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//color to grey mapping <H. Muelner> <jurgene>
|
||||
//#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000)
|
||||
#define RGB2GRAY(r,g,b) (((b)*117 + (g)*601 + (r)*306) >> 10)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,210 @@
|
|||
#if !defined(__ximadefs_h)
|
||||
#define __ximadefs_h
|
||||
|
||||
#include "ximacfg.h"
|
||||
|
||||
#if /*defined(_AFXDLL)||*/defined(_USRDLL)
|
||||
#define DLL_EXP __declspec(dllexport)
|
||||
#elif defined(_MSC_VER)&&(_MSC_VER<1200)
|
||||
#define DLL_EXP __declspec(dllimport)
|
||||
#else
|
||||
#define DLL_EXP
|
||||
#endif
|
||||
|
||||
|
||||
#if CXIMAGE_SUPPORT_EXCEPTION_HANDLING
|
||||
#define cx_try try
|
||||
#define cx_throw(message) throw(message)
|
||||
#define cx_catch catch (const char *message)
|
||||
#else
|
||||
#define cx_try bool cx_error=false;
|
||||
#define cx_throw(message) {cx_error=true; if(strcmp(message,"")) strncpy(info.szLastError,message,255); goto cx_error_catch;}
|
||||
#define cx_catch cx_error_catch: char message[]=""; if(cx_error)
|
||||
#endif
|
||||
|
||||
|
||||
#if CXIMAGE_SUPPORT_JP2 || CXIMAGE_SUPPORT_JPC || CXIMAGE_SUPPORT_PGX || CXIMAGE_SUPPORT_PNM || CXIMAGE_SUPPORT_RAS
|
||||
#define CXIMAGE_SUPPORT_JASPER 1
|
||||
#else
|
||||
#define CXIMAGE_SUPPORT_JASPER 0
|
||||
#endif
|
||||
|
||||
#if CXIMAGE_SUPPORT_DSP
|
||||
#undef CXIMAGE_SUPPORT_TRANSFORMATION
|
||||
#define CXIMAGE_SUPPORT_TRANSFORMATION 1
|
||||
#endif
|
||||
|
||||
#if CXIMAGE_SUPPORT_TRANSFORMATION || CXIMAGE_SUPPORT_TIF || CXIMAGE_SUPPORT_TGA || CXIMAGE_SUPPORT_BMP || CXIMAGE_SUPPORT_WINDOWS
|
||||
#define CXIMAGE_SUPPORT_BASICTRANSFORMATIONS 1
|
||||
#endif
|
||||
|
||||
#if CXIMAGE_SUPPORT_DSP || CXIMAGE_SUPPORT_TRANSFORMATION
|
||||
#undef CXIMAGE_SUPPORT_INTERPOLATION
|
||||
#define CXIMAGE_SUPPORT_INTERPOLATION 1
|
||||
#endif
|
||||
|
||||
#if (CXIMAGE_SUPPORT_DECODE == 0)
|
||||
#undef CXIMAGE_SUPPORT_EXIF
|
||||
#define CXIMAGE_SUPPORT_EXIF 0
|
||||
#endif
|
||||
|
||||
#if defined (_WIN32_WCE)
|
||||
#undef CXIMAGE_SUPPORT_WMF
|
||||
#define CXIMAGE_SUPPORT_WMF 0
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(_WIN32_WCE)
|
||||
#undef CXIMAGE_SUPPORT_WINDOWS
|
||||
#define CXIMAGE_SUPPORT_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
#ifndef max
|
||||
#define max(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.141592653589793f
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32_WCE)
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
|
||||
#ifndef _COMPLEX_DEFINED
|
||||
|
||||
typedef struct tagcomplex {
|
||||
double x,y;
|
||||
} _complex;
|
||||
|
||||
#endif
|
||||
|
||||
#define _cabs(c) sqrt(c.x*c.x+c.y*c.y)
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32_WCE)
|
||||
#include "stdint.h"
|
||||
#endif
|
||||
|
||||
#if !defined(WIN32) && !defined(_WIN32_WCE)
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
typedef uint32_t COLORREF;
|
||||
typedef void* HANDLE;
|
||||
typedef void* HRGN;
|
||||
|
||||
#ifndef BOOL
|
||||
#define BOOL bool
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE true
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE false
|
||||
#endif
|
||||
|
||||
#ifndef TCHAR
|
||||
#define TCHAR char
|
||||
#define _T
|
||||
#endif
|
||||
|
||||
typedef struct tagRECT
|
||||
{
|
||||
int32_t left;
|
||||
int32_t top;
|
||||
int32_t right;
|
||||
int32_t bottom;
|
||||
} RECT;
|
||||
|
||||
typedef struct tagPOINT
|
||||
{
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
} POINT;
|
||||
|
||||
typedef struct tagRGBQUAD {
|
||||
uint8_t rgbBlue;
|
||||
uint8_t rgbGreen;
|
||||
uint8_t rgbRed;
|
||||
uint8_t rgbReserved;
|
||||
} RGBQUAD;
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct tagBITMAPINFOHEADER{
|
||||
uint32_t biSize;
|
||||
int32_t biWidth;
|
||||
int32_t biHeight;
|
||||
uint16_t biPlanes;
|
||||
uint16_t biBitCount;
|
||||
uint32_t biCompression;
|
||||
uint32_t biSizeImage;
|
||||
int32_t biXPelsPerMeter;
|
||||
int32_t biYPelsPerMeter;
|
||||
uint32_t biClrUsed;
|
||||
uint32_t biClrImportant;
|
||||
} BITMAPINFOHEADER;
|
||||
|
||||
typedef struct tagBITMAPFILEHEADER {
|
||||
uint16_t bfType;
|
||||
uint32_t bfSize;
|
||||
uint16_t bfReserved1;
|
||||
uint16_t bfReserved2;
|
||||
uint32_t bfOffBits;
|
||||
} BITMAPFILEHEADER;
|
||||
|
||||
typedef struct tagBITMAPCOREHEADER {
|
||||
uint32_t bcSize;
|
||||
uint16_t bcWidth;
|
||||
uint16_t bcHeight;
|
||||
uint16_t bcPlanes;
|
||||
uint16_t bcBitCount;
|
||||
} BITMAPCOREHEADER;
|
||||
|
||||
typedef struct tagRGBTRIPLE {
|
||||
uint8_t rgbtBlue;
|
||||
uint8_t rgbtGreen;
|
||||
uint8_t rgbtRed;
|
||||
} RGBTRIPLE;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define BI_RGB 0L
|
||||
#define BI_RLE8 1L
|
||||
#define BI_RLE4 2L
|
||||
#define BI_BITFIELDS 3L
|
||||
|
||||
#define GetRValue(rgb) ((uint8_t)(rgb))
|
||||
#define GetGValue(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8))
|
||||
#define GetBValue(rgb) ((uint8_t)((rgb)>>16))
|
||||
#define RGB(r,g,b) ((COLORREF)(((uint8_t)(r)|((uint16_t)((uint8_t)(g))<<8))|(((uint32_t)(uint8_t)(b))<<16)))
|
||||
|
||||
#ifndef _COMPLEX_DEFINED
|
||||
|
||||
typedef struct tagcomplex {
|
||||
double x,y;
|
||||
} _complex;
|
||||
|
||||
#endif
|
||||
|
||||
#define _cabs(c) sqrt(c.x*c.x+c.y*c.y)
|
||||
|
||||
#endif
|
||||
|
||||
#endif //__ximadefs
|
|
@ -0,0 +1,809 @@
|
|||
/*
|
||||
* File: ximage.h
|
||||
* Purpose: General Purpose Image Class
|
||||
*/
|
||||
/*
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
|
||||
|
||||
CxImage version 7.0.2 07/Feb/2011
|
||||
|
||||
CxImage : Copyright (C) 2001 - 2010, Davide Pizzolato
|
||||
|
||||
Original CImage and CImageIterator implementation are:
|
||||
Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)
|
||||
|
||||
Covered code is provided under this license on an "as is" basis, without warranty
|
||||
of any kind, either expressed or implied, including, without limitation, warranties
|
||||
that the covered code is free of defects, merchantable, fit for a particular purpose
|
||||
or non-infringing. The entire risk as to the quality and performance of the covered
|
||||
code is with you. Should any covered code prove defective in any respect, you (not
|
||||
the initial developer or any other contributor) assume the cost of any necessary
|
||||
servicing, repair or correction. This disclaimer of warranty constitutes an essential
|
||||
part of this license. No use of any covered code is authorized hereunder except under
|
||||
this disclaimer.
|
||||
|
||||
Permission is hereby granted to use, copy, modify, and distribute this
|
||||
source code, or portions hereof, for any purpose, including commercial applications,
|
||||
freely and without fee, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Other information about CxImage, and the latest version, can be found at the
|
||||
CxImage home page: http://www.xdp.it/cximage/
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
*/
|
||||
#if !defined(__CXIMAGE_H)
|
||||
#define __CXIMAGE_H
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifdef _LINUX
|
||||
#define _XOPEN_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#include "xfile.h"
|
||||
#include "xiofile.h"
|
||||
#include "xmemfile.h"
|
||||
#include "ximadef.h" //<vho> adjust some #define
|
||||
|
||||
/* see "ximacfg.h" for CxImage configuration options */
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CxImage formats enumerator
|
||||
enum ENUM_CXIMAGE_FORMATS{
|
||||
CXIMAGE_FORMAT_UNKNOWN = 0,
|
||||
#if CXIMAGE_SUPPORT_BMP
|
||||
CXIMAGE_FORMAT_BMP = 1,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_GIF
|
||||
CXIMAGE_FORMAT_GIF = 2,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_JPG
|
||||
CXIMAGE_FORMAT_JPG = 3,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_PNG
|
||||
CXIMAGE_FORMAT_PNG = 4,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_ICO
|
||||
CXIMAGE_FORMAT_ICO = 5,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_TIF
|
||||
CXIMAGE_FORMAT_TIF = 6,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_TGA
|
||||
CXIMAGE_FORMAT_TGA = 7,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_PCX
|
||||
CXIMAGE_FORMAT_PCX = 8,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_WBMP
|
||||
CXIMAGE_FORMAT_WBMP = 9,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_WMF
|
||||
CXIMAGE_FORMAT_WMF = 10,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_JP2
|
||||
CXIMAGE_FORMAT_JP2 = 11,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_JPC
|
||||
CXIMAGE_FORMAT_JPC = 12,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_PGX
|
||||
CXIMAGE_FORMAT_PGX = 13,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_PNM
|
||||
CXIMAGE_FORMAT_PNM = 14,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_RAS
|
||||
CXIMAGE_FORMAT_RAS = 15,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_JBG
|
||||
CXIMAGE_FORMAT_JBG = 16,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_MNG
|
||||
CXIMAGE_FORMAT_MNG = 17,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_SKA
|
||||
CXIMAGE_FORMAT_SKA = 18,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_RAW
|
||||
CXIMAGE_FORMAT_RAW = 19,
|
||||
#endif
|
||||
#if CXIMAGE_SUPPORT_PSD
|
||||
CXIMAGE_FORMAT_PSD = 20,
|
||||
#endif
|
||||
CMAX_IMAGE_FORMATS = CXIMAGE_SUPPORT_BMP + CXIMAGE_SUPPORT_GIF + CXIMAGE_SUPPORT_JPG +
|
||||
CXIMAGE_SUPPORT_PNG + CXIMAGE_SUPPORT_MNG + CXIMAGE_SUPPORT_ICO +
|
||||
CXIMAGE_SUPPORT_TIF + CXIMAGE_SUPPORT_TGA + CXIMAGE_SUPPORT_PCX +
|
||||
CXIMAGE_SUPPORT_WBMP+ CXIMAGE_SUPPORT_WMF +
|
||||
CXIMAGE_SUPPORT_JBG + CXIMAGE_SUPPORT_JP2 + CXIMAGE_SUPPORT_JPC +
|
||||
CXIMAGE_SUPPORT_PGX + CXIMAGE_SUPPORT_PNM + CXIMAGE_SUPPORT_RAS +
|
||||
CXIMAGE_SUPPORT_SKA + CXIMAGE_SUPPORT_RAW + CXIMAGE_SUPPORT_PSD + 1
|
||||
};
|
||||
|
||||
#if CXIMAGE_SUPPORT_EXIF
|
||||
|
||||
#define MAX_COMMENT 255
|
||||
#define MAX_SECTIONS 20
|
||||
|
||||
typedef struct tag_ExifInfo {
|
||||
char Version [5];
|
||||
char CameraMake [32];
|
||||
char CameraModel [40];
|
||||
char DateTime [20];
|
||||
int32_t Height, Width;
|
||||
int32_t Orientation;
|
||||
int32_t IsColor;
|
||||
int32_t Process;
|
||||
int32_t FlashUsed;
|
||||
float FocalLength;
|
||||
float ExposureTime;
|
||||
float ApertureFNumber;
|
||||
float Distance;
|
||||
float CCDWidth;
|
||||
float ExposureBias;
|
||||
int32_t Whitebalance;
|
||||
int32_t MeteringMode;
|
||||
int32_t ExposureProgram;
|
||||
int32_t ISOequivalent;
|
||||
int32_t CompressionLevel;
|
||||
float FocalplaneXRes;
|
||||
float FocalplaneYRes;
|
||||
float FocalplaneUnits;
|
||||
float Xresolution;
|
||||
float Yresolution;
|
||||
float ResolutionUnit;
|
||||
float Brightness;
|
||||
char Comments[MAX_COMMENT+1];
|
||||
|
||||
uint8_t * ThumbnailPointer; /* Pointer at the thumbnail */
|
||||
unsigned ThumbnailSize; /* Size of thumbnail. */
|
||||
|
||||
bool IsExif;
|
||||
} EXIFINFO;
|
||||
|
||||
#endif //CXIMAGE_SUPPORT_EXIF
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CxImage class
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
class DLL_EXP CxImage
|
||||
{
|
||||
//extensible information collector
|
||||
typedef struct tagCxImageInfo {
|
||||
uint32_t dwEffWidth; ///< uint32_t aligned scan line width
|
||||
uint8_t* pImage; ///< THE IMAGE BITS
|
||||
CxImage* pGhost; ///< if this is a ghost, pGhost points to the body
|
||||
CxImage* pParent; ///< if this is a layer, pParent points to the body
|
||||
uint32_t dwType; ///< original image format
|
||||
char szLastError[256]; ///< debugging
|
||||
int32_t nProgress; ///< monitor
|
||||
int32_t nEscape; ///< escape
|
||||
int32_t nBkgndIndex; ///< used for GIF, PNG, MNG
|
||||
RGBQUAD nBkgndColor; ///< used for RGB transparency
|
||||
float fQuality; ///< used for JPEG, JPEG2000 (0.0f ... 100.0f)
|
||||
uint8_t nJpegScale; ///< used for JPEG [ignacio]
|
||||
int32_t nFrame; ///< used for TIF, GIF, MNG : actual frame
|
||||
int32_t nNumFrames; ///< used for TIF, GIF, MNG : total number of frames
|
||||
uint32_t dwFrameDelay; ///< used for GIF, MNG
|
||||
int32_t xDPI; ///< horizontal resolution
|
||||
int32_t yDPI; ///< vertical resolution
|
||||
RECT rSelectionBox; ///< bounding rectangle
|
||||
uint8_t nAlphaMax; ///< max opacity (fade)
|
||||
bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled.
|
||||
bool bEnabled; ///< enables the painting functions
|
||||
int32_t xOffset;
|
||||
int32_t yOffset;
|
||||
uint32_t dwCodecOpt[CMAX_IMAGE_FORMATS]; ///< for GIF, TIF : 0=def.1=unc,2=fax3,3=fax4,4=pack,5=jpg
|
||||
RGBQUAD last_c; ///< for GetNearestIndex optimization
|
||||
uint8_t last_c_index;
|
||||
bool last_c_isvalid;
|
||||
int32_t nNumLayers;
|
||||
uint32_t dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags
|
||||
uint8_t dispmeth;
|
||||
bool bGetAllFrames;
|
||||
bool bLittleEndianHost;
|
||||
|
||||
#if CXIMAGE_SUPPORT_EXIF
|
||||
EXIFINFO ExifInfo;
|
||||
#endif
|
||||
|
||||
} CXIMAGEINFO;
|
||||
|
||||
public:
|
||||
//public structures
|
||||
struct rgb_color { uint8_t r,g,b; };
|
||||
|
||||
#if CXIMAGE_SUPPORT_WINDOWS
|
||||
// <VATI> text placement data
|
||||
// members must be initialized with the InitTextInfo(&this) function.
|
||||
typedef struct tagCxTextInfo
|
||||
{
|
||||
#if defined (_WIN32_WCE)
|
||||
TCHAR text[256]; ///< text for windows CE
|
||||
#else
|
||||
TCHAR text[4096]; ///< text (char -> TCHAR for UNICODE [Cesar M])
|
||||
#endif
|
||||
LOGFONT lfont; ///< font and codepage data
|
||||
COLORREF fcolor; ///< foreground color
|
||||
int32_t align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text
|
||||
uint8_t smooth; ///< text smoothing option. Default is false.
|
||||
uint8_t opaque; ///< text has background or hasn't. Default is true.
|
||||
///< data for background (ignored if .opaque==FALSE)
|
||||
COLORREF bcolor; ///< background color
|
||||
float b_opacity; ///< opacity value for background between 0.0-1.0 Default is 0. (opaque)
|
||||
uint8_t b_outline; ///< outline width for background (zero: no outline)
|
||||
uint8_t b_round; ///< rounding radius for background rectangle. % of the height, between 0-50. Default is 10.
|
||||
///< (backgr. always has a frame: width = 3 pixel + 10% of height by default.)
|
||||
} CXTEXTINFO;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/** \addtogroup Constructors */ //@{
|
||||
CxImage(uint32_t imagetype = 0);
|
||||
CxImage(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
|
||||
CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
|
||||
#if CXIMAGE_SUPPORT_DECODE
|
||||
CxImage(const TCHAR * filename, uint32_t imagetype); // For UNICODE support: char -> TCHAR
|
||||
CxImage(FILE * stream, uint32_t imagetype);
|
||||
CxImage(CxFile * stream, uint32_t imagetype);
|
||||
CxImage(uint8_t * buffer, uint32_t size, uint32_t imagetype);
|
||||
#endif
|
||||
virtual ~CxImage() { DestroyFrames(); Destroy(); };
|
||||
CxImage& operator = (const CxImage&);
|
||||
//@}
|
||||
|
||||
/** \addtogroup Initialization */ //@{
|
||||
void* Create(uint32_t dwWidth, uint32_t dwHeight, uint32_t wBpp, uint32_t imagetype = 0);
|
||||
bool Destroy();
|
||||
bool DestroyFrames();
|
||||
void Clear(uint8_t bval=0);
|
||||
void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
|
||||
bool Transfer(CxImage &from, bool bTransferFrames = true);
|
||||
bool CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
|
||||
bool CreateFromMatrix(uint8_t** ppMatrix,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
|
||||
void FreeMemory(void* memblock);
|
||||
|
||||
uint32_t Dump(uint8_t * dst);
|
||||
uint32_t UnDump(const uint8_t * src);
|
||||
uint32_t DumpSize();
|
||||
|
||||
//@}
|
||||
|
||||
/** \addtogroup Attributes */ //@{
|
||||
int32_t GetSize();
|
||||
uint8_t* GetBits(uint32_t row = 0);
|
||||
uint8_t GetColorType();
|
||||
void* GetDIB() const;
|
||||
uint32_t GetHeight() const;
|
||||
uint32_t GetWidth() const;
|
||||
uint32_t GetEffWidth() const;
|
||||
uint32_t GetNumColors() const;
|
||||
uint16_t GetBpp() const;
|
||||
uint32_t GetType() const;
|
||||
const char* GetLastError();
|
||||
static const TCHAR* GetVersion();
|
||||
static const float GetVersionNumber();
|
||||
|
||||
uint32_t GetFrameDelay() const;
|
||||
void SetFrameDelay(uint32_t d);
|
||||
|
||||
void GetOffset(int32_t *x,int32_t *y);
|
||||
void SetOffset(int32_t x,int32_t y);
|
||||
|
||||
uint8_t GetJpegQuality() const;
|
||||
void SetJpegQuality(uint8_t q);
|
||||
float GetJpegQualityF() const;
|
||||
void SetJpegQualityF(float q);
|
||||
|
||||
uint8_t GetJpegScale() const;
|
||||
void SetJpegScale(uint8_t q);
|
||||
|
||||
#if CXIMAGE_SUPPORT_EXIF
|
||||
EXIFINFO *GetExifInfo() {return &info.ExifInfo;};
|
||||
bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t imageType);
|
||||
#if CXIMAGE_SUPPORT_TRANSFORMATION
|
||||
bool RotateExif(int32_t orientation = 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int32_t GetXDPI() const;
|
||||
int32_t GetYDPI() const;
|
||||
void SetXDPI(int32_t dpi);
|
||||
void SetYDPI(int32_t dpi);
|
||||
|
||||
uint32_t GetClrImportant() const;
|
||||
void SetClrImportant(uint32_t ncolors = 0);
|
||||
|
||||
int32_t GetProgress() const;
|
||||
int32_t GetEscape() const;
|
||||
void SetProgress(int32_t p);
|
||||
void SetEscape(int32_t i);
|
||||
|
||||
int32_t GetTransIndex() const;
|
||||
RGBQUAD GetTransColor();
|
||||
void SetTransIndex(int32_t idx);
|
||||
void SetTransColor(RGBQUAD rgb);
|
||||
bool IsTransparent() const;
|
||||
|
||||
uint32_t GetCodecOption(uint32_t imagetype = 0);
|
||||
bool SetCodecOption(uint32_t opt, uint32_t imagetype = 0);
|
||||
|
||||
uint32_t GetFlags() const;
|
||||
void SetFlags(uint32_t flags, bool bLockReservedFlags = true);
|
||||
|
||||
uint8_t GetDisposalMethod() const;
|
||||
void SetDisposalMethod(uint8_t dm);
|
||||
|
||||
bool SetType(uint32_t type);
|
||||
|
||||
static uint32_t GetNumTypes();
|
||||
static uint32_t GetTypeIdFromName(const TCHAR* ext);
|
||||
static uint32_t GetTypeIdFromIndex(const uint32_t index);
|
||||
static uint32_t GetTypeIndexFromId(const uint32_t id);
|
||||
|
||||
bool GetRetreiveAllFrames() const;
|
||||
void SetRetreiveAllFrames(bool flag);
|
||||
CxImage * GetFrame(int32_t nFrame) const;
|
||||
|
||||
//void* GetUserData() const {return info.pUserData;}
|
||||
//void SetUserData(void* pUserData) {info.pUserData = pUserData;}
|
||||
//@}
|
||||
|
||||
/** \addtogroup Palette
|
||||
* These functions have no effects on RGB images and in this case the returned value is always 0.
|
||||
* @{ */
|
||||
bool IsGrayScale();
|
||||
bool IsIndexed() const;
|
||||
bool IsSamePalette(CxImage &img, bool bCheckAlpha = true);
|
||||
uint32_t GetPaletteSize();
|
||||
RGBQUAD* GetPalette() const;
|
||||
RGBQUAD GetPaletteColor(uint8_t idx);
|
||||
bool GetPaletteColor(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b);
|
||||
uint8_t GetNearestIndex(RGBQUAD c);
|
||||
void BlendPalette(COLORREF cr,int32_t perc);
|
||||
void SetGrayPalette();
|
||||
void SetPalette(uint32_t n, uint8_t *r, uint8_t *g, uint8_t *b);
|
||||
void SetPalette(RGBQUAD* pPal,uint32_t nColors=256);
|
||||
void SetPalette(rgb_color *rgb,uint32_t nColors=256);
|
||||
void SetPaletteColor(uint8_t idx, uint8_t r, uint8_t g, uint8_t b, uint8_t alpha=0);
|
||||
void SetPaletteColor(uint8_t idx, RGBQUAD c);
|
||||
void SetPaletteColor(uint8_t idx, COLORREF cr);
|
||||
void SwapIndex(uint8_t idx1, uint8_t idx2);
|
||||
void SwapRGB2BGR();
|
||||
void SetStdPalette();
|
||||
//@}
|
||||
|
||||
/** \addtogroup Pixel */ //@{
|
||||
bool IsInside(int32_t x, int32_t y);
|
||||
bool IsTransparent(int32_t x,int32_t y);
|
||||
bool GetTransparentMask(CxImage* iDst = 0);
|
||||
RGBQUAD GetPixelColor(int32_t x,int32_t y, bool bGetAlpha = true);
|
||||
uint8_t GetPixelIndex(int32_t x,int32_t y);
|
||||
uint8_t GetPixelGray(int32_t x, int32_t y);
|
||||
void SetPixelColor(int32_t x,int32_t y,RGBQUAD c, bool bSetAlpha = false);
|
||||
void SetPixelColor(int32_t x,int32_t y,COLORREF cr);
|
||||
void SetPixelIndex(int32_t x,int32_t y,uint8_t i);
|
||||
void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, RGBQUAD color, bool bSetAlpha=false);
|
||||
void DrawLine(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, COLORREF cr);
|
||||
void BlendPixelColor(int32_t x,int32_t y,RGBQUAD c, float blend, bool bSetAlpha = false);
|
||||
bool SetRectColor(int32_t left, int32_t top, int32_t right, int32_t bottom, RGBQUAD color, bool bSetAlpha = false);
|
||||
bool SetRectColor(RECT& rect, RGBQUAD color, bool bSetAlpha = false);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
uint8_t BlindGetPixelIndex(const int32_t x,const int32_t y);
|
||||
RGBQUAD BlindGetPixelColor(const int32_t x,const int32_t y, bool bGetAlpha = true);
|
||||
void *BlindGetPixelPointer(const int32_t x,const int32_t y);
|
||||
void BlindSetPixelColor(int32_t x,int32_t y,RGBQUAD c, bool bSetAlpha = false);
|
||||
void BlindSetPixelIndex(int32_t x,int32_t y,uint8_t i);
|
||||
//@}
|
||||
|
||||
public:
|
||||
|
||||
#if CXIMAGE_SUPPORT_INTERPOLATION
|
||||
/** \addtogroup Interpolation */ //@{
|
||||
//overflow methods:
|
||||
enum OverflowMethod {
|
||||
OM_COLOR=1,
|
||||
OM_BACKGROUND=2,
|
||||
OM_TRANSPARENT=3,
|
||||
OM_WRAP=4,
|
||||
OM_REPEAT=5,
|
||||
OM_MIRROR=6
|
||||
};
|
||||
void OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod);
|
||||
void OverflowCoordinates(int32_t &x, int32_t &y, OverflowMethod const ofMethod);
|
||||
RGBQUAD GetPixelColorWithOverflow(int32_t x, int32_t y, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
|
||||
//interpolation methods:
|
||||
enum InterpolationMethod {
|
||||
IM_NEAREST_NEIGHBOUR=1,
|
||||
IM_BILINEAR =2,
|
||||
IM_BSPLINE =3,
|
||||
IM_BICUBIC =4,
|
||||
IM_BICUBIC2 =5,
|
||||
IM_LANCZOS =6,
|
||||
IM_BOX =7,
|
||||
IM_HERMITE =8,
|
||||
IM_HAMMING =9,
|
||||
IM_SINC =10,
|
||||
IM_BLACKMAN =11,
|
||||
IM_BESSEL =12,
|
||||
IM_GAUSSIAN =13,
|
||||
IM_QUADRATIC =14,
|
||||
IM_MITCHELL =15,
|
||||
IM_CATROM =16,
|
||||
IM_HANNING =17,
|
||||
IM_POWER =18
|
||||
};
|
||||
RGBQUAD GetPixelColorInterpolated(float x,float y, InterpolationMethod const inMethod=IM_BILINEAR, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
|
||||
RGBQUAD GetAreaColorInterpolated(float const xc, float const yc, float const w, float const h, InterpolationMethod const inMethod, OverflowMethod const ofMethod=OM_BACKGROUND, RGBQUAD* const rplColor=0);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
void AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa);
|
||||
//@}
|
||||
|
||||
/** \addtogroup Kernels */ //@{
|
||||
public:
|
||||
static float KernelBSpline(const float x);
|
||||
static float KernelLinear(const float t);
|
||||
static float KernelCubic(const float t);
|
||||
static float KernelGeneralizedCubic(const float t, const float a=-1);
|
||||
static float KernelLanczosSinc(const float t, const float r = 3);
|
||||
static float KernelBox(const float x);
|
||||
static float KernelHermite(const float x);
|
||||
static float KernelHamming(const float x);
|
||||
static float KernelSinc(const float x);
|
||||
static float KernelBlackman(const float x);
|
||||
static float KernelBessel_J1(const float x);
|
||||
static float KernelBessel_P1(const float x);
|
||||
static float KernelBessel_Q1(const float x);
|
||||
static float KernelBessel_Order1(float x);
|
||||
static float KernelBessel(const float x);
|
||||
static float KernelGaussian(const float x);
|
||||
static float KernelQuadratic(const float x);
|
||||
static float KernelMitchell(const float x);
|
||||
static float KernelCatrom(const float x);
|
||||
static float KernelHanning(const float x);
|
||||
static float KernelPower(const float x, const float a = 2);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_INTERPOLATION
|
||||
|
||||
/** \addtogroup Painting */ //@{
|
||||
#if CXIMAGE_SUPPORT_WINDOWS
|
||||
int32_t Blt(HDC pDC, int32_t x=0, int32_t y=0);
|
||||
HBITMAP Draw2HBITMAP(HDC hdc, int32_t x, int32_t y, int32_t cx, int32_t cy, RECT* pClipRect, bool bSmooth);
|
||||
HBITMAP MakeBitmap(HDC hdc = NULL, bool bTransparency = false);
|
||||
HICON MakeIcon(HDC hdc = NULL, bool bTransparency = false);
|
||||
HANDLE CopyToHandle();
|
||||
bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard)
|
||||
bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0, bool bTransparency = false); //Windows resource
|
||||
bool CreateFromHICON(HICON hico, bool bTransparency = false);
|
||||
int32_t Draw(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1, RECT* pClipRect = 0, bool bSmooth = false, bool bFlipY = false);
|
||||
int32_t Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false, bool bFlipY = false);
|
||||
int32_t Stretch(HDC hdc, int32_t xoffset, int32_t yoffset, int32_t xsize, int32_t ysize, uint32_t dwRop = SRCCOPY);
|
||||
int32_t Stretch(HDC hdc, const RECT& rect, uint32_t dwRop = SRCCOPY);
|
||||
int32_t Tile(HDC hdc, RECT *rc);
|
||||
int32_t Draw2(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1);
|
||||
int32_t Draw2(HDC hdc, const RECT& rect);
|
||||
//int32_t DrawString(HDC hdc, int32_t x, int32_t y, const char* text, RGBQUAD color, const char* font, int32_t lSize=0, int32_t lWeight=400, uint8_t bItalic=0, uint8_t bUnderline=0, bool bSetAlpha=false);
|
||||
int32_t DrawString(HDC hdc, int32_t x, int32_t y, const TCHAR* text, RGBQUAD color, const TCHAR* font, int32_t lSize=0, int32_t lWeight=400, uint8_t bItalic=0, uint8_t bUnderline=0, bool bSetAlpha=false);
|
||||
// <VATI> extensions
|
||||
int32_t DrawStringEx(HDC hdc, int32_t x, int32_t y, CXTEXTINFO *pTextType, bool bSetAlpha=false );
|
||||
void InitTextInfo( CXTEXTINFO *txt );
|
||||
protected:
|
||||
bool IsHBITMAPAlphaValid( HBITMAP hbmp );
|
||||
public:
|
||||
#endif //CXIMAGE_SUPPORT_WINDOWS
|
||||
//@}
|
||||
|
||||
// file operations
|
||||
#if CXIMAGE_SUPPORT_DECODE
|
||||
/** \addtogroup Decode */ //@{
|
||||
#ifdef WIN32
|
||||
//bool Load(LPCWSTR filename, uint32_t imagetype=0);
|
||||
bool LoadResource(HRSRC hRes, uint32_t imagetype, HMODULE hModule=NULL);
|
||||
#endif
|
||||
// For UNICODE support: char -> TCHAR
|
||||
bool Load(const TCHAR* filename, uint32_t imagetype=0);
|
||||
//bool Load(const char * filename, uint32_t imagetype=0);
|
||||
bool Decode(FILE * hFile, uint32_t imagetype);
|
||||
bool Decode(CxFile * hFile, uint32_t imagetype);
|
||||
bool Decode(uint8_t * buffer, uint32_t size, uint32_t imagetype);
|
||||
|
||||
bool CheckFormat(CxFile * hFile, uint32_t imagetype = 0);
|
||||
bool CheckFormat(uint8_t * buffer, uint32_t size, uint32_t imagetype = 0);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_DECODE
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
bool EncodeSafeCheck(CxFile *hFile);
|
||||
//@}
|
||||
|
||||
public:
|
||||
/** \addtogroup Encode */ //@{
|
||||
#ifdef WIN32
|
||||
//bool Save(LPCWSTR filename, uint32_t imagetype=0);
|
||||
#endif
|
||||
// For UNICODE support: char -> TCHAR
|
||||
bool Save(const TCHAR* filename, uint32_t imagetype);
|
||||
//bool Save(const char * filename, uint32_t imagetype=0);
|
||||
bool Encode(FILE * hFile, uint32_t imagetype);
|
||||
bool Encode(CxFile * hFile, uint32_t imagetype);
|
||||
bool Encode(CxFile * hFile, CxImage ** pImages, int32_t pagecount, uint32_t imagetype);
|
||||
bool Encode(FILE *hFile, CxImage ** pImages, int32_t pagecount, uint32_t imagetype);
|
||||
bool Encode(uint8_t * &buffer, int32_t &size, uint32_t imagetype);
|
||||
|
||||
bool Encode2RGBA(CxFile *hFile, bool bFlipY = false);
|
||||
bool Encode2RGBA(uint8_t * &buffer, int32_t &size, bool bFlipY = false);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
/** \addtogroup Attributes */ //@{
|
||||
//misc.
|
||||
bool IsValid() const;
|
||||
bool IsEnabled() const;
|
||||
void Enable(bool enable=true);
|
||||
|
||||
// frame operations
|
||||
int32_t GetNumFrames() const;
|
||||
int32_t GetFrame() const;
|
||||
void SetFrame(int32_t nFrame);
|
||||
//@}
|
||||
|
||||
#if CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
|
||||
/** \addtogroup BasicTransformations */ //@{
|
||||
bool GrayScale();
|
||||
bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);
|
||||
bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);
|
||||
bool Negative();
|
||||
bool RotateLeft(CxImage* iDst = NULL);
|
||||
bool RotateRight(CxImage* iDst = NULL);
|
||||
bool IncreaseBpp(uint32_t nbit);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_BASICTRANSFORMATIONS
|
||||
|
||||
#if CXIMAGE_SUPPORT_TRANSFORMATION
|
||||
/** \addtogroup Transformations */ //@{
|
||||
// image operations
|
||||
bool Rotate(float angle, CxImage* iDst = NULL);
|
||||
bool Rotate2(float angle, CxImage *iDst = NULL, InterpolationMethod inMethod=IM_BILINEAR,
|
||||
OverflowMethod ofMethod=OM_BACKGROUND, RGBQUAD *replColor=0,
|
||||
bool const optimizeRightAngles=true, bool const bKeepOriginalSize=false);
|
||||
bool Rotate180(CxImage* iDst = NULL);
|
||||
bool Resample(int32_t newx, int32_t newy, int32_t mode = 1, CxImage* iDst = NULL);
|
||||
bool Resample2(int32_t newx, int32_t newy, InterpolationMethod const inMethod=IM_BICUBIC2,
|
||||
OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL,
|
||||
bool const disableAveraging=false);
|
||||
bool DecreaseBpp(uint32_t nbit, bool errordiffusion, RGBQUAD* ppal = 0, uint32_t clrimportant = 0);
|
||||
bool Dither(int32_t method = 0);
|
||||
bool Crop(int32_t left, int32_t top, int32_t right, int32_t bottom, CxImage* iDst = NULL);
|
||||
bool Crop(const RECT& rect, CxImage* iDst = NULL);
|
||||
bool CropRotatedRectangle( int32_t topx, int32_t topy, int32_t width, int32_t height, float angle, CxImage* iDst = NULL);
|
||||
bool Skew(float xgain, float ygain, int32_t xpivot=0, int32_t ypivot=0, bool bEnableInterpolation = false);
|
||||
bool Expand(int32_t left, int32_t top, int32_t right, int32_t bottom, RGBQUAD canvascolor, CxImage* iDst = 0);
|
||||
bool Expand(int32_t newx, int32_t newy, RGBQUAD canvascolor, CxImage* iDst = 0);
|
||||
bool Thumbnail(int32_t newx, int32_t newy, RGBQUAD canvascolor, CxImage* iDst = 0);
|
||||
bool CircleTransform(int32_t type,int32_t rmax=0,float Koeff=1.0f);
|
||||
bool QIShrink(int32_t newx, int32_t newy, CxImage* const iDst = NULL, bool bChangeBpp = false);
|
||||
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_TRANSFORMATION
|
||||
|
||||
#if CXIMAGE_SUPPORT_DSP
|
||||
/** \addtogroup DSP */ //@{
|
||||
bool Contour();
|
||||
bool HistogramStretch(int32_t method = 0, double threshold = 0);
|
||||
bool HistogramEqualize();
|
||||
bool HistogramNormalize();
|
||||
bool HistogramRoot();
|
||||
bool HistogramLog();
|
||||
int32_t Histogram(int32_t* red, int32_t* green = 0, int32_t* blue = 0, int32_t* gray = 0, int32_t colorspace = 0);
|
||||
bool Jitter(int32_t radius=2);
|
||||
bool Repair(float radius = 0.25f, int32_t niterations = 1, int32_t colorspace = 0);
|
||||
bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, int32_t colorspace = 0);
|
||||
bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, int32_t direction = 1, bool bForceFFT = true, bool bMagnitude = true);
|
||||
bool Noise(int32_t level);
|
||||
bool Median(int32_t Ksize=3);
|
||||
bool Gamma(float gamma);
|
||||
bool GammaRGB(float gammaR, float gammaG, float gammaB);
|
||||
bool ShiftRGB(int32_t r, int32_t g, int32_t b);
|
||||
bool Threshold(uint8_t level);
|
||||
bool Threshold(CxImage* pThresholdMask);
|
||||
bool Threshold2(uint8_t level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha = false);
|
||||
bool Colorize(uint8_t hue, uint8_t sat, float blend = 1.0f);
|
||||
bool Light(int32_t brightness, int32_t contrast = 0);
|
||||
float Mean();
|
||||
bool Filter(int32_t* kernel, int32_t Ksize, int32_t Kfactor, int32_t Koffset);
|
||||
bool Erode(int32_t Ksize=2);
|
||||
bool Dilate(int32_t Ksize=2);
|
||||
bool Edge(int32_t Ksize=2);
|
||||
void HuePalette(float correction=1);
|
||||
enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen, OpAvg, OpBlendAlpha };
|
||||
void Mix(CxImage & imgsrc2, ImageOpType op, int32_t lXOffset = 0, int32_t lYOffset = 0, bool bMixAlpha = false);
|
||||
void MixFrom(CxImage & imagesrc2, int32_t lXOffset, int32_t lYOffset);
|
||||
bool UnsharpMask(float radius = 5.0f, float amount = 0.5f, int32_t threshold = 0);
|
||||
bool Lut(uint8_t* pLut);
|
||||
bool Lut(uint8_t* pLutR, uint8_t* pLutG, uint8_t* pLutB, uint8_t* pLutA = 0);
|
||||
bool GaussianBlur(float radius = 1.0f, CxImage* iDst = 0);
|
||||
bool TextBlur(uint8_t threshold = 100, uint8_t decay = 2, uint8_t max_depth = 5, bool bBlurHorizontal = true, bool bBlurVertical = true, CxImage* iDst = 0);
|
||||
bool SelectiveBlur(float radius = 1.0f, uint8_t threshold = 25, CxImage* iDst = 0);
|
||||
bool Solarize(uint8_t level = 128, bool bLinkedChannels = true);
|
||||
bool FloodFill(const int32_t xStart, const int32_t yStart, const RGBQUAD cFillColor, const uint8_t tolerance = 0,
|
||||
uint8_t nOpacity = 255, const bool bSelectFilledArea = false, const uint8_t nSelectionLevel = 255);
|
||||
bool Saturate(const int32_t saturation, const int32_t colorspace = 1);
|
||||
bool ConvertColorSpace(const int32_t dstColorSpace, const int32_t srcColorSpace);
|
||||
int32_t OptimalThreshold(int32_t method = 0, RECT * pBox = 0, CxImage* pContrastMask = 0);
|
||||
bool AdaptiveThreshold(int32_t method = 0, int32_t nBoxSize = 64, CxImage* pContrastMask = 0, int32_t nBias = 0, float fGlobalLocalBalance = 0.5f);
|
||||
bool RedEyeRemove(float strength = 0.8f);
|
||||
bool Trace(RGBQUAD color_target, RGBQUAD color_trace);
|
||||
|
||||
//@}
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
bool IsPowerof2(int32_t x);
|
||||
bool FFT(int32_t dir,int32_t m,double *x,double *y);
|
||||
bool DFT(int32_t dir,int32_t m,double *x1,double *y1,double *x2,double *y2);
|
||||
bool RepairChannel(CxImage *ch, float radius);
|
||||
// <nipper>
|
||||
int32_t gen_convolve_matrix (float radius, float **cmatrix_p);
|
||||
float* gen_lookup_table (float *cmatrix, int32_t cmatrix_length);
|
||||
void blur_line (float *ctable, float *cmatrix, int32_t cmatrix_length, uint8_t* cur_col, uint8_t* dest_col, int32_t y, int32_t bytes);
|
||||
void blur_text (uint8_t threshold, uint8_t decay, uint8_t max_depth, CxImage* iSrc, CxImage* iDst, uint8_t bytes);
|
||||
//@}
|
||||
|
||||
public:
|
||||
/** \addtogroup ColorSpace */ //@{
|
||||
bool SplitRGB(CxImage* r,CxImage* g,CxImage* b);
|
||||
bool SplitYUV(CxImage* y,CxImage* u,CxImage* v);
|
||||
bool SplitHSL(CxImage* h,CxImage* s,CxImage* l);
|
||||
bool SplitYIQ(CxImage* y,CxImage* i,CxImage* q);
|
||||
bool SplitXYZ(CxImage* x,CxImage* y,CxImage* z);
|
||||
bool SplitCMYK(CxImage* c,CxImage* m,CxImage* y,CxImage* k);
|
||||
static RGBQUAD HSLtoRGB(COLORREF cHSLColor);
|
||||
static RGBQUAD RGBtoHSL(RGBQUAD lRGBColor);
|
||||
static RGBQUAD HSLtoRGB(RGBQUAD lHSLColor);
|
||||
static RGBQUAD YUVtoRGB(RGBQUAD lYUVColor);
|
||||
static RGBQUAD RGBtoYUV(RGBQUAD lRGBColor);
|
||||
static RGBQUAD YIQtoRGB(RGBQUAD lYIQColor);
|
||||
static RGBQUAD RGBtoYIQ(RGBQUAD lRGBColor);
|
||||
static RGBQUAD XYZtoRGB(RGBQUAD lXYZColor);
|
||||
static RGBQUAD RGBtoXYZ(RGBQUAD lRGBColor);
|
||||
#endif //CXIMAGE_SUPPORT_DSP
|
||||
static RGBQUAD RGBtoRGBQUAD(COLORREF cr);
|
||||
static COLORREF RGBQUADtoRGB (RGBQUAD c);
|
||||
//@}
|
||||
|
||||
/** \addtogroup Selection */ //@{
|
||||
bool SelectionIsValid();
|
||||
#if CXIMAGE_SUPPORT_SELECTION
|
||||
bool SelectionClear(uint8_t level = 0);
|
||||
bool SelectionCreate();
|
||||
bool SelectionDelete();
|
||||
bool SelectionInvert();
|
||||
bool SelectionMirror();
|
||||
bool SelectionFlip();
|
||||
bool SelectionAddRect(RECT r, uint8_t level = 255);
|
||||
bool SelectionAddEllipse(RECT r, uint8_t level = 255);
|
||||
bool SelectionAddPolygon(POINT *points, int32_t npoints, uint8_t level = 255);
|
||||
bool SelectionAddColor(RGBQUAD c, uint8_t level = 255);
|
||||
bool SelectionAddPixel(int32_t x, int32_t y, uint8_t level = 255);
|
||||
bool SelectionCopy(CxImage &from);
|
||||
bool SelectionIsInside(int32_t x, int32_t y);
|
||||
void SelectionGetBox(RECT& r);
|
||||
bool SelectionToHRGN(HRGN& region);
|
||||
bool SelectionSplit(CxImage *dest);
|
||||
uint8_t SelectionGet(const int32_t x,const int32_t y);
|
||||
bool SelectionSet(CxImage &from);
|
||||
void SelectionRebuildBox();
|
||||
uint8_t* SelectionGetPointer(const int32_t x = 0,const int32_t y = 0);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
bool BlindSelectionIsInside(int32_t x, int32_t y);
|
||||
uint8_t BlindSelectionGet(const int32_t x,const int32_t y);
|
||||
void SelectionSet(const int32_t x,const int32_t y,const uint8_t level);
|
||||
|
||||
public:
|
||||
|
||||
#endif //CXIMAGE_SUPPORT_SELECTION
|
||||
//@}
|
||||
|
||||
#if CXIMAGE_SUPPORT_ALPHA
|
||||
/** \addtogroup Alpha */ //@{
|
||||
void AlphaClear();
|
||||
bool AlphaCreate();
|
||||
void AlphaDelete();
|
||||
void AlphaInvert();
|
||||
bool AlphaMirror();
|
||||
bool AlphaFlip();
|
||||
bool AlphaCopy(CxImage &from);
|
||||
bool AlphaSplit(CxImage *dest);
|
||||
void AlphaStrip();
|
||||
void AlphaSet(uint8_t level);
|
||||
bool AlphaSet(CxImage &from);
|
||||
void AlphaSet(const int32_t x,const int32_t y,const uint8_t level);
|
||||
uint8_t AlphaGet(const int32_t x,const int32_t y);
|
||||
uint8_t AlphaGetMax() const;
|
||||
void AlphaSetMax(uint8_t nAlphaMax);
|
||||
bool AlphaIsValid();
|
||||
uint8_t* AlphaGetPointer(const int32_t x = 0,const int32_t y = 0);
|
||||
bool AlphaFromTransparency();
|
||||
|
||||
void AlphaPaletteClear();
|
||||
void AlphaPaletteEnable(bool enable=true);
|
||||
bool AlphaPaletteIsEnabled();
|
||||
bool AlphaPaletteIsValid();
|
||||
bool AlphaPaletteSplit(CxImage *dest);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
uint8_t BlindAlphaGet(const int32_t x,const int32_t y);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_ALPHA
|
||||
|
||||
public:
|
||||
#if CXIMAGE_SUPPORT_LAYERS
|
||||
/** \addtogroup Layers */ //@{
|
||||
bool LayerCreate(int32_t position = -1);
|
||||
bool LayerDelete(int32_t position = -1);
|
||||
void LayerDeleteAll();
|
||||
CxImage* GetLayer(int32_t position);
|
||||
CxImage* GetParent() const;
|
||||
int32_t GetNumLayers() const;
|
||||
int32_t LayerDrawAll(HDC hdc, int32_t x=0, int32_t y=0, int32_t cx = -1, int32_t cy = -1, RECT* pClipRect = 0, bool bSmooth = false);
|
||||
int32_t LayerDrawAll(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false);
|
||||
//@}
|
||||
#endif //CXIMAGE_SUPPORT_LAYERS
|
||||
|
||||
protected:
|
||||
/** \addtogroup Protected */ //@{
|
||||
void Startup(uint32_t imagetype = 0);
|
||||
void CopyInfo(const CxImage &src);
|
||||
void Ghost(const CxImage *src);
|
||||
void RGBtoBGR(uint8_t *buffer, int32_t length);
|
||||
static float HueToRGB(float n1,float n2, float hue);
|
||||
void Bitfield2RGB(uint8_t *src, uint32_t redmask, uint32_t greenmask, uint32_t bluemask, uint8_t bpp);
|
||||
static int32_t CompareColors(const void *elem1, const void *elem2);
|
||||
int16_t m_ntohs(const int16_t word);
|
||||
int32_t m_ntohl(const int32_t dword);
|
||||
void bihtoh(BITMAPINFOHEADER* bih);
|
||||
|
||||
void* pDib; //contains the header, the palette, the pixels
|
||||
BITMAPINFOHEADER head; //standard header
|
||||
CXIMAGEINFO info; //extended information
|
||||
uint8_t* pSelection; //selected region
|
||||
uint8_t* pAlpha; //alpha channel
|
||||
CxImage** ppLayers; //generic layers
|
||||
CxImage** ppFrames;
|
||||
//@}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
#endif // !defined(__CXIMAGE_H)
|
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* File: ximagif.h
|
||||
* Purpose: GIF Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageGIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
|
||||
*
|
||||
* original CImageGIF and CImageIterator implementation are:
|
||||
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
|
||||
*
|
||||
* 6/15/97 Randy Spann: Added GIF87a writing support
|
||||
* R.Spann@ConnRiver.net
|
||||
*
|
||||
* DECODE.C - An LZW decoder for GIF
|
||||
* Copyright (C) 1987, by Steven A. Bennett
|
||||
* Copyright (C) 1994, C++ version by Alejandro Aguilar Sierra
|
||||
*
|
||||
* In accordance with the above, I want to credit Steve Wilhite who wrote
|
||||
* the code which this is heavily inspired by...
|
||||
*
|
||||
* GIF and 'Graphics Interchange Format' are trademarks (tm) of
|
||||
* Compuserve, Incorporated, an H&R Block Company.
|
||||
*
|
||||
* Release Notes: This file contains a decoder routine for GIF images
|
||||
* which is similar, structurally, to the original routine by Steve Wilhite.
|
||||
* It is, however, somewhat noticably faster in most cases.
|
||||
*
|
||||
* ==========================================================
|
||||
*/
|
||||
|
||||
#if !defined(__ximaGIF_h)
|
||||
#define __ximaGIF_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_GIF
|
||||
|
||||
typedef int16_t code_int;
|
||||
|
||||
/* Various error codes used by decoder */
|
||||
#define OUT_OF_MEMORY -10
|
||||
#define BAD_CODE_SIZE -20
|
||||
#define READ_ERROR -1
|
||||
#define WRITE_ERROR -2
|
||||
#define OPEN_ERROR -3
|
||||
#define CREATE_ERROR -4
|
||||
#define BAD_LINE_WIDTH -5
|
||||
#define MAX_CODES 4095
|
||||
#define GIFBUFTAM 16383
|
||||
#define TRANSPARENCY_CODE 0xF9
|
||||
|
||||
//LZW GIF Image compression
|
||||
#define MAXBITSCODES 12
|
||||
#define HSIZE 5003 /* 80% occupancy */
|
||||
#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1)
|
||||
#define HashTabOf(i) htab[i]
|
||||
#define CodeTabOf(i) codetab[i]
|
||||
|
||||
|
||||
class CImageIterator;
|
||||
class DLL_EXP CxImageGIF: public CxImage
|
||||
{
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct tag_gifgce{
|
||||
uint8_t flags; /*res:3|dispmeth:3|userinputflag:1|transpcolflag:1*/
|
||||
uint16_t delaytime;
|
||||
uint8_t transpcolindex;
|
||||
} struct_gifgce;
|
||||
|
||||
typedef struct tag_dscgif{ /* Logic Screen Descriptor */
|
||||
char header[6]; /* Firma and version */
|
||||
uint16_t scrwidth;
|
||||
uint16_t scrheight;
|
||||
char pflds;
|
||||
char bcindx;
|
||||
char pxasrat;
|
||||
} struct_dscgif;
|
||||
|
||||
typedef struct tag_image{ /* Image Descriptor */
|
||||
uint16_t l;
|
||||
uint16_t t;
|
||||
uint16_t w;
|
||||
uint16_t h;
|
||||
uint8_t pf;
|
||||
} struct_image;
|
||||
|
||||
typedef struct tag_TabCol{ /* Tabla de colores */
|
||||
int16_t colres; /* color resolution */
|
||||
int16_t sogct; /* size of global color table */
|
||||
rgb_color paleta[256]; /* paleta */
|
||||
} struct_TabCol;
|
||||
|
||||
typedef struct tag_RLE{
|
||||
int32_t rl_pixel;
|
||||
int32_t rl_basecode;
|
||||
int32_t rl_count;
|
||||
int32_t rl_table_pixel;
|
||||
int32_t rl_table_max;
|
||||
int32_t just_cleared;
|
||||
int32_t out_bits;
|
||||
int32_t out_bits_init;
|
||||
int32_t out_count;
|
||||
int32_t out_bump;
|
||||
int32_t out_bump_init;
|
||||
int32_t out_clear;
|
||||
int32_t out_clear_init;
|
||||
int32_t max_ocodes;
|
||||
int32_t code_clear;
|
||||
int32_t code_eof;
|
||||
uint32_t obuf;
|
||||
int32_t obits;
|
||||
uint8_t oblock[256];
|
||||
int32_t oblen;
|
||||
} struct_RLE;
|
||||
#pragma pack()
|
||||
|
||||
public:
|
||||
CxImageGIF();
|
||||
~CxImageGIF();
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_GIF);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_GIF);}
|
||||
|
||||
bool Decode(CxFile * fp);
|
||||
bool Decode(FILE *fp) { CxIOFile file(fp); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * fp);
|
||||
bool Encode(CxFile * fp, CxImage ** pImages, int32_t pagecount, bool bLocalColorMap = false, bool bLocalDispMeth = false);
|
||||
bool Encode(FILE *fp) { CxIOFile file(fp); return Encode(&file); }
|
||||
bool Encode(FILE *fp, CxImage ** pImages, int32_t pagecount, bool bLocalColorMap = false)
|
||||
{ CxIOFile file(fp); return Encode(&file, pImages, pagecount, bLocalColorMap); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
void SetLoops(int32_t loops);
|
||||
int32_t GetLoops();
|
||||
void SetComment(const char* sz_comment_in);
|
||||
void GetComment(char* sz_comment_out);
|
||||
|
||||
protected:
|
||||
bool DecodeExtension(CxFile *fp);
|
||||
void EncodeHeader(CxFile *fp);
|
||||
void EncodeLoopExtension(CxFile *fp);
|
||||
void EncodeExtension(CxFile *fp);
|
||||
void EncodeBody(CxFile *fp, bool bLocalColorMap = false);
|
||||
void EncodeComment(CxFile *fp);
|
||||
bool EncodeRGB(CxFile *fp);
|
||||
void GifMix(CxImage & imgsrc2, struct_image & imgdesc);
|
||||
|
||||
struct_gifgce gifgce;
|
||||
|
||||
int32_t curx, cury;
|
||||
int32_t CountDown;
|
||||
uint32_t cur_accum;
|
||||
int32_t cur_bits;
|
||||
int32_t interlaced, iypos, istep, iheight, ipass;
|
||||
int32_t ibf;
|
||||
int32_t ibfmax;
|
||||
uint8_t * buf;
|
||||
// Implementation
|
||||
int32_t GifNextPixel ();
|
||||
void Putword (int32_t w, CxFile* fp );
|
||||
void compressNONE (int32_t init_bits, CxFile* outfile);
|
||||
void compressLZW (int32_t init_bits, CxFile* outfile);
|
||||
void output (code_int code );
|
||||
void cl_hash (int32_t hsize);
|
||||
void char_out (int32_t c);
|
||||
void flush_char ();
|
||||
int16_t init_exp(int16_t size);
|
||||
int16_t get_next_code(CxFile*);
|
||||
int16_t decoder(CxFile*, CImageIterator* iter, int16_t linewidth, int32_t &bad_code_count);
|
||||
int32_t get_byte(CxFile*);
|
||||
int32_t out_line(CImageIterator* iter, uint8_t *pixels, int32_t linelen);
|
||||
int32_t get_num_frames(CxFile *f,struct_TabCol* TabColSrc,struct_dscgif* dscgif);
|
||||
int32_t seek_next_image(CxFile* fp, int32_t position);
|
||||
|
||||
int16_t curr_size; /* The current code size */
|
||||
int16_t clear; /* Value for a clear code */
|
||||
int16_t ending; /* Value for a ending code */
|
||||
int16_t newcodes; /* First available code */
|
||||
int16_t top_slot; /* Highest code for current size */
|
||||
int16_t slot; /* Last read code */
|
||||
|
||||
/* The following static variables are used
|
||||
* for seperating out codes */
|
||||
int16_t navail_bytes; /* # bytes left in block */
|
||||
int16_t nbits_left; /* # bits left in current uint8_t */
|
||||
uint8_t b1; /* Current uint8_t */
|
||||
uint8_t * byte_buff; /* Current block */
|
||||
uint8_t *pbytes; /* Pointer to next uint8_t in block */
|
||||
/* The reason we have these seperated like this instead of using
|
||||
* a structure like the original Wilhite code did, is because this
|
||||
* stuff generally produces significantly faster code when compiled...
|
||||
* This code is full of similar speedups... (For a good book on writing
|
||||
* C for speed or for space optomisation, see Efficient C by Tom Plum,
|
||||
* published by Plum-Hall Associates...)
|
||||
*/
|
||||
uint8_t * stack; /* Stack for storing pixels */
|
||||
uint8_t * suffix; /* Suffix table */
|
||||
uint16_t * prefix; /* Prefix linked list */
|
||||
|
||||
//LZW GIF Image compression routines
|
||||
int32_t * htab;
|
||||
uint16_t * codetab;
|
||||
int32_t n_bits; /* number of bits/code */
|
||||
code_int maxcode; /* maximum code, given n_bits */
|
||||
code_int free_ent; /* first unused entry */
|
||||
int32_t clear_flg;
|
||||
int32_t g_init_bits;
|
||||
CxFile* g_outfile;
|
||||
int32_t ClearCode;
|
||||
int32_t EOFCode;
|
||||
|
||||
int32_t a_count;
|
||||
char * accum;
|
||||
|
||||
char * m_comment;
|
||||
int32_t m_loops;
|
||||
|
||||
//RLE compression routines
|
||||
void compressRLE( int32_t init_bits, CxFile* outfile);
|
||||
void rle_clear(struct_RLE* rle);
|
||||
void rle_flush(struct_RLE* rle);
|
||||
void rle_flush_withtable(int32_t count, struct_RLE* rle);
|
||||
void rle_flush_clearorrep(int32_t count, struct_RLE* rle);
|
||||
void rle_flush_fromclear(int32_t count,struct_RLE* rle);
|
||||
void rle_output_plain(int32_t c,struct_RLE* rle);
|
||||
void rle_reset_out_clear(struct_RLE* rle);
|
||||
uint32_t rle_compute_triangle_count(uint32_t count, uint32_t nrepcodes);
|
||||
uint32_t rle_isqrt(uint32_t x);
|
||||
void rle_write_block(struct_RLE* rle);
|
||||
void rle_block_out(uint8_t c, struct_RLE* rle);
|
||||
void rle_block_flush(struct_RLE* rle);
|
||||
void rle_output(int32_t val, struct_RLE* rle);
|
||||
void rle_output_flush(struct_RLE* rle);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* File: ximaico.h
|
||||
* Purpose: ICON Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageICO (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaICO_h)
|
||||
#define __ximaICO_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_ICO
|
||||
|
||||
class CxImageICO: public CxImage
|
||||
{
|
||||
typedef struct tagIconDirectoryEntry {
|
||||
uint8_t bWidth;
|
||||
uint8_t bHeight;
|
||||
uint8_t bColorCount;
|
||||
uint8_t bReserved;
|
||||
uint16_t wPlanes;
|
||||
uint16_t wBitCount;
|
||||
uint32_t dwBytesInRes;
|
||||
uint32_t dwImageOffset;
|
||||
} ICONDIRENTRY;
|
||||
|
||||
typedef struct tagIconDir {
|
||||
uint16_t idReserved;
|
||||
uint16_t idType;
|
||||
uint16_t idCount;
|
||||
} ICONHEADER;
|
||||
|
||||
public:
|
||||
CxImageICO(): CxImage(CXIMAGE_FORMAT_ICO) {m_dwImageOffset=0;}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile, bool bAppend=false, int32_t nPageCount=0);
|
||||
bool Encode(CxFile * hFile, CxImage ** pImages, int32_t nPageCount);
|
||||
bool Encode(FILE *hFile, bool bAppend=false, int32_t nPageCount=0)
|
||||
{ CxIOFile file(hFile); return Encode(&file,bAppend,nPageCount); }
|
||||
bool Encode(FILE *hFile, CxImage ** pImages, int32_t nPageCount)
|
||||
{ CxIOFile file(hFile); return Encode(&file, pImages, nPageCount); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
uint32_t m_dwImageOffset;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
* File: ImaIter.h
|
||||
* Purpose: Declaration of the Platform Independent Image Base Class
|
||||
* Author: Alejandro Aguilar Sierra
|
||||
* Created: 1995
|
||||
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
|
||||
*
|
||||
* 07/08/2001 Davide Pizzolato - www.xdp.it
|
||||
* - removed slow loops
|
||||
* - added safe checks
|
||||
*
|
||||
* Permission is given by the author to freely redistribute and include
|
||||
* this code in any program as int32_t as this credit is given where due.
|
||||
*
|
||||
* COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
|
||||
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
|
||||
* THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
|
||||
* OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
|
||||
* CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
|
||||
* THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
|
||||
* SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
|
||||
* PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER.
|
||||
*
|
||||
* Use at your own risk!
|
||||
* ==========================================================
|
||||
*/
|
||||
|
||||
#if !defined(__ImaIter_h)
|
||||
#define __ImaIter_h
|
||||
|
||||
#include "ximage.h"
|
||||
#include "ximadef.h"
|
||||
|
||||
class CImageIterator
|
||||
{
|
||||
friend class CxImage;
|
||||
protected:
|
||||
int32_t Itx, Ity; // Counters
|
||||
int32_t Stepx, Stepy;
|
||||
uint8_t* IterImage; // Image pointer
|
||||
CxImage *ima;
|
||||
public:
|
||||
// Constructors
|
||||
CImageIterator ( void );
|
||||
CImageIterator ( CxImage *image );
|
||||
operator CxImage* ();
|
||||
|
||||
// Iterators
|
||||
BOOL ItOK ();
|
||||
void Reset ();
|
||||
void Upset ();
|
||||
void SetRow(uint8_t *buf, int32_t n);
|
||||
void GetRow(uint8_t *buf, int32_t n);
|
||||
uint8_t GetByte( ) { return IterImage[Itx]; }
|
||||
void SetByte(uint8_t b) { IterImage[Itx] = b; }
|
||||
uint8_t* GetRow(void);
|
||||
uint8_t* GetRow(int32_t n);
|
||||
BOOL NextRow();
|
||||
BOOL PrevRow();
|
||||
BOOL NextByte();
|
||||
BOOL PrevByte();
|
||||
|
||||
void SetSteps(int32_t x, int32_t y=0) { Stepx = x; Stepy = y; }
|
||||
void GetSteps(int32_t *x, int32_t *y) { *x = Stepx; *y = Stepy; }
|
||||
BOOL NextStep();
|
||||
BOOL PrevStep();
|
||||
|
||||
void SetY(int32_t y); /* AD - for interlace */
|
||||
int32_t GetY() {return Ity;}
|
||||
BOOL GetCol(uint8_t* pCol, uint32_t x);
|
||||
BOOL SetCol(uint8_t* pCol, uint32_t x);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline
|
||||
CImageIterator::CImageIterator(void)
|
||||
{
|
||||
ima = 0;
|
||||
IterImage = 0;
|
||||
Itx = Ity = 0;
|
||||
Stepx = Stepy = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline
|
||||
CImageIterator::CImageIterator(CxImage *imageImpl): ima(imageImpl)
|
||||
{
|
||||
if (ima) IterImage = ima->GetBits();
|
||||
Itx = Ity = 0;
|
||||
Stepx = Stepy = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline
|
||||
CImageIterator::operator CxImage* ()
|
||||
{
|
||||
return ima;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::ItOK ()
|
||||
{
|
||||
if (ima) return ima->IsInside(Itx, Ity);
|
||||
else return FALSE;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline void CImageIterator::Reset()
|
||||
{
|
||||
if (ima) IterImage = ima->GetBits();
|
||||
else IterImage=0;
|
||||
Itx = Ity = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline void CImageIterator::Upset()
|
||||
{
|
||||
Itx = 0;
|
||||
Ity = ima->GetHeight()-1;
|
||||
IterImage = ima->GetBits() + ima->GetEffWidth()*(ima->GetHeight()-1);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::NextRow()
|
||||
{
|
||||
if (++Ity >= (int32_t)ima->GetHeight()) return 0;
|
||||
IterImage += ima->GetEffWidth();
|
||||
return 1;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::PrevRow()
|
||||
{
|
||||
if (--Ity < 0) return 0;
|
||||
IterImage -= ima->GetEffWidth();
|
||||
return 1;
|
||||
}
|
||||
/* AD - for interlace */
|
||||
inline void CImageIterator::SetY(int32_t y)
|
||||
{
|
||||
if ((y < 0) || (y > (int32_t)ima->GetHeight())) return;
|
||||
Ity = y;
|
||||
IterImage = ima->GetBits() + ima->GetEffWidth()*y;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline void CImageIterator::SetRow(uint8_t *buf, int32_t n)
|
||||
{
|
||||
if (n<0) n = (int32_t)ima->GetEffWidth();
|
||||
else n = min(n,(int32_t)ima->GetEffWidth());
|
||||
|
||||
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline void CImageIterator::GetRow(uint8_t *buf, int32_t n)
|
||||
{
|
||||
if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0))
|
||||
memcpy(buf,IterImage,min(n,(int32_t)ima->GetEffWidth()));
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline uint8_t* CImageIterator::GetRow()
|
||||
{
|
||||
return IterImage;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline uint8_t* CImageIterator::GetRow(int32_t n)
|
||||
{
|
||||
SetY(n);
|
||||
return IterImage;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::NextByte()
|
||||
{
|
||||
if (++Itx < (int32_t)ima->GetEffWidth()) return 1;
|
||||
else
|
||||
if (++Ity < (int32_t)ima->GetHeight()){
|
||||
IterImage += ima->GetEffWidth();
|
||||
Itx = 0;
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::PrevByte()
|
||||
{
|
||||
if (--Itx >= 0) return 1;
|
||||
else
|
||||
if (--Ity >= 0){
|
||||
IterImage -= ima->GetEffWidth();
|
||||
Itx = 0;
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::NextStep()
|
||||
{
|
||||
Itx += Stepx;
|
||||
if (Itx < (int32_t)ima->GetEffWidth()) return 1;
|
||||
else {
|
||||
Ity += Stepy;
|
||||
if (Ity < (int32_t)ima->GetHeight()){
|
||||
IterImage += ima->GetEffWidth();
|
||||
Itx = 0;
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::PrevStep()
|
||||
{
|
||||
Itx -= Stepx;
|
||||
if (Itx >= 0) return 1;
|
||||
else {
|
||||
Ity -= Stepy;
|
||||
if (Ity >= 0 && Ity < (int32_t)ima->GetHeight()) {
|
||||
IterImage -= ima->GetEffWidth();
|
||||
Itx = 0;
|
||||
return 1;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::GetCol(uint8_t* pCol, uint32_t x)
|
||||
{
|
||||
if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
|
||||
return 0;
|
||||
uint32_t h = ima->GetHeight();
|
||||
//uint32_t line = ima->GetEffWidth();
|
||||
uint8_t bytes = (uint8_t)(ima->GetBpp()>>3);
|
||||
uint8_t* pSrc;
|
||||
for (uint32_t y=0;y<h;y++){
|
||||
pSrc = ima->GetBits(y) + x*bytes;
|
||||
for (uint8_t w=0;w<bytes;w++){
|
||||
*pCol++=*pSrc++;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
inline BOOL CImageIterator::SetCol(uint8_t* pCol, uint32_t x)
|
||||
{
|
||||
if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth()))
|
||||
return 0;
|
||||
uint32_t h = ima->GetHeight();
|
||||
//uint32_t line = ima->GetEffWidth();
|
||||
uint8_t bytes = (uint8_t)(ima->GetBpp()>>3);
|
||||
uint8_t* pSrc;
|
||||
for (uint32_t y=0;y<h;y++){
|
||||
pSrc = ima->GetBits(y) + x*bytes;
|
||||
for (uint8_t w=0;w<bytes;w++){
|
||||
*pSrc++=*pCol++;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#endif
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* File: ximajas.h
|
||||
* Purpose: Jasper Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageJAS (c) 12/Apr/2003 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* based on JasPer Copyright (c) 2001-2003 Michael David Adams - All rights reserved.
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaJAS_h)
|
||||
#define __ximaJAS_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_JASPER
|
||||
|
||||
#ifdef _LINUX
|
||||
#include <jasper/jasper.h>
|
||||
#else
|
||||
#include "../jasper/include/jasper/jasper.h"
|
||||
#endif
|
||||
|
||||
class CxImageJAS: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageJAS(): CxImage((uint32_t)0) {} // <vho> cast to uint32_t
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,0);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,0);}
|
||||
bool Decode(CxFile * hFile, uint32_t imagetype = 0);
|
||||
bool Decode(FILE *hFile, uint32_t imagetype = 0) { CxIOFile file(hFile); return Decode(&file,imagetype); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile, uint32_t imagetype = 0);
|
||||
bool Encode(FILE *hFile, uint32_t imagetype = 0) { CxIOFile file(hFile); return Encode(&file,imagetype); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
|
||||
class CxFileJas
|
||||
{
|
||||
public:
|
||||
CxFileJas(CxFile* pFile,jas_stream_t *stream)
|
||||
{
|
||||
if (stream->obj_) jas_free(stream->obj_);
|
||||
stream->obj_ = pFile;
|
||||
|
||||
// <vho> - cannot set the stream->ops_->functions here,
|
||||
// because this overwrites a static structure in the Jasper library.
|
||||
// This structure is used by Jasper for internal operations too, e.g. tempfile.
|
||||
// However the ops_ pointer in the stream can be overwritten.
|
||||
|
||||
//stream->ops_->close_ = JasClose;
|
||||
//stream->ops_->read_ = JasRead;
|
||||
//stream->ops_->seek_ = JasSeek;
|
||||
//stream->ops_->write_ = JasWrite;
|
||||
|
||||
jas_stream_CxFile.close_ = JasClose;
|
||||
jas_stream_CxFile.read_ = JasRead;
|
||||
jas_stream_CxFile.seek_ = JasSeek;
|
||||
jas_stream_CxFile.write_ = JasWrite;
|
||||
|
||||
stream->ops_ = &jas_stream_CxFile;
|
||||
|
||||
// <vho> - end
|
||||
}
|
||||
static int32_t JasRead(jas_stream_obj_t *obj, char *buf, int32_t cnt)
|
||||
{ return ((CxFile*)obj)->Read(buf,1,cnt); }
|
||||
static int32_t JasWrite(jas_stream_obj_t *obj, char *buf, int32_t cnt)
|
||||
{ return ((CxFile*)obj)->Write(buf,1,cnt); }
|
||||
static long JasSeek(jas_stream_obj_t *obj, long offset, int32_t origin)
|
||||
{ return ((CxFile*)obj)->Seek(offset,origin); }
|
||||
static int32_t JasClose(jas_stream_obj_t * /*obj*/)
|
||||
{ return 1; }
|
||||
|
||||
// <vho>
|
||||
private:
|
||||
jas_stream_ops_t jas_stream_CxFile;
|
||||
// <vho> - end
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* File: ximajbg.h
|
||||
* Purpose: JBG Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageJBG (c) 18/Aug/2002 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* based on LIBJBG Copyright (c) 2002, Markus Kuhn - All rights reserved.
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaJBG_h)
|
||||
#define __ximaJBG_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_JBG
|
||||
|
||||
extern "C" {
|
||||
#include "../jbig/jbig.h"
|
||||
};
|
||||
|
||||
class CxImageJBG: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageJBG(): CxImage(CXIMAGE_FORMAT_JBG) {}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JBG);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JBG);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
static void jbig_data_out(uint8_t *buffer, uint32_t len, void *file)
|
||||
{((CxFile*)file)->Write(buffer,len,1);}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* File: ximajpg.h
|
||||
* Purpose: JPG Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageJPG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
|
||||
*
|
||||
* Special thanks to Chris Shearer Cooper for CxFileJpg tips & code
|
||||
*
|
||||
* EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>
|
||||
*
|
||||
* original CImageJPG and CImageIterator implementation are:
|
||||
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
|
||||
*
|
||||
* This software is based in part on the work of the Independent JPEG Group.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaJPEG_h)
|
||||
#define __ximaJPEG_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_JPG
|
||||
|
||||
#define CXIMAGEJPG_SUPPORT_EXIF CXIMAGE_SUPPORT_EXIF
|
||||
|
||||
extern "C" {
|
||||
#ifdef _LINUX
|
||||
#include <jpeglib.h>
|
||||
#include <jerror.h>
|
||||
#else
|
||||
#include "../jpeg/jpeglib.h"
|
||||
#include "../jpeg/jerror.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
class DLL_EXP CxImageJPG: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageJPG();
|
||||
~CxImageJPG();
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_JPG);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_JPG);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
/*
|
||||
* EXIF support based on jhead-1.8 by Matthias Wandel <mwandel(at)rim(dot)net>
|
||||
*/
|
||||
|
||||
#if CXIMAGEJPG_SUPPORT_EXIF
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// JPEG markers consist of one or more 0xFF bytes, followed by a marker
|
||||
// code byte (which is not an FF). Here are the marker codes of interest
|
||||
// in this program. (See jdmarker.c for a more complete list.)
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
#define M_SOF0 0xC0 // Start Of Frame N
|
||||
#define M_SOF1 0xC1 // N indicates which compression process
|
||||
#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use
|
||||
#define M_SOF3 0xC3
|
||||
#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers
|
||||
#define M_SOF6 0xC6
|
||||
#define M_SOF7 0xC7
|
||||
#define M_SOF9 0xC9
|
||||
#define M_SOF10 0xCA
|
||||
#define M_SOF11 0xCB
|
||||
#define M_SOF13 0xCD
|
||||
#define M_SOF14 0xCE
|
||||
#define M_SOF15 0xCF
|
||||
#define M_SOI 0xD8 // Start Of Image (beginning of datastream)
|
||||
#define M_EOI 0xD9 // End Of Image (end of datastream)
|
||||
#define M_SOS 0xDA // Start Of Scan (begins compressed data)
|
||||
#define M_JFIF 0xE0 // Jfif marker
|
||||
#define M_EXIF 0xE1 // Exif marker
|
||||
#define M_COM 0xFE // COMment
|
||||
|
||||
#define PSEUDO_IMAGE_MARKER 0x123; // Extra value.
|
||||
|
||||
#define EXIF_READ_EXIF 0x01
|
||||
#define EXIF_READ_IMAGE 0x02
|
||||
#define EXIF_READ_ALL 0x03
|
||||
|
||||
class DLL_EXP CxExifInfo
|
||||
{
|
||||
|
||||
typedef struct tag_Section_t{
|
||||
uint8_t* Data;
|
||||
int32_t Type;
|
||||
unsigned Size;
|
||||
} Section_t;
|
||||
|
||||
public:
|
||||
EXIFINFO* m_exifinfo;
|
||||
char m_szLastError[256];
|
||||
CxExifInfo(EXIFINFO* info = NULL);
|
||||
~CxExifInfo();
|
||||
bool DecodeExif(CxFile * hFile, int32_t nReadMode = EXIF_READ_EXIF);
|
||||
bool EncodeExif(CxFile * hFile);
|
||||
void DiscardAllButExif();
|
||||
protected:
|
||||
bool process_EXIF(uint8_t * CharBuf, uint32_t length);
|
||||
void process_COM (const uint8_t * Data, int32_t length);
|
||||
void process_SOFn (const uint8_t * Data, int32_t marker);
|
||||
int32_t Get16u(void * Short);
|
||||
int32_t Get16m(void * Short);
|
||||
int32_t Get32s(void * Long);
|
||||
uint32_t Get32u(void * Long);
|
||||
double ConvertAnyFormat(void * ValuePtr, int32_t Format);
|
||||
void* FindSection(int32_t SectionType);
|
||||
bool ProcessExifDir(uint8_t * DirStart, uint8_t * OffsetBase, unsigned ExifLength,
|
||||
EXIFINFO * const pInfo, uint8_t ** const LastExifRefdP, int32_t NestingLevel=0);
|
||||
int32_t ExifImageWidth;
|
||||
int32_t MotorolaOrder;
|
||||
Section_t Sections[MAX_SECTIONS];
|
||||
int32_t SectionsRead;
|
||||
bool freeinfo;
|
||||
};
|
||||
|
||||
CxExifInfo* m_exif;
|
||||
bool DecodeExif(CxFile * hFile);
|
||||
bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); }
|
||||
bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t type);
|
||||
|
||||
#endif //CXIMAGEJPG_SUPPORT_EXIF
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// C x F i l e J p g ////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// thanks to Chris Shearer Cooper <cscooper(at)frii(dot)com>
|
||||
class CxFileJpg : public jpeg_destination_mgr, public jpeg_source_mgr
|
||||
{
|
||||
public:
|
||||
enum { eBufSize = 4096 };
|
||||
|
||||
CxFileJpg(CxFile* pFile)
|
||||
{
|
||||
m_pFile = pFile;
|
||||
|
||||
init_destination = InitDestination;
|
||||
empty_output_buffer = EmptyOutputBuffer;
|
||||
term_destination = TermDestination;
|
||||
|
||||
init_source = InitSource;
|
||||
fill_input_buffer = FillInputBuffer;
|
||||
skip_input_data = SkipInputData;
|
||||
resync_to_restart = jpeg_resync_to_restart; // use default method
|
||||
term_source = TermSource;
|
||||
next_input_byte = NULL; //* => next byte to read from buffer
|
||||
bytes_in_buffer = 0; //* # of bytes remaining in buffer
|
||||
|
||||
m_pBuffer = new uint8_t[eBufSize];
|
||||
}
|
||||
~CxFileJpg()
|
||||
{
|
||||
delete [] m_pBuffer;
|
||||
}
|
||||
|
||||
static void InitDestination(j_compress_ptr cinfo)
|
||||
{
|
||||
CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
|
||||
pDest->next_output_byte = pDest->m_pBuffer;
|
||||
pDest->free_in_buffer = eBufSize;
|
||||
}
|
||||
|
||||
static boolean EmptyOutputBuffer(j_compress_ptr cinfo)
|
||||
{
|
||||
CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
|
||||
if (pDest->m_pFile->Write(pDest->m_pBuffer,1,eBufSize)!=(size_t)eBufSize)
|
||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
pDest->next_output_byte = pDest->m_pBuffer;
|
||||
pDest->free_in_buffer = eBufSize;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void TermDestination(j_compress_ptr cinfo)
|
||||
{
|
||||
CxFileJpg* pDest = (CxFileJpg*)cinfo->dest;
|
||||
size_t datacount = eBufSize - pDest->free_in_buffer;
|
||||
/* Write any data remaining in the buffer */
|
||||
if (datacount > 0) {
|
||||
if (!pDest->m_pFile->Write(pDest->m_pBuffer,1,datacount))
|
||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
}
|
||||
pDest->m_pFile->Flush();
|
||||
/* Make sure we wrote the output file OK */
|
||||
if (pDest->m_pFile->Error()) ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
return;
|
||||
}
|
||||
|
||||
static void InitSource(j_decompress_ptr cinfo)
|
||||
{
|
||||
CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
|
||||
pSource->m_bStartOfFile = TRUE;
|
||||
}
|
||||
|
||||
static boolean FillInputBuffer(j_decompress_ptr cinfo)
|
||||
{
|
||||
size_t nbytes;
|
||||
CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
|
||||
nbytes = pSource->m_pFile->Read(pSource->m_pBuffer,1,eBufSize);
|
||||
if (nbytes <= 0){
|
||||
if (pSource->m_bStartOfFile) //* Treat empty input file as fatal error
|
||||
ERREXIT(cinfo, JERR_INPUT_EMPTY);
|
||||
WARNMS(cinfo, JWRN_JPEG_EOF);
|
||||
// Insert a fake EOI marker
|
||||
pSource->m_pBuffer[0] = (JOCTET) 0xFF;
|
||||
pSource->m_pBuffer[1] = (JOCTET) JPEG_EOI;
|
||||
nbytes = 2;
|
||||
}
|
||||
pSource->next_input_byte = pSource->m_pBuffer;
|
||||
pSource->bytes_in_buffer = nbytes;
|
||||
pSource->m_bStartOfFile = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void SkipInputData(j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
CxFileJpg* pSource = (CxFileJpg*)cinfo->src;
|
||||
if (num_bytes > 0){
|
||||
while (num_bytes > (int32_t)pSource->bytes_in_buffer){
|
||||
num_bytes -= (int32_t)pSource->bytes_in_buffer;
|
||||
FillInputBuffer(cinfo);
|
||||
// note we assume that fill_input_buffer will never return FALSE,
|
||||
// so suspension need not be handled.
|
||||
}
|
||||
pSource->next_input_byte += (size_t) num_bytes;
|
||||
pSource->bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
static void TermSource(j_decompress_ptr /*cinfo*/)
|
||||
{
|
||||
return;
|
||||
}
|
||||
protected:
|
||||
CxFile *m_pFile;
|
||||
uint8_t *m_pBuffer;
|
||||
bool m_bStartOfFile;
|
||||
};
|
||||
|
||||
public:
|
||||
enum CODEC_OPTION
|
||||
{
|
||||
ENCODE_BASELINE = 0x1,
|
||||
ENCODE_ARITHMETIC = 0x2,
|
||||
ENCODE_GRAYSCALE = 0x4,
|
||||
ENCODE_OPTIMIZE = 0x8,
|
||||
ENCODE_PROGRESSIVE = 0x10,
|
||||
ENCODE_LOSSLESS = 0x20,
|
||||
ENCODE_SMOOTHING = 0x40,
|
||||
DECODE_GRAYSCALE = 0x80,
|
||||
DECODE_QUANTIZE = 0x100,
|
||||
DECODE_DITHER = 0x200,
|
||||
DECODE_ONEPASS = 0x400,
|
||||
DECODE_NOSMOOTH = 0x800,
|
||||
ENCODE_SUBSAMPLE_422 = 0x1000,
|
||||
ENCODE_SUBSAMPLE_444 = 0x2000
|
||||
};
|
||||
|
||||
int32_t m_nPredictor;
|
||||
int32_t m_nPointTransform;
|
||||
int32_t m_nSmoothing;
|
||||
int32_t m_nQuantize;
|
||||
J_DITHER_MODE m_nDither;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* File: ximamng.h
|
||||
* Purpose: Declaration of the MNG Image Class
|
||||
* Author: Davide Pizzolato - www.xdp.it
|
||||
* Created: 2001
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageMNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Frank Haug <f.haug(at)jdm(dot)de> for suggestions and code.
|
||||
*
|
||||
* original mng.cpp code created by Nikolaus Brennig, November 14th, 2000. <virtualnik(at)nol(dot)at>
|
||||
*
|
||||
* LIBMNG Copyright (c) 2000,2001 Gerard Juyn (gerard@libmng.com)
|
||||
* ==========================================================
|
||||
*/
|
||||
|
||||
#if !defined(__ximaMNG_h)
|
||||
#define __ximaMNG_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_MNG
|
||||
|
||||
//#define MNG_NO_CMS
|
||||
#define MNG_SUPPORT_DISPLAY
|
||||
#define MNG_SUPPORT_READ
|
||||
#define MNG_SUPPORT_WRITE
|
||||
#define MNG_ACCESS_CHUNKS
|
||||
#define MNG_STORE_CHUNKS
|
||||
|
||||
extern "C" {
|
||||
#include "../mng/libmng.h"
|
||||
#include "../mng/libmng_data.h"
|
||||
#include "../mng/libmng_error.h"
|
||||
}
|
||||
|
||||
//uint32_t _stdcall RunMNGThread(void *lpParam);
|
||||
|
||||
typedef struct tagmngstuff
|
||||
{
|
||||
CxFile *file;
|
||||
uint8_t *image;
|
||||
uint8_t *alpha;
|
||||
HANDLE thread;
|
||||
mng_uint32 delay;
|
||||
mng_uint32 width;
|
||||
mng_uint32 height;
|
||||
mng_uint32 effwdt;
|
||||
mng_int16 bpp;
|
||||
mng_bool animation;
|
||||
mng_bool animation_enabled;
|
||||
float speed;
|
||||
int32_t nBkgndIndex;
|
||||
RGBQUAD nBkgndColor;
|
||||
} mngstuff;
|
||||
|
||||
class CxImageMNG: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageMNG();
|
||||
~CxImageMNG();
|
||||
|
||||
bool Load(const TCHAR * imageFileName);
|
||||
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_MNG);}
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
int32_t Resume();
|
||||
void SetSpeed(float speed);
|
||||
|
||||
mng_handle hmng;
|
||||
mngstuff mnginfo;
|
||||
protected:
|
||||
void WritePNG(mng_handle hMNG, int32_t Frame, int32_t FrameCount );
|
||||
void SetCallbacks(mng_handle mng);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* File: ximapcx.h
|
||||
* Purpose: PCX Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImagePCX (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Parts of the code come from Paintlib: Copyright (c) 1996-1998 Ulrich von Zadow
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaPCX_h)
|
||||
#define __ximaPCX_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_PCX
|
||||
|
||||
class CxImagePCX: public CxImage
|
||||
{
|
||||
// PCX Image File
|
||||
#pragma pack(1)
|
||||
typedef struct tagPCXHEADER
|
||||
{
|
||||
char Manufacturer; // always 0X0A
|
||||
char Version; // version number
|
||||
char Encoding; // always 1
|
||||
char BitsPerPixel; // color bits
|
||||
uint16_t Xmin, Ymin; // image origin
|
||||
uint16_t Xmax, Ymax; // image dimensions
|
||||
uint16_t Hres, Vres; // resolution values
|
||||
uint8_t ColorMap[16][3]; // color palette
|
||||
char Reserved;
|
||||
char ColorPlanes; // color planes
|
||||
uint16_t BytesPerLine; // line buffer size
|
||||
uint16_t PaletteType; // grey or color palette
|
||||
char Filter[58];
|
||||
} PCXHEADER;
|
||||
#pragma pack()
|
||||
|
||||
public:
|
||||
CxImagePCX(): CxImage(CXIMAGE_FORMAT_PCX) {}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PCX);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PCX);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
bool PCX_PlanesToPixels(uint8_t * pixels, uint8_t * bitplanes, int16_t bytesperline, int16_t planes, int16_t bitsperpixel);
|
||||
bool PCX_UnpackPixels(uint8_t * pixels, uint8_t * bitplanes, int16_t bytesperline, int16_t planes, int16_t bitsperpixel);
|
||||
void PCX_PackPixels(const int32_t p,uint8_t &c, uint8_t &n, CxFile &f);
|
||||
void PCX_PackPlanes(uint8_t* buff, const int32_t size, CxFile &f);
|
||||
void PCX_PixelsToPlanes(uint8_t* raw, int32_t width, uint8_t* buf, int32_t plane);
|
||||
void PCX_toh(PCXHEADER* p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* File: ximapng.h
|
||||
* Purpose: PNG Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
|
||||
*
|
||||
* original CImagePNG and CImageIterator implementation are:
|
||||
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
|
||||
*
|
||||
* libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaPNG_h)
|
||||
#define __ximaPNG_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_PNG
|
||||
|
||||
extern "C" {
|
||||
#ifdef _LINUX
|
||||
#undef _DLL
|
||||
#include <png.h>
|
||||
#include <pngstruct.h>
|
||||
#include <pnginfo.h>
|
||||
#else
|
||||
#include "../png/png.h"
|
||||
#include "../png/pngstruct.h"
|
||||
#include "../png/pnginfo.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
class CxImagePNG: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
enum CODEC_OPTION
|
||||
{
|
||||
ENCODE_INTERLACE = 0x01,
|
||||
// Exclusive compression types : 3 bit wide field
|
||||
ENCODE_COMPRESSION_MASK = 0x0E,
|
||||
ENCODE_NO_COMPRESSION = 1 << 1,
|
||||
ENCODE_BEST_SPEED = 2 << 1,
|
||||
ENCODE_BEST_COMPRESSION = 3 << 1,
|
||||
ENCODE_DEFAULT_COMPRESSION = 4 << 1
|
||||
};
|
||||
|
||||
protected:
|
||||
void ima_png_error(png_struct *png_ptr, char *message);
|
||||
void expand2to4bpp(uint8_t* prow);
|
||||
|
||||
static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
|
||||
if (hFile == NULL || hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");
|
||||
}
|
||||
|
||||
static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
|
||||
if (hFile == NULL || hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");
|
||||
}
|
||||
|
||||
static void PNGAPI user_flush_data(png_structp png_ptr)
|
||||
{
|
||||
CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
|
||||
if (hFile == NULL || !hFile->Flush()) png_error(png_ptr, "Flush Error");
|
||||
}
|
||||
|
||||
static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg)
|
||||
{
|
||||
strncpy((char*)png_ptr->error_ptr,error_msg,255);
|
||||
longjmp(png_ptr->png_jmpbuf, 1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* File: ximapsd.h
|
||||
* Purpose: PSD Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImagePSD (c) Dec/2010
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* libpsd (c) 2004-2007 Graphest Software
|
||||
*
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaPSD_h)
|
||||
#define __ximaPSD_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_PSD
|
||||
|
||||
#define CXIMAGE_USE_LIBPSD 1
|
||||
|
||||
#if CXIMAGE_USE_LIBPSD
|
||||
extern "C" {
|
||||
#include "../libpsd/libpsd.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
class CxImagePSD: public CxImage
|
||||
{
|
||||
|
||||
public:
|
||||
CxImagePSD(): CxImage(CXIMAGE_FORMAT_PSD) {}
|
||||
|
||||
// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PSD);}
|
||||
// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PSD);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
//#if CXIMAGE_SUPPORT_EXIF
|
||||
// bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t type);
|
||||
//#endif //CXIMAGE_SUPPORT_EXIF
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
#if CXIMAGE_USE_LIBPSD
|
||||
protected:
|
||||
class CxFilePsd
|
||||
{
|
||||
public:
|
||||
CxFilePsd(CxFile* pFile,psd_context *context)
|
||||
{
|
||||
context->file = pFile;
|
||||
|
||||
psd_CxFile_ops.size_ = psd_file_size;
|
||||
psd_CxFile_ops.seek_ = psd_file_seek;
|
||||
psd_CxFile_ops.read_ = psd_file_read;
|
||||
// psd_CxFile_ops.write_ = psd_file_write;
|
||||
// psd_CxFile_ops.close_ = psd_file_close;
|
||||
// psd_CxFile_ops.gets_ = psd_file_gets;
|
||||
// psd_CxFile_ops.eof_ = psd_file_eof;
|
||||
// psd_CxFile_ops.tell_ = psd_file_tell;
|
||||
// psd_CxFile_ops.getc_ = psd_file_getc;
|
||||
// psd_CxFile_ops.scanf_ = psd_file_scanf;
|
||||
|
||||
context->ops_ = &psd_CxFile_ops;
|
||||
|
||||
}
|
||||
|
||||
static int32_t psd_file_size(psd_file_obj *obj)
|
||||
{ return ((CxFile*)obj)->Size(); }
|
||||
|
||||
static int32_t psd_file_seek(psd_file_obj *obj, int32_t offset, int32_t origin)
|
||||
{ return ((CxFile*)obj)->Seek(offset,origin); }
|
||||
|
||||
static int32_t psd_file_read(psd_file_obj *obj, void *buf, int32_t size, int32_t cnt)
|
||||
{ return ((CxFile*)obj)->Read(buf,size,cnt); }
|
||||
|
||||
// static int32_t psd_file_write(psd_file_obj *obj, void *buf, int32_t size, int32_t cnt)
|
||||
// { return ((CxFile*)obj)->Write(buf,size,cnt); }
|
||||
|
||||
// static int32_t psd_file_close(psd_file_obj *obj)
|
||||
// { return 1; /*((CxFile*)obj)->Close();*/ }
|
||||
|
||||
// static char* psd_file_gets(psd_file_obj *obj, char *string, int32_t n)
|
||||
// { return ((CxFile*)obj)->GetS(string,n); }
|
||||
|
||||
// static int32_t psd_file_eof(psd_file_obj *obj)
|
||||
// { return ((CxFile*)obj)->Eof(); }
|
||||
|
||||
// static long psd_file_tell(psd_file_obj *obj)
|
||||
// { return ((CxFile*)obj)->Tell(); }
|
||||
|
||||
// static int32_t psd_file_getc(psd_file_obj *obj)
|
||||
// { return ((CxFile*)obj)->GetC(); }
|
||||
|
||||
// static int32_t psd_file_scanf(psd_file_obj *obj,const char *format, void* output)
|
||||
// { return ((CxFile*)obj)->Scanf(format, output); }
|
||||
|
||||
private:
|
||||
psd_file_ops psd_CxFile_ops;
|
||||
};
|
||||
#endif //CXIMAGE_USE_LIBPSD
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* File: ximaraw.h
|
||||
* Purpose: RAW Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageRAW (c) May/2006 pdw63
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
* Special thanks to David Coffin for dcraw without which this class would not exist
|
||||
*
|
||||
* libdcr (c) Dec/2007 Davide Pizzolato - www.xdp.it
|
||||
*
|
||||
* based on dcraw.c -- Dave Coffin's raw photo decoder
|
||||
* Copyright 1997-2007 by Dave Coffin, dcoffin a cybercom o net
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaRAW_h)
|
||||
#define __ximaRAW_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_RAW
|
||||
|
||||
extern "C" {
|
||||
#include "../raw/libdcr.h"
|
||||
}
|
||||
|
||||
class CxImageRAW: public CxImage
|
||||
{
|
||||
|
||||
public:
|
||||
CxImageRAW(): CxImage(CXIMAGE_FORMAT_RAW) {}
|
||||
|
||||
// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_EXIF
|
||||
bool GetExifThumbnail(const TCHAR *filename, const TCHAR *outname, int32_t type);
|
||||
#endif //CXIMAGE_SUPPORT_EXIF
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
enum CODEC_OPTION
|
||||
{
|
||||
DECODE_QUALITY_LIN = 0x00,
|
||||
DECODE_QUALITY_VNG = 0x01,
|
||||
DECODE_QUALITY_PPG = 0x02,
|
||||
DECODE_QUALITY_AHD = 0x03,
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
class CxFileRaw
|
||||
{
|
||||
public:
|
||||
CxFileRaw(CxFile* pFile,DCRAW *stream)
|
||||
{
|
||||
stream->obj_ = pFile;
|
||||
|
||||
ras_stream_CxFile.read_ = raw_sfile_read;
|
||||
ras_stream_CxFile.write_ = raw_sfile_write;
|
||||
ras_stream_CxFile.seek_ = raw_sfile_seek;
|
||||
ras_stream_CxFile.close_ = raw_sfile_close;
|
||||
ras_stream_CxFile.gets_ = raw_sfile_gets;
|
||||
ras_stream_CxFile.eof_ = raw_sfile_eof;
|
||||
ras_stream_CxFile.tell_ = raw_sfile_tell;
|
||||
ras_stream_CxFile.getc_ = raw_sfile_getc;
|
||||
ras_stream_CxFile.scanf_ = raw_sfile_scanf;
|
||||
|
||||
stream->ops_ = &ras_stream_CxFile;
|
||||
|
||||
}
|
||||
|
||||
static int32_t raw_sfile_read(dcr_stream_obj *obj, void *buf, int32_t size, int32_t cnt)
|
||||
{ return ((CxFile*)obj)->Read(buf,size,cnt); }
|
||||
|
||||
static int32_t raw_sfile_write(dcr_stream_obj *obj, void *buf, int32_t size, int32_t cnt)
|
||||
{ return ((CxFile*)obj)->Write(buf,size,cnt); }
|
||||
|
||||
static long raw_sfile_seek(dcr_stream_obj *obj, long offset, int32_t origin)
|
||||
{ return ((CxFile*)obj)->Seek(offset,origin); }
|
||||
|
||||
static int32_t raw_sfile_close(dcr_stream_obj *obj)
|
||||
{ return 1; /*((CxFile*)obj)->Close();*/ }
|
||||
|
||||
static char* raw_sfile_gets(dcr_stream_obj *obj, char *string, int32_t n)
|
||||
{ return ((CxFile*)obj)->GetS(string,n); }
|
||||
|
||||
static int32_t raw_sfile_eof(dcr_stream_obj *obj)
|
||||
{ return ((CxFile*)obj)->Eof(); }
|
||||
|
||||
static long raw_sfile_tell(dcr_stream_obj *obj)
|
||||
{ return ((CxFile*)obj)->Tell(); }
|
||||
|
||||
static int32_t raw_sfile_getc(dcr_stream_obj *obj)
|
||||
{ return ((CxFile*)obj)->GetC(); }
|
||||
|
||||
static int32_t raw_sfile_scanf(dcr_stream_obj *obj,const char *format, void* output)
|
||||
{ return ((CxFile*)obj)->Scanf(format, output); }
|
||||
|
||||
private:
|
||||
dcr_stream_ops ras_stream_CxFile;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* File: ximaska.h
|
||||
* Purpose: SKA Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageSKA (c) 25/Sep/2007 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaSKA_h)
|
||||
#define __ximaSKA_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_SKA
|
||||
|
||||
class CxImageSKA: public CxImage
|
||||
{
|
||||
#pragma pack(1)
|
||||
typedef struct tagSkaHeader {
|
||||
uint16_t Width;
|
||||
uint16_t Height;
|
||||
uint8_t BppExp;
|
||||
uint32_t dwUnknown;
|
||||
} SKAHEADER;
|
||||
#pragma pack()
|
||||
|
||||
public:
|
||||
CxImageSKA(): CxImage(CXIMAGE_FORMAT_SKA) {}
|
||||
|
||||
// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_ICO);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* File: ximatga.h
|
||||
* Purpose: TARGA Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageTGA (c) 05/Jan/2002 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Parts of the code come from Paintlib : Copyright (c) 1996-1998 Ulrich von Zadow
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaTGA_h)
|
||||
#define __ximaTGA_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_TGA
|
||||
|
||||
class CxImageTGA: public CxImage
|
||||
{
|
||||
#pragma pack(1)
|
||||
typedef struct tagTgaHeader
|
||||
{
|
||||
uint8_t IdLength; // Image ID Field Length
|
||||
uint8_t CmapType; // Color Map Type
|
||||
uint8_t ImageType; // Image Type
|
||||
|
||||
uint16_t CmapIndex; // First Entry Index
|
||||
uint16_t CmapLength; // Color Map Length
|
||||
uint8_t CmapEntrySize; // Color Map Entry Size
|
||||
|
||||
uint16_t X_Origin; // X-origin of Image
|
||||
uint16_t Y_Origin; // Y-origin of Image
|
||||
uint16_t ImageWidth; // Image Width
|
||||
uint16_t ImageHeight; // Image Height
|
||||
uint8_t PixelDepth; // Pixel Depth
|
||||
uint8_t ImagDesc; // Image Descriptor
|
||||
} TGAHEADER;
|
||||
#pragma pack()
|
||||
|
||||
public:
|
||||
CxImageTGA(): CxImage(CXIMAGE_FORMAT_TGA) {}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TGA);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TGA);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
protected:
|
||||
uint8_t ExpandCompressedLine(uint8_t* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int32_t width, int32_t y, uint8_t rleLeftover);
|
||||
void ExpandUncompressedLine(uint8_t* pDest,TGAHEADER* ptgaHead,CxFile *hFile,int32_t width, int32_t y, int32_t xoffset);
|
||||
void tga_toh(TGAHEADER* p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,39 @@
|
|||
#if !defined(__ximath_h)
|
||||
#define __ximath_h
|
||||
|
||||
#include "ximadef.h"
|
||||
|
||||
//***bd*** simple floating point point
|
||||
class DLL_EXP CxPoint2
|
||||
{
|
||||
public:
|
||||
CxPoint2();
|
||||
CxPoint2(float const x_, float const y_);
|
||||
CxPoint2(CxPoint2 const &p);
|
||||
|
||||
float Distance(CxPoint2 const p2);
|
||||
float Distance(float const x_, float const y_);
|
||||
|
||||
float x,y;
|
||||
};
|
||||
|
||||
//and simple rectangle
|
||||
class DLL_EXP CxRect2
|
||||
{
|
||||
public:
|
||||
CxRect2();
|
||||
CxRect2(float const x1_, float const y1_, float const x2_, float const y2_);
|
||||
CxRect2(CxPoint2 const &bl, CxPoint2 const &tr);
|
||||
CxRect2(CxRect2 const &p);
|
||||
|
||||
float Surface() const;
|
||||
CxRect2 CrossSection(CxRect2 const &r2) const;
|
||||
CxPoint2 Center() const;
|
||||
float Width() const;
|
||||
float Height() const;
|
||||
|
||||
CxPoint2 botLeft;
|
||||
CxPoint2 topRight;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* File: ximatif.h
|
||||
* Purpose: TIFF Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageTIF (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
*
|
||||
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
|
||||
*
|
||||
* Special thanks to Abe <God(dot)bless(at)marihuana(dot)com> for MultiPageTIFF code.
|
||||
*
|
||||
* LibTIFF is:
|
||||
* Copyright (c) 1988-1997 Sam Leffler
|
||||
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
||||
* ==========================================================
|
||||
*/
|
||||
|
||||
#if !defined(__ximatif_h)
|
||||
#define __ximatif_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_TIF
|
||||
|
||||
#include "../tiff/tiffio.h"
|
||||
|
||||
class DLL_EXP CxImageTIF: public CxImage
|
||||
{
|
||||
public:
|
||||
CxImageTIF(): CxImage(CXIMAGE_FORMAT_TIF) {m_tif2=NULL; m_multipage=false; m_pages=0;}
|
||||
~CxImageTIF();
|
||||
|
||||
TIFF* TIFFOpenEx(CxFile * hFile);
|
||||
void TIFFCloseEx(TIFF* tif);
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_TIF);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_TIF);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile, bool bAppend=false);
|
||||
bool Encode(CxFile * hFile, CxImage ** pImages, int32_t pagecount);
|
||||
bool Encode(FILE *hFile, bool bAppend=false) { CxIOFile file(hFile); return Encode(&file,bAppend); }
|
||||
bool Encode(FILE *hFile, CxImage ** pImages, int32_t pagecount)
|
||||
{ CxIOFile file(hFile); return Encode(&file, pImages, pagecount); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
protected:
|
||||
void TileToStrip(uint8* out, uint8* in, uint32 rows, uint32 cols, int32_t outskew, int32_t inskew);
|
||||
bool EncodeBody(TIFF *m_tif, bool multipage=false, int32_t page=0, int32_t pagecount=0);
|
||||
TIFF *m_tif2;
|
||||
bool m_multipage;
|
||||
int32_t m_pages;
|
||||
void MoveBits( uint8_t* dest, uint8_t* from, int32_t count, int32_t bpp );
|
||||
void MoveBitsPal( uint8_t* dest, uint8_t*from, int32_t count, int32_t bpp, RGBQUAD* pal );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* File: ximawbmp.h
|
||||
* Purpose: WBMP Image Class Loader and Writer
|
||||
*/
|
||||
/* ==========================================================
|
||||
* CxImageWBMP (c) 12/Jul/2002 Davide Pizzolato - www.xdp.it
|
||||
* For conditions of distribution and use, see copyright notice in ximage.h
|
||||
* ==========================================================
|
||||
*/
|
||||
#if !defined(__ximaWBMP_h)
|
||||
#define __ximaWBMP_h
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_WBMP
|
||||
|
||||
class CxImageWBMP: public CxImage
|
||||
{
|
||||
#pragma pack(1)
|
||||
typedef struct tagWbmpHeader
|
||||
{
|
||||
uint32_t Type; // 0
|
||||
uint8_t FixHeader; // 0
|
||||
uint32_t ImageWidth; // Image Width
|
||||
uint32_t ImageHeight; // Image Height
|
||||
} WBMPHEADER;
|
||||
#pragma pack()
|
||||
public:
|
||||
CxImageWBMP(): CxImage(CXIMAGE_FORMAT_WBMP) {}
|
||||
|
||||
// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_WBMP);}
|
||||
// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_WBMP);}
|
||||
bool Decode(CxFile * hFile);
|
||||
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
|
||||
protected:
|
||||
bool ReadOctet(CxFile * hFile, uint32_t *data);
|
||||
|
||||
public:
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
protected:
|
||||
bool WriteOctet(CxFile * hFile, const uint32_t data);
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
*********************************************************************
|
||||
* File: ximawmf.h
|
||||
* Purpose: Windows Metafile Class Loader and Writer
|
||||
* Author: Volker Horch - vhorch@gmx.de
|
||||
* created: 13-Jun-2002
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*********************************************************************
|
||||
Notes by Author:
|
||||
*********************************************************************
|
||||
|
||||
Limitations:
|
||||
============
|
||||
|
||||
a) Transparency:
|
||||
|
||||
A Metafile is vector graphics, which has transparency by design.
|
||||
This class always converts into a Bitmap format. Transparency is
|
||||
supported, but there is no good way to find out, which parts
|
||||
of the Metafile are transparent. There are two ways how we can
|
||||
handle this:
|
||||
|
||||
- Clear the Background of the Bitmap with the background color
|
||||
you like (i have used COLOR_WINDOW) and don't support transparency.
|
||||
|
||||
below #define XMF_SUPPORT_TRANSPARENCY 0
|
||||
#define XMF_COLOR_BACK RGB(Background color you like)
|
||||
|
||||
- Clear the Background of the Bitmap with a very unusual color
|
||||
(which one ?) and use this color as the transparent color
|
||||
|
||||
below #define XMF_SUPPORT_TRANSPARENCY 1
|
||||
#define XMF_COLOR_TRANSPARENT_R ...
|
||||
#define XMF_COLOR_TRANSPARENT_G ...
|
||||
#define XMF_COLOR_TRANSPARENT_B ...
|
||||
|
||||
b) Resolution
|
||||
|
||||
Once we have converted the Metafile into a Bitmap and we zoom in
|
||||
or out, the image may not look very good. If we still had the
|
||||
original Metafile, zooming would produce good results always.
|
||||
|
||||
c) Size
|
||||
|
||||
Although the filesize of a Metafile may be very small, it might
|
||||
produce a Bitmap with a bombastic size. Assume you have a Metafile
|
||||
with an image size of 6000*4000, which contains just one Metafile
|
||||
record ((e.g. a line from (0,0) to (6000, 4000)). The filesize
|
||||
of this Metafile would be let's say 100kB. If we convert it to
|
||||
a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume
|
||||
about 68MB of memory.
|
||||
|
||||
I have choosen, to limit the size of the Bitmap to max.
|
||||
screensize, to avoid memory problems.
|
||||
|
||||
If you want something else,
|
||||
modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below
|
||||
|
||||
*********************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _XIMAWMF_H
|
||||
#define _XIMAWMF_H
|
||||
|
||||
#include "ximage.h"
|
||||
|
||||
#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
|
||||
|
||||
class CxImageWMF: public CxImage
|
||||
{
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct tagRECT16
|
||||
{
|
||||
int16_t left;
|
||||
int16_t top;
|
||||
int16_t right;
|
||||
int16_t bottom;
|
||||
} RECT16;
|
||||
|
||||
// taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)
|
||||
typedef struct tagMETAFILEHEADER
|
||||
{
|
||||
uint32_t key; // always 0x9ac6cdd7
|
||||
uint16_t reserved1; // reserved = 0
|
||||
RECT16 bbox; // bounding rectangle in metafile units as defined in "inch"
|
||||
uint16_t inch; // number of metafile units per inch (should be < 1440)
|
||||
uint32_t reserved2; // reserved = 0
|
||||
uint16_t checksum; // sum of the first 10 WORDS (using XOR operator)
|
||||
} METAFILEHEADER;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
public:
|
||||
CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }
|
||||
|
||||
bool Decode(CxFile * hFile, int32_t nForceWidth=0, int32_t nForceHeight=0);
|
||||
bool Decode(FILE *hFile, int32_t nForceWidth=0, int32_t nForceHeight=0)
|
||||
{ CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); }
|
||||
|
||||
#if CXIMAGE_SUPPORT_ENCODE
|
||||
bool Encode(CxFile * hFile);
|
||||
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
|
||||
#endif // CXIMAGE_SUPPORT_ENCODE
|
||||
|
||||
protected:
|
||||
void ShrinkMetafile(int32_t &cx, int32_t &cy);
|
||||
BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader);
|
||||
HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader);
|
||||
HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh);
|
||||
|
||||
};
|
||||
|
||||
#define METAFILEKEY 0x9ac6cdd7L
|
||||
|
||||
// Background color definition (if no transparency). see Notes above
|
||||
#define XMF_COLOR_BACK GetSysColor(COLOR_WINDOW)
|
||||
// alternatives
|
||||
//#define XMF_COLOR_BACK RGB(192, 192, 192) // lite gray
|
||||
//#define XMF_COLOR_BACK RGB( 0, 0, 0) // black
|
||||
//#define XMF_COLOR_BACK RGB(255, 255, 255) // white
|
||||
|
||||
|
||||
// transparency support. see Notes above
|
||||
#define XMF_SUPPORT_TRANSPARENCY 0
|
||||
#define XMF_COLOR_TRANSPARENT_R 211
|
||||
#define XMF_COLOR_TRANSPARENT_G 121
|
||||
#define XMF_COLOR_TRANSPARENT_B 112
|
||||
// don't change
|
||||
#define XMF_COLOR_TRANSPARENT RGB (XMF_COLOR_TRANSPARENT_R, \
|
||||
XMF_COLOR_TRANSPARENT_G, \
|
||||
XMF_COLOR_TRANSPARENT_B)
|
||||
// don't change
|
||||
#define XMF_RGBQUAD_TRANSPARENT XMF_COLOR_TRANSPARENT_B, \
|
||||
XMF_COLOR_TRANSPARENT_G, \
|
||||
XMF_COLOR_TRANSPARENT_R, \
|
||||
0
|
||||
// max. size. see Notes above
|
||||
// alternatives
|
||||
//#define XMF_MAXSIZE_CX (GetSystemMetrics(SM_CXSCREEN)-10)
|
||||
//#define XMF_MAXSIZE_CY (GetSystemMetrics(SM_CYSCREEN)-50)
|
||||
//#define XMF_MAXSIZE_CX (2*GetSystemMetrics(SM_CXSCREEN)/3)
|
||||
//#define XMF_MAXSIZE_CY (2*GetSystemMetrics(SM_CYSCREEN)/3)
|
||||
#define XMF_MAXSIZE_CX 4000
|
||||
#define XMF_MAXSIZE_CY 4000
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,125 @@
|
|||
#if !defined(__xiofile_h)
|
||||
#define __xiofile_h
|
||||
|
||||
#include "xfile.h"
|
||||
//#include <TCHAR.h>
|
||||
|
||||
class DLL_EXP CxIOFile : public CxFile
|
||||
{
|
||||
public:
|
||||
CxIOFile(FILE* fp = NULL)
|
||||
{
|
||||
m_fp = fp;
|
||||
m_bCloseFile = (bool)(fp==0);
|
||||
}
|
||||
|
||||
~CxIOFile()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
bool Open(const TCHAR * filename, const TCHAR * mode)
|
||||
{
|
||||
if (m_fp) return false; // Can't re-open without closing first
|
||||
|
||||
m_fp = _tfopen(filename, mode);
|
||||
if (!m_fp) return false;
|
||||
|
||||
m_bCloseFile = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual bool Close()
|
||||
{
|
||||
int32_t iErr = 0;
|
||||
if ( (m_fp) && (m_bCloseFile) ){
|
||||
iErr = fclose(m_fp);
|
||||
m_fp = NULL;
|
||||
}
|
||||
return (bool)(iErr==0);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual size_t Read(void *buffer, size_t size, size_t count)
|
||||
{
|
||||
if (!m_fp) return 0;
|
||||
return fread(buffer, size, count, m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual size_t Write(const void *buffer, size_t size, size_t count)
|
||||
{
|
||||
if (!m_fp) return 0;
|
||||
return fwrite(buffer, size, count, m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual bool Seek(int32_t offset, int32_t origin)
|
||||
{
|
||||
if (!m_fp) return false;
|
||||
return (bool)(fseek(m_fp, offset, origin) == 0);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual int32_t Tell()
|
||||
{
|
||||
if (!m_fp) return 0;
|
||||
return ftell(m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual int32_t Size()
|
||||
{
|
||||
if (!m_fp) return -1;
|
||||
int32_t pos,size;
|
||||
pos = ftell(m_fp);
|
||||
fseek(m_fp, 0, SEEK_END);
|
||||
size = ftell(m_fp);
|
||||
fseek(m_fp, pos,SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual bool Flush()
|
||||
{
|
||||
if (!m_fp) return false;
|
||||
return (bool)(fflush(m_fp) == 0);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual bool Eof()
|
||||
{
|
||||
if (!m_fp) return true;
|
||||
return (bool)(feof(m_fp) != 0);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual int32_t Error()
|
||||
{
|
||||
if (!m_fp) return -1;
|
||||
return ferror(m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual bool PutC(uint8_t c)
|
||||
{
|
||||
if (!m_fp) return false;
|
||||
return (bool)(fputc(c, m_fp) == c);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual int32_t GetC()
|
||||
{
|
||||
if (!m_fp) return EOF;
|
||||
return getc(m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual char * GetS(char *string, int32_t n)
|
||||
{
|
||||
if (!m_fp) return NULL;
|
||||
return fgets(string,n,m_fp);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
virtual int32_t Scanf(const char *format, void* output)
|
||||
{
|
||||
if (!m_fp) return EOF;
|
||||
return fscanf(m_fp, format, output);
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
protected:
|
||||
FILE *m_fp;
|
||||
bool m_bCloseFile;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
#if !defined(__xmemfile_h)
|
||||
#define __xmemfile_h
|
||||
|
||||
#include "xfile.h"
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
class DLL_EXP CxMemFile : public CxFile
|
||||
{
|
||||
public:
|
||||
CxMemFile(uint8_t* pBuffer = NULL, uint32_t size = 0);
|
||||
~CxMemFile();
|
||||
|
||||
bool Open();
|
||||
uint8_t* GetBuffer(bool bDetachBuffer = true);
|
||||
|
||||
virtual bool Close();
|
||||
virtual size_t Read(void *buffer, size_t size, size_t count);
|
||||
virtual size_t Write(const void *buffer, size_t size, size_t count);
|
||||
virtual bool Seek(int32_t offset, int32_t origin);
|
||||
virtual int32_t Tell();
|
||||
virtual int32_t Size();
|
||||
virtual bool Flush();
|
||||
virtual bool Eof();
|
||||
virtual int32_t Error();
|
||||
virtual bool PutC(uint8_t c);
|
||||
virtual int32_t GetC();
|
||||
virtual char * GetS(char *string, int32_t n);
|
||||
virtual int32_t Scanf(const char *format, void* output);
|
||||
|
||||
protected:
|
||||
bool Alloc(uint32_t nBytes);
|
||||
void Free();
|
||||
|
||||
uint8_t* m_pBuffer;
|
||||
uint32_t m_Size;
|
||||
bool m_bFreeOnClose;
|
||||
int32_t m_Position; //current position
|
||||
int32_t m_Edge; //buffer size
|
||||
bool m_bEOF;
|
||||
};
|
||||
|
||||
#endif
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue