diff --git a/CMakeLists.txt b/CMakeLists.txt index 07d6ee477f9..750c006e7bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -245,9 +245,6 @@ if (NOT WIN32) find_package(GLEW REQUIRED) find_package(OpenAL REQUIRED) find_package(JPEG) - if (JPEG_FOUND) - set(USE_CXIMAGE TRUE) - endif() find_package(Ogg REQUIRED) find_package(Vorbis REQUIRED) find_package(Theora REQUIRED) diff --git a/Externals/CMakeLists.txt b/Externals/CMakeLists.txt index a634c9b4c70..2e9d979b018 100644 --- a/Externals/CMakeLists.txt +++ b/Externals/CMakeLists.txt @@ -6,11 +6,6 @@ endif() add_subdirectory(xrLuaFix) add_subdirectory(luabind) - -if (USE_CXIMAGE) - add_subdirectory(cximage) -endif() - add_subdirectory(GameSpy) add_subdirectory(OPCODE) add_subdirectory(ode) diff --git a/Externals/cximage/CMakeLists.txt b/Externals/cximage/CMakeLists.txt deleted file mode 100644 index 5d60d8345bc..00000000000 --- a/Externals/cximage/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -add_library(cximage STATIC) - -target_sources(cximage PRIVATE - xfile.h - ximacfg.cpp - ximacfg.h - ximadef.h - ximaenc.cpp - ximaexif.cpp - ximage.cpp - ximage.h - ximainfo.cpp - ximaint.cpp - ximaiter.h - ximajpg.cpp - ximajpg.h - ximalpha.cpp - ximalyr.cpp - ximapal.cpp - ximasel.cpp - ximath.cpp - ximath.h - xiofile.h - xiofile.cpp - xmemfile.cpp - xmemfile.h -) - -target_include_directories(cximage - PRIVATE - "${CMAKE_SOURCE_DIR}/src" -) - -target_link_libraries(cximage - PRIVATE - $<$:JPEG::JPEG> -) - -target_compile_definitions(cximage - PRIVATE - CXIMAGE_BUILD -) - -# XXX: Clang-9 internal error in function GetPixelColorInterpolated during optimization -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND (CMAKE_CXX_COMPILER_VERSION MATCHES "9.0.0" OR CMAKE_CXX_COMPILER_VERSION MATCHES "10.0.0")) - set_property(SOURCE ximaint.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION TRUE) -endif() - -set_target_properties(cximage PROPERTIES - PREFIX "" - POSITION_INDEPENDENT_CODE ON -) diff --git a/Externals/cximage/cximage.vcxproj b/Externals/cximage/cximage.vcxproj deleted file mode 100644 index f928fbf03ff..00000000000 --- a/Externals/cximage/cximage.vcxproj +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - CxImage - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4} - - - - - - - StaticLibrary - - - - - - - - - - - - $(xrExternals);%(AdditionalIncludeDirectories) - JAS_WIN_MSVC_BUILD;CXIMAGE_BUILD;%(PreprocessorDefinitions) - false - 4100;4611;4702;%(DisableSpecificWarnings) - NotUsing - - - jpeg-static.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {a0f7d1fb-59a7-4717-a7e4-96f37e91998e} - - - - - - \ No newline at end of file diff --git a/Externals/cximage/cximage.vcxproj.filters b/Externals/cximage/cximage.vcxproj.filters deleted file mode 100644 index c933de1b2ca..00000000000 --- a/Externals/cximage/cximage.vcxproj.filters +++ /dev/null @@ -1,86 +0,0 @@ - - - - - {809204d4-54e2-4efc-8562-d4d26b493cb0} - cpp;c;cxx;rc;def;r;odl;idl;hpj;bat - - - {9ef7aa3b-52be-4021-835b-decbb0f3b1f9} - h;hpp;hxx;hm;inl - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/Externals/cximage/license.txt b/Externals/cximage/license.txt deleted file mode 100644 index 8cc0197bbfb..00000000000 --- a/Externals/cximage/license.txt +++ /dev/null @@ -1,48 +0,0 @@ -This copy of the CxImage notices is provided for your convenience. In case of -any discrepancy between this copy and the notices in the file ximage.h that is -included in the CxImage distribution, the latter shall prevail. - -If you modify CxImage you may insert additional notices immediately following -this sentence. - --------------------------------------------------------------------------------- - -COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - -CxImage version 6.0.0 02/Feb/2008 - -CxImage : Copyright (C) 2001 - 2008, 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 - --------------------------------------------------------------------------------- diff --git a/Externals/cximage/xfile.h b/Externals/cximage/xfile.h deleted file mode 100644 index b64594ee97b..00000000000 --- a/Externals/cximage/xfile.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 -#endif - -#include -#include - -#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(long offset, int origin) = 0; - virtual long Tell() = 0; - virtual long Size() = 0; - virtual bool Flush() = 0; - virtual bool Eof() = 0; - virtual long Error() = 0; - virtual bool PutC(unsigned char c) - { - // Default implementation - size_t nWrote = Write(&c, 1, 1); - return (bool)(nWrote == 1); - } - virtual long GetC() = 0; - virtual char * GetS(char *string, int n) = 0; - virtual long Scanf(const char *format, void* output) = 0; -}; - -#endif //__xfile_h diff --git a/Externals/cximage/ximacfg.cpp b/Externals/cximage/ximacfg.cpp deleted file mode 100644 index 81e70574954..00000000000 --- a/Externals/cximage/ximacfg.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "ximacfg.h" - -#define XRCORE_API XR_IMPORT -#include "xrCore/xrMemory.h" - -void* cxalloc(size_t size) -{ - return xr_malloc(size); -} - -void cxfree(void* ptr) -{ - return xr_free(ptr); -} - -void* cxrealloc(void* ptr, size_t size) -{ - return xr_realloc(ptr, size); -} - -#undef XRCORE_API diff --git a/Externals/cximage/ximacfg.h b/Externals/cximage/ximacfg.h deleted file mode 100644 index 245fde4dfe9..00000000000 --- a/Externals/cximage/ximacfg.h +++ /dev/null @@ -1,77 +0,0 @@ -#if !defined(__ximaCFG_h) -#define __ximaCFG_h -#if !defined(WIN32) -#include -#endif - -#include "Common/Common.hpp" -#include "Common/Platform.hpp" - -extern "C" void* cxalloc(size_t size); -extern "C" void cxfree(void* ptr); -extern "C" void* cxrealloc(void* ptr, size_t size); - -#ifdef CXIMAGE_AS_SHARED_LIBRARY //must be defined in Release_Shared configuration -#ifdef CXIMAGE_BUILD -#define CXIMAGE_API XR_EXPORT -#else -#define CXIMAGE_API XR_IMPORT -#endif //#ifdef CXIMAGE_BUILD -#else //if CXIMAGE_AS_SHARED_LIBRARY linking as static library ... -#define CXIMAGE_API -#endif //CXIMAGE_AS_SHARED_LIBRARY - -///////////////////////////////////////////////////////////////////////////// -// 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 // -#define CXIMAGE_SUPPORT_WINDOWS 1 - -///////////////////////////////////////////////////////////////////////////// -// CxImage supported formats -#define CXIMAGE_SUPPORT_BMP 0 -#define CXIMAGE_SUPPORT_GIF 0 -#define CXIMAGE_SUPPORT_JPG 1 -#define CXIMAGE_SUPPORT_PNG 0 -#define CXIMAGE_SUPPORT_ICO 0 -#define CXIMAGE_SUPPORT_TIF 0 -#define CXIMAGE_SUPPORT_TGA 0 -#define CXIMAGE_SUPPORT_PCX 0 -#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 0 - -#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_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 0 - -///////////////////////////////////////////////////////////////////////////// -//color to grey mapping -//#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 diff --git a/Externals/cximage/ximadef.h b/Externals/cximage/ximadef.h deleted file mode 100644 index 4d3660621fe..00000000000 --- a/Externals/cximage/ximadef.h +++ /dev/null @@ -1,175 +0,0 @@ -#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 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 -#endif - -#include -#include - -#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 -#include -#include - -typedef uint8_t BYTE; -typedef DWORD COLORREF; -typedef void* HRGN; -typedef void* HDC; - -typedef int boolean; - -#ifndef TCHAR -#define TCHAR char -#endif - -typedef struct tagRGBQUAD { - BYTE rgbBlue; - BYTE rgbGreen; - BYTE rgbRed; - BYTE rgbReserved; -} RGBQUAD; - -#pragma pack(push, 1) - -typedef struct tagBITMAPINFOHEADER{ - DWORD biSize; - long biWidth; - long biHeight; - WORD biPlanes; - WORD biBitCount; - DWORD biCompression; - DWORD biSizeImage; - long biXPelsPerMeter; - long biYPelsPerMeter; - DWORD biClrUsed; - DWORD biClrImportant; -} BITMAPINFOHEADER; - -typedef struct tagBITMAPFILEHEADER { - WORD bfType; - DWORD bfSize; - WORD bfReserved1; - WORD bfReserved2; - DWORD bfOffBits; -} BITMAPFILEHEADER; - -typedef struct tagBITMAPCOREHEADER { - DWORD bcSize; - WORD bcWidth; - WORD bcHeight; - WORD bcPlanes; - WORD bcBitCount; -} BITMAPCOREHEADER; - -typedef struct tagRGBTRIPLE { - BYTE rgbtBlue; - BYTE rgbtGreen; - BYTE rgbtRed; -} RGBTRIPLE; - -#pragma pack(pop) - -#define BI_RGB 0L -#define BI_RLE8 1L -#define BI_RLE4 2L -#define BI_BITFIELDS 3L - -#define GetRValue(rgb) ((BYTE)(rgb)) -#define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) -#define GetBValue(rgb) ((BYTE)((rgb)>>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 diff --git a/Externals/cximage/ximaenc.cpp b/Externals/cximage/ximaenc.cpp deleted file mode 100644 index 0b944031d0f..00000000000 --- a/Externals/cximage/ximaenc.cpp +++ /dev/null @@ -1,1008 +0,0 @@ -// xImaCodec.cpp : Encode Decode functions -/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximage.h" - -#if defined(WIN32) || defined(_WIN32_WCE) -#include -#else -#define _tfopen fopen -#define _T(x) x -#endif - -#if CXIMAGE_SUPPORT_JPG -#include "ximajpg.h" -#endif - -#if CXIMAGE_SUPPORT_GIF -#include "ximagif.h" -#endif - -#if CXIMAGE_SUPPORT_PNG -#include "ximapng.h" -#endif - -#if CXIMAGE_SUPPORT_MNG -#include "ximamng.h" -#endif - -#if CXIMAGE_SUPPORT_BMP -#include "ximabmp.h" -#endif - -#if CXIMAGE_SUPPORT_ICO -#include "ximaico.h" -#endif - -#if CXIMAGE_SUPPORT_TIF -#include "ximatif.h" -#endif - -#if CXIMAGE_SUPPORT_TGA -#include "ximatga.h" -#endif - -#if CXIMAGE_SUPPORT_PCX -#include "ximapcx.h" -#endif - -#if CXIMAGE_SUPPORT_WBMP -#include "ximawbmp.h" -#endif - -#if CXIMAGE_SUPPORT_WMF -#include "ximawmf.h" // - WMF/EMF support -#endif - -#if CXIMAGE_SUPPORT_JBG -#include "ximajbg.h" -#endif - -#if CXIMAGE_SUPPORT_JASPER -#include "ximajas.h" -#endif - -#if CXIMAGE_SUPPORT_SKA -#include "ximaska.h" -#endif - -#if CXIMAGE_SUPPORT_RAW -#include "ximaraw.h" -#endif - -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_ENCODE -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::EncodeSafeCheck(CxFile *hFile) -{ - if (hFile==NULL) { - strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); - return true; - } - - if (pDib==NULL){ - strcpy(info.szLastError,CXIMAGE_ERR_NOIMAGE); - return true; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -//#ifdef WIN32 -//bool CxImage::Save(LPCWSTR filename, DWORD imagetype) -//{ -// FILE* hFile; //file handle to write the image -// if ((hFile=_wfopen(filename,L"wb"))==NULL) return false; -// bool bOK = Encode(hFile,imagetype); -// fclose(hFile); -// return bOK; -//} -//#endif //WIN32 -//////////////////////////////////////////////////////////////////////////////// -// For UNICODE support: char -> TCHAR -/** - * Saves to disk the image in a specific format. - * \param filename: file name - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Save(const TCHAR * filename, DWORD imagetype) -{ - FILE* hFile; //file handle to write the image - - if ((hFile=_tfopen(filename,_T("wb")))==NULL) return false; // For UNICODE support - - bool bOK = Encode(hFile,imagetype); - fclose(hFile); - return bOK; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Saves to disk the image in a specific format. - * \param hFile: file handle, open and enabled for writing. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Encode(FILE *hFile, DWORD imagetype) -{ - CxIOFile file(hFile); - return Encode(&file,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Saves to memory buffer the image in a specific format. - * \param buffer: output memory buffer pointer. Must be NULL, - * the function allocates and fill the memory, - * the application must free the buffer, see also FreeMemory(). - * \param size: output memory buffer size. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Encode(BYTE * &buffer, long &size, DWORD imagetype) -{ - if (buffer!=NULL){ - strcpy(info.szLastError,"the buffer must be empty"); - return false; - } - CxMemFile file; - file.Open(); - if(Encode(&file,imagetype)){ - buffer=file.GetBuffer(); - size=file.Size(); - return true; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Saves to disk the image in a specific format. - * \param hFile: file handle (CxMemFile or CxIOFile), with write access. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - * \sa ENUM_CXIMAGE_FORMATS - */ -bool CxImage::Encode(CxFile *hFile, DWORD imagetype) -{ - -#if CXIMAGE_SUPPORT_BMP - - if (imagetype==CXIMAGE_FORMAT_BMP){ - CxImageBMP newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_ICO - if (imagetype==CXIMAGE_FORMAT_ICO){ - CxImageICO newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_TIF - if (imagetype==CXIMAGE_FORMAT_TIF){ - CxImageTIF newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JPG - if (imagetype==CXIMAGE_FORMAT_JPG){ - CxImageJPG newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_GIF - if (imagetype==CXIMAGE_FORMAT_GIF){ - CxImageGIF newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_PNG - if (imagetype==CXIMAGE_FORMAT_PNG){ - CxImagePNG newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_MNG - if (imagetype==CXIMAGE_FORMAT_MNG){ - CxImageMNG newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_TGA - if (imagetype==CXIMAGE_FORMAT_TGA){ - CxImageTGA newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_PCX - if (imagetype==CXIMAGE_FORMAT_PCX){ - CxImagePCX newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_WBMP - if (imagetype==CXIMAGE_FORMAT_WBMP){ - CxImageWBMP newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // - WMF/EMF support - if (imagetype==CXIMAGE_FORMAT_WMF){ - CxImageWMF newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JBG - if (imagetype==CXIMAGE_FORMAT_JBG){ - CxImageJBG newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JASPER - if ( - #if CXIMAGE_SUPPORT_JP2 - imagetype==CXIMAGE_FORMAT_JP2 || - #endif - #if CXIMAGE_SUPPORT_JPC - imagetype==CXIMAGE_FORMAT_JPC || - #endif - #if CXIMAGE_SUPPORT_PGX - imagetype==CXIMAGE_FORMAT_PGX || - #endif - #if CXIMAGE_SUPPORT_PNM - imagetype==CXIMAGE_FORMAT_PNM || - #endif - #if CXIMAGE_SUPPORT_RAS - imagetype==CXIMAGE_FORMAT_RAS || - #endif - false ){ - CxImageJAS newima; - newima.Ghost(this); - if (newima.Encode(hFile,imagetype)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - -#if CXIMAGE_SUPPORT_SKA - if (imagetype==CXIMAGE_FORMAT_SKA){ - CxImageSKA newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - -#if CXIMAGE_SUPPORT_RAW - if (imagetype==CXIMAGE_FORMAT_RAW){ - CxImageRAW newima; - newima.Ghost(this); - if (newima.Encode(hFile)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - - strcpy(info.szLastError,"Encode: Unknown format"); - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers. - * \param hFile: file handle. - * \param pImages: array of CxImage pointers. - * \param pagecount: number of images. - * \param imagetype: can be CXIMAGE_FORMAT_TIF or CXIMAGE_FORMAT_GIF. - * \return true if everything is ok - */ -bool CxImage::Encode(FILE * hFile, CxImage ** pImages, int pagecount, DWORD imagetype) -{ - CxIOFile file(hFile); - return Encode(&file, pImages, pagecount,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Saves to disk or memory pagecount images, referenced by an array of CxImage pointers. - * \param hFile: file handle (CxMemFile or CxIOFile), with write access. - * \param pImages: array of CxImage pointers. - * \param pagecount: number of images. - * \param imagetype: can be CXIMAGE_FORMAT_TIF, CXIMAGE_FORMAT_GIF or CXIMAGE_FORMAT_ICO. - * \return true if everything is ok - */ -bool CxImage::Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype) -{ -#if CXIMAGE_SUPPORT_TIF - if (imagetype==CXIMAGE_FORMAT_TIF){ - CxImageTIF newima; - newima.Ghost(this); - if (newima.Encode(hFile,pImages,pagecount)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_GIF - if (imagetype==CXIMAGE_FORMAT_GIF){ - CxImageGIF newima; - newima.Ghost(this); - if (newima.Encode(hFile,pImages,pagecount)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_ICO - if (imagetype==CXIMAGE_FORMAT_ICO){ - CxImageICO newima; - newima.Ghost(this); - if (newima.Encode(hFile,pImages,pagecount)){ - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - strcpy(info.szLastError,"Multipage Encode, Unsupported operation for this format"); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * exports the image into a RGBA buffer, Useful for OpenGL applications. - * \param buffer: output memory buffer pointer. Must be NULL, - * the function allocates and fill the memory, - * the application must free the buffer, see also FreeMemory(). - * \param size: output memory buffer size. - * \param bFlipY: direction of Y axis. default = false. - * \return true if everything is ok - */ -bool CxImage::Encode2RGBA(BYTE * &buffer, long &size, bool bFlipY) -{ - if (buffer!=NULL){ - strcpy(info.szLastError,"the buffer must be empty"); - return false; - } - CxMemFile file; - file.Open(); - if(Encode2RGBA(&file,bFlipY)){ - buffer=file.GetBuffer(); - size=file.Size(); - return true; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * exports the image into a RGBA buffer, Useful for OpenGL applications. - * \param hFile: file handle (CxMemFile or CxIOFile), with write access. - * \param bFlipY: direction of Y axis. default = false. - * \return true if everything is ok - */ -bool CxImage::Encode2RGBA(CxFile *hFile, bool bFlipY) -{ - if (EncodeSafeCheck(hFile)) return false; - - for (long y1 = 0; y1 < head.biHeight; y1++) { - long y = bFlipY ? head.biHeight - 1 - y1 : y1; - for(long x = 0; x < head.biWidth; x++) { - RGBQUAD color = BlindGetPixelColor(x,y); - hFile->PutC(color.rgbRed); - hFile->PutC(color.rgbGreen); - hFile->PutC(color.rgbBlue); - hFile->PutC(color.rgbReserved); - } - } - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -#endif //CXIMAGE_SUPPORT_ENCODE -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_DECODE -//////////////////////////////////////////////////////////////////////////////// -// For UNICODE support: char -> TCHAR -/** - * Reads from disk the image in a specific format. - * - If decoding fails using the specified image format, - * the function will try the automatic file format recognition. - * - * \param filename: file name - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Load(const TCHAR * filename, DWORD imagetype) -//bool CxImage::Load(const char * filename, DWORD imagetype) -{ - /*FILE* hFile; //file handle to read the image - if ((hFile=fopen(filename,"rb"))==NULL) return false; - bool bOK = Decode(hFile,imagetype); - fclose(hFile);*/ - - /* automatic file type recognition */ - bool bOK = false; - if ( GetTypeIndexFromId(imagetype) ){ - FILE* hFile; //file handle to read the image - - if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support - - bOK = Decode(hFile,imagetype); - fclose(hFile); - if (bOK) return bOK; - } - - char szError[256]; - strcpy(szError,info.szLastError); //save the first error - - // if failed, try automatic recognition of the file... - FILE* hFile; - - if ((hFile=_tfopen(filename,_T("rb")))==NULL) return false; // For UNICODE support - - bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN); - fclose(hFile); - - if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error - - return bOK; -} -//////////////////////////////////////////////////////////////////////////////// -#ifdef WIN32 -//bool CxImage::Load(LPCWSTR filename, DWORD imagetype) -//{ -// /*FILE* hFile; //file handle to read the image -// if ((hFile=_wfopen(filename, L"rb"))==NULL) return false; -// bool bOK = Decode(hFile,imagetype); -// fclose(hFile);*/ -// -// /* automatic file type recognition */ -// bool bOK = false; -// if ( GetTypeIndexFromId(imagetype) ){ -// FILE* hFile; //file handle to read the image -// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false; -// bOK = Decode(hFile,imagetype); -// fclose(hFile); -// if (bOK) return bOK; -// } -// -// char szError[256]; -// strcpy(szError,info.szLastError); //save the first error -// -// // if failed, try automatic recognition of the file... -// FILE* hFile; //file handle to read the image -// if ((hFile=_wfopen(filename,L"rb"))==NULL) return false; -// bOK = Decode(hFile,CXIMAGE_FORMAT_UNKNOWN); -// fclose(hFile); -// -// if (!bOK && imagetype > 0) strcpy(info.szLastError,szError); //restore the first error -// -// return bOK; -//} -//////////////////////////////////////////////////////////////////////////////// -/** - * Loads an image from the application resources. - * \param hRes: the resource handle returned by FindResource(). - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS. - * \param hModule: NULL for internal resource, or external application/DLL hinstance returned by LoadLibray. - * \return true if everything is ok - */ -bool CxImage::LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule) -{ - DWORD rsize=SizeofResource(hModule,hRes); - HGLOBAL hMem=::LoadResource(hModule,hRes); - if (hMem){ - char* lpVoid=(char*)LockResource(hMem); - if (lpVoid){ - // FILE* fTmp=tmpfile(); doesn't work with network - /*char tmpPath[MAX_PATH] = {0}; - char tmpFile[MAX_PATH] = {0}; - GetTempPath(MAX_PATH,tmpPath); - GetTempFileName(tmpPath,"IMG",0,tmpFile); - FILE* fTmp=fopen(tmpFile,"w+b"); - if (fTmp){ - fwrite(lpVoid,rsize,1,fTmp); - fseek(fTmp,0,SEEK_SET); - bool bOK = Decode(fTmp,imagetype); - fclose(fTmp); - DeleteFile(tmpFile); - return bOK; - }*/ - - CxMemFile fTmp((BYTE*)lpVoid,rsize); - return Decode(&fTmp,imagetype); - } - } else strcpy(info.szLastError,"Unable to load resource!"); - return false; -} -#endif //WIN32 -//////////////////////////////////////////////////////////////////////////////// -/** - * Constructor from file name, see Load() - * \param filename: file name - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - */ -// -// > filename: file name -// > imagetype: specify the image format (CXIMAGE_FORMAT_BMP,...) -// For UNICODE support: char -> TCHAR -CxImage::CxImage(const TCHAR * filename, DWORD imagetype) -//CxImage::CxImage(const char * filename, DWORD imagetype) -{ - Startup(imagetype); - Load(filename,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Constructor from file handle, see Decode() - * \param stream: file handle, with read access. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - */ -CxImage::CxImage(FILE * stream, DWORD imagetype) -{ - Startup(imagetype); - Decode(stream,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Constructor from CxFile object, see Decode() - * \param stream: file handle (CxMemFile or CxIOFile), with read access. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - */ -CxImage::CxImage(CxFile * stream, DWORD imagetype) -{ - Startup(imagetype); - Decode(stream,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Constructor from memory buffer, see Decode() - * \param buffer: memory buffer - * \param size: size of buffer - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - */ -CxImage::CxImage(BYTE * buffer, DWORD size, DWORD imagetype) -{ - Startup(imagetype); - CxMemFile stream(buffer,size); - Decode(&stream,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Loads an image from memory buffer - * \param buffer: memory buffer - * \param size: size of buffer - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Decode(BYTE * buffer, DWORD size, DWORD imagetype) -{ - CxMemFile file(buffer,size); - return Decode(&file,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Loads an image from file handle. - * \param hFile: file handle, with read access. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - */ -bool CxImage::Decode(FILE *hFile, DWORD imagetype) -{ - CxIOFile file(hFile); - return Decode(&file,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Loads an image from CxFile object - * \param hFile: file handle (CxMemFile or CxIOFile), with read access. - * \param imagetype: file format, see ENUM_CXIMAGE_FORMATS - * \return true if everything is ok - * \sa ENUM_CXIMAGE_FORMATS - */ -bool CxImage::Decode(CxFile *hFile, DWORD imagetype) -{ - if (hFile == NULL){ - strcpy(info.szLastError,CXIMAGE_ERR_NOFILE); - return false; - } - - if (imagetype==CXIMAGE_FORMAT_UNKNOWN){ - DWORD pos = hFile->Tell(); -#if CXIMAGE_SUPPORT_BMP - { CxImageBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_JPG - { CxImageJPG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_ICO - { CxImageICO newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_GIF - { CxImageGIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_PNG - { CxImagePNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_TIF - { CxImageTIF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_MNG - { CxImageMNG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_TGA - { CxImageTGA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_PCX - { CxImagePCX newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_WBMP - { CxImageWBMP newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS - { CxImageWMF newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_JBG - { CxImageJBG newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_JASPER - { CxImageJAS newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_SKA - { CxImageSKA newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif -#if CXIMAGE_SUPPORT_RAW - { CxImageRAW newima; newima.CopyInfo(*this); if (newima.Decode(hFile)) { Transfer(newima); return true; } else hFile->Seek(pos,SEEK_SET); } -#endif - } - -#if CXIMAGE_SUPPORT_BMP - if (imagetype==CXIMAGE_FORMAT_BMP){ - CxImageBMP newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JPG - if (imagetype==CXIMAGE_FORMAT_JPG){ - CxImageJPG newima; - newima.CopyInfo(*this); // - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_ICO - if (imagetype==CXIMAGE_FORMAT_ICO){ - CxImageICO newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - info.nNumFrames = newima.info.nNumFrames; - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_GIF - if (imagetype==CXIMAGE_FORMAT_GIF){ - CxImageGIF newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - info.nNumFrames = newima.info.nNumFrames; - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_PNG - if (imagetype==CXIMAGE_FORMAT_PNG){ - CxImagePNG newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_TIF - if (imagetype==CXIMAGE_FORMAT_TIF){ - CxImageTIF newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - info.nNumFrames = newima.info.nNumFrames; - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_MNG - if (imagetype==CXIMAGE_FORMAT_MNG){ - CxImageMNG newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - info.nNumFrames = newima.info.nNumFrames; - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_TGA - if (imagetype==CXIMAGE_FORMAT_TGA){ - CxImageTGA newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_PCX - if (imagetype==CXIMAGE_FORMAT_PCX){ - CxImagePCX newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_WBMP - if (imagetype==CXIMAGE_FORMAT_WBMP){ - CxImageWBMP newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS // vho - WMF support - if (imagetype == CXIMAGE_FORMAT_WMF){ - CxImageWMF newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JBG - if (imagetype==CXIMAGE_FORMAT_JBG){ - CxImageJBG newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_JASPER - if ( - #if CXIMAGE_SUPPORT_JP2 - imagetype==CXIMAGE_FORMAT_JP2 || - #endif - #if CXIMAGE_SUPPORT_JPC - imagetype==CXIMAGE_FORMAT_JPC || - #endif - #if CXIMAGE_SUPPORT_PGX - imagetype==CXIMAGE_FORMAT_PGX || - #endif - #if CXIMAGE_SUPPORT_PNM - imagetype==CXIMAGE_FORMAT_PNM || - #endif - #if CXIMAGE_SUPPORT_RAS - imagetype==CXIMAGE_FORMAT_RAS || - #endif - false ){ - CxImageJAS newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile,imagetype)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif -#if CXIMAGE_SUPPORT_SKA - if (imagetype==CXIMAGE_FORMAT_SKA){ - CxImageSKA newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - -#if CXIMAGE_SUPPORT_RAW - if (imagetype==CXIMAGE_FORMAT_RAW){ - CxImageRAW newima; - newima.CopyInfo(*this); - if (newima.Decode(hFile)){ - Transfer(newima); - return true; - } else { - strcpy(info.szLastError,newima.GetLastError()); - return false; - } - } -#endif - - strcpy(info.szLastError,"Decode: Unknown or wrong format"); - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Loads an image from CxFile object - * \param hFile: file handle (CxMemFile or CxIOFile), with read access. - * \param imagetype: file format, default = 0 (CXIMAGE_FORMAT_UNKNOWN) - * \return : if imagetype is not 0, the function returns true when imagetype - * matches the file image format. If imagetype is 0, the function returns true - * when the file image format is recognized as a supported format. - * If the returned value is true, use GetHeight(), GetWidth() or GetType() - * to retrieve the basic image information. - * \sa ENUM_CXIMAGE_FORMATS - */ -bool CxImage::CheckFormat(CxFile * hFile, DWORD imagetype) -{ - SetType(CXIMAGE_FORMAT_UNKNOWN); - SetEscape(-1); - - if (!Decode(hFile,imagetype)) - return false; - - if (GetType() == CXIMAGE_FORMAT_UNKNOWN || GetType() != imagetype) - return false; - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::CheckFormat(BYTE * buffer, DWORD size, DWORD imagetype) -{ - if (buffer==NULL || size==0){ - strcpy(info.szLastError,"invalid or empty buffer"); - return false; - } - CxMemFile file(buffer,size); - return CheckFormat(&file,imagetype); -} -//////////////////////////////////////////////////////////////////////////////// -#endif //CXIMAGE_SUPPORT_DECODE -//////////////////////////////////////////////////////////////////////////////// - -#if !defined(WIN32) && !defined(_WIN32_WCE) -#undef _tfopen -#undef _T -#endif diff --git a/Externals/cximage/ximaexif.cpp b/Externals/cximage/ximaexif.cpp deleted file mode 100644 index db7650d8907..00000000000 --- a/Externals/cximage/ximaexif.cpp +++ /dev/null @@ -1,878 +0,0 @@ -/* - * File: ximaexif.cpp - * Purpose: EXIF reader - * 18/Aug/2002 Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - * based on jhead-1.8 by Matthias Wandel - */ - -#include "ximajpg.h" - -#if CXIMAGEJPG_SUPPORT_EXIF - -//////////////////////////////////////////////////////////////////////////////// -CxImageJPG::CxExifInfo::CxExifInfo(EXIFINFO* info) -{ - if (info) { - m_exifinfo = info; - freeinfo = false; - } else { - m_exifinfo = new EXIFINFO; - memset(m_exifinfo,0,sizeof(EXIFINFO)); - freeinfo = true; - } - - m_szLastError[0]='\0'; - ExifImageWidth = MotorolaOrder = 0; - SectionsRead=0; - memset(&Sections, 0, MAX_SECTIONS * sizeof(Section_t)); -} -//////////////////////////////////////////////////////////////////////////////// -CxImageJPG::CxExifInfo::~CxExifInfo() -{ - for(int i=0;iGetC(); - - if (a != 0xff || hFile->GetC() != M_SOI){ - return false; - } - - for(;;){ - int itemlen; - int marker = 0; - int ll,lh, got; - BYTE * Data; - - if (SectionsRead >= MAX_SECTIONS){ - strcpy(m_szLastError,"Too many sections in jpg file"); - return false; - } - - for (a=0;a<7;a++){ - marker = hFile->GetC(); - if (marker != 0xff) break; - - if (a >= 6){ - printf("too many padding bytes\n"); - return false; - } - } - - if (marker == 0xff){ - // 0xff is legal padding, but if we get that many, something's wrong. - strcpy(m_szLastError,"too many padding bytes!"); - return false; - } - - Sections[SectionsRead].Type = marker; - - // Read the length of the section. - lh = hFile->GetC(); - ll = hFile->GetC(); - - itemlen = (lh << 8) | ll; - - if (itemlen < 2){ - strcpy(m_szLastError,"invalid marker"); - return false; - } - - Sections[SectionsRead].Size = itemlen; - - Data = (BYTE *)cxalloc(itemlen);//malloc(itemlen); - if (Data == NULL){ - strcpy(m_szLastError,"Could not allocate memory"); - return false; - } - Sections[SectionsRead].Data = Data; - - // Store first two pre-read bytes. - Data[0] = (BYTE)lh; - Data[1] = (BYTE)ll; - - got = hFile->Read(Data+2, 1, itemlen-2); // Read the whole section. - if (got != itemlen-2){ - strcpy(m_szLastError,"Premature end of file?"); - return false; - } - SectionsRead += 1; - - switch(marker){ - - case M_SOS: // stop before hitting compressed data - // If reading entire image is requested, read the rest of the data. - if (nReadMode & EXIF_READ_IMAGE){ - int cp, ep, size; - // Determine how much file is left. - cp = hFile->Tell(); - hFile->Seek(0, SEEK_END); - ep = hFile->Tell(); - hFile->Seek(cp, SEEK_SET); - - size = ep-cp; - Data = (BYTE *)cxalloc(size);//malloc(size); - if (Data == NULL){ - strcpy(m_szLastError,"could not allocate data for entire image"); - return false; - } - - got = hFile->Read(Data, 1, size); - if (got != size){ - strcpy(m_szLastError,"could not read the rest of the image"); - return false; - } - - Sections[SectionsRead].Data = Data; - Sections[SectionsRead].Size = size; - Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; - SectionsRead ++; - } - return true; - - case M_EOI: // in case it's a tables-only JPEG stream - printf("No image in jpeg!\n"); - return false; - - case M_COM: // Comment section - if (HaveCom || ((nReadMode & EXIF_READ_EXIF) == 0)){ - // Discard this section. - cxfree(Sections[--SectionsRead].Data);//free(Sections[--SectionsRead].Data); - Sections[SectionsRead].Data=0; - }else{ - process_COM(Data, itemlen); - HaveCom = true; - } - break; - - case M_JFIF: - // Regular jpegs always have this tag, exif images have the exif - // marker instead, althogh ACDsee will write images with both markers. - // this program will re-create this marker on absence of exif marker. - // hence no need to keep the copy from the file. - cxfree(Sections[--SectionsRead].Data);//free(Sections[--SectionsRead].Data); - Sections[SectionsRead].Data=0; - break; - - case M_EXIF: - // Seen files from some 'U-lead' software with Vivitar scanner - // that uses marker 31 for non exif stuff. Thus make sure - // it says 'Exif' in the section before treating it as exif. - if ((nReadMode & EXIF_READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ - m_exifinfo->IsExif = process_EXIF((BYTE *)Data+2, itemlen); - }else{ - // Discard this section. - cxfree(Sections[--SectionsRead].Data);//free(Sections[--SectionsRead].Data); - Sections[SectionsRead].Data=0; - } - break; - - case M_SOF0: - case M_SOF1: - case M_SOF2: - case M_SOF3: - case M_SOF5: - case M_SOF6: - case M_SOF7: - case M_SOF9: - case M_SOF10: - case M_SOF11: - case M_SOF13: - case M_SOF14: - case M_SOF15: - process_SOFn(Data, marker); - break; - default: - // Skip any other sections. - //if (ShowTags) printf("Jpeg section marker 0x%02x size %d\n",marker, itemlen); - break; - } - } - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/*-------------------------------------------------------------------------- - Process a EXIF marker - Describes all the drivel that most digital cameras include... ---------------------------------------------------------------------------*/ -bool CxImageJPG::CxExifInfo::process_EXIF(unsigned char * CharBuf, unsigned int length) -{ - m_exifinfo->FlashUsed = 0; - /* If it's from a digicam, and it used flash, it says so. */ - m_exifinfo->Comments[0] = '\0'; /* Initial value - null string */ - - ExifImageWidth = 0; - - { /* Check the EXIF header component */ - static const unsigned char ExifHeader[] = "Exif\0\0"; - if (memcmp(CharBuf+0, ExifHeader,6)){ - strcpy(m_szLastError,"Incorrect Exif header"); - return false; - } - } - - if (memcmp(CharBuf+6,"II",2) == 0){ - MotorolaOrder = 0; - }else{ - if (memcmp(CharBuf+6,"MM",2) == 0){ - MotorolaOrder = 1; - }else{ - strcpy(m_szLastError,"Invalid Exif alignment marker."); - return false; - } - } - - /* Check the next two values for correctness. */ - if (Get16u(CharBuf+8) != 0x2a){ - strcpy(m_szLastError,"Invalid Exif start (1)"); - return false; - } - - int FirstOffset = Get32u(CharBuf+10); - /* - if (FirstOffset < 8 || FirstOffset > 16){ - // I used to ensure this was set to 8 (website I used indicated its 8) - // but PENTAX Optio 230 has it set differently, and uses it as offset. (Sept 11 2002) - strcpy(m_szLastError,"Suspicious offset of first IFD value"); - return false; - }*/ - - unsigned char * LastExifRefd = CharBuf; - - /* First directory starts 16 bytes in. Offsets start at 8 bytes in. */ - if (!ProcessExifDir(CharBuf+14, CharBuf+6, length-6, m_exifinfo, &LastExifRefd)) - return false; - - /* give a chance for a second directory */ - if (FirstOffset > 8) { - if (!ProcessExifDir(CharBuf+14+FirstOffset-8, CharBuf+6, length-6, m_exifinfo, &LastExifRefd)) - return false; - } - - /* This is how far the interesting (non thumbnail) part of the exif went. */ - // int ExifSettingsLength = LastExifRefd - CharBuf; - - /* Compute the CCD width, in milimeters. */ - if (m_exifinfo->FocalplaneXRes != 0){ - m_exifinfo->CCDWidth = (float)(ExifImageWidth * m_exifinfo->FocalplaneUnits / m_exifinfo->FocalplaneXRes); - } - - return true; -} -//-------------------------------------------------------------------------- -// Get 16 bits motorola order (always) for jpeg header stuff. -//-------------------------------------------------------------------------- -int CxImageJPG::CxExifInfo::Get16m(void * Short) -{ - return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1]; -} -//////////////////////////////////////////////////////////////////////////////// -/*-------------------------------------------------------------------------- - Convert a 16 bit unsigned value from file's native byte order ---------------------------------------------------------------------------*/ -int CxImageJPG::CxExifInfo::Get16u(void * Short) -{ - if (MotorolaOrder){ - return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1]; - }else{ - return (((unsigned char *)Short)[1] << 8) | ((unsigned char *)Short)[0]; - } -} -//////////////////////////////////////////////////////////////////////////////// -/*-------------------------------------------------------------------------- - Convert a 32 bit signed value from file's native byte order ---------------------------------------------------------------------------*/ -long CxImageJPG::CxExifInfo::Get32s(void * Long) -{ - if (MotorolaOrder){ - return ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16) - | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 ); - }else{ - return ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16) - | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 ); - } -} -//////////////////////////////////////////////////////////////////////////////// -/*-------------------------------------------------------------------------- - Convert a 32 bit unsigned value from file's native byte order ---------------------------------------------------------------------------*/ -unsigned long CxImageJPG::CxExifInfo::Get32u(void * Long) -{ - return (unsigned long)Get32s(Long) & 0xffffffff; -} -//////////////////////////////////////////////////////////////////////////////// - -/* Describes format descriptor */ -static const int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; -#define NUM_FORMATS 12 - -#define FMT_BYTE 1 -#define FMT_STRING 2 -#define FMT_USHORT 3 -#define FMT_ULONG 4 -#define FMT_URATIONAL 5 -#define FMT_SBYTE 6 -#define FMT_UNDEFINED 7 -#define FMT_SSHORT 8 -#define FMT_SLONG 9 -#define FMT_SRATIONAL 10 -#define FMT_SINGLE 11 -#define FMT_DOUBLE 12 - -/* Describes tag values */ - -#define TAG_EXIF_VERSION 0x9000 -#define TAG_EXIF_OFFSET 0x8769 -#define TAG_INTEROP_OFFSET 0xa005 - -#define TAG_MAKE 0x010F -#define TAG_MODEL 0x0110 - -#define TAG_ORIENTATION 0x0112 -#define TAG_XRESOLUTION 0x011A -#define TAG_YRESOLUTION 0x011B -#define TAG_RESOLUTIONUNIT 0x0128 - -#define TAG_EXPOSURETIME 0x829A -#define TAG_FNUMBER 0x829D - -#define TAG_SHUTTERSPEED 0x9201 -#define TAG_APERTURE 0x9202 -#define TAG_BRIGHTNESS 0x9203 -#define TAG_MAXAPERTURE 0x9205 -#define TAG_FOCALLENGTH 0x920A - -#define TAG_DATETIME_ORIGINAL 0x9003 -#define TAG_USERCOMMENT 0x9286 - -#define TAG_SUBJECT_DISTANCE 0x9206 -#define TAG_FLASH 0x9209 - -#define TAG_FOCALPLANEXRES 0xa20E -#define TAG_FOCALPLANEYRES 0xa20F -#define TAG_FOCALPLANEUNITS 0xa210 -#define TAG_EXIF_IMAGEWIDTH 0xA002 -#define TAG_EXIF_IMAGELENGTH 0xA003 - -/* the following is added 05-jan-2001 vcs */ -#define TAG_EXPOSURE_BIAS 0x9204 -#define TAG_WHITEBALANCE 0x9208 -#define TAG_METERING_MODE 0x9207 -#define TAG_EXPOSURE_PROGRAM 0x8822 -#define TAG_ISO_EQUIVALENT 0x8827 -#define TAG_COMPRESSION_LEVEL 0x9102 - -#define TAG_THUMBNAIL_OFFSET 0x0201 -#define TAG_THUMBNAIL_LENGTH 0x0202 - - -/*-------------------------------------------------------------------------- - Process one of the nested EXIF directories. ---------------------------------------------------------------------------*/ -bool CxImageJPG::CxExifInfo::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, - EXIFINFO * const m_exifinfo, unsigned char ** const LastExifRefdP, int NestingLevel) -{ - int de; - int a; - int NumDirEntries; - unsigned ThumbnailOffset = 0; - unsigned ThumbnailSize = 0; - - if (NestingLevel > 4){ - strcpy(m_szLastError,"Maximum directory nesting exceeded (corrupt exif header)"); - return false; - } - - NumDirEntries = Get16u(DirStart); - - if ((DirStart+2+NumDirEntries*12) > (OffsetBase+ExifLength)){ - strcpy(m_szLastError,"Illegally sized directory"); - return false; - } - - for (de=0;de= NUM_FORMATS) { - /* (-1) catches illegal zero case as unsigned underflows to positive large */ - strcpy(m_szLastError,"Illegal format code in EXIF dir"); - return false; - } - - ByteCount = Components * BytesPerFormat[Format]; - - if (ByteCount > 4){ - unsigned OffsetVal; - OffsetVal = Get32u(DirEntry+8); - /* If its bigger than 4 bytes, the dir entry contains an offset.*/ - if (OffsetVal+ByteCount > ExifLength){ - /* Bogus pointer offset and / or bytecount value */ - strcpy(m_szLastError,"Illegal pointer offset value in EXIF."); - return false; - } - ValuePtr = OffsetBase+OffsetVal; - }else{ - /* 4 bytes or less and value is in the dir entry itself */ - ValuePtr = DirEntry+8; - } - - if (*LastExifRefdP < ValuePtr+ByteCount){ - /* Keep track of last byte in the exif header that was - actually referenced. That way, we know where the - discardable thumbnail data begins. - */ - *LastExifRefdP = ValuePtr+ByteCount; - } - - /* Extract useful components of tag */ - switch(Tag){ - - case TAG_MAKE: - strncpy(m_exifinfo->CameraMake, (char*)ValuePtr, 31); - break; - - case TAG_MODEL: - strncpy(m_exifinfo->CameraModel, (char*)ValuePtr, 39); - break; - - case TAG_EXIF_VERSION: - strncpy(m_exifinfo->Version,(char*)ValuePtr, 4); - break; - - case TAG_DATETIME_ORIGINAL: - strncpy(m_exifinfo->DateTime, (char*)ValuePtr, 19); - break; - - case TAG_USERCOMMENT: - // Olympus has this padded with trailing spaces. Remove these first. - for (a=ByteCount;;){ - a--; - if (((char*)ValuePtr)[a] == ' '){ - ((char*)ValuePtr)[a] = '\0'; - }else{ - break; - } - if (a == 0) break; - } - - /* Copy the comment */ - if (memcmp(ValuePtr, "ASCII",5) == 0){ - for (a=5;a<10;a++){ - char c; - c = ((char*)ValuePtr)[a]; - if (c != '\0' && c != ' '){ - strncpy(m_exifinfo->Comments, (char*)ValuePtr+a, 199); - break; - } - } - - }else{ - strncpy(m_exifinfo->Comments, (char*)ValuePtr, 199); - } - break; - - case TAG_FNUMBER: - /* Simplest way of expressing aperture, so I trust it the most. - (overwrite previously computd value if there is one) - */ - m_exifinfo->ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_APERTURE: - case TAG_MAXAPERTURE: - /* More relevant info always comes earlier, so only - use this field if we don't have appropriate aperture - information yet. - */ - if (m_exifinfo->ApertureFNumber == 0){ - m_exifinfo->ApertureFNumber = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0f)*0.5); - } - break; - - case TAG_BRIGHTNESS: - m_exifinfo->Brightness = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_FOCALLENGTH: - /* Nice digital cameras actually save the focal length - as a function of how farthey are zoomed in. - */ - - m_exifinfo->FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_SUBJECT_DISTANCE: - /* Inidcates the distacne the autofocus camera is focused to. - Tends to be less accurate as distance increases. - */ - m_exifinfo->Distance = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_EXPOSURETIME: - /* Simplest way of expressing exposure time, so I - trust it most. (overwrite previously computd value - if there is one) - */ - m_exifinfo->ExposureTime = - (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_SHUTTERSPEED: - /* More complicated way of expressing exposure time, - so only use this value if we don't already have it - from somewhere else. - */ - if (m_exifinfo->ExposureTime == 0){ - m_exifinfo->ExposureTime = (float) - (1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2.0f))); - } - break; - - case TAG_FLASH: - if ((int)ConvertAnyFormat(ValuePtr, Format) & 7){ - m_exifinfo->FlashUsed = 1; - }else{ - m_exifinfo->FlashUsed = 0; - } - break; - - case TAG_ORIENTATION: - m_exifinfo->Orientation = (int)ConvertAnyFormat(ValuePtr, Format); - if (m_exifinfo->Orientation < 1 || m_exifinfo->Orientation > 8){ - strcpy(m_szLastError,"Undefined rotation value"); - m_exifinfo->Orientation = 0; - } - break; - - case TAG_EXIF_IMAGELENGTH: - case TAG_EXIF_IMAGEWIDTH: - /* Use largest of height and width to deal with images - that have been rotated to portrait format. - */ - a = (int)ConvertAnyFormat(ValuePtr, Format); - if (ExifImageWidth < a) ExifImageWidth = a; - break; - - case TAG_FOCALPLANEXRES: - m_exifinfo->FocalplaneXRes = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_FOCALPLANEYRES: - m_exifinfo->FocalplaneYRes = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_RESOLUTIONUNIT: - switch((int)ConvertAnyFormat(ValuePtr, Format)){ - case 1: m_exifinfo->ResolutionUnit = 1.0f; break; /* 1 inch */ - case 2: m_exifinfo->ResolutionUnit = 1.0f; break; - case 3: m_exifinfo->ResolutionUnit = 0.3937007874f; break; /* 1 centimeter*/ - case 4: m_exifinfo->ResolutionUnit = 0.03937007874f; break; /* 1 millimeter*/ - case 5: m_exifinfo->ResolutionUnit = 0.00003937007874f; /* 1 micrometer*/ - } - break; - - case TAG_FOCALPLANEUNITS: - switch((int)ConvertAnyFormat(ValuePtr, Format)){ - case 1: m_exifinfo->FocalplaneUnits = 1.0f; break; /* 1 inch */ - case 2: m_exifinfo->FocalplaneUnits = 1.0f; break; - case 3: m_exifinfo->FocalplaneUnits = 0.3937007874f; break; /* 1 centimeter*/ - case 4: m_exifinfo->FocalplaneUnits = 0.03937007874f; break; /* 1 millimeter*/ - case 5: m_exifinfo->FocalplaneUnits = 0.00003937007874f; /* 1 micrometer*/ - } - break; - - // Remaining cases contributed by: Volker C. Schoech - - case TAG_EXPOSURE_BIAS: - m_exifinfo->ExposureBias = (float) ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_WHITEBALANCE: - m_exifinfo->Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_METERING_MODE: - m_exifinfo->MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_EXPOSURE_PROGRAM: - m_exifinfo->ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_ISO_EQUIVALENT: - m_exifinfo->ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); - if ( m_exifinfo->ISOequivalent < 50 ) m_exifinfo->ISOequivalent *= 200; - break; - - case TAG_COMPRESSION_LEVEL: - m_exifinfo->CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_XRESOLUTION: - m_exifinfo->Xresolution = (float)ConvertAnyFormat(ValuePtr, Format); - break; - case TAG_YRESOLUTION: - m_exifinfo->Yresolution = (float)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_THUMBNAIL_OFFSET: - ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); - break; - - case TAG_THUMBNAIL_LENGTH: - ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); - break; - - } - - if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ - unsigned char * SubdirStart; - unsigned Offset = Get32u(ValuePtr); - if (Offset>8){ - SubdirStart = OffsetBase + Offset; - if (SubdirStart < OffsetBase || - SubdirStart > OffsetBase+ExifLength){ - strcpy(m_szLastError,"Illegal subdirectory link"); - return false; - } - ProcessExifDir(SubdirStart, OffsetBase, ExifLength, m_exifinfo, LastExifRefdP, NestingLevel+1); - } - continue; - } - } - - - { - /* In addition to linking to subdirectories via exif tags, - there's also a potential link to another directory at the end - of each directory. This has got to be the result of a - committee! - */ - unsigned char * SubdirStart; - unsigned Offset; - Offset = Get16u(DirStart+2+12*NumDirEntries); - if (Offset){ - SubdirStart = OffsetBase + Offset; - if (SubdirStart < OffsetBase - || SubdirStart > OffsetBase+ExifLength){ - strcpy(m_szLastError,"Illegal subdirectory link"); - return false; - } - ProcessExifDir(SubdirStart, OffsetBase, ExifLength, m_exifinfo, LastExifRefdP, NestingLevel+1); - } - } - - - if (ThumbnailSize && ThumbnailOffset){ - if (ThumbnailSize + ThumbnailOffset <= ExifLength){ - /* The thumbnail pointer appears to be valid. Store it. */ - m_exifinfo->ThumbnailPointer = OffsetBase + ThumbnailOffset; - m_exifinfo->ThumbnailSize = ThumbnailSize; - } - } - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/*-------------------------------------------------------------------------- - Evaluate number, be it int, rational, or float from directory. ---------------------------------------------------------------------------*/ -double CxImageJPG::CxExifInfo::ConvertAnyFormat(void * ValuePtr, int Format) -{ - double Value; - Value = 0; - - switch(Format){ - case FMT_SBYTE: Value = *(signed char *)ValuePtr; break; - case FMT_BYTE: Value = *(unsigned char *)ValuePtr; break; - - case FMT_USHORT: Value = Get16u(ValuePtr); break; - case FMT_ULONG: Value = Get32u(ValuePtr); break; - - case FMT_URATIONAL: - case FMT_SRATIONAL: - { - int Num,Den; - Num = Get32s(ValuePtr); - Den = Get32s(4+(char *)ValuePtr); - if (Den == 0){ - Value = 0; - }else{ - Value = (double)Num/Den; - } - break; - } - - case FMT_SSHORT: Value = (signed short)Get16u(ValuePtr); break; - case FMT_SLONG: Value = Get32s(ValuePtr); break; - - /* Not sure if this is correct (never seen float used in Exif format) - */ - case FMT_SINGLE: Value = (double)*(float *)ValuePtr; break; - case FMT_DOUBLE: Value = *(double *)ValuePtr; break; - } - return Value; -} -//////////////////////////////////////////////////////////////////////////////// -void CxImageJPG::CxExifInfo::process_COM (const BYTE * Data, int length) -{ - int ch; - char Comment[MAX_COMMENT+1]; - int nch; - int a; - - nch = 0; - - if (length > MAX_COMMENT) length = MAX_COMMENT; // Truncate if it won't fit in our structure. - - for (a=2;aComments,Comment); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImageJPG::CxExifInfo::process_SOFn (const BYTE * Data, int marker) -{ - int data_precision, num_components; - - data_precision = Data[2]; - m_exifinfo->Height = Get16m((void*)(Data+3)); - m_exifinfo->Width = Get16m((void*)(Data+5)); - num_components = Data[7]; - - if (num_components == 3){ - m_exifinfo->IsColor = 1; - }else{ - m_exifinfo->IsColor = 0; - } - - m_exifinfo->Process = marker; - - //if (ShowTags) printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", - // ImageInfo.Width, ImageInfo.Height, num_components, data_precision); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * this will work only on a CxImageJPG object, if the image originally has valid EXIF data - \verbatim - CxImageJPG jpg; - CxIOFile in,out; - in.Open("D:\\exif_in.jpg","rb"); - out.Open("D:\\exif_out.jpg","w+b"); - jpg.Decode(&in); - if (jpg.IsValid()){ - jpg.RotateLeft(); - jpg.Encode(&out); - } - \endverbatim -*/ -bool CxImageJPG::CxExifInfo::EncodeExif(CxFile * hFile) -{ - int a; - - if (FindSection(M_SOS)==NULL){ - strcpy(m_szLastError,"Can't write exif : didn't read all"); - return false; - } - - // Initial static jpeg marker. - hFile->PutC(0xff); - hFile->PutC(0xd8); - - if (Sections[0].Type != M_EXIF && Sections[0].Type != M_JFIF){ - // The image must start with an exif or jfif marker. If we threw those away, create one. - static BYTE JfifHead[18] = { - 0xff, M_JFIF, - 0x00, 0x10, 'J' , 'F' , 'I' , 'F' , 0x00, 0x01, - 0x01, 0x01, 0x01, 0x2C, 0x01, 0x2C, 0x00, 0x00 - }; - hFile->Write(JfifHead, 18, 1); - } - - // Write all the misc sections - for (a=0;aPutC(0xff); - hFile->PutC((unsigned char)(Sections[a].Type)); - hFile->Write(Sections[a].Data, Sections[a].Size, 1); - } - - // Write the remaining image data. - hFile->Write(Sections[a].Data, Sections[a].Size, 1); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -void CxImageJPG::CxExifInfo::DiscardAllButExif() -{ - Section_t ExifKeeper; - Section_t CommentKeeper; - int a; - - memset(&ExifKeeper, 0, sizeof(ExifKeeper)); - memset(&CommentKeeper, 0, sizeof(ExifKeeper)); - - for (a=0;a Use it before Create() - */ -void CxImage::CopyInfo(const CxImage &src) -{ - if (pDib==NULL) memcpy(&info,&src.info,sizeof(CXIMAGEINFO)); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa Copy - */ -CxImage& CxImage::operator = (const CxImage& isrc) -{ - if (this != &isrc) Copy(isrc); - return *this; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Initializes or rebuilds the image. - * \param dwWidth: width - * \param dwHeight: height - * \param wBpp: bit per pixel, can be 1, 4, 8, 24 - * \param imagetype: (optional) set the image format, see ENUM_CXIMAGE_FORMATS - * \return pointer to the internal pDib object; NULL if an error occurs. - */ -void* CxImage::Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype) -{ - // destroy the existing image (if any) - if (!Destroy()) - return NULL; - - // prevent further actions if width or height are not vaild - if ((dwWidth == 0) || (dwHeight == 0)){ - strcpy(info.szLastError,"CxImage::Create : width and height must be greater than zero"); - return NULL; - } - - // Make sure bits per pixel is valid - if (wBpp <= 1) wBpp = 1; - else if (wBpp <= 4) wBpp = 4; - else if (wBpp <= 8) wBpp = 8; - else wBpp = 24; - - // limit memory requirements (and also a check for bad parameters) - if (((dwWidth*dwHeight*wBpp)>>3) > CXIMAGE_MAX_MEMORY || - ((dwWidth*dwHeight*wBpp)/wBpp) != (dwWidth*dwHeight)) - { - strcpy(info.szLastError,"CXIMAGE_MAX_MEMORY exceeded"); - return NULL; - } - - // set the correct bpp value - switch (wBpp){ - case 1: - head.biClrUsed = 2; break; - case 4: - head.biClrUsed = 16; break; - case 8: - head.biClrUsed = 256; break; - default: - head.biClrUsed = 0; - } - - //set the common image informations - info.dwEffWidth = ((((wBpp * dwWidth) + 31) / 32) * 4); - info.dwType = imagetype; - - // initialize BITMAPINFOHEADER - head.biSize = sizeof(BITMAPINFOHEADER); // - head.biWidth = dwWidth; // fill in width from parameter - head.biHeight = dwHeight; // fill in height from parameter - head.biPlanes = 1; // must be 1 - head.biBitCount = (WORD)wBpp; // from parameter - head.biCompression = BI_RGB; - head.biSizeImage = info.dwEffWidth * dwHeight; -// head.biXPelsPerMeter = 0; See SetXDPI -// head.biYPelsPerMeter = 0; See SetYDPI -// head.biClrImportant = 0; See SetClrImportant - - pDib = cxalloc(GetSize());//malloc(GetSize()); // alloc memory block to store our bitmap - if (!pDib){ - strcpy(info.szLastError,"CxImage::Create can't allocate memory"); - return NULL; - } - - //clear the palette - RGBQUAD* pal=GetPalette(); - if (pal) memset(pal,0,GetPaletteSize()); - //Destroy the existing selection -#if CXIMAGE_SUPPORT_SELECTION - if (pSelection) SelectionDelete(); -#endif //CXIMAGE_SUPPORT_SELECTION - //Destroy the existing alpha channel -#if CXIMAGE_SUPPORT_ALPHA - if (pAlpha) AlphaDelete(); -#endif //CXIMAGE_SUPPORT_ALPHA - - // use our bitmap info structure to fill in first part of - // our DIB with the BITMAPINFOHEADER - BITMAPINFOHEADER* lpbi; - lpbi = (BITMAPINFOHEADER*)(pDib); - *lpbi = head; - - info.pImage=GetBits(); - - return pDib; //return handle to the DIB -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return pointer to the image pixels. USE CAREFULLY - */ -BYTE* CxImage::GetBits(DWORD row) -{ - if (pDib){ - if (row) { - if (row<(DWORD)head.biHeight){ - return ((BYTE*)pDib + *(DWORD*)pDib + GetPaletteSize() + (info.dwEffWidth * row)); - } else { - return NULL; - } - } else { - return ((BYTE*)pDib + *(DWORD*)pDib + GetPaletteSize()); - } - } - return NULL; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return the size in bytes of the internal pDib object - */ -long CxImage::GetSize() -{ - return head.biSize + head.biSizeImage + GetPaletteSize(); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the coordinates are inside the image - * \return true if x and y are both inside the image - */ -bool CxImage::IsInside(long x, long y) -{ - return (0<=y && y 0) bval = 255; - } - if (GetBpp() == 4){ - bval = (BYTE)(17*(0x0F & bval)); - } - - memset(info.pImage,bval,head.biSizeImage); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Transfers the image from an existing source image. The source becomes empty. - * \return true if everything is ok - */ -bool CxImage::Transfer(CxImage &from, bool bTransferFrames /*=true*/) -{ - if (!Destroy()) - return false; - - memcpy(&head,&from.head,sizeof(BITMAPINFOHEADER)); - memcpy(&info,&from.info,sizeof(CXIMAGEINFO)); - - pDib = from.pDib; - pSelection = from.pSelection; - pAlpha = from.pAlpha; - ppLayers = from.ppLayers; - - memset(&from.head,0,sizeof(BITMAPINFOHEADER)); - memset(&from.info,0,sizeof(CXIMAGEINFO)); - from.pDib = from.pSelection = from.pAlpha = NULL; - from.ppLayers = NULL; - - if (bTransferFrames){ - DestroyFrames(); - ppFrames = from.ppFrames; - from.ppFrames = NULL; - } - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * (this) points to the same pDib owned by (*from), the image remains in (*from) - * but (this) has the access to the pixels. Use carefully !!! - */ -void CxImage::Ghost(const CxImage *from) -{ - if (from){ - memcpy(&head,&from->head,sizeof(BITMAPINFOHEADER)); - memcpy(&info,&from->info,sizeof(CXIMAGEINFO)); - pDib = from->pDib; - pSelection = from->pSelection; - pAlpha = from->pAlpha; - ppLayers = from->ppLayers; - ppFrames = from->ppFrames; - info.pGhost=(CxImage *)from; - } -} -//////////////////////////////////////////////////////////////////////////////// -/** - * turns a 16 or 32 bit bitfield image into a RGB image - */ -void CxImage::Bitfield2RGB(BYTE *src, DWORD redmask, DWORD greenmask, DWORD bluemask, BYTE bpp) -{ - switch (bpp){ - case 16: - { - DWORD ns[3]={0,0,0}; - // compute the number of shift for each mask - for (int i=0;i<16;i++){ - if ((redmask>>i)&0x01) ns[0]++; - if ((greenmask>>i)&0x01) ns[1]++; - if ((bluemask>>i)&0x01) ns[2]++; - } - ns[1]+=ns[0]; ns[2]+=ns[1]; ns[0]=8-ns[0]; ns[1]-=8; ns[2]-=8; - // dword aligned width for 16 bit image - long effwidth2=(((head.biWidth + 1) / 2) * 4); - WORD w; - long y2,y3,x2,x3; - BYTE *p=info.pImage; - // scan the buffer in reverse direction to avoid reallocations - for (long y=head.biHeight-1; y>=0; y--){ - y2=effwidth2*y; - y3=info.dwEffWidth*y; - for (long x=head.biWidth-1; x>=0; x--){ - x2 = 2*x+y2; - x3 = 3*x+y3; - w = (WORD)(src[x2]+256*src[1+x2]); - p[ x3]=(BYTE)((w & bluemask)<>ns[1]); - p[2+x3]=(BYTE)((w & redmask)>>ns[2]); - } - } - break; - } - case 32: - { - DWORD ns[3]={0,0,0}; - // compute the number of shift for each mask - for (int i=8;i<32;i+=8){ - if (redmask>>i) ns[0]++; - if (greenmask>>i) ns[1]++; - if (bluemask>>i) ns[2]++; - } - // dword aligned width for 32 bit image - long effwidth4 = head.biWidth * 4; - long y4,y3,x4,x3; - BYTE *p=info.pImage; - // scan the buffer in reverse direction to avoid reallocations - for (long y=head.biHeight-1; y>=0; y--){ - y4=effwidth4*y; - y3=info.dwEffWidth*y; - for (long x=head.biWidth-1; x>=0; x--){ - x4 = 4*x+y4; - x3 = 3*x+y3; - p[ x3]=src[ns[2]+x4]; - p[1+x3]=src[ns[1]+x4]; - p[2+x3]=src[ns[0]+x4]; - } - } - } - - } - return; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Creates an image from a generic buffer - * \param pArray: source memory buffer - * \param dwWidth: image width - * \param dwHeight: image height - * \param dwBitsperpixel: can be 1,4,8,24,32 - * \param dwBytesperline: line alignment, in bytes, for a single row stored in pArray - * \param bFlipImage: tune this parameter if the image is upsidedown - * \return true if everything is ok - */ -bool CxImage::CreateFromArray(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage) -{ - if (pArray==NULL) return false; - if (!((dwBitsperpixel==1)||(dwBitsperpixel==4)||(dwBitsperpixel==8)|| - (dwBitsperpixel==24)||(dwBitsperpixel==32))) return false; - - if (!Create(dwWidth,dwHeight,dwBitsperpixel)) return false; - - if (dwBitsperpixel<24) SetGrayPalette(); - -#if CXIMAGE_SUPPORT_ALPHA - if (dwBitsperpixel==32) AlphaCreate(); -#endif //CXIMAGE_SUPPORT_ALPHA - - BYTE *dst,*src; - - for (DWORD y = 0; yrgbRed,c1->rgbGreen,c1->rgbBlue); - int g2 = (int)RGB2GRAY(c2->rgbRed,c2->rgbGreen,c2->rgbBlue); - - return (g1-g2); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * simply calls "if (memblock) free(memblock);". - * Useful when calling Encode for a memory buffer, - * from a DLL compiled with different memory management options. - * CxImage::FreeMemory will use the same memory environment used by Encode. - * \author [livecn] - */ -void CxImage::FreeMemory(void* memblock) -{ - if (memblock) - cxfree(memblock);//free(memblock); -} -//////////////////////////////////////////////////////////////////////////////// -//EOF diff --git a/Externals/cximage/ximage.h b/Externals/cximage/ximage.h deleted file mode 100644 index 52c3617258c..00000000000 --- a/Externals/cximage/ximage.h +++ /dev/null @@ -1,735 +0,0 @@ -/* - * File: ximage.h - * Purpose: General Purpose Image Class - */ -/* - -------------------------------------------------------------------------------- - - COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: - - CxImage version 6.0.0 02/Feb/2008 - - CxImage : Copyright (C) 2001 - 2008, 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 - -///////////////////////////////////////////////////////////////////////////// -#include "xfile.h" -#include "xiofile.h" -#include "xmemfile.h" -#include "ximadef.h" // 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 -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 + 1 -}; - -///////////////////////////////////////////////////////////////////////////// -// CxImage class -///////////////////////////////////////////////////////////////////////////// -class DLL_EXP CxImage -{ -//extensible information collector -typedef struct tagCxImageInfo { - DWORD dwEffWidth; ///< DWORD aligned scan line width - BYTE* 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 - DWORD dwType; ///< original image format - char szLastError[256]; ///< debugging - long nProgress; ///< monitor - long nEscape; ///< escape - long nBkgndIndex; ///< used for GIF, PNG, MNG - RGBQUAD nBkgndColor; ///< used for RGB transparency - float fQuality; ///< used for JPEG, JPEG2000 (0.0f ... 100.0f) - BYTE nJpegScale; ///< used for JPEG [ignacio] - long nFrame; ///< used for TIF, GIF, MNG : actual frame - long nNumFrames; ///< used for TIF, GIF, MNG : total number of frames - DWORD dwFrameDelay; ///< used for GIF, MNG - long xDPI; ///< horizontal resolution - long yDPI; ///< vertical resolution - RECT rSelectionBox; ///< bounding rectangle - BYTE nAlphaMax; ///< max opacity (fade) - bool bAlphaPaletteEnabled; ///< true if alpha values in the palette are enabled. - bool bEnabled; ///< enables the painting functions - long xOffset; - long yOffset; - DWORD 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 - BYTE last_c_index; - bool last_c_isvalid; - long nNumLayers; - DWORD dwFlags; ///< 0x??00000 = reserved, 0x00??0000 = blend mode, 0x0000???? = layer id - user flags - BYTE dispmeth; - bool bGetAllFrames; - bool bLittleEndianHost; - -} CXIMAGEINFO; - -public: - //public structures -struct rgb_color { BYTE r,g,b; }; - -#if CXIMAGE_SUPPORT_WINDOWS -// 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 - long align; ///< DT_CENTER, DT_RIGHT, DT_LEFT aligment for multiline text - BYTE smooth; ///< text smoothing option. Default is false. - BYTE 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) - BYTE b_outline; ///< outline width for background (zero: no outline) - BYTE 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(DWORD imagetype = 0); - CxImage(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); - CxImage(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true); - CxImage(const TCHAR * filename, DWORD imagetype); // For UNICODE support: char -> TCHAR - CxImage(FILE * stream, DWORD imagetype); - CxImage(CxFile * stream, DWORD imagetype); - CxImage(BYTE * buffer, DWORD size, DWORD imagetype); - virtual ~CxImage() { DestroyFrames(); Destroy(); }; - CxImage& operator = (const CxImage&); -//@} - -/** \addtogroup Initialization */ //@{ - void* Create(DWORD dwWidth, DWORD dwHeight, DWORD wBpp, DWORD imagetype = 0); - bool Destroy(); - bool DestroyFrames(); - void Clear(BYTE 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(BYTE* pArray,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); - bool CreateFromMatrix(BYTE** ppMatrix,DWORD dwWidth,DWORD dwHeight,DWORD dwBitsperpixel, DWORD dwBytesperline, bool bFlipImage); - void FreeMemory(void* memblock); - - DWORD Dump(BYTE * dst); - DWORD UnDump(const BYTE * src); - DWORD DumpSize(); - -//@} - -/** \addtogroup Attributes */ //@{ - long GetSize(); - BYTE* GetBits(DWORD row = 0); - BYTE GetColorType(); - void* GetDIB() const; - DWORD GetHeight() const; - DWORD GetWidth() const; - DWORD GetEffWidth() const; - DWORD GetNumColors() const; - WORD GetBpp() const; - DWORD GetType() const; - const char* GetLastError(); - static const TCHAR* GetVersion(); - static const float GetVersionNumber(); - - DWORD GetFrameDelay() const; - void SetFrameDelay(DWORD d); - - void GetOffset(long *x,long *y); - void SetOffset(long x,long y); - - BYTE GetJpegQuality() const; - void SetJpegQuality(BYTE q); - float GetJpegQualityF() const; - void SetJpegQualityF(float q); - - BYTE GetJpegScale() const; - void SetJpegScale(BYTE q); - - long GetXDPI() const; - long GetYDPI() const; - void SetXDPI(long dpi); - void SetYDPI(long dpi); - - DWORD GetClrImportant() const; - void SetClrImportant(DWORD ncolors = 0); - - long GetProgress() const; - long GetEscape() const; - void SetProgress(long p); - void SetEscape(long i); - - long GetTransIndex() const; - RGBQUAD GetTransColor(); - void SetTransIndex(long idx); - void SetTransColor(RGBQUAD rgb); - bool IsTransparent() const; - - DWORD GetCodecOption(DWORD imagetype = 0); - bool SetCodecOption(DWORD opt, DWORD imagetype = 0); - - DWORD GetFlags() const; - void SetFlags(DWORD flags, bool bLockReservedFlags = true); - - BYTE GetDisposalMethod() const; - void SetDisposalMethod(BYTE dm); - - bool SetType(DWORD type); - - static DWORD GetNumTypes(); - static DWORD GetTypeIdFromName(const TCHAR* ext); - static DWORD GetTypeIdFromIndex(const DWORD index); - static DWORD GetTypeIndexFromId(const DWORD id); - - bool GetRetreiveAllFrames() const; - void SetRetreiveAllFrames(bool flag); - CxImage * GetFrame(long 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); - DWORD GetPaletteSize(); - RGBQUAD* GetPalette() const; - RGBQUAD GetPaletteColor(BYTE idx); - bool GetPaletteColor(BYTE i, BYTE* r, BYTE* g, BYTE* b); - BYTE GetNearestIndex(RGBQUAD c); - void BlendPalette(COLORREF cr,long perc); - void SetGrayPalette(); - void SetPalette(DWORD n, BYTE *r, BYTE *g, BYTE *b); - void SetPalette(RGBQUAD* pPal,DWORD nColors=256); - void SetPalette(rgb_color *rgb,DWORD nColors=256); - void SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha=0); - void SetPaletteColor(BYTE idx, RGBQUAD c); - void SetPaletteColor(BYTE idx, COLORREF cr); - void SwapIndex(BYTE idx1, BYTE idx2); - void SwapRGB2BGR(); - void SetStdPalette(); -//@} - -/** \addtogroup Pixel */ //@{ - bool IsInside(long x, long y); - bool IsTransparent(long x,long y); - bool GetTransparentMask(CxImage* iDst = 0); - RGBQUAD GetPixelColor(long x,long y, bool bGetAlpha = true); - BYTE GetPixelIndex(long x,long y); - BYTE GetPixelGray(long x, long y); - void SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false); - void SetPixelColor(long x,long y,COLORREF cr); - void SetPixelIndex(long x,long y,BYTE i); - void DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha=false); - void DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr); - void BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha = false); -//@} - -protected: -/** \addtogroup Protected */ //@{ - BYTE BlindGetPixelIndex(const long x,const long y); - RGBQUAD BlindGetPixelColor(const long x,const long y, bool bGetAlpha = true); - void *BlindGetPixelPointer(const long x,const long y); - void BlindSetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha = false); - void BlindSetPixelIndex(long x,long y,BYTE 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(long &x, long &y, OverflowMethod const ofMethod); - RGBQUAD GetPixelColorWithOverflow(long x, long 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 - long Blt(HDC pDC, long x=0, long y=0); - HBITMAP MakeBitmap(HDC hdc = NULL); - HANDLE CopyToHandle(); - bool CreateFromHANDLE(HANDLE hMem); //Windows objects (clipboard) - bool CreateFromHBITMAP(HBITMAP hbmp, HPALETTE hpal=0); //Windows resource - bool CreateFromHICON(HICON hico); - long Draw(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false); - long Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false); - long Stretch(HDC hdc, long xoffset, long yoffset, long xsize, long ysize, DWORD dwRop = SRCCOPY); - long Stretch(HDC hdc, const RECT& rect, DWORD dwRop = SRCCOPY); - long Tile(HDC hdc, RECT *rc); - long Draw2(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1); - long Draw2(HDC hdc, const RECT& rect); - //long DrawString(HDC hdc, long x, long y, const char* text, RGBQUAD color, const char* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); - long DrawString(HDC hdc, long x, long y, const TCHAR* text, RGBQUAD color, const TCHAR* font, long lSize=0, long lWeight=400, BYTE bItalic=0, BYTE bUnderline=0, bool bSetAlpha=false); - // extensions - long DrawStringEx(HDC hdc, long x, long y, CXTEXTINFO *pTextType, bool bSetAlpha=false ); - void InitTextInfo( CXTEXTINFO *txt ); -#endif //CXIMAGE_SUPPORT_WINDOWS -//@} - - // file operations -#if CXIMAGE_SUPPORT_DECODE -/** \addtogroup Decode */ //@{ -#ifdef WIN32 - //bool Load(LPCWSTR filename, DWORD imagetype=0); - bool LoadResource(HRSRC hRes, DWORD imagetype, HMODULE hModule=NULL); -#endif - // For UNICODE support: char -> TCHAR - bool Load(const TCHAR* filename, DWORD imagetype=0); - //bool Load(const char * filename, DWORD imagetype=0); - bool Decode(FILE * hFile, DWORD imagetype); - bool Decode(CxFile * hFile, DWORD imagetype); - bool Decode(BYTE * buffer, DWORD size, DWORD imagetype); - - bool CheckFormat(CxFile * hFile, DWORD imagetype = 0); - bool CheckFormat(BYTE * buffer, DWORD size, DWORD 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, DWORD imagetype=0); -#endif - // For UNICODE support: char -> TCHAR - bool Save(const TCHAR* filename, DWORD imagetype); - //bool Save(const char * filename, DWORD imagetype=0); - bool Encode(FILE * hFile, DWORD imagetype); - bool Encode(CxFile * hFile, DWORD imagetype); - bool Encode(CxFile * hFile, CxImage ** pImages, int pagecount, DWORD imagetype); - bool Encode(FILE *hFile, CxImage ** pImages, int pagecount, DWORD imagetype); - bool Encode(BYTE * &buffer, long &size, DWORD imagetype); - - bool Encode2RGBA(CxFile *hFile, bool bFlipY = false); - bool Encode2RGBA(BYTE * &buffer, long &size, bool bFlipY = false); -//@} -#endif //CXIMAGE_SUPPORT_ENCODE - -/** \addtogroup Attributes */ //@{ - //misc. - bool IsValid() const; - bool IsEnabled() const; - void Enable(bool enable=true); - - // frame operations - long GetNumFrames() const; - long GetFrame() const; - void SetFrame(long 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); -//@} -#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(long newx, long newy, int mode = 1, CxImage* iDst = NULL); - bool Resample2(long newx, long newy, InterpolationMethod const inMethod=IM_BICUBIC2, - OverflowMethod const ofMethod=OM_REPEAT, CxImage* const iDst = NULL, - bool const disableAveraging=false); - bool DecreaseBpp(DWORD nbit, bool errordiffusion, RGBQUAD* ppal = 0, DWORD clrimportant = 0); - bool IncreaseBpp(DWORD nbit); - bool Dither(long method = 0); - bool Crop(long left, long top, long right, long bottom, CxImage* iDst = NULL); - bool Crop(const RECT& rect, CxImage* iDst = NULL); - bool CropRotatedRectangle( long topx, long topy, long width, long height, float angle, CxImage* iDst = NULL); - bool Skew(float xgain, float ygain, long xpivot=0, long ypivot=0, bool bEnableInterpolation = false); - bool Expand(long left, long top, long right, long bottom, RGBQUAD canvascolor, CxImage* iDst = 0); - bool Expand(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); - bool Thumbnail(long newx, long newy, RGBQUAD canvascolor, CxImage* iDst = 0); - bool CircleTransform(int type,long rmax=0,float Koeff=1.0f); - bool RedEyeRemove(float strength = 0.8f); - bool QIShrink(long newx, long newy, CxImage* const iDst = NULL, bool bChangeBpp = false); - -//@} -#endif //CXIMAGE_SUPPORT_TRANSFORMATION - -#if CXIMAGE_SUPPORT_DSP -/** \addtogroup DSP */ //@{ - bool Contour(); - bool HistogramStretch(long method = 0, double threshold = 0); - bool HistogramEqualize(); - bool HistogramNormalize(); - bool HistogramRoot(); - bool HistogramLog(); - long Histogram(long* red, long* green = 0, long* blue = 0, long* gray = 0, long colorspace = 0); - bool Jitter(long radius=2); - bool Repair(float radius = 0.25f, long niterations = 1, long colorspace = 0); - bool Combine(CxImage* r,CxImage* g,CxImage* b,CxImage* a, long colorspace = 0); - bool FFT2(CxImage* srcReal, CxImage* srcImag, CxImage* dstReal, CxImage* dstImag, long direction = 1, bool bForceFFT = true, bool bMagnitude = true); - bool Noise(long level); - bool Median(long Ksize=3); - bool Gamma(float gamma); - bool GammaRGB(float gammaR, float gammaG, float gammaB); - bool ShiftRGB(long r, long g, long b); - bool Threshold(BYTE level); - bool Threshold(CxImage* pThresholdMask); - bool Threshold2(BYTE level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha = false); - bool Colorize(BYTE hue, BYTE sat, float blend = 1.0f); - bool Light(long brightness, long contrast = 0); - float Mean(); - bool Filter(long* kernel, long Ksize, long Kfactor, long Koffset); - bool Erode(long Ksize=2); - bool Dilate(long Ksize=2); - bool Edge(long Ksize=2); - void HuePalette(float correction=1); - enum ImageOpType { OpAdd, OpAnd, OpXor, OpOr, OpMask, OpSrcCopy, OpDstCopy, OpSub, OpSrcBlend, OpScreen, OpAvg }; - void Mix(CxImage & imgsrc2, ImageOpType op, long lXOffset = 0, long lYOffset = 0, bool bMixAlpha = false); - void MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset); - bool UnsharpMask(float radius = 5.0f, float amount = 0.5f, int threshold = 0); - bool Lut(BYTE* pLut); - bool Lut(BYTE* pLutR, BYTE* pLutG, BYTE* pLutB, BYTE* pLutA = 0); - bool GaussianBlur(float radius = 1.0f, CxImage* iDst = 0); - bool TextBlur(BYTE threshold = 100, BYTE decay = 2, BYTE max_depth = 5, bool bBlurHorizontal = true, bool bBlurVertical = true, CxImage* iDst = 0); - bool SelectiveBlur(float radius = 1.0f, BYTE threshold = 25, CxImage* iDst = 0); - bool Solarize(BYTE level = 128, bool bLinkedChannels = true); - bool FloodFill(const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE tolerance = 0, - BYTE nOpacity = 255, const bool bSelectFilledArea = false, const BYTE nSelectionLevel = 255); - bool Saturate(const long saturation, const long colorspace = 1); - bool ConvertColorSpace(const long dstColorSpace, const long srcColorSpace); - int OptimalThreshold(long method = 0, RECT * pBox = 0, CxImage* pContrastMask = 0); - bool AdaptiveThreshold(long method = 0, long nBoxSize = 64, CxImage* pContrastMask = 0, long nBias = 0, float fGlobalLocalBalance = 0.5f); - -//@} - -protected: -/** \addtogroup Protected */ //@{ - bool IsPowerof2(long x); - bool FFT(int dir,int m,double *x,double *y); - bool DFT(int dir,long m,double *x1,double *y1,double *x2,double *y2); - bool RepairChannel(CxImage *ch, float radius); - // - int gen_convolve_matrix (float radius, float **cmatrix_p); - float* gen_lookup_table (float *cmatrix, int cmatrix_length); - void blur_line (float *ctable, float *cmatrix, int cmatrix_length, BYTE* cur_col, BYTE* dest_col, int y, long bytes); - void blur_text (BYTE threshold, BYTE decay, BYTE max_depth, CxImage* iSrc, CxImage* iDst, BYTE 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); -//@} - -#if CXIMAGE_SUPPORT_SELECTION -/** \addtogroup Selection */ //@{ - bool SelectionClear(BYTE level = 0); - bool SelectionCreate(); - bool SelectionDelete(); - bool SelectionInvert(); - bool SelectionMirror(); - bool SelectionFlip(); - bool SelectionAddRect(RECT r, BYTE level = 255); - bool SelectionAddEllipse(RECT r, BYTE level = 255); - bool SelectionAddPolygon(POINT *points, long npoints, BYTE level = 255); - bool SelectionAddColor(RGBQUAD c, BYTE level = 255); - bool SelectionAddPixel(long x, long y, BYTE level = 255); - bool SelectionCopy(CxImage &from); - bool SelectionIsInside(long x, long y); - bool SelectionIsValid(); - void SelectionGetBox(RECT& r); - bool SelectionToHRGN(HRGN& region); - bool SelectionSplit(CxImage *dest); - BYTE SelectionGet(const long x,const long y); - bool SelectionSet(CxImage &from); - void SelectionRebuildBox(); - BYTE* SelectionGetPointer(const long x = 0,const long y = 0); -//@} - -protected: -/** \addtogroup Protected */ //@{ - bool BlindSelectionIsInside(long x, long y); - BYTE BlindSelectionGet(const long x,const long y); - void SelectionSet(const long x,const long y,const BYTE 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(BYTE level); - bool AlphaSet(CxImage &from); - void AlphaSet(const long x,const long y,const BYTE level); - BYTE AlphaGet(const long x,const long y); - BYTE AlphaGetMax() const; - void AlphaSetMax(BYTE nAlphaMax); - bool AlphaIsValid(); - BYTE* AlphaGetPointer(const long x = 0,const long y = 0); - bool AlphaFromTransparency(); - - void AlphaPaletteClear(); - void AlphaPaletteEnable(bool enable=true); - bool AlphaPaletteIsEnabled(); - bool AlphaPaletteIsValid(); - bool AlphaPaletteSplit(CxImage *dest); -//@} - -protected: -/** \addtogroup Protected */ //@{ - BYTE BlindAlphaGet(const long x,const long y); -//@} -#endif //CXIMAGE_SUPPORT_ALPHA - -public: -#if CXIMAGE_SUPPORT_LAYERS -/** \addtogroup Layers */ //@{ - bool LayerCreate(long position = -1); - bool LayerDelete(long position = -1); - void LayerDeleteAll(); - CxImage* GetLayer(long position); - CxImage* GetParent() const; - long GetNumLayers() const; - long LayerDrawAll(HDC hdc, long x=0, long y=0, long cx = -1, long cy = -1, RECT* pClipRect = 0, bool bSmooth = false); - long LayerDrawAll(HDC hdc, const RECT& rect, RECT* pClipRect=NULL, bool bSmooth = false); -//@} -#endif //CXIMAGE_SUPPORT_LAYERS - -protected: -/** \addtogroup Protected */ //@{ - void Startup(DWORD imagetype = 0); - void CopyInfo(const CxImage &src); - void Ghost(const CxImage *src); - void RGBtoBGR(BYTE *buffer, int length); - static float HueToRGB(float n1,float n2, float hue); - void Bitfield2RGB(BYTE *src, DWORD redmask, DWORD greenmask, DWORD bluemask, BYTE bpp); - static int CompareColors(const void *elem1, const void *elem2); - short cx_ntohs(const short word); - long cx_ntohl(const long dword); - void cx_bihtoh(BITMAPINFOHEADER* bih); - - void* pDib; //contains the header, the palette, the pixels - BITMAPINFOHEADER head; //standard header - CXIMAGEINFO info; //extended information - BYTE* pSelection; //selected region - BYTE* pAlpha; //alpha channel - CxImage** ppLayers; //generic layers - CxImage** ppFrames; -//@} -}; - -//////////////////////////////////////////////////////////////////////////// -#endif // !defined(__CXIMAGE_H) diff --git a/Externals/cximage/ximainfo.cpp b/Externals/cximage/ximainfo.cpp deleted file mode 100644 index 3b6c20b031e..00000000000 --- a/Externals/cximage/ximainfo.cpp +++ /dev/null @@ -1,929 +0,0 @@ -// ximainfo.cpp : main attributes -/* 03/10/2004 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximage.h" - -#if defined(WIN32) || defined(_WIN32_WCE) -#include -#else -#define _tcsnicmp(a,b,c) strcasecmp(a,b) -#define _T(x) x -#endif - -//////////////////////////////////////////////////////////////////////////////// -/** - * \return the color used for transparency, and/or for background color - */ -RGBQUAD CxImage::GetTransColor() -{ - if (head.biBitCount<24 && info.nBkgndIndex>=0) return GetPaletteColor((BYTE)info.nBkgndIndex); - return info.nBkgndColor; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Gets the index used for transparency. Returns -1 for no transparancy. - */ -long CxImage::GetTransIndex() const -{ - return info.nBkgndIndex; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the index used for transparency with 1, 4 and 8 bpp images. Set to -1 to remove the effect. - */ -void CxImage::SetTransIndex(long idx) -{ - if (idx<(long)head.biClrUsed) - info.nBkgndIndex = idx; - else - info.nBkgndIndex = 0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the color used for transparency with 24 bpp images. - * You must call SetTransIndex(0) to enable the effect, SetTransIndex(-1) to disable it. - */ -void CxImage::SetTransColor(RGBQUAD rgb) -{ - rgb.rgbReserved=0; - info.nBkgndColor = rgb; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::IsTransparent() const -{ - return info.nBkgndIndex>=0; // -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Returns true if the image has 256 colors or less. - */ -bool CxImage::IsIndexed() const -{ - return head.biClrUsed!=0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return 1 = indexed, 2 = RGB, 4 = RGBA - */ -BYTE CxImage::GetColorType() -{ - BYTE b = (BYTE)((head.biBitCount>8) ? 2 /*COLORTYPE_COLOR*/ : 1 /*COLORTYPE_PALETTE*/); -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) b = 4 /*COLORTYPE_ALPHA*/; -#endif //CXIMAGE_SUPPORT_ALPHA - return b; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return Resolution for TIFF, JPEG, PNG and BMP formats. - */ -long CxImage::GetXDPI() const -{ - return info.xDPI; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return Resolution for TIFF, JPEG, PNG and BMP formats. - */ -long CxImage::GetYDPI() const -{ - return info.yDPI; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Set resolution for TIFF, JPEG, PNG and BMP formats. - */ -void CxImage::SetXDPI(long dpi) -{ - if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI; - info.xDPI = dpi; - head.biXPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5); - if (pDib) ((BITMAPINFOHEADER*)pDib)->biXPelsPerMeter = head.biXPelsPerMeter; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Set resolution for TIFF, JPEG, PNG and BMP formats. - */ -void CxImage::SetYDPI(long dpi) -{ - if (dpi<=0) dpi = CXIMAGE_DEFAULT_DPI; - info.yDPI = dpi; - head.biYPelsPerMeter = (long) floor(dpi * 10000.0 / 254.0 + 0.5); - if (pDib) ((BITMAPINFOHEADER*)pDib)->biYPelsPerMeter = head.biYPelsPerMeter; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa SetFlags - */ -DWORD CxImage::GetFlags() const -{ - return info.dwFlags; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Image flags, for future use - * \param flags - * - 0x??00000 = reserved for 16 bit, CMYK, multilayer - * - 0x00??0000 = blend modes - * - 0x0000???? = layer id or user flags - * - * \param bLockReservedFlags protects the "reserved" and "blend modes" flags - */ -void CxImage::SetFlags(DWORD flags, bool bLockReservedFlags) -{ - if (bLockReservedFlags) info.dwFlags = flags & 0x0000ffff; - else info.dwFlags = flags; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa SetCodecOption - */ -DWORD CxImage::GetCodecOption(DWORD imagetype) -{ - imagetype = GetTypeIndexFromId(imagetype); - if (imagetype==0){ - imagetype = GetTypeIndexFromId(GetType()); - } - return info.dwCodecOpt[imagetype]; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Encode option for GIF, TIF and JPG. - * - GIF : 0 = LZW (default), 1 = none, 2 = RLE. - * - TIF : 0 = automatic (default), or a valid compression code as defined in "tiff.h" (COMPRESSION_NONE = 1, COMPRESSION_CCITTRLE = 2, ...) - * - JPG : valid values stored in enum CODEC_OPTION ( ENCODE_BASELINE = 0x01, ENCODE_PROGRESSIVE = 0x10, ...) - * - RAW : valid values stored in enum CODEC_OPTION ( DECODE_QUALITY_LIN = 0x00, DECODE_QUALITY_VNG = 0x01, ...) - * - * \return true if everything is ok - */ -bool CxImage::SetCodecOption(DWORD opt, DWORD imagetype) -{ - imagetype = GetTypeIndexFromId(imagetype); - if (imagetype==0){ - imagetype = GetTypeIndexFromId(GetType()); - } - info.dwCodecOpt[imagetype] = opt; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return internal hDib object.. - */ -void* CxImage::GetDIB() const -{ - return pDib; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetHeight() const -{ - return head.biHeight; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetWidth() const -{ - return head.biWidth; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return DWORD aligned width of the image. - */ -DWORD CxImage::GetEffWidth() const -{ - return info.dwEffWidth; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return 2, 16, 256; 0 for RGB images. - */ -DWORD CxImage::GetNumColors() const -{ - return head.biClrUsed; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return: 1, 4, 8, 24. - */ -WORD CxImage::GetBpp() const -{ - return head.biBitCount; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return original image format - * \sa ENUM_CXIMAGE_FORMATS. - */ -DWORD CxImage::GetType() const -{ - return info.dwType; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * change image format identifier - * \sa ENUM_CXIMAGE_FORMATS. - */ -bool CxImage::SetType(DWORD type) -{ - switch (type){ -#if CXIMAGE_SUPPORT_BMP - case CXIMAGE_FORMAT_BMP: -#endif -#if CXIMAGE_SUPPORT_GIF - case CXIMAGE_FORMAT_GIF: -#endif -#if CXIMAGE_SUPPORT_JPG - case CXIMAGE_FORMAT_JPG: -#endif -#if CXIMAGE_SUPPORT_PNG - case CXIMAGE_FORMAT_PNG: -#endif -#if CXIMAGE_SUPPORT_MNG - case CXIMAGE_FORMAT_MNG: -#endif -#if CXIMAGE_SUPPORT_ICO - case CXIMAGE_FORMAT_ICO: -#endif -#if CXIMAGE_SUPPORT_TIF - case CXIMAGE_FORMAT_TIF: -#endif -#if CXIMAGE_SUPPORT_TGA - case CXIMAGE_FORMAT_TGA: -#endif -#if CXIMAGE_SUPPORT_PCX - case CXIMAGE_FORMAT_PCX: -#endif -#if CXIMAGE_SUPPORT_WBMP - case CXIMAGE_FORMAT_WBMP: -#endif -#if CXIMAGE_SUPPORT_WMF - case CXIMAGE_FORMAT_WMF: -#endif -#if CXIMAGE_SUPPORT_JBG - case CXIMAGE_FORMAT_JBG: -#endif -#if CXIMAGE_SUPPORT_JP2 - case CXIMAGE_FORMAT_JP2: -#endif -#if CXIMAGE_SUPPORT_JPC - case CXIMAGE_FORMAT_JPC: -#endif -#if CXIMAGE_SUPPORT_PGX - case CXIMAGE_FORMAT_PGX: -#endif -#if CXIMAGE_SUPPORT_PNM - case CXIMAGE_FORMAT_PNM: -#endif -#if CXIMAGE_SUPPORT_RAS - case CXIMAGE_FORMAT_RAS: -#endif -#if CXIMAGE_SUPPORT_SKA - case CXIMAGE_FORMAT_SKA: -#endif -#if CXIMAGE_SUPPORT_RAW - case CXIMAGE_FORMAT_RAW: -#endif - info.dwType = type; - return true; - } - info.dwType = CXIMAGE_FORMAT_UNKNOWN; - return false; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetNumTypes() -{ - return CMAX_IMAGE_FORMATS-1; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetTypeIdFromName(const TCHAR* ext) -{ -#if CXIMAGE_SUPPORT_BMP - if (_tcsnicmp(ext,_T("bmp"),3)==0 ) return CXIMAGE_FORMAT_BMP; -#endif -#if CXIMAGE_SUPPORT_JPG - if (_tcsnicmp(ext,_T("jpg"),3)==0 || - _tcsnicmp(ext,_T("jpe"),3)==0 || - _tcsnicmp(ext,_T("jfi"),3)==0 ) return CXIMAGE_FORMAT_JPG; -#endif -#if CXIMAGE_SUPPORT_GIF - if (_tcsnicmp(ext,_T("gif"),3)==0 ) return CXIMAGE_FORMAT_GIF; -#endif -#if CXIMAGE_SUPPORT_PNG - if (_tcsnicmp(ext,_T("png"),3)==0 ) return CXIMAGE_FORMAT_PNG; -#endif -#if CXIMAGE_SUPPORT_ICO - if (_tcsnicmp(ext,_T("ico"),3)==0 || - _tcsnicmp(ext,_T("cur"),3)==0 ) return CXIMAGE_FORMAT_ICO; -#endif -#if CXIMAGE_SUPPORT_TIF - if (_tcsnicmp(ext,_T("tif"),3)==0 ) return CXIMAGE_FORMAT_TIF; -#endif -#if CXIMAGE_SUPPORT_TGA - if (_tcsnicmp(ext,_T("tga"),3)==0 ) return CXIMAGE_FORMAT_TGA; -#endif -#if CXIMAGE_SUPPORT_PCX - if (_tcsnicmp(ext,_T("pcx"),3)==0 ) return CXIMAGE_FORMAT_PCX; -#endif -#if CXIMAGE_SUPPORT_WBMP - if (_tcsnicmp(ext,_T("wbm"),3)==0 ) return CXIMAGE_FORMAT_WBMP; -#endif -#if CXIMAGE_SUPPORT_WMF - if (_tcsnicmp(ext,_T("wmf"),3)==0 || - _tcsnicmp(ext,_T("emf"),3)==0 ) return CXIMAGE_FORMAT_WMF; -#endif -#if CXIMAGE_SUPPORT_JP2 - if (_tcsnicmp(ext,_T("jp2"),3)==0 || - _tcsnicmp(ext,_T("j2k"),3)==0 ) return CXIMAGE_FORMAT_JP2; -#endif -#if CXIMAGE_SUPPORT_JPC - if (_tcsnicmp(ext,_T("jpc"),3)==0 || - _tcsnicmp(ext,_T("j2c"),3)==0 ) return CXIMAGE_FORMAT_JPC; -#endif -#if CXIMAGE_SUPPORT_PGX - if (_tcsnicmp(ext,_T("pgx"),3)==0 ) return CXIMAGE_FORMAT_PGX; -#endif -#if CXIMAGE_SUPPORT_RAS - if (_tcsnicmp(ext,_T("ras"),3)==0 ) return CXIMAGE_FORMAT_RAS; -#endif -#if CXIMAGE_SUPPORT_PNM - if (_tcsnicmp(ext,_T("pnm"),3)==0 || - _tcsnicmp(ext,_T("pgm"),3)==0 || - _tcsnicmp(ext,_T("ppm"),3)==0 ) return CXIMAGE_FORMAT_PNM; -#endif -#if CXIMAGE_SUPPORT_JBG - if (_tcsnicmp(ext,_T("jbg"),3)==0 ) return CXIMAGE_FORMAT_JBG; -#endif -#if CXIMAGE_SUPPORT_MNG - if (_tcsnicmp(ext,_T("mng"),3)==0 || - _tcsnicmp(ext,_T("jng"),3)==0 ) return CXIMAGE_FORMAT_MNG; -#endif -#if CXIMAGE_SUPPORT_SKA - if (_tcsnicmp(ext,_T("ska"),3)==0 ) return CXIMAGE_FORMAT_SKA; -#endif -#if CXIMAGE_SUPPORT_RAW - if (_tcsnicmp(ext,_T("nef"),3)==0 || - _tcsnicmp(ext,_T("crw"),3)==0 || - _tcsnicmp(ext,_T("cr2"),3)==0 || - _tcsnicmp(ext,_T("dng"),3)==0 || - _tcsnicmp(ext,_T("arw"),3)==0 || - _tcsnicmp(ext,_T("erf"),3)==0 || - _tcsnicmp(ext,_T("3fr"),3)==0 || - _tcsnicmp(ext,_T("dcr"),3)==0 || - _tcsnicmp(ext,_T("raw"),3)==0 || - _tcsnicmp(ext,_T("x3f"),3)==0 || - _tcsnicmp(ext,_T("mef"),3)==0 || - _tcsnicmp(ext,_T("raf"),3)==0 || - _tcsnicmp(ext,_T("mrw"),3)==0 || - _tcsnicmp(ext,_T("pef"),3)==0 || - _tcsnicmp(ext,_T("sr2"),3)==0 || - _tcsnicmp(ext,_T("orf"),3)==0 ) return CXIMAGE_FORMAT_RAW; -#endif - - return CXIMAGE_FORMAT_UNKNOWN; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetTypeIdFromIndex(const DWORD index) -{ - DWORD n; - - n=0; if (index == n) return CXIMAGE_FORMAT_UNKNOWN; -#if CXIMAGE_SUPPORT_BMP - n++; if (index == n) return CXIMAGE_FORMAT_BMP; -#endif -#if CXIMAGE_SUPPORT_GIF - n++; if (index == n) return CXIMAGE_FORMAT_GIF; -#endif -#if CXIMAGE_SUPPORT_JPG - n++; if (index == n) return CXIMAGE_FORMAT_JPG; -#endif -#if CXIMAGE_SUPPORT_PNG - n++; if (index == n) return CXIMAGE_FORMAT_PNG; -#endif -#if CXIMAGE_SUPPORT_ICO - n++; if (index == n) return CXIMAGE_FORMAT_ICO; -#endif -#if CXIMAGE_SUPPORT_TIF - n++; if (index == n) return CXIMAGE_FORMAT_TIF; -#endif -#if CXIMAGE_SUPPORT_TGA - n++; if (index == n) return CXIMAGE_FORMAT_TGA; -#endif -#if CXIMAGE_SUPPORT_PCX - n++; if (index == n) return CXIMAGE_FORMAT_PCX; -#endif -#if CXIMAGE_SUPPORT_WBMP - n++; if (index == n) return CXIMAGE_FORMAT_WBMP; -#endif -#if CXIMAGE_SUPPORT_WMF - n++; if (index == n) return CXIMAGE_FORMAT_WMF; -#endif -#if CXIMAGE_SUPPORT_JP2 - n++; if (index == n) return CXIMAGE_FORMAT_JP2; -#endif -#if CXIMAGE_SUPPORT_JPC - n++; if (index == n) return CXIMAGE_FORMAT_JPC; -#endif -#if CXIMAGE_SUPPORT_PGX - n++; if (index == n) return CXIMAGE_FORMAT_PGX; -#endif -#if CXIMAGE_SUPPORT_PNM - n++; if (index == n) return CXIMAGE_FORMAT_PNM; -#endif -#if CXIMAGE_SUPPORT_RAS - n++; if (index == n) return CXIMAGE_FORMAT_RAS; -#endif -#if CXIMAGE_SUPPORT_JBG - n++; if (index == n) return CXIMAGE_FORMAT_JBG; -#endif -#if CXIMAGE_SUPPORT_MNG - n++; if (index == n) return CXIMAGE_FORMAT_MNG; -#endif -#if CXIMAGE_SUPPORT_SKA - n++; if (index == n) return CXIMAGE_FORMAT_SKA; -#endif -#if CXIMAGE_SUPPORT_RAW - n++; if (index == n) return CXIMAGE_FORMAT_RAW; -#endif - - return CXIMAGE_FORMAT_UNKNOWN; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::GetTypeIndexFromId(const DWORD id) -{ - DWORD n; - - n=0; if (id == CXIMAGE_FORMAT_UNKNOWN) return n; -#if CXIMAGE_SUPPORT_BMP - n++; if (id == CXIMAGE_FORMAT_BMP) return n; -#endif -#if CXIMAGE_SUPPORT_GIF - n++; if (id == CXIMAGE_FORMAT_GIF) return n; -#endif -#if CXIMAGE_SUPPORT_JPG - n++; if (id == CXIMAGE_FORMAT_JPG) return n; -#endif -#if CXIMAGE_SUPPORT_PNG - n++; if (id == CXIMAGE_FORMAT_PNG) return n; -#endif -#if CXIMAGE_SUPPORT_ICO - n++; if (id == CXIMAGE_FORMAT_ICO) return n; -#endif -#if CXIMAGE_SUPPORT_TIF - n++; if (id == CXIMAGE_FORMAT_TIF) return n; -#endif -#if CXIMAGE_SUPPORT_TGA - n++; if (id == CXIMAGE_FORMAT_TGA) return n; -#endif -#if CXIMAGE_SUPPORT_PCX - n++; if (id == CXIMAGE_FORMAT_PCX) return n; -#endif -#if CXIMAGE_SUPPORT_WBMP - n++; if (id == CXIMAGE_FORMAT_WBMP) return n; -#endif -#if CXIMAGE_SUPPORT_WMF - n++; if (id == CXIMAGE_FORMAT_WMF) return n; -#endif -#if CXIMAGE_SUPPORT_JP2 - n++; if (id == CXIMAGE_FORMAT_JP2) return n; -#endif -#if CXIMAGE_SUPPORT_JPC - n++; if (id == CXIMAGE_FORMAT_JPC) return n; -#endif -#if CXIMAGE_SUPPORT_PGX - n++; if (id == CXIMAGE_FORMAT_PGX) return n; -#endif -#if CXIMAGE_SUPPORT_PNM - n++; if (id == CXIMAGE_FORMAT_PNM) return n; -#endif -#if CXIMAGE_SUPPORT_RAS - n++; if (id == CXIMAGE_FORMAT_RAS) return n; -#endif -#if CXIMAGE_SUPPORT_JBG - n++; if (id == CXIMAGE_FORMAT_JBG) return n; -#endif -#if CXIMAGE_SUPPORT_MNG - n++; if (id == CXIMAGE_FORMAT_MNG) return n; -#endif -#if CXIMAGE_SUPPORT_SKA - n++; if (id == CXIMAGE_FORMAT_SKA) return n; -#endif -#if CXIMAGE_SUPPORT_RAW - n++; if (id == CXIMAGE_FORMAT_RAW) return n; -#endif - - return 0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return current frame delay in milliseconds. Only for GIF and MNG formats. - */ -DWORD CxImage::GetFrameDelay() const -{ - return info.dwFrameDelay; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets current frame delay. Only for GIF format. - * \param d = delay in milliseconds - */ -void CxImage::SetFrameDelay(DWORD d) -{ - info.dwFrameDelay=d; -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::GetOffset(long *x,long *y) -{ - *x=info.xOffset; - *y=info.yOffset; -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::SetOffset(long x,long y) -{ - info.xOffset=x; - info.yOffset=y; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa SetJpegQuality, GetJpegQualityF - * \author [DP]; changes [Stefan Schürmans] - */ -BYTE CxImage::GetJpegQuality() const -{ - return (BYTE)(info.fQuality + 0.5f); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa SetJpegQuality, GetJpegQuality - * \author [Stefan Schürmans] - */ -float CxImage::GetJpegQualityF() const -{ - return info.fQuality; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * quality level for JPEG and JPEG2000 - * \param q: can be from 0 to 100 - * \author [DP]; changes [Stefan Schürmans] - */ -void CxImage::SetJpegQuality(BYTE q){ - info.fQuality = (float)q; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * quality level for JPEG and JPEG2000 - * necessary for JPEG2000 when quality is between 0.0 and 1.0 - * \param q: can be from 0.0 to 100.0 - * \author [Stefan Schürmans] - */ -void CxImage::SetJpegQualityF(float q){ - if (q>0) info.fQuality = q; - else info.fQuality = 0.0f; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa SetJpegScale - */ -BYTE CxImage::GetJpegScale() const -{ - return info.nJpegScale; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * scaling down during JPEG decoding valid numbers are 1, 2, 4, 8 - * \author [ignacio] - */ -void CxImage::SetJpegScale(BYTE q){ - info.nJpegScale = q; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Used to monitor the slow loops. - * \return value is from 0 to 100. - * \sa SetProgress - */ -long CxImage::GetProgress() const -{ - return info.nProgress; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return the escape code. - * \sa SetEscape - */ -long CxImage::GetEscape() const -{ - return info.nEscape; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Forces the value of the internal progress variable. - * \param p should be from 0 to 100. - * \sa GetProgress - */ -void CxImage::SetProgress(long p) -{ - info.nProgress = p; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Used to quit the slow loops or the codecs. - * - SetEscape(-1) before Decode forces the function to exit, right after - * the image width and height are available ( for bmp, jpg, gif, tif ) - */ -void CxImage::SetEscape(long i) -{ - info.nEscape = i; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the image is correctly initializated. - */ -bool CxImage::IsValid() const -{ - return pDib!=0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * True if the image is enabled for painting. - */ -bool CxImage::IsEnabled() const -{ - return info.bEnabled; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Enables/disables the image. - */ -void CxImage::Enable(bool enable) -{ - info.bEnabled=enable; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * This function must be used after a Decode() / Load() call. - * Use the sequence SetFrame(-1); Load(...); GetNumFrames(); - * to get the number of images without loading the first image. - * \return the number of images in the file. - */ -long CxImage::GetNumFrames() const -{ - return info.nNumFrames; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return the current selected image (zero-based index). - */ -long CxImage::GetFrame() const -{ - return info.nFrame; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the image number that the next Decode() / Load() call will load - */ -void CxImage::SetFrame(long nFrame){ - info.nFrame=nFrame; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the method for drawing the frame related to others - * \sa GetDisposalMethod - */ -void CxImage::SetDisposalMethod(BYTE dm) -{ info.dispmeth=dm; } -//////////////////////////////////////////////////////////////////////////////// -/** - * Gets the method for drawing the frame related to others - * Values : 0 - No disposal specified. The decoder is - * not required to take any action. - * 1 - Do not dispose. The graphic is to be left - * in place. - * 2 - Restore to background color. The area used by the - * graphic must be restored to the background color. - * 3 - Restore to previous. The decoder is required to - * restore the area overwritten by the graphic with - * what was there prior to rendering the graphic. - * 4-7 - To be defined. - */ -BYTE CxImage::GetDisposalMethod() const -{ return info.dispmeth; } -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::GetRetreiveAllFrames() const -{ return info.bGetAllFrames; } -//////////////////////////////////////////////////////////////////////////////// -void CxImage::SetRetreiveAllFrames(bool flag) -{ info.bGetAllFrames = flag; } -//////////////////////////////////////////////////////////////////////////////// -CxImage * CxImage::GetFrame(long nFrame) const -{ - if ( ppFrames == NULL) return NULL; - if ( info.nNumFrames == 0) return NULL; - if ( nFrame >= info.nNumFrames ) return NULL; - if ( nFrame < 0) nFrame = info.nNumFrames - 1; - return ppFrames[nFrame]; -} -//////////////////////////////////////////////////////////////////////////////// -short CxImage::cx_ntohs(const short word) -{ - if (info.bLittleEndianHost) return word; - return ( (word & 0xff) << 8 ) | ( (word >> 8) & 0xff ); -} -//////////////////////////////////////////////////////////////////////////////// -long CxImage::cx_ntohl(const long dword) -{ - if (info.bLittleEndianHost) return dword; - return ((dword & 0xff) << 24 ) | ((dword & 0xff00) << 8 ) | - ((dword >> 8) & 0xff00) | ((dword >> 24) & 0xff); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::cx_bihtoh(BITMAPINFOHEADER* bih) -{ - bih->biSize = cx_ntohl(bih->biSize); - bih->biWidth = cx_ntohl(bih->biWidth); - bih->biHeight = cx_ntohl(bih->biHeight); - bih->biPlanes = cx_ntohs(bih->biPlanes); - bih->biBitCount = cx_ntohs(bih->biBitCount); - bih->biCompression = cx_ntohl(bih->biCompression); - bih->biSizeImage = cx_ntohl(bih->biSizeImage); - bih->biXPelsPerMeter = cx_ntohl(bih->biXPelsPerMeter); - bih->biYPelsPerMeter = cx_ntohl(bih->biYPelsPerMeter); - bih->biClrUsed = cx_ntohl(bih->biClrUsed); - bih->biClrImportant = cx_ntohl(bih->biClrImportant); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Returns the last reported error. - */ -const char* CxImage::GetLastError() -{ - return info.szLastError; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::DumpSize() -{ - DWORD n; - n = sizeof(BITMAPINFOHEADER) + sizeof(CXIMAGEINFO) + GetSize(); - - if (pAlpha){ - n += 1 + head.biWidth * head.biHeight; - } else n++; - - if (pSelection){ - n += 1 + head.biWidth * head.biHeight; - } else n++; - - if (ppLayers){ - for (long m=0; mDumpSize(); - } - } - } else n++; - - if (ppFrames){ - for (long m=0; mDumpSize(); - } - } - } else n++; - - return n; -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::Dump(BYTE * dst) -{ - if (!dst) return 0; - - memcpy(dst,&head,sizeof(BITMAPINFOHEADER)); - dst += sizeof(BITMAPINFOHEADER); - - memcpy(dst,&info,sizeof(CXIMAGEINFO)); - dst += sizeof(CXIMAGEINFO); - - memcpy(dst,pDib,GetSize()); - dst += GetSize(); - - if (pAlpha){ - memset(dst++, 1, 1); - memcpy(dst,pAlpha,head.biWidth * head.biHeight); - dst += head.biWidth * head.biHeight; - } else { - memset(dst++, 0, 1); - } - - if (pSelection){ - memset(dst++, 1, 1); - memcpy(dst,pSelection,head.biWidth * head.biHeight); - dst += head.biWidth * head.biHeight; - } else { - memset(dst++, 0, 1); - } - - if (ppLayers){ - memset(dst++, 1, 1); - for (long m=0; mDump(dst); - } - } - } else { - memset(dst++, 0, 1); - } - - if (ppFrames){ - memset(dst++, 1, 1); - for (long m=0; mDump(dst); - } - } - } else { - memset(dst++, 0, 1); - } - - return DumpSize(); -} -//////////////////////////////////////////////////////////////////////////////// -DWORD CxImage::UnDump(const BYTE * src) -{ - if (!src) - return 0; - if (!Destroy()) - return 0; - if (!DestroyFrames()) - return 0; - - DWORD n = 0; - - memcpy(&head,src,sizeof(BITMAPINFOHEADER)); - n += sizeof(BITMAPINFOHEADER); - - memcpy(&info,&src[n],sizeof(CXIMAGEINFO)); - n += sizeof(CXIMAGEINFO); - - if (!Create(head.biWidth, head.biHeight, head.biBitCount, info.dwType)) - return 0; - - memcpy(pDib,&src[n],GetSize()); - n += GetSize(); - - if (src[n++]){ - if (AlphaCreate()){ - memcpy(pAlpha, &src[n], head.biWidth * head.biHeight); - } - n += head.biWidth * head.biHeight; - } - - if (src[n++]){ - RECT box = info.rSelectionBox; - if (SelectionCreate()){ - info.rSelectionBox = box; - memcpy(pSelection, &src[n], head.biWidth * head.biHeight); - } - n += head.biWidth * head.biHeight; - } - - if (src[n++]){ - ppLayers = new CxImage*[info.nNumLayers]; - for (long m=0; mUnDump(&src[n]); - } - } - - if (src[n++]){ - ppFrames = new CxImage*[info.nNumFrames]; - for (long m=0; mUnDump(&src[n]); - } - } - - return n; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * \return A.BBCCCDDDD - * - A = main version - * - BB = main revision - * - CCC = minor revision (letter) - * - DDDD = experimental revision - */ -const float CxImage::GetVersionNumber() -{ - return 6.000000015f; -} -//////////////////////////////////////////////////////////////////////////////// -const TCHAR* CxImage::GetVersion() -{ - static const TCHAR CxImageVersion[] = _T("CxImage 6.0.0"); - return (CxImageVersion); -} -//////////////////////////////////////////////////////////////////////////////// - -#if !defined(WIN32) && !defined(_WIN32_WCE) -#undef _tcsnicmp -#undef _T -#endif diff --git a/Externals/cximage/ximaint.cpp b/Externals/cximage/ximaint.cpp deleted file mode 100644 index 6814d5e2d39..00000000000 --- a/Externals/cximage/ximaint.cpp +++ /dev/null @@ -1,1056 +0,0 @@ -// xImaInt.cpp : interpolation functions -/* 02/2004 - Branko Brevensek - * CxImage version 6.0.0 02/Feb/2008 - Davide Pizzolato - www.xdp.it - */ - -#include "ximage.h" -#include "ximath.h" - -#if CXIMAGE_SUPPORT_INTERPOLATION - -//////////////////////////////////////////////////////////////////////////////// -/** - * Recalculates coordinates according to specified overflow method. - * If pixel (x,y) lies within image, nothing changes. - * - * \param x, y - coordinates of pixel - * \param ofMethod - overflow method - * - * \return x, y - new coordinates (pixel (x,y) now lies inside image) - * - * \author ***bd*** 2.2004 - */ -void CxImage::OverflowCoordinates(long &x, long &y, OverflowMethod const ofMethod) -{ - if (IsInside(x,y)) return; //if pixel is within bounds, no change - switch (ofMethod) { - case OM_REPEAT: - //clip coordinates - x=MAX(x,0); x=MIN(x, head.biWidth-1); - y=MAX(y,0); y=MIN(y, head.biHeight-1); - break; - case OM_WRAP: - //wrap coordinates - x = x % head.biWidth; - y = y % head.biHeight; - if (x<0) x = head.biWidth + x; - if (y<0) y = head.biHeight + y; - break; - case OM_MIRROR: - //mirror pixels near border - if (x<0) x=((-x) % head.biWidth); - else if (x>=head.biWidth) x=head.biWidth-(x % head.biWidth + 1); - if (y<0) y=((-y) % head.biHeight); - else if (y>=head.biHeight) y=head.biHeight-(y % head.biHeight + 1); - break; - default: - return; - }//switch -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * See OverflowCoordinates for integer version - * \author ***bd*** 2.2004 - */ -void CxImage::OverflowCoordinates(float &x, float &y, OverflowMethod const ofMethod) -{ - if (x>=0 && x=0 && y=head.biWidth) x=head.biWidth-((float)fmod(x, (float) head.biWidth) + 1); - if (y<0) y=(float)fmod(-y, (float) head.biHeight); - else if (y>=head.biHeight) y=head.biHeight-((float)fmod(y, (float) head.biHeight) + 1); - break; - default: - return; - }//switch -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * Method return pixel color. Different methods are implemented for out of bounds pixels. - * If an image has alpha channel, alpha value is returned in .RGBReserved. - * - * \param x,y : pixel coordinates - * \param ofMethod : out-of-bounds method: - * - OF_WRAP - wrap over to pixels on other side of the image - * - OF_REPEAT - repeat last pixel on the edge - * - OF_COLOR - return input value of color - * - OF_BACKGROUND - return background color (if not set, return input color) - * - OF_TRANSPARENT - return transparent pixel - * - * \param rplColor : input color (returned for out-of-bound coordinates in OF_COLOR mode and if other mode is not applicable) - * - * \return color : color of pixel - * \author ***bd*** 2.2004 - */ -RGBQUAD CxImage::GetPixelColorWithOverflow(long x, long y, OverflowMethod const ofMethod, RGBQUAD* const rplColor) -{ - RGBQUAD color; //color to return - if ((!IsInside(x,y)) || pDib==NULL) { //is pixel within bouns?: - //pixel is out of bounds or no DIB - if (rplColor!=NULL) - color=*rplColor; - else { - color.rgbRed=color.rgbGreen=color.rgbBlue=255; color.rgbReserved=0; //default replacement colour: white transparent - }//if - if (pDib==NULL) return color; - //pixel is out of bounds: - switch (ofMethod) { - case OM_TRANSPARENT: -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) { - //alpha transparency is supported and image has alpha layer - color.rgbReserved=0; - } else { -#endif //CXIMAGE_SUPPORT_ALPHA - //no alpha transparency - if (GetTransIndex()>=0) { - color=GetTransColor(); //single color transparency enabled (return transparent color) - }//if -#if CXIMAGE_SUPPORT_ALPHA - }//if -#endif //CXIMAGE_SUPPORT_ALPHA - return color; - case OM_BACKGROUND: - //return background color (if it exists, otherwise input value) - if (info.nBkgndIndex >= 0) { - if (head.biBitCount<24) color = GetPaletteColor((BYTE)info.nBkgndIndex); - else color = info.nBkgndColor; - }//if - return color; - case OM_REPEAT: - case OM_WRAP: - case OM_MIRROR: - OverflowCoordinates(x,y,ofMethod); - break; - default: - //simply return replacement color (OM_COLOR and others) - return color; - }//switch - }//if - //just return specified pixel (it's within bounds) - return BlindGetPixelColor(x,y); -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * This method reconstructs image according to chosen interpolation method and then returns pixel (x,y). - * (x,y) can lie between actual image pixels. If (x,y) lies outside of image, method returns value - * according to overflow method. - * This method is very useful for geometrical image transformations, where destination pixel - * can often assume color value lying between source pixels. - * - * \param (x,y) - coordinates of pixel to return - * GPCI method recreates "analogue" image back from digital data, so x and y - * are float values and color value of point (1.1,1) will generally not be same - * as (1,1). Center of first pixel is at (0,0) and center of pixel right to it is (1,0). - * (0.5,0) is half way between these two pixels. - * \param inMethod - interpolation (reconstruction) method (kernel) to use: - * - IM_NEAREST_NEIGHBOUR - returns colour of nearest lying pixel (causes stairy look of - * processed images) - * - IM_BILINEAR - interpolates colour from four neighbouring pixels (softens image a bit) - * - IM_BICUBIC - interpolates from 16 neighbouring pixels (can produce "halo" artifacts) - * - IM_BICUBIC2 - interpolates from 16 neighbouring pixels (perhaps a bit less halo artifacts - than IM_BICUBIC) - * - IM_BSPLINE - interpolates from 16 neighbouring pixels (softens image, washes colours) - * (As far as I know, image should be prefiltered for this method to give - * good results... some other time :) ) - * This method uses bicubic interpolation kernel from CXImage 5.99a and older - * versions. - * - IM_LANCZOS - interpolates from 12*12 pixels (slow, ringing artifacts) - * - * \param ofMethod - overflow method (see comments at GetPixelColorWithOverflow) - * \param rplColor - pointer to color used for out of borders pixels in OM_COLOR mode - * (and other modes if colour can't calculated in a specified way) - * - * \return interpolated color value (including interpolated alpha value, if image has alpha layer) - * - * \author ***bd*** 2.2004 - */ -RGBQUAD CxImage::GetPixelColorInterpolated( - float x,float y, - InterpolationMethod const inMethod, - OverflowMethod const ofMethod, - RGBQUAD* const rplColor) -{ - //calculate nearest pixel - int xi=(int)(x); if (x<0) xi--; //these replace (incredibly slow) floor (Visual c++ 2003, AMD Athlon) - int yi=(int)(y); if (y<0) yi--; - RGBQUAD color; //calculated colour - - switch (inMethod) { - case IM_NEAREST_NEIGHBOUR: - return GetPixelColorWithOverflow((long)(x+0.5f), (long)(y+0.5f), ofMethod, rplColor); - default: { - //IM_BILINEAR: bilinear interpolation - if (xi<-1 || xi>=head.biWidth || yi<-1 || yi>=head.biHeight) { //all 4 points are outside bounds?: - switch (ofMethod) { - case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: - //we don't need to interpolate anything with all points outside in this case - return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); - default: - //recalculate coordinates and use faster method later on - OverflowCoordinates(x,y,ofMethod); - xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi - yi=(int)(y); if (y<0) yi--; - }//switch - }//if - //get four neighbouring pixels - if ((xi+1)=0 && (yi+1)=0 && head.biClrUsed==0) { - //all pixels are inside RGB24 image... optimize reading (and use fixed point arithmetic) - WORD wt1=(WORD)((x-xi)*256.0f), wt2=(WORD)((y-yi)*256.0f); - WORD wd=wt1*wt2>>8; - WORD wb=wt1-wd; - WORD wc=wt2-wd; - WORD wa=256-wt1-wc; - WORD wrr,wgg,wbb; - BYTE *pxptr=(BYTE*)info.pImage+yi*info.dwEffWidth+xi*3; - wbb=wa*(*pxptr++); wgg=wa*(*pxptr++); wrr=wa*(*pxptr++); - wbb+=wb*(*pxptr++); wgg+=wb*(*pxptr++); wrr+=wb*(*pxptr); - pxptr+=(info.dwEffWidth-5); //move to next row - wbb+=wc*(*pxptr++); wgg+=wc*(*pxptr++); wrr+=wc*(*pxptr++); - wbb+=wd*(*pxptr++); wgg+=wd*(*pxptr++); wrr+=wd*(*pxptr); - color.rgbRed=(BYTE) (wrr>>8); color.rgbGreen=(BYTE) (wgg>>8); color.rgbBlue=(BYTE) (wbb>>8); -#if CXIMAGE_SUPPORT_ALPHA - if (pAlpha) { - WORD waa; - //image has alpha layer... we have to do the same for alpha data - pxptr=AlphaGetPointer(xi,yi); //pointer to first byte - waa=wa*(*pxptr++); waa+=wb*(*pxptr); //first two pixels - pxptr+=(head.biWidth-1); //move to next row - waa+=wc*(*pxptr++); waa+=wd*(*pxptr); //and second row pixels - color.rgbReserved=(BYTE) (waa>>8); - } else -#endif - { //Alpha not supported or no alpha at all - color.rgbReserved = 0; - } - return color; - } else { - //default (slower) way to get pixels (not RGB24 or some pixels out of borders) - float t1=x-xi, t2=y-yi; - float d=t1*t2; - float b=t1-d; - float c=t2-d; - float a=1-t1-c; - RGBQUAD rgb11,rgb21,rgb12,rgb22; - rgb11=GetPixelColorWithOverflow(xi, yi, ofMethod, rplColor); - rgb21=GetPixelColorWithOverflow(xi+1, yi, ofMethod, rplColor); - rgb12=GetPixelColorWithOverflow(xi, yi+1, ofMethod, rplColor); - rgb22=GetPixelColorWithOverflow(xi+1, yi+1, ofMethod, rplColor); - //calculate linear interpolation - color.rgbRed=(BYTE) (a*rgb11.rgbRed+b*rgb21.rgbRed+c*rgb12.rgbRed+d*rgb22.rgbRed); - color.rgbGreen=(BYTE) (a*rgb11.rgbGreen+b*rgb21.rgbGreen+c*rgb12.rgbGreen+d*rgb22.rgbGreen); - color.rgbBlue=(BYTE) (a*rgb11.rgbBlue+b*rgb21.rgbBlue+c*rgb12.rgbBlue+d*rgb22.rgbBlue); -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) - color.rgbReserved=(BYTE) (a*rgb11.rgbReserved+b*rgb21.rgbReserved+c*rgb12.rgbReserved+d*rgb22.rgbReserved); - else -#endif - { //Alpha not supported or no alpha at all - color.rgbReserved = 0; - } - return color; - }//if - }//default - case IM_BICUBIC: - case IM_BICUBIC2: - case IM_BSPLINE: - case IM_BOX: - case IM_HERMITE: - case IM_HAMMING: - case IM_SINC: - case IM_BLACKMAN: - case IM_BESSEL: - case IM_GAUSSIAN: - case IM_QUADRATIC: - case IM_MITCHELL: - case IM_CATROM: - case IM_HANNING: - case IM_POWER: - //bicubic interpolation(s) - if (((xi+2)<0) || ((xi-1)>=head.biWidth) || ((yi+2)<0) || ((yi-1)>=head.biHeight)) { //all points are outside bounds?: - switch (ofMethod) { - case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: - //we don't need to interpolate anything with all points outside in this case - return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); - break; - default: - //recalculate coordinates and use faster method later on - OverflowCoordinates(x,y,ofMethod); - xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi - yi=(int)(y); if (y<0) yi--; - }//switch - }//if - - //some variables needed from here on - int xii,yii; //x any y integer indexes for loops - float kernel, kernelyc; //kernel cache - float kernelx[12], kernely[4]; //precalculated kernel values - float rr,gg,bb,aa; //accumulated color values - //calculate multiplication factors for all pixels - int i; - switch (inMethod) { - case IM_BICUBIC: - for (i=0; i<4; i++) { - kernelx[i]=KernelCubic((float)(xi+i-1-x)); - kernely[i]=KernelCubic((float)(yi+i-1-y)); - }//for i - break; - case IM_BICUBIC2: - for (i=0; i<4; i++) { - kernelx[i]=KernelGeneralizedCubic((float)(xi+i-1-x), -0.5); - kernely[i]=KernelGeneralizedCubic((float)(yi+i-1-y), -0.5); - }//for i - break; - case IM_BSPLINE: - for (i=0; i<4; i++) { - kernelx[i]=KernelBSpline((float)(xi+i-1-x)); - kernely[i]=KernelBSpline((float)(yi+i-1-y)); - }//for i - break; - case IM_BOX: - for (i=0; i<4; i++) { - kernelx[i]=KernelBox((float)(xi+i-1-x)); - kernely[i]=KernelBox((float)(yi+i-1-y)); - }//for i - break; - case IM_HERMITE: - for (i=0; i<4; i++) { - kernelx[i]=KernelHermite((float)(xi+i-1-x)); - kernely[i]=KernelHermite((float)(yi+i-1-y)); - }//for i - break; - case IM_HAMMING: - for (i=0; i<4; i++) { - kernelx[i]=KernelHamming((float)(xi+i-1-x)); - kernely[i]=KernelHamming((float)(yi+i-1-y)); - }//for i - break; - case IM_SINC: - for (i=0; i<4; i++) { - kernelx[i]=KernelSinc((float)(xi+i-1-x)); - kernely[i]=KernelSinc((float)(yi+i-1-y)); - }//for i - break; - case IM_BLACKMAN: - for (i=0; i<4; i++) { - kernelx[i]=KernelBlackman((float)(xi+i-1-x)); - kernely[i]=KernelBlackman((float)(yi+i-1-y)); - }//for i - break; - case IM_BESSEL: - for (i=0; i<4; i++) { - kernelx[i]=KernelBessel((float)(xi+i-1-x)); - kernely[i]=KernelBessel((float)(yi+i-1-y)); - }//for i - break; - case IM_GAUSSIAN: - for (i=0; i<4; i++) { - kernelx[i]=KernelGaussian((float)(xi+i-1-x)); - kernely[i]=KernelGaussian((float)(yi+i-1-y)); - }//for i - break; - case IM_QUADRATIC: - for (i=0; i<4; i++) { - kernelx[i]=KernelQuadratic((float)(xi+i-1-x)); - kernely[i]=KernelQuadratic((float)(yi+i-1-y)); - }//for i - break; - case IM_MITCHELL: - for (i=0; i<4; i++) { - kernelx[i]=KernelMitchell((float)(xi+i-1-x)); - kernely[i]=KernelMitchell((float)(yi+i-1-y)); - }//for i - break; - case IM_CATROM: - for (i=0; i<4; i++) { - kernelx[i]=KernelCatrom((float)(xi+i-1-x)); - kernely[i]=KernelCatrom((float)(yi+i-1-y)); - }//for i - break; - case IM_HANNING: - for (i=0; i<4; i++) { - kernelx[i]=KernelHanning((float)(xi+i-1-x)); - kernely[i]=KernelHanning((float)(yi+i-1-y)); - }//for i - break; - case IM_POWER: - for (i=0; i<4; i++) { - kernelx[i]=KernelPower((float)(xi+i-1-x)); - kernely[i]=KernelPower((float)(yi+i-1-y)); - }//for i - break; - }//switch - rr=gg=bb=aa=0; - if (((xi+2)=1 && ((yi+2)=1) && !IsIndexed()) { - //optimized interpolation (faster pixel reads) for RGB24 images with all pixels inside bounds - BYTE *pxptr, *pxptra; - for (yii=yi-1; yii255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; - if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; - if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) { - if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; - } else -#endif - { //Alpha not supported or no alpha at all - color.rgbReserved = 0; - } - return color; - case IM_LANCZOS: - //lanczos window (16*16) sinc interpolation - if (((xi+6)<0) || ((xi-5)>=head.biWidth) || ((yi+6)<0) || ((yi-5)>=head.biHeight)) { - //all points are outside bounds - switch (ofMethod) { - case OM_COLOR: case OM_TRANSPARENT: case OM_BACKGROUND: - //we don't need to interpolate anything with all points outside in this case - return GetPixelColorWithOverflow(-999, -999, ofMethod, rplColor); - break; - default: - //recalculate coordinates and use faster method later on - OverflowCoordinates(x,y,ofMethod); - xi=(int)(x); if (x<0) xi--; //x and/or y have changed ... recalculate xi and yi - yi=(int)(y); if (y<0) yi--; - }//switch - }//if - - for (xii=xi-5; xii=0) && ((yi+6)=0) && !IsIndexed()) { - //optimized interpolation (faster pixel reads) for RGB24 images with all pixels inside bounds - BYTE *pxptr, *pxptra; - for (yii=yi-5; yii255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; - if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; - if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) { - if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; - } else -#endif - { //Alpha not supported or no alpha at all - color.rgbReserved = 0; - } - return color; - }//switch -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Helper function for GetAreaColorInterpolated. - * Adds 'surf' portion of image pixel with color 'color' to (rr,gg,bb,aa). - */ -void CxImage::AddAveragingCont(RGBQUAD const &color, float const surf, float &rr, float &gg, float &bb, float &aa) -{ - rr+=color.rgbRed*surf; - gg+=color.rgbGreen*surf; - bb+=color.rgbBlue*surf; -#if CXIMAGE_SUPPORT_ALPHA - aa+=color.rgbReserved*surf; -#endif -} -//////////////////////////////////////////////////////////////////////////////// -/** - * This method is similar to GetPixelColorInterpolated, but this method also properly handles - * subsampling. - * If you need to sample original image with interval of more than 1 pixel (as when shrinking an image), - * you should use this method instead of GetPixelColorInterpolated or aliasing will occur. - * When area width and height are both less than pixel, this method gets pixel color by interpolating - * color of frame center with selected (inMethod) interpolation by calling GetPixelColorInterpolated. - * If width and height are more than 1, method calculates color by averaging color of pixels within area. - * Interpolation method is not used in this case. Pixel color is interpolated by averaging instead. - * If only one of both is more than 1, method uses combination of interpolation and averaging. - * Chosen interpolation method is used, but since it is averaged later on, there is little difference - * between IM_BILINEAR (perhaps best for this case) and better methods. IM_NEAREST_NEIGHBOUR again - * leads to aliasing artifacts. - * This method is a bit slower than GetPixelColorInterpolated and when aliasing is not a problem, you should - * simply use the later. - * - * \param xc, yc - center of (rectangular) area - * \param w, h - width and height of area - * \param inMethod - interpolation method that is used, when interpolation is used (see above) - * \param ofMethod - overflow method used when retrieving individual pixel colors - * \param rplColor - replacement colour to use, in OM_COLOR - * - * \author ***bd*** 2.2004 - */ -RGBQUAD CxImage::GetAreaColorInterpolated( - float const xc, float const yc, float const w, float const h, - InterpolationMethod const inMethod, - OverflowMethod const ofMethod, - RGBQUAD* const rplColor) -{ - RGBQUAD color; //calculated colour - - if (h<=1 && w<=1) { - //both width and height are less than one... we will use interpolation of center point - return GetPixelColorInterpolated(xc, yc, inMethod, ofMethod, rplColor); - } else { - //area is wider and/or taller than one pixel: - CxRect2 area(xc-w/2.0f, yc-h/2.0f, xc+w/2.0f, yc+h/2.0f); //area - int xi1=(int)(area.botLeft.x+0.49999999f); //low x - int yi1=(int)(area.botLeft.y+0.49999999f); //low y - - - int xi2=(int)(area.topRight.x+0.5f); //top x - int yi2=(int)(area.topRight.y+0.5f); //top y (for loops) - - float rr,gg,bb,aa; //red, green, blue and alpha components - rr=gg=bb=aa=0; - int x,y; //loop counters - float s=0; //surface of all pixels - float cps; //surface of current crosssection - if (h>1 && w>1) { - //width and height of area are greater than one pixel, so we can employ "ordinary" averaging - CxRect2 intBL, intTR; //bottom left and top right intersection - intBL=area.CrossSection(CxRect2(((float)xi1)-0.5f, ((float)yi1)-0.5f, ((float)xi1)+0.5f, ((float)yi1)+0.5f)); - intTR=area.CrossSection(CxRect2(((float)xi2)-0.5f, ((float)yi2)-0.5f, ((float)xi2)+0.5f, ((float)yi2)+0.5f)); - float wBL, wTR, hBL, hTR; - wBL=intBL.Width(); //width of bottom left pixel-area intersection - hBL=intBL.Height(); //height of bottom left... - wTR=intTR.Width(); //width of top right... - hTR=intTR.Height(); //height of top right... - - AddAveragingCont(GetPixelColorWithOverflow(xi1,yi1,ofMethod,rplColor), wBL*hBL, rr, gg, bb, aa); //bottom left pixel - AddAveragingCont(GetPixelColorWithOverflow(xi2,yi1,ofMethod,rplColor), wTR*hBL, rr, gg, bb, aa); //bottom right pixel - AddAveragingCont(GetPixelColorWithOverflow(xi1,yi2,ofMethod,rplColor), wBL*hTR, rr, gg, bb, aa); //top left pixel - AddAveragingCont(GetPixelColorWithOverflow(xi2,yi2,ofMethod,rplColor), wTR*hTR, rr, gg, bb, aa); //top right pixel - //bottom and top row - for (x=xi1+1; x255) rr=255; if (rr<0) rr=0; color.rgbRed=(BYTE) rr; - if (gg>255) gg=255; if (gg<0) gg=0; color.rgbGreen=(BYTE) gg; - if (bb>255) bb=255; if (bb<0) bb=0; color.rgbBlue=(BYTE) bb; -#if CXIMAGE_SUPPORT_ALPHA - if (AlphaIsValid()) { - if (aa>255) aa=255; if (aa<0) aa=0; color.rgbReserved=(BYTE) aa; - }//if -#endif - }//if - return color; -} - -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBSpline(const float x) -{ - if (x>2.0f) return 0.0f; - // thanks to Kristian Kratzenstein - float a, b, c, d; - float xm1 = x - 1.0f; // Was calculatet anyway cause the "if((x-1.0f) < 0)" - float xp1 = x + 1.0f; - float xp2 = x + 2.0f; - - if ((xp2) <= 0.0f) a = 0.0f; else a = xp2*xp2*xp2; // Only float, not float -> double -> float - if ((xp1) <= 0.0f) b = 0.0f; else b = xp1*xp1*xp1; - if (x <= 0) c = 0.0f; else c = x*x*x; - if ((xm1) <= 0.0f) d = 0.0f; else d = xm1*xm1*xm1; - - return (0.16666666666666666667f * (a - (4.0f * b) + (6.0f * c) - (4.0f * d))); - - /* equivalent - if (x < -2.0) - return(0.0f); - if (x < -1.0) - return((2.0f+x)*(2.0f+x)*(2.0f+x)*0.16666666666666666667f); - if (x < 0.0) - return((4.0f+x*x*(-6.0f-3.0f*x))*0.16666666666666666667f); - if (x < 1.0) - return((4.0f+x*x*(-6.0f+3.0f*x))*0.16666666666666666667f); - if (x < 2.0) - return((2.0f-x)*(2.0f-x)*(2.0f-x)*0.16666666666666666667f); - return(0.0f); - */ -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * Bilinear interpolation kernel: - \verbatim - / - | 1-t , if 0 <= t <= 1 - h(t) = | t+1 , if -1 <= t < 0 - | 0 , otherwise - \ - \endverbatim - * ***bd*** 2.2004 - */ -float CxImage::KernelLinear(const float t) -{ -// if (0<=t && t<=1) return 1-t; -// if (-1<=t && t<0) return 1+t; -// return 0; - - // - if (t < -1.0f) - return 0.0f; - if (t < 0.0f) - return 1.0f+t; - if (t < 1.0f) - return 1.0f-t; - return 0.0f; -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * Bicubic interpolation kernel (a=-1): - \verbatim - / - | 1-2|t|**2+|t|**3 , if |t| < 1 - h(t) = | 4-8|t|+5|t|**2-|t|**3 , if 1<=|t|<2 - | 0 , otherwise - \ - \endverbatim - * ***bd*** 2.2004 - */ -float CxImage::KernelCubic(const float t) -{ - float abs_t = (float)fabs(t); - float abs_t_sq = abs_t * abs_t; - if (abs_t<1) return 1-2*abs_t_sq+abs_t_sq*abs_t; - if (abs_t<2) return 4 - 8*abs_t +5*abs_t_sq - abs_t_sq*abs_t; - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * Bicubic kernel (for a=-1 it is the same as BicubicKernel): - \verbatim - / - | (a+2)|t|**3 - (a+3)|t|**2 + 1 , |t| <= 1 - h(t) = | a|t|**3 - 5a|t|**2 + 8a|t| - 4a , 1 < |t| <= 2 - | 0 , otherwise - \ - \endverbatim - * Often used values for a are -1 and -1/2. - */ -float CxImage::KernelGeneralizedCubic(const float t, const float a) -{ - float abs_t = (float)fabs(t); - float abs_t_sq = abs_t * abs_t; - if (abs_t<1) return (a+2)*abs_t_sq*abs_t - (a+3)*abs_t_sq + 1; - if (abs_t<2) return a*abs_t_sq*abs_t - 5*a*abs_t_sq + 8*a*abs_t - 4*a; - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -/** - * Lanczos windowed sinc interpolation kernel with radius r. - \verbatim - / - h(t) = | sinc(t)*sinc(t/r) , if |t| r) return 0; - if (t==0) return 1; - float pit=PI*t; - float pitd=pit/r; - return (float)((sin(pit)/pit) * (sin(pitd)/pitd)); -} - -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBox(const float x) -{ - if (x < -0.5f) - return 0.0f; - if (x < 0.5f) - return 1.0f; - return 0.0f; -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelHermite(const float x) -{ - if (x < -1.0f) - return 0.0f; - if (x < 0.0f) - return (-2.0f*x-3.0f)*x*x+1.0f; - if (x < 1.0f) - return (2.0f*x-3.0f)*x*x+1.0f; - return 0.0f; -// if (fabs(x)>1) return 0.0f; -// return(0.5f+0.5f*(float)cos(PI*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelHanning(const float x) -{ - if (fabs(x)>1) return 0.0f; - return (0.5f+0.5f*(float)cos(PI*x))*((float)sin(PI*x)/(PI*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelHamming(const float x) -{ - if (x < -1.0f) - return 0.0f; - if (x < 0.0f) - return 0.92f*(-2.0f*x-3.0f)*x*x+1.0f; - if (x < 1.0f) - return 0.92f*(2.0f*x-3.0f)*x*x+1.0f; - return 0.0f; -// if (fabs(x)>1) return 0.0f; -// return(0.54f+0.46f*(float)cos(PI*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelSinc(const float x) -{ - if (x == 0.0) - return(1.0); - return((float)sin(PI*x)/(PI*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBlackman(const float x) -{ - //if (fabs(x)>1) return 0.0f; - return (0.42f+0.5f*(float)cos(PI*x)+0.08f*(float)cos(2.0f*PI*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBessel_J1(const float x) -{ - double p, q; - - long i; - - static const double - Pone[] = - { - 0.581199354001606143928050809e+21, - -0.6672106568924916298020941484e+20, - 0.2316433580634002297931815435e+19, - -0.3588817569910106050743641413e+17, - 0.2908795263834775409737601689e+15, - -0.1322983480332126453125473247e+13, - 0.3413234182301700539091292655e+10, - -0.4695753530642995859767162166e+7, - 0.270112271089232341485679099e+4 - }, - Qone[] = - { - 0.11623987080032122878585294e+22, - 0.1185770712190320999837113348e+20, - 0.6092061398917521746105196863e+17, - 0.2081661221307607351240184229e+15, - 0.5243710262167649715406728642e+12, - 0.1013863514358673989967045588e+10, - 0.1501793594998585505921097578e+7, - 0.1606931573481487801970916749e+4, - 0.1e+1 - }; - - p = Pone[8]; - q = Qone[8]; - for (i=7; i >= 0; i--) - { - p = p*x*x+Pone[i]; - q = q*x*x+Qone[i]; - } - return (float)(p/q); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBessel_P1(const float x) -{ - double p, q; - - long i; - - static const double - Pone[] = - { - 0.352246649133679798341724373e+5, - 0.62758845247161281269005675e+5, - 0.313539631109159574238669888e+5, - 0.49854832060594338434500455e+4, - 0.2111529182853962382105718e+3, - 0.12571716929145341558495e+1 - }, - Qone[] = - { - 0.352246649133679798068390431e+5, - 0.626943469593560511888833731e+5, - 0.312404063819041039923015703e+5, - 0.4930396490181088979386097e+4, - 0.2030775189134759322293574e+3, - 0.1e+1 - }; - - p = Pone[5]; - q = Qone[5]; - for (i=4; i >= 0; i--) - { - p = p*(8.0/x)*(8.0/x)+Pone[i]; - q = q*(8.0/x)*(8.0/x)+Qone[i]; - } - return (float)(p/q); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBessel_Q1(const float x) -{ - double p, q; - - long i; - - static const double - Pone[] = - { - 0.3511751914303552822533318e+3, - 0.7210391804904475039280863e+3, - 0.4259873011654442389886993e+3, - 0.831898957673850827325226e+2, - 0.45681716295512267064405e+1, - 0.3532840052740123642735e-1 - }, - Qone[] = - { - 0.74917374171809127714519505e+4, - 0.154141773392650970499848051e+5, - 0.91522317015169922705904727e+4, - 0.18111867005523513506724158e+4, - 0.1038187585462133728776636e+3, - 0.1e+1 - }; - - p = Pone[5]; - q = Qone[5]; - for (i=4; i >= 0; i--) - { - p = p*(8.0/x)*(8.0/x)+Pone[i]; - q = q*(8.0/x)*(8.0/x)+Qone[i]; - } - return (float)(p/q); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBessel_Order1(float x) -{ - float p, q; - - if (x == 0.0) - return (0.0f); - p = x; - if (x < 0.0) - x=(-x); - if (x < 8.0) - return(p*KernelBessel_J1(x)); - q = (float)sqrt(2.0f/(PI*x))*(float)(KernelBessel_P1(x)*(1.0f/sqrt(2.0f)*(sin(x)-cos(x)))-8.0f/x*KernelBessel_Q1(x)* - (-1.0f/sqrt(2.0f)*(sin(x)+cos(x)))); - if (p < 0.0f) - q = (-q); - return (q); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelBessel(const float x) -{ - if (x == 0.0f) - return(PI/4.0f); - return(KernelBessel_Order1(PI*x)/(2.0f*x)); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelGaussian(const float x) -{ - return (float)(exp(-2.0f*x*x)*0.79788456080287f/*sqrt(2.0f/PI)*/); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelQuadratic(const float x) -{ - if (x < -1.5f) - return(0.0f); - if (x < -0.5f) - return(0.5f*(x+1.5f)*(x+1.5f)); - if (x < 0.5f) - return(0.75f-x*x); - if (x < 1.5f) - return(0.5f*(x-1.5f)*(x-1.5f)); - return(0.0f); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelMitchell(const float x) -{ - constexpr float KM_B = (1.0f / 3.0f); - constexpr float KM_C = (1.0f / 3.0f); - constexpr float KM_P0 = (( 6.0f - 2.0f * KM_B ) / 6.0f); - constexpr float KM_P2 = ((-18.0f + 12.0f * KM_B + 6.0f * KM_C) / 6.0f); - constexpr float KM_P3 = (( 12.0f - 9.0f * KM_B - 6.0f * KM_C) / 6.0f); - constexpr float KM_Q0 = (( 8.0f * KM_B + 24.0f * KM_C) / 6.0f); - constexpr float KM_Q1 = ((-12.0f * KM_B - 48.0f * KM_C) / 6.0f); - constexpr float KM_Q2 = (( 6.0f * KM_B + 30.0f * KM_C) / 6.0f); - constexpr float KM_Q3 = (( -1.0f * KM_B - 6.0f * KM_C) / 6.0f); - - if (x < -2.0) - return(0.0f); - if (x < -1.0) - return(KM_Q0-x*(KM_Q1-x*(KM_Q2-x*KM_Q3))); - if (x < 0.0f) - return(KM_P0+x*x*(KM_P2-x*KM_P3)); - if (x < 1.0f) - return(KM_P0+x*x*(KM_P2+x*KM_P3)); - if (x < 2.0f) - return(KM_Q0+x*(KM_Q1+x*(KM_Q2+x*KM_Q3))); - return(0.0f); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelCatrom(const float x) -{ - if (x < -2.0) - return(0.0f); - if (x < -1.0) - return(0.5f*(4.0f+x*(8.0f+x*(5.0f+x)))); - if (x < 0.0) - return(0.5f*(2.0f+x*x*(-5.0f-3.0f*x))); - if (x < 1.0) - return(0.5f*(2.0f+x*x*(-5.0f+3.0f*x))); - if (x < 2.0) - return(0.5f*(4.0f+x*(-8.0f+x*(5.0f-x)))); - return(0.0f); -} -//////////////////////////////////////////////////////////////////////////////// -float CxImage::KernelPower(const float x, const float a) -{ - if (fabs(x)>1) return 0.0f; - return (1.0f - (float)fabs(pow(x,a))); -} -//////////////////////////////////////////////////////////////////////////////// - -#endif diff --git a/Externals/cximage/ximaiter.h b/Externals/cximage/ximaiter.h deleted file mode 100644 index 9628ea55a62..00000000000 --- a/Externals/cximage/ximaiter.h +++ /dev/null @@ -1,253 +0,0 @@ -/* - * File: ImaIter.h - * Purpose: Declaration of the Platform Independent Image Base Class - * Author: Alejandro Aguilar Sierra - * Created: 1995 - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * 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 long 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: - int Itx, Ity; // Counters - int Stepx, Stepy; - BYTE* IterImage; // Image pointer - CxImage *ima; -public: - // Constructors - CImageIterator ( void ); - CImageIterator ( CxImage *image ); - operator CxImage* (); - - // Iterators - bool ItOK (); - void Reset (); - void Upset (); - void SetRow(BYTE *buf, int n); - void GetRow(BYTE *buf, int n); - BYTE GetByte( ) { return IterImage[Itx]; } - void SetByte(BYTE b) { IterImage[Itx] = b; } - BYTE* GetRow(void); - BYTE* GetRow(int n); - bool NextRow(); - bool PrevRow(); - bool NextByte(); - bool PrevByte(); - - void SetSteps(int x, int y=0) { Stepx = x; Stepy = y; } - void GetSteps(int *x, int *y) { *x = Stepx; *y = Stepy; } - bool NextStep(); - bool PrevStep(); - - void SetY(int y); /* AD - for interlace */ - int GetY() {return Ity;} - bool GetCol(BYTE* pCol, DWORD x); - bool SetCol(BYTE* pCol, DWORD 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 >= (int)ima->GetHeight()) return false; - IterImage += ima->GetEffWidth(); - return true; -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::PrevRow() -{ - if (--Ity < 0) return false; - IterImage -= ima->GetEffWidth(); - return true; -} -/* AD - for interlace */ -inline void CImageIterator::SetY(int y) -{ - if ((y < 0) || (y > (int)ima->GetHeight())) return; - Ity = y; - IterImage = ima->GetBits() + ima->GetEffWidth()*y; -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::SetRow(BYTE *buf, int n) -{ - if (n<0) n = (int)ima->GetEffWidth(); - else n = MIN(n,(int)ima->GetEffWidth()); - - if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) memcpy(IterImage,buf,n); -} -///////////////////////////////////////////////////////////////////// -inline void CImageIterator::GetRow(BYTE *buf, int n) -{ - if ((IterImage!=NULL)&&(buf!=NULL)&&(n>0)) - memcpy(buf,IterImage,MIN(n,(int)ima->GetEffWidth())); -} -///////////////////////////////////////////////////////////////////// -inline BYTE* CImageIterator::GetRow() -{ - return IterImage; -} -///////////////////////////////////////////////////////////////////// -inline BYTE* CImageIterator::GetRow(int n) -{ - SetY(n); - return IterImage; -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::NextByte() -{ - if (++Itx < (int)ima->GetEffWidth()) return true; - else - if (++Ity < (int)ima->GetHeight()){ - IterImage += ima->GetEffWidth(); - Itx = 0; - return true; - } else - return false; -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::PrevByte() -{ - if (--Itx >= 0) return true; - else - if (--Ity >= 0){ - IterImage -= ima->GetEffWidth(); - Itx = 0; - return true; - } else - return false; -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::NextStep() -{ - Itx += Stepx; - if (Itx < (int)ima->GetEffWidth()) return true; - else { - Ity += Stepy; - if (Ity < (int)ima->GetHeight()){ - IterImage += ima->GetEffWidth(); - Itx = 0; - return true; - } else - return false; - } -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::PrevStep() -{ - Itx -= Stepx; - if (Itx >= 0) return true; - else { - Ity -= Stepy; - if (Ity >= 0 && Ity < (int)ima->GetHeight()) { - IterImage -= ima->GetEffWidth(); - Itx = 0; - return true; - } else - return false; - } -} -///////////////////////////////////////////////////////////////////// -inline bool CImageIterator::GetCol(BYTE* pCol, DWORD x) -{ - if ((pCol==0)||(ima->GetBpp()<8)||(x>=ima->GetWidth())) - return false; - DWORD h = ima->GetHeight(); - //DWORD line = ima->GetEffWidth(); - BYTE bytes = (BYTE)(ima->GetBpp()>>3); - BYTE* pSrc; - for (DWORD y=0;yGetBits(y) + x*bytes; - for (BYTE w=0;wGetBpp()<8)||(x>=ima->GetWidth())) - return false; - DWORD h = ima->GetHeight(); - //DWORD line = ima->GetEffWidth(); - BYTE bytes = (BYTE)(ima->GetBpp()>>3); - BYTE* pSrc; - for (DWORD y=0;yGetBits(y) + x*bytes; - for (BYTE w=0;w - -struct jpg_error_mgr { - struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ - char* buffer; /* error message */ -}; -typedef jpg_error_mgr *jpg_error_ptr; - -//////////////////////////////////////////////////////////////////////////////// -// Here's the routine that will replace the standard error_exit method: -//////////////////////////////////////////////////////////////////////////////// -static void -ima_jpeg_error_exit (j_common_ptr cinfo) -{ - /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ - jpg_error_ptr myerr = (jpg_error_ptr) cinfo->err; - /* Create the message */ - myerr->pub.format_message (cinfo, myerr->buffer); - /* Send it to stderr, adding a newline */ - /* Return control to the setjmp point */ - longjmp(myerr->setjmp_buffer, 1); -} -//////////////////////////////////////////////////////////////////////////////// -CxImageJPG::CxImageJPG(): CxImage(CXIMAGE_FORMAT_JPG) -{ -#if CXIMAGEJPG_SUPPORT_EXIF - m_exif = NULL; - memset(&m_exifinfo, 0, sizeof(EXIFINFO)); -#endif -} -//////////////////////////////////////////////////////////////////////////////// -CxImageJPG::~CxImageJPG() -{ -#if CXIMAGEJPG_SUPPORT_EXIF - if (m_exif) delete m_exif; -#endif -} -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGEJPG_SUPPORT_EXIF -bool CxImageJPG::DecodeExif(CxFile * hFile) -{ - m_exif = new CxExifInfo(&m_exifinfo); - if (m_exif){ - long pos=hFile->Tell(); - m_exif->DecodeExif(hFile); - hFile->Seek(pos,SEEK_SET); - return m_exif->m_exifinfo->IsExif; - } else { - return false; - } -} -#endif //CXIMAGEJPG_SUPPORT_EXIF -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_DECODE -//////////////////////////////////////////////////////////////////////////////// -bool CxImageJPG::Decode(CxFile * hFile) -{ - - bool is_exif = false; -#if CXIMAGEJPG_SUPPORT_EXIF - is_exif = DecodeExif(hFile); -#endif - - CImageIterator iter(this); - /* This struct contains the JPEG decompression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - */ - struct jpeg_decompress_struct cinfo; - /* We use our private extension JPEG error handler. */ - struct jpg_error_mgr jerr; - jerr.buffer=info.szLastError; - /* More stuff */ - JSAMPARRAY buffer; /* Output row buffer */ - int row_stride; /* physical row width in output buffer */ - - /* In this example we want to open the input file before doing anything else, - * so that the setjmp() error recovery below can assume the file is open. - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to read binary files. - */ - - /* Step 1: allocate and initialize JPEG decompression object */ - /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = ima_jpeg_error_exit; - - /* Establish the setjmp return context for my_error_exit to use. */ -#pragma warning(push) -#pragma warning(disable:4611) - if (setjmp(jerr.setjmp_buffer)) { -#pragma warning(pop) - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - jpeg_destroy_decompress(&cinfo); - return 0; - } - /* Now we can initialize the JPEG decompression object. */ - jpeg_create_decompress(&cinfo); - - /* Step 2: specify data source (eg, a file) */ - //jpeg_stdio_src(&cinfo, infile); - CxFileJpg src(hFile); - cinfo.src = &src; - - /* Step 3: read file parameters with jpeg_read_header() */ - (void) jpeg_read_header(&cinfo, true); - - /* Step 4 handle decoder options*/ - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_GRAYSCALE) != 0) - cinfo.out_color_space = JCS_GRAYSCALE; - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_QUANTIZE) != 0) { - cinfo.quantize_colors = true; - cinfo.desired_number_of_colors = GetJpegQuality(); - } - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_DITHER) != 0) - cinfo.dither_mode = m_nDither; - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_ONEPASS) != 0) - cinfo.two_pass_quantize = false; - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & DECODE_NOSMOOTH) != 0) - cinfo.do_fancy_upsampling = false; - -//: Load true color images as RGB (no quantize) -/* Step 4: set parameters for decompression */ -/* if (cinfo.jpeg_color_space!=JCS_GRAYSCALE) { - * cinfo.quantize_colors = true; - * cinfo.desired_number_of_colors = 128; - *} - */ // - - // Set the scale - cinfo.scale_denom = GetJpegScale(); - - // Borrowed the idea from GIF implementation - if (info.nEscape == -1) { - // Return output dimensions only - jpeg_calc_output_dimensions(&cinfo); - head.biWidth = cinfo.output_width; - head.biHeight = cinfo.output_height; - info.dwType = CXIMAGE_FORMAT_JPG; - jpeg_destroy_decompress(&cinfo); - return true; - } - - /* Step 5: Start decompressor */ - jpeg_start_decompress(&cinfo); - - /* We may need to do some setup of our own at this point before reading - * the data. After jpeg_start_decompress() we have the correct scaled - * output image dimensions available, as well as the output colormap - * if we asked for color quantization. - */ - //Create the image using output dimensions - //Create(cinfo.image_width, cinfo.image_height, 8*cinfo.output_components, CXIMAGE_FORMAT_JPG); - Create(cinfo.output_width, cinfo.output_height, 8*cinfo.output_components, CXIMAGE_FORMAT_JPG); - - if (!pDib) longjmp(jerr.setjmp_buffer, 1); // check if the image has been created - - if (is_exif){ -#if CXIMAGEJPG_SUPPORT_EXIF - if ((m_exifinfo.Xresolution != 0.0) && (m_exifinfo.ResolutionUnit != 0)) - SetXDPI((long)(m_exifinfo.Xresolution/m_exifinfo.ResolutionUnit)); - if ((m_exifinfo.Yresolution != 0.0) && (m_exifinfo.ResolutionUnit != 0)) - SetYDPI((long)(m_exifinfo.Yresolution/m_exifinfo.ResolutionUnit)); -#endif - } else { - switch (cinfo.density_unit) { - case 0: // [andy] fix for aspect ratio... - if((cinfo.Y_density > 0) && (cinfo.X_density > 0)){ - SetYDPI((long)(GetXDPI()*(float(cinfo.Y_density)/float(cinfo.X_density)))); - } - break; - case 2: // [andy] fix: cinfo.X/Y_density is pixels per centimeter - SetXDPI((long)floor(cinfo.X_density * 2.54 + 0.5)); - SetYDPI((long)floor(cinfo.Y_density * 2.54 + 0.5)); - break; - default: - SetXDPI(cinfo.X_density); - SetYDPI(cinfo.Y_density); - } - } - - if (cinfo.out_color_space==JCS_GRAYSCALE){ - SetGrayPalette(); - head.biClrUsed =256; - } else { - if (cinfo.quantize_colors){ - SetPalette(cinfo.actual_number_of_colors, cinfo.colormap[0], cinfo.colormap[1], cinfo.colormap[2]); - head.biClrUsed=cinfo.actual_number_of_colors; - } else { - head.biClrUsed=0; - } - } - - /* JSAMPLEs per row in output buffer */ - row_stride = cinfo.output_width * cinfo.output_components; - - /* Make a one-row-high sample array that will go away when done with image */ - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); - - /* Step 6: while (scan lines remain to be read) */ - /* jpeg_read_scanlines(...); */ - /* Here we use the library's state variable cinfo.output_scanline as the - * loop counter, so that we don't have to keep track ourselves. - */ - iter.Upset(); - while (cinfo.output_scanline < cinfo.output_height) { - - if (info.nEscape) longjmp(jerr.setjmp_buffer, 1); // - cancel decoding - - (void) jpeg_read_scanlines(&cinfo, buffer, 1); - // info.nProgress = (long)(100*cinfo.output_scanline/cinfo.output_height); - // Step 6a: CMYK->RGB */ - if ((cinfo.num_components==4)&&(cinfo.quantize_colors==false)){ - BYTE k,*dst,*src; - dst=iter.GetRow(); - src=buffer[0]; - for(long x3=0,x4=0; x3<(long)info.dwEffWidth && x4 Step 7A: Swap red and blue components - // not necessary if swapped red and blue definition in jmorecfg.h;ln322 - if ((cinfo.num_components==3)&&(cinfo.quantize_colors==false)){ - BYTE* r0=GetBits(); - for(long y=0;y - cancel decoding - RGBtoBGR(r0,3*head.biWidth); - r0+=info.dwEffWidth; - } - } - - /* Step 8: Release JPEG decompression object */ - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_decompress(&cinfo); - - /* At this point you may want to check to see whether any corrupt-data - * warnings occurred (test whether jerr.pub.num_warnings is nonzero). - */ - - /* And we're done! */ - return true; -} -//////////////////////////////////////////////////////////////////////////////// -#endif //CXIMAGE_SUPPORT_DECODE -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_ENCODE - -#ifdef DEBUG -// XXX: dirty hack. -#undef max -#undef min -#define XRCORE_API XR_IMPORT -#include "xrCore/xrDebug_macros.h" // needed for VERIFY in FTimer.h -#include "xrCommon/math_funcs_inline.h" // needed for fis_zero() in FTimer.h -#include "xrCore/FTimer.h" -#include "xrCore/log.h" -#undef XRCORE_API -#endif - -//////////////////////////////////////////////////////////////////////////////// -bool CxImageJPG::Encode(CxFile * hFile) -{ - if (EncodeSafeCheck(hFile)) return false; - - if (head.biClrUsed!=0 && !IsGrayScale()){ - strcpy(info.szLastError,"JPEG can save only RGB or GreyScale images"); - return false; - } - - // necessary for EXIF, and for roll backs - long pos=hFile->Tell(); - - /* This struct contains the JPEG compression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - * It is possible to have several such structures, representing multiple - * compression/decompression processes, in existence at once. We refer - * to any one struct (and its associated working data) as a "JPEG object". - */ - struct jpeg_compress_struct cinfo; - /* This struct represents a JPEG error handler. It is declared separately - * because applications often want to supply a specialized error handler - * (see the second half of this file for an example). But here we just - * take the easy way out and use the standard error handler, which will - * print a message on stderr and call exit() if compression fails. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - //struct jpeg_error_mgr jerr; - /* We use our private extension JPEG error handler. */ - struct jpg_error_mgr jerr; - jerr.buffer=info.szLastError; - /* More stuff */ - int row_stride; /* physical row width in image buffer */ - JSAMPARRAY buffer; /* Output row buffer */ - - /* Step 1: allocate and initialize JPEG compression object */ - /* We have to set up the error handler first, in case the initialization - * step fails. (Unlikely, but it could happen if you are out of memory.) - * This routine fills in the contents of struct jerr, and returns jerr's - * address which we place into the link field in cinfo. - */ - //cinfo.err = jpeg_std_error(&jerr); - /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = ima_jpeg_error_exit; - - /* Establish the setjmp return context for my_error_exit to use. */ -#pragma warning(push) -#pragma warning(disable:4611) - if (setjmp(jerr.setjmp_buffer)) { -#pragma warning(pop) - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - strcpy(info.szLastError, jerr.buffer); // - jpeg_destroy_compress(&cinfo); - return 0; - } - - /* Now we can initialize the JPEG compression object. */ - jpeg_create_compress(&cinfo); - /* Step 2: specify data destination (eg, a file) */ - /* Note: steps 2 and 3 can be done in either order. */ - /* Here we use the library-supplied code to send compressed data to a - * stdio stream. You can also write your own code to do something else. - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to write binary files. - */ - - //jpeg_stdio_dest(&cinfo, outfile); - CxFileJpg dest(hFile); - cinfo.dest = &dest; - - /* Step 3: set parameters for compression */ - /* First we supply a description of the input image. - * Four fields of the cinfo struct must be filled in: - */ - cinfo.image_width = GetWidth(); // image width and height, in pixels - cinfo.image_height = GetHeight(); - - if (IsGrayScale()){ - cinfo.input_components = 1; // # of color components per pixel - cinfo.in_color_space = JCS_GRAYSCALE; /* colorspace of input image */ - } else { - cinfo.input_components = 3; // # of color components per pixel - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - } - - /* Now use the library's routine to set default compression parameters. - * (You must set at least cinfo.in_color_space before calling this, - * since the defaults depend on the source color space.) - */ - jpeg_set_defaults(&cinfo); - /* Now you can set any non-default parameters you wish to. - * Here we just illustrate the use of quality (quantization table) scaling: - */ - -//#ifdef C_ARITH_CODING_SUPPORTED - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_ARITHMETIC) != 0) - cinfo.arith_code = true; -//#endif - -//#ifdef ENTROPY_OPT_SUPPORTED - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_OPTIMIZE) != 0) - cinfo.optimize_coding = true; -//#endif - - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_GRAYSCALE) != 0) - jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE); - - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_SMOOTHING) != 0) - cinfo.smoothing_factor = m_nSmoothing; - - jpeg_set_quality(&cinfo, GetJpegQuality(), (GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_BASELINE) != 0); - -//#ifdef C_PROGRESSIVE_SUPPORTED - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_PROGRESSIVE) != 0) - jpeg_simple_progression(&cinfo); -//#endif - -#ifdef C_LOSSLESS_SUPPORTED - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_LOSSLESS) != 0) - jpeg_simple_lossless(&cinfo, m_nPredictor, m_nPointTransform); -#endif - - //SetCodecOption(ENCODE_SUBSAMPLE_444 | GetCodecOption(CXIMAGE_FORMAT_JPG),CXIMAGE_FORMAT_JPG); - - // 2x2, 1x1, 1x1 (4:1:1) : High (default sub sampling) - cinfo.comp_info[0].h_samp_factor = 2; - cinfo.comp_info[0].v_samp_factor = 2; - cinfo.comp_info[1].h_samp_factor = 1; - cinfo.comp_info[1].v_samp_factor = 1; - cinfo.comp_info[2].h_samp_factor = 1; - cinfo.comp_info[2].v_samp_factor = 1; - - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_SUBSAMPLE_422) != 0){ - // 2x1, 1x1, 1x1 (4:2:2) : Medium - cinfo.comp_info[0].h_samp_factor = 2; - cinfo.comp_info[0].v_samp_factor = 1; - cinfo.comp_info[1].h_samp_factor = 1; - cinfo.comp_info[1].v_samp_factor = 1; - cinfo.comp_info[2].h_samp_factor = 1; - cinfo.comp_info[2].v_samp_factor = 1; - } - - if ((GetCodecOption(CXIMAGE_FORMAT_JPG) & ENCODE_SUBSAMPLE_444) != 0){ - // 1x1 1x1 1x1 (4:4:4) : None - cinfo.comp_info[0].h_samp_factor = 1; - cinfo.comp_info[0].v_samp_factor = 1; - cinfo.comp_info[1].h_samp_factor = 1; - cinfo.comp_info[1].v_samp_factor = 1; - cinfo.comp_info[2].h_samp_factor = 1; - cinfo.comp_info[2].v_samp_factor = 1; - } - - cinfo.density_unit=1; - cinfo.X_density=(unsigned short)GetXDPI(); - cinfo.Y_density=(unsigned short)GetYDPI(); - - /* Step 4: Start compressor */ - /* true ensures that we will write a complete interchange-JPEG file. - * Pass true unless you are very sure of what you're doing. - */ - jpeg_start_compress(&cinfo, true); - - /* Step 5: while (scan lines remain to be written) */ - /* jpeg_write_scanlines(...); */ - /* Here we use the library's state variable cinfo.next_scanline as the - * loop counter, so that we don't have to keep track ourselves. - * To keep things simple, we pass one scanline per call; you can pass - * more if you wish, though. - */ - row_stride = info.dwEffWidth; /* JSAMPLEs per row in image_buffer */ - - // "8+row_stride" fix heap deallocation problem during debug??? - buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr) &cinfo, JPOOL_IMAGE, 8+row_stride, 1); - - CImageIterator iter(this); - -#ifdef DEBUG - CTimer tmp_dbg_timer; - tmp_dbg_timer.Start(); -#endif //#ifdef DEBUG - - iter.Upset(); - while (cinfo.next_scanline < cinfo.image_height) { - // info.nProgress = (long)(100*cinfo.next_scanline/cinfo.image_height); - iter.GetRow(buffer[0], row_stride); - // not necessary if swapped red and blue definition in jmorecfg.h;ln322 - if (head.biClrUsed==0){ // swap R & B for RGB images - RGBtoBGR(buffer[0], row_stride); // Lance : 1998/09/01 : Bug ID: EXP-2.1.1-9 - } - iter.PrevRow(); - (void) jpeg_write_scanlines(&cinfo, buffer, 1); - } - -#ifdef DEBUG - Msg("JPEG compressing cycle time : %u ms", tmp_dbg_timer.GetElapsed_ms()); -#endif - - - /* Step 6: Finish compression */ - jpeg_finish_compress(&cinfo); - - /* Step 7: release JPEG compression object */ - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_compress(&cinfo); - - -#if CXIMAGEJPG_SUPPORT_EXIF - if (m_exif && m_exif->m_exifinfo->IsExif){ - // discard useless sections (if any) read from original image - m_exif->DiscardAllButExif(); - // read new created image, to split the sections - hFile->Seek(pos,SEEK_SET); - m_exif->DecodeExif(hFile,EXIF_READ_IMAGE); - // save back the image, adding EXIF section - hFile->Seek(pos,SEEK_SET); - m_exif->EncodeExif(hFile); - } -#endif - - - /* And we're done! */ - return true; -} -//////////////////////////////////////////////////////////////////////////////// -#endif // CXIMAGE_SUPPORT_ENCODE -//////////////////////////////////////////////////////////////////////////////// -#endif // CXIMAGE_SUPPORT_JPG - diff --git a/Externals/cximage/ximajpg.h b/Externals/cximage/ximajpg.h deleted file mode 100644 index 900c1cf4b02..00000000000 --- a/Externals/cximage/ximajpg.h +++ /dev/null @@ -1,315 +0,0 @@ -/* - * 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 - * - * original CImageJPG and CImageIterator implementation are: - * Copyright: (c) 1995, Alejandro Aguilar Sierra - * - * 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 - -#include -#include - -#define CXIMAGEJPG_SUPPORT_EXIF 1 - -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 - */ - -#if CXIMAGEJPG_SUPPORT_EXIF - -#define MAX_COMMENT 1000 -#define MAX_SECTIONS 20 - -typedef struct tag_ExifInfo { - char Version [5]; - char CameraMake [32]; - char CameraModel [40]; - char DateTime [20]; - int Height, Width; - int Orientation; - int IsColor; - int Process; - int FlashUsed; - float FocalLength; - float ExposureTime; - float ApertureFNumber; - float Distance; - float CCDWidth; - float ExposureBias; - int Whitebalance; - int MeteringMode; - int ExposureProgram; - int ISOequivalent; - int CompressionLevel; - float FocalplaneXRes; - float FocalplaneYRes; - float FocalplaneUnits; - float Xresolution; - float Yresolution; - float ResolutionUnit; - float Brightness; - char Comments[MAX_COMMENT]; - - unsigned char * ThumbnailPointer; /* Pointer at the thumbnail */ - unsigned ThumbnailSize; /* Size of thumbnail. */ - - bool IsExif; -} EXIFINFO; - -//-------------------------------------------------------------------------- -// 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{ - BYTE* Data; - int Type; - unsigned Size; -} Section_t; - -public: - EXIFINFO* m_exifinfo; - char m_szLastError[256]; - CxExifInfo(EXIFINFO* info = NULL); - ~CxExifInfo(); - bool DecodeExif(CxFile * hFile, int nReadMode = EXIF_READ_EXIF); - bool EncodeExif(CxFile * hFile); - void DiscardAllButExif(); -protected: - bool process_EXIF(unsigned char * CharBuf, unsigned int length); - void process_COM (const BYTE * Data, int length); - void process_SOFn (const BYTE * Data, int marker); - int Get16u(void * Short); - int Get16m(void * Short); - long Get32s(void * Long); - unsigned long Get32u(void * Long); - double ConvertAnyFormat(void * ValuePtr, int Format); - void* FindSection(int SectionType); - bool ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength, - EXIFINFO * const pInfo, unsigned char ** const LastExifRefdP, int NestingLevel=0); - int ExifImageWidth; - int MotorolaOrder; - Section_t Sections[MAX_SECTIONS]; - int SectionsRead; - bool freeinfo; -}; - - CxExifInfo* m_exif; - EXIFINFO m_exifinfo; - bool DecodeExif(CxFile * hFile); - bool DecodeExif(FILE * hFile) { CxIOFile file(hFile); return DecodeExif(&file); } - -#endif //CXIMAGEJPG_SUPPORT_EXIF - -//////////////////////////////////////////////////////////////////////////////////////// -////////////////////// C x F i l e J p g //////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// - -// thanks to Chris Shearer Cooper -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 unsigned char[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 > (long)pSource->bytes_in_buffer){ - num_bytes -= (long)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; - unsigned char *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 - }; - - int m_nPredictor; - int m_nPointTransform; - int m_nSmoothing; - int m_nQuantize; - J_DITHER_MODE m_nDither; - -}; - -#endif - -#endif diff --git a/Externals/cximage/ximalpha.cpp b/Externals/cximage/ximalpha.cpp deleted file mode 100644 index e595c0bbbcf..00000000000 --- a/Externals/cximage/ximalpha.cpp +++ /dev/null @@ -1,365 +0,0 @@ -// xImalpha.cpp : Alpha channel functions -/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_ALPHA - -//////////////////////////////////////////////////////////////////////////////// -/** - * \sa AlphaSetMax - */ -BYTE CxImage::AlphaGetMax() const -{ - return info.nAlphaMax; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets global Alpha (opacity) value applied to the whole image, - * valid only for painting functions. - * \param nAlphaMax: can be from 0 to 255 - */ -void CxImage::AlphaSetMax(BYTE nAlphaMax) -{ - info.nAlphaMax=nAlphaMax; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the image has a valid alpha channel. - */ -bool CxImage::AlphaIsValid() -{ - return pAlpha!=0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Enables the alpha palette, so the Draw() function changes its behavior. - */ -void CxImage::AlphaPaletteEnable(bool enable) -{ - info.bAlphaPaletteEnabled=enable; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * True if the alpha palette is enabled for painting. - */ -bool CxImage::AlphaPaletteIsEnabled() -{ - return info.bAlphaPaletteEnabled; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the alpha channel to full transparent. AlphaSet(0) has the same effect - */ -void CxImage::AlphaClear() -{ - if (pAlpha) memset(pAlpha,0,head.biWidth * head.biHeight); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets the alpha level for the whole image. - * \param level : from 0 (transparent) to 255 (opaque) - */ -void CxImage::AlphaSet(BYTE level) -{ - if (pAlpha) memset(pAlpha,level,head.biWidth * head.biHeight); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Allocates an empty (opaque) alpha channel. - */ -bool CxImage::AlphaCreate() -{ - if (pAlpha==NULL) { - pAlpha = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - if (pAlpha) memset(pAlpha,255,head.biWidth * head.biHeight); - } - return (pAlpha!=0); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::AlphaDelete() -{ - if (pAlpha) { cxfree(pAlpha);/*free(pAlpha);*/ pAlpha=0; } -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::AlphaInvert() -{ - if (pAlpha) { - BYTE *iSrc=pAlpha; - long n=head.biHeight*head.biWidth; - for(long i=0; i < n; i++){ - *iSrc=(BYTE)~(*(iSrc)); - iSrc++; - } - } -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Imports an existing alpa channel from another image with the same width and height. - */ -bool CxImage::AlphaCopy(CxImage &from) -{ - if (from.pAlpha == NULL || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; - if (pAlpha==NULL) pAlpha = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - if (pAlpha==NULL) return false; - memcpy(pAlpha,from.pAlpha,head.biWidth * head.biHeight); - info.nAlphaMax=from.info.nAlphaMax; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Creates the alpha channel from a gray scale image. - */ -bool CxImage::AlphaSet(CxImage &from) -{ - if (!from.IsGrayScale() || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; - if (pAlpha==NULL) pAlpha = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - BYTE* src = from.info.pImage; - BYTE* dst = pAlpha; - if (src==NULL || dst==NULL) return false; - for (long y=0; y>8); - c.rgbGreen = (BYTE)((c.rgbGreen * a + a1 * info.nBkgndColor.rgbGreen)>>8); - c.rgbRed = (BYTE)((c.rgbRed * a + a1 * info.nBkgndColor.rgbRed)>>8); - BlindSetPixelColor(x,y,c); - } - } - AlphaDelete(); - } else { - CxImage tmp(head.biWidth,head.biHeight,24); - if (!tmp.IsValid()){ - strcpy(info.szLastError,tmp.GetLastError()); - return; - } - - for(long y=0; y>8); - c.rgbGreen = (BYTE)((c.rgbGreen * a + a1 * info.nBkgndColor.rgbGreen)>>8); - c.rgbRed = (BYTE)((c.rgbRed * a + a1 * info.nBkgndColor.rgbRed)>>8); - tmp.BlindSetPixelColor(x,y,c); - } - } - Transfer(tmp); - } - return; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::AlphaFlip() -{ - if (!pAlpha) return false; - - BYTE *buff = (BYTE*)cxalloc(head.biWidth);//malloc(head.biWidth); - if (!buff) return false; - - BYTE *iSrc,*iDst; - iSrc = pAlpha + (head.biHeight-1)*head.biWidth; - iDst = pAlpha; - for (long i=0; i<(head.biHeight/2); ++i) - { - memcpy(buff, iSrc, head.biWidth); - memcpy(iSrc, iDst, head.biWidth); - memcpy(iDst, buff, head.biWidth); - iSrc-=head.biWidth; - iDst+=head.biWidth; - } - - cxfree(buff);//free(buff); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::AlphaMirror() -{ - if (!pAlpha) return false; - BYTE* pAlpha2 = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - if (!pAlpha2) return false; - BYTE *iSrc,*iDst; - long wdt=head.biWidth-1; - iSrc=pAlpha + wdt; - iDst=pAlpha2; - for(long y=0; y < head.biHeight; y++){ - for(long x=0; x <= wdt; x++) - *(iDst+x)=*(iSrc-x); - iSrc+=head.biWidth; - iDst+=head.biWidth; - } - cxfree(pAlpha);//free(pAlpha); - pAlpha=pAlpha2; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Exports the alpha channel in a 8bpp grayscale image. - */ -bool CxImage::AlphaSplit(CxImage *dest) -{ - if (!pAlpha || !dest) return false; - - CxImage tmp(head.biWidth,head.biHeight,8); - if (!tmp.IsValid()){ - strcpy(info.szLastError,tmp.GetLastError()); - return false; - } - - for(long y=0; yTransfer(tmp); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Exports the alpha palette channel in a 8bpp grayscale image. - */ -bool CxImage::AlphaPaletteSplit(CxImage *dest) -{ - if (!AlphaPaletteIsValid() || !dest) return false; - - CxImage tmp(head.biWidth,head.biHeight,8); - if (!tmp.IsValid()){ - strcpy(info.szLastError,tmp.GetLastError()); - return false; - } - - for(long y=0; yTransfer(tmp); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Merge in the alpha layer the transparent color mask - * (previously set with SetTransColor or SetTransIndex) - */ -bool CxImage::AlphaFromTransparency() -{ - if (!IsValid() || !IsTransparent()) - return false; - - AlphaCreate(); - - for(long y=0; y info.nNumLayers ) position = info.nNumLayers; - - CxImage** ptmp = new CxImage*[info.nNumLayers + 1]; - if (ptmp==0) return false; - - int i=0; - for (int n=0; ninfo.pParent = this; - } else { - cxfree(ptmp);//free(ptmp); - return false; - } - - info.nNumLayers++; - delete [] ppLayers; - ppLayers = ptmp; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Deletes a layer. If position is less than 0, the last layer will be deleted - */ -bool CxImage::LayerDelete(long position) -{ - if ( position >= info.nNumLayers ) return false; - if ( position < 0) position = info.nNumLayers - 1; - if ( position < 0) return false; - - if (info.nNumLayers>1){ - - CxImage** ptmp = new CxImage*[info.nNumLayers - 1]; - if (ptmp==0) return false; - - int i=0; - for (int n=0; n= info.nNumLayers ) return NULL; - if ( position < 0) position = info.nNumLayers - 1; - return ppLayers[position]; -} -//////////////////////////////////////////////////////////////////////////////// -#endif //CXIMAGE_SUPPORT_LAYERS diff --git a/Externals/cximage/ximapal.cpp b/Externals/cximage/ximapal.cpp deleted file mode 100644 index 97f0d9aeaa0..00000000000 --- a/Externals/cximage/ximapal.cpp +++ /dev/null @@ -1,834 +0,0 @@ -// xImaPal.cpp : Palette and Pixel functions -/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximage.h" - -//////////////////////////////////////////////////////////////////////////////// -/** - * returns the palette dimension in byte - */ -DWORD CxImage::GetPaletteSize() -{ - return (head.biClrUsed * sizeof(RGBQUAD)); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::SetPaletteColor(BYTE idx, BYTE r, BYTE g, BYTE b, BYTE alpha) -{ - if ((pDib)&&(head.biClrUsed)){ - BYTE* iDst = (BYTE*)(pDib) + sizeof(BITMAPINFOHEADER); - if (idx=head.biWidth)||(y>=head.biHeight)) { - if (info.nBkgndIndex >= 0) return (BYTE)info.nBkgndIndex; - else return *info.pImage; - } - if (head.biBitCount==8){ - return info.pImage[y*info.dwEffWidth + x]; - } else { - BYTE pos; - BYTE iDst= info.pImage[y*info.dwEffWidth + (x*head.biBitCount >> 3)]; - if (head.biBitCount==4){ - pos = (BYTE)(4*(1-x%2)); - iDst &= (0x0F<> pos); - } else if (head.biBitCount==1){ - pos = (BYTE)(7-x%8); - iDst &= (0x01<> pos); - } - } - return 0; -} -//////////////////////////////////////////////////////////////////////////////// -BYTE CxImage::BlindGetPixelIndex(const long x,const long y) -{ -#ifdef _DEBUG - if ((pDib==NULL) || (head.biClrUsed==0) || !IsInside(x,y)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return 0; - #endif -#endif - - if (head.biBitCount==8){ - return info.pImage[y*info.dwEffWidth + x]; - } else { - BYTE pos; - BYTE iDst= info.pImage[y*info.dwEffWidth + (x*head.biBitCount >> 3)]; - if (head.biBitCount==4){ - pos = (BYTE)(4*(1-x%2)); - iDst &= (0x0F<> pos); - } else if (head.biBitCount==1){ - pos = (BYTE)(7-x%8); - iDst &= (0x01<> pos); - } - } - return 0; -} -//////////////////////////////////////////////////////////////////////////////// -RGBQUAD CxImage::GetPixelColor(long x,long y, bool bGetAlpha) -{ -// RGBQUAD rgb={0,0,0,0}; - RGBQUAD rgb=info.nBkgndColor; // - if ((pDib==NULL)||(x<0)||(y<0)|| - (x>=head.biWidth)||(y>=head.biHeight)){ - if (info.nBkgndIndex >= 0){ - if (head.biBitCount<24) return GetPaletteColor((BYTE)info.nBkgndIndex); - else return info.nBkgndColor; - } else if (pDib) return GetPixelColor(0,0); - return rgb; - } - - if (head.biClrUsed){ - rgb = GetPaletteColor(BlindGetPixelIndex(x,y)); - } else { - BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; - rgb.rgbBlue = *iDst++; - rgb.rgbGreen= *iDst++; - rgb.rgbRed = *iDst; - } -#if CXIMAGE_SUPPORT_ALPHA - if (pAlpha && bGetAlpha) rgb.rgbReserved = BlindAlphaGet(x,y); -#else - rgb.rgbReserved = 0; -#endif //CXIMAGE_SUPPORT_ALPHA - return rgb; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * This is (a bit) faster version of GetPixelColor. - * It tests bounds only in debug mode (_DEBUG defined). - * - * It is an error to request out-of-borders pixel with this method. - * In DEBUG mode an exception will be thrown, and data will be violated in non-DEBUG mode. - * \author ***bd*** 2.2004 - */ -RGBQUAD CxImage::BlindGetPixelColor(const long x,const long y, bool bGetAlpha) -{ - RGBQUAD rgb; -#ifdef _DEBUG - if ((pDib==NULL) || !IsInside(x,y)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - {rgb.rgbReserved = 0; return rgb;} - #endif -#endif - - if (head.biClrUsed){ - rgb = GetPaletteColor(BlindGetPixelIndex(x,y)); - } else { - BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; - rgb.rgbBlue = *iDst++; - rgb.rgbGreen= *iDst++; - rgb.rgbRed = *iDst; - rgb.rgbReserved = 0; //needed for images without alpha layer - } -#if CXIMAGE_SUPPORT_ALPHA - if (pAlpha && bGetAlpha) rgb.rgbReserved = BlindAlphaGet(x,y); -#else - rgb.rgbReserved = 0; -#endif //CXIMAGE_SUPPORT_ALPHA - return rgb; -} -//////////////////////////////////////////////////////////////////////////////// -BYTE CxImage::GetPixelGray(long x, long y) -{ - RGBQUAD color = GetPixelColor(x,y); - return (BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::BlindSetPixelIndex(long x,long y,BYTE i) -{ -#ifdef _DEBUG - if ((pDib==NULL)||(head.biClrUsed==0)|| - (x<0)||(y<0)||(x>=head.biWidth)||(y>=head.biHeight)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return; - #endif -#endif - - if (head.biBitCount==8){ - info.pImage[y*info.dwEffWidth + x]=i; - return; - } else { - BYTE pos; - BYTE* iDst= info.pImage + y*info.dwEffWidth + (x*head.biBitCount >> 3); - if (head.biBitCount==4){ - pos = (BYTE)(4*(1-x%2)); - *iDst &= ~(0x0F<=head.biWidth)||(y>=head.biHeight)) return ; - - if (head.biBitCount==8){ - info.pImage[y*info.dwEffWidth + x]=i; - return; - } else { - BYTE pos; - BYTE* iDst= info.pImage + y*info.dwEffWidth + (x*head.biBitCount >> 3); - if (head.biBitCount==4){ - pos = (BYTE)(4*(1-x%2)); - *iDst &= ~(0x0F<=head.biWidth)||(y>=head.biHeight)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return; - #endif -#endif - if (head.biClrUsed) - BlindSetPixelIndex(x,y,GetNearestIndex(c)); - else { - BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; - *iDst++ = c.rgbBlue; - *iDst++ = c.rgbGreen; - *iDst = c.rgbRed; - } -#if CXIMAGE_SUPPORT_ALPHA - if (bSetAlpha) AlphaSet(x,y,c.rgbReserved); -#endif //CXIMAGE_SUPPORT_ALPHA -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::SetPixelColor(long x,long y,RGBQUAD c, bool bSetAlpha) -{ - if ((pDib==NULL)||(x<0)||(y<0)|| - (x>=head.biWidth)||(y>=head.biHeight)) return; - if (head.biClrUsed) - BlindSetPixelIndex(x,y,GetNearestIndex(c)); - else { - BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; - *iDst++ = c.rgbBlue; - *iDst++ = c.rgbGreen; - *iDst = c.rgbRed; - } -#if CXIMAGE_SUPPORT_ALPHA - if (bSetAlpha) AlphaSet(x,y,c.rgbReserved); -#endif //CXIMAGE_SUPPORT_ALPHA -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Blends the current pixel color with a new color. - * \param x,y = pixel - * \param c = new color - * \param blend = can be from 0 (no effect) to 1 (full effect). - * \param bSetAlpha = if true, blends also the alpha component stored in c.rgbReserved - */ -void CxImage::BlendPixelColor(long x,long y,RGBQUAD c, float blend, bool bSetAlpha) -{ - if ((pDib==NULL)||(x<0)||(y<0)|| - (x>=head.biWidth)||(y>=head.biHeight)) return; - - int a0 = (int)(256*blend); - int a1 = 256 - a0; - - RGBQUAD c0 = BlindGetPixelColor(x,y); - c.rgbRed = (BYTE)((c.rgbRed * a0 + c0.rgbRed * a1)>>8); - c.rgbBlue = (BYTE)((c.rgbBlue * a0 + c0.rgbBlue * a1)>>8); - c.rgbGreen = (BYTE)((c.rgbGreen * a0 + c0.rgbGreen * a1)>>8); - - if (head.biClrUsed) - BlindSetPixelIndex(x,y,GetNearestIndex(c)); - else { - BYTE* iDst = info.pImage + y*info.dwEffWidth + x*3; - *iDst++ = c.rgbBlue; - *iDst++ = c.rgbGreen; - *iDst = c.rgbRed; -#if CXIMAGE_SUPPORT_ALPHA - if (bSetAlpha) AlphaSet(x,y,c.rgbReserved); -#endif //CXIMAGE_SUPPORT_ALPHA - } -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Returns the best palette index that matches a specified color. - */ -BYTE CxImage::GetNearestIndex(RGBQUAD c) -{ - if ((pDib==NULL)||(head.biClrUsed==0)) return 0; - - // check matching with the previous result - if (info.last_c_isvalid && (*(long*)&info.last_c == *(long*)&c)) return info.last_c_index; - info.last_c = c; - info.last_c_isvalid = true; - - BYTE* iDst = (BYTE*)(pDib) + sizeof(BITMAPINFOHEADER); - long distance=200000; - int i,j = 0; - long k,l; - int m = (int)(head.biClrImportant==0 ? head.biClrUsed : head.biClrImportant); - for(i=0,l=0;i100) perc=100; - for(i=0;i=0){ - if (head.biClrUsed){ - if (GetPixelIndex(x,y) == info.nBkgndIndex) return true; - } else { - RGBQUAD ct = info.nBkgndColor; - RGBQUAD c = GetPixelColor(x,y,false); - if (*(long*)&c==*(long*)&ct) return true; - } - } - -#if CXIMAGE_SUPPORT_ALPHA - if (pAlpha) return AlphaGet(x,y)==0; -#endif - - return false; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::GetTransparentMask(CxImage* iDst) -{ - if (!pDib) return false; - - CxImage tmp; - tmp.Create(head.biWidth, head.biHeight, 1, GetType()); - tmp.SetStdPalette(); - tmp.Clear(0); - - for(long y=0; yTransfer(tmp); - else Transfer(tmp); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if image has the same palette, if any. - * \param img = image to compare. - * \param bCheckAlpha = check also the rgbReserved field. - */ -bool CxImage::IsSamePalette(CxImage &img, bool bCheckAlpha) -{ - if (head.biClrUsed != img.head.biClrUsed) - return false; - if (head.biClrUsed == 0) - return false; - - RGBQUAD c1,c2; - for (DWORD n=0; n256) { - head.biClrImportant = 0; - return; - } - - switch(head.biBitCount){ - case 1: - head.biClrImportant = MIN(ncolors,2); - break; - case 4: - head.biClrImportant = MIN(ncolors,16); - break; - case 8: - head.biClrImportant = ncolors; - break; - } - return; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Returns pointer to pixel. Currently implemented only for truecolor images. - * - * \param x,y - coordinates - * - * \return pointer to first byte of pixel data - * - * \author ***bd*** 2.2004 - */ -void* CxImage::BlindGetPixelPointer(const long x, const long y) -{ -#ifdef _DEBUG - if ((pDib==NULL) || !IsInside(x,y)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return 0; - #endif -#endif - if (!IsIndexed()) - return info.pImage + y*info.dwEffWidth + x*3; - else - return 0; -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::DrawLine(int StartX, int EndX, int StartY, int EndY, COLORREF cr) -{ - DrawLine(StartX, EndX, StartY, EndY, RGBtoRGBQUAD(cr)); -} -//////////////////////////////////////////////////////////////////////////////// -void CxImage::DrawLine(int StartX, int EndX, int StartY, int EndY, RGBQUAD color, bool bSetAlpha) -{ - if (!pDib) return; - ////////////////////////////////////////////////////// - // Draws a line using the Bresenham line algorithm - // Thanks to Jordan DeLozier - ////////////////////////////////////////////////////// - int x1 = StartX; - int y1 = StartY; - int x = x1; // Start x off at the first pixel - int y = y1; // Start y off at the first pixel - int x2 = EndX; - int y2 = EndY; - - int xinc1,xinc2,yinc1,yinc2; // Increasing values - int den, num, numadd,numpixels; - int deltax = abs(x2 - x1); // The difference between the x's - int deltay = abs(y2 - y1); // The difference between the y's - - // Get Increasing Values - if (x2 >= x1) { // The x-values are increasing - xinc1 = 1; - xinc2 = 1; - } else { // The x-values are decreasing - xinc1 = -1; - xinc2 = -1; - } - - if (y2 >= y1) { // The y-values are increasing - yinc1 = 1; - yinc2 = 1; - } else { // The y-values are decreasing - yinc1 = -1; - yinc2 = -1; - } - - // Actually draw the line - if (deltax >= deltay) // There is at least one x-value for every y-value - { - xinc1 = 0; // Don't change the x when numerator >= denominator - yinc2 = 0; // Don't change the y for every iteration - den = deltax; - num = deltax / 2; - numadd = deltay; - numpixels = deltax; // There are more x-values than y-values - } - else // There is at least one y-value for every x-value - { - xinc2 = 0; // Don't change the x for every iteration - yinc1 = 0; // Don't change the y when numerator >= denominator - den = deltay; - num = deltay / 2; - numadd = deltax; - numpixels = deltay; // There are more y-values than x-values - } - - for (int curpixel = 0; curpixel <= numpixels; curpixel++) - { - // Draw the current pixel - SetPixelColor(x,y,color,bSetAlpha); - - num += numadd; // Increase the numerator by the top of the fraction - if (num >= den) // Check if numerator >= denominator - { - num -= den; // Calculate the new numerator value - x += xinc1; // Change the x as appropriate - y += yinc1; // Change the y as appropriate - } - x += xinc2; // Change the x as appropriate - y += yinc2; // Change the y as appropriate - } -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Sets a palette with standard colors for 1, 4 and 8 bpp images. - */ -void CxImage::SetStdPalette() -{ - if (!pDib) return; - switch (head.biBitCount){ - case 8: - { - const BYTE pal256[1024] = {0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0,128,0,0,0,128,0,128,0,128,128,0,0,192,192,192,0, - 192,220,192,0,240,202,166,0,212,240,255,0,177,226,255,0,142,212,255,0,107,198,255,0, - 72,184,255,0,37,170,255,0,0,170,255,0,0,146,220,0,0,122,185,0,0,98,150,0,0,74,115,0,0, - 50,80,0,212,227,255,0,177,199,255,0,142,171,255,0,107,143,255,0,72,115,255,0,37,87,255,0,0, - 85,255,0,0,73,220,0,0,61,185,0,0,49,150,0,0,37,115,0,0,25,80,0,212,212,255,0,177,177,255,0, - 142,142,255,0,107,107,255,0,72,72,255,0,37,37,255,0,0,0,254,0,0,0,220,0,0,0,185,0,0,0,150,0, - 0,0,115,0,0,0,80,0,227,212,255,0,199,177,255,0,171,142,255,0,143,107,255,0,115,72,255,0, - 87,37,255,0,85,0,255,0,73,0,220,0,61,0,185,0,49,0,150,0,37,0,115,0,25,0,80,0,240,212,255,0, - 226,177,255,0,212,142,255,0,198,107,255,0,184,72,255,0,170,37,255,0,170,0,255,0,146,0,220,0, - 122,0,185,0,98,0,150,0,74,0,115,0,50,0,80,0,255,212,255,0,255,177,255,0,255,142,255,0,255,107,255,0, - 255,72,255,0,255,37,255,0,254,0,254,0,220,0,220,0,185,0,185,0,150,0,150,0,115,0,115,0,80,0,80,0, - 255,212,240,0,255,177,226,0,255,142,212,0,255,107,198,0,255,72,184,0,255,37,170,0,255,0,170,0, - 220,0,146,0,185,0,122,0,150,0,98,0,115,0,74,0,80,0,50,0,255,212,227,0,255,177,199,0,255,142,171,0, - 255,107,143,0,255,72,115,0,255,37,87,0,255,0,85,0,220,0,73,0,185,0,61,0,150,0,49,0,115,0,37,0, - 80,0,25,0,255,212,212,0,255,177,177,0,255,142,142,0,255,107,107,0,255,72,72,0,255,37,37,0,254,0, - 0,0,220,0,0,0,185,0,0,0,150,0,0,0,115,0,0,0,80,0,0,0,255,227,212,0,255,199,177,0,255,171,142,0, - 255,143,107,0,255,115,72,0,255,87,37,0,255,85,0,0,220,73,0,0,185,61,0,0,150,49,0,0,115,37,0, - 0,80,25,0,0,255,240,212,0,255,226,177,0,255,212,142,0,255,198,107,0,255,184,72,0,255,170,37,0, - 255,170,0,0,220,146,0,0,185,122,0,0,150,98,0,0,115,74,0,0,80,50,0,0,255,255,212,0,255,255,177,0, - 255,255,142,0,255,255,107,0,255,255,72,0,255,255,37,0,254,254,0,0,220,220,0,0,185,185,0,0,150,150,0, - 0,115,115,0,0,80,80,0,0,240,255,212,0,226,255,177,0,212,255,142,0,198,255,107,0,184,255,72,0, - 170,255,37,0,170,255,0,0,146,220,0,0,122,185,0,0,98,150,0,0,74,115,0,0,50,80,0,0,227,255,212,0, - 199,255,177,0,171,255,142,0,143,255,107,0,115,255,72,0,87,255,37,0,85,255,0,0,73,220,0,0,61,185,0, - 0,49,150,0,0,37,115,0,0,25,80,0,0,212,255,212,0,177,255,177,0,142,255,142,0,107,255,107,0,72,255,72,0, - 37,255,37,0,0,254,0,0,0,220,0,0,0,185,0,0,0,150,0,0,0,115,0,0,0,80,0,0,212,255,227,0,177,255,199,0, - 142,255,171,0,107,255,143,0,72,255,115,0,37,255,87,0,0,255,85,0,0,220,73,0,0,185,61,0,0,150,49,0,0, - 115,37,0,0,80,25,0,212,255,240,0,177,255,226,0,142,255,212,0,107,255,198,0,72,255,184,0,37,255,170,0, - 0,255,170,0,0,220,146,0,0,185,122,0,0,150,98,0,0,115,74,0,0,80,50,0,212,255,255,0,177,255,255,0, - 142,255,255,0,107,255,255,0,72,255,255,0,37,255,255,0,0,254,254,0,0,220,220,0,0,185,185,0,0, - 150,150,0,0,115,115,0,0,80,80,0,242,242,242,0,230,230,230,0,218,218,218,0,206,206,206,0,194,194,194,0, - 182,182,182,0,170,170,170,0,158,158,158,0,146,146,146,0,134,134,134,0,122,122,122,0,110,110,110,0, - 98,98,98,0,86,86,86,0,74,74,74,0,62,62,62,0,50,50,50,0,38,38,38,0,26,26,26,0,14,14,14,0,240,251,255,0, - 164,160,160,0,128,128,128,0,0,0,255,0,0,255,0,0,0,255,255,0,255,0,0,0,255,0,255,0,255,255,0,0,255,255,255,0}; - memcpy(GetPalette(),pal256,1024); - break; - } - case 4: - { - const BYTE pal16[64]={0,0,0,0,0,0,128,0,0,128,0,0,0,128,128,0,128,0,0,0,128,0,128,0,128,128,0,0,192,192,192,0, - 128,128,128,0,0,0,255,0,0,255,0,0,0,255,255,0,255,0,0,0,255,0,255,0,255,255,0,0,255,255,255,0}; - memcpy(GetPalette(),pal16,64); - break; - } - case 1: - { - const BYTE pal2[8]={0,0,0,0,255,255,255,0}; - memcpy(GetPalette(),pal2,8); - break; - } - } - info.last_c_isvalid = false; - return; -} -//////////////////////////////////////////////////////////////////////////////// diff --git a/Externals/cximage/ximasel.cpp b/Externals/cximage/ximasel.cpp deleted file mode 100644 index 8831eba081a..00000000000 --- a/Externals/cximage/ximasel.cpp +++ /dev/null @@ -1,697 +0,0 @@ -// xImaSel.cpp : Selection functions -/* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 6.0.0 02/Feb/2008 - */ - -#include "ximage.h" - -#if CXIMAGE_SUPPORT_SELECTION - -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the image has a valid selection. - */ -bool CxImage::SelectionIsValid() -{ - return pSelection!=0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Gets the smallest rectangle that contains the selection - */ -void CxImage::SelectionGetBox(RECT& r) -{ - memcpy(&r,&info.rSelectionBox,sizeof(RECT)); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Empties the selection. - */ -bool CxImage::SelectionClear(BYTE level) -{ - if (pSelection){ - if (level==0){ - memset(pSelection,0,head.biWidth * head.biHeight); - info.rSelectionBox.left = head.biWidth; - info.rSelectionBox.bottom = head.biHeight; - info.rSelectionBox.right = info.rSelectionBox.top = 0; - } else { - memset(pSelection,level,head.biWidth * head.biHeight); - info.rSelectionBox.right = head.biWidth; - info.rSelectionBox.top = head.biHeight; - info.rSelectionBox.left = info.rSelectionBox.bottom = 0; - } - return true; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Allocates an empty selection. - */ -bool CxImage::SelectionCreate() -{ - SelectionDelete(); - pSelection = (BYTE*)calloc(head.biWidth * head.biHeight, 1); - return (pSelection!=0); -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Deallocates the selction. - */ -bool CxImage::SelectionDelete() -{ - if (pSelection){ - cxfree(pSelection);//free(pSelection); - pSelection=NULL; - } - info.rSelectionBox.left = head.biWidth; - info.rSelectionBox.bottom = head.biHeight; - info.rSelectionBox.right = info.rSelectionBox.top = 0; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the coordinates are inside the selection. - */ -bool CxImage::SelectionIsInside(long x, long y) -{ - if (IsInside(x,y)){ - if (pSelection==NULL) return true; - return pSelection[x+y*head.biWidth]!=0; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Checks if the coordinates are inside the selection. - * "blind" version assumes that (x,y) is inside to the image. - */ -bool CxImage::BlindSelectionIsInside(long x, long y) -{ -#ifdef _DEBUG - if (!IsInside(x,y)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return 0; - #endif -#endif - if (pSelection==NULL) return true; - return pSelection[x+y*head.biWidth]!=0; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Adds a rectangle to the existing selection. - */ -bool CxImage::SelectionAddRect(RECT r, BYTE level) -{ - if (pSelection==NULL) SelectionCreate(); - if (pSelection==NULL) return false; - - RECT r2; - if (r.left r2.left) info.rSelectionBox.left = MAX(0L,MIN(head.biWidth,r2.left)); - if (info.rSelectionBox.right <= r2.right) info.rSelectionBox.right = MAX(0L,MIN(head.biWidth,r2.right+1)); - if (info.rSelectionBox.bottom > r2.bottom) info.rSelectionBox.bottom = MAX(0L,MIN(head.biHeight,r2.bottom)); - - long ymin = MAX(0L,MIN(head.biHeight,r2.bottom)); - long ymax = MAX(0L,MIN(head.biHeight,r2.top+1)); - long xmin = MAX(0L,MIN(head.biWidth,r2.left)); - long xmax = MAX(0L,MIN(head.biWidth,r2.right+1)); - - for (long y=ymin; y (xcenter - xradius)) info.rSelectionBox.left = MAX(0L,MIN(head.biWidth,(xcenter - xradius))); - if (info.rSelectionBox.right <= (xcenter + xradius)) info.rSelectionBox.right = MAX(0L,MIN(head.biWidth,(xcenter + xradius + 1))); - if (info.rSelectionBox.bottom > (ycenter - yradius)) info.rSelectionBox.bottom = MAX(0L,MIN(head.biHeight,(ycenter - yradius))); - if (info.rSelectionBox.top <= (ycenter + yradius)) info.rSelectionBox.top = MAX(0L,MIN(head.biHeight,(ycenter + yradius + 1))); - - long xmin = MAX(0L,MIN(head.biWidth,xcenter - xradius)); - long xmax = MAX(0L,MIN(head.biWidth,xcenter + xradius + 1)); - long ymin = MAX(0L,MIN(head.biHeight,ycenter - yradius)); - long ymax = MAX(0L,MIN(head.biHeight,ycenter + yradius + 1)); - - long y,yo; - for (y=ymin; yy) pSelection[x + y * head.biWidth] = level; - } - } - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Inverts the selection. - * Note: the SelectionBox is set to "full image", call SelectionGetBox before (if necessary) - */ -bool CxImage::SelectionInvert() -{ - if (pSelection) { - BYTE *iSrc=pSelection; - long n=head.biHeight*head.biWidth; - for(long i=0; i < n; i++){ - *iSrc=(BYTE)~(*(iSrc)); - iSrc++; - } - - SelectionRebuildBox(); - - return true; - } - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Imports an existing region from another image with the same width and height. - */ -bool CxImage::SelectionCopy(CxImage &from) -{ - if (from.pSelection == NULL || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight) return false; - if (pSelection==NULL) pSelection = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - if (pSelection==NULL) return false; - memcpy(pSelection,from.pSelection,head.biWidth * head.biHeight); - memcpy(&info.rSelectionBox,&from.info.rSelectionBox,sizeof(RECT)); - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Adds a polygonal region to the existing selection. points points to an array of POINT structures. - * Each structure specifies the x-coordinate and y-coordinate of one vertex of the polygon. - * npoints specifies the number of POINT structures in the array pointed to by points. - */ -bool CxImage::SelectionAddPolygon(POINT *points, long npoints, BYTE level) -{ - if (points==NULL || npoints<3) return false; - - if (pSelection==NULL) SelectionCreate(); - if (pSelection==NULL) return false; - - BYTE* plocal = (BYTE*)calloc(head.biWidth*head.biHeight, 1); - RECT localbox = {head.biWidth,0,0,head.biHeight}; - - long x,y,i=0; - POINT *current; - POINT *next = NULL; - POINT *start = NULL; - //trace contour - while (i < npoints){ - current = &points[i]; - if (current->x!=-1){ - if (i==0 || (i>0 && points[i-1].x==-1)) start = &points[i]; - - if ((i+1)==npoints || points[i+1].x==-1) - next = start; - else - next = &points[i+1]; - - float beta; - if (current->x != next->x){ - beta = (float)(next->y - current->y)/(float)(next->x - current->x); - if (current->x < next->x){ - for (x=current->x; x<=next->x; x++){ - y = (long)(current->y + (x - current->x) * beta); - if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; - } - } else { - for (x=current->x; x>=next->x; x--){ - y = (long)(current->y + (x - current->x) * beta); - if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; - } - } - } - if (current->y != next->y){ - beta = (float)(next->x - current->x)/(float)(next->y - current->y); - if (current->y < next->y){ - for (y=current->y; y<=next->y; y++){ - x = (long)(current->x + (y - current->y) * beta); - if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; - } - } else { - for (y=current->y; y>=next->y; y--){ - x = (long)(current->x + (y - current->y) * beta); - if (IsInside(x,y)) plocal[x + y * head.biWidth] = 255; - } - } - } - } - - RECT r2; - if (current->x < next->x) {r2.left=current->x; r2.right=next->x; } else {r2.left=next->x ; r2.right=current->x; } - if (current->y < next->y) {r2.bottom=current->y; r2.top=next->y; } else {r2.bottom=next->y ; r2.top=current->y; } - if (localbox.top < r2.top) localbox.top = MAX(0L,MIN(head.biHeight-1,r2.top+1)); - if (localbox.left > r2.left) localbox.left = MAX(0L,MIN(head.biWidth-1,r2.left-1)); - if (localbox.right < r2.right) localbox.right = MAX(0L,MIN(head.biWidth-1,r2.right+1)); - if (localbox.bottom > r2.bottom) localbox.bottom = MAX(0L,MIN(head.biHeight-1,r2.bottom-1)); - - i++; - } - - //fill the outer region - long npix=(localbox.right - localbox.left)*(localbox.top - localbox.bottom); - POINT* pix = (POINT*)calloc(npix,sizeof(POINT)); - BYTE back=0, mark=1; - long fx, fy, fxx, fyy, first, last; - long xmin = 0; - long xmax = 0; - long ymin = 0; - long ymax = 0; - - for (int side=0; side<4; side++){ - switch(side){ - case 0: - xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.bottom+1; - break; - case 1: - xmin=localbox.right; xmax=localbox.right+1; ymin=localbox.bottom; ymax=localbox.top+1; - break; - case 2: - xmin=localbox.left; xmax=localbox.right+1; ymin=localbox.top; ymax=localbox.top+1; - break; - case 3: - xmin=localbox.left; xmax=localbox.left+1; ymin=localbox.bottom; ymax=localbox.top+1; - break; - } - //fill from the border points - for(y=ymin;y=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) - { - plocal[fxx + fyy*head.biWidth] = mark; - if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ - pix[last].x = fx; - pix[last].y = fy - 1; - last++; - if (last == npix) last = 0; - } - if ((fyy + 1)=localbox.left && fxx<=localbox.right && fyy>=localbox.bottom && fyy<=localbox.top ) - { - plocal[fxx + (y + fy)*head.biWidth] = mark; - if (fyy > 0 && plocal[fxx + (fyy - 1)*head.biWidth] == back){ - pix[last].x = fx; - pix[last].y = fy - 1; - last++; - if (last == npix) last = 0; - } - if ((fyy + 1) localbox.left) info.rSelectionBox.left = MIN(head.biWidth,localbox.left); - if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = MIN(head.biWidth,localbox.right + 1); - if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = MIN(head.biHeight,localbox.bottom); - - cxfree(plocal);//free(plocal); - cxfree(pix);//free(pix); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Adds to the selection all the pixels matching the specified color. - */ -bool CxImage::SelectionAddColor(RGBQUAD c, BYTE level) -{ - if (pSelection==NULL) SelectionCreate(); - if (pSelection==NULL) return false; - - RECT localbox = {head.biWidth,0,0,head.biHeight}; - - for (long y = 0; y < head.biHeight; y++){ - for (long x = 0; x < head.biWidth; x++){ - RGBQUAD color = BlindGetPixelColor(x, y); - if (color.rgbRed == c.rgbRed && - color.rgbGreen == c.rgbGreen && - color.rgbBlue == c.rgbBlue) - { - pSelection[x + y * head.biWidth] = level; - - if (localbox.top < y) localbox.top = y; - if (localbox.left > x) localbox.left = x; - if (localbox.right < x) localbox.right = x; - if (localbox.bottom > y) localbox.bottom = y; - } - } - } - - if (info.rSelectionBox.top <= localbox.top) info.rSelectionBox.top = localbox.top + 1; - if (info.rSelectionBox.left > localbox.left) info.rSelectionBox.left = localbox.left; - if (info.rSelectionBox.right <= localbox.right) info.rSelectionBox.right = localbox.right + 1; - if (info.rSelectionBox.bottom > localbox.bottom) info.rSelectionBox.bottom = localbox.bottom; - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Adds a single pixel to the existing selection. - */ -bool CxImage::SelectionAddPixel(long x, long y, BYTE level) -{ - if (pSelection==NULL) SelectionCreate(); - if (pSelection==NULL) return false; - - if (IsInside(x,y)) { - pSelection[x + y * head.biWidth] = level; // set the correct mask bit - - if (info.rSelectionBox.top <= y) info.rSelectionBox.top = y+1; - if (info.rSelectionBox.left > x) info.rSelectionBox.left = x; - if (info.rSelectionBox.right <= x) info.rSelectionBox.right = x+1; - if (info.rSelectionBox.bottom > y) info.rSelectionBox.bottom = y; - - return true; - } - - return false; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Exports the selection channel in a 8bpp grayscale image. - */ -bool CxImage::SelectionSplit(CxImage *dest) -{ - if (!pSelection || !dest) return false; - - CxImage tmp(head.biWidth,head.biHeight,8); - if (!tmp.IsValid()){ - strcpy(info.szLastError,tmp.GetLastError()); - return false; - } - - for(long y=0; yTransfer(tmp); - - return true; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Creates the selection channel from a gray scale image. - * black = unselected - */ -bool CxImage::SelectionSet(CxImage &from) -{ - if (!from.IsGrayScale() || head.biWidth != from.head.biWidth || head.biHeight != from.head.biHeight){ - strcpy(info.szLastError,"CxImage::SelectionSet: wrong width or height, or image is not gray scale"); - return false; - } - - if (pSelection==NULL) pSelection = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - - BYTE* src = from.info.pImage; - BYTE* dst = pSelection; - if (src==NULL || dst==NULL){ - strcpy(info.szLastError,"CxImage::SelectionSet: null pointer"); - return false; - } - - for (long y=0; y=info.rSelectionBox.right; x--){ - if (pSelection[x+y*head.biWidth]){ - info.rSelectionBox.right = x+1; - continue; - } - } - } - - for (x=0; x=info.rSelectionBox.top; y--){ - if (pSelection[x+y*head.biWidth]){ - info.rSelectionBox.top = y+1; - continue; - } - } - } - -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Gets the Selection level for a single pixel - * "blind" version assumes that (x,y) is inside to the image. - */ -BYTE CxImage::BlindSelectionGet(const long x,const long y) -{ -#ifdef _DEBUG - if (!IsInside(x,y) || (pSelection==0)) - #if CXIMAGE_SUPPORT_EXCEPTION_HANDLING - throw 0; - #else - return 0; - #endif -#endif - return pSelection[x+y*head.biWidth]; -} -//////////////////////////////////////////////////////////////////////////////// -/** - * Returns pointer to selection data for pixel (x,y). - */ -BYTE* CxImage::SelectionGetPointer(const long x,const long y) -{ - if (pSelection && IsInside(x,y)) return pSelection+x+y*head.biWidth; - return 0; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::SelectionFlip() -{ - if (!pSelection) return false; - - BYTE *buff = (BYTE*)cxalloc(head.biWidth);//malloc(head.biWidth); - if (!buff) return false; - - BYTE *iSrc,*iDst; - iSrc = pSelection + (head.biHeight-1)*head.biWidth; - iDst = pSelection; - for (long i=0; i<(head.biHeight/2); ++i) - { - memcpy(buff, iSrc, head.biWidth); - memcpy(iSrc, iDst, head.biWidth); - memcpy(iDst, buff, head.biWidth); - iSrc-=head.biWidth; - iDst+=head.biWidth; - } - - cxfree(buff);//free(buff); - - long top = info.rSelectionBox.top; - info.rSelectionBox.top = head.biHeight - info.rSelectionBox.bottom; - info.rSelectionBox.bottom = head.biHeight - top; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -bool CxImage::SelectionMirror() -{ - if (!pSelection) return false; - BYTE* pSelection2 = (BYTE*)cxalloc(head.biWidth * head.biHeight);//malloc(head.biWidth * head.biHeight); - if (!pSelection2) return false; - - BYTE *iSrc,*iDst; - long wdt=head.biWidth-1; - iSrc=pSelection + wdt; - iDst=pSelection2; - for(long y=0; y < head.biHeight; y++){ - for(long x=0; x <= wdt; x++) - *(iDst+x)=*(iSrc-x); - iSrc+=head.biWidth; - iDst+=head.biWidth; - } - cxfree(pSelection);//free(pSelection); - pSelection=pSelection2; - - long left = info.rSelectionBox.left; - info.rSelectionBox.left = head.biWidth - info.rSelectionBox.right; - info.rSelectionBox.right = head.biWidth - left; - return true; -} -//////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_WINDOWS -/** - * Converts the selection in a HRGN object. - */ -bool CxImage::SelectionToHRGN(HRGN& region) -{ - if (pSelection && region){ - for(int y = 0; y < head.biHeight; y++){ - HRGN hTemp = NULL; - int iStart = -1; - int x = 0; - for(; x < head.biWidth; x++){ - if (pSelection[x + y * head.biWidth] != 0){ - if (iStart == -1) iStart = x; - continue; - }else{ - if (iStart >= 0){ - hTemp = CreateRectRgn(iStart, y, x, y + 1); - CombineRgn(region, hTemp, region, RGN_OR); - DeleteObject(hTemp); - iStart = -1; - } - } - } - if (iStart >= 0){ - hTemp = CreateRectRgn(iStart, y, x, y + 1); - CombineRgn(region, hTemp, region, RGN_OR); - DeleteObject(hTemp); - iStart = -1; - } - } - return true; - } - return false; -} -#endif //CXIMAGE_SUPPORT_WINDOWS -//////////////////////////////////////////////////////////////////////////////// -#endif //CXIMAGE_SUPPORT_SELECTION diff --git a/Externals/cximage/ximath.cpp b/Externals/cximage/ximath.cpp deleted file mode 100644 index 67070d8f8de..00000000000 --- a/Externals/cximage/ximath.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "ximage.h" -#include "ximath.h" -#include - -//this module should contain some classes for geometrical transformations -//usable with selections, etc... once it's done, that is. :) - -CxPoint2::CxPoint2() -{ - x=y=0.0f; -} - -CxPoint2::CxPoint2(float const x_, float const y_) -{ - x=x_; - y=y_; -} - -CxPoint2::CxPoint2(CxPoint2 const &p) -{ - x=p.x; - y=p.y; -} - -float CxPoint2::Distance(CxPoint2 const p2) -{ - return (float)sqrt((x-p2.x)*(x-p2.x)+(y-p2.y)*(y-p2.y)); -} - -float CxPoint2::Distance(float const x_, float const y_) -{ - return (float)sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_)); -} - -CxRect2::CxRect2() -{ -} - -CxRect2::CxRect2(float const x1_, float const y1_, float const x2_, float const y2_) -{ - botLeft.x=x1_; - botLeft.y=y1_; - topRight.x=x2_; - topRight.y=y2_; -} - -CxRect2::CxRect2(CxRect2 const &p) : botLeft(p.botLeft), topRight(p.topRight) -{ -} - -float CxRect2::Surface() const -/* - * Returns the surface of rectangle. - */ -{ - return (topRight.x-botLeft.x)*(topRight.y-botLeft.y); -} - -CxRect2 CxRect2::CrossSection(CxRect2 const &r2) const -/* - * Returns crossection with another rectangle. - */ -{ - CxRect2 cs; - cs.botLeft.x=MAX(botLeft.x, r2.botLeft.x); - cs.botLeft.y=MAX(botLeft.y, r2.botLeft.y); - cs.topRight.x=MIN(topRight.x, r2.topRight.x); - cs.topRight.y=MIN(topRight.y, r2.topRight.y); - if (cs.botLeft.x<=cs.topRight.x && cs.botLeft.y<=cs.topRight.y) { - return cs; - } else { - return CxRect2(0,0,0,0); - }//if -} - -CxPoint2 CxRect2::Center() const -/* - * Returns the center point of rectangle. - */ -{ - return CxPoint2((topRight.x+botLeft.x)/2.0f, (topRight.y+botLeft.y)/2.0f); -} - -float CxRect2::Width() const -//returns rectangle width -{ - return topRight.x-botLeft.x; -} - -float CxRect2::Height() const -//returns rectangle height -{ - return topRight.y-botLeft.y; -} - diff --git a/Externals/cximage/ximath.h b/Externals/cximage/ximath.h deleted file mode 100644 index 10b98984e4f..00000000000 --- a/Externals/cximage/ximath.h +++ /dev/null @@ -1,39 +0,0 @@ -#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 diff --git a/Externals/cximage/xiofile.cpp b/Externals/cximage/xiofile.cpp deleted file mode 100644 index 78bfc820a2b..00000000000 --- a/Externals/cximage/xiofile.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include "xiofile.h" - -#if defined(WIN32) || defined(_WIN32_WCE) -#include -#else -#define _tfopen fopen -#endif - -bool CxIOFile::Open(LPCTSTR filename, LPCTSTR 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; -} - -#if !defined(WIN32) && !defined(_WIN32_WCE) -#undef _tfopen -#endif diff --git a/Externals/cximage/xiofile.h b/Externals/cximage/xiofile.h deleted file mode 100644 index 890d05204ce..00000000000 --- a/Externals/cximage/xiofile.h +++ /dev/null @@ -1,115 +0,0 @@ -#if !defined(__xiofile_h) -#define __xiofile_h - -#include "xfile.h" - - -class DLL_EXP CxIOFile : public CxFile - { -public: - CxIOFile(FILE* fp = NULL) - { - m_fp = fp; - m_bCloseFile = (bool)(fp==0); - } - - ~CxIOFile() - { - Close(); - } -////////////////////////////////////////////////////////// - bool Open(LPCTSTR filename, LPCTSTR mode); -////////////////////////////////////////////////////////// - virtual bool Close() - { - int 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(long offset, int origin) - { - if (!m_fp) return false; - return (bool)(fseek(m_fp, offset, origin) == 0); - } -////////////////////////////////////////////////////////// - virtual long Tell() - { - if (!m_fp) return 0; - return ftell(m_fp); - } -////////////////////////////////////////////////////////// - virtual long Size() - { - if (!m_fp) return -1; - long 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 long Error() - { - if (!m_fp) return -1; - return ferror(m_fp); - } -////////////////////////////////////////////////////////// - virtual bool PutC(unsigned char c) - { - if (!m_fp) return false; - return (bool)(fputc(c, m_fp) == c); - } -////////////////////////////////////////////////////////// - virtual long GetC() - { - if (!m_fp) return EOF; - return getc(m_fp); - } -////////////////////////////////////////////////////////// - virtual char * GetS(char *string, int n) - { - if (!m_fp) return NULL; - return fgets(string,n,m_fp); - } -////////////////////////////////////////////////////////// - virtual long 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 diff --git a/Externals/cximage/xmemfile.cpp b/Externals/cximage/xmemfile.cpp deleted file mode 100644 index e50b08e0dd7..00000000000 --- a/Externals/cximage/xmemfile.cpp +++ /dev/null @@ -1,202 +0,0 @@ -#include "xmemfile.h" - -////////////////////////////////////////////////////////// -CxMemFile::CxMemFile(BYTE* pBuffer, DWORD size) -{ - m_pBuffer = pBuffer; - m_Position = 0; - m_Size = m_Edge = size; - m_bFreeOnClose = (bool)(pBuffer==0); -} -////////////////////////////////////////////////////////// -CxMemFile::~CxMemFile() -{ - Close(); -} -////////////////////////////////////////////////////////// -bool CxMemFile::Close() -{ - if ( (m_pBuffer) && (m_bFreeOnClose) ){ - cxfree(m_pBuffer);//free(m_pBuffer); - m_pBuffer = NULL; - m_Size = 0; - } - return true; -} -////////////////////////////////////////////////////////// -bool CxMemFile::Open() -{ - if (m_pBuffer) return false; // Can't re-open without closing first - - m_Position = m_Size = m_Edge = 0; - m_pBuffer=(BYTE*)cxalloc(1);//malloc(1); - m_bFreeOnClose = true; - - return (m_pBuffer!=0); -} -////////////////////////////////////////////////////////// -BYTE* CxMemFile::GetBuffer(bool bDetachBuffer) -{ - //can only detach, avoid inadvertantly attaching to - // memory that may not be ours [Jason De Arte] - if( bDetachBuffer ) - m_bFreeOnClose = false; - return m_pBuffer; -} -////////////////////////////////////////////////////////// -size_t CxMemFile::Read(void *buffer, size_t size, size_t count) -{ - if (buffer==NULL) return 0; - - if (m_pBuffer==NULL) return 0; - if (m_Position >= (long)m_Size) return 0; - - long nCount = (long)(count*size); - if (nCount == 0) return 0; - - long nRead; - if (m_Position + nCount > (long)m_Size) - nRead = (m_Size - m_Position); - else - nRead = nCount; - - memcpy(buffer, m_pBuffer + m_Position, nRead); - m_Position += nRead; - - return (size_t)(nRead/size); -} -////////////////////////////////////////////////////////// -size_t CxMemFile::Write(const void *buffer, size_t size, size_t count) -{ - if (m_pBuffer==NULL) return 0; - if (buffer==NULL) return 0; - - long nCount = (long)(count*size); - if (nCount == 0) return 0; - - if (m_Position + nCount > m_Edge){ - if (!Alloc(m_Position + nCount)){ - return false; - } - } - - memcpy(m_pBuffer + m_Position, buffer, nCount); - - m_Position += nCount; - - if (m_Position > (long)m_Size) m_Size = m_Position; - - return count; -} -////////////////////////////////////////////////////////// -bool CxMemFile::Seek(long offset, int origin) -{ - if (m_pBuffer==NULL) return false; - long lNewPos = m_Position; - - if (origin == SEEK_SET) lNewPos = offset; - else if (origin == SEEK_CUR) lNewPos += offset; - else if (origin == SEEK_END) lNewPos = m_Size + offset; - else return false; - - if (lNewPos < 0) lNewPos = 0; - - m_Position = lNewPos; - return true; -} -////////////////////////////////////////////////////////// -long CxMemFile::Tell() -{ - if (m_pBuffer==NULL) return -1; - return m_Position; -} -////////////////////////////////////////////////////////// -long CxMemFile::Size() -{ - if (m_pBuffer==NULL) return -1; - return m_Size; -} -////////////////////////////////////////////////////////// -bool CxMemFile::Flush() -{ - if (m_pBuffer==NULL) return false; - return true; -} -////////////////////////////////////////////////////////// -bool CxMemFile::Eof() -{ - if (m_pBuffer==NULL) return true; - return (m_Position >= (long)m_Size); -} -////////////////////////////////////////////////////////// -long CxMemFile::Error() -{ - if (m_pBuffer==NULL) return -1; - return (m_Position > (long)m_Size); -} -////////////////////////////////////////////////////////// -bool CxMemFile::PutC(unsigned char c) -{ - if (m_pBuffer==NULL) return false; - - if (m_Position >= m_Edge){ - if (!Alloc(m_Position + 1)){ - return false; - } - } - - m_pBuffer[m_Position++] = c; - - if (m_Position > (long)m_Size) m_Size = m_Position; - - return true; -} -////////////////////////////////////////////////////////// -long CxMemFile::GetC() -{ - if (Eof()) return EOF; - return *(BYTE*)((BYTE*)m_pBuffer + m_Position++); -} -////////////////////////////////////////////////////////// -char * CxMemFile::GetS(char *string, int n) -{ - n--; - long c,i=0; - while (i (DWORD)m_Edge) - { - // find new buffer size - DWORD dwNewBufferSize = (DWORD)(((dwNewLen>>16)+1)<<16); - - // allocate new buffer - if (m_pBuffer == NULL) m_pBuffer = (BYTE*)cxalloc(dwNewBufferSize);//malloc(dwNewBufferSize); - else m_pBuffer = (BYTE*)cxrealloc(m_pBuffer, dwNewBufferSize);//realloc(m_pBuffer, dwNewBufferSize); - // I own this buffer now (caller knows nothing about it) - m_bFreeOnClose = true; - - m_Edge = dwNewBufferSize; - } - return (m_pBuffer!=0); -} -////////////////////////////////////////////////////////// -void CxMemFile::Free() -{ - Close(); -} -////////////////////////////////////////////////////////// diff --git a/Externals/cximage/xmemfile.h b/Externals/cximage/xmemfile.h deleted file mode 100644 index f87e4f9b110..00000000000 --- a/Externals/cximage/xmemfile.h +++ /dev/null @@ -1,41 +0,0 @@ -#if !defined(__xmemfile_h) -#define __xmemfile_h - -#include "xfile.h" - -////////////////////////////////////////////////////////// -class DLL_EXP CxMemFile : public CxFile -{ -public: - CxMemFile(BYTE* pBuffer = NULL, DWORD size = 0); - ~CxMemFile(); - - bool Open(); - BYTE* 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(long offset, int origin); - virtual long Tell(); - virtual long Size(); - virtual bool Flush(); - virtual bool Eof(); - virtual long Error(); - virtual bool PutC(unsigned char c); - virtual long GetC(); - virtual char * GetS(char *string, int n); - virtual long Scanf(const char *format, void* output); - -protected: - bool Alloc(DWORD nBytes); - void Free(); - - BYTE* m_pBuffer; - DWORD m_Size; - bool m_bFreeOnClose; - long m_Position; //current position - long m_Edge; //buffer size -}; - -#endif diff --git a/misc/windows/xrbinup.cmd b/misc/windows/xrbinup.cmd index 72735a0ef5a..232d03db15e 100644 --- a/misc/windows/xrbinup.cmd +++ b/misc/windows/xrbinup.cmd @@ -86,10 +86,6 @@ if %platform%==Win32 ( if %platform%==Win64 ( call :COPY_FILE amd_ags_x64.dll ) -rem CxImage is compiled as DLLs only in debug configuration -if %cfg%==Debug ( - call :COPY_FILE CxImage.dll -) call :COPY_FILE LuaJIT.dll call :COPY_FILE luabind.dll call :COPY_FILE ODE.dll diff --git a/src/engine.sln b/src/engine.sln index 9507ebc6c10..f669f1db4f1 100644 --- a/src/engine.sln +++ b/src/engine.sln @@ -47,8 +47,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrRender_R4", "Layers\xrRen EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp_configs_verifyer", "utils\mp_configs_verifyer\mp_configs_verifyer.vcxproj", "{1924EF23-A05E-40E5-93F2-6CCD64BE1F8B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CxImage", "..\Externals\cximage\cximage.vcxproj", "{880CD250-BA77-4DAF-A8D4-552F12DD3AE4}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "editors", "editors", "{CB0C814D-FB4E-453B-B7A0-716F4A1EACA4}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrWeatherEditor", "editors\xrWeatherEditor\xrWeatherEditor.vcxproj", "{492D3DFE-9068-4E7E-A008-7C2420A651C0}" @@ -676,38 +674,6 @@ Global {1924EF23-A05E-40E5-93F2-6CCD64BE1F8B}.Release|x64.Build.0 = Release|x64 {1924EF23-A05E-40E5-93F2-6CCD64BE1F8B}.Release|x86.ActiveCfg = Release|Win32 {1924EF23-A05E-40E5-93F2-6CCD64BE1F8B}.Release|x86.Build.0 = Release|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|ARM.ActiveCfg = Debug|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|ARM.Build.0 = Debug|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|ARM64.ActiveCfg = Debug|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|ARM64.Build.0 = Debug|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|x64.ActiveCfg = Debug|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|x64.Build.0 = Debug|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|x86.ActiveCfg = Debug|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Debug|x86.Build.0 = Debug|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|ARM.ActiveCfg = Mixed|ARM - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|ARM.Build.0 = Mixed|ARM - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|ARM64.ActiveCfg = Mixed|ARM64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|ARM64.Build.0 = Mixed|ARM64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|x64.ActiveCfg = Mixed|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|x64.Build.0 = Mixed|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|x86.ActiveCfg = Mixed|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Mixed|x86.Build.0 = Mixed|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|ARM.ActiveCfg = Release Master Gold|ARM - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|ARM.Build.0 = Release Master Gold|ARM - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|ARM64.ActiveCfg = Release Master Gold|ARM64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|ARM64.Build.0 = Release Master Gold|ARM64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|x64.ActiveCfg = Release Master Gold|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|x64.Build.0 = Release Master Gold|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|x86.ActiveCfg = Release Master Gold|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release Master Gold|x86.Build.0 = Release Master Gold|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|ARM.ActiveCfg = Release|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|ARM.Build.0 = Release|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|ARM64.ActiveCfg = Release|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|ARM64.Build.0 = Release|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|x64.ActiveCfg = Release|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|x64.Build.0 = Release|x64 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|x86.ActiveCfg = Release|Win32 - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4}.Release|x86.Build.0 = Release|Win32 {492D3DFE-9068-4E7E-A008-7C2420A651C0}.Debug|ARM.ActiveCfg = Debug|Win32 {492D3DFE-9068-4E7E-A008-7C2420A651C0}.Debug|ARM64.ActiveCfg = Debug|x64 {492D3DFE-9068-4E7E-A008-7C2420A651C0}.Debug|x64.ActiveCfg = Debug|x64 @@ -1518,7 +1484,6 @@ Global {EF76867B-6EB8-4DC0-A1D6-E964FAD6FC7B} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B} {3AD26FD3-4F52-4E22-A4CF-AD4C49E74C61} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B} {1924EF23-A05E-40E5-93F2-6CCD64BE1F8B} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B} - {880CD250-BA77-4DAF-A8D4-552F12DD3AE4} = {2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348} {492D3DFE-9068-4E7E-A008-7C2420A651C0} = {CB0C814D-FB4E-453B-B7A0-716F4A1EACA4} {CCD4AFAE-AA10-42C6-A452-FDEE497CCDF1} = {2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348} {67FF193E-2C20-402A-9026-9F5F6327503C} = {2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348} diff --git a/src/xrGame/CMakeLists.txt b/src/xrGame/CMakeLists.txt index 6d7ca9b4ae0..02b4ec50002 100644 --- a/src/xrGame/CMakeLists.txt +++ b/src/xrGame/CMakeLists.txt @@ -2600,7 +2600,6 @@ target_include_directories(xrGame "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/src/xrServerEntities" - "$<$:${CMAKE_SOURCE_DIR}/Externals/cximage>" "${CMAKE_SOURCE_DIR}/Externals/GameSpy/src" "${CMAKE_SOURCE_DIR}/Externals/ode/include" "${CMAKE_SOURCE_DIR}/Externals/OpenAutomate/inc" @@ -2619,7 +2618,6 @@ target_link_libraries(xrGame xrUICore xrSound xrScriptEngine - $<$:cximage> xrGameSpy xrCDB xrPhysics diff --git a/src/xrGame/xrGame.vcxproj b/src/xrGame/xrGame.vcxproj index 7ed3020f2df..54ee5a81250 100644 --- a/src/xrGame/xrGame.vcxproj +++ b/src/xrGame/xrGame.vcxproj @@ -24,7 +24,7 @@ - $(SolutionDir)xrServerEntities;$(xrExternals)ode/include;$(xrExternals)GameSpy\src;$(xrExternals)OpenAutomate\inc;$(xrExternals)CxImage;%(AdditionalIncludeDirectories) + $(SolutionDir)xrServerEntities;$(xrExternals)ode/include;$(xrExternals)GameSpy\src;$(xrExternals)OpenAutomate\inc;%(AdditionalIncludeDirectories) _USRDLL;XRGAME_EXPORTS;%(PreprocessorDefinitions) 4237;4250;%(DisableSpecificWarnings) @@ -3487,9 +3487,6 @@ {435bac9a-b225-457d-ab40-c9bd0cc8838c} - - {880cd250-ba77-4daf-a8d4-552f12dd3ae4} - {5cb057d8-4464-40a6-af10-c26b826d1d90}