diff options
Diffstat (limited to 'tk/generic/tkImgPPM.c')
-rw-r--r-- | tk/generic/tkImgPPM.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/tk/generic/tkImgPPM.c b/tk/generic/tkImgPPM.c index 02309eb6588..8e5d17aee2b 100644 --- a/tk/generic/tkImgPPM.c +++ b/tk/generic/tkImgPPM.c @@ -16,6 +16,8 @@ * RCS: @(#) $Id$ */ +#define USE_OLD_IMAGE + #include "tkInt.h" #include "tkPort.h" @@ -110,7 +112,7 @@ FileMatchPPM(chan, fileName, formatString, widthPtr, heightPtr) * * Results: * A standard TCL completion code. If TCL_ERROR is returned - * then an error message is left in interp->result. + * then an error message is left in the interp's result. * * Side effects: * The access position in file f is changed, and new data is @@ -151,7 +153,7 @@ FileReadPPM(interp, chan, fileName, formatString, imageHandle, destX, destY, return TCL_ERROR; } if ((maxIntensity <= 0) || (maxIntensity >= 256)) { - char buffer[30]; + char buffer[TCL_INTEGER_SPACE]; sprintf(buffer, "%d", maxIntensity); Tcl_AppendResult(interp, "PPM image file \"", fileName, @@ -183,6 +185,7 @@ FileReadPPM(interp, chan, fileName, formatString, imageHandle, destX, destY, block.offset[1] = 1; block.offset[2] = 2; } + block.offset[3] = 0; block.width = width; block.pitch = block.pixelSize * fileWidth; @@ -243,7 +246,7 @@ FileReadPPM(interp, chan, fileName, formatString, imageHandle, destX, destY, * * Results: * A standard TCL completion code. If TCL_ERROR is returned - * then an error message is left in interp->result. + * then an error message is left in the interp's result. * * Side effects: * Data is written to the file given by "fileName". @@ -262,13 +265,22 @@ FileWritePPM(interp, fileName, formatString, blockPtr) int w, h; int greenOffset, blueOffset, nBytes; unsigned char *pixelPtr, *pixLinePtr; - char header[30]; + char header[16 + TCL_INTEGER_SPACE * 2]; chan = Tcl_OpenFileChannel(interp, fileName, "w", 0666); if (chan == NULL) { return TCL_ERROR; } + if (Tcl_SetChannelOption(interp, chan, "-translation", "binary") + != TCL_OK) { + return TCL_ERROR; + } + if (Tcl_SetChannelOption(interp, chan, "-encoding", "binary") + != TCL_OK) { + return TCL_ERROR; + } + sprintf(header, "P6\n%d %d\n255\n", blockPtr->width, blockPtr->height); Tcl_Write(chan, header, -1); @@ -343,7 +355,7 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) { #define BUFFER_SIZE 1000 char buffer[BUFFER_SIZE]; - int i, numFields, firstInLine; + int i, numFields; int type = 0; char c; @@ -355,7 +367,6 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) if (Tcl_Read(chan, &c, 1) != 1) { return 0; } - firstInLine = 1; i = 0; for (numFields = 0; numFields < 4; numFields++) { /* @@ -364,7 +375,6 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) while (1) { while (isspace(UCHAR(c))) { - firstInLine = (c == '\n'); if (Tcl_Read(chan, &c, 1) != 1) { return 0; } @@ -377,7 +387,6 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) return 0; } } while (c != '\n'); - firstInLine = 1; } /* @@ -397,7 +406,6 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) buffer[i] = ' '; i++; } - firstInLine = 0; } done: buffer[i] = 0; @@ -419,3 +427,4 @@ ReadPPMFileHeader(chan, widthPtr, heightPtr, maxIntensityPtr) } return type; } + |