summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tkImgGIF.c15
-rw-r--r--generic/tkImgPNG.c74
2 files changed, 48 insertions, 41 deletions
diff --git a/generic/tkImgGIF.c b/generic/tkImgGIF.c
index 9b70344..6368972 100644
--- a/generic/tkImgGIF.c
+++ b/generic/tkImgGIF.c
@@ -704,6 +704,7 @@ FileReadGIF(
}
if ((width > 0) && (height > 0)) {
+ unsigned char* pixelPtr;
Tk_PhotoImageBlock block;
int transparent = -1;
if (gifGraphicControlExtensionBlock.blockPresent) {
@@ -729,23 +730,25 @@ FileReadGIF(
goto error;
}
nBytes = block.pitch * imageHeight;
- block.pixelPtr = (unsigned char *)ckalloc(nBytes);
- if (block.pixelPtr) {
- memset(block.pixelPtr, 0, nBytes);
+ pixelPtr = (unsigned char*)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 5eb85a7..2879ae2 100644
--- a/generic/tkImgPNG.c
+++ b/generic/tkImgPNG.c
@@ -205,7 +205,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,
Tcl_Obj *metadataInObj);
@@ -2476,14 +2477,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 result;
Tcl_Size chunkSz;
unsigned long crc;
@@ -2631,8 +2637,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;
}
@@ -2786,13 +2792,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;
}
/*
@@ -2862,21 +2867,19 @@ FileMatchPNG(
static int
FileReadPNG(
- Tcl_Interp *interp, /* Interpreter to use for reporting errors. */
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
Tcl_Channel chan, /* The image file, open for reading. */
- TCL_UNUSED(const char *), /* The name of the image file. */
+ TCL_UNUSED(const char*), /* The name of the image file. */
Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be 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. */
- TCL_UNUSED(int), /* Dimensions of block of photo image to be
+ int width, int height, /* Dimensions of block of photo image to be
* written to. */
- TCL_UNUSED(int),
- TCL_UNUSED(int), /* Coordinates of top-left pixel to be used in
+ int srcX, int srcY, /* Coordinates of top-left pixel to be used in
* image being read. */
- TCL_UNUSED(int),
- Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
+ Tcl_Obj* metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
int result = TCL_ERROR;
@@ -2884,7 +2887,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);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {
@@ -2968,16 +2971,17 @@ StringMatchPNG(
static int
StringReadPNG(
- Tcl_Interp *interp, /* interpreter for reporting errors in */
- Tcl_Obj *pObjData, /* object containing the image */
- Tcl_Obj *fmtObj, /* format object, or NULL */
- TCL_UNUSED(Tcl_Obj *), /* metadata input, may be NULL */
- Tk_PhotoHandle imageHandle, /* the image to write this data into */
- int destX, int destY, /* The rectangular region of the */
- TCL_UNUSED(int), /* image to copy */
- TCL_UNUSED(int),
- TCL_UNUSED(int),
- TCL_UNUSED(int),
+ Tcl_Interp* interp, /* Interpreter to use for reporting errors. */
+ Tcl_Obj *pObjData,
+ Tcl_Obj *fmtObj, /* User-specified format object, or NULL. */
+ TCL_UNUSED(Tcl_Obj*), /* metadata input, may be 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. */
Tcl_Obj *metadataOutObj) /* metadata return dict, may be NULL */
{
PNGImage png;
@@ -2987,7 +2991,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);
}
if (TCL_OK == result && metadataOutObj != NULL && png.DPI != -1) {