Index: head/graphics/libimg/Makefile =================================================================== --- head/graphics/libimg/Makefile (revision 560346) +++ head/graphics/libimg/Makefile (revision 560347) @@ -1,63 +1,64 @@ # Created by: Glenn Johnson # $FreeBSD$ PORTNAME= libimg -PORTVERSION= 1.4.9 +PORTVERSION= 1.4.12 CATEGORIES?= graphics tk tcl MASTER_SITES= SF/tkimg/tkimg/${PORTVERSION:R}/tkimg%20${PORTVERSION} DISTNAME= Img-${PORTVERSION}-Source MAINTAINER= mi@aldan.algebra.com COMMENT= Library of image format handlers for Tk4.1 and later LICENSE= TclTk LICENSE_NAME= Tcl/Tk License LICENSE_FILE= ${WRKSRC}/license.terms LICENSE_PERMS= auto-accept pkg-sell pkg-mirror dist-sell dist-mirror BUILD_DEPENDS= dtplite:devel/tcllib LIB_DEPENDS= libfontconfig.so:x11-fonts/fontconfig \ libfreetype.so:print/freetype2 \ libpng.so:graphics/png \ libtiff.so:graphics/tiff USES= autoreconf jpeg tk:tea xorg dos2unix PLIST_SUB+= PORTVERSION=${PORTVERSION} USE_XORG= x11 xext xft xrender xscrnsaver OPTIONS_DEFINE= EXAMPLES OPTIONS_SUB= yes WRKSRC= ${WRKDIR}/Img-${PORTVERSION} DOS2UNIX_GLOB= *.[ch] *.tcl *.msg *.in *.test license.terms # We don't need the bundled libraries: EXTRACT_AFTER_ARGS= --exclude 'config.*' --exclude Makefile \ --exclude 'compat' --exclude win MAKE_ARGS+= INSTALL_ROOT="${STAGEDIR}" CONFIGURE_ENV= WRKDIR="${WRKDIR}" +CONFIGURE_ARGS+=--enable-shared --disable-stubs post-patch: ${REINPLACE_CMD} -E -e 's,"(zlib|tiff|jpeg|png)tcl.h",<\1.h>,' \ -e 's,jpeg\.h,jpeglib.h,' ${WRKSRC}/*/*.[ch] .for d in jpeg png tiff zlib ${TOUCH} ${WRKDIR}/$dtclConfig.sh .endfor post-configure: .for l in jpeg png tiff # Link with -l$l ${REINPLACE_CMD} -E \ -e 's,^SHLIB_LD_LIBS[[:space:]]*=[[:space:]]*(.*),SHLIB_LD_LIBS=\1 -l$l,' \ ${WRKSRC}/$l/Makefile .endfor do-test: cd ${WRKSRC}/tests && \ ${SETENV} TCLLIBPATH=${WRKSRC:Q} ${WISH} ${WRKSRC}/tests/all post-install-EXAMPLES-on: @${MKDIR} ${STAGEDIR}${EXAMPLESDIR}/msgs/ ${INSTALL_DATA} ${WRKSRC}/msgs/*.msg ${STAGEDIR}${EXAMPLESDIR}/msgs/ ${INSTALL_SCRIPT} ${WRKSRC}/demo.tcl ${WRKSRC}/tkv.tcl ${STAGEDIR}${EXAMPLESDIR}/ .include Index: head/graphics/libimg/distinfo =================================================================== --- head/graphics/libimg/distinfo (revision 560346) +++ head/graphics/libimg/distinfo (revision 560347) @@ -1,3 +1,3 @@ -TIMESTAMP = 1579572018 -SHA256 (Img-1.4.9-Source.tar.gz) = 89aa029d9352de02c483857bc85b27af52f1b77907ee276047e13e894d1e3629 -SIZE (Img-1.4.9-Source.tar.gz) = 7702460 +TIMESTAMP = 1609788426 +SHA256 (Img-1.4.12-Source.tar.gz) = 4ff4e4d836ec41f0b56eba5fb73e628387a0dbfdcb7d8bb5821bb6edde0922f9 +SIZE (Img-1.4.12-Source.tar.gz) = 8363871 Index: head/graphics/libimg/files/patch-config =================================================================== --- head/graphics/libimg/files/patch-config (revision 560346) +++ head/graphics/libimg/files/patch-config (revision 560347) @@ -1,60 +1,60 @@ --- base/Makefile.in 2013-11-21 17:03:14.000000000 -0500 +++ base/Makefile.in 2014-06-09 15:29:06.000000000 -0400 @@ -432,5 +432,5 @@ $(INSTALL_DATA) pkgIndex.tcl $(DESTDIR)$(pkglibdir); \ fi - $(INSTALL_DATA) tkimgConfig.sh $(DESTDIR)$(libdir) + $(INSTALL_DATA) tkimgConfig.sh $(DESTDIR)$(libdir)/Img #======================================================================== --- Makefile.in 2013-11-21 17:03:12.000000000 -0500 +++ Makefile.in 2014-06-09 15:13:46.000000000 -0400 @@ -58,5 +58,5 @@ # Directory where libimg.a is at run-time: -LIB_RUNTIME_DIR = $(libdir)/$(PACKAGE_NAME)$(PACKAGE_VERSION) +LIB_RUNTIME_DIR = $(libdir)/$(PACKAGE_NAME) # Directory in which to install the archive libimg.a: @@ -145,5 +145,5 @@ mv pkgIndex.tcl Img/exec_prefix/lib/Img/pkgIndex.tcl chmod ugo+w Img/exec_prefix/lib/Img/pkgIndex.tcl - for p in Img/exec_prefix/lib/*.sh ; do \ + for p in Img/exec_prefix/lib/Img/*.sh ; do \ sed -e 's#$(libdir)/[^/ ]*\([/ ]\)#$(LIB_RUNTIME_DIR)\1#' \ $$p > $$p.1 && mv -f $$p.1 $$p ; \ @@ -156,5 +156,5 @@ done mkdir -p $(INSTALL_ROOT)$(libdir) - for p in Img/exec_prefix/lib/*.sh ; do \ + for p in Img/exec_prefix/lib/Img/*.sh ; do \ $(INSTALL_PROGRAM) $$p $(INSTALL_ROOT)$(libdir)/`basename $$p` ; \ done ---- configure.in 2014-06-09 15:13:46.000000000 -0400 -+++ configure.in 2013-11-21 17:03:14.000000000 -0500 +--- configure.ac 2020-08-29 18:40:53.178382500 -0400 ++++ configure.ac 2021-01-04 15:12:55.394745000 -0500 @@ -110,16 +110,12 @@ TEA_CONFIG_COLLECT -TEA_CONFIG_SUBDIR(zlib, [--disable-option-checking]) -TEA_CONFIG_SUBDIR(libpng, [--with-zlibtcl=`pwd`/zlib --disable-option-checking]) -TEA_CONFIG_SUBDIR(libtiff, [--disable-option-checking]) -TEA_CONFIG_SUBDIR(libjpeg, [--disable-option-checking]) TEA_CONFIG_SUBDIR(base, [--disable-option-checking]) TEA_CONFIG_SUBDIR(bmp, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(gif, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(ico, [--with-tkimg=`pwd`/base --disable-option-checking]) -TEA_CONFIG_SUBDIR(jpeg, [--with-tkimg=`pwd`/base --with-jpegtcl=`pwd`/libjpeg --disable-option-checking]) +TEA_CONFIG_SUBDIR(jpeg, [--with-tkimg=`pwd`/base --with-jpegtcl="$WRKDIR" --disable-option-checking]) TEA_CONFIG_SUBDIR(pcx, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(pixmap, [--with-tkimg=`pwd`/base --disable-option-checking]) -TEA_CONFIG_SUBDIR(png, [--with-tkimg=`pwd`/base --with-pngtcl=`pwd`/libpng --with-zlibtcl=`pwd`/zlib --disable-option-checking]) +TEA_CONFIG_SUBDIR(png, [--with-tkimg=`pwd`/base --with-pngtcl="$WRKDIR" --with-zlibtcl="$WRKDIR" --disable-option-checking]) TEA_CONFIG_SUBDIR(ppm, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(ps, [--with-tkimg=`pwd`/base --disable-option-checking]) @@ -127,5 +123,5 @@ TEA_CONFIG_SUBDIR(sun, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(tga, [--with-tkimg=`pwd`/base --disable-option-checking]) -TEA_CONFIG_SUBDIR(tiff, [--with-tkimg=`pwd`/base --with-tifftcl=`pwd`/libtiff --with-zlibtcl=`pwd`/zlib --with-jpegtcl=`pwd`/libjpeg --disable-option-checking]) +TEA_CONFIG_SUBDIR(tiff, [--with-tkimg=`pwd`/base --with-tifftcl="$WRKDIR" --with-zlibtcl="WRKDIR" --with-jpegtcl="$WRKDIR" --disable-option-checking]) TEA_CONFIG_SUBDIR(window, [--with-tkimg=`pwd`/base --disable-option-checking]) TEA_CONFIG_SUBDIR(xbm, [--with-tkimg=`pwd`/base --disable-option-checking]) Index: head/graphics/libimg/files/patch-jpeg =================================================================== --- head/graphics/libimg/files/patch-jpeg (revision 560346) +++ head/graphics/libimg/files/patch-jpeg (revision 560347) @@ -1,148 +1,153 @@ ---- jpeg/jpeg.c 2018-09-14 09:53:49.000000000 -0400 -+++ jpeg/jpeg.c 2020-01-20 21:56:13.089925000 -0500 -@@ -62,5 +62,9 @@ - +--- jpeg/jpeg.c 2019-03-22 10:47:24.654594000 -0400 ++++ jpeg/jpeg.c 2021-01-04 14:38:51.161931000 -0500 +@@ -64,5 +64,9 @@ #include "tkimg.h" + #ifdef USE_TCL_STUBS -#include "jpegtcl.h" +#ifdef EXTERN +# undef EXTERN +#endif +#include +#include + #else + #include "jpeglib.h" +@@ -70,8 +74,5 @@ + #endif - static int SetupJPegLibrary(Tcl_Interp *interp); -@@ -143,86 +147,11 @@ +-static int SetupJPegLibrary(Tcl_Interp *interp); +- +-#define MORE_INITIALIZATION \ +- if (SetupJPegLibrary (interp) != TCL_OK) { return TCL_ERROR; } ++#define MORE_INITIALIZATION {} + #include "init.c" +@@ -149,88 +150,4 @@ + - - static int - SetupJPegLibrary (interp) - Tcl_Interp *interp; - { +-static int +-SetupJPegLibrary( +- Tcl_Interp *interp +-) { - struct jpeg_compress_struct *cinfo; /* libjpeg's parameter structure */ - struct my_error_mgr jerror; /* for controlling libjpeg error handling */ - int i; - +-#ifdef USE_TCL_STUBS - if (Jpegtcl_InitStubs(interp, JPEGTCL_VERSION, 0) == NULL) { - return TCL_ERROR; - } +-#endif - - /* The followin code tries to determine if the JPEG library is - valid at all. The library might be configured differently, - which will produce core dumps. Also it might be that - fields appear in different places in jpeg_compress_struct - or jpeg_decompress_struct. This will make the library totally - unusable. In stead of a core-dump, we better have a proper - error message */ - - /* overallocat size, so we don't get a core-dump if the library - thinks that the structure is much larger */ - - cinfo = (struct jpeg_compress_struct *) ckalloc(8*sizeof(struct jpeg_compress_struct)); - cinfo->err = jpeg_std_error(&jerror.pub); - jerror.pub.error_exit = my_error_exit; - jerror.pub.output_message = my_output_message; - /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerror.setjmp_buffer)) { - /* If we get here, the JPEG library is invalid. */ - jpeg_destroy_compress(cinfo); - ckfree((char *)cinfo); - - if (interp) { - Tcl_AppendResult(interp, "couldn't use \"", "jpegtcl", - "\": please upgrade to at least version 6a", (char *) NULL); - } - return TCL_ERROR; - } - - /* Now we can initialize libjpeg. */ - ((char *) cinfo)[sizeof(struct jpeg_compress_struct)] = 53; - jpeg_create_compress(cinfo); - if (((char *) cinfo)[sizeof(struct jpeg_compress_struct)] != 53) { - /* Oops. The library changed this value, which is outside the - * structure. Definitely, the library is invalid!!!! */ - ERREXIT(cinfo, JMSG_NOMESSAGE); - } - - /* Set up JPEG compression parameters. */ - cinfo->image_width = 16; - cinfo->image_height = 16; - cinfo->input_components = 3; - cinfo->in_color_space = JCS_RGB; - cinfo->data_precision = -1; - cinfo->optimize_coding = TRUE; - cinfo->dct_method = -1; - cinfo->X_density = 0; - cinfo->Y_density = 0; - jpeg_set_defaults(cinfo); - - if ((cinfo->data_precision != BITS_IN_JSAMPLE) || - (cinfo->optimize_coding != FALSE) || - (cinfo->dct_method != JDCT_DEFAULT) || - (cinfo->X_density != 1) || - (cinfo->Y_density != 1)) { - ERREXIT(cinfo, JMSG_NOMESSAGE); - } - for (i = 0; i < NUM_ARITH_TBLS; i++) { - if ((cinfo->arith_dc_L[i] != 0) || - (cinfo->arith_dc_U[i] != 1) || - (cinfo->arith_ac_K[i] != 5)) { - ERREXIT(cinfo, JMSG_NOMESSAGE); - } - } - jpeg_destroy_compress(cinfo); - ckfree((char *) cinfo); - return TCL_OK; - } - +- return TCL_OK; +-} - +- /* *---------------------------------------------------------------------- -@@ -860,8 +789,6 @@ - } +@@ -866,8 +783,6 @@ case 2: { + #ifdef USE_JPEGTCL_STUBS - if (jpeg_simple_progression != NULL) { - /* Select simple progressive mode. */ - jpeg_simple_progression(cinfo); - } + /* Select simple progressive mode. */ + jpeg_simple_progression(cinfo); - break; - } -@@ -899,5 +826,5 @@ - greenOffset = blockPtr->offset[1] - blockPtr->offset[0]; - blueOffset = blockPtr->offset[2] - blockPtr->offset[0]; -- if ((jpeg_set_colorspace != NULL) && -+ if ( - (grayscale || (!greenOffset && !blueOffset))) { - /* Generate monochrome JPEG file if source block is grayscale. */ + #else + jpeg_simple_progression(cinfo); --- tests/jpeg.test 2016-07-30 10:30:48.000000000 -0400 +++ tests/jpeg.test 2020-01-20 21:43:20.086115000 -0500 @@ -24,5 +24,5 @@ source $file2.base64 - test jpeg-1.1 {} -setup { + test jpeg-1.1 {} -constraints nonPortable -setup { catch {image delete i} } -body { @@ -33,5 +33,5 @@ } -result $imgdata2 - test jpeg-1.2 {} -setup { + test jpeg-1.2 {} -constraints nonPortable -setup { catch {image delete i} } -body { @@ -42,5 +42,5 @@ } -result $imgdata2 - test jpeg-1.3 {} -setup { + test jpeg-1.3 {} -constraints nonPortable -setup { catch {image delete i} } -body { @@ -52,5 +52,5 @@ } -result $imgdata2 - test jpeg-1.4 {} -setup { + test jpeg-1.4 {} -constraints nonPortable -setup { catch {image delete i} } -body { Index: head/graphics/libimg/files/patch-tiff =================================================================== --- head/graphics/libimg/files/patch-tiff (revision 560346) +++ head/graphics/libimg/files/patch-tiff (revision 560347) @@ -1,369 +1,439 @@ --- tiff/configure 2013-11-21 17:03:14.000000000 -0500 +++ tiff/configure 2014-06-09 14:00:22.000000000 -0400 @@ -8232,5 +8232,5 @@ - vars="tiff.c tiffJpeg.c tiffZip.c tiffPixar.c" + vars="tiff.c" for i in $vars; do case $i in ---- tiff/tiff.c 2019-03-02 16:33:00.000000000 -0500 -+++ tiff/tiff.c 2020-01-20 21:20:18.135776000 -0500 -@@ -19,11 +19,15 @@ +--- tiff/tiff.c 2020-08-26 17:17:10.040341300 -0400 ++++ tiff/tiff.c 2021-01-04 15:02:19.857169000 -0500 +@@ -20,11 +20,15 @@ #endif #include "tkimg.h" -#include "tifftcl.h" -#include "zlibtcl.h" +#ifdef EXTERN +# undef EXTERN +#endif +#include +#include +#include #ifdef HAVE_STDLIB_H #undef HAVE_STDLIB_H #endif -#include "jpegtcl.h" +#include + static int SetupTiffLibrary(Tcl_Interp *interp); +@@ -37,7 +41,4 @@ + #include "tiffInt.h" -@@ -35,7 +39,4 @@ - #include "init.c" - --#include "tiffInt.h" - +-extern DLLIMPORT int unlink(const char *); - - extern DLLIMPORT int unlink(const char *); - -@@ -88,52 +89,11 @@ - Tcl_Interp *interp; + /* + * Prototypes for local procedures defined in this file: +@@ -84,44 +85,7 @@ + SetupTiffLibrary (Tcl_Interp *interp) { - static int initialized = 0; - - if (Tifftcl_InitStubs(interp, TIFFTCL_VERSION, 0) == NULL) { - return TCL_ERROR; - } - - if (errorMessage) { - ckfree(errorMessage); - errorMessage = NULL; - } +- if (errorMessage) { +- ckfree(errorMessage); +- errorMessage = NULL; +- } - if (TIFFSetErrorHandler != NULL) { - TIFFSetErrorHandler(_TIFFerr); - } - if (TIFFSetWarningHandler != NULL) { -- TIFFSetWarningHandler(_TIFFwarn); +- TIFFSetWarningHandler(_TIFFwarn); - } - - /* - * Initialize jpeg and zlib too, for use by the CODEC's we register - * with the base TIFF library in this package. - */ - - if (Jpegtcl_InitStubs(interp, JPEGTCL_VERSION, 0) == NULL) { - return TCL_ERROR; - } - - if (!initialized) { -- initialized = 1; -- if ( -- TIFFRegisterCODEC && TIFFError && TIFFPredictorInit && -- _TIFFMergeFieldInfo && TIFFFlushData1 && _TIFFNoPostDecode && -- TIFFTileRowSize && TIFFScanlineSize && _TIFFsetByteArray && -- TIFFVSetField && TIFFSwabArrayOfShort -- ) { +- initialized = 1; +- if (Zlibtcl_InitStubs(interp, ZLIBTCL_VERSION, 0) == NULL) { +- return TCL_ERROR; +- } +- TIFFRegisterCODEC (COMPRESSION_DEFLATE, "Deflate", TkimgTIFFInitZip); +- TIFFRegisterCODEC (COMPRESSION_ADOBE_DEFLATE, "AdobeDeflate", TkimgTIFFInitZip); - -- if (Zlibtcl_InitStubs(interp, ZLIBTCL_VERSION, 0) == NULL) { -- return TCL_ERROR; -- } -- TIFFRegisterCODEC (COMPRESSION_DEFLATE, "Deflate", TkimgTIFFInitZip); -- TIFFRegisterCODEC (COMPRESSION_ADOBE_DEFLATE, "AdobeDeflate", TkimgTIFFInitZip); +- if (Jpegtcl_InitStubs(interp, JPEGTCL_VERSION, 0) == NULL) { +- return TCL_ERROR; +- } +- TIFFRegisterCODEC (COMPRESSION_JPEG, "JPEG", TkimgTIFFInitJpeg); +- TIFFRegisterCODEC (COMPRESSION_PIXARLOG, "PixarLog", TkimgTIFFInitPixar); +- } + TIFFSetErrorHandler(_TIFFerr); + TIFFSetWarningHandler(_TIFFwarn); - -- if (Jpegtcl_InitStubs(interp, JPEGTCL_VERSION, 0) == NULL) { -- return TCL_ERROR; -- } -- TIFFRegisterCODEC (COMPRESSION_JPEG, "JPEG", TkimgTIFFInitJpeg); -- TIFFRegisterCODEC (COMPRESSION_PIXARLOG, "PixarLog", TkimgTIFFInitPixar); -- } -- } ++ return TCL_OK; } -@@ -451,9 +411,6 @@ - { +@@ -435,8 +399,6 @@ + ) { TIFF *tif; -- char *tempFileName = NULL, tempFileNameBuffer[256]; -- size_t count; - int result; +- char *dir, *tempFileName = NULL, tempFileNameBuffer[1024]; +- int count, result; ++ int result; tkimg_MFile handle; -- char buffer[1024]; +- char buffer[4096]; char *dataPtr = NULL; -@@ -462,35 +419,13 @@ +@@ -445,66 +407,13 @@ } - if (TIFFClientOpen) { -- if (handle.state != IMG_STRING) { -- dataPtr = ckalloc((handle.length*3)/4 + 2); -- handle.length = tkimg_Read2(&handle, dataPtr, handle.length); -- handle.data = dataPtr; -- } -- handle.state = 0; -- tif = TIFFClientOpen("inline data", "r", (thandle_t) &handle, -- readString, writeString, seekString, closeDummy, -- sizeString, mapDummy, unMapDummy); +- if (handle.state != IMG_STRING) { +- dataPtr = ckalloc((handle.length*3)/4 + 2); +- handle.length = tkimg_Read2(&handle, dataPtr, handle.length); +- handle.data = dataPtr; +- } +- handle.state = 0; +- tif = TIFFClientOpen("inline data", "r", (thandle_t) &handle, +- readString, writeString, seekString, closeDummy, +- sizeString, mapDummy, unMapDummy); - } else { -- Tcl_Channel outchan; -- tempFileName = tmpnam(tempFileNameBuffer); -- outchan = tkimg_OpenFileChannel(interp, tempFileName, 0644); -- if (!outchan) { -- return TCL_ERROR; -- } +- FILE *outfile; +-#ifdef WIN32 +- char dirBuffer[512]; +- HANDLE h; - -- count = (size_t)tkimg_Read2(&handle, buffer, 1024); -- while (count == 1024) { -- Tcl_Write(outchan, buffer, count); -- count = (size_t)tkimg_Read2(&handle, buffer, 1024); -- } -- if (count + 1 > 1){ -- Tcl_Write(outchan, buffer, count); -- } -- if (Tcl_Close(interp, outchan) == TCL_ERROR) { -- return TCL_ERROR; -- } -- tif = TIFFOpen(tempFileName, "r"); +- dir = dirBuffer; +- strcpy(dir, "."); +- GetTempPathA(sizeof (dirBuffer), dir); +- tempFileName = tempFileNameBuffer; +- tempFileName[0] = '\0'; +- GetTempFileNameA(dir, "tki", 0, tempFileName); +- h = CreateFileA(tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, +- CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); +- if (h != INVALID_HANDLE_VALUE) { +- CloseHandle(h); +- } +-#else +- dir = getenv("TMPDIR"); +- tempFileName = tempFileNameBuffer; +- if (dir) { +- strcpy(tempFileName, dir); +- } else { +-#ifdef P_tmpdir +- strcpy(tempFileName, P_tmpdir); +-#else +- strcpy(tempFileName, "/tmp"); +-#endif +- } +- strcat(tempFileName, "/tkimgXXXXXX"); +- result = mkstemp(tempFileName); +- if (result >= 0) { +- close(result); +- } +-#endif +- outfile = fopen(tempFileName, "wb"); +- if (outfile == NULL) { +- Tcl_AppendResult(interp, "error open output file", (char *) NULL); +- return TCL_ERROR; +- } +- +- count = tkimg_Read2(&handle, buffer, sizeof (buffer)); +- while (count == sizeof (buffer)) { +- fwrite(buffer, 1, sizeof (buffer), outfile); +- count = tkimg_Read2(&handle, buffer, sizeof (buffer)); +- } +- if (count + 1 > 1){ +- fwrite(buffer, 1, count, outfile); +- } +- fclose(outfile); +- tif = TIFFOpen(tempFileName, "r"); - } + if (handle.state != IMG_STRING) { -+ dataPtr = ckalloc((handle.length*3)/4 + 2); -+ handle.length = tkimg_Read(&handle, dataPtr, handle.length); -+ handle.data = dataPtr; ++ dataPtr = ckalloc((handle.length*3)/4 + 2); ++ handle.length = tkimg_Read2(&handle, dataPtr, handle.length); ++ handle.data = dataPtr; + } + handle.state = 0; + tif = TIFFClientOpen("inline data", "r", (thandle_t) &handle, -+ readString, writeString, seekString, closeDummy, -+ sizeString, mapDummy, unMapDummy); ++ readString, writeString, seekString, closeDummy, ++ sizeString, mapDummy, unMapDummy); if (tif != NULL) { -@@ -500,7 +435,4 @@ - result = TCL_ERROR; +@@ -514,7 +423,4 @@ + result = TCL_ERROR; } - if (tempFileName) { -- unlink(tempFileName); +- unlink(tempFileName); - } if (result == TCL_ERROR) { - Tcl_AppendResult(interp, errorMessage, (char *) NULL); -@@ -527,38 +459,12 @@ - { + Tcl_AppendResult(interp, errorMessage, (char *) NULL); +@@ -540,68 +446,13 @@ + ) { TIFF *tif; -- char *tempFileName = NULL, tempFileNameBuffer[256]; -- size_t count; -- int result; -- char buffer[1024]; +- char *dir, *tempFileName = NULL, tempFileNameBuffer[1024]; +- int count, result; +- char buffer[4096]; - - if (TIFFClientOpen) { -- tkimg_MFile handle; -- handle.data = (char *) chan; -- handle.state = IMG_CHAN; -- tif = TIFFClientOpen(fileName, "r", (thandle_t) &handle, -- readMFile, writeDummy, seekMFile, closeDummy, -- sizeMFile, mapDummy, unMapDummy); +- tkimg_MFile handle; +- handle.data = (char *) chan; +- handle.state = IMG_CHAN; +- tif = TIFFClientOpen(fileName, "r", (thandle_t) &handle, +- readMFile, writeDummy, seekMFile, closeDummy, +- sizeMFile, mapDummy, unMapDummy); - } else { -- Tcl_Channel outchan; -- tempFileName = tmpnam(tempFileNameBuffer); -- outchan = tkimg_OpenFileChannel(interp, tempFileName, 0644); -- if (!outchan) { -- return TCL_ERROR; -- } -+ int result; -+ tkimg_MFile handle; - -- count = (size_t)Tcl_Read(chan, buffer, 1024); -- while (count == 1024) { -- Tcl_Write(outchan, buffer, count); -- count = (size_t)Tcl_Read(chan, buffer, 1024); -- } -- if (count + 1 > 1){ -- Tcl_Write(outchan, buffer, count); -- } -- if (Tcl_Close(interp, outchan) == TCL_ERROR) { -- return TCL_ERROR; -- } +- FILE *outfile; +-#ifdef WIN32 +- char dirBuffer[512]; +- HANDLE h; - -- tif = TIFFOpen(tempFileName, "r"); -- } +- dir = dirBuffer; +- strcpy(dir, "."); +- GetTempPathA(sizeof (dirBuffer), dir); +- tempFileName = tempFileNameBuffer; +- tempFileName[0] = '\0'; +- GetTempFileNameA(dir, "tki", 0, tempFileName); +- h = CreateFileA(tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, +- CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); +- if (h != INVALID_HANDLE_VALUE) { +- CloseHandle(h); +- } +-#else +- dir = getenv("TMPDIR"); +- tempFileName = tempFileNameBuffer; +- if (dir) { +- strcpy(tempFileName, dir); +- } else { +-#ifdef P_tmpdir +- strcpy(tempFileName, P_tmpdir); +-#else +- strcpy(tempFileName, "/tmp"); +-#endif +- } +- strcat(tempFileName, "/tkimgXXXXXX"); +- result = mkstemp(tempFileName); +- if (result >= 0) { +- close(result); +- } +-#endif +- outfile = fopen(tempFileName, "wb"); +- if (outfile == NULL) { +- Tcl_AppendResult(interp, "error open output file", (char *) NULL); +- return TCL_ERROR; +- } ++ int result; + +- count = Tcl_Read(chan, buffer, sizeof (buffer)); +- while (count == sizeof (buffer)) { +- fwrite(buffer, 1, sizeof (buffer), outfile); +- count = Tcl_Read(chan, buffer, sizeof (buffer)); +- } +- if (count>0){ +- fwrite(buffer, 1, count, outfile); +- } +- fclose(outfile); ++ tkimg_MFile handle; + handle.data = (char *) chan; + handle.state = IMG_CHAN; + tif = TIFFClientOpen(fileName, "r", (thandle_t) &handle, -+ readMFile, writeDummy, seekMFile, closeDummy, -+ sizeMFile, mapDummy, unMapDummy); ++ readMFile, writeDummy, seekMFile, closeDummy, ++ sizeMFile, mapDummy, unMapDummy); + +- tif = TIFFOpen(tempFileName, "r"); +- } if (tif) { - result = CommonRead(interp, tif, format, imageHandle, -@@ -567,7 +473,4 @@ - result = TCL_ERROR; + result = CommonRead(interp, tif, format, imageHandle, +@@ -610,7 +461,4 @@ + result = TCL_ERROR; } - if (tempFileName) { -- unlink(tempFileName); +- unlink(tempFileName); - } if (result == TCL_ERROR) { - Tcl_AppendResult(interp, errorMessage, (char *) NULL); -@@ -637,5 +540,5 @@ + Tcl_AppendResult(interp, errorMessage, (char *) NULL); +@@ -678,5 +526,5 @@ npixels = w * h; - raster = (uint32*) TkimgTIFFmalloc(npixels * sizeof (uint32)); + raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32)); block.width = w; block.height = h; -@@ -648,5 +551,5 @@ +@@ -689,5 +537,5 @@ if (!TIFFReadRGBAImage(tif, w, h, raster, 0) || errorMessage) { - TkimgTIFFfree (raster); + _TIFFfree (raster); - if (errorMessage) { - Tcl_AppendResult(interp, errorMessage, (char *) NULL); -@@ -665,5 +568,5 @@ + if (errorMessage) { + Tcl_AppendResult(interp, errorMessage, (char *) NULL); +@@ -705,5 +553,5 @@ } - TkimgTIFFfree (raster); + _TIFFfree (raster); TIFFClose(tif); return result; -@@ -676,7 +579,6 @@ - ) { - TIFF *tif; -- int result, comp; -+ int result, comp, length; +@@ -718,5 +566,4 @@ + int result, comp; tkimg_MFile handle; -- char *tempFileName = NULL, tempFileNameBuffer[256]; +- char *dir, *tempFileName = NULL, tempFileNameBuffer[256]; Tcl_DString dstring; const char *mode; -@@ -688,14 +590,9 @@ +@@ -728,46 +575,9 @@ } - if (TIFFClientOpen) { -- Tcl_DStringInit(&dstring); -- tkimg_WriteInit(&dstring, &handle); -- tif = TIFFClientOpen("inline data", mode, (thandle_t) &handle, -- readString, writeString, seekString, closeDummy, -- sizeString, mapDummy, unMapDummy); +- Tcl_DStringInit(&dstring); +- tkimg_WriteInit(&dstring, &handle); +- tif = TIFFClientOpen("inline data", mode, (thandle_t) &handle, +- readString, writeString, seekString, closeDummy, +- sizeString, mapDummy, unMapDummy); - } else { -- tempFileName = tmpnam(tempFileNameBuffer); -- tif = TIFFOpen(tempFileName,mode); +-#ifdef WIN32 +- char dirBuffer[512]; +- HANDLE h; +- +- dir = dirBuffer; +- strcpy(dir, "."); +- GetTempPathA(sizeof (dirBuffer), dir); +- tempFileName = tempFileNameBuffer; +- tempFileName[0] = '\0'; +- GetTempFileNameA(dir, "tki", 0, tempFileName); +- h = CreateFileA(tempFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, +- CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL); +- if (h != INVALID_HANDLE_VALUE) { +- CloseHandle(h); +- } +-#else +- dir = getenv("TMPDIR"); +- tempFileName = tempFileNameBuffer; +- if (dir) { +- strcpy(tempFileName, dir); +- } else { +-#ifdef P_tmpdir +- strcpy(tempFileName, P_tmpdir); +-#else +- strcpy(tempFileName, "/tmp"); +-#endif +- } +- strcat(tempFileName, "/tkimgXXXXXX"); +- result = mkstemp(tempFileName); +- if (result >= 0) { +- close(result); +- } +-#endif +- tif = TIFFOpen(tempFileName,mode); - } + Tcl_DStringInit(&dstring); + tkimg_WriteInit(&dstring, &handle); + tif = TIFFClientOpen("inline data", mode, (thandle_t) &handle, -+ readString, writeString, seekString, closeDummy, -+ sizeString, mapDummy, unMapDummy); ++ readString, writeString, seekString, closeDummy, ++ sizeString, mapDummy, unMapDummy); result = CommonWrite(interp, tif, comp, blockPtr); -@@ -703,7 +600,4 @@ +@@ -775,11 +585,4 @@ if (result != TCL_OK) { -- if (tempFileName) { -- unlink(tempFileName); -- } - Tcl_AppendResult(interp, errorMessage, (char *) NULL); - ckfree(errorMessage); -@@ -712,29 +606,8 @@ +- if (tempFileName) { +-#ifdef WIN32 +- DeleteFileA(tempFileName); +-#else +- unlink(tempFileName); +-#endif +- } + Tcl_AppendResult(interp, errorMessage, (char *) NULL); + ckfree(errorMessage); +@@ -788,43 +591,13 @@ } - if (tempFileName) { -- Tcl_Channel inchan; -- char buffer[1024]; -- inchan = tkimg_OpenFileChannel(interp, tempFileName, 0644); -- if (!inchan) { -- return TCL_ERROR; -- } -- tkimg_WriteInit(&data, &handle); +- FILE *infile; +- char buffer[4096]; - -- result = Tcl_Read(inchan, buffer, 1024); -- while ((result == TCL_OK) && !Tcl_Eof(inchan)) { -- tkimg_Write2(&handle, buffer, result); -- result = Tcl_Read(inchan, buffer, 1024); -- } -- if (result == TCL_OK) { -- tkimg_Write2(&handle, buffer, result); -- result = Tcl_Close(interp, inchan); -- } -- unlink(tempFileName); +- infile = fopen(tempFileName, "rb"); +- if (infile == NULL) { +- Tcl_AppendResult(interp, "error open input file", (char *) NULL); +- return TCL_ERROR; +- } +- tkimg_WriteInit(&data, &handle); +- +- result = fread(buffer, 1, sizeof (buffer), infile); +- while (result > 0) { +- tkimg_Write2(&handle, buffer, result); +- result = fread(buffer, 1, sizeof (buffer), infile); +- } +- if (ferror(infile)) { +- Tcl_AppendResult(interp, "error reading input file", (char *) NULL); +- result = TCL_ERROR; +- } +- fclose(infile); +-#ifdef WIN32 +- DeleteFileA(tempFileName); +-#else +- unlink(tempFileName); +-#endif - } else { -- int length = handle.length; -- tkimg_WriteInit(&data, &handle); -- tkimg_Write2(&handle, Tcl_DStringValue(&dstring), length); -- Tcl_DStringFree(&dstring); +- int length = handle.length; +- tkimg_WriteInit(&data, &handle); +- tkimg_Write2(&handle, Tcl_DStringValue(&dstring), length); +- Tcl_DStringFree(&dstring); - } -+ length = handle.length; ++ int length = handle.length; + tkimg_WriteInit(&data, &handle); -+ tkimg_Write(&handle, Tcl_DStringValue(&dstring), length); ++ tkimg_Write2(&handle, Tcl_DStringValue(&dstring), length); + Tcl_DStringFree(&dstring); ++ tkimg_Putc(IMG_DONE, &handle); - if (result == TCL_OK) { -@@ -956,36 +829,2 @@ - return TCL_OK; +- if (result == TCL_OK) { +- Tcl_DStringResult(interp, &data); +- } else { +- Tcl_DStringFree(&data); +- } +- return result; ++ Tcl_DStringResult(interp, &data); ++ ++ return TCL_OK; } -- --void --TkimgTIFFfree (data) -- tdata_t data; --{ + +@@ -1043,9 +816,5 @@ + TkimgTIFFfree(tdata_t data) + { - if (_TIFFfree) { -- _TIFFfree(data); +- _TIFFfree(data); - } else { -- ckfree((char *) data); +- ckfree((char *) data); - } --} -- --tdata_t --TkimgTIFFmalloc(size) -- tsize_t size; --{ ++ _TIFFfree(data); + } + +@@ -1053,9 +822,5 @@ + TkimgTIFFmalloc(tsize_t size) + { - if (_TIFFmalloc) { -- return _TIFFmalloc(size); +- return _TIFFmalloc(size); - } else { -- return ckalloc(size); +- return attemptckalloc(size); - } --} -- --tdata_t --TkimgTIFFrealloc(data, size) -- tdata_t data; -- tsize_t size; --{ ++ return _TIFFmalloc(size); + } + +@@ -1065,8 +830,4 @@ + tsize_t size + ) { - if (_TIFFrealloc) { -- return _TIFFrealloc(data, size); +- return _TIFFrealloc(data, size); - } else { -- return ckrealloc(data, size); +- return attemptckrealloc(data, size); - } --} ---- tests/tiff.test 2016-07-30 10:31:08.000000000 -0400 -+++ tests/tiff.test 2020-01-20 21:44:30.430340000 -0500 -@@ -22,5 +22,5 @@ - source $file.base64 - -- test tiff-1.1 {} -setup { -+ test tiff-1.1 {} -constraints nonPortable -setup { - catch {image delete i} - } -body { -@@ -31,5 +31,5 @@ - } -result $imgdata - -- test tiff-1.2 {} -setup { -+ test tiff-1.2 {} -constraints nonPortable -setup { - catch {image delete i} - } -body { -@@ -40,5 +40,5 @@ - } -result $imgdata - -- test tiff-1.3 {} -setup { -+ test tiff-1.3 {} -constraints nonPortable -setup { - catch {image delete i} - } -body { -@@ -50,5 +50,5 @@ - } -result $imgdata - -- test tiff-1.4 {} -setup { -+ test tiff-1.4 {} -constraints nonPortable -setup { - catch {image delete i} - } -body { ++ return _TIFFrealloc(data, size); + }