summaryrefslogtreecommitdiffstats
path: root/generic/tkImgPPM.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tkImgPPM.c')
-rw-r--r--generic/tkImgPPM.c90
1 files changed, 41 insertions, 49 deletions
diff --git a/generic/tkImgPPM.c b/generic/tkImgPPM.c
index edd1b71..8a46fde 100644
--- a/generic/tkImgPPM.c
+++ b/generic/tkImgPPM.c
@@ -34,14 +34,14 @@
* The format record for the PPM file format:
*/
-static int FileMatchPPM(Tcl_Channel chan, const char *fileName,
+static int FileMatchPPM(Tcl_Channel chan, CONST char *fileName,
Tcl_Obj *format, int *widthPtr, int *heightPtr,
Tcl_Interp *interp);
static int FileReadPPM(Tcl_Interp *interp, Tcl_Channel chan,
- const char *fileName, Tcl_Obj *format,
+ CONST char *fileName, Tcl_Obj *format,
Tk_PhotoHandle imageHandle, int destX, int destY,
int width, int height, int srcX, int srcY);
-static int FileWritePPM(Tcl_Interp *interp, const char *fileName,
+static int FileWritePPM(Tcl_Interp *interp, CONST char *fileName,
Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
static int StringWritePPM(Tcl_Interp *interp, Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr);
@@ -60,7 +60,6 @@ Tk_PhotoImageFormat tkImgFmtPPM = {
StringReadPPM, /* stringReadProc */
FileWritePPM, /* fileWriteProc */
StringWritePPM, /* stringWriteProc */
- NULL
};
/*
@@ -94,7 +93,7 @@ static int ReadPPMStringHeader(Tcl_Obj *dataObj, int *widthPtr,
static int
FileMatchPPM(
Tcl_Channel chan, /* The image file, open for reading. */
- const char *fileName, /* The name of the image file. */
+ CONST char *fileName, /* The name of the image file. */
Tcl_Obj *format, /* User-specified format string, or NULL. */
int *widthPtr, int *heightPtr,
/* The dimensions of the image are returned
@@ -130,7 +129,7 @@ static int
FileReadPPM(
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. */
+ CONST char *fileName, /* The name of the image file. */
Tcl_Obj *format, /* User-specified format string, or NULL. */
Tk_PhotoHandle imageHandle, /* The photo image to write into. */
int destX, int destY, /* Coordinates of top-left pixel in photo
@@ -147,22 +146,21 @@ FileReadPPM(
type = ReadPPMFileHeader(chan, &fileWidth, &fileHeight, &maxIntensity);
if (type == 0) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "couldn't read raw PPM header from file \"%s\"", fileName));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "NO_HEADER", NULL);
+ Tcl_AppendResult(interp, "couldn't read raw PPM header from file \"",
+ fileName, "\"", NULL);
return TCL_ERROR;
}
if ((fileWidth <= 0) || (fileHeight <= 0)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "PPM image file \"%s\" has dimension(s) <= 0", fileName));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "DIMENSIONS", NULL);
+ Tcl_AppendResult(interp, "PPM image file \"", fileName,
+ "\" has dimension(s) <= 0", NULL);
return TCL_ERROR;
}
if ((maxIntensity <= 0) || (maxIntensity >= 256)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "PPM image file \"%s\" has bad maximum intensity value %d",
- fileName, maxIntensity));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "INTENSITY", NULL);
+ char buffer[TCL_INTEGER_SPACE];
+
+ sprintf(buffer, "%d", maxIntensity);
+ Tcl_AppendResult(interp, "PPM image file \"", fileName,
+ "\" has bad maximum intensity value ", buffer, NULL);
return TCL_ERROR;
}
@@ -209,7 +207,7 @@ FileReadPPM(
nLines = 1;
}
nBytes = nLines * block.pitch;
- pixelPtr = ckalloc(nBytes);
+ pixelPtr = (unsigned char *) ckalloc((unsigned) nBytes);
block.pixelPtr = pixelPtr + srcX * block.pixelSize;
for (h = height; h > 0; h -= nLines) {
@@ -219,13 +217,11 @@ FileReadPPM(
}
count = Tcl_Read(chan, (char *) pixelPtr, nBytes);
if (count != nBytes) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "error reading PPM image file \"%s\": %s", fileName,
- Tcl_Eof(chan)?"not enough data":Tcl_PosixError(interp)));
- if (Tcl_Eof(chan)) {
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "EOF", NULL);
- }
- ckfree(pixelPtr);
+ Tcl_AppendResult(interp, "error reading PPM image file \"",
+ fileName, "\": ",
+ Tcl_Eof(chan) ? "not enough data" : Tcl_PosixError(interp),
+ NULL);
+ ckfree((char *) pixelPtr);
return TCL_ERROR;
}
if (maxIntensity != 255) {
@@ -238,13 +234,13 @@ FileReadPPM(
block.height = nLines;
if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
width, nLines, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
- ckfree(pixelPtr);
+ ckfree((char *) pixelPtr);
return TCL_ERROR;
}
destY += nLines;
}
- ckfree(pixelPtr);
+ ckfree((char *) pixelPtr);
return TCL_OK;
}
@@ -269,7 +265,7 @@ FileReadPPM(
static int
FileWritePPM(
Tcl_Interp *interp,
- const char *fileName,
+ CONST char *fileName,
Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr)
{
@@ -328,8 +324,8 @@ FileWritePPM(
chan = NULL;
writeerror:
- Tcl_SetObjResult(interp, Tcl_ObjPrintf("error writing \"%s\": %s",
- fileName, Tcl_PosixError(interp)));
+ Tcl_AppendResult(interp, "error writing \"", fileName, "\": ",
+ Tcl_PosixError(interp), NULL);
if (chan != NULL) {
Tcl_Close(NULL, chan);
}
@@ -485,22 +481,22 @@ StringReadPPM(
type = ReadPPMStringHeader(dataObj, &fileWidth, &fileHeight,
&maxIntensity, &dataBuffer, &dataSize);
if (type == 0) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "couldn't read raw PPM header from string", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "NO_HEADER", NULL);
+ Tcl_AppendResult(interp, "couldn't read raw PPM header from string",
+ NULL);
return TCL_ERROR;
}
if ((fileWidth <= 0) || (fileHeight <= 0)) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "PPM image data has dimension(s) <= 0", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "DIMENSIONS", NULL);
+ Tcl_AppendResult(interp, "PPM image data has dimension(s) <= 0",
+ NULL);
return TCL_ERROR;
}
if ((maxIntensity <= 0) || (maxIntensity >= 256)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "PPM image data has bad maximum intensity value %d",
- maxIntensity));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "INTENSITY", NULL);
+ char buffer[TCL_INTEGER_SPACE];
+
+ sprintf(buffer, "%d", maxIntensity);
+ Tcl_AppendResult(interp,
+ "PPM image data has bad maximum intensity value ", buffer,
+ NULL);
return TCL_ERROR;
}
@@ -541,9 +537,7 @@ StringReadPPM(
*/
if (block.pitch*height > dataSize) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "truncated PPM data", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "TRUNCATED", NULL);
+ Tcl_AppendResult(interp, "truncated PPM data", NULL);
return TCL_ERROR;
}
block.pixelPtr = dataBuffer + srcX * block.pixelSize;
@@ -565,7 +559,7 @@ StringReadPPM(
nLines = 1;
}
nBytes = nLines * block.pitch;
- pixelPtr = ckalloc(nBytes);
+ pixelPtr = (unsigned char *) ckalloc((unsigned) nBytes);
block.pixelPtr = pixelPtr + srcX * block.pixelSize;
for (h = height; h > 0; h -= nLines) {
@@ -576,10 +570,8 @@ StringReadPPM(
nBytes = nLines * block.pitch;
}
if (dataSize < nBytes) {
- ckfree(pixelPtr);
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "truncated PPM data", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PPM", "TRUNCATED", NULL);
+ ckfree((char *) pixelPtr);
+ Tcl_AppendResult(interp, "truncated PPM data", NULL);
return TCL_ERROR;
}
for (p=pixelPtr,count=nBytes ; count>0 ; count--,p++,dataBuffer++) {
@@ -589,13 +581,13 @@ StringReadPPM(
block.height = nLines;
if (Tk_PhotoPutBlock(interp, imageHandle, &block, destX, destY,
width, nLines, TK_PHOTO_COMPOSITE_SET) != TCL_OK) {
- ckfree(pixelPtr);
+ ckfree((char *) pixelPtr);
return TCL_ERROR;
}
destY += nLines;
}
- ckfree(pixelPtr);
+ ckfree((char *) pixelPtr);
return TCL_OK;
}