diff options
Diffstat (limited to 'lcms2mt/utils')
-rw-r--r-- | lcms2mt/utils/delphi/lcms2dll.pas | 7 | ||||
-rw-r--r-- | lcms2mt/utils/jpgicc/Makefile.in | 1 | ||||
-rw-r--r-- | lcms2mt/utils/jpgicc/jpgicc.c | 87 | ||||
-rw-r--r-- | lcms2mt/utils/linkicc/Makefile.in | 1 | ||||
-rw-r--r-- | lcms2mt/utils/matlab/howto.txt | 4 | ||||
-rw-r--r-- | lcms2mt/utils/psicc/Makefile.in | 1 | ||||
-rw-r--r-- | lcms2mt/utils/tificc/Makefile.in | 1 | ||||
-rw-r--r-- | lcms2mt/utils/tificc/tificc.c | 56 | ||||
-rw-r--r-- | lcms2mt/utils/transicc/Makefile.in | 1 |
9 files changed, 103 insertions, 56 deletions
diff --git a/lcms2mt/utils/delphi/lcms2dll.pas b/lcms2mt/utils/delphi/lcms2dll.pas index 9af7a0d1..9368fc92 100644 --- a/lcms2mt/utils/delphi/lcms2dll.pas +++ b/lcms2mt/utils/delphi/lcms2dll.pas @@ -3,7 +3,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2021 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -25,7 +25,7 @@ // //--------------------------------------------------------------------------------- // -// Version 2.6 +// Version 2.13 // UNIT lcms2dll; @@ -1659,6 +1659,9 @@ FUNCTION cmsDetectDestinationBlackPoint( BlackPoint: LPcmsCIEXYZ; hProfile: cmsH // Estimate total area coverage FUNCTION cmsDetectTAC(hProfile: cmsHPROFILE): cmsFloat64Number; StdCall; +// Estimate profile gamma +FUNCTION cmsDetectRGBProfileGamma(hProfile: cmsHPROFILE): cmsFloat64Number; StdCall; + // Poor man's gamut mapping FUNCTION cmsDesaturateLab(Lab: LPcmsCIELab; amax, amin, bmax, bmin: cmsFloat64Number): cmsBool; StdCall; diff --git a/lcms2mt/utils/jpgicc/Makefile.in b/lcms2mt/utils/jpgicc/Makefile.in index 3d27bddc..e5f805f9 100644 --- a/lcms2mt/utils/jpgicc/Makefile.in +++ b/lcms2mt/utils/jpgicc/Makefile.in @@ -272,6 +272,7 @@ LIB_ZLIB = @LIB_ZLIB@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ diff --git a/lcms2mt/utils/jpgicc/jpgicc.c b/lcms2mt/utils/jpgicc/jpgicc.c index 00ac7aea..d03a79b5 100644 --- a/lcms2mt/utils/jpgicc/jpgicc.c +++ b/lcms2mt/utils/jpgicc/jpgicc.c @@ -274,7 +274,7 @@ cmsHPROFILE CreatePCS2ITU_ICC(void) #define PS_FIXED_TO_FLOAT(h, l) ((float) (h) + ((float) (l)/(1<<16))) static -cmsBool ProcessPhotoshopAPP13(JOCTET FAR *data, int datalen) +cmsBool ProcessPhotoshopAPP13(JOCTET *data, int datalen) { int i; @@ -299,6 +299,8 @@ cmsBool ProcessPhotoshopAPP13(JOCTET FAR *data, int datalen) len = ((((GETJOCTET(data[i]<<8) + GETJOCTET(data[i+1]))<<8) + GETJOCTET(data[i+2]))<<8) + GETJOCTET(data[i+3]); + if (len < 0) return FALSE; // Keep bug hunters away + i += 4; // Size if (type == 0x03ED && len >= 16) { @@ -330,7 +332,7 @@ cmsBool HandlePhotoshopAPP13(jpeg_saved_marker_ptr ptr) if (ptr -> marker == (JPEG_APP0 + 13) && ptr -> data_length > 9) { - JOCTET FAR* data = ptr -> data; + JOCTET* data = ptr -> data; if(GETJOCTET(data[0]) == 0x50 && GETJOCTET(data[1]) == 0x68 && @@ -363,45 +365,62 @@ typedef unsigned int uint32_t; #define YRESOLUTION 0x011b #define RESOLUTION_UNIT 0x128 +// Abort if crafted file +static +void craftedFile(void) +{ + FatalError("Corrupted EXIF data"); +} + // Read a 16-bit word static -uint16_t read16(uint8_t* arr, int pos, int swapBytes) +uint16_t read16(uint8_t* arr, size_t pos, int swapBytes, size_t max) { - uint8_t b1 = arr[pos]; - uint8_t b2 = arr[pos+1]; + if (pos + 2 >= max) + { + craftedFile(); + return 0; + } + else + { + uint8_t b1 = arr[pos]; + uint8_t b2 = arr[pos + 1]; - return (swapBytes) ? ((b2 << 8) | b1) : ((b1 << 8) | b2); + return (swapBytes) ? ((b2 << 8) | b1) : ((b1 << 8) | b2); + } } // Read a 32-bit word static -uint32_t read32(uint8_t* arr, int pos, int swapBytes) +uint32_t read32(uint8_t* arr, size_t pos, int swapBytes, size_t max) { - if(!swapBytes) { - - return (arr[pos] << 24) | - (arr[pos+1] << 16) | - (arr[pos+2] << 8) | - arr[pos+3]; + if (pos + 4 >= max) + { + craftedFile(); + return 0; } + else + { + if (!swapBytes) { - return arr[pos] | - (arr[pos+1] << 8) | - (arr[pos+2] << 16) | - (arr[pos+3] << 24); + return (arr[pos] << 24) | (arr[pos + 1] << 16) | (arr[pos + 2] << 8) | arr[pos + 3]; + } + + return arr[pos] | (arr[pos + 1] << 8) | (arr[pos + 2] << 16) | (arr[pos + 3] << 24); + } } static -int read_tag(uint8_t* arr, int pos, int swapBytes, void* dest) +int read_tag(uint8_t* arr, int pos, int swapBytes, void* dest, size_t max) { // Format should be 5 over here (rational) - uint32_t format = read16(arr, pos + 2, swapBytes); + uint32_t format = read16(arr, pos + 2, swapBytes, max); // Components should be 1 - uint32_t components = read32(arr, pos + 4, swapBytes); + uint32_t components = read32(arr, pos + 4, swapBytes, max); // Points to the value uint32_t offset; @@ -411,20 +430,20 @@ int read_tag(uint8_t* arr, int pos, int swapBytes, void* dest) if (format == 3) offset = pos + 8; else - offset = read32(arr, pos + 8, swapBytes); + offset = read32(arr, pos + 8, swapBytes, max); switch (format) { case 5: // Rational { - double num = read32(arr, offset, swapBytes); - double den = read32(arr, offset + 4, swapBytes); + double num = read32(arr, offset, swapBytes, max); + double den = read32(arr, offset + 4, swapBytes, max); *(double *) dest = num / den; } break; case 3: // uint 16 - *(int*) dest = read16(arr, offset, swapBytes); + *(int*) dest = read16(arr, offset, swapBytes, max); break; default: return 0; @@ -437,7 +456,7 @@ int read_tag(uint8_t* arr, int pos, int swapBytes, void* dest) // Handler for EXIF data static - cmsBool HandleEXIF(struct jpeg_decompress_struct* cinfo) +cmsBool HandleEXIF(struct jpeg_decompress_struct* cinfo) { jpeg_saved_marker_ptr ptr; uint32_t ifd_ofs; @@ -450,7 +469,9 @@ static for (ptr = cinfo ->marker_list; ptr; ptr = ptr ->next) { if ((ptr ->marker == JPEG_APP0+1) && ptr ->data_length > 6) { - JOCTET FAR* data = ptr -> data; + + JOCTET* data = ptr -> data; + size_t max = ptr->data_length; if (memcmp(data, "Exif\0\0", 6) == 0) { @@ -459,7 +480,7 @@ static // 8 byte TIFF header // first two determine byte order pos = 0; - if (read16(data, pos, 0) == INTEL_BYTE_ORDER) { + if (read16(data, pos, 0, max) == INTEL_BYTE_ORDER) { swapBytes = 1; } @@ -469,28 +490,28 @@ static pos += 2; // offset to Image File Directory (includes the previous 8 bytes) - ifd_ofs = read32(data, pos, swapBytes); + ifd_ofs = read32(data, pos, swapBytes, max); // Search the directory for resolution tags - numEntries = read16(data, ifd_ofs, swapBytes); + numEntries = read16(data, ifd_ofs, swapBytes, max); for (i=0; i < numEntries; i++) { uint32_t entryOffset = ifd_ofs + 2 + (12 * i); - uint32_t tag = read16(data, entryOffset, swapBytes); + uint32_t tag = read16(data, entryOffset, swapBytes, max); switch (tag) { case RESOLUTION_UNIT: - if (!read_tag(data, entryOffset, swapBytes, &Unit)) return FALSE; + if (!read_tag(data, entryOffset, swapBytes, &Unit, max)) return FALSE; break; case XRESOLUTION: - if (!read_tag(data, entryOffset, swapBytes, &XRes)) return FALSE; + if (!read_tag(data, entryOffset, swapBytes, &XRes, max)) return FALSE; break; case YRESOLUTION: - if (!read_tag(data, entryOffset, swapBytes, &YRes)) return FALSE; + if (!read_tag(data, entryOffset, swapBytes, &YRes, max)) return FALSE; break; default:; diff --git a/lcms2mt/utils/linkicc/Makefile.in b/lcms2mt/utils/linkicc/Makefile.in index 4477c79a..b6772f7a 100644 --- a/lcms2mt/utils/linkicc/Makefile.in +++ b/lcms2mt/utils/linkicc/Makefile.in @@ -272,6 +272,7 @@ LIB_ZLIB = @LIB_ZLIB@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ diff --git a/lcms2mt/utils/matlab/howto.txt b/lcms2mt/utils/matlab/howto.txt new file mode 100644 index 00000000..2490d3df --- /dev/null +++ b/lcms2mt/utils/matlab/howto.txt @@ -0,0 +1,4 @@ + +To compile for matlab use: + +mex @lcms_rsp diff --git a/lcms2mt/utils/psicc/Makefile.in b/lcms2mt/utils/psicc/Makefile.in index 06e6959c..0d271590 100644 --- a/lcms2mt/utils/psicc/Makefile.in +++ b/lcms2mt/utils/psicc/Makefile.in @@ -272,6 +272,7 @@ LIB_ZLIB = @LIB_ZLIB@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ diff --git a/lcms2mt/utils/tificc/Makefile.in b/lcms2mt/utils/tificc/Makefile.in index 53bcd8b3..009654c5 100644 --- a/lcms2mt/utils/tificc/Makefile.in +++ b/lcms2mt/utils/tificc/Makefile.in @@ -272,6 +272,7 @@ LIB_ZLIB = @LIB_ZLIB@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ diff --git a/lcms2mt/utils/tificc/tificc.c b/lcms2mt/utils/tificc/tificc.c index 9801a1c4..91687d9f 100644 --- a/lcms2mt/utils/tificc/tificc.c +++ b/lcms2mt/utils/tificc/tificc.c @@ -29,6 +29,14 @@ #include "tiffio.h" #include "utils.h" +// Fix broken libtiff 4.3.0, thanks to Bob Friesenhahn for uncovering this + +#if defined(HAVE_STDINT_H) && (TIFFLIB_VERSION >= 20201219) +# undef uint16 +# define uint16 uint16_t +# undef uint32 +# define uint32 uint32_t +#endif /* TIFFLIB_VERSION */ // Flags @@ -57,16 +65,15 @@ static const char* SaveEmbedded = NULL; static void ConsoleWarningHandler(const char* module, const char* fmt, va_list ap) { - char e[512] = { '\0' }; - if (module != NULL) - strcat(strcpy(e, module), ": "); - - vsprintf(e+strlen(e), fmt, ap); - strcat(e, "."); if (Verbose) { - fprintf(stderr, "\nWarning"); - fprintf(stderr, " %s\n", e); + fprintf(stderr, "Warning: "); + + if (module != NULL) + fprintf(stderr, "[%s] ", module); + + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); fflush(stderr); } } @@ -74,18 +81,18 @@ void ConsoleWarningHandler(const char* module, const char* fmt, va_list ap) static void ConsoleErrorHandler(const char* module, const char* fmt, va_list ap) { - char e[512] = { '\0' }; + if (Verbose) { + + fprintf(stderr, "Error: "); - if (module != NULL) { - if (strlen(module) < 500) - strcat(strcpy(e, module), ": "); + if (module != NULL) + fprintf(stderr, "[%s] ", module); + + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + fflush(stderr); } - vsprintf(e+strlen(e), fmt, ap); - strcat(e, "."); - fprintf(stderr, "\nError"); - fprintf(stderr, " %s\n", e); - fflush(stderr); } @@ -96,7 +103,7 @@ void Warning(const char *frm, ...) va_list args; va_start(args, frm); - ConsoleWarningHandler("[tificc]", frm, args); + ConsoleWarningHandler("tificc", frm, args); va_end(args); } @@ -304,6 +311,8 @@ cmsUInt32Number GetInputPixelType(TIFF *Bank) case PHOTOMETRIC_RGB: pt = PT_RGB; + if (ColorChannels < 3) + FatalError("Sorry, RGB needs at least 3 samples per pixel"); break; @@ -312,7 +321,6 @@ cmsUInt32Number GetInputPixelType(TIFF *Bank) break; case PHOTOMETRIC_SEPARATED: - pt = PixelTypeFromChanCount(ColorChannels); break; @@ -409,6 +417,9 @@ int TileBasedXform(cmsContext ContextID, cmsHTRANSFORM hXForm, TIFF* in, TIFF* o BufferIn + (j*BufSizeIn), BufSizeIn) < 0) goto cleanup; } + if (PixelCount < 0) + FatalError("TIFF is corrupted"); + cmsDoTransform(ContextID, hXForm, BufferIn, BufferOut, PixelCount); for (j=0; j < nPlanes; j++) { @@ -477,6 +488,9 @@ int StripBasedXform(cmsContext ContextID, cmsHTRANSFORM hXForm, TIFF* in, TIFF* PixelCount = (int) sw * (iml < sl ? iml : sl); iml -= sl; + if (PixelCount < 0) + FatalError("TIFF is corrupted"); + cmsDoTransform(ContextID, hXForm, BufferIn, BufferOut, PixelCount); for (j=0; j < nPlanes; j++) { @@ -1141,8 +1155,8 @@ int main(int argc, char* argv[]) TIFF *in, *out; - fprintf(stderr, "Little CMS ICC profile applier for TIFF - v6.3 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0); - fprintf(stderr, "Copyright (c) 1998-2020 Marti Maria Saguer. See COPYING file for details.\n"); + fprintf(stderr, "Little CMS ICC profile applier for TIFF - v6.4 [LittleCMS %2.2f]\n\n", LCMS_VERSION / 1000.0); + fprintf(stderr, "Copyright (c) 1998-2021 Marti Maria Saguer. See COPYING file for details.\n"); fflush(stderr); ContextID = cmsCreateContext(NULL, NULL); diff --git a/lcms2mt/utils/transicc/Makefile.in b/lcms2mt/utils/transicc/Makefile.in index f3e029b5..7e2d1fb8 100644 --- a/lcms2mt/utils/transicc/Makefile.in +++ b/lcms2mt/utils/transicc/Makefile.in @@ -272,6 +272,7 @@ LIB_ZLIB = @LIB_ZLIB@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ |