diff options
author | fvogel <fvogelnew1@free.fr> | 2024-06-11 03:17:35 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2024-06-11 03:17:35 (GMT) |
commit | 15dc2cfa976b10c2dcd29e446a331a7d7f04b790 (patch) | |
tree | 44df2ad1b11369807463f910f8ac4a6702bb0edf /generic | |
parent | 13ad83e207e848df4017b03f3f51087b16c2b079 (diff) | |
parent | f59389521788b120e5293872c26ececc0724b294 (diff) | |
download | tk-15dc2cfa976b10c2dcd29e446a331a7d7f04b790.zip tk-15dc2cfa976b10c2dcd29e446a331a7d7f04b790.tar.gz tk-15dc2cfa976b10c2dcd29e446a331a7d7f04b790.tar.bz2 |
Fix [1576528fff]: image read file with -from option.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkImgGIF.c | 15 | ||||
-rw-r--r-- | generic/tkImgPNG.c | 80 |
2 files changed, 51 insertions, 44 deletions
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c index 3467bd5..7e237fa 100644 --- a/generic/tkImgGIF.c +++ b/generic/tkImgGIF.c @@ -677,6 +677,7 @@ FileReadGIF( } if ((width > 0) && (height > 0)) { + unsigned char* pixelPtr; Tk_PhotoImageBlock block; /* @@ -699,23 +700,25 @@ FileReadGIF( goto error; } nBytes = block.pitch * imageHeight; - block.pixelPtr = ckalloc(nBytes); - if (block.pixelPtr) { - memset(block.pixelPtr, 0, nBytes); + pixelPtr = ckalloc(nBytes); + if (pixelPtr) { + memset(pixelPtr, 0, nBytes); } + block.pixelPtr = pixelPtr; if (ReadImage(gifConfPtr, interp, block.pixelPtr, chan, imageWidth, imageHeight, colorMap, srcX, srcY, BitSet(buf[8], INTERLACE), transparent) != TCL_OK) { - ckfree(block.pixelPtr); + ckfree(pixelPtr); goto error; } + block.pixelPtr += srcX * block.pixelSize + srcY * block.pitch; if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY, width, height, TK_PHOTO_COMPOSITE_SET) != TCL_OK) { - ckfree(block.pixelPtr); + ckfree(pixelPtr); goto error; } - ckfree(block.pixelPtr); + ckfree(pixelPtr); } /* diff --git a/generic/tkImgPNG.c b/generic/tkImgPNG.c index 83406d9..fccb465 100644 --- a/generic/tkImgPNG.c +++ b/generic/tkImgPNG.c @@ -196,7 +196,8 @@ static void CleanupPNGImage(PNGImage *pngPtr); static int DecodeLine(Tcl_Interp *interp, PNGImage *pngPtr); static int DecodePNG(Tcl_Interp *interp, PNGImage *pngPtr, Tcl_Obj *fmtObj, Tk_PhotoHandle imageHandle, - int destX, int destY); + int destX, int destY, int width, int height, + int srcX, int srcY); static int EncodePNG(Tcl_Interp *interp, Tk_PhotoImageBlock *blockPtr, PNGImage *pngPtr); static int FileMatchPNG(Tcl_Channel chan, const char *fileName, @@ -2374,15 +2375,19 @@ ParseFormat( static int DecodePNG( - Tcl_Interp *interp, - PNGImage *pngPtr, - Tcl_Obj *fmtObj, - Tk_PhotoHandle imageHandle, - int destX, - int destY) + Tcl_Interp *interp, /* Interpreter to use for reporting errors. */ + PNGImage *pngPtr, /* PNG image information record. */ + Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */ + Tk_PhotoHandle imageHandle, /* The photo image to write into. */ + int destX, int destY, /* Coordinates of top-left pixel in photo + * image to be written to. */ + int width, int height, /* Dimensions of block of photo image to be + * written to. */ + int srcX, int srcY) /* Coordinates of top-left pixel to be used in + * image being read. */ { unsigned long chunkType; - int chunkSz; + int result, chunkSz; unsigned long crc; /* @@ -2483,8 +2488,8 @@ DecodePNG( * to negative here: Tk will not shrink the image. */ - if (Tk_PhotoExpand(interp, imageHandle, destX + pngPtr->block.width, - destY + pngPtr->block.height) == TCL_ERROR) { + if (Tk_PhotoExpand(interp, imageHandle, destX + width, + destY + height) == TCL_ERROR) { return TCL_ERROR; } @@ -2638,13 +2643,12 @@ DecodePNG( * Copy the decoded image block into the Tk photo image. */ - if (Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY, - pngPtr->block.width, pngPtr->block.height, - TK_PHOTO_COMPOSITE_SET) == TCL_ERROR) { - return TCL_ERROR; - } + pngPtr->block.pixelPtr += srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch; + result = Tk_PhotoPutBlock(interp, imageHandle, &pngPtr->block, destX, destY, + width, height, TK_PHOTO_COMPOSITE_SET); + pngPtr->block.pixelPtr -= srcX * pngPtr->block.pixelSize + srcY * pngPtr->block.pitch; - return TCL_OK; + return result; } /* @@ -2711,17 +2715,17 @@ FileMatchPNG( static int FileReadPNG( - Tcl_Interp *interp, - Tcl_Channel chan, - const char *fileName, - Tcl_Obj *fmtObj, - Tk_PhotoHandle imageHandle, - int destX, - int destY, - int width, - int height, - int srcX, - int srcY) + Tcl_Interp* interp, /* Interpreter to use for reporting errors. */ + Tcl_Channel chan, /* The image file, open for reading. */ + const char* fileName, /* The name of the image file. */ + Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */ + Tk_PhotoHandle imageHandle, /* The photo image to write into. */ + int destX, int destY, /* Coordinates of top-left pixel in photo + * image to be written to. */ + int width, int height, /* Dimensions of block of photo image to be + * written to. */ + int srcX, int srcY) /* Coordinates of top-left pixel to be used in + * image being read. */ { PNGImage png; int result = TCL_ERROR; @@ -2729,7 +2733,7 @@ FileReadPNG( result = InitPNGImage(interp, &png, chan, NULL, TCL_ZLIB_STREAM_INFLATE); if (TCL_OK == result) { - result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY); + result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY); } CleanupPNGImage(&png); @@ -2799,16 +2803,16 @@ StringMatchPNG( static int StringReadPNG( - Tcl_Interp *interp, + Tcl_Interp* interp, /* Interpreter to use for reporting errors. */ Tcl_Obj *pObjData, - Tcl_Obj *fmtObj, - Tk_PhotoHandle imageHandle, - int destX, - int destY, - int width, - int height, - int srcX, - int srcY) + Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */ + Tk_PhotoHandle imageHandle, /* The photo image to write into. */ + int destX, int destY, /* Coordinates of top-left pixel in photo + * image to be written to. */ + int width, int height, /* Dimensions of block of photo image to be + * written to. */ + int srcX, int srcY) /* Coordinates of top-left pixel to be used in + * image being read. */ { PNGImage png; int result = TCL_ERROR; @@ -2817,7 +2821,7 @@ StringReadPNG( TCL_ZLIB_STREAM_INFLATE); if (TCL_OK == result) { - result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY); + result = DecodePNG(interp, &png, fmtObj, imageHandle, destX, destY, width, height, srcX, srcY); } CleanupPNGImage(&png); |