diff options
-rw-r--r-- | generic/tkImgPNG.c | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/generic/tkImgPNG.c b/generic/tkImgPNG.c index 83406d9..c44c7fe 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; /* @@ -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); |