summaryrefslogtreecommitdiffstats
path: root/generic/tkImgPNG.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2011-09-27 10:38:26 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2011-09-27 10:38:26 (GMT)
commitb039eb53fbc3db111d347bbb70eb88bb0ff49354 (patch)
tree51fa23b65a2fc9f8e338bf25d399ef93c3b454c3 /generic/tkImgPNG.c
parent6f0061cc623242e99306b0dc9e5642b84be8cef5 (diff)
downloadtk-b039eb53fbc3db111d347bbb70eb88bb0ff49354.zip
tk-b039eb53fbc3db111d347bbb70eb88bb0ff49354.tar.gz
tk-b039eb53fbc3db111d347bbb70eb88bb0ff49354.tar.bz2
* generic/tkImgPNG.c (WriteExtraChunks): [Bug 3405839]: Write the sDAT
chunk with the correct length.
Diffstat (limited to 'generic/tkImgPNG.c')
-rw-r--r--generic/tkImgPNG.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/generic/tkImgPNG.c b/generic/tkImgPNG.c
index d5a0b98..8d6721e 100644
--- a/generic/tkImgPNG.c
+++ b/generic/tkImgPNG.c
@@ -3180,6 +3180,7 @@ WriteExtraChunks(
static const unsigned char sBIT_contents[] = {
8, 8, 8, 8
};
+ int sBIT_length = 4;
Tcl_DString buf;
/*
@@ -3188,7 +3189,23 @@ WriteExtraChunks(
* data model is.
*/
- if (WriteChunk(interp, pngPtr, CHUNK_sBIT, sBIT_contents, 4) != TCL_OK) {
+ switch (pngPtr->colorType) {
+ case PNG_COLOR_GRAY:
+ sBIT_length = 1;
+ break;
+ case PNG_COLOR_GRAYALPHA:
+ sBIT_length = 2;
+ break;
+ case PNG_COLOR_RGB:
+ case PNG_COLOR_PLTE:
+ sBIT_length = 3;
+ break;
+ case PNG_COLOR_RGBA:
+ sBIT_length = 4;
+ break;
+ }
+ if (WriteChunk(interp, pngPtr, CHUNK_sBIT, sBIT_contents, sBIT_length)
+ != TCL_OK) {
return TCL_ERROR;
}