diff options
author | Denton Woods <devil.imagelib@gmail.com> | 2002-07-19 21:10:48 +0000 |
---|---|---|
committer | Denton Woods <devil.imagelib@gmail.com> | 2002-07-19 21:10:48 +0000 |
commit | 861cff3ef3ae634ccb2364e04ce582136c30d372 (patch) | |
tree | 150a071645c57aea74a71c453a7570eeb96a78e3 | |
parent | d4393d02b5b81403076265f4fa989567b9f46f88 (diff) | |
download | devil-861cff3ef3ae634ccb2364e04ce582136c30d372.tar.gz |
1.6.5 updates
55 files changed, 1129 insertions, 297 deletions
diff --git a/DevIL/CREDITS b/DevIL/CREDITS index 9c70c853..0ae87418 100644 --- a/DevIL/CREDITS +++ b/DevIL/CREDITS @@ -1,4 +1,4 @@ -Credits as of 06/04/2002 +Credits as of 06/24/2002 ------------------------ If I inadvertently omitted anyone's name from this list, please e-mail me at @@ -219,3 +219,5 @@ Alberto Barbati for noticing that the IL_NEU_QUANT_SAMPLE mode wasn't being used Ryan Butterfoss for his contributions to the DDS saving code. +Computer Graphics (C Version) book by Hearn and Baker for the arbitrary polygon filling code. + diff --git a/DevIL/ChangeLog b/DevIL/ChangeLog index 714b6d66..3247d522 100644 --- a/DevIL/ChangeLog +++ b/DevIL/ChangeLog @@ -1,3 +1,24 @@ +1.6.5 +----- + +- Created a stress test application. +- Found out that you have to set PNG_NO_STDIO when compiling libpng on Win32, + or else it will try to write via fprintf on an error, causing a crash. +- Fixed a similar problem with libjpeg, though you don't have to recompile. +- Fixed a problem converting palette'd images to higher than IL_UNSIGNED_BYTE. +- Changed 1-bit .bmp files to use 0 and 1 instead of 0 and 255 (using a palette). +- Fixed a divide by 0 in iluPixelize() if the pixel size was 0. +- Fixed some problems with iluEqualize(). +- Found and fixed three memory leaks using Paul Nettle's memory manager. +- Changed the filters to properly work on images with higher than 8-bit channels. +- Fixed some uninitialized values when using ilConvertImage on palette'd images. +- Fixed a problem saving .dds mipmaps. +- Fixed a bug saving .dds files with blocks of all the same colour. +- Added support for the IL_LUMINANCE_ALPHA format. +- Fixed a bug loading corrupt .gif files. +- Added region checking in ILU. + + 1.6.1 ----- diff --git a/DevIL/README.unix b/DevIL/README.unix index 70c6f1f8..e1b61edc 100644 --- a/DevIL/README.unix +++ b/DevIL/README.unix @@ -1,4 +1,4 @@ -Developer's Image Library version 1.6.1 Readme, Notes and Quick Use +Developer's Image Library version 1.6.5 Readme, Notes and Quick Use ------------------------------------------------------------------- <DZA[afk]> DevIL song: "la la la, a cross-platform image library utilizing a diff --git a/DevIL/README.win b/DevIL/README.win index 78bb9795..051b3265 100644 --- a/DevIL/README.win +++ b/DevIL/README.win @@ -1,4 +1,4 @@ -Developer's Image Library version 1.6.1 Readme, Notes and Quick Use +Developer's Image Library version 1.6.5 Readme, Notes and Quick Use ------------------------------------------------------------------- <DZA[afk]> DevIL song: "la la la, a cross-platform image library utilizing a diff --git a/DevIL/configure b/DevIL/configure index 9b7e18fe..e64dd49c 100755 --- a/DevIL/configure +++ b/DevIL/configure @@ -1139,7 +1139,7 @@ rm -f conftest.sh DEVIL_MAJOR=1 DEVIL_MINOR=6 -DEVIL_REVISION=1 +DEVIL_REVISION=5 DEVIL_VERSION=$DEVIL_MAJOR$DEVIL_MINOR$DEVIL_REVISION DEVIL_LTVERSION=1:$DEVIL_VERSION:0 diff --git a/DevIL/configure.in b/DevIL/configure.in index eab75421..1968a91e 100644 --- a/DevIL/configure.in +++ b/DevIL/configure.in @@ -21,7 +21,7 @@ dnl DEVIL_MAJOR=1 DEVIL_MINOR=6 -DEVIL_REVISION=1 +DEVIL_REVISION=5 DEVIL_VERSION=$DEVIL_MAJOR$DEVIL_MINOR$DEVIL_REVISION DEVIL_LTVERSION=1:$DEVIL_VERSION:0 AC_SUBST(DEVIL_LTVERSION) @@ -30,7 +30,7 @@ dnl dnl Basic conf dnl -AC_REVISION($Revision: 1.25 $) +AC_REVISION($Revision: 1.26 $) AC_CONFIG_AUX_DIR(libtools) AC_PREFIX_DEFAULT(/usr/local) AC_CANONICAL_HOST diff --git a/DevIL/examples/WindowsTest/WindowsTest.aps b/DevIL/examples/WindowsTest/WindowsTest.aps Binary files differindex 55add28e..cf659d5c 100644 --- a/DevIL/examples/WindowsTest/WindowsTest.aps +++ b/DevIL/examples/WindowsTest/WindowsTest.aps diff --git a/DevIL/examples/WindowsTest/WindowsTest.cpp b/DevIL/examples/WindowsTest/WindowsTest.cpp index 4e64e471..9769a726 100644 --- a/DevIL/examples/WindowsTest/WindowsTest.cpp +++ b/DevIL/examples/WindowsTest/WindowsTest.cpp @@ -24,8 +24,8 @@ //#include <sdl.h> #include "resource.h" -//#pragma comment(lib, "sdl.lib") -//#pragma comment(lib, "sdlmain.lib") +#pragma comment(lib, "sdl.lib") +#pragma comment(lib, "sdlmain.lib") #pragma comment(lib, "colorpicker.lib") @@ -311,7 +311,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ILubyte *AlphaChannel; ILenum Origin; - switch (message) { case WM_CREATE: @@ -700,6 +699,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ilConvertImage(IL_LUMINANCE, ilGetInteger(IL_IMAGE_TYPE)); break; + case ID_CONVERT_LUMINANCEALPHA: + ilConvertImage(IL_LUMINANCE_ALPHA, ilGetInteger(IL_IMAGE_TYPE)); + break; + case ID_EDIT_VIEWALPHA: Origin = ilGetInteger(IL_ORIGIN_MODE); AlphaChannel = ilGetAlpha(IL_UNSIGNED_BYTE); diff --git a/DevIL/examples/WindowsTest/WindowsTest.rc b/DevIL/examples/WindowsTest/WindowsTest.rc index 8e1465cb..53e02378 100644 --- a/DevIL/examples/WindowsTest/WindowsTest.rc +++ b/DevIL/examples/WindowsTest/WindowsTest.rc @@ -169,6 +169,7 @@ BEGIN BEGIN MENUITEM "&Colour Indexed", ID_CONVERT_PALETTE MENUITEM "&Luminance", ID_CONVERT_LUMINANCE + MENUITEM "L&uminance Alpha", ID_CONVERT_LUMINANCEALPHA MENUITEM "&Rgb", ID_CONVERT_RGB MENUITEM "Rgba", ID_CONVERT_RGBA MENUITEM "&Bgr", ID_CONVERT_BGR diff --git a/DevIL/examples/WindowsTest/resource.h b/DevIL/examples/WindowsTest/resource.h index 329d9588..65735560 100644 --- a/DevIL/examples/WindowsTest/resource.h +++ b/DevIL/examples/WindowsTest/resource.h @@ -93,6 +93,7 @@ #define ID_EFFECTSTOOLS_BACKGROUNDCOLOUR 32813 #define ID_EDIT_VIEWALPHA 32814 #define ID_FILE_PROPERTIES 32815 +#define ID_CONVERT_LUMINANCEALPHA 32816 #define IDC_STATIC -1 // Next default values for new objects @@ -100,7 +101,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 184 -#define _APS_NEXT_COMMAND_VALUE 32816 +#define _APS_NEXT_COMMAND_VALUE 32817 #define _APS_NEXT_CONTROL_VALUE 1033 #define _APS_NEXT_SYMED_VALUE 110 #endif diff --git a/DevIL/include/IL/devil_internal_exports.h b/DevIL/include/IL/devil_internal_exports.h index 36b23f60..1bade0d8 100644 --- a/DevIL/include/IL/devil_internal_exports.h +++ b/DevIL/include/IL/devil_internal_exports.h @@ -65,6 +65,8 @@ typedef struct ILimage // Memory functions ILAPI ILvoid* ILAPIENTRY ialloc(ILuint Size); ILAPI ILvoid ILAPIENTRY ifree(ILvoid *Ptr); +ILAPI ILvoid* ILAPIENTRY icalloc(ILuint Size, ILuint Num); + // Internal library functions in IL diff --git a/DevIL/include/IL/il.h b/DevIL/include/IL/il.h index bbbfdc31..189d2f5b 100644 --- a/DevIL/include/IL/il.h +++ b/DevIL/include/IL/il.h @@ -89,7 +89,7 @@ extern "C" { #ifdef _WIN32 //#define IL_USE_IJL // Whether we use the Intel Jpeg Library (else use libjpeg). #ifndef IL_STATIC_LIB - #ifdef _MSC_VER + #if defined(_MSC_VER) || defined(__BORLANDC__) #ifndef _IL_BUILD_LIBRARY #ifdef IL_DEBUG #pragma comment(lib, "devil-d.lib") @@ -97,7 +97,7 @@ extern "C" { #pragma comment(lib, "devil.lib") #endif//IL_DEBUG #endif//_IL_BUILD_LIBRARY - #endif//_MSC_VER + #endif//_MSC_VER || __BORLANDC__ #endif//IL_STATIC_LIB #endif//_WIN32 @@ -141,6 +141,7 @@ typedef void ILvoid; #define IL_BGR 0x80E0 #define IL_BGRA 0x80E1 #define IL_LUMINANCE 0x1909 +#define IL_LUMINANCE_ALPHA 0x190A #define IL_BYTE 0x1400 @@ -554,8 +555,8 @@ ILAPI ILboolean ILAPIENTRY ilLoadDataF(ILHANDLE File, ILuint Width, ILuint Heig ILAPI ILboolean ILAPIENTRY ilLoadDataL(ILvoid *Lump, ILuint Size, ILuint Width, ILuint Height, ILuint Depth, ILubyte Bpp); ILAPI ILboolean ILAPIENTRY ilSaveData(const ILstring FileName); -ILAPI ILboolean ILAPIENTRY ilLoadFromJpegStruct(ILvoid* JpegDecompressorPtr); -ILAPI ILboolean ILAPIENTRY ilSaveFromJpegStruct(ILvoid* JpegCompressorPtr); +ILAPI ILboolean ILAPIENTRY ilLoadFromJpegStruct(ILvoid* JpegDecompressorPtr); +ILAPI ILboolean ILAPIENTRY ilSaveFromJpegStruct(ILvoid* JpegCompressorPtr); // For all those weirdos that spell "colour" without the 'u'. #define ilClearColor ilClearColour diff --git a/DevIL/include/IL/ilu.h b/DevIL/include/IL/ilu.h index 1e98ea87..f9f6a3dc 100644 --- a/DevIL/include/IL/ilu.h +++ b/DevIL/include/IL/ilu.h @@ -25,7 +25,7 @@ extern "C" { #ifdef _WIN32 #ifndef IL_STATIC_LIB - #ifdef _MSC_VER + #if defined(_MSC_VER) || defined(__BORLANDC__) #ifndef _ILU_BUILD_LIBRARY #ifdef IL_DEBUG #pragma comment(lib, "ilu-d.lib") @@ -33,7 +33,7 @@ extern "C" { #pragma comment(lib, "ilu.lib") #endif//_DEBUG #endif//_ILU_BUILD_LIBRARY - #endif//_MSC_VER + #endif//_MSC_VER || __BORLANDC__ #endif//IL_STATIC_LIB #endif//_WIN32 @@ -112,6 +112,17 @@ typedef struct ILinfo } ILinfo; +typedef struct ILpointf +{ + ILfloat x, y; +} ILpointf; + +typedef struct ILpointi +{ + ILint x, y; +} ILpointi; + + // ImageLib Utility Functions ILAPI ILboolean ILAPIENTRY iluAlienify(ILvoid); ILAPI ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter); @@ -145,8 +156,8 @@ ILAPI ILboolean ILAPIENTRY iluMirror(ILvoid); ILAPI ILboolean ILAPIENTRY iluNegative(ILvoid); ILAPI ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance); ILAPI ILboolean ILAPIENTRY iluPixelize(ILuint PixSize); -//ILAPI ILvoid ILAPIENTRY iluRegionf(ILfloat ULx, ILfloat ULy, ILfloat BRx, ILfloat BRy); -//ILAPI ILvoid ILAPIENTRY iluRegioni(ILuint ULx, ILuint ULy, ILuint BRx, ILuint BRy); +ILAPI ILvoid ILAPIENTRY iluRegionfv(ILpointf *Points, ILuint n); +ILAPI ILvoid ILAPIENTRY iluRegioniv(ILpointi *Points, ILuint n); ILAPI ILboolean ILAPIENTRY iluReplaceColour(ILubyte Red, ILubyte Green, ILubyte Blue, ILfloat Tolerance); ILAPI ILboolean ILAPIENTRY iluRotate(ILfloat Angle); ILAPI ILboolean ILAPIENTRY iluRotate3D(ILfloat x, ILfloat y, ILfloat z, ILfloat Angle); diff --git a/DevIL/include/IL/ilut.h b/DevIL/include/IL/ilut.h index a2e2c0ab..3ac37032 100644 --- a/DevIL/include/IL/ilut.h +++ b/DevIL/include/IL/ilut.h @@ -26,7 +26,7 @@ extern "C" { #ifdef _WIN32 #ifndef IL_STATIC_LIB - #ifdef _MSC_VER + #if defined(_MSC_VER) || defined(__BORLANDC__) #ifndef _ILUT_BUILD_LIBRARY #ifdef IL_DEBUG #pragma comment(lib, "ilut-d.lib") @@ -34,7 +34,7 @@ extern "C" { #pragma comment(lib, "ilut.lib") #endif//_DEBUG #endif//_ILUT_BUILD_LIBRARY - #endif//_MSC_VER + #endif//_MSC_VER || __BORLANDC__ #endif//IL_STATIC_LIB #endif//_WIN32 diff --git a/DevIL/projects/djgpp/makefile b/DevIL/projects/djgpp/makefile index aea94fb4..a9d3fd1b 100644 --- a/DevIL/projects/djgpp/makefile +++ b/DevIL/projects/djgpp/makefile @@ -1,6 +1,6 @@ ################################### # Djgpp Makefile for DevIL # -# Last Modified: 05/27/2002 # +# Last Modified: 07/13/2002 # ################################### # Uncomment any of the following lines to define them @@ -83,7 +83,8 @@ ILUOBJ= $(ILUODIR)/ilu_error.o $(ILUODIR)/ilu_filter.o $(ILUODIR)/ilu_internal.o $(ILUODIR)/ilu_manip.o $(ILUODIR)/ilu_mipmap.o $(ILUODIR)/ilu_filter_rcg.o \ $(ILUODIR)/ilu_noise.o $(ILUODIR)/ilu_rotate.o $(ILUODIR)/ilu_scale.o \ $(ILUODIR)/ilu_states.o $(ILUODIR)/ilu_utilities.o $(ILUODIR)/ilu_main.o \ - $(ILUODIR)/ilu_alloc.o $(ILUODIR)/ilu_scale2d.o $(ILUODIR)/ilu_scale3d.o + $(ILUODIR)/ilu_alloc.o $(ILUODIR)/ilu_scale2d.o $(ILUODIR)/ilu_scale3d.o \ + $(ILUODIR)/ilu_region.o ILUTDIR= ./../../src-ILUT/src diff --git a/DevIL/projects/msvc/ImageLib.dsw b/DevIL/projects/msvc/ImageLib.dsw index f71d1fe6..5c135b98 100644 --- a/DevIL/projects/msvc/ImageLib.dsw +++ b/DevIL/projects/msvc/ImageLib.dsw @@ -3,24 +3,6 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ############################################################################### -Project: "Benchmark"=..\..\test\BENCHMARK\Benchmark.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name IL - End Project Dependency - Begin Project Dependency - Project_Dep_Name ILU - End Project Dependency -}}} - -############################################################################### - Project: "Cpp Wrapper"="..\..\Cpp Wrapper\Cpp Wrapper.dsp" - Package Owner=<4> Package=<5> @@ -98,27 +80,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name IL End Project Dependency -}}} - -############################################################################### - -Project: "VolTex"=..\..\TEST\VolTex\VolTex.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name IL - End Project Dependency Begin Project Dependency Project_Dep_Name ILU End Project Dependency - Begin Project Dependency - Project_Dep_Name ILUT - End Project Dependency }}} ############################################################################### diff --git a/DevIL/src-IL/include/il_gif.h b/DevIL/src-IL/include/il_gif.h index ad8dd894..fdfdf969 100644 --- a/DevIL/src-IL/include/il_gif.h +++ b/DevIL/src-IL/include/il_gif.h @@ -62,7 +62,7 @@ ILboolean iIsValidGif(ILvoid); ILboolean GetPalette(ILubyte Info, ILpal *Pal); ILboolean GetImages(ILpal *GlobalPal); ILboolean SkipExtensions(GFXCONTROL *Gfx); -ILboolean GifGetData(ILubyte *Data); +ILboolean GifGetData(ILubyte *Data, ILuint ImageSize); ILboolean RemoveInterlace(ILvoid); ILboolean CopyPalette(ILpal *Dest, ILpal *Src); ILboolean ConvertTransparent(ILimage *Image, ILubyte TransColour); diff --git a/DevIL/src-IL/include/il_internal.h b/DevIL/src-IL/include/il_internal.h index 7ce11e07..93aee5f6 100644 --- a/DevIL/src-IL/include/il_internal.h +++ b/DevIL/src-IL/include/il_internal.h @@ -36,7 +36,6 @@ #include "il_files.h" #include "il_endian.h" -#include "il_alloc.h" // Windows-specific #ifdef _WIN32 diff --git a/DevIL/src-IL/include/il_stack.h b/DevIL/src-IL/include/il_stack.h index 5502294d..d9ee5181 100644 --- a/DevIL/src-IL/include/il_stack.h +++ b/DevIL/src-IL/include/il_stack.h @@ -30,9 +30,6 @@ typedef struct iFree ILboolean iEnlargeStack(ILvoid); ILvoid iFreeMem(ILvoid); -// In alloc.c -void AddToAtexit(); - // Globals for il_stack.c ILuint StackSize = 0; ILuint LastUsed = 0; diff --git a/DevIL/src-IL/msvc/IL.rc b/DevIL/src-IL/msvc/IL.rc index b5eba585..fff3706c 100644 --- a/DevIL/src-IL/msvc/IL.rc +++ b/DevIL/src-IL/msvc/IL.rc @@ -60,8 +60,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,6,1 - PRODUCTVERSION 0,1,6,1 + FILEVERSION 0,1,6,5 + PRODUCTVERSION 0,1,6,5 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x29L @@ -76,17 +76,17 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "DevIL: A great portable image library in development\0" + VALUE "Comments", "DevIL: A portable image library in development\0" VALUE "CompanyName", "Abysmal Software\0" - VALUE "FileDescription", "DevIL: A great portable image library in development\0" - VALUE "FileVersion", "1.6.1\0" + VALUE "FileDescription", "DevIL: A portable image library in development\0" + VALUE "FileVersion", "1.6.5\0" VALUE "InternalName", "Developer's Image Library (DevIL)\0" VALUE "LegalCopyright", "Copyright © 2000-2002\0" VALUE "LegalTrademarks", "Under LGPL License\0" VALUE "OriginalFilename", "DevIL.dll\0" VALUE "PrivateBuild", "Open Source\0" VALUE "ProductName", "Developer's Image Library (DevIL)\0" - VALUE "ProductVersion", "1.6.1\0" + VALUE "ProductVersion", "1.6.5\0" VALUE "SpecialBuild", "eh?\0" END END @@ -115,7 +115,7 @@ IDI_ICON1 ICON DISCARDABLE "resources\\IL Logo.ico" STRINGTABLE DISCARDABLE BEGIN - IDC_OPENIL "Developer's Image Library, Version 1.6.1" + IDC_OPENIL "Developer's Image Library, Version 1.6.5" END #endif // English (U.S.) resources diff --git a/DevIL/src-IL/src/il_alloc.c b/DevIL/src-IL/src/il_alloc.c index b0907666..135063aa 100644 --- a/DevIL/src-IL/src/il_alloc.c +++ b/DevIL/src-IL/src/il_alloc.c @@ -19,6 +19,9 @@ //mAlloc ialloc; //mFree ifree; +mAlloc ialloc_ptr = NULL; +mFree ifree_ptr = NULL; + ILvoid* ILAPIENTRY DefaultAllocFunc(ILuint Size) { @@ -45,6 +48,19 @@ ILvoid ILAPIENTRY ifree(ILvoid *Ptr) } +ILvoid* ILAPIENTRY icalloc(ILuint Size, ILuint Num) +{ + ILvoid *Ptr; + + Ptr = ialloc(Size * Num); + if (Ptr == NULL) + return NULL; + memset(Ptr, 0, Size * Num); + + return Ptr; +} + + ILvoid ILAPIENTRY DefaultFreeFunc(ILvoid *Ptr) { if (Ptr) @@ -63,10 +79,24 @@ ILvoid ILAPIENTRY ilResetMemory() ILvoid ILAPIENTRY ilSetMemory(mAlloc AllocFunc, mFree FreeFunc) { - if (AllocFunc == NULL || FreeFunc == NULL) { + /*if (AllocFunc == NULL || FreeFunc == NULL) { ilSetError(IL_INVALID_PARAM); return; + }*/ + + if (AllocFunc == NULL || FreeFunc == NULL) { + if (ialloc_ptr == NULL || ifree_ptr == NULL) { + ialloc_ptr = DefaultAllocFunc; + ifree_ptr = DefaultFreeFunc; + } + + // If not, we have the special case used by ilInit, so that + // ilSetMemory can be called before ilInit to control all + // memory usage of DevIL. + + return; } + ialloc_ptr = AllocFunc; ifree_ptr = FreeFunc; return; diff --git a/DevIL/src-IL/src/il_bmp.c b/DevIL/src-IL/src/il_bmp.c index f5a56823..f3f751fc 100644 --- a/DevIL/src-IL/src/il_bmp.c +++ b/DevIL/src-IL/src/il_bmp.c @@ -368,7 +368,7 @@ ILboolean ilReadUncompBmp(BMPHEAD *Header) k = 128; for (c = 0; c < 8; c++) { iCurImage->Data[j * iCurImage->Width + i] = - (!!(ByteData & k) == 1 ? 255 : 0); + (!!(ByteData & k) == 1 ? 1 : 0); k >>= 1; if (++i >= iCurImage->Width) break; @@ -391,7 +391,7 @@ ILboolean ilReadUncompBmp(BMPHEAD *Header) k = 128; for (c = 0; c < 8; c++) { iCurImage->Data[j * iCurImage->Width + i] = - (!!(ByteData & k) == 1 ? 255 : 0); + (!!(ByteData & k) == 1 ? 1 : 0); k >>= 1; if (++i >= iCurImage->Width) break; @@ -869,7 +869,7 @@ ILboolean iGetOS2Bmp(OS2_HEAD *Header) k = 128; for (c = 0; c < 8; c++) { iCurImage->Data[j * iCurImage->Width + i] = - (!!(ByteData & k) == 1 ? 255 : 0); + (!!(ByteData & k) == 1 ? 1 : 0); k >>= 1; if (++i >= iCurImage->Width) break; diff --git a/DevIL/src-IL/src/il_convbuff.c b/DevIL/src-IL/src/il_convbuff.c index 6a67094b..ced4af79 100644 --- a/DevIL/src-IL/src/il_convbuff.c +++ b/DevIL/src-IL/src/il_convbuff.c @@ -276,6 +276,68 @@ ILAPI ILvoid* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, IL } break; + case IL_LUMINANCE_ALPHA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3 * 2); + CHECK_ALLOC(); + Size = NumPix / 3; + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[c]; + } + NewData[i*2] = (ILubyte)Resultf; + NewData[i*2+1] = UCHAR_MAX; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILushort*)(NewData))[i*2] = (ILushort)Resultf; + ((ILushort*)(NewData))[i*2+1] = USHRT_MAX; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILuint*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILuint*)(NewData))[i*2] = (ILuint)Resultf; + ((ILuint*)(NewData))[i*2+1] = UINT_MAX; + } + break; + case IL_FLOAT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILfloat*)(NewData))[i*2] = Resultf; + ((ILfloat*)(NewData))[i*2+1] = 1.0f; + } + break; + case IL_DOUBLE: + for (i = 0; i < Size; i++) { + Resultd = 0; + for (c = 0; c < 3; c++) { + Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILdouble*)(NewData))[i*2] = Resultd; + ((ILdouble*)(NewData))[i*2+1] = 1.0; + } + break; + } + break; + default: ilSetError(IL_INVALID_CONVERSION); if (Data != Buffer) @@ -487,6 +549,68 @@ ILAPI ILvoid* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, IL } break; + case IL_LUMINANCE_ALPHA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4 * 2); + CHECK_ALLOC(); + Size = NumPix / 4 * 2; + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0; i < Size; i += 2) { + Resultf = 0.0f; + for (c = 0; c < 3; c++) { + Resultf += ((ILubyte*)(Data))[i * 2 + c] * LumFactor[c]; + } + NewData[i] = (ILubyte)Resultf; + NewData[i+1] = ((ILubyte*)(Data))[i * 2 + 3]; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0; i < Size; i += 2) { + Resultf = 0.0f; + for (c = 0; c < 3; c++) { + Resultf += ((ILushort*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILushort*)(NewData))[i] = (ILushort)Resultf; + ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i * 2 + 3]; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILuint*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILuint*)(NewData))[i] = (ILuint)Resultd; + ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i * 2 + 3]; + } + break; + case IL_FLOAT: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILfloat*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILfloat*)(NewData))[i] = (ILfloat)Resultd; + ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i * 2 + 3]; + } + break; + case IL_DOUBLE: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILdouble*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILdouble*)(NewData))[i] = Resultd; + ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i * 2 + 3]; + } + break; + } + break; + default: ilSetError(IL_INVALID_CONVERSION); if (Data != Buffer) @@ -703,6 +827,68 @@ ILAPI ILvoid* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, IL } break; + case IL_LUMINANCE_ALPHA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 3 * 2); + CHECK_ALLOC(); + Size = NumPix / 3; + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILubyte*)(Data))[i * 3 + c] * LumFactor[c]; + } + NewData[i*2] = (ILubyte)Resultf; + NewData[i*2+1] = UCHAR_MAX; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILushort*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILushort*)(NewData))[i*2] = (ILushort)Resultf; + ((ILushort*)(NewData))[i*2+1] = USHRT_MAX; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILuint*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILuint*)(NewData))[i*2] = (ILuint)Resultf; + ((ILuint*)(NewData))[i*2+1] = UINT_MAX; + } + break; + case IL_FLOAT: + for (i = 0; i < Size; i++) { + Resultf = 0; + for (c = 0; c < 3; c++) { + Resultf += ((ILfloat*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILfloat*)(NewData))[i*2] = Resultf; + ((ILfloat*)(NewData))[i*2+1] = 1.0f; + } + break; + case IL_DOUBLE: + for (i = 0; i < Size; i++) { + Resultd = 0; + for (c = 0; c < 3; c++) { + Resultd += ((ILdouble*)(Data))[i * 3 + c] * LumFactor[c]; + } + ((ILdouble*)(NewData))[i*2] = Resultd; + ((ILdouble*)(NewData))[i*2+1] = 1.0; + } + break; + } + break; + default: ilSetError(IL_INVALID_CONVERSION); if (Data != Buffer) @@ -914,6 +1100,68 @@ ILAPI ILvoid* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, IL } break; + case IL_LUMINANCE_ALPHA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 4 * 2); + CHECK_ALLOC(); + Size = NumPix / 4 * 2; + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0; i < Size; i += 2) { + Resultf = 0.0f; + for (c = 0; c < 3; c++) { + Resultf += ((ILubyte*)(Data))[i * 2 + c] * LumFactor[c]; + } + NewData[i] = (ILubyte)Resultf; + NewData[i+1] = ((ILubyte*)(Data))[i * 2 + 3]; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0; i < Size; i += 2) { + Resultf = 0.0f; + for (c = 0; c < 3; c++) { + Resultf += ((ILushort*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILushort*)(NewData))[i] = (ILushort)Resultf; + ((ILushort*)(NewData))[i+1] = ((ILushort*)(Data))[i * 2 + 3]; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILuint*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILuint*)(NewData))[i] = (ILuint)Resultd; + ((ILuint*)(NewData))[i+1] = ((ILuint*)(Data))[i * 2 + 3]; + } + break; + case IL_FLOAT: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILfloat*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILfloat*)(NewData))[i] = (ILfloat)Resultd; + ((ILfloat*)(NewData))[i+1] = ((ILfloat*)(Data))[i * 2 + 3]; + } + break; + case IL_DOUBLE: + for (i = 0; i < Size; i += 2) { + Resultd = 0.0; + for (c = 0; c < 3; c++) { + Resultd += ((ILdouble*)(Data))[i * 2 + c] * LumFactor[c]; + } + ((ILdouble*)(NewData))[i] = Resultd; + ((ILdouble*)(NewData))[i+1] = ((ILdouble*)(Data))[i * 2 + 3]; + } + break; + } + break; + default: ilSetError(IL_INVALID_CONVERSION); if (Data != Buffer) @@ -1026,6 +1274,219 @@ ILAPI ILvoid* ILAPIENTRY ilConvertBuffer(ILuint SizeOfData, ILenum SrcFormat, IL } break; + case IL_LUMINANCE_ALPHA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest * 2); + CHECK_ALLOC(); + + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0; i < NumPix; i++) { + NewData[i * 2] = ((ILubyte*)(Data))[i]; + NewData[i * 2 + 1] = UCHAR_MAX; // Full opacity + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0; i < NumPix; i++) { + ((ILushort*)(NewData))[i * 2] = ((ILushort*)(Data))[i]; + ((ILushort*)(NewData))[i * 2 + 1] = USHRT_MAX; // Full opacity + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0; i < NumPix; i++) { + ((ILuint*)(NewData))[i * 2] = ((ILuint*)(Data))[i]; + ((ILuint*)(NewData))[i * 2 + 1] = UINT_MAX; // Full opacity + } + break; + case IL_FLOAT: + for (i = 0; i < NumPix; i++) { + ((ILfloat*)(NewData))[i * 2] = ((ILfloat*)(Data))[i]; + ((ILfloat*)(NewData))[i * 2 + 1] = 1.0f; // Full opacity + } + break; + case IL_DOUBLE: + for (i = 0; i < NumPix; i++) { + ((ILdouble*)(NewData))[i * 2] = ((ILdouble*)(Data))[i]; + ((ILdouble*)(NewData))[i * 2 + 1] = 1.0; // Full opacity + } + break; + } + break; + + + /*case IL_COLOUR_INDEX: + NewData = (ILubyte*)ialloc(iCurImage->SizeOfData); + NewImage->Pal.Palette = (ILubyte*)ialloc(768); + if (NewData == NULL || NewImage->Pal.Palette) { + ifree(NewImage); + return IL_FALSE; + } + + // Fill the palette + for (i = 0; i < 256; i++) { + for (c = 0; c < 3; c++) { + NewImage->Pal.Palette[i * 3 + c] = (ILubyte)i; + } + } + // Copy the data + for (i = 0; i < iCurImage->SizeOfData; i++) { + NewData[i] = iCurImage->Data[i]; + } + break;*/ + + default: + ilSetError(IL_INVALID_CONVERSION); + if (Data != Buffer) + ifree(Data); + return NULL; + } + break; + + + case IL_LUMINANCE_ALPHA: + switch (DestFormat) + { + case IL_RGB: + case IL_BGR: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2 * 3); + CHECK_ALLOC(); + + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0, j = 0; i < NumPix; i += 2, j += 3) { + for (c = 0; c < 3; c++) { + NewData[j + c] = ((ILubyte*)(Data))[i]; + } + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 3) { + for (c = 0; c < 3; c++) { + ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i]; + } + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 3) { + for (c = 0; c < 3; c++) { + ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i]; + } + } + break; + case IL_FLOAT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 3) { + for (c = 0; c < 3; c++) { + ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i]; + } + } + break; + case IL_DOUBLE: + for (i = 0, j = 0; i < NumPix; i += 2, j += 3) { + for (c = 0; c < 3; c++) { + ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i]; + } + } + break; + } + break; + + case IL_RGBA: + case IL_BGRA: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2 * 4); + CHECK_ALLOC(); + + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0, j = 0; i < NumPix; i += 2, j += 4) { + for (c = 0; c < 3; c++) { + NewData[j + c] = ((ILubyte*)(Data))[i]; + } + NewData[j + 3] = ((ILubyte*)(Data))[i+1]; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 4) { + for (c = 0; c < 3; c++) { + ((ILushort*)(NewData))[j + c] = ((ILushort*)(Data))[i]; + } + ((ILushort*)(NewData))[j + 3] = ((ILushort*)(Data))[i+1]; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 4) { + for (c = 0; c < 3; c++) { + ((ILuint*)(NewData))[j + c] = ((ILuint*)(Data))[i]; + } + ((ILuint*)(NewData))[j + 3] = ((ILuint*)(Data))[i+1]; + } + break; + case IL_FLOAT: + for (i = 0, j = 0; i < NumPix; i += 2, j += 4) { + for (c = 0; c < 3; c++) { + ((ILfloat*)(NewData))[j + c] = ((ILfloat*)(Data))[i]; + } + ((ILfloat*)(NewData))[j + 3] = ((ILfloat*)(Data))[i+1]; + } + break; + case IL_DOUBLE: + for (i = 0, j = 0; i < NumPix; i += 2, j += 4) { + for (c = 0; c < 3; c++) { + ((ILdouble*)(NewData))[j + c] = ((ILdouble*)(Data))[i]; + } + ((ILdouble*)(NewData))[j + 3] = ((ILdouble*)(Data))[i+1]; + } + break; + } + break; + + case IL_LUMINANCE: + NewData = (ILubyte*)ialloc(NumPix * BpcDest / 2); + CHECK_ALLOC(); + + switch (DestType) + { + case IL_UNSIGNED_BYTE: + case IL_BYTE: + for (i = 0, j = 0; i < NumPix; i += 2, j++) { + NewData[j] = ((ILubyte*)(Data))[i]; + } + break; + case IL_UNSIGNED_SHORT: + case IL_SHORT: + for (i = 0, j = 0; i < NumPix; i += 2, j++) { + ((ILushort*)(NewData))[j] = ((ILushort*)(Data))[i]; + } + break; + case IL_UNSIGNED_INT: + case IL_INT: + for (i = 0, j = 0; i < NumPix; i += 2, j++) { + ((ILuint*)(NewData))[j] = ((ILuint*)(Data))[i]; + } + break; + case IL_FLOAT: + for (i = 0, j = 0; i < NumPix; i += 2, j++) { + ((ILfloat*)(NewData))[j] = ((ILfloat*)(Data))[i]; + } + break; + case IL_DOUBLE: + for (i = 0, j = 0; i < NumPix; i += 2, j++) { + ((ILdouble*)(NewData))[j] = ((ILdouble*)(Data))[i]; + } + break; + } + break; + /*case IL_COLOUR_INDEX: NewData = (ILubyte*)ialloc(iCurImage->SizeOfData); NewImage->Pal.Palette = (ILubyte*)ialloc(768); diff --git a/DevIL/src-IL/src/il_convert.c b/DevIL/src-IL/src/il_convert.c index b6a40a19..9fb221c5 100644 --- a/DevIL/src-IL/src/il_convert.c +++ b/DevIL/src-IL/src/il_convert.c @@ -20,12 +20,12 @@ ILimage *iConvertPalette(ILimage *Image, ILenum DestFormat) { static const ILfloat LumFactor[3] = { 0.212671f, 0.715160f, 0.072169f }; // http://www.inforamp.net/~poynton/ and libpng's libpng.txt - Used for conversion to luminance. ILimage *NewImage = NULL, *CurImage = NULL; - ILuint i, j, c, Size; + ILuint i, j, k, c, Size, LumBpp = 1; ILfloat Resultf; ILubyte *Temp = NULL; ILboolean Converted; - NewImage = (ILimage*)calloc(1, sizeof(ILimage)); // Much better to have it all set to 0. + NewImage = (ILimage*)icalloc(1, sizeof(ILimage)); // Much better to have it all set to 0. if (NewImage == NULL) { return IL_FALSE; } @@ -38,26 +38,34 @@ ILimage *iConvertPalette(ILimage *Image, ILenum DestFormat) return NULL; } - if (DestFormat == IL_LUMINANCE) { + if (DestFormat == IL_LUMINANCE || DestFormat == IL_LUMINANCE_ALPHA) { if (NewImage->Pal.Palette) ifree(NewImage->Pal.Palette); + if (DestFormat == IL_LUMINANCE_ALPHA) + LumBpp = 2; switch (iCurImage->Pal.PalType) { case IL_PAL_RGB24: case IL_PAL_RGB32: case IL_PAL_RGBA32: - Temp = (ILubyte*)ialloc(Image->Pal.PalSize / ilGetBppPal(Image->Pal.PalType)); + Temp = (ILubyte*)ialloc(LumBpp * Image->Pal.PalSize / ilGetBppPal(Image->Pal.PalType)); if (Temp == NULL) goto alloc_error; Size = ilGetBppPal(Image->Pal.PalType); - for (i = 0; i < Image->Pal.PalSize; i += Size) { + for (i = 0, k = 0; i < Image->Pal.PalSize; i += Size, k += LumBpp) { Resultf = 0.0f; for (c = 0; c < Size; c++) { Resultf += Image->Pal.Palette[i + c] * LumFactor[c]; } - Temp[i / Size] = (ILubyte)Resultf; + Temp[k] = (ILubyte)Resultf; + if (LumBpp == 2) { + if (iCurImage->Pal.PalType == IL_PAL_RGBA32) + Temp[k+1] = Image->Pal.Palette[i + 3]; + else + Temp[k+1] = 0xff; + } } break; @@ -65,36 +73,53 @@ ILimage *iConvertPalette(ILimage *Image, ILenum DestFormat) case IL_PAL_BGR24: case IL_PAL_BGR32: case IL_PAL_BGRA32: - Temp = (ILubyte*)ialloc(Image->Pal.PalSize / ilGetBppPal(Image->Pal.PalType)); + Temp = (ILubyte*)ialloc(LumBpp * Image->Pal.PalSize / ilGetBppPal(Image->Pal.PalType)); if (Temp == NULL) goto alloc_error; Size = ilGetBppPal(Image->Pal.PalType); - for (i = 0; i < Image->Pal.PalSize; i += Size) { + for (i = 0, k = 0; i < Image->Pal.PalSize; i += Size, k += LumBpp) { Resultf = 0.0f; j = 2; for (c = 0; c < Size; c++, j--) { Resultf += Image->Pal.Palette[i + c] * LumFactor[j]; } - Temp[i / Size] = (ILubyte)Resultf; + Temp[k] = (ILubyte)Resultf; + if (LumBpp == 2) { + if (iCurImage->Pal.PalType == IL_PAL_RGBA32) + Temp[k+1] = Image->Pal.Palette[i + 3]; + else + Temp[k+1] = 0xff; + } } break; } - NewImage->Data = (ILubyte*)ialloc(Image->SizeOfData); + NewImage->Pal.Palette = NULL; + NewImage->Pal.PalSize = 0; + NewImage->Pal.PalType = IL_PAL_NONE; + NewImage->Format = DestFormat; + NewImage->Bpp = LumBpp; + NewImage->Bps = NewImage->Width * LumBpp; + NewImage->SizeOfData = NewImage->SizeOfPlane = NewImage->Bps * NewImage->Height; + NewImage->Data = (ILubyte*)ialloc(NewImage->SizeOfData); if (NewImage->Data == NULL) goto alloc_error; - for (i = 0; i < Image->SizeOfData; i++) { - NewImage->Data[i] = Temp[Image->Data[i]]; + + if (LumBpp == 2) { + for (i = 0; i < Image->SizeOfData; i++) { + NewImage->Data[i*2] = Temp[Image->Data[i] * 2]; + NewImage->Data[i*2+1] = Temp[Image->Data[i] * 2 + 1]; + } + } + else { + for (i = 0; i < Image->SizeOfData; i++) { + NewImage->Data[i] = Temp[Image->Data[i]]; + } } ifree(Temp); - NewImage->Pal.Palette = NULL; - NewImage->Pal.PalSize = 0; - NewImage->Pal.PalType = IL_PAL_NONE; - NewImage->Format = IL_LUMINANCE; - return NewImage; } @@ -145,7 +170,6 @@ ILimage *iConvertPalette(ILimage *Image, ILenum DestFormat) default: ilCloseImage(NewImage); - ilSetCurImage(CurImage); ilSetError(IL_INVALID_CONVERSION); return NULL; } @@ -196,6 +220,7 @@ ILAPI ILimage* ILAPIENTRY iConvertImage(ILimage *Image, ILenum DestFormat, ILenu { ILimage *NewImage, *CurImage; ILuint i; + ILubyte *NewData; CurImage = Image; if (Image == NULL) { @@ -204,13 +229,32 @@ ILAPI ILimage* ILAPIENTRY iConvertImage(ILimage *Image, ILenum DestFormat, ILenu } // We don't support 16-bit color indices (or higher). - if (Image->Format == IL_COLOUR_INDEX && DestType >= IL_SHORT) { + if (DestFormat == IL_COLOUR_INDEX && DestType >= IL_SHORT) { ilSetError(IL_INVALID_CONVERSION); return NULL; } if (Image->Format == IL_COLOUR_INDEX) { NewImage = iConvertPalette(Image, DestFormat); + if (DestType == NewImage->Type) + return NewImage; + + NewData = ilConvertBuffer(NewImage->SizeOfData, NewImage->Format, DestFormat, NewImage->Type, DestType, NewImage->Data); + if (NewData == NULL) { + ifree(NewImage); // ilCloseImage not needed. + return NULL; + } + ifree(NewImage->Data); + NewImage->Data = NewData; + + ilCopyImageAttr(NewImage, Image); + NewImage->Format = DestFormat; + NewImage->Type = DestType; + NewImage->Bpc = ilGetBppType(DestType); + NewImage->Bpp = ilGetBppFormat(DestFormat); + NewImage->Bps = NewImage->Bpp * NewImage->Bpc * NewImage->Width; + NewImage->SizeOfPlane = NewImage->Bps * NewImage->Height; + NewImage->SizeOfData = NewImage->SizeOfPlane * NewImage->Depth; } else if (DestFormat == IL_COLOUR_INDEX && Image->Format != IL_LUMINANCE) { if (iGetInt(IL_QUANTIZATION_MODE) == IL_NEU_QUANT) @@ -219,7 +263,7 @@ ILAPI ILimage* ILAPIENTRY iConvertImage(ILimage *Image, ILenum DestFormat, ILenu return iQuantizeImage(Image, 256); } else { - NewImage = (ILimage*)calloc(1, sizeof(ILimage)); // Much better to have it all set to 0. + NewImage = (ILimage*)icalloc(1, sizeof(ILimage)); // Much better to have it all set to 0. if (NewImage == NULL) { return NULL; } diff --git a/DevIL/src-IL/src/il_dds-save.c b/DevIL/src-IL/src/il_dds-save.c index 32bf2673..697017e9 100644 --- a/DevIL/src-IL/src/il_dds-save.c +++ b/DevIL/src-IL/src/il_dds-save.c @@ -79,7 +79,7 @@ ILboolean iSaveDdsInternal() WriteHeader(iCurImage, DXTCFormat); numMipMaps = ilGetInteger(IL_NUM_MIPMAPS); - for (counter = 0; counter < numMipMaps; counter++) { + for (counter = 0; counter <= numMipMaps; counter++) { ilActiveMipmap(counter); if (iCurImage->Origin != IL_ORIGIN_UPPER_LEFT) { @@ -157,7 +157,7 @@ ILboolean WriteHeader(ILimage *Image, ILenum DXTCFormat) } SaveLittleUInt(LinearSize); // LinearSize SaveLittleUInt(0); // Depth - SaveLittleUInt(ilGetInteger(IL_NUM_MIPMAPS)); // MipMapCount + SaveLittleUInt(ilGetInteger(IL_NUM_MIPMAPS) + 1); // MipMapCount SaveLittleUInt(0); // AlphaBitDepth for (i = 0; i < 10; i++) @@ -631,7 +631,7 @@ ILvoid ChooseEndpoints(ILushort *Block, ILushort *ex0, ILushort *ex1) { ILuint i, j; Color888 Colours[16]; - ILuint Farthest = 0, d; + ILint Farthest = -1, d; for (i = 0; i < 16; i++) { ShortToColor888(Block[i], &Colours[i]); diff --git a/DevIL/src-IL/src/il_devil.c b/DevIL/src-IL/src/il_devil.c index e5f054b3..79c02d3e 100644 --- a/DevIL/src-IL/src/il_devil.c +++ b/DevIL/src-IL/src/il_devil.c @@ -60,6 +60,9 @@ ILAPI ILimage* ILAPIENTRY ilNewImage(ILuint Width, ILuint Height, ILuint Depth, case 1: Image->Format = IL_LUMINANCE; break; + case 2: + Image->Format = IL_LUMINANCE_ALPHA; + break; case 3: Image->Format = IL_RGB; break; @@ -227,15 +230,24 @@ ILubyte* ILAPIENTRY ilGetPalette() // (http://www.newscientist.com/news/news.jsp?id=ns99991775) // *(http://www.space.com/scienceastronomy/universe_color_020308.html)* //ILfloat ClearRed = 0.269f, ClearGreen = 0.388f, ClearBlue = 0.342f, ClearAlpha = 0.0f; -ILfloat ClearRed = 1.0f, ClearGreen = 0.972549f, ClearBlue = 0.90588f, ClearAlpha = 0.0f; +ILfloat ClearRed = 1.0f, ClearGreen = 0.972549f, ClearBlue = 0.90588f, ClearAlpha = 0.0f, + ClearLum = 1.0f; ILvoid ILAPIENTRY ilClearColour(ILclampf Red, ILclampf Green, ILclampf Blue, ILclampf Alpha) { // Clamp to 0.0f - 1.0f. - ClearRed = Red < 0.0f ? 0.0f : (Red > 1.0f ? 1.0f : Red); - ClearGreen = Green < 0.0f ? 0.0f : (Green > 1.0f ? 1.0f : Green); - ClearBlue = Blue < 0.0f ? 0.0f : (Blue > 1.0f ? 1.0f : Blue); - ClearAlpha = Alpha < 0.0f ? 0.0f : (Alpha > 1.0f ? 1.0f : Alpha); + ClearRed = Red < 0.0f ? 0.0f : (Red > 1.0f ? 1.0f : Red); + ClearGreen = Green < 0.0f ? 0.0f : (Green > 1.0f ? 1.0f : Green); + ClearBlue = Blue < 0.0f ? 0.0f : (Blue > 1.0f ? 1.0f : Blue); + ClearAlpha = Alpha < 0.0f ? 0.0f : (Alpha > 1.0f ? 1.0f : Alpha); + + if ((Red == Green) && (Red == Blue) && (Green == Blue)) { + ClearLum = Red < 0.0f ? 0.0f : (Red > 1.0f ? 1.0f : Red); + } + else { + ClearLum = 0.212671f * ClearRed + 0.715160f * ClearGreen + 0.072169f * ClearBlue; + ClearLum = ClearLum < 0.0f ? 0.0f : (ClearLum > 1.0f ? 1.0f : ClearLum); + } return; } @@ -287,6 +299,10 @@ ILAPI ILvoid ILAPIENTRY ilGetClear(ILvoid *Colours, ILenum Format, ILenum Type) BytePtr[0] = (ILubyte)(ClearAlpha * UCHAR_MAX); break; + case IL_LUMINANCE_ALPHA: + BytePtr[0] = (ILubyte)(ClearLum * UCHAR_MAX); + BytePtr[1] = (ILubyte)(ClearAlpha * UCHAR_MAX); + case IL_COLOUR_INDEX: BytePtr[0] = (ILubyte)(ClearAlpha * UCHAR_MAX); break; @@ -333,6 +349,11 @@ ILAPI ILvoid ILAPIENTRY ilGetClear(ILvoid *Colours, ILenum Format, ILenum Type) ShortPtr[0] = (ILushort)(ClearAlpha * USHRT_MAX); break; + case IL_LUMINANCE_ALPHA: + ShortPtr[0] = (ILushort)(ClearLum * USHRT_MAX); + ShortPtr[1] = (ILushort)(ClearAlpha * USHRT_MAX); + break; + case IL_COLOUR_INDEX: ShortPtr[0] = (ILushort)(ClearAlpha * USHRT_MAX); break; @@ -379,6 +400,11 @@ ILAPI ILvoid ILAPIENTRY ilGetClear(ILvoid *Colours, ILenum Format, ILenum Type) IntPtr[0] = (ILuint)(ClearAlpha * UINT_MAX); break; + case IL_LUMINANCE_ALPHA: + IntPtr[0] = (ILuint)(ClearLum * UINT_MAX); + IntPtr[1] = (ILuint)(ClearAlpha * UINT_MAX); + break; + case IL_COLOUR_INDEX: IntPtr[0] = (ILuint)(ClearAlpha * UINT_MAX); break; @@ -424,6 +450,11 @@ ILAPI ILvoid ILAPIENTRY ilGetClear(ILvoid *Colours, ILenum Format, ILenum Type) FloatPtr[0] = ClearAlpha; break; + case IL_LUMINANCE_ALPHA: + FloatPtr[0] = ClearLum; + FloatPtr[0] = ClearAlpha; + break; + case IL_COLOUR_INDEX: FloatPtr[0] = ClearAlpha; break; @@ -469,6 +500,11 @@ ILAPI ILvoid ILAPIENTRY ilGetClear(ILvoid *Colours, ILenum Format, ILenum Type) DblPtr[0] = ClearAlpha; break; + case IL_LUMINANCE_ALPHA: + DblPtr[0] = ClearLum; + DblPtr[1] = ClearAlpha; + break; + case IL_COLOUR_INDEX: DblPtr[0] = ClearAlpha; break; @@ -591,14 +627,16 @@ ILAPI ILboolean ILAPIENTRY ilClearImage_(ILimage *Image) //! Overlays the image found in Src on top of the current bound image at the coords specified. ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, ILint ZCoord) { - ILuint c, x, y, z, SrcIndex, DestIndex, ConvBps, ConvSizePlane; + ILuint x, y, z, SrcIndex, DestIndex, ConvBps, ConvSizePlane; + ILint c; ILimage *Dest;//, *Src; ILubyte *Converted; ILuint DestName = ilGetCurName(); ILfloat FrontPer, BackPer; ILenum DestOrigin, SrcOrigin; - ILuint StartX, StartY, StartZ; - ILboolean DestFlipped = IL_FALSE, SrcFlipped = IL_FALSE; + ILuint StartX, StartY, StartZ, AlphaOff; + ILubyte *SrcTemp = NULL; + ILboolean DestFlipped = IL_FALSE; if (DestName == 0 || iCurImage == NULL) { @@ -617,8 +655,16 @@ ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, I SrcOrigin = iCurImage->Origin; if (iCurImage->Origin == IL_ORIGIN_LOWER_LEFT) { - SrcFlipped = IL_TRUE; - ilFlipImage(); + SrcTemp = iGetFlipped(iCurImage); + if (SrcTemp == NULL) { + ilBindImage(DestName); + if (DestFlipped) + ilFlipImage(); + return IL_FALSE; + } + } + else { + SrcTemp = iCurImage->Data; } if (Dest == NULL || iCurImage == NULL) { @@ -626,7 +672,7 @@ ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, I return IL_FALSE; } - Converted = ilConvertBuffer(iCurImage->SizeOfData, iCurImage->Format, Dest->Format, iCurImage->Type, Dest->Type, iCurImage->Data); + Converted = ilConvertBuffer(iCurImage->SizeOfData, iCurImage->Format, Dest->Format, iCurImage->Type, Dest->Type, SrcTemp); if (Converted == NULL) return IL_FALSE; @@ -637,18 +683,25 @@ ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, I StartY = YCoord >= 0 ? 0 : -YCoord; StartZ = ZCoord >= 0 ? 0 : -ZCoord; - if (iCurImage->Format == IL_RGBA || iCurImage->Format == IL_BGRA) { + if (iCurImage->Format == IL_RGBA || iCurImage->Format == IL_BGRA || iCurImage->Format == IL_LUMINANCE_ALPHA) { + if (iCurImage->Format == IL_LUMINANCE_ALPHA) + AlphaOff = 1; + else + AlphaOff = 3; + for (z = StartZ; z < iCurImage->Depth && (ILint)z + ZCoord < (ILint)Dest->Depth; z++) { for (y = StartY; y < iCurImage->Height && (ILint)y + YCoord < (ILint)Dest->Height; y++) { for (x = StartX; x < iCurImage->Width && (ILint)x + XCoord < (ILint)Dest->Width; x++) { SrcIndex = z * ConvSizePlane + y * ConvBps + x * Dest->Bpp; DestIndex = (z + ZCoord) * Dest->SizeOfPlane + (y + YCoord) * Dest->Bps + (x + XCoord) * Dest->Bpp; - FrontPer = iCurImage->Data[z * iCurImage->SizeOfPlane + y * iCurImage->Bps + x * iCurImage->Bpp + 3] / 255.0f; + FrontPer = iCurImage->Data[z * iCurImage->SizeOfPlane + y * iCurImage->Bps + x * iCurImage->Bpp + AlphaOff] / 255.0f; BackPer = 1.0f - FrontPer; - for (c = 0; c < iCurImage->Bpp; c++) { + for (c = 0; c < iCurImage->Bpp - 1; c++) { Dest->Data[DestIndex + c] = (ILubyte)(Converted[SrcIndex + c] * FrontPer + Dest->Data[DestIndex + c] * BackPer); } + // Keep the original alpha. + //Dest->Data[DestIndex + c + 1] = Dest->Data[DestIndex + c + 1]; } } } @@ -666,8 +719,8 @@ ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, I } } - if (SrcFlipped) - ilFlipImage(); + if (SrcTemp != iCurImage->Data) + ifree(SrcTemp); ilBindImage(DestName); if (DestFlipped) @@ -681,14 +734,16 @@ ILboolean ILAPIENTRY ilOverlayImage(ILuint Source, ILint XCoord, ILint YCoord, I ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ, ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width, ILuint Height, ILuint Depth) { - ILuint c, x, y, z, SrcIndex, DestIndex, ConvBps, ConvSizePlane; + ILuint x, y, z, SrcIndex, DestIndex, ConvBps, ConvSizePlane; ILimage *Dest; ILubyte *Converted; ILuint DestName = ilGetCurName(); + ILint c; ILfloat FrontPer, BackPer; ILenum DestOrigin, SrcOrigin; - ILuint StartX, StartY, StartZ; - ILboolean SrcFlipped = IL_FALSE, DestFlipped = IL_FALSE; + ILuint StartX, StartY, StartZ, AlphaOff; + ILboolean DestFlipped = IL_FALSE; + ILubyte *SrcTemp; if (DestName == 0 || iCurImage == NULL) { @@ -707,8 +762,16 @@ ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ SrcOrigin = iCurImage->Origin; if (iCurImage->Origin == IL_ORIGIN_LOWER_LEFT) { - SrcFlipped = IL_TRUE; - ilFlipImage(); + SrcTemp = iGetFlipped(iCurImage); + if (SrcTemp == NULL) { + ilBindImage(DestName); + if (DestFlipped) + ilFlipImage(); + return IL_FALSE; + } + } + else { + SrcTemp = iCurImage->Data; } if (Dest == NULL || iCurImage == NULL) { @@ -716,7 +779,7 @@ ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ return IL_FALSE; } - Converted = ilConvertBuffer(iCurImage->SizeOfData, iCurImage->Format, Dest->Format, iCurImage->Type, Dest->Type, iCurImage->Data); + Converted = ilConvertBuffer(iCurImage->SizeOfData, iCurImage->Format, Dest->Format, iCurImage->Type, Dest->Type, SrcTemp); if (Converted == NULL) return IL_FALSE; @@ -731,7 +794,12 @@ ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ Height = Height + SrcY < Dest->Height ? Height + SrcY : Dest->Height; Depth = Depth + SrcZ < Dest->Depth ? Depth + SrcZ : Dest->Depth; - if (iCurImage->Format == IL_RGBA || iCurImage->Format == IL_BGRA) { + if (iCurImage->Format == IL_RGBA || iCurImage->Format == IL_BGRA || iCurImage->Format == IL_LUMINANCE_ALPHA) { + if (iCurImage->Format == IL_LUMINANCE_ALPHA) + AlphaOff = 1; + else + AlphaOff = 3; + for (z = StartZ; z < Depth && z + DestZ < Dest->Depth; z++) { for (y = StartY; y < Height && y + DestY < Dest->Height; y++) { for (x = StartX; x < Width && x + DestX < Dest->Width; x++) { @@ -740,10 +808,12 @@ ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ // Use the original alpha FrontPer = iCurImage->Data[(z + SrcZ) * iCurImage->SizeOfPlane + (y + SrcY) * iCurImage->Bps + (x + SrcX) * iCurImage->Bpp + 3] / 255.0f; BackPer = 1.0f - FrontPer; - for (c = 0; c < Dest->Bpp; c++) { + for (c = 0; c < Dest->Bpp - 1; c++) { Dest->Data[DestIndex + c] = (ILubyte)(Converted[SrcIndex + c] * FrontPer + Dest->Data[DestIndex + c] * BackPer); } + // Keep the original alpha. + //Dest->Data[DestIndex + c + 1] = Dest->Data[DestIndex + c + 1]; } } } @@ -761,8 +831,8 @@ ILboolean ILAPIENTRY ilBlit(ILuint Source, ILint DestX, ILint DestY, ILint DestZ } } - if (SrcFlipped) - ilFlipImage(); + if (SrcTemp != iCurImage->Data) + ifree(SrcTemp); ilBindImage(DestName); if (DestFlipped) @@ -790,7 +860,7 @@ ILboolean iCopySubImage(ILimage *Dest, ILimage *Src) memcpy(DestTemp->Data, SrcTemp->Data, SrcTemp->SizeOfData); if (SrcTemp->Next) { - DestTemp->Next = (ILimage*)calloc(1, sizeof(ILimage)); + DestTemp->Next = (ILimage*)icalloc(1, sizeof(ILimage)); if (!DestTemp->Next) { return IL_FALSE; } @@ -808,7 +878,7 @@ ILboolean iCopySubImage(ILimage *Dest, ILimage *Src) ILboolean iCopySubImages(ILimage *Dest, ILimage *Src) { if (Src->Layers) { - Dest->Layers = (ILimage*)calloc(1, sizeof(ILimage)); + Dest->Layers = (ILimage*)icalloc(1, sizeof(ILimage)); if (!Dest->Layers) { return IL_FALSE; } @@ -818,7 +888,7 @@ ILboolean iCopySubImages(ILimage *Dest, ILimage *Src) Dest->NumLayers = Src->NumLayers; if (Src->Mipmaps) { - Dest->Mipmaps = (ILimage*)calloc(1, sizeof(ILimage)); + Dest->Mipmaps = (ILimage*)icalloc(1, sizeof(ILimage)); if (!Dest->Mipmaps) { return IL_FALSE; } @@ -828,7 +898,7 @@ ILboolean iCopySubImages(ILimage *Dest, ILimage *Src) Dest->NumMips = Src->NumMips; if (Src->Next) { - Dest->Next = (ILimage*)calloc(1, sizeof(ILimage)); + Dest->Next = (ILimage*)icalloc(1, sizeof(ILimage)); if (!Dest->Next) { return IL_FALSE; } diff --git a/DevIL/src-IL/src/il_gif.c b/DevIL/src-IL/src/il_gif.c index eaeb4c90..fcee1a3f 100644 --- a/DevIL/src-IL/src/il_gif.c +++ b/DevIL/src-IL/src/il_gif.c @@ -277,7 +277,7 @@ ILboolean GetImages(ILpal *GlobalPal) } - if (!GifGetData(TempData)) { + if (!GifGetData(TempData, Image->SizeOfData)) { ilSetError(IL_ILLEGAL_FILE_VALUE); goto error_clean; } @@ -310,6 +310,8 @@ ILboolean GetImages(ILpal *GlobalPal) } } + i = itell(); + // Terminates each block. if (igetc() != 0x00) break; @@ -451,12 +453,13 @@ ILint get_next_code(void) } -ILboolean GifGetData(ILubyte *Data) +ILboolean GifGetData(ILubyte *Data, ILuint ImageSize) { ILubyte *sp; ILint code, fc, oc; ILubyte size; ILint c; + ILuint i = 0; size = igetc(); if (size < 2 || 9 < size) { @@ -482,7 +485,7 @@ ILboolean GifGetData(ILubyte *Data) oc = fc = 0; sp = stack; - while ((c = get_next_code()) != ending) { + while ((c = get_next_code()) != ending && i < ImageSize) { if (c == clear) { curr_size = size + 1; slot = newcodes; @@ -493,7 +496,9 @@ ILboolean GifGetData(ILubyte *Data) if (c >= slot) c = 0; oc = fc = c; - *Data++ = c; + //if (i < ImageSize) + Data[i++] = c; + //*Data++ = c; } else { code = c; @@ -518,7 +523,9 @@ ILboolean GifGetData(ILubyte *Data) } while (sp > stack) { sp--; - *Data++ = *sp; + //if (i < ImageSize) + Data[i++] = *sp; + //*Data++ = *sp; } } } diff --git a/DevIL/src-IL/src/il_io.c b/DevIL/src-IL/src/il_io.c index d5e67346..3da9c340 100644 --- a/DevIL/src-IL/src/il_io.c +++ b/DevIL/src-IL/src/il_io.c @@ -40,8 +40,8 @@ ILAPI ILenum ILAPIENTRY ilTypeFromExt(const ILstring FileName) return IL_PNG; if (!iStrCmp(Ext, IL_TEXT("bmp")) || !iStrCmp(Ext, IL_TEXT("dib"))) return IL_BMP; - if (!iStrCmp(Ext, IL_TEXT("gif"))) - return IL_GIF; + /*if (!iStrCmp(Ext, IL_TEXT("gif"))) + return IL_GIF;*/ if (!iStrCmp(Ext, IL_TEXT("cut"))) return IL_CUT; if (!iStrCmp(Ext, IL_TEXT("ico")) || !iStrCmp(Ext, IL_TEXT("cur"))) @@ -137,10 +137,10 @@ ILenum ilDetermineTypeF(ILHANDLE File) return IL_BMP; #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF if (ilIsValidGifF(File)) return IL_GIF; - #endif + #endif*/ #ifndef IL_NO_LIF if (ilIsValidLifF(File)) @@ -216,10 +216,10 @@ ILenum ilDetermineTypeL(ILvoid *Lump, ILuint Size) return IL_BMP; #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF if (ilIsValidGifL(Lump, Size)) return IL_GIF; - #endif + #endif*/ #ifndef IL_NO_LIF if (ilIsValidLifL(Lump, Size)) @@ -299,10 +299,10 @@ ILboolean ILAPIENTRY ilIsValid(ILenum Type, const ILstring FileName) return ilIsValidBmp(FileName); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilIsValidGif(FileName); - #endif + #endif*/ #ifndef IL_NO_LIF case IL_LIF: @@ -384,10 +384,10 @@ ILboolean ILAPIENTRY ilIsValidF(ILenum Type, ILHANDLE File) return ilIsValidBmpF(File); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilIsValidGifF(File); - #endif + #endif*/ #ifndef IL_NO_LIF case IL_LIF: @@ -464,10 +464,10 @@ ILboolean ILAPIENTRY ilIsValidL(ILenum Type, ILvoid *Lump, ILuint Size) return ilIsValidBmpL(Lump, Size); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilIsValidGifL(Lump, Size); - #endif + #endif*/ #ifndef IL_NO_LIF case IL_LIF: @@ -552,10 +552,10 @@ ILboolean ILAPIENTRY ilLoad(ILenum Type, const ILstring FileName) return ilLoadBmp(FileName); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilLoadGif(FileName); - #endif + #endif*/ #ifndef IL_NO_CUT case IL_CUT: @@ -708,10 +708,10 @@ ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File) return ilLoadBmpF(File); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilLoadGifF(File); - #endif + #endif*/ #ifndef IL_NO_CUT case IL_CUT: @@ -795,6 +795,11 @@ ILboolean ILAPIENTRY ilLoadF(ILenum Type, ILHANDLE File) return ilLoadSgiF(File); #endif + #ifndef IL_NO_TIF + case IL_TIF: + return ilLoadTiffF(File); + #endif + #ifndef IL_NO_WAL case IL_WAL: return ilLoadWalF(File); @@ -851,10 +856,10 @@ ILboolean ILAPIENTRY ilLoadL(ILenum Type, ILvoid *Lump, ILuint Size) return ilLoadBmpL(Lump, Size); #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF case IL_GIF: return ilLoadGifL(Lump, Size); - #endif + #endif*/ #ifndef IL_NO_CUT case IL_CUT: @@ -1016,11 +1021,11 @@ ILboolean ILAPIENTRY ilLoadImage(const ILstring FileName) } #endif - #ifndef IL_NO_GIF + /*#ifndef IL_NO_GIF if (!iStrCmp(Ext, IL_TEXT("gif"))) { return ilLoadGif(FileName); } - #endif + #endif*/ #ifndef IL_NO_CUT if (!iStrCmp(Ext, IL_TEXT("cut"))) { @@ -1275,11 +1280,11 @@ ILuint ILAPIENTRY ilSaveF(ILenum Type, ILHANDLE File) break; #endif - #ifndef IL_NO_TIF + /*#ifndef IL_NO_TIF case IL_TIF: Ret = ilSaveTiffF(File); break; - #endif + #endif*/ default: ilSetError(IL_INVALID_ENUM); @@ -1346,11 +1351,11 @@ ILuint ILAPIENTRY ilSaveL(ILenum Type, ILvoid *Lump, ILuint Size) break; #endif - #ifndef IL_NO_TIF + /*#ifndef IL_NO_TIF case IL_TIF: Ret = ilSaveTiffL(Lump, Size); break; - #endif + #endif*/ default: ilSetError(IL_INVALID_ENUM); diff --git a/DevIL/src-IL/src/il_jpeg.c b/DevIL/src-IL/src/il_jpeg.c index 476c1df0..6dbb66f6 100644 --- a/DevIL/src-IL/src/il_jpeg.c +++ b/DevIL/src-IL/src/il_jpeg.c @@ -304,6 +304,7 @@ ILboolean iLoadJpegInternal() JpegInfo.err = jpeg_std_error( &Error ); // init standard error handlers Error.error_exit = iJpegErrorExit; // add our exit handler + Error.output_message = OutputMsg; if ( (result = setjmp( JpegJumpBuffer ) == 0) != IL_FALSE ) { diff --git a/DevIL/src-IL/src/il_manip.c b/DevIL/src-IL/src/il_manip.c index 1448cec9..e6f8dfa5 100644 --- a/DevIL/src-IL/src/il_manip.c +++ b/DevIL/src-IL/src/il_manip.c @@ -671,7 +671,7 @@ ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type) ILushort *AlphaShort; ILuint *AlphaInt; ILdouble *AlphaDbl; - ILuint i, j, Bpc, Size; + ILuint i, j, Bpc, Size, AlphaOff; Bpc = ilGetBppType(Type); if (Bpc == 0) { @@ -708,18 +708,23 @@ ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type) return Alpha; } + if (TempImage->Format == IL_LUMINANCE_ALPHA) + AlphaOff = 2; + else + AlphaOff = 4; + switch (TempImage->Type) { case IL_BYTE: case IL_UNSIGNED_BYTE: - for (i = 3, j = 0; i < Size; i += 4, j++) + for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++) Alpha[j] = TempImage->Data[i]; break; case IL_SHORT: case IL_UNSIGNED_SHORT: AlphaShort = (ILushort*)Alpha; - for (i = 3, j = 0; i < Size; i += 4, j++) + for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++) AlphaShort[j] = ((ILushort*)TempImage->Data)[i]; break; @@ -727,13 +732,13 @@ ILubyte* ILAPIENTRY ilGetAlpha(ILenum Type) case IL_UNSIGNED_INT: case IL_FLOAT: // Can throw float in here, because it's the same size. AlphaInt = (ILuint*)Alpha; - for (i = 3, j = 0; i < Size; i += 4, j++) + for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++) AlphaInt[j] = ((ILuint*)TempImage->Data)[i]; break; case IL_DOUBLE: AlphaDbl = (ILdouble*)Alpha; - for (i = 3, j = 0; i < Size; i += 4, j++) + for (i = AlphaOff-1, j = 0; i < Size; i += AlphaOff, j++) AlphaDbl[j] = ((ILdouble*)TempImage->Data)[i]; break; } diff --git a/DevIL/src-IL/src/il_mng.c b/DevIL/src-IL/src/il_mng.c index 62d5a98b..fc5bd33b 100644 --- a/DevIL/src-IL/src/il_mng.c +++ b/DevIL/src-IL/src/il_mng.c @@ -24,7 +24,7 @@ //--------------------------------------------------------------------------------------------- mng_ptr MNG_DECL mymngalloc(mng_size_t size) { - return (mng_ptr)calloc(1, size); + return (mng_ptr)icalloc(1, size); } diff --git a/DevIL/src-IL/src/il_neuquant.c b/DevIL/src-IL/src/il_neuquant.c index 514f5a6b..c69fa7b8 100644 --- a/DevIL/src-IL/src/il_neuquant.c +++ b/DevIL/src-IL/src/il_neuquant.c @@ -413,7 +413,7 @@ ILimage *iNeuQuant(ILimage *Image) learn(); unbiasnet(); - NewImage = (ILimage*)calloc(sizeof(ILimage), 1); + NewImage = (ILimage*)icalloc(sizeof(ILimage), 1); if (NewImage == NULL) { ilCloseImage(TempImage); return NULL; diff --git a/DevIL/src-IL/src/il_pal.c b/DevIL/src-IL/src/il_pal.c index cd3f2a68..db036fbb 100644 --- a/DevIL/src-IL/src/il_pal.c +++ b/DevIL/src-IL/src/il_pal.c @@ -589,14 +589,8 @@ ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat) if (NewPal == NULL) { return NULL; } - NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize); - if (NewPal->Palette == NULL) { - ifree(NewPal); - return IL_FALSE; - } NewPal->PalSize = Pal->PalSize; NewPal->PalType = Pal->PalType; - memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize); switch (DestFormat) { @@ -606,9 +600,9 @@ ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat) { case IL_PAL_RGB24: NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize); + if (NewPal->Palette == NULL) + goto alloc_error; if (DestFormat == IL_PAL_BGR24) { - if (NewPal->Palette == NULL) - goto alloc_error; j = ilGetBppPal(Pal->PalType); for (i = 0; i < Pal->PalSize; i += j) { NewPal->Palette[i] = Pal->Palette[i+2]; @@ -624,9 +618,9 @@ ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat) case IL_PAL_BGR24: NewPal->Palette = (ILubyte*)ialloc(Pal->PalSize); + if (NewPal->Palette == NULL) + goto alloc_error; if (DestFormat == IL_PAL_RGB24) { - if (NewPal->Palette == NULL) - goto alloc_error; j = ilGetBppPal(Pal->PalType); for (i = 0; i < Pal->PalSize; i += j) { NewPal->Palette[i] = Pal->Palette[i+2]; @@ -763,6 +757,9 @@ ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat) NewPal->Palette[i+3] = Pal->Palette[i+3]; } } + else { + memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize); + } NewPal->PalType = DestFormat; break; @@ -801,6 +798,9 @@ ILAPI ILpal* ILAPIENTRY iConvertPal(ILpal *Pal, ILenum DestFormat) NewPal->Palette[i+3] = Pal->Palette[i+3]; } } + else { + memcpy(NewPal->Palette, Pal->Palette, Pal->PalSize); + } NewPal->PalType = DestFormat; break; diff --git a/DevIL/src-IL/src/il_png.c b/DevIL/src-IL/src/il_png.c index 6c86bb8a..76ffa681 100644 --- a/DevIL/src-IL/src/il_png.c +++ b/DevIL/src-IL/src/il_png.c @@ -18,7 +18,7 @@ #include "il_manip.h" #if PNG_LIBPNG_VER < 10200 - //#warning DevIL was designed with libpng 1.2.0 or higher in mind. Consider upgrading at www.libpng.org + #warning DevIL was designed with libpng 1.2.0 or higher in mind. Consider upgrading at www.libpng.org #endif ILboolean iIsValidPng(ILvoid); @@ -204,14 +204,20 @@ static ILvoid png_read(png_structp png_ptr, png_bytep data, png_size_t length) } -static void png_error_warn(png_structp png_ptr, png_const_charp message) +static void png_error_func(png_structp png_ptr, png_const_charp message) +{ + ilSetError(IL_LIB_PNG_ERROR); + return; +} + +static void png_warn_func(png_structp png_ptr, png_const_charp message) { return; } ILint readpng_init() { - png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_warn, png_error_warn); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_func, png_warn_func); if (!png_ptr) return 4; /* out of memory */ @@ -236,8 +242,8 @@ ILint readpng_init() } - png_set_read_fn(png_ptr, NULL, &png_read); - png_set_error_fn(png_ptr, NULL, &png_error_warn, &png_error_warn); + png_set_read_fn(png_ptr, NULL, png_read); + png_set_error_fn(png_ptr, NULL, png_error_func, png_warn_func); // png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */ @@ -458,7 +464,7 @@ ILboolean iSavePngInternal() * the library version is compatible with the one used at compile time, * in case we are using dynamically linked libraries. REQUIRED. */ - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_warn, png_error_warn); + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error_func, png_warn_func); if (png_ptr == NULL) { ilSetError(IL_LIB_PNG_ERROR); return IL_FALSE; diff --git a/DevIL/src-IL/src/il_quantizer.c b/DevIL/src-IL/src/il_quantizer.c index e87e20cf..d5800ba7 100644 --- a/DevIL/src-IL/src/il_quantizer.c +++ b/DevIL/src-IL/src/il_quantizer.c @@ -541,7 +541,7 @@ ILimage *iQuantizeImage(ILimage *Image, ILuint NumCols) ifree(Ir); ilCloseImage(TempImage); - NewImage = (ILimage*)calloc(sizeof(ILimage), 1); + NewImage = (ILimage*)icalloc(sizeof(ILimage), 1); if (NewImage == NULL) { return NULL; } diff --git a/DevIL/src-IL/src/il_stack.c b/DevIL/src-IL/src/il_stack.c index eae85233..8ac9b663 100644 --- a/DevIL/src-IL/src/il_stack.c +++ b/DevIL/src-IL/src/il_stack.c @@ -532,7 +532,7 @@ ILboolean IsInit = IL_FALSE; // ONLY call at startup. ILvoid ILAPIENTRY ilInit() { - ilResetMemory(); // Do first, since it handles allocations. + ilSetMemory(NULL, NULL); // Do first, since it handles allocations. ilSetError(IL_NO_ERROR); ilDefaultStates(); // Set states to their defaults. // Sets default file-reading callbacks. @@ -610,7 +610,8 @@ ILAPI ILvoid ILAPIENTRY iBindImageTemp() if (!iEnlargeStack()) return; -// LastUsed = 1; + if (LastUsed <2 ) + LastUsed = 2; CurName = 1; ParentImage = IL_TRUE; if (!ImageStack[1]) diff --git a/DevIL/src-IL/src/il_states.c b/DevIL/src-IL/src/il_states.c index 167e0791..87eba2b1 100644 --- a/DevIL/src-IL/src/il_states.c +++ b/DevIL/src-IL/src/il_states.c @@ -17,7 +17,7 @@ #include <stdlib.h> const ILstring _ilVendor = IL_TEXT("Abysmal Software"); -const ILstring _ilVersion = IL_TEXT("Developer's Image Library (DevIL) 1.6.1"); +const ILstring _ilVersion = IL_TEXT("Developer's Image Library (DevIL) 1.6.5"); const ILstring _ilLoadExt = "" IL_BMP_EXT IL_CUT_EXT IL_DCX_EXT IL_DDS_EXT IL_GIF_EXT IL_ICO_EXT IL_JPG_EXT IL_LIF_EXT IL_MDL_EXT IL_MNG_EXT IL_PCX_EXT IL_PIC_EXT diff --git a/DevIL/src-IL/src/il_tiff.c b/DevIL/src-IL/src/il_tiff.c index 7376eb34..47687107 100644 --- a/DevIL/src-IL/src/il_tiff.c +++ b/DevIL/src-IL/src/il_tiff.c @@ -26,7 +26,7 @@ ILboolean iLoadTiffInternal(ILvoid); char* iMakeString(ILvoid); TIFF* iTIFFOpen(char *Mode); -ILboolean iSaveTiffInternal(ILvoid); +ILboolean iSaveTiffInternal(char *Filename); /*----------------------------------------------------------------------------*/ @@ -432,7 +432,8 @@ ILboolean ilSaveTiff(const ILstring FileName) return bTiff; } - bTiff = ilSaveTiffF(TiffFile); + //bTiff = ilSaveTiffF(TiffFile); + bTiff = iSaveTiffInternal(FileName); iclosew(TiffFile); return bTiff; @@ -442,23 +443,27 @@ ILboolean ilSaveTiff(const ILstring FileName) //! Writes a Tiff to an already-opened file ILboolean ilSaveTiffF(ILHANDLE File) { - iSetOutputFile(File); - return iSaveTiffInternal(); +// iSetOutputFile(File); +// return iSaveTiffInternal(); + ilSetError(IL_FILE_READ_ERROR); + return IL_FALSE; } //! Writes a Tiff to a memory "lump" ILboolean ilSaveTiffL(ILvoid *Lump, ILuint Size) { - iSetOutputLump(Lump, Size); - return iSaveTiffInternal(); +// iSetOutputLump(Lump, Size); +// return iSaveTiffInternal(); + ilSetError(IL_FILE_READ_ERROR); + return IL_FALSE; } // @TODO: Accept palettes! // Internal function used to save the Tiff. -ILboolean iSaveTiffInternal() +ILboolean iSaveTiffInternal(char *Filename) { ILenum Format; ILenum Compression; @@ -491,8 +496,8 @@ ILboolean iSaveTiffInternal() TempImage = iCurImage; } - //File = TIFFOpen(FileName, "w"); - File = iTIFFOpen("w"); + File = TIFFOpen(Filename, "w"); + //File = iTIFFOpen("w"); if (File == NULL) { ilSetError(IL_COULD_NOT_OPEN_FILE); return IL_FALSE; @@ -523,7 +528,7 @@ ILboolean iSaveTiffInternal() TIFFSetField(File, TIFFTAG_IMAGEDESCRIPTION, iGetString(IL_TIF_DESCRIPTION_STRING)); TIFFSetField(File, TIFFTAG_DATETIME, iMakeString()); - + TIFFSetField(File, TIFFTAG_ORIENTATION, TempImage->Origin == IL_ORIGIN_UPPER_LEFT ? ORIENTATION_TOPLEFT : ORIENTATION_BOTLEFT); diff --git a/DevIL/src-IL/src/il_utility.c b/DevIL/src-IL/src/il_utility.c index 071c9cc6..54973c30 100644 --- a/DevIL/src-IL/src/il_utility.c +++ b/DevIL/src-IL/src/il_utility.c @@ -23,6 +23,8 @@ ILAPI ILubyte ILAPIENTRY ilGetBppFormat(ILenum Format) return 1; case IL_LUMINANCE: return 1; + case IL_LUMINANCE_ALPHA: + return 2; case IL_RGB: return 3; case IL_BGR: diff --git a/DevIL/src-IL/src/il_wal.c b/DevIL/src-IL/src/il_wal.c index a4b89ef9..7e8d1053 100644 --- a/DevIL/src-IL/src/il_wal.c +++ b/DevIL/src-IL/src/il_wal.c @@ -92,7 +92,7 @@ ILboolean iLoadWalInternal() return IL_FALSE; for (i = 0; i < 3; i++) { - Mipmaps[i] = (ILimage*)calloc(sizeof(ILimage), 1); + Mipmaps[i] = (ILimage*)icalloc(sizeof(ILimage), 1); if (Mipmaps[i] == NULL) goto cleanup_error; Mipmaps[i]->Pal.Palette = (ILubyte*)ialloc(768); diff --git a/DevIL/src-ILU/include/ilu_internal.h b/DevIL/src-ILU/include/ilu_internal.h index 435b9e87..b93c3235 100644 --- a/DevIL/src-ILU/include/ilu_internal.h +++ b/DevIL/src-ILU/include/ilu_internal.h @@ -82,6 +82,7 @@ ILfloat ilCos(ILfloat Angle); ILfloat ilSin(ILfloat Angle); ILint ilRound(ILfloat Num); ILuint iluScaleAdvanced(ILuint Width, ILuint Height, ILenum Filter); +ILubyte *iScanFill(ILvoid); #endif//INTERNAL_H diff --git a/DevIL/src-ILU/msvc/ILU.dsp b/DevIL/src-ILU/msvc/ILU.dsp index de940d03..ac3e3f3f 100644 --- a/DevIL/src-ILU/msvc/ILU.dsp +++ b/DevIL/src-ILU/msvc/ILU.dsp @@ -173,6 +173,10 @@ SOURCE=..\src\ilu_noise.c # End Source File # Begin Source File +SOURCE=..\src\ilu_region.c +# End Source File +# Begin Source File + SOURCE=..\src\ilu_rotate.c # End Source File # Begin Source File @@ -221,6 +225,10 @@ SOURCE=..\include\ilu_mipmap.h # End Source File # Begin Source File +SOURCE=..\include\ilu_region.h +# End Source File +# Begin Source File + SOURCE=..\include\ilu_states.h # End Source File # End Group diff --git a/DevIL/src-ILU/msvc/ILU.rc b/DevIL/src-ILU/msvc/ILU.rc index 50ee36d6..a836c1ef 100644 --- a/DevIL/src-ILU/msvc/ILU.rc +++ b/DevIL/src-ILU/msvc/ILU.rc @@ -60,8 +60,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,6,1 - PRODUCTVERSION 0,1,6,1 + FILEVERSION 0,1,6,5 + PRODUCTVERSION 0,1,6,5 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x29L @@ -76,17 +76,17 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "ILU: A great portable image library in development\0" + VALUE "Comments", "ILU: A portable image library in development\0" VALUE "CompanyName", "Abysmal Software\0" - VALUE "FileDescription", "ILU: A great portable image library in development\0" - VALUE "FileVersion", "1.6.1\0" + VALUE "FileDescription", "ILU: A portable image library in development\0" + VALUE "FileVersion", "1.6.5\0" VALUE "InternalName", "ILU\0" VALUE "LegalCopyright", "Copyright © 2000-2002\0" VALUE "LegalTrademarks", "Under LGPL License\0" VALUE "OriginalFilename", "ILU.dll\0" VALUE "PrivateBuild", "Open Source\0" VALUE "ProductName", "Developer's Image Utilities Library\0" - VALUE "ProductVersion", "1.6.1\0" + VALUE "ProductVersion", "1.6.5\0" VALUE "SpecialBuild", "eh?\0" END END @@ -115,7 +115,7 @@ IDI_ICON1 ICON DISCARDABLE "resources\\IL Logo.ico" STRINGTABLE DISCARDABLE BEGIN - IDC_OPENILU "Developer's Image Utilities Library, Version 1.6.1" + IDC_OPENILU "Developer's Image Utilities Library, Version 1.6.5" END #endif // English (U.S.) resources diff --git a/DevIL/src-ILU/msvc/ilu.def b/DevIL/src-ILU/msvc/ilu.def index 5223dd31..bc3dc4e7 100644 --- a/DevIL/src-ILU/msvc/ilu.def +++ b/DevIL/src-ILU/msvc/ilu.def @@ -33,6 +33,8 @@ iluMirror iluNegative iluNoisify iluPixelize +iluRegionfv +iluRegioniv iluReplaceColour iluRotate iluRotate3D diff --git a/DevIL/src-ILU/src/Makefile.am b/DevIL/src-ILU/src/Makefile.am index ec704bfd..20a73d09 100644 --- a/DevIL/src-ILU/src/Makefile.am +++ b/DevIL/src-ILU/src/Makefile.am @@ -5,7 +5,7 @@ libILU_la_SOURCES = ilu_alloc.c ilu_internal.c ilu_noise.c \ ilu_rotate.c ilu_scaling.c ilu_filter.c \ ilu_manip.c ilu_scale2d.c ilu_states.c \ ilu_filter_rcg.c ilu_mipmap.c ilu_scale3d.c \ - ilu_utilities.c + ilu_utilities.c ilu_region.c CFLAGS = @LIBILU_CFLAGS@ diff --git a/DevIL/src-ILU/src/Makefile.in b/DevIL/src-ILU/src/Makefile.in index e564e868..de18fdc4 100644 --- a/DevIL/src-ILU/src/Makefile.in +++ b/DevIL/src-ILU/src/Makefile.in @@ -98,7 +98,7 @@ sdl_config = @sdl_config@ lib_LTLIBRARIES = libILU.la -libILU_la_SOURCES = ilu_alloc.c ilu_internal.c ilu_noise.c ilu_scale.c ilu_error.c ilu_main.c ilu_rotate.c ilu_scaling.c ilu_filter.c ilu_manip.c ilu_scale2d.c ilu_states.c ilu_filter_rcg.c ilu_mipmap.c ilu_scale3d.c ilu_utilities.c +libILU_la_SOURCES = ilu_alloc.c ilu_internal.c ilu_noise.c ilu_scale.c ilu_error.c ilu_main.c ilu_rotate.c ilu_scaling.c ilu_filter.c ilu_manip.c ilu_scale2d.c ilu_states.c ilu_filter_rcg.c ilu_mipmap.c ilu_scale3d.c ilu_utilities.c ilu_region.c CFLAGS = @LIBILU_CFLAGS@ @@ -125,7 +125,7 @@ libILU_la_DEPENDENCIES = libILU_la_OBJECTS = ilu_alloc.lo ilu_internal.lo ilu_noise.lo \ ilu_scale.lo ilu_error.lo ilu_main.lo ilu_rotate.lo ilu_scaling.lo \ ilu_filter.lo ilu_manip.lo ilu_scale2d.lo ilu_states.lo \ -ilu_filter_rcg.lo ilu_mipmap.lo ilu_scale3d.lo ilu_utilities.lo +ilu_filter_rcg.lo ilu_mipmap.lo ilu_scale3d.lo ilu_utilities.lo ilu_region.lo COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) diff --git a/DevIL/src-ILU/src/ilu_filter.c b/DevIL/src-ILU/src/ilu_filter.c index 391d454e..4d2ef77e 100644 --- a/DevIL/src-ILU/src/ilu_filter.c +++ b/DevIL/src-ILU/src/ilu_filter.c @@ -21,10 +21,11 @@ //! Pixelizes an image ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) { - ILuint x, y, z, i, j, k, c, Total, Tested; + ILuint x, y, z, i, j, k, c, r, Total, Tested; ILushort *ShortPtr; ILuint *IntPtr; ILdouble *DblPtr, DblTotal, DblTested; + ILubyte *RegionMask; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -32,9 +33,15 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) return IL_FALSE; } + if (PixSize == 0) + PixSize = 1; + r = 0; + if (iluCurImage->Format == IL_COLOUR_INDEX) ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); + RegionMask = iScanFill(); + switch (iluCurImage->Bpc) { case 1: @@ -56,6 +63,10 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { for (j = 0; j < PixSize && y+j < iluCurImage->Height; j++) { for (i = 0; i < PixSize && x+i < iluCurImage->Width; i++, Tested++) { + if (RegionMask) { + if (!RegionMask[(y+j) * iluCurImage->Width + (x+i)]) + continue; + } iluCurImage->Data[(z+k) * iluCurImage->SizeOfPlane + (y+j) * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = Total; @@ -72,7 +83,7 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) iluCurImage->Bps /= 2; for (z = 0; z < iluCurImage->Depth; z += PixSize) { for (y = 0; y < iluCurImage->Height; y += PixSize) { - for (x = 0; x < iluCurImage->Width; x += PixSize) { + for (x = 0; x < iluCurImage->Width; x += PixSize, r += PixSize) { for (c = 0; c < iluCurImage->Bpp; c++) { Total = 0; Tested = 0; for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { @@ -88,9 +99,11 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { for (j = 0; j < PixSize && y+j < iluCurImage->Height; j++) { for (i = 0; i < PixSize && x+i < iluCurImage->Width; i++, Tested++) { - ShortPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) - * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = - Total; + if (RegionMask[r+i]) { + ShortPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) + * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = + Total; + } } } } @@ -105,7 +118,7 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) iluCurImage->Bps /= 4; for (z = 0; z < iluCurImage->Depth; z += PixSize) { for (y = 0; y < iluCurImage->Height; y += PixSize) { - for (x = 0; x < iluCurImage->Width; x += PixSize) { + for (x = 0; x < iluCurImage->Width; x += PixSize, r += PixSize) { for (c = 0; c < iluCurImage->Bpp; c++) { Total = 0; Tested = 0; for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { @@ -121,9 +134,11 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { for (j = 0; j < PixSize && y+j < iluCurImage->Height; j++) { for (i = 0; i < PixSize && x+i < iluCurImage->Width; i++, Tested++) { - IntPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) - * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = - Total; + if (RegionMask[r+i]) { + IntPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) + * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = + Total; + } } } } @@ -138,7 +153,7 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) iluCurImage->Bps /= 8; for (z = 0; z < iluCurImage->Depth; z += PixSize) { for (y = 0; y < iluCurImage->Height; y += PixSize) { - for (x = 0; x < iluCurImage->Width; x += PixSize) { + for (x = 0; x < iluCurImage->Width; x += PixSize, r += PixSize) { for (c = 0; c < iluCurImage->Bpp; c++) { DblTotal = 0.0; DblTested = 0.0; for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { @@ -154,9 +169,11 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) for (k = 0; k < PixSize && z+k < iluCurImage->Depth; k++) { for (j = 0; j < PixSize && y+j < iluCurImage->Height; j++) { for (i = 0; i < PixSize && x+i < iluCurImage->Width; i++, DblTested++) { - DblPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) - * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = - DblTotal; + if (RegionMask[r+i]) { + DblPtr[(z+k) * iluCurImage->SizeOfPlane + (y+j) + * iluCurImage->Bps + (x+i) * iluCurImage->Bpp + c] = + DblTotal; + } } } } @@ -168,6 +185,8 @@ ILboolean ILAPIENTRY iluPixelize(ILuint PixSize) break; } + ifree(RegionMask); + return IL_TRUE; } @@ -182,7 +201,7 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) { ILint x, y, c, LastX, LastY, Offsets[9]; ILuint i, Temp, z; - ILubyte *Data, *ImgData, *NewData; + ILubyte *Data, *ImgData, *NewData, *RegionMask; ILdouble Num; if (Image == NULL) { @@ -195,6 +214,8 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) return NULL; } + RegionMask = iScanFill(); + Filt *= 11; // Preserve original data. ImgData = Image->Data; @@ -205,11 +226,20 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) LastY = Image->Height - 1; for (y = 1; y < LastY; y++) { for (x = 1; x < LastX; x++) { + Offsets[4] = ((y ) * Image->Width + (x )) * Image->Bpp; + if (RegionMask) { + if (!RegionMask[y * Image->Width + x]) { + for (c = 0; c < Image->Bpp; c++) { + Data[Offsets[4]+c] = Image->Data[Offsets[4]+c]; + } + continue; + } + } + Offsets[0] = ((y-1) * Image->Width + (x-1)) * Image->Bpp; Offsets[1] = ((y-1) * Image->Width + (x )) * Image->Bpp; Offsets[2] = ((y-1) * Image->Width + (x+1)) * Image->Bpp; Offsets[3] = ((y ) * Image->Width + (x-1)) * Image->Bpp; - Offsets[4] = ((y ) * Image->Width + (x )) * Image->Bpp; Offsets[5] = ((y ) * Image->Width + (x+1)) * Image->Bpp; Offsets[6] = ((y+1) * Image->Width + (x-1)) * Image->Bpp; Offsets[7] = ((y+1) * Image->Width + (x )) * Image->Bpp; @@ -269,6 +299,12 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) // First row for (x = 1; x < (ILint)Image->Width-1; x++) { + if (RegionMask) { + if (!RegionMask[x]) { + Data[y + x * Image->Bpp + c] = Image->Data[y + x * Image->Bpp + c]; + continue; + } + } for (c = 0; c < Image->Bpp; c++) { Num = Image->Data[(x-1) * Image->Bpp + c] * Filters[Filt] + Image->Data[x * Image->Bpp + c] * Filters[Filt+1]+ @@ -291,6 +327,12 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) // Last row y = (Image->Height - 1) * Image->Bps; for (x = 1; x < (ILint)Image->Width-1; x++) { + if (RegionMask) { + if (!RegionMask[(Image->Height - 1) * Image->Width + x]) { + Data[y + x * Image->Bpp + c] = Image->Data[y + x * Image->Bpp + c]; + continue; + } + } for (c = 0; c < Image->Bpp; c++) { Num = Image->Data[y - Image->Bps + (x-1) * Image->Bpp + c] * Filters[Filt] + Image->Data[y - Image->Bps + x * Image->Bpp + c] * Filters[Filt+1]+ @@ -312,6 +354,12 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) // Left side for (i = 1, y = Image->Bps; i < Image->Height-1; i++, y += Image->Bps) { + if (RegionMask) { + if (!RegionMask[y / Image->Bpp]) { + Data[y + c] = Image->Data[y + c]; + continue; + } + } for (c = 0; c < Image->Bpp; c++) { Num = Image->Data[y - Image->Bps + c] * Filters[Filt] + Image->Data[y - Image->Bps + Image->Bpp + c] * Filters[Filt+1]+ @@ -333,6 +381,14 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) // Right side for (i = 1, y = Image->Bps * 2 - Image->Bpp; i < Image->Height-1; i++, y += Image->Bps) { + if (RegionMask) { + if (!RegionMask[y / Image->Bpp + (Image->Width - 1)]) { + for (c = 0; c < Image->Bpp; c++) { + Data[y + c] = Image->Data[y + c]; + } + continue; + } + } for (c = 0; c < Image->Bpp; c++) { Num = Image->Data[y - Image->Bps + c] * Filters[Filt] + Image->Data[y - Image->Bps + Image->Bpp + c] * Filters[Filt+1]+ @@ -357,6 +413,8 @@ ILubyte *Filter(ILimage *Image, ILushort Filt) Data += Image->SizeOfPlane; } + ifree(RegionMask); + // Restore original data. Image->Data = ImgData; Data = NewData; @@ -369,7 +427,8 @@ ILboolean ILAPIENTRY iluEdgeDetectP() { ILubyte *HPass, *VPass; ILuint i; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -381,11 +440,20 @@ ILboolean ILAPIENTRY iluEdgeDetectP() Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } + HPass = Filter(iluCurImage, 4); VPass = Filter(iluCurImage, 5); - if (!HPass || !VPass) + if (!HPass || !VPass) { + ifree(HPass); + ifree(VPass); return IL_FALSE; + } // Combine the two passes // Optimization by Matt Denham @@ -407,6 +475,8 @@ ILboolean ILAPIENTRY iluEdgeDetectP() if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -416,7 +486,8 @@ ILboolean ILAPIENTRY iluEdgeDetectS() { ILubyte *HPass, *VPass; ILuint i; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -428,11 +499,19 @@ ILboolean ILAPIENTRY iluEdgeDetectS() Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } HPass = Filter(iluCurImage, 2); VPass = Filter(iluCurImage, 3); - if (!HPass || !VPass) + if (!HPass || !VPass) { + ifree(HPass); + ifree(VPass); return IL_FALSE; + } // Combine the two passes // Optimization by Matt Denham @@ -454,6 +533,8 @@ ILboolean ILAPIENTRY iluEdgeDetectS() if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -463,7 +544,8 @@ ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter) { ILubyte *Data; ILuint i; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -475,6 +557,11 @@ ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter) Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } for (i = 0; i < Iter; i++) { Data = Filter(iluCurImage, 0); @@ -486,6 +573,8 @@ ILboolean ILAPIENTRY iluBlurAvg(ILuint Iter) if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -495,7 +584,8 @@ ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter) { ILubyte *Data; ILuint i; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -507,6 +597,11 @@ ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter) Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } for (i = 0; i < Iter; i++) { Data = Filter(iluCurImage, 1); @@ -518,6 +613,8 @@ ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter) if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -526,7 +623,8 @@ ILboolean ILAPIENTRY iluBlurGaussian(ILuint Iter) ILboolean ILAPIENTRY iluEmboss() { ILubyte *Data; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -538,6 +636,11 @@ ILboolean ILAPIENTRY iluEmboss() Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } Data = Filter(iluCurImage, 6); if (!Data) @@ -547,6 +650,8 @@ ILboolean ILAPIENTRY iluEmboss() if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -586,7 +691,8 @@ ILboolean ILAPIENTRY iluEmboss() ILboolean ILAPIENTRY iluEdgeDetectE() { ILubyte *Data; - ILboolean Palette = IL_FALSE; + ILboolean Palette = IL_FALSE, Converted = IL_FALSE; + ILenum Type; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -598,6 +704,11 @@ ILboolean ILAPIENTRY iluEdgeDetectE() Palette = IL_TRUE; ilConvertImage(ilGetPalBaseType(iluCurImage->Pal.PalType), IL_UNSIGNED_BYTE); } + else if (iluCurImage->Type > IL_UNSIGNED_BYTE) { + Converted = IL_TRUE; + Type = iluCurImage->Type; + ilConvertImage(iluCurImage->Format, IL_UNSIGNED_BYTE); + } Data = Filter(iluCurImage, 7); if (!Data) @@ -607,6 +718,8 @@ ILboolean ILAPIENTRY iluEdgeDetectE() if (Palette) ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); + else if (Converted) + ilConvertImage(iluCurImage->Format, Type); return IL_TRUE; } @@ -1121,3 +1234,4 @@ ILboolean ILAPIENTRY iluSharpen(ILfloat Factor, ILuint Iter) return IL_TRUE; } + diff --git a/DevIL/src-ILU/src/ilu_filter_rcg.c b/DevIL/src-ILU/src/ilu_filter_rcg.c index e4a8e600..24668654 100644 --- a/DevIL/src-ILU/src/ilu_filter_rcg.c +++ b/DevIL/src-ILU/src/ilu_filter_rcg.c @@ -368,7 +368,7 @@ int i; /* ILubyte column in source bitmap being processed */ fscale = 1.0 / xscale; contribX->n = 0; - contribX->p = (CONTRIB *)calloc((int) (width * 2 + 1), + contribX->p = (CONTRIB *)icalloc((int) (width * 2 + 1), sizeof(CONTRIB)); if (contribX->p == NULL) { return -1; @@ -398,7 +398,7 @@ int i; /* ILubyte column in source bitmap being processed */ { /* Expanding image */ contribX->n = 0; - contribX->p = (CONTRIB *)calloc((int) (fwidth * 2 + 1), + contribX->p = (CONTRIB*)icalloc((int) (fwidth * 2 + 1), sizeof(CONTRIB)); if (contribX->p == NULL) { return -1; @@ -461,7 +461,7 @@ double fwidth; /* Build y weights */ /* pre-calculate filter contributions for a column */ - contribY = (CLIST *)calloc(dst->Height, sizeof(CLIST)); + contribY = (CLIST*)icalloc(dst->Height, sizeof(CLIST)); if (contribY == NULL) { ifree(tmp); return -1; @@ -476,7 +476,7 @@ double fwidth; for(i = 0; i < (ILint)dst->Height; ++i) { contribY[i].n = 0; - contribY[i].p = (CONTRIB*)calloc((int) (width * 2 + 1), + contribY[i].p = (CONTRIB*)icalloc((int) (width * 2 + 1), sizeof(CONTRIB)); if(contribY[i].p == NULL) { ifree(tmp); @@ -504,7 +504,7 @@ double fwidth; } else { for(i = 0; i < (ILint)dst->Height; ++i) { contribY[i].n = 0; - contribY[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1), + contribY[i].p = (CONTRIB*)icalloc((int) (fwidth * 2 + 1), sizeof(CONTRIB)); if (contribY[i].p == NULL) { ifree(tmp); diff --git a/DevIL/src-ILU/src/ilu_manip.c b/DevIL/src-ILU/src/ilu_manip.c index af018faa..978ed38a 100644 --- a/DevIL/src-ILU/src/ilu_manip.c +++ b/DevIL/src-ILU/src/ilu_manip.c @@ -468,9 +468,10 @@ ILboolean ILAPIENTRY iluInvertAlpha() //! Inverts the colours in the image ILboolean ILAPIENTRY iluNegative() { - ILuint i, j, *IntPtr, NumPix; + ILuint i, j, c, *IntPtr, NumPix, Bpp; ILubyte *Data; ILushort *ShortPtr; + ILubyte *RegionMask; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -491,32 +492,72 @@ ILboolean ILAPIENTRY iluNegative() i = iluCurImage->SizeOfData; } + RegionMask = iScanFill(); // @TODO: Optimize this some. NumPix = i / iluCurImage->Bpc; - switch (iluCurImage->Bpc) - { - case 1: - for (j = 0; j < NumPix; j++, Data++) { - *(Data) = ~*(Data); - } - break; + Bpp = iluCurImage->Bpp; - case 2: - ShortPtr = (ILushort*)Data; - for (j = 0; j < NumPix; j++, ShortPtr++) { - *(ShortPtr) = ~*(ShortPtr); - } - break; + if (RegionMask) { + switch (iluCurImage->Bpc) + { + case 1: + for (j = 0, i = 0; j < NumPix; j += Bpp, i++, Data += Bpp) { + for (c = 0; c < Bpp; c++) { + if (RegionMask[i]) + *(Data+c) = ~*(Data+c); + } + } + break; - case 4: - IntPtr = (ILuint*)Data; - for (j = 0; j < NumPix; j++, IntPtr++) { - *(IntPtr) = ~*(IntPtr); - } - break; + case 2: + ShortPtr = (ILushort*)Data; + for (j = 0, i = 0; j < NumPix; j += Bpp, i++, ShortPtr += Bpp) { + for (c = 0; c < Bpp; c++) { + if (RegionMask[i]) + *(ShortPtr+c) = ~*(ShortPtr+c); + } + } + break; + + case 4: + IntPtr = (ILuint*)Data; + for (j = 0, i = 0; j < NumPix; j += Bpp, i++, IntPtr += Bpp) { + for (c = 0; c < Bpp; c++) { + if (RegionMask[i]) + *(IntPtr+c) = ~*(IntPtr+c); + } + } + break; + } } + else { + switch (iluCurImage->Bpc) + { + case 1: + for (j = 0; j < NumPix; j++, Data++) { + *(Data) = ~*(Data); + } + break; + + case 2: + ShortPtr = (ILushort*)Data; + for (j = 0; j < NumPix; j++, ShortPtr++) { + *(ShortPtr) = ~*(ShortPtr); + } + break; + + case 4: + IntPtr = (ILuint*)Data; + for (j = 0; j < NumPix; j++, IntPtr++) { + *(IntPtr) = ~*(IntPtr); + } + break; + } + } + + ifree(RegionMask); return IL_TRUE; } @@ -848,7 +889,7 @@ ILboolean ILAPIENTRY iluEqualize() ILuint i = 0; // index variable ILuint j = 0; // index variable ILuint Sum=0; - ILuint NumPixels; + ILuint NumPixels, Bpp; ILint Intensity; ILfloat Scale; ILint IntensityNew; @@ -865,13 +906,20 @@ ILboolean ILAPIENTRY iluEqualize() return 0; } - NumPixels = iluCurImage->Width * iluCurImage->Height * iluCurImage->Depth; - // @TODO: Change to work with other types! - /*if (iluCurImage->Bpc > 1) { - ilSetError(IL_ILLEGAL_OPERATION); + if (iluCurImage->Bpc > 1) { + ilSetError(ILU_INTERNAL_ERROR); return IL_FALSE; - }*/ + } + + if (iluCurImage->Format == IL_COLOUR_INDEX) { + NumPixels = iluCurImage->Pal.PalSize / ilGetBppPal(iluCurImage->Pal.PalType); + Bpp = ilGetBppPal(iluCurImage->Pal.PalType); + } + else { + NumPixels = iluCurImage->Width * iluCurImage->Height * iluCurImage->Depth; + Bpp = iluCurImage->Bpp; + } // Clear the tables. memset(Histogram, 0, 256 * sizeof(ILuint)); @@ -893,8 +941,6 @@ ILboolean ILAPIENTRY iluEqualize() Sum = 0; } - if (iluCurImage->Format == IL_COLOUR_INDEX) - NumPixels = iluCurImage->Pal.PalSize / ilGetBppPal(iluCurImage->Pal.PalType); BytePtr = (iluCurImage->Format == IL_COLOUR_INDEX) ? iluCurImage->Pal.Palette : iluCurImage->Data; ShortPtr = (ILushort*)iluCurImage->Data; @@ -913,26 +959,32 @@ ILboolean ILAPIENTRY iluEqualize() switch (iluCurImage->Bpc) { case 1: - // Calculate new pixel + // Calculate new pixel(s) NewColour[0] = (ILuint)(BytePtr[i * iluCurImage->Bpp] * Scale); - NewColour[1] = (ILuint)(BytePtr[i * iluCurImage->Bpp + 1] * Scale); - NewColour[2] = (ILuint)(BytePtr[i * iluCurImage->Bpp + 2] * Scale); + if (Bpp >= 3) { + NewColour[1] = (ILuint)(BytePtr[i * iluCurImage->Bpp + 1] * Scale); + NewColour[2] = (ILuint)(BytePtr[i * iluCurImage->Bpp + 2] * Scale); + } // Clamp values if (NewColour[0] > UCHAR_MAX) NewColour[0] = UCHAR_MAX; - if (NewColour[1] > UCHAR_MAX) - NewColour[1] = UCHAR_MAX; - if (NewColour[2] > UCHAR_MAX) - NewColour[2] = UCHAR_MAX; + if (Bpp >= 3) { + if (NewColour[1] > UCHAR_MAX) + NewColour[1] = UCHAR_MAX; + if (NewColour[2] > UCHAR_MAX) + NewColour[2] = UCHAR_MAX; + } - // Store pixel - BytePtr[i * iluCurImage->Bpp] = (ILubyte)NewColour[0]; - BytePtr[i * iluCurImage->Bpp + 1] = (ILubyte)NewColour[1]; - BytePtr[i * iluCurImage->Bpp + 2] = (ILubyte)NewColour[2]; + // Store pixel(s) + BytePtr[i * iluCurImage->Bpp] = (ILubyte)NewColour[0]; + if (Bpp >= 3) { + BytePtr[i * iluCurImage->Bpp + 1] = (ILubyte)NewColour[1]; + BytePtr[i * iluCurImage->Bpp + 2] = (ILubyte)NewColour[2]; + } break; - case 2: + /*case 2: // Calculate new pixel NewColour[0] = (ILuint)(ShortPtr[i * iluCurImage->Bpp] * Scale); NewColour[1] = (ILuint)(ShortPtr[i * iluCurImage->Bpp + 1] * Scale); @@ -970,7 +1022,7 @@ ILboolean ILAPIENTRY iluEqualize() IntPtr[i * 4 * iluCurImage->Bpp] = NewColour[0]; IntPtr[i * 4 * iluCurImage->Bpp + 1] = NewColour[1]; IntPtr[i * 4 * iluCurImage->Bpp + 2] = NewColour[2]; - break; + break;*/ } } diff --git a/DevIL/src-ILU/src/ilu_noise.c b/DevIL/src-ILU/src/ilu_noise.c index 9e3509e5..c094be76 100644 --- a/DevIL/src-ILU/src/ilu_noise.c +++ b/DevIL/src-ILU/src/ilu_noise.c @@ -21,10 +21,11 @@ // This will probably use Perlin noise and parameters in the future. ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) { - ILuint i, c, Factor, Factor2, NumPix; + ILuint i, j, c, Factor, Factor2, NumPix; ILint Val; ILushort *ShortPtr; ILuint *IntPtr; + ILubyte *RegionMask; iluCurImage = ilGetCurImage(); if (iluCurImage == NULL) { @@ -32,6 +33,8 @@ ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) return IL_FALSE; } + RegionMask = iScanFill(); + // @TODO: Change this to work correctly without time()! //srand(time(NULL)); NumPix = iluCurImage->SizeOfData / iluCurImage->Bpc; @@ -43,7 +46,11 @@ ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) if (Factor == 0) return IL_TRUE; Factor2 = Factor + Factor; - for (i = 0; i < NumPix; i += iluCurImage->Bpp) { + for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { + if (RegionMask) { + if (!RegionMask[j]) + continue; + } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if ((ILint)iluCurImage->Data[i + c] + Val > UCHAR_MAX) @@ -61,7 +68,11 @@ ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) return IL_TRUE; Factor2 = Factor + Factor; ShortPtr = (ILushort*)iluCurImage->Data; - for (i = 0; i < NumPix; i += iluCurImage->Bpp) { + for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { + if (RegionMask) { + if (!RegionMask[j]) + continue; + } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if ((ILint)ShortPtr[i + c] + Val > USHRT_MAX) @@ -79,7 +90,11 @@ ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) return IL_TRUE; Factor2 = Factor + Factor; IntPtr = (ILuint*)iluCurImage->Data; - for (i = 0; i < NumPix; i += iluCurImage->Bpp) { + for (i = 0, j = 0; i < NumPix; i += iluCurImage->Bpp, j++) { + if (RegionMask) { + if (!RegionMask[j]) + continue; + } Val = (ILint)((ILint)(rand() % Factor2) - Factor); for (c = 0; c < iluCurImage->Bpp; c++) { if (IntPtr[i + c] + Val > UINT_MAX) @@ -93,6 +108,8 @@ ILboolean ILAPIENTRY iluNoisify(ILclampf Tolerance) break; } + ifree(RegionMask); + return IL_TRUE; } diff --git a/DevIL/src-ILU/src/ilu_rotate.c b/DevIL/src-ILU/src/ilu_rotate.c index 7fec2beb..c4ce32d2 100644 --- a/DevIL/src-ILU/src/ilu_rotate.c +++ b/DevIL/src-ILU/src/ilu_rotate.c @@ -92,7 +92,7 @@ ILAPI ILimage* ILAPIENTRY iluRotate_(ILimage *Image, ILfloat Angle) ILushort *ShortPtr; ILuint *IntPtr; - Rotated = (ILimage*)calloc(1, sizeof(ILimage)); + Rotated = (ILimage*)icalloc(1, sizeof(ILimage)); if (Rotated == NULL) return NULL; if (ilCopyImageAttr(Rotated, Image) == IL_FALSE) { diff --git a/DevIL/src-ILU/src/ilu_scale.c b/DevIL/src-ILU/src/ilu_scale.c index 6d35fe32..8201ff9b 100644 --- a/DevIL/src-ILU/src/ilu_scale.c +++ b/DevIL/src-ILU/src/ilu_scale.c @@ -98,7 +98,7 @@ ILAPI ILimage* ILAPIENTRY iluScale_(ILimage *Image, ILuint Width, ILuint Height, } // So we don't replicate this 3 times (one in each iluScalexD_() function. - Scaled = (ILimage*)calloc(1, sizeof(ILimage)); + Scaled = (ILimage*)icalloc(1, sizeof(ILimage)); if (ilCopyImageAttr(Scaled, ToScale) == IL_FALSE) { ilCloseImage(Scaled); if (ToScale != Image) diff --git a/DevIL/src-ILU/src/ilu_scaling.c b/DevIL/src-ILU/src/ilu_scaling.c index b62a9f3d..316d7c71 100644 --- a/DevIL/src-ILU/src/ilu_scaling.c +++ b/DevIL/src-ILU/src/ilu_scaling.c @@ -247,13 +247,13 @@ double fwidth; /* filter width (support) */ yscale = (double) dst->ysize / (double) src->ysize; /* pre-calculate filter contributions for a row */ - contrib = (CLIST *)calloc(dst->xsize, sizeof(CLIST)); + contrib = (CLIST*)icalloc(dst->xsize, sizeof(CLIST)); if(xscale < 1.0) { width = fwidth / xscale; fscale = 1.0 / xscale; for(i = 0; i < dst->xsize; ++i) { contrib[i].n = 0; - contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1), + contrib[i].p = (CONTRIB*)icalloc((int) (width * 2 + 1), sizeof(CONTRIB)); center = (double) i / xscale; left = ceil(center - width); @@ -276,8 +276,7 @@ double fwidth; /* filter width (support) */ } else { for(i = 0; i < dst->xsize; ++i) { contrib[i].n = 0; - contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1), - sizeof(CONTRIB)); + contrib[i].p = (CONTRIB*)icalloc((int) (fwidth * 2 + 1), sizeof(CONTRIB)); center = (double) i / xscale; left = ceil(center - fwidth); right = floor(center + fwidth); @@ -299,7 +298,7 @@ double fwidth; /* filter width (support) */ } /* apply filter to zoom horizontally from src to tmp */ - raster = (Pixel *)calloc(src->xsize, sizeof(Pixel)); + raster = (Pixel*)icalloc(src->xsize, sizeof(Pixel)); for(k = 0; k < tmp->ysize; ++k) { get_row(raster, src, k); for(i = 0; i < tmp->xsize; ++i) { @@ -321,14 +320,13 @@ double fwidth; /* filter width (support) */ ifree(contrib); /* pre-calculate filter contributions for a column */ - contrib = (CLIST *)calloc(dst->ysize, sizeof(CLIST)); + contrib = (CLIST*)icalloc(dst->ysize, sizeof(CLIST)); if(yscale < 1.0) { width = fwidth / yscale; fscale = 1.0 / yscale; for(i = 0; i < dst->ysize; ++i) { contrib[i].n = 0; - contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1), - sizeof(CONTRIB)); + contrib[i].p = (CONTRIB*)icalloc((int) (width * 2 + 1), sizeof(CONTRIB)); center = (double) i / yscale; left = ceil(center - width); right = floor(center + width); @@ -350,7 +348,7 @@ double fwidth; /* filter width (support) */ } else { for(i = 0; i < dst->ysize; ++i) { contrib[i].n = 0; - contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1), + contrib[i].p = (CONTRIB*)icalloc((int) (fwidth * 2 + 1), sizeof(CONTRIB)); center = (double) i / yscale; left = ceil(center - fwidth); @@ -373,7 +371,7 @@ double fwidth; /* filter width (support) */ } /* apply filter to zoom vertically from tmp to dst */ - raster = (Pixel *)calloc(tmp->ysize, sizeof(Pixel)); + raster = (Pixel*)icalloc(tmp->ysize, sizeof(Pixel)); for(k = 0; k < dst->xsize; ++k) { get_column(raster, tmp, k); for(i = 0; i < dst->ysize; ++i) { diff --git a/DevIL/src-ILU/src/ilu_states.c b/DevIL/src-ILU/src/ilu_states.c index 7f7fc035..5bfb10ab 100644 --- a/DevIL/src-ILU/src/ilu_states.c +++ b/DevIL/src-ILU/src/ilu_states.c @@ -16,7 +16,7 @@ const ILstring _iluVendor = IL_TEXT("Abysmal Software"); -const ILstring _iluVersion = IL_TEXT("Developer's Image Library Utilities (ILU) 1.6.1"); +const ILstring _iluVersion = IL_TEXT("Developer's Image Library Utilities (ILU) 1.6.5"); const ILstring ILAPIENTRY iluGetString(ILenum StringName) diff --git a/DevIL/src-ILUT/msvc/ILUT.rc b/DevIL/src-ILUT/msvc/ILUT.rc index 32281d01..87301c86 100644 --- a/DevIL/src-ILUT/msvc/ILUT.rc +++ b/DevIL/src-ILUT/msvc/ILUT.rc @@ -60,8 +60,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,1,6,1 - PRODUCTVERSION 0,1,6,1 + FILEVERSION 0,1,6,5 + PRODUCTVERSION 0,1,6,5 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x29L @@ -76,17 +76,17 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "ILUT: A great portable image library in development\0" + VALUE "Comments", "ILUT: A portable image library in development\0" VALUE "CompanyName", "Abysmal Software\0" - VALUE "FileDescription", "ILUT: A great portable image library in development\0" - VALUE "FileVersion", "1.6.1\0" + VALUE "FileDescription", "ILUT: A portable image library in development\0" + VALUE "FileVersion", "1.6.5\0" VALUE "InternalName", "ILUT\0" VALUE "LegalCopyright", "Copyright © 2000-2002\0" VALUE "LegalTrademarks", "Under LGPL License\0" VALUE "OriginalFilename", "ILUT.dll\0" VALUE "PrivateBuild", "Open Source\0" VALUE "ProductName", "Developer's Image Utility Toolkit Library\0" - VALUE "ProductVersion", "1.6.1\0" + VALUE "ProductVersion", "1.6.5\0" VALUE "SpecialBuild", "eh?\0" END END @@ -115,7 +115,7 @@ IDI_ICON1 ICON DISCARDABLE "resources\\IL Logo.ico" STRINGTABLE DISCARDABLE BEGIN - IDC_OPENILUT "Developer's Image Utility Toolkit Library, Version 1.6.1" + IDC_OPENILUT "Developer's Image Utility Toolkit Library, Version 1.6.5" END #endif // English (U.S.) resources |