diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2004-03-26 14:34:04 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2004-03-26 14:34:04 (GMT) |
commit | 246e7b68e9ece313df64749d30522c60f7a4b19d (patch) | |
tree | 2e56346380aefd775268df59e1c95838672bceed /generic/tkImgPhoto.c | |
parent | f1f907b161a5731a076878b32c989b4acd4acfdb (diff) | |
download | tk-246e7b68e9ece313df64749d30522c60f7a4b19d.zip tk-246e7b68e9ece313df64749d30522c60f7a4b19d.tar.gz tk-246e7b68e9ece313df64749d30522c60f7a4b19d.tar.bz2 |
Allow old-style image formats to create string representations of photos,
and allow the production of PPM format data in a string. [Bug 923555]
Diffstat (limited to 'generic/tkImgPhoto.c')
-rw-r--r-- | generic/tkImgPhoto.c | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index d5bf02d..936c4b5 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -17,7 +17,7 @@ * Department of Computer Science, * Australian National University. * - * RCS: @(#) $Id: tkImgPhoto.c,v 1.44 2004/02/09 14:48:20 dkf Exp $ + * RCS: @(#) $Id: tkImgPhoto.c,v 1.45 2004/03/26 14:34:05 dkf Exp $ */ #include "tkInt.h" @@ -934,10 +934,12 @@ ImgPhotoCmd(clientData, interp, objc, objv) */ if (options.options & OPT_FORMAT) { + matched = 0; for (imageFormat = tsdPtr->formatList; imageFormat != NULL; imageFormat = imageFormat->nextPtr) { if ((strncasecmp(Tcl_GetString(options.format), imageFormat->name, strlen(imageFormat->name)) == 0)) { + matched = 1; if (imageFormat->stringWriteProc != NULL) { stringWriteProc = imageFormat->stringWriteProc; break; @@ -945,9 +947,25 @@ ImgPhotoCmd(clientData, interp, objc, objv) } } if (stringWriteProc == NULL) { + oldformat = 1; + for (imageFormat = tsdPtr->oldFormatList; imageFormat != NULL; + imageFormat = imageFormat->nextPtr) { + if ((strncasecmp(Tcl_GetString(options.format), + imageFormat->name, + strlen(imageFormat->name)) == 0)) { + matched = 1; + if (imageFormat->stringWriteProc != NULL) { + stringWriteProc = imageFormat->stringWriteProc; + break; + } + } + } + } + if (stringWriteProc == NULL) { Tcl_AppendResult(interp, "image string format \"", - Tcl_GetString(options.format), - "\" is not supported", (char *) NULL); + Tcl_GetString(options.format), "\" is ", + (matched ? "not supported" : "unknown"), + (char *) NULL); return TCL_ERROR; } } else { @@ -961,9 +979,25 @@ ImgPhotoCmd(clientData, interp, objc, objv) data = ImgGetPhoto(masterPtr, &block, &options); - result = ((int (*) _ANSI_ARGS_((Tcl_Interp *interp, Tcl_Obj *formatString, - Tk_PhotoImageBlock *blockPtr, VOID *dummy))) stringWriteProc) - (interp, options.format, &block, (VOID *) NULL); + if (oldformat) { + Tcl_DString buffer; + + Tcl_DStringInit(&buffer); + result = ((int (*) _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_DString *dataPtr, char *formatString, + Tk_PhotoImageBlock *blockPtr))) stringWriteProc) + (interp, &buffer, Tcl_GetString(options.format), &block); + if (result == TCL_OK) { + Tcl_DStringResult(interp, &buffer); + } else { + Tcl_DStringFree(&buffer); + } + } else { + result = ((int (*) _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *formatString, Tk_PhotoImageBlock *blockPtr, + VOID *dummy))) stringWriteProc) + (interp, options.format, &block, (VOID *) NULL); + } if (options.background) { Tk_FreeColor(options.background); } |