From: <bi...@us...> - 2008-02-17 21:24:17
|
Revision: 9577 http://amsn.svn.sourceforge.net/amsn/?rev=9577&view=rev Author: billiob Date: 2008-02-17 13:24:06 -0800 (Sun, 17 Feb 2008) Log Message: ----------- Use CxImage 6.00 Modified Paths: -------------- trunk/amsn/utils/TkCximage/src/CxImage/Rules.mk trunk/amsn/utils/TkCximage/src/CxImage/cximage.dsp trunk/amsn/utils/TkCximage/src/CxImage/license.txt trunk/amsn/utils/TkCximage/src/CxImage/xfile.h trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.h trunk/amsn/utils/TkCximage/src/CxImage/ximacfg.h trunk/amsn/utils/TkCximage/src/CxImage/ximadef.h trunk/amsn/utils/TkCximage/src/CxImage/ximadsp.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximaenc.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximaexif.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximage.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximage.h trunk/amsn/utils/TkCximage/src/CxImage/ximagif.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximagif.h trunk/amsn/utils/TkCximage/src/CxImage/ximahist.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximainfo.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximaint.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximaiter.h trunk/amsn/utils/TkCximage/src/CxImage/ximajpg.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximajpg.h trunk/amsn/utils/TkCximage/src/CxImage/ximalpha.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximalyr.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximapal.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximapng.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximapng.h trunk/amsn/utils/TkCximage/src/CxImage/ximasel.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximatga.cpp trunk/amsn/utils/TkCximage/src/CxImage/ximatga.h trunk/amsn/utils/TkCximage/src/CxImage/ximatran.cpp trunk/amsn/utils/TkCximage/src/CxImage/xiofile.h trunk/amsn/utils/TkCximage/src/CxImage/xmemfile.cpp trunk/amsn/utils/TkCximage/src/CxImage/xmemfile.h trunk/amsn/utils/TkCximage/src/PhotoFormat.cpp trunk/amsn/utils/TkCximage/src/procs.cpp Modified: trunk/amsn/utils/TkCximage/src/CxImage/Rules.mk =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/Rules.mk 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/Rules.mk 2008-02-17 21:24:06 UTC (rev 9577) @@ -2,12 +2,12 @@ $(tkcximage_dir)/src/CxImage/ximagif.cpp.o $(tkcximage_dir)/src/CxImage/ximainfo.cpp.o \ $(tkcximage_dir)/src/CxImage/ximajpg.cpp.o $(tkcximage_dir)/src/CxImage/ximalyr.cpp.o \ $(tkcximage_dir)/src/CxImage/ximapng.cpp.o $(tkcximage_dir)/src/CxImage/ximatga.cpp.o \ - $(tkcximage_dir)/src/CxImage/ximatran.cpp.o $(tkcximage_dir)/src/CxImage/ximabmp.cpp.o \ - $(tkcximage_dir)/src/CxImage/ximaenc.cpp.o $(tkcximage_dir)/src/CxImage/ximage.cpp.o \ - $(tkcximage_dir)/src/CxImage/ximahist.cpp.o $(tkcximage_dir)/src/CxImage/ximaint.cpp.o \ + $(tkcximage_dir)/src/CxImage/ximatran.cpp.o $(tkcximage_dir)/src/CxImage/ximabmp.cpp.o \ + $(tkcximage_dir)/src/CxImage/ximaenc.cpp.o $(tkcximage_dir)/src/CxImage/ximage.cpp.o \ + $(tkcximage_dir)/src/CxImage/ximahist.cpp.o $(tkcximage_dir)/src/CxImage/ximaint.cpp.o \ $(tkcximage_dir)/src/CxImage/ximalpha.cpp.o $(tkcximage_dir)/src/CxImage/ximapal.cpp.o \ $(tkcximage_dir)/src/CxImage/ximasel.cpp.o $(tkcximage_dir)/src/CxImage/ximath.cpp.o \ - $(tkcximage_dir)/src/CxImage/xmemfile.cpp.o + $(tkcximage_dir)/src/CxImage/xmemfile.cpp.o TARGETS-Cximage := $(tkcximage_dir)/src/CxImage/libCxImage.a Modified: trunk/amsn/utils/TkCximage/src/CxImage/cximage.dsp =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/cximage.dsp 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/cximage.dsp 2008-02-17 21:24:06 UTC (rev 9577) @@ -4,7 +4,7 @@ # TARGTYPE "Win32 (x86) Static Library" 0x0104 -CFG=CxImage - Win32 Debug +CFG=CxImage - Win32 Unicode Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE @@ -13,12 +13,14 @@ !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE -!MESSAGE NMAKE /f "cximage.mak" CFG="CxImage - Win32 Debug" +!MESSAGE NMAKE /f "cximage.mak" CFG="CxImage - Win32 Unicode Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE +!MESSAGE "CxImage - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE "CxImage - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "CxImage - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE "CxImage - Win32 Unicode Debug" (based on "Win32 (x86) Static Library") +!MESSAGE "CxImage - Win32 Unicode Release" (based on "Win32 (x86) Static Library") !MESSAGE # Begin Project @@ -28,9 +30,33 @@ CPP=cl.exe RSC=rc.exe -!IF "$(CFG)" == "CxImage - Win32 Release" +!IF "$(CFG)" == "CxImage - Win32 Debug" # PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 2 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "WIN32" /D "_DEBUG" /D "_LIB" /D "JAS_WIN_MSVC_BUILD" /D "_CRT_SECURE_NO_DEPRECATE" /FD /GZ /c +# SUBTRACT CPP /Fr /YX +# ADD BASE RSC /l 0x410 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + +!ELSEIF "$(CFG)" == "CxImage - Win32 Release" + +# PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" @@ -41,10 +67,10 @@ # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\jpeg" /I "..\png" /I "..\zlib" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "_AFXDLL" /D "JAS_WIN_MSVC_BUILD" /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "WIN32" /D "NDEBUG" /D "_LIB" /D "JAS_WIN_MSVC_BUILD" /D "_CRT_SECURE_NO_DEPRECATE" /FD /c # SUBTRACT CPP /YX # ADD BASE RSC /l 0x410 /d "NDEBUG" -# ADD RSC /l 0x410 /d "NDEBUG" /d "_AFXDLL" +# ADD RSC /l 0x809 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -52,23 +78,24 @@ # ADD BASE LIB32 /nologo # ADD LIB32 /nologo -!ELSEIF "$(CFG)" == "CxImage - Win32 Debug" +!ELSEIF "$(CFG)" == "CxImage - Win32 Unicode Debug" -# PROP BASE Use_MFC 0 +# PROP BASE Use_MFC 2 # PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Output_Dir "CxImage___Win32_Unicode_Debug" +# PROP BASE Intermediate_Dir "CxImage___Win32_Unicode_Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 2 # PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" +# PROP Output_Dir "Unicode_Debug" +# PROP Intermediate_Dir "Unicode_Debug" # PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "_AFXDLL" /D "JAS_WIN_MSVC_BUILD" /FD /GZ /c +# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "_AFXDLL" /D "JAS_WIN_MSVC_BUILD" /FD /GZ /c +# SUBTRACT BASE CPP /Fr /YX +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "_LIB" /D "JAS_WIN_MSVC_BUILD" /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NON_CONFORMING_SWPRINTFS" /FD /GZ /c # SUBTRACT CPP /Fr /YX -# ADD BASE RSC /l 0x410 /d "_DEBUG" -# ADD RSC /l 0x410 /d "_DEBUG" /d "_AFXDLL" +# ADD BASE RSC /l 0x410 /d "_DEBUG" /d "_AFXDLL" +# ADD RSC /l 0x809 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo @@ -76,17 +103,48 @@ # ADD BASE LIB32 /nologo # ADD LIB32 /nologo +!ELSEIF "$(CFG)" == "CxImage - Win32 Unicode Release" + +# PROP BASE Use_MFC 2 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "CxImage___Win32_Unicode_Release" +# PROP BASE Intermediate_Dir "CxImage___Win32_Unicode_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 2 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Unicode_Release" +# PROP Intermediate_Dir "Unicode_Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "_AFXDLL" /D "JAS_WIN_MSVC_BUILD" /FD /c +# SUBTRACT BASE CPP /YX +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\jpeg" /I "..\png" /I "..\zlib" /I "..\mng" /I "..\tiff" /I "..\j2k" /I "..\jasper\include" /D "_LIB" /D "JAS_WIN_MSVC_BUILD" /D "WIN32" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NON_CONFORMING_SWPRINTFS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x410 /d "NDEBUG" /d "_AFXDLL" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo + !ENDIF # Begin Target +# Name "CxImage - Win32 Debug" # Name "CxImage - Win32 Release" -# Name "CxImage - Win32 Debug" +# Name "CxImage - Win32 Unicode Debug" +# Name "CxImage - Win32 Unicode Release" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File +SOURCE=.\tif_xfile.cpp +# End Source File +# Begin Source File + SOURCE=.\ximabmp.cpp # End Source File # Begin Source File @@ -115,6 +173,10 @@ # End Source File # Begin Source File +SOURCE=.\ximaico.cpp +# End Source File +# Begin Source File + SOURCE=.\ximainfo.cpp # End Source File # Begin Source File @@ -123,6 +185,14 @@ # End Source File # Begin Source File +SOURCE=.\ximajas.cpp +# End Source File +# Begin Source File + +SOURCE=.\ximajbg.cpp +# End Source File +# Begin Source File + SOURCE=.\ximajpg.cpp # End Source File # Begin Source File @@ -135,18 +205,34 @@ # End Source File # Begin Source File +SOURCE=.\ximamng.cpp +# End Source File +# Begin Source File + SOURCE=.\ximapal.cpp # End Source File # Begin Source File +SOURCE=.\ximapcx.cpp +# End Source File +# Begin Source File + SOURCE=.\ximapng.cpp # End Source File # Begin Source File +SOURCE=.\ximaraw.cpp +# End Source File +# Begin Source File + SOURCE=.\ximasel.cpp # End Source File # Begin Source File +SOURCE=.\ximaska.cpp +# End Source File +# Begin Source File + SOURCE=.\ximatga.cpp # End Source File # Begin Source File @@ -155,10 +241,26 @@ # End Source File # Begin Source File +SOURCE=.\ximatif.cpp +# End Source File +# Begin Source File + SOURCE=.\ximatran.cpp # End Source File # Begin Source File +SOURCE=.\ximawbmp.cpp +# End Source File +# Begin Source File + +SOURCE=.\ximawmf.cpp +# End Source File +# Begin Source File + +SOURCE=.\ximawnd.cpp +# End Source File +# Begin Source File + SOURCE=.\xmemfile.cpp # End Source File # End Group @@ -199,10 +301,6 @@ # End Source File # Begin Source File -SOURCE=.\ximaj2k.h -# End Source File -# Begin Source File - SOURCE=.\ximajas.h # End Source File # Begin Source File @@ -227,6 +325,14 @@ # End Source File # Begin Source File +SOURCE=.\ximaraw.h +# End Source File +# Begin Source File + +SOURCE=.\ximaska.h +# End Source File +# Begin Source File + SOURCE=.\ximatga.h # End Source File # Begin Source File Modified: trunk/amsn/utils/TkCximage/src/CxImage/license.txt =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/license.txt 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/license.txt 2008-02-17 21:24:06 UTC (rev 9577) @@ -9,9 +9,9 @@ COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: -CxImage version 5.99c 17/Oct/2004 +CxImage version 6.0.0 02/Feb/2008 -CxImage : Copyright (C) 2001 - 2004, Davide Pizzolato +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) Modified: trunk/amsn/utils/TkCximage/src/CxImage/xfile.h =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/xfile.h 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/xfile.h 2008-02-17 21:24:06 UTC (rev 9577) @@ -9,6 +9,7 @@ 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 @@ -40,7 +41,7 @@ #if !defined(__xfile_h) #define __xfile_h -#ifdef WIN32 +#if defined (WIN32) || defined (_WIN32_WCE) #include <windows.h> #endif @@ -71,6 +72,8 @@ 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 Modified: trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.cpp =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.cpp 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.cpp 2008-02-17 21:24:06 UTC (rev 9577) @@ -2,7 +2,7 @@ * File: ximabmp.cpp * Purpose: Platform Independent BMP Image Class Loader and Writer * 07/Aug/2001 Davide Pizzolato - www.xdp.it - * CxImage version 5.99c 17/Oct/2004 + * CxImage version 6.0.0 02/Feb/2008 */ #include "ximabmp.h" @@ -26,12 +26,52 @@ hdr.bfReserved1 = hdr.bfReserved2 = 0; hdr.bfOffBits = 14 /*sizeof(BITMAPFILEHEADER)*/ + head.biSize + GetPaletteSize(); - //copy attributes - memcpy(pDib,&head,sizeof(BITMAPINFOHEADER)); - // Write the file header - hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1); - // Write the DIB header and the pixels - hFile->Write(pDib,GetSize(),1); + hdr.bfType = ntohs(hdr.bfType); + hdr.bfSize = ntohl(hdr.bfSize); + hdr.bfOffBits = ntohl(hdr.bfOffBits); + +#if CXIMAGE_SUPPORT_ALPHA + if (GetNumColors()==0 && AlphaIsValid()){ + + BITMAPINFOHEADER infohdr; + memcpy(&infohdr,&head,sizeof(BITMAPINFOHEADER)); + infohdr.biCompression = BI_RGB; + infohdr.biBitCount = 32; + DWORD dwEffWidth = ((((infohdr.biBitCount * infohdr.biWidth) + 31) / 32) * 4); + infohdr.biSizeImage = dwEffWidth * infohdr.biHeight; + + hdr.bfSize = infohdr.biSize + infohdr.biSizeImage + 14 /*sizeof(BITMAPFILEHEADER)*/; + + hdr.bfSize = ntohl(hdr.bfSize); + bihtoh(&infohdr); + + // Write the file header + hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1); + hFile->Write(&infohdr,sizeof(BITMAPINFOHEADER),1); + //and DIB+ALPHA interlaced + BYTE *srcalpha = AlphaGetPointer(); + for(long y = 0; y < infohdr.biHeight; ++y){ + BYTE *srcdib = GetBits(y); + for(long x = 0; x < infohdr.biWidth; ++x){ + hFile->Write(srcdib,3,1); + hFile->Write(srcalpha,1,1); + srcdib += 3; + ++srcalpha; + } + } + + } else +#endif //CXIMAGE_SUPPORT_ALPHA + { + // Write the file header + hFile->Write(&hdr,min(14,sizeof(BITMAPFILEHEADER)),1); + //copy attributes + memcpy(pDib,&head,sizeof(BITMAPINFOHEADER)); + bihtoh((BITMAPINFOHEADER*)pDib); + // Write the DIB header and the pixels + hFile->Write(pDib,GetSize(),1); + bihtoh((BITMAPINFOHEADER*)pDib); + } return true; } //////////////////////////////////////////////////////////////////////////////// @@ -39,36 +79,25 @@ //////////////////////////////////////////////////////////////////////////////// #if CXIMAGE_SUPPORT_DECODE //////////////////////////////////////////////////////////////////////////////// -bool CxImageBMP::CheckFormat(BYTE * buffer, DWORD size, basic_image_information *basic_info){ - BITMAPFILEHEADER *bf; - BITMAPINFOHEADER *bi; - - bf = (BITMAPFILEHEADER *) buffer; - - if (size < (sizeof(*bf)+sizeof(*bi))) return false; - if (bf->bfType != BFT_BITMAP) return false; - bi = (BITMAPINFOHEADER *) (buffer + sizeof(*bf)); - - create_basic_image_information(CXIMAGE_FORMAT_BMP,bi->biWidth,bi->biHeight, basic_info); - return true; -} - - bool CxImageBMP::Decode(CxFile * hFile) { if (hFile == NULL) return false; BITMAPFILEHEADER bf; DWORD off = hFile->Tell(); //<CSC> - try { - if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) throw "Not a BMP"; + cx_try { + if (hFile->Read(&bf,min(14,sizeof(bf)),1)==0) cx_throw("Not a BMP"); + + bf.bfSize = ntohl(bf.bfSize); + bf.bfOffBits = ntohl(bf.bfOffBits); + if (bf.bfType != BFT_BITMAP) { //do we have a RC HEADER? bf.bfOffBits = 0L; hFile->Seek(off,SEEK_SET); } BITMAPINFOHEADER bmpHeader; - if (!DibReadBitmapInfo(hFile,&bmpHeader)) throw "Error reading BMP info"; + if (!DibReadBitmapInfo(hFile,&bmpHeader)) cx_throw("Error reading BMP info"); DWORD dwCompression=bmpHeader.biCompression; DWORD dwBitCount=bmpHeader.biBitCount; //preserve for BI_BITFIELDS compression <Thomas Ernst> bool bIsOldBmp = bmpHeader.biSize == sizeof(BITMAPCOREHEADER); @@ -80,18 +109,17 @@ // Return output dimensions only head.biWidth = bmpHeader.biWidth; head.biHeight = bmpHeader.biHeight; - throw "output dimensions returned"; + info.dwType = CXIMAGE_FORMAT_BMP; + cx_throw("output dimensions returned"); } if (!Create(bmpHeader.biWidth,bmpHeader.biHeight,bmpHeader.biBitCount,CXIMAGE_FORMAT_BMP)) - throw "Can't allocate memory"; + cx_throw(""); - head.biXPelsPerMeter = bmpHeader.biXPelsPerMeter; - head.biYPelsPerMeter = bmpHeader.biYPelsPerMeter; - info.xDPI = (long) floor(bmpHeader.biXPelsPerMeter * 254.0 / 10000.0 + 0.5); - info.yDPI = (long) floor(bmpHeader.biYPelsPerMeter * 254.0 / 10000.0 + 0.5); + SetXDPI((long) floor(bmpHeader.biXPelsPerMeter * 254.0 / 10000.0 + 0.5)); + SetYDPI((long) floor(bmpHeader.biYPelsPerMeter * 254.0 / 10000.0 + 0.5)); - if (info.nEscape) throw "Cancelled"; // <vho> - cancel decoding + if (info.nEscape) cx_throw("Cancelled"); // <vho> - cancel decoding RGBQUAD *pRgb = GetPalette(); if (pRgb){ @@ -112,26 +140,56 @@ } } - if (info.nEscape) throw "Cancelled"; // <vho> - cancel decoding + if (info.nEscape) cx_throw("Cancelled"); // <vho> - cancel decoding switch (dwBitCount) { case 32 : + DWORD bfmask[3]; + if (dwCompression == BI_BITFIELDS) + { + hFile->Read(bfmask, 12, 1); + } else { + bfmask[0]=0x00FF0000; + bfmask[1]=0x0000FF00; + bfmask[2]=0x000000FF; + } if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); if (dwCompression == BI_BITFIELDS || dwCompression == BI_RGB){ long imagesize=4*head.biHeight*head.biWidth; BYTE* buff32=(BYTE*)malloc(imagesize); if (buff32){ hFile->Read(buff32, imagesize,1); // read in the pixels - Bitfield2RGB(buff32,0,0,0,32); + +#if CXIMAGE_SUPPORT_ALPHA + if (dwCompression == BI_RGB){ + AlphaCreate(); + if (AlphaIsValid()){ + bool bAlphaOk = false; + BYTE* p; + for (long y=0; y<head.biHeight; y++){ + p = buff32 + 3 + head.biWidth * 4 * y; + for (long x=0; x<head.biWidth; x++){ + if (*p) bAlphaOk = true; + AlphaSet(x,y,*p); + p+=4; + } + } + // fix if alpha pixels are all zero + if (!bAlphaOk) AlphaInvert(); + } + } +#endif //CXIMAGE_SUPPORT_ALPHA + + Bitfield2RGB(buff32,bfmask[0],bfmask[1],bfmask[2],32); free(buff32); - } else throw "can't allocate memory"; - } else throw "unknown compression"; + } else cx_throw("can't allocate memory"); + } else cx_throw("unknown compression"); break; case 24 : if (bf.bfOffBits != 0L) hFile->Seek(off + bf.bfOffBits,SEEK_SET); if (dwCompression == BI_RGB){ hFile->Read(info.pImage, head.biSizeImage,1); // read in the pixels - } else throw "unknown compression"; + } else cx_throw("unknown compression"); break; case 16 : { @@ -147,7 +205,7 @@ // read in the pixels hFile->Read(info.pImage, head.biHeight*((head.biWidth+1)/2)*4,1); // transform into RGB - Bitfield2RGB(info.pImage,(WORD)bfmask[0],(WORD)bfmask[1],(WORD)bfmask[2],16); + Bitfield2RGB(info.pImage,bfmask[0],bfmask[1],bfmask[2],16); break; } case 8 : @@ -167,8 +225,8 @@ BOOL low_nibble = FALSE; CImageIterator iter(this); - for (BOOL bContinue = TRUE; bContinue;) { - hFile->Read(&status_byte, sizeof(BYTE), 1); + for (BOOL bContinue = TRUE; bContinue && hFile->Read(&status_byte, sizeof(BYTE), 1);) { + switch (status_byte) { case RLE_COMMAND : hFile->Read(&status_byte, sizeof(BYTE), 1); @@ -197,21 +255,27 @@ hFile->Read(&second_byte, sizeof(BYTE), 1); BYTE *sline = iter.GetRow(scanline); for (int i = 0; i < status_byte; i++) { - if (low_nibble) { - if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ - *(sline + bits) |= (second_byte & 0x0F); + if ((BYTE*)(sline+bits) < (BYTE*)(info.pImage+head.biSizeImage)){ + if (low_nibble) { + if (i&1) + *(sline + bits) |= (second_byte & 0x0f); + else + *(sline + bits) |= (second_byte & 0xf0)>>4; + bits++; + } else { + if (i&1) + *(sline + bits) = (BYTE)(second_byte & 0x0f)<<4; + else + *(sline + bits) = (BYTE)(second_byte & 0xf0); } - if (i != status_byte - 1) - hFile->Read(&second_byte, sizeof(BYTE), 1); - bits++; - } else { - if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ - *(sline + bits) = (BYTE)(second_byte & 0xF0); - } } + + if ((i & 1) && (i != (status_byte - 1))) + hFile->Read(&second_byte, sizeof(BYTE), 1); + low_nibble = !low_nibble; } - if ((((status_byte+1) >> 1) & 1 )== 1) + if ((((status_byte+1) >> 1) & 1 ) == 1) hFile->Read(&second_byte, sizeof(BYTE), 1); break; }; @@ -221,16 +285,20 @@ BYTE *sline = iter.GetRow(scanline); hFile->Read(&second_byte, sizeof(BYTE), 1); for (unsigned i = 0; i < status_byte; i++) { - if (low_nibble) { - if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ - *(sline + bits) |= (second_byte & 0x0F); + if ((BYTE*)(sline+bits) < (BYTE*)(info.pImage+head.biSizeImage)){ + if (low_nibble) { + if (i&1) + *(sline + bits) |= (second_byte & 0x0f); + else + *(sline + bits) |= (second_byte & 0xf0)>>4; + bits++; + } else { + if (i&1) + *(sline + bits) = (BYTE)(second_byte & 0x0f)<<4; + else + *(sline + bits) = (BYTE)(second_byte & 0xf0); } - bits++; - } else { - if ((DWORD)(sline+bits) < (DWORD)(info.pImage+head.biSizeImage)){ - *(sline + bits) = (BYTE)(second_byte & 0xF0); - } - } + } low_nibble = !low_nibble; } } @@ -247,8 +315,7 @@ int bits = 0; CImageIterator iter(this); - for (BOOL bContinue = TRUE; bContinue; ) { - hFile->Read(&status_byte, sizeof(BYTE), 1); + for (BOOL bContinue = TRUE; bContinue && hFile->Read(&status_byte, sizeof(BYTE), 1);) { switch (status_byte) { case RLE_COMMAND : hFile->Read(&status_byte, sizeof(BYTE), 1); @@ -289,7 +356,6 @@ *(sline + bits) = second_byte; bits++; } else { - bContinue = FALSE; break; } } @@ -299,15 +365,15 @@ break; } default : - throw "compression type not supported"; + cx_throw("compression type not supported"); } } if (bTopDownDib) Flip(); //<Flanders> - } catch (const char *message) { - strncpy(info.szLastError,message,255); - if (info.nEscape==-1) return true; + } cx_catch { + if (strcmp(message,"")) strncpy(info.szLastError,message,255); + if (info.nEscape == -1 && info.dwType == CXIMAGE_FORMAT_BMP) return true; return false; } return true; @@ -325,7 +391,7 @@ if (fh->Read(pdib,sizeof(BITMAPINFOHEADER),1)==0) return false; - BITMAPCOREHEADER bc; + bihtoh(pdib); switch (pdib->biSize) // what type of bitmap info is this? { @@ -337,7 +403,8 @@ break; case sizeof(BITMAPCOREHEADER): - bc = *(BITMAPCOREHEADER*)pdib; + { + BITMAPCOREHEADER bc = *(BITMAPCOREHEADER*)pdib; pdib->biSize = bc.bcSize; pdib->biWidth = (DWORD)bc.bcWidth; pdib->biHeight = (DWORD)bc.bcHeight; @@ -351,15 +418,16 @@ pdib->biClrImportant = 0; fh->Seek((long)(sizeof(BITMAPCOREHEADER)-sizeof(BITMAPINFOHEADER)), SEEK_CUR); - + } break; default: //give a last chance if (pdib->biSize>(sizeof(BITMAPINFOHEADER))&& - (pdib->biSizeImage==(unsigned long)(pdib->biHeight*((((pdib->biBitCount*pdib->biWidth)+31)/32)*4)))&& - (pdib->biPlanes==1)&&(pdib->biCompression==BI_RGB)&&(pdib->biClrUsed==0)) + (pdib->biSizeImage>=(unsigned long)(pdib->biHeight*((((pdib->biBitCount*pdib->biWidth)+31)/32)*4)))&& + (pdib->biPlanes==1)&&(pdib->biClrUsed==0)) { - fh->Seek((long)(pdib->biSize - sizeof(BITMAPINFOHEADER)),SEEK_CUR); + if (pdib->biCompression==BI_RGB) + fh->Seek((long)(pdib->biSize - sizeof(BITMAPINFOHEADER)),SEEK_CUR); break; } return false; Modified: trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.h =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.h 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/ximabmp.h 2008-02-17 21:24:06 UTC (rev 9577) @@ -40,7 +40,6 @@ bool Decode(CxFile * hFile); bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } - static bool CheckFormat(BYTE * buffer, DWORD size, basic_image_information *basic_info); #if CXIMAGE_SUPPORT_ENCODE bool Encode(CxFile * hFile); Modified: trunk/amsn/utils/TkCximage/src/CxImage/ximacfg.h =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/ximacfg.h 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/ximacfg.h 2008-02-17 21:24:06 UTC (rev 9577) @@ -13,7 +13,6 @@ #define CXIMAGE_SUPPORT_DECODE 1 #define CXIMAGE_SUPPORT_ENCODE 1 //<vho><T.Peck> #define CXIMAGE_SUPPORT_WINDOWS 0 -#define CXIMAGE_SUPPORT_WINCE 0 //<T.Peck> ///////////////////////////////////////////////////////////////////////////// // CxImage supported formats @@ -21,15 +20,12 @@ #define CXIMAGE_SUPPORT_GIF 1 #define CXIMAGE_SUPPORT_JPG 1 #define CXIMAGE_SUPPORT_PNG 1 -#define CXIMAGE_SUPPORT_MNG 0 #define CXIMAGE_SUPPORT_ICO 0 #define CXIMAGE_SUPPORT_TIF 0 #define CXIMAGE_SUPPORT_TGA 1 #define CXIMAGE_SUPPORT_PCX 0 #define CXIMAGE_SUPPORT_WBMP 0 #define CXIMAGE_SUPPORT_WMF 0 -#define CXIMAGE_SUPPORT_J2K 0 // Beta, use JP2 -#define CXIMAGE_SUPPORT_JBG 0 // GPL'd see ../jbig/copying.txt & ../jbig/patents.htm #define CXIMAGE_SUPPORT_JP2 0 #define CXIMAGE_SUPPORT_JPC 0 @@ -37,13 +33,22 @@ #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 256000000 +#define CXIMAGE_MAX_MEMORY 268435456 +#define CXIMAGE_DEFAULT_DPI 96 + #define CXIMAGE_ERR_NOFILE "null file handler" #define CXIMAGE_ERR_NOIMAGE "null image!!!" +#define CXIMAGE_SUPPORT_EXCEPTION_HANDLING 1 + ///////////////////////////////////////////////////////////////////////////// //color to grey mapping <H. Muelner> <jurgene> //#define RGB2GRAY(r,g,b) (((b)*114 + (g)*587 + (r)*299)/1000) Modified: trunk/amsn/utils/TkCximage/src/CxImage/ximadef.h =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/ximadef.h 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/ximadef.h 2008-02-17 21:24:06 UTC (rev 9577) @@ -11,6 +11,18 @@ #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 @@ -31,14 +43,12 @@ #define CXIMAGE_SUPPORT_INTERPOLATION 1 #endif -#if CXIMAGE_SUPPORT_WINCE +#if defined (_WIN32_WCE) #undef CXIMAGE_SUPPORT_WMF #define CXIMAGE_SUPPORT_WMF 0 - #undef CXIMAGE_SUPPORT_WINDOWS - #define CXIMAGE_SUPPORT_WINDOWS 0 #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(_WIN32_WCE) #undef CXIMAGE_SUPPORT_WINDOWS #define CXIMAGE_SUPPORT_WINDOWS 0 #endif @@ -55,7 +65,7 @@ #endif -#ifdef WIN32 +#if defined(WIN32) || defined(_WIN32_WCE) #include <windows.h> #include <tchar.h> #endif @@ -63,7 +73,6 @@ #include <stdio.h> #include <math.h> - #ifdef __BORLANDC__ #ifndef _COMPLEX_DEFINED @@ -79,7 +88,7 @@ #endif -#ifndef WIN32 +#if !defined(WIN32) && !defined(_WIN32_WCE) #include <stdlib.h> #include <string.h> Modified: trunk/amsn/utils/TkCximage/src/CxImage/ximadsp.cpp =================================================================== --- trunk/amsn/utils/TkCximage/src/CxImage/ximadsp.cpp 2008-02-17 20:23:23 UTC (rev 9576) +++ trunk/amsn/utils/TkCximage/src/CxImage/ximadsp.cpp 2008-02-17 21:24:06 UTC (rev 9577) @@ -1,6 +1,6 @@ // xImaDsp.cpp : DSP functions /* 07/08/2001 v1.00 - Davide Pizzolato - www.xdp.it - * CxImage version 5.99c 17/Oct/2004 + * CxImage version 6.0.0 02/Feb/2008 */ #include "ximage.h" @@ -12,7 +12,7 @@ //////////////////////////////////////////////////////////////////////////////// /** * Converts the image to B&W. - * The Mean() function can be used for calculating the optimal threshold. + * The OptimalThreshold() function can be used for calculating the optimal threshold. * \param level: the lightness threshold. * \return true if everything is ok */ @@ -24,16 +24,19 @@ GrayScale(); CxImage tmp(head.biWidth,head.biHeight,1); - if (!tmp.IsValid()) return false; + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } for (long y=0;y<head.biHeight;y++){ info.nProgress = (long)(100*y/head.biHeight); if (info.nEscape) break; for (long x=0;x<head.biWidth;x++){ - if (GetPixelIndex(x,y)>level) - tmp.SetPixelIndex(x,y,1); + if (BlindGetPixelIndex(x,y)>level) + tmp.BlindSetPixelIndex(x,y,1); else - tmp.SetPixelIndex(x,y,0); + tmp.BlindSetPixelIndex(x,y,0); } } tmp.SetPaletteColor(0,0,0,0); @@ -43,6 +46,102 @@ } //////////////////////////////////////////////////////////////////////////////// /** + * Converts the image to B&W, using a threshold mask + * \param pThresholdMask: the lightness threshold mask. + * the pThresholdMask image must be grayscale with same with and height of the current image + * \return true if everything is ok + */ +bool CxImage::Threshold(CxImage* pThresholdMask) +{ + if (!pDib) return false; + if (head.biBitCount == 1) return true; + + if (!pThresholdMask) return false; + + if (!pThresholdMask->IsValid() || + !pThresholdMask->IsGrayScale() || + pThresholdMask->GetWidth() != GetWidth() || + pThresholdMask->GetHeight() != GetHeight()){ + strcpy(info.szLastError,"invalid ThresholdMask"); + return false; + } + + GrayScale(); + + CxImage tmp(head.biWidth,head.biHeight,1); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } + + for (long y=0;y<head.biHeight;y++){ + info.nProgress = (long)(100*y/head.biHeight); + if (info.nEscape) break; + for (long x=0;x<head.biWidth;x++){ + if (BlindGetPixelIndex(x,y)>pThresholdMask->BlindGetPixelIndex(x,y)) + tmp.BlindSetPixelIndex(x,y,1); + else + tmp.BlindSetPixelIndex(x,y,0); + } + } + tmp.SetPaletteColor(0,0,0,0); + tmp.SetPaletteColor(1,255,255,255); + Transfer(tmp); + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** + * Filters only the pixels with a lightness less (or more) than the threshold level, + * and preserves the colors for the unfiltered pixels. + * \param level = the lightness threshold. + * \param bDirection = false: filter dark pixels, true: filter light pixels + * \param nBkgndColor = filtered pixels are set to nBkgndColor color + * \param bSetAlpha = if true, sets also the alpha component for the filtered pixels, with nBkgndColor.rgbReserved + * \return true if everything is ok + * \author [DP], [wangsongtao] + */ +//////////////////////////////////////////////////////////////////////////////// +bool CxImage::Threshold2(BYTE level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha) +{ + if (!pDib) return false; + if (head.biBitCount == 1) return true; + + CxImage tmp(*this, true, false, false); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } + + tmp.GrayScale(); + + long xmin,xmax,ymin,ymax; + if (pSelection){ + xmin = info.rSelectionBox.left; xmax = info.rSelectionBox.right; + ymin = info.rSelectionBox.bottom; ymax = info.rSelectionBox.top; + } else { + xmin = ymin = 0; + xmax = head.biWidth; ymax=head.biHeight; + } + + for(long y=ymin; y<ymax; y++){ + info.nProgress = (long)(100*y/head.biHeight); + if (info.nEscape) break; + for(long x=xmin; x<xmax; x++){ +#if CXIMAGE_SUPPORT_SELECTION + if (BlindSelectionIsInside(x,y)) +#endif //CXIMAGE_SUPPORT_SELECTION + { + BYTE i = tmp.BlindGetPixelIndex(x,y); + if (!bDirection && i<level) BlindSetPixelColor(x,y,nBkgndColor,bSetAlpha); + if (bDirection && i>=level) BlindSetPixelColor(x,y,nBkgndColor,bSetAlpha); + } + } + } + + return true; +} +//////////////////////////////////////////////////////////////////////////////// +/** * Extract RGB channels from the image. Each channel is an 8 bit grayscale image. * \param r,g,b: pointers to CxImage objects, to store the splited channels * \return true if everything is ok @@ -59,10 +158,10 @@ RGBQUAD color; for(long y=0; y<head.biHeight; y++){ for(long x=0; x<head.biWidth; x++){ - color = GetPixelColor(x,y); - if (r) tmpr.SetPixelIndex(x,y,color.rgbRed); - if (g) tmpg.SetPixelIndex(x,y,color.rgbGreen); - if (b) tmpb.SetPixelIndex(x,y,color.rgbBlue); + color = BlindGetPixelColor(x,y); + if (r) tmpr.BlindSetPixelIndex(x,y,color.rgbRed); + if (g) tmpg.BlindSetPixelIndex(x,y,color.rgbGreen); + if (b) tmpb.BlindSetPixelIndex(x,y,color.rgbBlue); } } @@ -102,11 +201,11 @@ RGBQUAD color; for(long yy=0; yy<head.biHeight; yy++){ for(long xx=0; xx<head.biWidth; xx++){ - color = GetPixelColor(xx,yy); - if (c) tmpc.SetPixelIndex(xx,yy,(BYTE)(255-color.rgbRed)); - if (m) tmpm.SetPixelIndex(xx,yy,(BYTE)(255-color.rgbGreen)); - if (y) tmpy.SetPixelIndex(xx,yy,(BYTE)(255-color.rgbBlue)); - if (k) tmpk.SetPixelIndex(xx,yy,(BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue)); + color = BlindGetPixelColor(xx,yy); + if (c) tmpc.BlindSetPixelIndex(xx,yy,(BYTE)(255-color.rgbRed)); + if (m) tmpm.BlindSetPixelIndex(xx,yy,(BYTE)(255-color.rgbGreen)); + if (y) tmpy.BlindSetPixelIndex(xx,yy,(BYTE)(255-color.rgbBlue)); + if (k) tmpk.BlindSetPixelIndex(xx,yy,(BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue)); } } @@ -140,10 +239,10 @@ RGBQUAD color; for(long yy=0; yy<head.biHeight; yy++){ for(long x=0; x<head.biWidth; x++){ - color = RGBtoYUV(GetPixelColor(x,yy)); - if (y) tmpy.SetPixelIndex(x,yy,color.rgbRed); - if (u) tmpu.SetPixelIndex(x,yy,color.rgbGreen); - if (v) tmpv.SetPixelIndex(x,yy,color.rgbBlue); + color = RGBtoYUV(BlindGetPixelColor(x,yy)); + if (y) tmpy.BlindSetPixelIndex(x,yy,color.rgbRed); + if (u) tmpu.BlindSetPixelIndex(x,yy,color.rgbGreen); + if (v) tmpv.BlindSetPixelIndex(x,yy,color.rgbBlue); } } @@ -175,10 +274,10 @@ RGBQUAD color; for(long yy=0; yy<head.biHeight; yy++){ for(long x=0; x<head.biWidth; x++){ - color = RGBtoYIQ(GetPixelColor(x,yy)); - if (y) tmpy.SetPixelIndex(x,yy,color.rgbRed); - if (i) tmpi.SetPixelIndex(x,yy,color.rgbGreen); - if (q) tmpq.SetPixelIndex(x,yy,color.rgbBlue); + color = RGBtoYIQ(BlindGetPixelColor(x,yy)); + if (y) tmpy.BlindSetPixelIndex(x,yy,color.rgbRed); + if (i) tmpi.BlindSetPixelIndex(x,yy,color.rgbGreen); + if (q) tmpq.BlindSetPixelIndex(x,yy,color.rgbBlue); } } @@ -210,10 +309,10 @@ RGBQUAD color; for(long yy=0; yy<head.biHeight; yy++){ for(long xx=0; xx<head.biWidth; xx++){ - color = RGBtoXYZ(GetPixelColor(xx,yy)); - if (x) tmpx.SetPixelIndex(xx,yy,color.rgbRed); - if (y) tmpy.SetPixelIndex(xx,yy,color.rgbGreen); - if (z) tmpz.SetPixelIndex(xx,yy,color.rgbBlue); + color = RGBtoXYZ(BlindGetPixelColor(xx,yy)); + if (x) tmpx.BlindSetPixelIndex(xx,yy,color.rgbRed); + if (y) tmpy.BlindSetPixelIndex(xx,yy,color.rgbGreen); + if (z) tmpz.BlindSetPixelIndex(xx,yy,color.rgbBlue); } } @@ -245,10 +344,10 @@ RGBQUAD color; for(long y=0; y<head.biHeight; y++){ for(long x=0; x<head.biWidth; x++){ - color = RGBtoHSL(GetPixelColor(x,y)); - if (h) tmph.SetPixelIndex(x,y,color.rgbRed); - if (s) tmps.SetPixelIndex(x,y,color.rgbGreen); - if (l) tmpl.SetPixelIndex(x,y,color.rgbBlue); + color = RGBtoHSL(BlindGetPixelColor(x,y)); + if (h) tmph.BlindSetPixelIndex(x,y,color.rgbRed); + if (s) tmps.BlindSetPixelIndex(x,y,color.rgbGreen); + if (l) tmpl.BlindSetPixelIndex(x,y,color.rgbBlue); } } @@ -538,21 +637,23 @@ } for(long y=ymin; y<ymax; y++){ + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); + if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { if (bFullBlend){ - color = RGBtoHSL(GetPixelColor(x,y)); + color = RGBtoHSL(BlindGetPixelColor(x,y)); color.rgbRed=hue; color.rgbGreen=sat; - SetPixelColor(x,y,HSLtoRGB(color)); + BlindSetPixelColor(x,y,HSLtoRGB(color)); } else { - color = GetPixelColor(x,y); - hsl = RGBtoHSL(color); + color = BlindGetPixelColor(x,y); hsl.rgbRed=hue; hsl.rgbGreen=sat; + hsl.rgbBlue = (BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue); hsl = HSLtoRGB(hsl); //BlendPixelColor(x,y,hsl,blend); //color.rgbRed = (BYTE)(hsl.rgbRed * blend + color.rgbRed * (1.0f - blend)); @@ -561,7 +662,7 @@ color.rgbRed = (BYTE)((hsl.rgbRed * a0 + color.rgbRed * a1)>>8); color.rgbBlue = (BYTE)((hsl.rgbBlue * a0 + color.rgbBlue * a1)>>8); color.rgbGreen = (BYTE)((hsl.rgbGreen * a0 + color.rgbGreen * a1)>>8); - SetPixelColor(x,y,color); + BlindSetPixelColor(x,y,color); } } } @@ -575,9 +676,9 @@ SetPaletteColor((BYTE)j,HSLtoRGB(color)); } else { color = GetPaletteColor((BYTE)j); - hsl = RGBtoHSL(color); hsl.rgbRed=hue; hsl.rgbGreen=sat; + hsl.rgbBlue = (BYTE)RGB2GRAY(color.rgbRed,color.rgbGreen,color.rgbBlue); hsl = HSLtoRGB(hsl); color.rgbRed = (BYTE)(hsl.rgbRed * blend + color.rgbRed * (1.0f - blend)); color.rgbBlue = (BYTE)(hsl.rgbBlue * blend + color.rgbBlue * (1.0f - blend)); @@ -604,7 +705,7 @@ BYTE cTable[256]; //<nipper> for (int i=0;i<256;i++) { - cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness))); + cTable[i] = (BYTE)max(0,min(255,(int)((i-128)*c + brightness + 0.5f))); } return Lut(cTable); @@ -618,7 +719,10 @@ if (!pDib) return 0; CxImage tmp(*this,true); - if (!tmp.IsValid()) return false; + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } tmp.GrayScale(); float sum=0; @@ -637,7 +741,7 @@ iSrc += tmp.info.dwEffWidth*ymin; // necessary for selections <Admir Hodzic> for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/ymax); //<Anatoly Ivasyuk> + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); //<zhanghk><Anatoly Ivasyuk> for(long x=xmin; x<xmax; x++){ sum+=iSrc[x]; } @@ -666,10 +770,14 @@ long k2 = Ksize/2; long kmax= Ksize-k2; long r,g,b,i; + long ksumcur,ksumtot; RGBQUAD c; - CxImage tmp(*this,pSelection!=0,true,true); - if (!tmp.IsValid()) return false; + CxImage tmp(*this); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long xmin,xmax,ymin,ymax; if (pSelection){ @@ -680,6 +788,13 @@ xmax = head.biWidth; ymax=head.biHeight; } + ksumtot = 0; + for(long j=-k2;j<kmax;j++){ + for(long k=-k2;k<kmax;k++){ + ksumtot += kernel[(j+k2)+Ksize*(k+k2)]; + } + } + if ((head.biBitCount==8) && IsGrayScale()) { unsigned char* cPtr; @@ -688,36 +803,37 @@ int iY, iY2, iY1; cPtr = info.pImage; cPtr2 = (unsigned char *)tmp.info.pImage; - if (Kfactor==0) Kfactor = 1; for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; - for(long x=xmin; x<xmax; x++){ - iY1 = y*info.dwEffWidth+x; + iY1 = y*info.dwEffWidth+xmin; + for(long x=xmin; x<xmax; x++, iY1++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { - if (y-k2 > 0 && (y+kmax-1) < head.biHeight && x-k2 > 0 && (x+kmax-1) < head.biWidth) + b=ksumcur=0; + iCount = 0; + iY2 = ((y-k2)*info.dwEffWidth); + for(long j=-k2;j<kmax;j++, iY2+=info.dwEffWidth) { - b=0; - iCount = 0; - iY2 = ((y-k2)*info.dwEffWidth); - for(long j=-k2;j<kmax;j++) + if (0>(y+j) || (y+j)>=head.biHeight) continue; + iY = iY2+x; + for(long k=-k2;k<kmax;k++, iCount++) { - iY = iY2+x; - for(long k=-k2;k<kmax;k++) - { - i=kernel[iCount]; - b += cPtr[iY+k] * i; - iCount++; - } - iY2 += info.dwEffWidth; + if (0>(x+k) || (x+k)>=head.biWidth) continue; + i=kernel[iCount]; + b += cPtr[iY+k] * i; + ksumcur += i; } + } + if (Kfactor==0 || ksumcur==0){ + cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b + Koffset))); + } else if (ksumtot == ksumcur) { cPtr2[iY1] = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset))); + } else { + cPtr2[iY1] = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset))); } - else - cPtr2[iY1] = cPtr[iY1]; } } } @@ -725,33 +841,39 @@ else { for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { - r=b=g=0; + r=b=g=ksumcur=0; for(long j=-k2;j<kmax;j++){ for(long k=-k2;k<kmax;k++){ - c=GetPixelColor(x+j,y+k); - i=kernel[(j+k2)+Ksize*(k+k2)]; + if (!IsInside(x+j,y+k)) continue; + c = BlindGetPixelColor(x+j,y+k); + i = kernel[(j+k2)+Ksize*(k+k2)]; r += c.rgbRed * i; g += c.rgbGreen * i; b += c.rgbBlue * i; + ksumcur += i; } } - if (Kfactor==0){ + if (Kfactor==0 || ksumcur==0){ c.rgbRed = (BYTE)min(255, max(0,(int)(r + Koffset))); c.rgbGreen = (BYTE)min(255, max(0,(int)(g + Koffset))); c.rgbBlue = (BYTE)min(255, max(0,(int)(b + Koffset))); - } else { + } else if (ksumtot == ksumcur) { c.rgbRed = (BYTE)min(255, max(0,(int)(r/Kfactor + Koffset))); c.rgbGreen = (BYTE)min(255, max(0,(int)(g/Kfactor + Koffset))); c.rgbBlue = (BYTE)min(255, max(0,(int)(b/Kfactor + Koffset))); + } else { + c.rgbRed = (BYTE)min(255, max(0,(int)((r*ksumtot)/(ksumcur*Kfactor) + Koffset))); + c.rgbGreen = (BYTE)min(255, max(0,(int)((g*ksumtot)/(ksumcur*Kfactor) + Koffset))); + c.rgbBlue = (BYTE)min(255, max(0,(int)((b*ksumtot)/(ksumcur*Kfactor) + Koffset))); } - tmp.SetPixelColor(x,y,c); + tmp.BlindSetPixelColor(x,y,c); } } } @@ -774,8 +896,11 @@ BYTE r,g,b; RGBQUAD c; - CxImage tmp(*this,pSelection!=0,true,true); - if (!tmp.IsValid()) return false; + CxImage tmp(*this); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long xmin,xmax,ymin,ymax; if (pSelection){ @@ -787,17 +912,18 @@ } for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { r=b=g=255; for(long j=-k2;j<kmax;j++){ for(long k=-k2;k<kmax;k++){ - c=GetPixelColor(x+j,y+k); + if (!IsInside(x+j,y+k)) continue; + c = BlindGetPixelColor(x+j,y+k); if (c.rgbRed < r) r=c.rgbRed; if (c.rgbGreen < g) g=c.rgbGreen; if (c.rgbBlue < b) b=c.rgbBlue; @@ -806,7 +932,7 @@ c.rgbRed = r; c.rgbGreen = g; c.rgbBlue = b; - tmp.SetPixelColor(x,y,c); + tmp.BlindSetPixelColor(x,y,c); } } } @@ -828,8 +954,11 @@ BYTE r,g,b; RGBQUAD c; - CxImage tmp(*this,pSelection!=0,true,true); - if (!tmp.IsValid()) return false; + CxImage tmp(*this); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long xmin,xmax,ymin,ymax; if (pSelection){ @@ -841,17 +970,18 @@ } for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { r=b=g=0; for(long j=-k2;j<kmax;j++){ for(long k=-k2;k<kmax;k++){ - c=GetPixelColor(x+j,y+k); + if (!IsInside(x+j,y+k)) continue; + c = BlindGetPixelColor(x+j,y+k); if (c.rgbRed > r) r=c.rgbRed; if (c.rgbGreen > g) g=c.rgbGreen; if (c.rgbBlue > b) b=c.rgbBlue; @@ -860,7 +990,7 @@ c.rgbRed = r; c.rgbGreen = g; c.rgbBlue = b; - tmp.SetPixelColor(x,y,c); + tmp.BlindSetPixelColor(x,y,c); } } } @@ -884,8 +1014,11 @@ BYTE r,g,b,rr,gg,bb; RGBQUAD c; - CxImage tmp(*this,pSelection!=0,true,true); - if (!tmp.IsValid()) return false; + CxImage tmp(*this); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long xmin,xmax,ymin,ymax; if (pSelection){ @@ -897,18 +1030,19 @@ } for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { r=b=g=0; rr=bb=gg=255; for(long j=-k2;j<kmax;j++){ for(long k=-k2;k<kmax;k++){ - c=GetPixelColor(x+j,y+k); + if (!IsInside(x+j,y+k)) continue; + c = BlindGetPixelColor(x+j,y+k); if (c.rgbRed > r) r=c.rgbRed; if (c.rgbGreen > g) g=c.rgbGreen; if (c.rgbBlue > b) b=c.rgbBlue; @@ -918,10 +1052,10 @@ if (c.rgbBlue < bb) bb=c.rgbBlue; } } - c.rgbRed = 255-abs(r-rr); - c.rgbGreen = 255-abs(g-gg); - c.rgbBlue = 255-abs(b-bb); - tmp.SetPixelColor(x,y,c); + c.rgbRed = (BYTE)(255-abs(r-rr)); + c.rgbGreen = (BYTE)(255-abs(g-gg)); + c.rgbBlue = (BYTE)(255-abs(b-bb)); + tmp.BlindSetPixelColor(x,y,c); } } } @@ -951,7 +1085,7 @@ AlphaCreate(); } - RGBQUAD rgbBackgrnd = GetTransColor(); + RGBQUAD rgbBackgrnd1 = GetTransColor(); RGBQUAD rgb1, rgb2, rgbDest; for(long lY=0;lY<lHeight;lY++) @@ -969,6 +1103,12 @@ rgb2 = imgsrc2.GetPixelColor(lX+lXOffset,lY+lYOffset); switch(op) { + case OpAvg: + rgbDest.rgbBlue = (BYTE)((rgb1.rgbBlue+rgb2.rgbBlue)/2); + rgbDest.rgbGreen = (BYTE)((rgb1.rgbGreen+rgb2.rgbGreen)/2); + rgbDest.rgbRed = (BYTE)((rgb1.rgbRed+rgb2.rgbRed)/2); + if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved+rgb2.rgbReserved)/2); + break; case OpAdd: rgbDest.rgbBlue = (BYTE)max(0,min(255,rgb1.rgbBlue+rgb2.rgbBlue)); rgbDest.rgbGreen = (BYTE)max(0,min(255,rgb1.rgbGreen+rgb2.rgbGreen)); @@ -1001,18 +1141,18 @@ break; case OpMask: if(rgb2.rgbBlue==0 && rgb2.rgbGreen==0 && rgb2.rgbRed==0) - rgbDest = rgbBackgrnd; + rgbDest = rgbBackgrnd1; else rgbDest = rgb1; break; case OpSrcCopy: - if(memcmp(&rgb1,&rgbBackgrnd,sizeof(RGBQUAD))==0) + if(IsTransparent(lX,lY)) rgbDest = rgb2; else // copy straight over rgbDest = rgb1; break; case OpDstCopy: - if(memcmp(&rgb2,&rgbBackgrnd,sizeof(RGBQUAD))==0) + if(imgsrc2.IsTransparent(lX+lXOffset,lY+lYOffset)) rgbDest = rgb1; else // copy straight over rgbDest = rgb2; @@ -1025,7 +1165,7 @@ a=0; } else if (imgsrc2.AlphaIsValid()){ a=imgsrc2.AlphaGet(lX+lXOffset,lY+lYOffset); - a =(BYTE)((a*(1+imgsrc2.info.nAlphaMax))>>8); + a =(BYTE)((a*imgsrc2.info.nAlphaMax)/255); } else { a=255; } @@ -1036,22 +1176,22 @@ rgbDest = rgb2; } else { //blend a1 = (BYTE)~a; - rgbDest.rgbBlue = (BYTE)((rgb1.rgbBlue*a1+rgb2.rgbBlue*a)>>8); - rgbDest.rgbGreen = (BYTE)((rgb1.rgbGreen*a1+rgb2.rgbGreen*a)>>8); - rgbDest.rgbRed = (BYTE)((rgb1.rgbRed*a1+rgb2.rgbRed*a)>>8); + rgbDest.rgbBlue = (BYTE)((rgb1.rgbBlue*a1+rgb2.rgbBlue*a)/255); + rgbDest.rgbGreen = (BYTE)((rgb1.rgbGreen*a1+rgb2.rgbGreen*a)/255); + rgbDest.rgbRed = (BYTE)((rgb1.rgbRed*a1+rgb2.rgbRed*a)/255); } - if (bEditAlpha) rgbDest.rgbReserved = (BYTE)(((1+rgb1.rgbReserved)*a)>>8); + if (bEditAlpha) rgbDest.rgbReserved = (BYTE)((rgb1.rgbReserved*a)/255); } break; case OpSrcBlend: - if(memcmp(&rgb1,&rgbBackgrnd,sizeof(RGBQUAD))==0) + if(IsTransparent(lX,lY)) rgbDest = rgb2; else { - long lBDiff = abs(rgb1.rgbBlue - rgbBackgrnd.rgbBlue); - long lGDiff = abs(rgb1.rgbGreen - rgbBackgrnd.rgbGreen); - long lRDiff = abs(rgb1.rgbRed - rgbBackgrnd.rgbRed); + long lBDiff = abs(rgb1.rgbBlue - rgbBackgrnd1.rgbBlue); + long lGDiff = abs(rgb1.rgbGreen - rgbBackgrnd1.rgbGreen); + long lRDiff = abs(rgb1.rgbRed - rgbBackgrnd1.rgbRed); double lAverage = (lBDiff+lGDiff+lRDiff)/3; double lThresh = 16; @@ -1083,23 +1223,26 @@ // thanks to Kenneth Ballard void CxImage::MixFrom(CxImage & imagesrc2, long lXOffset, long lYOffset) { - RGBQUAD rgbBackgrnd = imagesrc2.GetTransColor(); - RGBQUAD rgb1; - long width = imagesrc2.GetWidth(); long height = imagesrc2.GetHeight(); int x, y; - for(x = 0; x < width; x++) - { - for(y = 0; y < height; y++) - { - rgb1 = imagesrc2.GetPixelColor(x, y); - if(memcmp(&rgb1, &rgbBackgrnd, sizeof(RGBQUAD)) != 0) - SetPixelColor(x + lXOffset, y + lYOffset, rgb1); - } - } + if (imagesrc2.IsTransparent()) { + for(x = 0; x < width; x++) { + for(y = 0; y < height; y++) { + if(!imagesrc2.IsTransparent(x,y)){ + SetPixelColor(x + lXOffset, y + lYOffset, imagesrc2.BlindGetPixelColor(x, y)); + } + } + } + } else { //no transparency so just set it <Matt> + for(x = 0; x < width; x++) { + for(y = 0; y < height; y++) { + SetPixelColor(x + lXOffset, y + lYOffset, imagesrc2.BlindGetPixelColor(x, y)); + } + } + } } //////////////////////////////////////////////////////////////////////////////// /** @@ -1125,14 +1268,14 @@ for(long y=ymin; y<ymax; y++){ for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { - color = GetPixelColor(x,y); + color = BlindGetPixelColor(x,y); color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + r))); color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + g))); color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + b))); - SetPixelColor(x,y,color); + BlindSetPixelColor(x,y,color); } } } @@ -1152,11 +1295,14 @@ * Adjusts the color balance of the image * \param gamma can be from 0.1 to 5. * \return true if everything is ok + * \sa GammaRGB */ bool CxImage::Gamma(float gamma) { if (!pDib) return false; + if (gamma <= 0.0f) return false; + double dinvgamma = 1/gamma; double dMax = pow(255.0, dinvgamma) / 255.0; @@ -1168,8 +1314,50 @@ return Lut(cTable); } //////////////////////////////////////////////////////////////////////////////// -#if CXIMAGE_SUPPORT_WINCE == 0 /** + * Adjusts the color balance indipendent for each color channel + * \param gammaR, gammaG, gammaB can be from 0.1 to 5. + * \return true if everything is ok + * \sa Gamma + */ +bool CxImage::GammaRGB(float gammaR, float gammaG, float gammaB) +{ + if (!pDib) return false; + + if (gammaR <= 0.0f) return false; + if (gammaG <= 0.0f) return false; + if (gammaB <= 0.0f) return false; + + double dinvgamma, dMax; + int i; + + dinvgamma = 1/gammaR; + dMax = pow(255.0, dinvgamma) / 255.0; + BYTE cTableR[256]; + for (i=0;i<256;i++) { + cTableR[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax))); + } + + dinvgamma = 1/gammaG; + dMax = pow(255.0, dinvgamma) / 255.0; + BYTE cTableG[256]; + for (i=0;i<256;i++) { + cTableG[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax))); + } + + dinvgamma = 1/gammaB; + dMax = pow(255.0, dinvgamma) / 255.0; + BYTE cTableB[256]; + for (i=0;i<256;i++) { + cTableB[i] = (BYTE)max(0,min(255,(int)( pow((double)i, dinvgamma) / dMax))); + } + + return Lut(cTableR, cTableG, cTableB); +} +//////////////////////////////////////////////////////////////////////////////// + +//#if !defined (_WIN32_WCE) +/** * Adjusts the intensity of each pixel to the median intensity of its surrounding pixels. * \param Ksize: size of the kernel. * \return true if everything is ok @@ -1184,8 +1372,11 @@ RGBQUAD* kernel = (RGBQUAD*)malloc(Ksize*Ksize*sizeof(RGBQUAD)); - CxImage tmp(*this,pSelection!=0,true,true); - if (!tmp.IsValid()) return false; + CxImage tmp(*this); + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long xmin,xmax,ymin,ymax; if (pSelection){ @@ -1197,16 +1388,17 @@ } for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/head.biHeight); + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); if (info.nEscape) break; for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { for(j=-k2, i=0;j<kmax;j++) - for(k=-k2;k<kmax;k++, i++) - kernel[i]=GetPixelColor(x+j,y+k); + for(k=-k2;k<kmax;k++) + if (IsInside(x+j,y+k)) + kernel[i++]=BlindGetPixelColor(x+j,y+k); qsort(kernel, i, sizeof(RGBQUAD), CompareColors); tmp.SetPixelColor(x,y,kernel[i/2]); @@ -1217,7 +1409,7 @@ Transfer(tmp); return true; } -#endif //CXIMAGE_SUPPORT_WINCE +//#endif //_WIN32_WCE //////////////////////////////////////////////////////////////////////////////// /** * Adds an uniform noise to the image @@ -1239,20 +1431,20 @@ } for(long y=ymin; y<ymax; y++){ - info.nProgress = (long)(100*y/ymax); //<Anatoly Ivasyuk> + info.nProgress = (long)(100*(y-ymin)/(ymax-ymin)); //<zhanghk><Anatoly Ivasyuk> for(long x=xmin; x<xmax; x++){ #if CXIMAGE_SUPPORT_SELECTION - if (SelectionIsInside(x,y)) + if (BlindSelectionIsInside(x,y)) #endif //CXIMAGE_SUPPORT_SELECTION { - color = GetPixelColor(x,y); + color = BlindGetPixelColor(x,y); n=(long)((rand()/(float)RAND_MAX - 0.5)*level); color.rgbRed = (BYTE)max(0,min(255,(int)(color.rgbRed + n))); n=(long)((rand()/(float)RAND_MAX - 0.5)*level); color.rgbGreen = (BYTE)max(0,min(255,(int)(color.rgbGreen + n))); n=(long)((rand()/(float)RAND_MAX - 0.5)*level); color.rgbBlue = (BYTE)max(0,min(255,(int)(color.rgbBlue + n))); - SetPixelColor(x,y,color); + BlindSetPixelColor(x,y,color); } } } @@ -1611,19 +1803,19 @@ c.rgbBlue=b->GetPixelIndex(x,y); switch (colorspace){ case 1: - SetPixelColor(x,y,HSLtoRGB(c)); + BlindSetPixelColor(x,y,HSLtoRGB(c)); break; case 2: - SetPixelColor(x,y,YUVtoRGB(c)); + BlindSetPixelColor(x,y,YUVtoRGB(c)); break; case 3: - SetPixelColor(x,y,YIQtoRGB(c)); + BlindSetPixelColor(x,y,YIQtoRGB(c)); break; case 4: - SetPixelColor(x,y,XYZtoRGB(c)); + BlindSetPixelColor(x,y,XYZtoRGB(c)); break; default: - SetPixelColor(x,y,c); + BlindSetPixelColor(x,y,c); } #if CXIMAGE_SUPPORT_ALPHA if (a) AlphaSet(x,y,a->GetPixelIndex(x,y)); @@ -1697,17 +1889,42 @@ if (ch==NULL) return false; CxImage tmp(*ch); - if (!tmp.IsValid()) return false; + if (!tmp.IsValid()){ + strcpy(info.szLastError,tmp.GetLastError()); + return false; + } long w = ch->GetWidth()-1; long h = ch->GetHeight()-1; - double correction,ix,iy,ixx,ixy,iyy,den,num; + double correction,ix,iy,ixx,ixy,iyy; int x,y,xy0,xp1,xm1,yp1,ym1; + for(x=1; x<w; x++){ for(y=1; y<h; y++){ - xy0 = ch->GetPixelIndex(x,y); + xy0 = ch->BlindGetPixelIndex(x,y); + xm1 = ch->BlindGetPixelIndex(x-1,y); + xp1 = ch->BlindGetPixelIndex(x+1,y); + ym1 = ch->BlindGetPixelIndex(x,y-1); + yp1 = ch->BlindGetPixelIndex(x,y+1); + + ix= (xp1-xm1)/2.0; + iy= (yp1-ym1)/2.0; + ixx= xp1 - 2.0 * xy0 + xm1; + iyy= yp1 - 2.0 * xy0 + ym1; + ixy=(ch->BlindGetPixelIndex(x+1,y+1) + ch->BlindGetPixelIndex(x-1,y-1) - + ch->BlindGetPixelIndex(x-1,y+1) - ch->BlindGetPixelIndex(x+1,y-1))/4.0; + + correction = ((1.0+iy*iy)*ixx - ix*iy*ixy + (1.0+ix*ix)*iyy)/(1.0+ix*ix+iy*iy); + + tmp.BlindSetPixelIndex(x,y,(BYTE)min(255,max(0,(xy0 + radius * correction + 0.5)))); + } + } + + for (x=0;x<=w;x++){ + for(y=0; y<=h; y+=h){ + xy0 = ch->BlindGetPixelIndex(x,y); xm1 = ch->GetPixelIndex(x-1,y); xp1 = ch->GetPixelIndex(x+1,y); ym1 = ch->GetPixelIndex(x,y-1); @@ -1717,25 +1934,35 @@ iy= (yp1-ym1)/2.0; ixx= xp1 - 2.0 * xy0 + xm1; iyy= yp1 - 2.0 * xy0 + ym1; - ixy=(ch->GetPixelIndex(x+1,y+1)+ch->GetPixelIndex(x-1,y-1)- - ch->GetPixelIndex(x-1,y+1)-ch->GetPixelIndex(x+1,y-1))/4.0; + ixy=(ch->GetPixelIndex(x+1,y+1) + ch-... [truncated message content] |