summaryrefslogtreecommitdiffstats
path: root/doc
ModeNameSize
-rw-r--r--Access.32978logstatsplain
-rw-r--r--AddErrInfo.313774logstatsplain
-rw-r--r--Alloc.33049logstatsplain
-rw-r--r--AllowExc.31610logstatsplain
-rw-r--r--AppInit.33000logstatsplain
-rw-r--r--AssocData.33541logstatsplain
-rw-r--r--Async.36733logstatsplain
-rw-r--r--BackgdErr.33164logstatsplain
-rw-r--r--Backslash.31446logstatsplain
-rw-r--r--BoolObj.33718logstatsplain
-rw-r--r--ByteArrObj.34130logstatsplain
-rw-r--r--CallDel.32506logstatsplain
-rw-r--r--Cancel.32845logstatsplain
-rw-r--r--ChnlStack.33889logstatsplain
-rw-r--r--Class.310378logstatsplain
-rw-r--r--CmdCmplt.3970logstatsplain
-rw-r--r--Concat.31738logstatsplain
-rw-r--r--CrtChannel.339447logstatsplain
-rw-r--r--CrtChnlHdlr.33743logstatsplain
-rw-r--r--CrtCloseHdlr.31790logstatsplain
-rw-r--r--CrtCommand.36315logstatsplain
-rw-r--r--CrtFileHdlr.33602logstatsplain
-rw-r--r--CrtInterp.37038logstatsplain
-rw-r--r--CrtMathFnc.37052logstatsplain
-rw-r--r--CrtObjCmd.313189logstatsplain
-rw-r--r--CrtSlave.310140logstatsplain
-rw-r--r--CrtTimerHdlr.32878logstatsplain
-rw-r--r--CrtTrace.38528logstatsplain
-rw-r--r--DString.36076logstatsplain
-rw-r--r--DetachPids.33080logstatsplain
-rw-r--r--DictObj.310592logstatsplain
-rw-r--r--DoOneEvent.34135logstatsplain
-rw-r--r--DoWhenIdle.33419logstatsplain
-rw-r--r--DoubleObj.32632logstatsplain
-rw-r--r--DumpActiveMemory.32261logstatsplain
-rw-r--r--Encoding.326823logstatsplain
-rw-r--r--Ensemble.39479logstatsplain
-rw-r--r--Environment.31062logstatsplain
-rw-r--r--Eval.38762logstatsplain
-rw-r--r--Exit.35976logstatsplain
-rw-r--r--ExprLong.33688logstatsplain
-rw-r--r--ExprLongObj.33695logstatsplain
-rw-r--r--FileSystem.368661logstatsplain
-rw-r--r--FindExec.32379logstatsplain
-rw-r--r--GetCwd.31722logstatsplain
-rw-r--r--GetHostName.3643logstatsplain
-rw-r--r--GetIndex.34709logstatsplain
-rw-r--r--GetInt.33739logstatsplain
-rw-r--r--GetOpnFl.32105logstatsplain
-rw-r--r--GetStdChan.33598logstatsplain
-rw-r--r--GetTime.34374logstatsplain
-rw-r--r--GetVersion.31628logstatsplain
-rw-r--r--Hash.313586logstatsplain
-rw-r--r--Init.3719logstatsplain
-rw-r--r--InitStubs.33521logstatsplain
-rw-r--r--IntObj.36358logstatsplain
-rw-r--r--Interp.36057logstatsplain
-rw-r--r--Limit.37857logstatsplain
-rw-r--r--LinkVar.310474logstatsplain
-rw-r--r--ListObj.310377logstatsplain
-rw-r--r--Load.32880logstatsplain
-rw-r--r--Method.310672logstatsplain
-rw-r--r--NRE.312973logstatsplain
-rw-r--r--Namespace.36382logstatsplain
-rw-r--r--Notifier.329835logstatsplain
-rw-r--r--OOInitStubs.31976logstatsplain
-rw-r--r--Object.314136logstatsplain
-rw-r--r--ObjectType.310441logstatsplain
-rw-r--r--OpenFileChnl.331262logstatsplain
-rw-r--r--OpenTcp.38121logstatsplain
-rw-r--r--Panic.33398logstatsplain
-rw-r--r--ParseArgs.37238logstatsplain
-rw-r--r--ParseCmd.321093logstatsplain
-rw-r--r--PkgRequire.33417logstatsplain
-rw-r--r--Preserve.34562logstatsplain
-rw-r--r--PrintDbl.31908logstatsplain
-rw-r--r--RecEvalObj.31929logstatsplain
-rw-r--r--RecordEval.32056logstatsplain
-rw-r--r--RegConfig.34344logstatsplain
-rw-r--r--RegExp.315239logstatsplain
-rw-r--r--SaveResult.35315logstatsplain
-rw-r--r--SetChanErr.36190logstatsplain
-rw-r--r--SetErrno.32091logstatsplain
-rw-r--r--SetRecLmt.31861logstatsplain
-rw-r--r--SetResult.310698logstatsplain
-rw-r--r--SetVar.310295logstatsplain
-rw-r--r--Signal.31005logstatsplain
-rw-r--r--Sleep.31066logstatsplain
-rw-r--r--SourceRCFile.3847logstatsplain
-rw-r--r--SplitList.37676logstatsplain
-rw-r--r--SplitPath.33410logstatsplain
-rw-r--r--StaticPkg.32897logstatsplain
-rw-r--r--StdChannels.34853logstatsplain
-rw-r--r--StrMatch.31623logstatsplain
-rw-r--r--StringObj.316931logstatsplain
-rw-r--r--SubstObj.32750logstatsplain
-rw-r--r--TCL_MEM_DEBUG.33706logstatsplain
-rw-r--r--Tcl.n10670logstatsplain
-rw-r--r--TclZlib.312642logstatsplain
-rw-r--r--Tcl_Main.38911logstatsplain
-rw-r--r--Thread.39825logstatsplain
-rw-r--r--ToUpper.32987logstatsplain
-rw-r--r--TraceCmd.36779logstatsplain
-rw-r--r--TraceVar.316871logstatsplain
-rw-r--r--Translate.32873logstatsplain
-rw-r--r--UniCharIsAlpha.32614logstatsplain
-rw-r--r--UpVar.32873logstatsplain
-rw-r--r--Utf.310878logstatsplain
-rw-r--r--WrongNumArgs.32877logstatsplain
-rw-r--r--after.n5586logstatsplain
-rw-r--r--append.n1313logstatsplain
-rw-r--r--apply.n3290logstatsplain
-rw-r--r--array.n7682logstatsplain
-rw-r--r--bgerror.n4069logstatsplain
-rw-r--r--binary.n35238logstatsplain
-rw-r--r--break.n1340logstatsplain
-rw-r--r--case.n2557logstatsplain
-rw-r--r--catch.n5630logstatsplain
-rw-r--r--cd.n1143logstatsplain
-rw-r--r--chan.n39581logstatsplain
-rw-r--r--class.n4859logstatsplain
-rw-r--r--clock.n40926logstatsplain
-rw-r--r--close.n4361logstatsplain
-rw-r--r--concat.n1685logstatsplain
-rw-r--r--continue.n1368logstatsplain
-rw-r--r--copy.n2463logstatsplain
-rw-r--r--coroutine.n6650logstatsplain
-rw-r--r--dde.n8190logstatsplain
-rw-r--r--define.n17160logstatsplain
-rw-r--r--dict.n18906logstatsplain
-rw-r--r--encoding.n4565logstatsplain
-rw-r--r--eof.n1585logstatsplain
-rw-r--r--error.n2382logstatsplain
-rw-r--r--eval.n2764logstatsplain
-rw-r--r--exec.n15938logstatsplain
-rw-r--r--exit.n1375logstatsplain
-rw-r--r--expr.n13922logstatsplain
-rw-r--r--fblocked.n2365logstatsplain
-rw-r--r--fconfigure.n12331logstatsplain
-rw-r--r--fcopy.n6620logstatsplain
-rw-r--r--file.n22223logstatsplain
-rw-r--r--fileevent.n6677logstatsplain
-rw-r--r--filename.n7485logstatsplain
-rw-r--r--flush.n1562logstatsplain
-rw-r--r--for.n2957logstatsplain
-rw-r--r--foreach.n3221logstatsplain
-rw-r--r--format.n10591logstatsplain
-rw-r--r--gets.n2518logstatsplain
-rw-r--r--glob.n8472logstatsplain
-rw-r--r--global.n1868logstatsplain
-rw-r--r--history.n4191logstatsplain
-rw-r--r--http.n22046logstatsplain
-rw-r--r--if.n2432logstatsplain
-rw-r--r--incr.n1663logstatsplain
-rw-r--r--info.n29598logstatsplain
-rw-r--r--interp.n43069logstatsplain
-rw-r--r--join.n1176logstatsplain
-rw-r--r--lappend.n1519logstatsplain
-rw-r--r--lassign.n1879logstatsplain
-rw-r--r--library.n14670logstatsplain
-rw-r--r--lindex.n3338logstatsplain
-rw-r--r--linsert.n2159logstatsplain
-rw-r--r--list.n1627logstatsplain
-rw-r--r--llength.n1305logstatsplain
-rw-r--r--lmap.n3103logstatsplain
-rw-r--r--load.n7994logstatsplain
-rw-r--r--lrange.n2220logstatsplain
-rw-r--r--lrepeat.n1173logstatsplain
-rw-r--r--lreplace.n2844logstatsplain
-rw-r--r--lreverse.n858logstatsplain
-rw-r--r--lsearch.n7264logstatsplain
-rw-r--r--lset.n4479logstatsplain
-rw-r--r--lsort.n7528logstatsplain
-rw-r--r--man.macros5810logstatsplain
-rw-r--r--mathfunc.n9608logstatsplain
-rw-r--r--mathop.n10917logstatsplain
-rw-r--r--memory.n4592logstatsplain
-rw-r--r--msgcat.n23444logstatsplain
-rw-r--r--my.n1649logstatsplain
-rw-r--r--namespace.n36146logstatsplain
-rw-r--r--next.n7635logstatsplain
-rw-r--r--object.n4976logstatsplain
-rw-r--r--open.n16765logstatsplain
-rw-r--r--package.n13703logstatsplain
-rw-r--r--packagens.n1921logstatsplain
-rw-r--r--pid.n1525logstatsplain
-rw-r--r--pkgMkIndex.n10622logstatsplain
-rw-r--r--platform.n3285logstatsplain
-rw-r--r--platform_shell.n2241logstatsplain
-rw-r--r--prefix.n3335logstatsplain
-rw-r--r--proc.n4992logstatsplain
-rw-r--r--puts.n3432logstatsplain
-rw-r--r--pwd.n1170logstatsplain
-rw-r--r--re_syntax.n27862logstatsplain
-rw-r--r--read.n3572logstatsplain
-rw-r--r--refchan.n15177logstatsplain
-rw-r--r--regexp.n6972logstatsplain
-rw-r--r--registry.n7821logstatsplain
-rw-r--r--regsub.n6082logstatsplain
-rw-r--r--rename.n1442logstatsplain
-rw-r--r--return.n13408logstatsplain
-rw-r--r--safe.n15497logstatsplain
-rw-r--r--scan.n11354logstatsplain
-rw-r--r--seek.n2868logstatsplain
-rw-r--r--self.n5285logstatsplain
-rw-r--r--set.n2494logstatsplain
-rw-r--r--socket.n10045logstatsplain
-rw-r--r--source.n2235logstatsplain
-rw-r--r--split.n2668logstatsplain
-rw-r--r--string.n19059logstatsplain
-rw-r--r--subst.n4740logstatsplain
-rw-r--r--switch.n6571logstatsplain
-rw-r--r--tailcall.n1934logstatsplain
-rw-r--r--tclsh.16072logstatsplain
-rw-r--r--tcltest.n46677logstatsplain
-rw-r--r--tclvars.n21741logstatsplain
-rw-r--r--tell.n1580logstatsplain
-rw-r--r--throw.n1759logstatsplain
-rw-r--r--time.n1145logstatsplain
-rw-r--r--tm.n10655logstatsplain
-rw-r--r--trace.n18100logstatsplain
-rw-r--r--transchan.n6748logstatsplain
-rw-r--r--try.n4048logstatsplain
-rw-r--r--unknown.n4130logstatsplain
-rw-r--r--unload.n7347logstatsplain
-rw-r--r--unset.n2221logstatsplain
-rw-r--r--update.n2332logstatsplain
-rw-r--r--uplevel.n4020logstatsplain
-rw-r--r--upvar.n4669logstatsplain
-rw-r--r--variable.n3224logstatsplain
-rw-r--r--vwait.n7036logstatsplain
-rw-r--r--while.n2210logstatsplain
-rw-r--r--zlib.n15552logstatsplain
- return TCL_OK;
- }
- if (options.options & OPT_FORMAT) {
- return TCL_ERROR;
- }
- Tcl_ResetResult(interp);
- if (Tcl_ListObjGetElements(interp, options.name,
- &dataHeight, &srcObjv) != TCL_OK) {
+ /*
+ * See if there's a format that can read the data
+ */
+
+ if (MatchStringFormat(interp, objv[2], options.format, &imageFormat,
+ &imageWidth, &imageHeight, &oldformat) != TCL_OK) {
return TCL_ERROR;
}
- tkwin = Tk_MainWindow(interp);
- block.pixelPtr = NULL;
- dataWidth = 0;
- pixelPtr = NULL;
- for (y = 0; y < dataHeight; ++y) {
- if (Tcl_ListObjGetElements(interp, srcObjv[y],
- &listObjc, &listObjv) != TCL_OK) {
- break;
- }
- if (y == 0) {
- if (listObjc == 0) {
- /*
- * Lines must be non-empty...
- */
-
- break;
- }
- dataWidth = listObjc;
- /*
- * Memory allocation overflow protection.
- * May not be able to trigger/ demo / test this.
- */
-
- if (dataWidth > (int)((UINT_MAX/3) / dataHeight)) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "photo image dimensions exceed Tcl memory limits", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
- "OVERFLOW", NULL);
- break;
- }
-
- pixelPtr = ckalloc(dataWidth * dataHeight * 3);
- block.pixelPtr = pixelPtr;
- } else if (listObjc != dataWidth) {
- Tcl_SetObjResult(interp, Tcl_NewStringObj(
- "all elements of color list must have the same"
- " number of elements", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
- "NON_RECTANGULAR", NULL);
- break;
- }
-
- for (x = 0; x < dataWidth; ++x) {
- const char *colorString = Tcl_GetString(listObjv[x]);
- XColor color;
- int tmpr, tmpg, tmpb;
-
- /*
- * We do not use Tk_GetColorFromObj() because we absolutely do
- * not want to invoke the fallback code.
- */
-
- if (colorString[0] == '#') {
- if (isxdigit(UCHAR(colorString[1])) &&
- isxdigit(UCHAR(colorString[2])) &&
- isxdigit(UCHAR(colorString[3]))) {
- if (colorString[4] == '\0') {
- /* Got #rgb */
- sscanf(colorString+1, "%1x%1x%1x",
- &tmpr, &tmpg, &tmpb);
- *pixelPtr++ = tmpr * 0x11;
- *pixelPtr++ = tmpg * 0x11;
- *pixelPtr++ = tmpb * 0x11;
- continue;
- } else if (isxdigit(UCHAR(colorString[4])) &&
- isxdigit(UCHAR(colorString[5])) &&
- isxdigit(UCHAR(colorString[6])) &&
- colorString[7] == '\0') {
- /* Got #rrggbb */
- sscanf(colorString+1, "%2x%2x%2x",
- &tmpr, &tmpg, &tmpb);
- *pixelPtr++ = tmpr;
- *pixelPtr++ = tmpg;
- *pixelPtr++ = tmpb;
- continue;
- }
- }
- }
-
- if (!TkParseColor(Tk_Display(tkwin), Tk_Colormap(tkwin),
- colorString, &color)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "can't parse color \"%s\"", colorString));
- Tcl_SetErrorCode(interp, "TK", "VALUE", "COLOR", NULL);
- break;
- }
- *pixelPtr++ = color.red >> 8;
- *pixelPtr++ = color.green >> 8;
- *pixelPtr++ = color.blue >> 8;
- }
- if (x < dataWidth) {
- break;
- }
+ if (!(options.options & OPT_TO) || (options.toX2 < 0)) {
+ options.toX2 = options.toX + imageWidth;
+ options.toY2 = options.toY + imageHeight;
}
- if (y < dataHeight || dataHeight == 0 || dataWidth == 0) {
- if (block.pixelPtr != NULL) {
- ckfree(block.pixelPtr);
- }
- if (y < dataHeight) {
- return TCL_ERROR;
+ if (imageWidth > options.toX2 - options.toX) {
+ imageWidth = options.toX2 - options.toX;
+ }
+ if (imageHeight > options.toY2 - options.toY) {
+ imageHeight = options.toY2 - options.toY;
+ }
+ format = options.format;
+ data = objv[2];
+ if (oldformat) {
+ if (format) {
+ format = (Tcl_Obj *) Tcl_GetString(format);
}
- return TCL_OK;
+ data = (Tcl_Obj *) Tcl_GetString(data);
}
+ if (imageFormat->stringReadProc(interp, data, format,
+ (Tk_PhotoHandle) masterPtr, options.toX, options.toY,
+ options.toX2 - options.toX,
+ options.toY2 - options.toY, 0, 0) != TCL_OK) {
+ return TCL_ERROR;
+ }
/*
- * Fill in default values for the -to option, then copy the block in
- * using Tk_PhotoPutBlock.
+ * SB: is the next line really needed? The stringReadProc
+ * writes image data with Tk_PhotoPutBlock(), which in turn
+ * takes care to notify the changed image and to set/unset the
+ * IMAGE_CHANGED bit.
*/
-
- if (!(options.options & OPT_TO) || (options.toX2 < 0)) {
- options.toX2 = options.toX + dataWidth;
- options.toY2 = options.toY + dataHeight;
- }
- block.width = dataWidth;
- block.height = dataHeight;
- block.pitch = dataWidth * 3;
- block.pixelSize = 3;
- block.offset[0] = 0;
- block.offset[1] = 1;
- block.offset[2] = 2;
- block.offset[3] = 0;
- result = Tk_PhotoPutBlock(interp, masterPtr, &block,
- options.toX, options.toY, options.toX2 - options.toX,
- options.toY2 - options.toY,
- TK_PHOTO_COMPOSITE_SET);
- ckfree(block.pixelPtr);
- return result;
-
+ masterPtr->flags |= IMAGE_CHANGED;
+
+ return TCL_OK;
+ }
case PHOTO_READ: {
Tcl_Obj *format;
@@ -1168,17 +1077,40 @@ ImgPhotoCmd(
switch ((enum transOptions) index) {
case PHOTO_TRANS_GET: {
- XRectangle testBox;
- TkRegion testRegion;
+ int boolMode;
- if (objc != 5) {
- Tcl_WrongNumArgs(interp, 3, objv, "x y");
+ /*
+ * parse fixed args and option
+ */
+
+ if (objc > 6 || objc < 5) {
+ Tcl_WrongNumArgs(interp, 3, objv, "x y ?-option?");
return TCL_ERROR;
}
if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
return TCL_ERROR;
}
+
+ index = 4;
+ memset(&options, 0, sizeof(options));
+ if (ParseSubcommandOptions(&options, interp,
+ OPT_ALPHA, &index, objc, objv) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (index < objc) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "unknown option \"%s\": must be -alpha",
+ Tcl_GetString(objv[index])));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION",
+ NULL);
+ return TCL_ERROR;
+ }
+ boolMode = 1;
+ if (options.options & OPT_ALPHA) {
+ boolMode = 0;
+ }
+
if ((x < 0) || (x >= masterPtr->width)
|| (y < 0) || (y >= masterPtr->height)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -1189,36 +1121,55 @@ ImgPhotoCmd(
return TCL_ERROR;
}
- testBox.x = x;
- testBox.y = y;
- testBox.width = 1;
- testBox.height = 1;
- /* What a way to do a test! */
- testRegion = TkCreateRegion();
- TkUnionRectWithRegion(&testBox, testRegion, testRegion);
- TkIntersectRegion(testRegion, masterPtr->validRegion, testRegion);
- TkClipBox(testRegion, &testBox);
- TkDestroyRegion(testRegion);
-
- Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
- testBox.width==0 && testBox.height==0));
+ /*
+ * Extract and return the desired value
+ */
+ pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
+ if (boolMode) {
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj( ! pixelPtr[3]));
+ } else {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(pixelPtr[3]));
+ }
return TCL_OK;
}
case PHOTO_TRANS_SET: {
- int transFlag;
+ int newVal, boolMode;
XRectangle setBox;
+ TkRegion modRegion;
- if (objc != 6) {
- Tcl_WrongNumArgs(interp, 3, objv, "x y boolean");
+ /*
+ * Parse args and option, check for valid values
+ */
+
+ if (objc < 6 || objc > 7) {
+ Tcl_WrongNumArgs(interp, 3, objv, "x y newVal ?-option?");
return TCL_ERROR;
}
if ((Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK)
- || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)
- || (Tcl_GetBooleanFromObj(interp, objv[5],
- &transFlag) != TCL_OK)) {
+ || (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK)) {
+ return TCL_ERROR;
+ }
+
+ index = 5;
+ memset(&options, 0, sizeof(options));
+ if (ParseSubcommandOptions(&options, interp,
+ OPT_ALPHA, &index, objc, objv) != TCL_OK) {
return TCL_ERROR;
}
+ if (index < objc) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "unknown option \"%s\": must be -alpha",
+ Tcl_GetString(objv[index])));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_OPTION",
+ NULL);
+ return TCL_ERROR;
+ }
+ boolMode = 1;
+ if (options.options & OPT_ALPHA) {
+ boolMode = 0;
+ }
+
if ((x < 0) || (x >= masterPtr->width)
|| (y < 0) || (y >= masterPtr->height)) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -1229,38 +1180,53 @@ ImgPhotoCmd(
return TCL_ERROR;
}
+ if (boolMode) {
+ if (Tcl_GetBooleanFromObj(interp, objv[5], &newVal) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ } else {
+ if (Tcl_GetIntFromObj(interp, objv[5], &newVal) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ if (newVal < 0 || newVal > 255) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "invalid alpha value \"%d\": "
+ "must be integer between 0 and 255", newVal));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
+ "BAD_VALUE", NULL);
+ return TCL_ERROR;
+ }
+ }
+
+ /*
+ * Set new alpha value for the pixel
+ */
+
+ pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
+ if (boolMode) {
+ pixelPtr[3] = newVal ? 0 : 255;
+ } else {
+ pixelPtr[3] = newVal;
+ }
+
+ /*
+ * Update the validRegion of the image
+ */
+
setBox.x = x;
setBox.y = y;
setBox.width = 1;
setBox.height = 1;
- pixelPtr = masterPtr->pix32 + (y * masterPtr->width + x) * 4;
-
- if (transFlag) {
- /*
- * Make pixel transparent.
- */
-
- TkRegion clearRegion = TkCreateRegion();
-
- TkUnionRectWithRegion(&setBox, clearRegion, clearRegion);
- TkSubtractRegion(masterPtr->validRegion, clearRegion,
+ modRegion = TkCreateRegion();
+ TkUnionRectWithRegion(&setBox, modRegion, modRegion);
+ if (pixelPtr[3]) {
+ TkUnionRectWithRegion(&setBox, masterPtr->validRegion,
masterPtr->validRegion);
- TkDestroyRegion(clearRegion);
-
- /*
- * Set the alpha value correctly.
- */
-
- pixelPtr[3] = 0;
} else {
- /*
- * Make pixel opaque.
- */
-
- TkUnionRectWithRegion(&setBox, masterPtr->validRegion,
+ TkSubtractRegion(masterPtr->validRegion, modRegion,
masterPtr->validRegion);
- pixelPtr[3] = 255;
}
+ TkDestroyRegion(modRegion);
/*
* Inform the generic image code that the image
@@ -1462,13 +1428,18 @@ GetExtension(
*
* This function is invoked to process one of the options which may be
* specified for the photo image subcommands, namely, -from, -to, -zoom,
- * -subsample, -format, -shrink, and -compositingrule.
+ * -subsample, -format, -shrink, -compositingrule, -alpha, -boolean and
+ * -withalpha.
+ * Parsing starts at the index in *optIndexPtr and stops at the end of
+ * objv[] or at the first value that does not belong to an option.
*
* Results:
* A standard Tcl result.
*
* Side effects:
- * Fields in *optPtr get filled in.
+ * Fields in *optPtr get filled in. The value of optIndexPtr is updated
+ * to contain the index of the first element in argv[] that was not
+ * parsed, or argc if the end of objv[] was reached.
*
*----------------------------------------------------------------------
*/
@@ -1593,7 +1564,8 @@ ParseSubcommandOptions(
return TCL_ERROR;
}
*optIndexPtr = index;
- } else if ((bit != OPT_SHRINK) && (bit != OPT_GRAYSCALE)) {
+ } else if (bit == OPT_TO || bit == OPT_FROM
+ || bit == OPT_SUBSAMPLE || bit == OPT_ZOOM) {
const char *val;
maxValues = ((bit == OPT_FROM) || (bit == OPT_TO)) ? 4 : 2;
@@ -2549,7 +2521,7 @@ MatchStringFormat(
int *oldformat) /* Returns 1 if the old image API is used. */
{
int matched = 0, useoldformat = 0;
- Tk_PhotoImageFormat *formatPtr;
+ Tk_PhotoImageFormat *formatPtr, *defaultFormatPtr = NULL;
ThreadSpecificData *tsdPtr =
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
const char *formatString = NULL;
@@ -2565,6 +2537,16 @@ MatchStringFormat(
for (formatPtr = tsdPtr->formatList; formatPtr != NULL;
formatPtr = formatPtr->nextPtr) {
+ /*
+ * To keep the behaviour of older versions (Tk <= 8.6), the default
+ * list-of-lists string format is checked last. Remember its position.
+ */
+
+ if (strncasecmp("default", formatPtr->name, strlen(formatPtr->name))
+ == 0) {
+ defaultFormatPtr = formatPtr;
+ }
+
if (formatObj != NULL) {
if (strncasecmp(formatString,
formatPtr->name, strlen(formatPtr->name)) != 0) {
@@ -2580,6 +2562,16 @@ MatchStringFormat(
return TCL_ERROR;
}
}
+
+ /*
+ * If this is the default format, and it was not passed as -format
+ * option, skip the stringMatchProc test. It'll be done later
+ */
+
+ if (formatObj == NULL && formatPtr == defaultFormatPtr) {
+ continue;
+ }
+
if ((formatPtr->stringMatchProc != NULL)
&& (formatPtr->stringReadProc != NULL)
&& formatPtr->stringMatchProc(data, formatObj,
@@ -2617,23 +2609,46 @@ MatchStringFormat(
}
}
}
+
if (formatPtr == NULL) {
- if ((formatObj != NULL) && !matched) {
+ /*
+ * Try the default format as last resort (only if no -format option
+ * was passed).
+ */
+
+ if ( formatObj == NULL && defaultFormatPtr == NULL) {
+ Tcl_Panic("default image format handler not registered");
+ }
+ if ( formatObj == NULL
+ && defaultFormatPtr->stringMatchProc != NULL
+ && defaultFormatPtr->stringReadProc != NULL
+ && defaultFormatPtr->stringMatchProc(data, formatObj,
+ widthPtr, heightPtr, interp) != 0) {
+ useoldformat = 0;
+ formatPtr = defaultFormatPtr;
+ } else if ((formatObj != NULL) && !matched) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"image format \"%s\" is not supported", formatString));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "PHOTO_FORMAT",
formatString, NULL);
+ return TCL_ERROR;
} else {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"couldn't recognize image data", -1));
Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO",
"UNRECOGNIZED_DATA", NULL);
+ return TCL_ERROR;
}
- return TCL_ERROR;
}
*imageFormatPtr = formatPtr;
*oldformat = useoldformat;
+
+ /*
+ * Some stringMatchProc might have left error messages and error codes in
+ * interp. Clear them before return.
+ */
+ Tcl_ResetResult(interp);
return TCL_OK;
}
@@ -3925,57 +3940,6 @@ ImgGetPhoto(
/*
*----------------------------------------------------------------------
*
- * ImgStringWrite --
- *
- * Default string write function. The data is formatted in the default
- * format as accepted by the "<img> put" command.
- *
- * Results:
- * A standard Tcl result.
- *
- * Side effects:
- * See the user documentation.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-ImgStringWrite(
- Tcl_Interp *interp,
- Tcl_Obj *formatString,
- Tk_PhotoImageBlock *blockPtr)
-{
- int greenOffset, blueOffset;
- Tcl_Obj *data;
-
- greenOffset = blockPtr->offset[1] - blockPtr->offset[0];
- blueOffset = blockPtr->offset[2] - blockPtr->offset[0];
-
- data = Tcl_NewObj();
- if ((blockPtr->width > 0) && (blockPtr->height > 0)) {
- int row, col;
-
- for (row=0; row<blockPtr->height; row++) {
- Tcl_Obj *line = Tcl_NewObj();
- unsigned char *pixelPtr = blockPtr->pixelPtr + blockPtr->offset[0]
- + row * blockPtr->pitch;
-
- for (col=0; col<blockPtr->width; col++) {
- Tcl_AppendPrintfToObj(line, "%s#%02x%02x%02x",
- col ? " " : "", *pixelPtr,
- pixelPtr[greenOffset], pixelPtr[blueOffset]);
- pixelPtr += blockPtr->pixelSize;
- }
- Tcl_ListObjAppendElement(NULL, data, line);
- }
- }
- Tcl_SetObjResult(interp, data);
- return TCL_OK;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* Tk_PhotoGetImage --
*
* This function is called to obtain image data from a photo image. This
@@ -4018,7 +3982,7 @@ Tk_PhotoGetImage(
/*
*--------------------------------------------------------------
*
- * TkPostscriptPhoto --
+ * ImgPostscriptPhoto --
*
* This function is called to output the contents of a photo image in
* Postscript by calling the Tk_PostscriptPhoto function.
@@ -4156,5 +4120,6 @@ Tk_PhotoSetSize_Panic(
* mode: c
* c-basic-offset: 4
* fill-column: 78
+ * tab-width: 8
* End:
*/
diff --git a/generic/tkInt.decls b/generic/tkInt.decls
index a13d8d7..c8f5775 100644
--- a/generic/tkInt.decls
+++ b/generic/tkInt.decls
@@ -634,6 +634,13 @@ declare 184 {
Tk_Font tkfont, const char *source, int numBytes, double x,
double y, double angle)
}
+
+# Debugging / testing functions for photo images
+declare 185 {
+ int TkDebugPhotoStringMatchDef(Tcl_Interp *inter, Tcl_Obj *data,
+ Tcl_Obj *formatString, int *widthPtr, int *heightPtr)
+}
+
##############################################################################
diff --git a/generic/tkInt.h b/generic/tkInt.h
index 474cfb0..ed22fc3 100644
--- a/generic/tkInt.h
+++ b/generic/tkInt.h
@@ -945,6 +945,7 @@ MODULE_SCOPE const Tk_SmoothMethod tkBezierSmoothMethod;
MODULE_SCOPE Tk_ImageType tkBitmapImageType;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtGIF;
MODULE_SCOPE void (*tkHandleEventProc) (XEvent* eventPtr);
+MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtDefault;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtPNG;
MODULE_SCOPE Tk_PhotoImageFormat tkImgFmtPPM;
MODULE_SCOPE TkMainInfo *tkMainWindowList;
diff --git a/generic/tkIntDecls.h b/generic/tkIntDecls.h
index b8addbd..0ffe157 100644
--- a/generic/tkIntDecls.h
+++ b/generic/tkIntDecls.h
@@ -550,6 +550,10 @@ EXTERN void TkDrawAngledChars(Display *display,
Drawable drawable, GC gc, Tk_Font tkfont,
const char *source, int numBytes, double x,
double y, double angle);
+/* 185 */
+EXTERN int TkDebugPhotoStringMatchDef(Tcl_Interp *inter,
+ Tcl_Obj *data, Tcl_Obj *formatString,
+ int *widthPtr, int *heightPtr);
typedef struct TkIntStubs {
int magic;
@@ -767,6 +771,7 @@ typedef struct TkIntStubs {
void (*tkUnderlineAngledTextLayout) (Display *display, Drawable drawable, GC gc, Tk_TextLayout layout, int x, int y, double angle, int underline); /* 182 */
int (*tkIntersectAngledTextLayout) (Tk_TextLayout layout, int x, int y, int width, int height, double angle); /* 183 */
void (*tkDrawAngledChars) (Display *display, Drawable drawable, GC gc, Tk_Font tkfont, const char *source, int numBytes, double x, double y, double angle); /* 184 */
+ int (*tkDebugPhotoStringMatchDef) (Tcl_Interp *inter, Tcl_Obj *data, Tcl_Obj *formatString, int *widthPtr, int *heightPtr); /* 185 */
} TkIntStubs;
extern const TkIntStubs *tkIntStubsPtr;
@@ -1139,6 +1144,8 @@ extern const TkIntStubs *tkIntStubsPtr;
(tkIntStubsPtr->tkIntersectAngledTextLayout) /* 183 */
#define TkDrawAngledChars \
(tkIntStubsPtr->tkDrawAngledChars) /* 184 */
+#define TkDebugPhotoStringMatchDef \
+ (tkIntStubsPtr->tkDebugPhotoStringMatchDef) /* 185 */
#endif /* defined(USE_TK_STUBS) */
diff --git a/generic/tkStubInit.c b/generic/tkStubInit.c
index bf55adf..a491622 100644
--- a/generic/tkStubInit.c
+++ b/generic/tkStubInit.c
@@ -473,6 +473,7 @@ static const TkIntStubs tkIntStubs = {
TkUnderlineAngledTextLayout, /* 182 */
TkIntersectAngledTextLayout, /* 183 */
TkDrawAngledChars, /* 184 */
+ TkDebugPhotoStringMatchDef, /* 185 */
};
static const TkIntPlatStubs tkIntPlatStubs = {
diff --git a/generic/tkTest.c b/generic/tkTest.c
index 61153e5..483fc0d 100644
--- a/generic/tkTest.c
+++ b/generic/tkTest.c
@@ -206,6 +206,9 @@ static int TrivialConfigObjCmd(ClientData dummy,
Tcl_Obj * const objv[]);
static void TrivialEventProc(ClientData clientData,
XEvent *eventPtr);
+static int TestPhotoStringMatchCmd(ClientData dummy,
+ Tcl_Interp *interp, int objc,
+ Tcl_Obj * const objv[]);
/*
*----------------------------------------------------------------------
@@ -269,6 +272,9 @@ Tktest_Init(
Tcl_CreateObjCommand(interp, "testprintf", TestprintfObjCmd, NULL, NULL);
Tcl_CreateObjCommand(interp, "testtext", TkpTesttextCmd,
(ClientData) Tk_MainWindow(interp), NULL);
+ Tcl_CreateObjCommand(interp, "testphotostringmatch",
+ TestPhotoStringMatchCmd, (ClientData) Tk_MainWindow(interp),
+ NULL);
#if defined(_WIN32) || defined(MAC_OSX_TK)
Tcl_CreateObjCommand(interp, "testmetrics", TestmetricsObjCmd,
@@ -2124,6 +2130,54 @@ CustomOptionFree(
ckfree(*(char **)internalPtr);
}
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * TestPhotoStringMatchCmd --
+ *
+ * This function implements the "testphotostringmatch" command. It
+ * provides a way from Tcl to call the string match function for the
+ * default image handler directly.
+ *
+ * Results:
+ * A standard Tcl result. If data is in the proper format, the result in
+ * interp will contain width and height as a list. If the data cannot be
+ * parsed as default image format, returns TCL_ERROR and leaves an
+ * appropriate error message in interp.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+ /* ARGSUSED */
+static int
+TestPhotoStringMatchCmd(
+ ClientData clientData, /* Main window for application. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *const objv[]) /* Argument strings. */
+{
+ Tcl_Obj *dummy = NULL;
+ Tcl_Obj *resultObj[2];
+ int width, height;
+
+ if (objc != 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "imageData");
+ return TCL_ERROR;
+ }
+ if (TkDebugPhotoStringMatchDef(interp, objv[1], dummy, &width, &height)) {
+ resultObj[0] = Tcl_NewIntObj(width);
+ resultObj[1] = Tcl_NewIntObj(height);
+ Tcl_SetObjResult(interp, Tcl_NewListObj(2, resultObj));
+ return TCL_OK;
+ } else {
+ return TCL_ERROR;
+ }
+}
+
+
/*
* Local Variables:
diff --git a/generic/tkTextBTree.c b/generic/tkTextBTree.c
index c20c546..81e31dc 100644
--- a/generic/tkTextBTree.c
+++ b/generic/tkTextBTree.c
@@ -799,6 +799,7 @@ RemovePixelClient(
nodePtr->numPixels[treePtr->pixelReferences-1];
}
if (treePtr->pixelReferences == 1) {
+ ckfree(nodePtr->numPixels);
nodePtr->numPixels = NULL;
} else {
nodePtr->numPixels = ckrealloc(nodePtr->numPixels,
@@ -1439,6 +1440,7 @@ TkBTreeDeleteIndexRange(
prevNodePtr->nextPtr = curNodePtr->nextPtr;
}
parentPtr->numChildren--;
+ DeleteSummaries(curNodePtr->summaryPtr);
ckfree(curNodePtr->numPixels);
ckfree(curNodePtr);
curNodePtr = parentPtr;
diff --git a/generic/tkWindow.c b/generic/tkWindow.c
index d9b5dec..ef06a5b 100644
--- a/generic/tkWindow.c
+++ b/generic/tkWindow.c
@@ -336,6 +336,7 @@ CreateTopLevelWindow(
* Create built-in photo image formats.
*/
+ Tk_CreatePhotoImageFormat(&tkImgFmtDefault);
Tk_CreatePhotoImageFormat(&tkImgFmtGIF);
Tk_CreatePhotoImageFormat(&tkImgFmtPNG);
Tk_CreatePhotoImageFormat(&tkImgFmtPPM);
diff --git a/library/console.tcl b/library/console.tcl
index ba68ccc..355a43b 100644
--- a/library/console.tcl
+++ b/library/console.tcl
@@ -286,6 +286,7 @@ proc ::tk::ConsoleHistory {cmd} {
}
.console delete promptEnd end
.console insert promptEnd $cmd {input stdin}
+ .console see end
}
next {
incr HistNum
@@ -302,6 +303,7 @@ proc ::tk::ConsoleHistory {cmd} {
}
.console delete promptEnd end
.console insert promptEnd $cmd {input stdin}
+ .console see end
}
reset {
set HistNum 1
diff --git a/library/listbox.tcl b/library/listbox.tcl
index 17c03c0..1b35b3d 100644
--- a/library/listbox.tcl
+++ b/library/listbox.tcl
@@ -206,7 +206,7 @@ if {"x11" eq [tk windowingsystem]} {
# Support for mousewheels on Linux/Unix commonly comes through mapping
# the wheel to the extended buttons. If you have a mousewheel, find
# Linux configuration info at:
- # http://www.inria.fr/koala/colas/mouse-wheel-scroll/
+ # http://linuxreviews.org/howtos/xfree/mouse/
bind Listbox <4> {
if {!$tk_strictMotif} {
%W yview scroll -5 units
diff --git a/library/text.tcl b/library/text.tcl
index 59e395c..836f928 100644
--- a/library/text.tcl
+++ b/library/text.tcl
@@ -463,7 +463,7 @@ if {"x11" eq [tk windowingsystem]} {
# Support for mousewheels on Linux/Unix commonly comes through mapping
# the wheel to the extended buttons. If you have a mousewheel, find
# Linux configuration info at:
- # http://www.inria.fr/koala/colas/mouse-wheel-scroll/
+ # http://linuxreviews.org/howtos/xfree/mouse/
bind Text <4> {
if {!$tk_strictMotif} {
%W yview scroll -50 pixels
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index 5ca8bfe..d1e67dc 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -858,6 +858,16 @@ XDrawLines(
CGContextAddLineToPoint(dc.context, prevx, prevy);
}
}
+ /*
+ * In the case of closed polylines, the first and last points
+ * are the same. We want miter or bevel join be rendered also
+ * at this point, this needs telling CoreGraphics that the
+ * path is closed.
+ */
+ if ((points[0].x == points[npoints-1].x) &&
+ (points[0].y == points[npoints-1].y)) {
+ CGContextClosePath(dc.context);
+ }
CGContextStrokePath(dc.context);
}
TkMacOSXRestoreDrawingContext(&dc);
diff --git a/tests/corruptMangled.gif b/tests/corruptMangled.gif
index ce043f0..9c1637c 100644
--- a/tests/corruptMangled.gif
+++ b/tests/corruptMangled.gif
Binary files differ
diff --git a/tests/imgListFormat.test b/tests/imgListFormat.test
new file mode 100644
index 0000000..c9dca56
--- /dev/null
+++ b/tests/imgListFormat.test
@@ -0,0 +1,661 @@
+# This file is a Tcl script to test out the default image data format
+# ("list format") implementend in the file tkImgListFormat.c.
+# It is organized in the standard fashion for Tcl tests.
+#
+# Copyright (c) 2017 Simon Bachmann
+# All rights reserved.
+#
+# Author: Simon Bachmann (simonbachmann@bluewin.ch)
+
+package require tcltest 2.2
+namespace import ::tcltest::*
+tcltest::configure {*}$argv
+tcltest::loadTestedCommands
+
+imageInit
+
+# find the teapot.ppm file for use in these tests
+set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm]
+testConstraint hasTeapotPhoto [file exists $teapotPhotoFile]
+# let's see if we have the semi-transparent one as well
+set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png]
+testConstraint hasTranspTeapotPhoto [file exists $transpTeapotPhotoFile]
+
+# ---------------------------------------------------------------------
+
+
+test imgListFormat-1.1 {ParseFormatOptions: default values} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{red green} {blue black}}
+ lindex [photo1 data] 1 1
+} -cleanup {
+ imageCleanup
+} -result {#000000}
+test imgListFormat-1.2 {ParseFormatOptions: format name as first arg} -setup {
+ image create photo photo1
+} -body {
+ photo1 put #1256ef -format {default} -to 0 0 10 10
+} -cleanup {
+ imageCleanup
+} -result {}
+test imgListFormat-1.3 {ParseFormatOptions: unknown option} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -bogus}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {bad format option "-bogus": must be -colorformat}
+test imgListFormat-1.4 {ParseFormatOptions: option not allowed} -setup {
+ image create photo photo1
+} -body {
+ photo1 put yellow -format {default -colorformat rgb}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {bad format option "-colorformat": no options allowed}
+test imgListFormat-1.5 {ParseFormatOptions: no -colorformat value} -setup {
+ image create photo photo1 -data black
+} -body {
+ photo1 data -format {default -colorformat}
+} -returnCodes error -result {the "-colorformat" option requires a value}
+test imgListFormat-1.6 {ParseFormatOptions: bad -colorformat val #1} -setup {
+ image create photo photo1
+} -body {
+ photo1 put yellow
+ photo1 data -format {default -colorformat bogus}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {bad color format "bogus": must be rgb, rgba, or list}
+test imgListFormat-1.7 {ParseFormatOptions: bad -colorformat val #2} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat tkcolor}
+} -returnCodes error -result \
+ {bad color format "tkcolor": must be rgb, rgba, or list}
+test imgListFormat-1.8 {ParseFormatOptions: bad -colorformat #3} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat emptystring}
+} -returnCodes error -result \
+ {bad color format "emptystring": must be rgb, rgba, or list}
+test imgListFormat-1.9 {ParseFormatOptions: bad -colorformat #4} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat rgb-short}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {bad color format "rgb-short": must be rgb, rgba, or list}
+test imgListFormat-1.10 {ParseFormatOptions: bad -colorformat #5} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat rgba-short}
+} -returnCodes error -result \
+ {bad color format "rgba-short": must be rgb, rgba, or list}
+test imgListFormat-1.11 {valid colorformats} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white#78
+ set result {}
+ lappend result [photo1 data -format {default -colorformat rgb}]
+ lappend result [photo1 data -format {default -colorformat rgba}]
+ lappend result [photo1 data -format {default -colorformat list}]
+ set result
+} -cleanup {
+ imageCleanup
+ unset result
+} -result {{{#ffffff}} {{#ffffff78}} {{{255 255 255 120}}}}
+
+# GetBadOptMsg: only use case already tested with imgListFormat-1.4
+
+test imgListFormat-3.1 {StringMatchDef: data is not a list} -body {
+ testphotostringmatch {not a " proper list}
+ # " (this comment is here only for editor highlighting)
+} -returnCodes error -result {unmatched open quote in list}
+# empty data case tested with imgPhoto-4.95 (imgPhoto.test)
+test imgListFormat-3.2 {StringMatchDef: \
+ list element not a proper list} -body {
+ testphotostringmatch {{red white} {not "} {blue green}}
+ # "
+} -returnCodes error -result {unmatched open quote in list}
+test imgListFormat-3.3 {StringMatchDef: \
+ sublists with differen lengths} -body {
+ testphotostringmatch {{#001122 #334455 #667788}
+ {#99AABB #CCDDEE}
+ {#FF0011 #223344 #556677}}
+} -returnCodes error -result \
+ {invalid row # 1: all rows must have the same number of elements}
+test imgListFormat-3.4 {StringMatchDef: base64 data is not parsed as valid \
+} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {
+ iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCA
+ YAAAEFsT2yAAAABGdBTUEAAYagMeiWXwAA
+ ABdJREFUCJkFwQEBAAAAgiD6P9pACRoqDk
+ fUBvt1wUFKAAAAAElFTkSuQmCC
+ } -format default
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {couldn't recognize image data}
+test imgListFormat-3.5 {StringMatchDef: valid data} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{blue green}
+ {yellow magenta}
+ {#000000 #FFFFFFFF}}
+ list [image width photo1] [image height photo1] \
+ [photo1 get 0 2 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {2 3 {0 0 0 255}}
+
+# ImgStringRead: most of the error cases cannot be tested with current code,
+# as the errors are detected by StringMatchDef
+test imgListFormat-4.1 {StringReadDef: use with -format opt} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -format "default"
+ photo1 get 0 0
+} -cleanup {
+ imageCleanup
+} -result {255 255 255}
+test imgListFormat-4.2 {StringReadDef: suboptions to format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -format {default -bogus}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {bad format option "-bogus": no options allowed}
+test imgListFormat-4.3 {StringReadDef: erroneous non-option argument} -setup {
+ image create photo photo1
+} -body {
+ photo1 put orange -format {default bogus}
+} -returnCodes error -result {bad format option "bogus": no options allowed}
+test imgListFormat-4.4 {StringReadDef: normal use case} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ set imgData [photo1 data]
+ photo2 put $imgData
+ string equal [photo1 data] [photo2 data]
+} -cleanup {
+ imageCleanup
+ unset imgData
+} -result {1}
+test imgListFormat-4.5 {StringReadDef: correct compositing rule} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+ image create photo photo2
+} -body {
+ photo2 put #FF0000 -to 0 0 50 50
+ photo2 put [photo1 data -format {default -colorformat rgba}] -to 10 10 40 40
+ list [photo2 get 0 0 -withalpha] [photo2 get 20 25 -withalpha] \
+ [photo2 get 49 49 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {{255 0 0 255} {0 78 185 225} {255 0 0 255}}
+
+test imgListFormat-5.1 {StringWriteDef: format options not a list} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default " bogus}
+ # "
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {unmatched open quote in list}
+test imgListFormat-5.2 {StringWriteDef: invalid format option} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -bogus}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {bad format option "-bogus": must be -colorformat}
+test imgListFormat-5.3 {StringWriteDef: non-option arg in format} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat list bogus}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {bad format option "bogus": must be -colorformat}
+test imgListFormat-5.4 {StringWriteDef: empty image} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format {default -colorformat rgba}
+} -cleanup {
+ imageCleanup
+} -result {}
+test imgListFormat-5.5 {StirngWriteDef: size of data} -setup {
+ image create photo photo1
+} -body {
+ photo1 put blue -to 0 0 35 64
+ set imgData [photo1 data]
+ list [llength [lindex $imgData 0]] [llength $imgData]
+} -cleanup {
+ unset imgData
+ imageCleanup
+} -result {35 64}
+test imgListFormat-5.6 {StringWriteDef: test some pixels #1} -constraints {
+ hasTeapotPhoto
+} -setup {
+ set result {}
+ image create photo photo1 -file $teapotPhotoFile
+} -body {
+ set imgData [photo1 data]
+ # note: with [lindex], the coords are inverted (y x)
+ lappend result [lindex $imgData 0 0]
+ lappend result [lindex $imgData 3 2]
+ lappend result [lindex $imgData 107 53]
+ lappend result [lindex $imgData 203 157]
+ lappend result [lindex $imgData 255 255]
+ set result
+} -cleanup {
+ unset result
+ unset imgData
+ imageCleanup
+} -result {{#135cc0} #135cc0 #a06d52 #e1c8ba #135cc0}
+test imgListFormat-5.7 {StringWriteDef: test some pixels #2} -constraints {
+ hasTeapotPhoto
+} -setup {
+ set result {}
+ image create photo photo1 -file $teapotPhotoFile
+} -body {
+ set imgData [photo1 data -format {default -colorformat rgba}]
+ # note: with [lindex], the coords are inverted (y x)
+ lappend result [lindex $imgData 0 0]
+ lappend result [lindex $imgData 3 2]
+ lappend result [lindex $imgData 107 53]
+ lappend result [lindex $imgData 203 157]
+ lappend result [lindex $imgData 255 255]
+ set result
+} -cleanup {
+ unset result
+ unset imgData
+ imageCleanup
+} -result {{#135cc0ff} #135cc0ff #a06d52ff #e1c8baff #135cc0ff}
+test imgListFormat-5.8 {StringWriteDef: test some pixels #3} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+} -body {
+ set imgData [photo1 data -format {default -colorformat rgb}]
+ set result {}
+ lappend result [lindex $imgData 3 2]
+ lappend result [lindex $imgData 107 53]
+ lappend result [lindex $imgData 203 157]
+ set result
+} -cleanup {
+ unset result
+ unset imgData
+ imageCleanup
+} -result {{#004eb9} #a14100 #ffca9f}
+test imgListFormat-5.9 {StringWriteDef: test some pixels #4} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+} -body {
+ set imgData [photo1 data -format {default -colorformat rgba}]
+ set result [lindex $imgData 3 2]
+ lappend result [lindex $imgData 107 53]
+ lappend result [lindex $imgData 203 157]
+ set result
+} -cleanup {
+ unset result
+ unset imgData
+ imageCleanup
+} -result {{#004eb9e1} #a14100aa #ffca9faf}
+test imgListFormat-5.10 {StringWriteDef: test some pixels #5} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+} -body {
+ set imgData [photo1 data -format {default -colorformat list}]
+ set result {}
+ lappend result [lindex $imgData 3 2]
+ lappend result [lindex $imgData 107 53]
+ lappend result [lindex $imgData 203 157]
+ set result
+} -cleanup {
+ unset imgData
+ unset result
+ imageCleanup
+} -result {{0 78 185 225} {161 65 0 170} {255 202 159 175}}
+
+test imgListFormat-6.1 {ParseColor: empty string} -setup {
+ image create photo photo1
+ set result {}
+} -body {
+ photo1 put {{"" ""} {"" ""}}
+ lappend result [image width photo1]
+ lappend result [image height photo1]
+ lappend result [photo1 get 1 1 -withalpha]
+ set result
+} -cleanup {
+ unset result
+ imageCleanup
+} -result {2 2 {0 0 0 0}}
+test imgListFormat-6.2 {ParseColor: empty string, mixed} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{black white} {{} white}}
+ list [photo1 get 0 0 -withalpha] [photo1 get 0 1 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {{0 0 0 255} {0 0 0 0}}
+test imgListFormat-6.3 {ParseColor: color name too long} -setup {
+ image create photo photo1
+ set longstr {}
+ for {set i 1} {$i <= 100} {incr i} {
+ append longstr "z"
+ }
+} -body {
+ photo1 put [list [list blue] [list $longstr]]
+} -cleanup {
+ imageCleanup
+ unset longstr
+} -returnCodes error -result {invalid color}
+test imgListFormat-6.4 {ParseColor: #XXX color, different forms} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#A123 #334455} {#012 #fffefd#00}}
+ photo1 data -format {default -colorformat rgba}
+} -cleanup {
+ imageCleanup
+} -result {{#aa112233 #334455ff} {#001122ff #fffefd00}}
+test imgListFormat-6.5 {ParseColor: list format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put [list [list [list 255 255 255]]]
+ photo1 get 0 0 -withalpha
+} -cleanup {
+ imageCleanup
+} -result {255 255 255 255}
+test imgListFormat-6.6 {ParseColor: string format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put [list [list [list white]]]
+ photo1 get 0 0 -withalpha
+} -cleanup {
+ imageCleanup
+} -result {255 255 255 255}
+test imgListFormat-6.7 {ParseColor: invalid color} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{blue red} {green bogus}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "bogus"}
+test imgListFormat-6.8 {ParseColor: overall test} -setup {
+ image create photo photo1
+ set result {}
+} -body {
+ photo1 put {
+ {snow@0.5 snow#80 snow#8 #fffffafafafa@0.5 #fffffabbfacc#8}
+ {#fffffafffaff#80 #ffffaafaa@.5 #ffffaafaa#8 #ffffaafaa#80 #fee#8}
+ {#fee#80 #fee@0.5 #fffafa@0.5 #fffafa#8 #fffafa#80}
+ {{0xff 250 0xfa 128} {255 250 250} #fee8 #fffafa80 snow}}
+ for {set y 0} {$y < 4} {incr y} {
+ for {set x 0} {$x < 5} {incr x} {
+ lappend result [photo1 get $x $y -withalpha]
+ }
+ }
+ set result
+} -cleanup {
+ imageCleanup
+ unset result
+} -result \
+{{255 250 250 128} {255 250 250 128} {255 250 250 136} {255 250 250 128}\
+{255 250 250 136} {255 250 250 128} {255 250 250 128} {255 250 250 136}\
+{255 250 250 128} {255 238 238 136} {255 238 238 128} {255 238 238 128}\
+{255 250 250 128} {255 250 250 136} {255 250 250 128} {255 250 250 128}\
+{255 250 250 255} {255 238 238 136} {255 250 250 128} {255 250 250 255}}
+
+# Note: these tests were written for an earlier implementation of
+# ParseColorAsList. For this reason, their order and layout do not follow the
+# current code very well. Test coverage is pretty good, nevertheless.
+test imgListFormat-7.1 {ParseColorAsList: invalid list} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{123 45 67 89} {123 45 " 67}}}
+ #"
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "123 45 " 67"}
+#"
+test imgListFormat-7.2 {ParseColorAsList: too few elements in list} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{0 255 0 255} {0 255}}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "0 255"}
+test imgListFormat-7.3 {ParseColorAsList: too many elements in list} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{0 100 200 255} {0 100 200 255 0}}}
+} -returnCodes error -result {invalid color name "0 100 200 255 0"}
+test imgListFormat-7.4 {ParseColorAsList: not an integer value} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{9 0xf3 87 65} {43 21 10 1.0}}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "43 21 10 1.0"}
+test imgListFormat-7.5 {ParseColorAsList: negative value in list} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{121 121 121} {121 121 -1}}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "121 121 -1"}
+test imgListFormat-7.6 {ParseColorAsList: value in list too large} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{0 1 2 3} {254 255 256}}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "254 255 256"}
+test imgListFormat-7.7 {ParseColorAsList: suffix not allowed} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{100 100 100} {100 100 100#FE}}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "100 100 100#FE"}
+test imgListFormat-7.8 {ParseColorAsList: valid list form} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{{0x0 0x10 0xfe 0xff} {0 100 254}}
+ {{30 30 30 0} {1 1 254 1}}}
+ list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] \
+ [photo1 get 0 1 -withalpha] [photo1 get 1 1 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {{0 16 254 255} {0 100 254 255} {30 30 30 0} {1 1 254 1}}
+test imgListFormat-7.9 {ParseColorAsList: additional spaces in list} -setup {
+ image create photo photo1
+} -body {
+ photo1 put { { { 1 2 3} {1 2 3} } { {1 2 3 } { 1 2 3 4 } } }
+ photo1 data -format {default -colorformat rgba}
+} -cleanup {
+ imageCleanup
+} -result {{#010203ff #010203ff} {#010203ff #01020304}}
+test imgListFormat-7.10 {ParseColorAsList: list format, string rep} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{"111 222 33 44"}}
+ photo1 get 0 0 -withalpha
+} -cleanup {
+ imageCleanup
+} -result {111 222 33 44}
+
+test imgListFormat-8.1 {ParseColorAsHex: RGB format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#010 #001100}}
+ photo1 data
+} -cleanup {
+ imageCleanup
+} -result {{#001100 #001100}}
+test imgListFormat-8.2 {ParseColorAsHex: invalid hex digit} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#ABCD #ABCZ}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "#ABCZ"}
+test imgListFormat-8.3 {ParseColorAsHex: RGB with suffix, 8 chars} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#FFfFFf #AbCdef#0}}
+ photo1 data
+} -cleanup {
+ imageCleanup
+} -result {{#ffffff #abcdef}}
+test imgListFormat-8.4 {ParseColor: valid #RGBA color} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#9bd5020d #7acF}}
+ list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {{155 213 2 13} {119 170 204 255}}
+
+test imgListFormat-9.1 {ParseColorAsStandard:
+ Tk color, valid suffixes} -setup {
+ image create photo photo1
+ set result {}
+} -body {
+ photo1 put {{blue@0.711 #114433#C} {#8D4#1A magenta}}
+ lappend result [photo1 get 0 0 -withalpha]
+ lappend result [photo1 get 1 0 -withalpha]
+ lappend result [photo1 get 0 1 -withalpha]
+ lappend result [photo1 get 1 1 -withalpha]
+ set result
+} -cleanup {
+ unset result
+ imageCleanup
+} -result {{0 0 255 181} {17 68 51 204} {136 221 68 26} {255 0 255 255}}
+test imgListFormat-9.2 {ParseColorAsStandard:
+ Tk color with and w/o suffixes} -setup {
+ image create photo photo1
+ set result {}
+} -body {
+ photo1 put {{#52D8a0 #2B5} {#E47@0.01 maroon#4}}
+ lappend result [photo1 get 0 0 -withalpha]
+ lappend result [photo1 get 1 0 -withalpha]
+ lappend result [photo1 get 0 1 -withalpha]
+ lappend result [photo1 get 1 1 -withalpha]
+ set result
+} -cleanup {
+ unset result
+ imageCleanup
+} -result {{82 216 160 255} {34 187 85 255} {238 68 119 3} {128 0 0 68}}
+test imgListFormat-9.3 {ParseColorAsStandard: wrong digit count} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#000 #00}}
+} -returnCodes error -result {invalid color name "#00"}
+test imgListFormat-9.4 {ParseColorAsStandard: @A suffix, not a float} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{blue@0.5 blue@bogus}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {invalid alpha suffix "@bogus": expected floating-point value}
+test imgListFormat-9.5 {ParseColorAsStandard: @A, value too low} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {green@.1 green@-0.1}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {invalid alpha suffix "@-0.1": value must be in the range from 0 to 1}
+test imgListFormat-9.6 {ParseColorAsStandard: @A, value too high} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#000000@0 #000000@1.0001}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {invalid alpha suffix "@1.0001": value must be in the range from 0 to 1}
+test imgListFormat-9.7 {ParseColorAsStandard: @A suffix, edge values} -setup {
+ imageCleanup
+ image create photo photo1
+} -body {
+ photo1 put {{yellow@1e-22 yellow@0.12352941 yellow@0.12352942 \
+ yellow@0.9999999}}
+ list [photo1 get 0 0 -withalpha] [photo1 get 1 0 -withalpha] \
+ [photo1 get 2 0 -withalpha] [photo1 get 3 0 -withalpha]
+} -cleanup {
+ imageCleanup
+} -result {{255 255 0 0} {255 255 0 31} {255 255 0 32} {255 255 0 255}}
+test imgListFormat-9.8 {ParseColorAsStandard: # suffix, no hex digits} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{black#f} {black#}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid alpha suffix "#"}
+test imgListFormat-9.9 {ParseColorAsStandard:
+ '#' suffix, too many digits} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#ABC#12 #ABC#123}}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid alpha suffix "#123"}
+test imgListFormat-9.10 {ParseColorAsStandard:
+ invalid digit in #X suffix} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#000#a #000#g}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid alpha suffix "#g": expected hex digit}
+test imgListFormat-9.11 {ParseColorAsStandard:
+ invalid digit in #XX suffix} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {green#2 green#2W}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid alpha suffix "#2W": expected hex digit}
+test imgListFormat-9.12 {ParseColorAsStandard:
+ invalid color: not a hex digit} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#ABCDEF@.99 #ABCDEG@.99}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "#ABCDEG@.99"}
+test imgListFormat-9.13 {ParseColorAsStandard: suffix not allowed #1} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#ABC@.5 #ABCD@0.5}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "#ABCD@0.5"}
+test imgListFormat-9.14 {ParseColorAsStandard: suffix not allowed #2} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {#1111 #1111#1}
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {invalid color name "#1111#1"}
+
+
+# ---------------------------------------------------------------------
+
+imageFinish
+
+# cleanup
+cleanupTests
+return
diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test
index 4f3611e..f67de84 100644
--- a/tests/imgPhoto.test
+++ b/tests/imgPhoto.test
@@ -10,14 +10,82 @@
#
# Author: Paul Mackerras (paulus@cs.anu.edu.au)
+#
+# This file is somewhat caothic: the order of the tests does not
+# really follow the order of the corresponding functions in
+# tkImgPhoto.c. Probably, because early versions had only a few tests
+# and over time test cases were added in bits and pieces.
+# To be noted, also, that this file is not complete: large portions of
+# code in tkImgPhoto.c have no test coverage.
+#
+# To help keeping the overview, the table below lists where to find
+# tests for each of the functions in tkImgPhoto.c. The function are
+# listed in the order as they appear in the source file.
+#
+
+#
+# Function name Tests for function
+#--------------------------------------------------------------------------
+# PhotoFormatThreadExitProc no tests
+# Tk_Create*PhotoImageFormat no tests
+# ImgPhotoCreate imgPhoto-2.*
+# ImgPhotoCmd imgPhoto-4.*, imgPhoto-17.*
+# GetExtension: no tests
+# ParseSubcommandOptions: imgPhoto-1.*
+# ImgPhotoConfigureMaster: imgPhoto-3.*, imgPhoto-15.*
+# toggleComplexAlphaIfNeeded: no tests
+# ImgPhotoDelete: imgPhoto-8.*
+# ImgPhotoCmdDeleteProc: imgPhoto-9.*
+# ImgPhotoSetSize: no tests
+# MatchFileFormat: imgPhoto-18.*
+# MatchSringFormat: imgPhoto-19.*
+# Tk_FindPhoto: imgPhoto-11.*
+# Tk_PhotoPutBlock: imgPhoto-10.*, imgPhoto-16.*
+# Tk_PhotoPutZoomedBlock: imgPhoto-12.*
+# Tk_DitherPhoto: no tets
+# Tk_PhotoBlank: no tests
+# Tk_PhotoExpand: no tests
+# Tk_PhotoGetSize: no tests
+# Tk_PhotoSetSize: no tests
+# TkGetPhotoValidRegion: no tests
+# ImgGetPhoto: no tests
+# Tk_PhotoGetImage no tests
+# ImgPostscriptPhoto no tests
+# Tk_PhotoPutBlock_NoComposite no tests, probably none needed
+# Tk_PhotoPutZoomedBlock_NoComposite no tests, probably none needed
+# Tk_PhotoExpand_Panic no tests, probably none needed
+# Tk_PhotoPutBlock_Panic no tests, probably none needed
+# Tk_PhotoPutZoomedBlock_Panic no tests, probably none needed
+# Tk_PhotoSetSize_Panic no tests, probably none needed
+#--------------------------------------------------------------------------
+#
+
+#
+# Some tests are not specific to a function in tkImgPhoto.c. They are:
+#
+
+#
+# Test name(s) Description
+#--------------------------------------------------------------------------
+# imgPhoto-5.* Do not really belong to this file. ImgPhotoGet and
+# ImgPhotoFree are defined in tkImgPhInstance.c.
+# imgPhoto-6.* Do not really belong to this file. ImgPhotoDisplay
+# is defined in tkImgPhInstance.c.
+# imgPhoto-7.* Do not really belong to this file. ImgPhotoFree is
+# defined in tkImgPhInstance.c.
+# imgPhoto-13.* Tests for separation in different interpreters
+# imgPhoto-14.* Test GIF format. Would belong to imgGIF.test
+# - which does not exist.
+#
+
package require tcltest 2.2
namespace import ::tcltest::*
tcltest::configure {*}$argv
tcltest::loadTestedCommands
-
-# Used for 4.65 - 4.73 tests
-# Now for some heftier testing, checking that setting and resetting of pixels'
-# transparency status doesn't "leak" with any one-off errors.
+
+#
+# Used for imgPhoto-4.65 - imgPhoto-4.73
+#
proc foreachPixel {img xVar yVar script} {
upvar 1 $xVar x $yVar y
set width [image width $img]
@@ -58,7 +126,10 @@ set README [makeFile {
# find the teapot.ppm file for use in these tests
set teapotPhotoFile [file join [file dirname [info script]] teapot.ppm]
testConstraint hasTeapotPhoto [file exists $teapotPhotoFile]
-
+# let's see if we have the semi-transparent one as well
+set transpTeapotPhotoFile [file join [file dirname [info script]] teapotTransparent.png]
+testConstraint hasTranspTeapotPhoto [file exists $transpTeapotPhotoFile]
+
proc base64ok {} {
expr {
![catch {package require base64}]
@@ -115,7 +186,23 @@ test imgPhoto-1.10 {options for photo images - error case} -body {
test imgPhoto-1.11 {options for photo images - error case} -body {
image create photo photo1 -format
} -returnCodes error -result {value for "-format" missing}
-
+test imgPhoto-1.12 {option -alpha, normal use} -setup {
+ image create photo photo1
+} -body {
+ photo1 put "white" -to 0 0
+ photo1 transparency get 0 0 -alpha
+} -cleanup {
+ imageCleanup
+} -result {255}
+test imgPhoto-1.13 {option -withalpha, normal use} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{blue green}}
+ photo1 get 1 0 -withalpha
+} -cleanup {
+ imageCleanup
+} -result {0 128 0 255}
+
test imgPhoto-2.1 {ImgPhotoCreate procedure} -setup {
imageCleanup
} -body {
@@ -138,7 +225,7 @@ test imgPhoto-2.2 {ImgPhotoCreate procedure} -setup {
# photo1 copy photo2
# set msg
# } {couldn't open "bogus.img": no such file or directory}
-
+
test imgPhoto-3.1 {ImgPhotoConfigureMaster procedure} -constraints {
hasTeapotPhoto
} -body {
@@ -174,7 +261,40 @@ test imgPhoto-3.3 {ImgPhotoConfigureMaster procedure} -constraints {
destroy .c
image delete photo1
} -result {256 256 {10 10 266 266} {300 10 556 266}}
-
+test imgPhoto-3.4 {ImgPhotoConfigureMaster: -data <ppm>} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ photo2 configure -data [photo1 data -format ppm -from 100 100 120 120]
+ list [image width photo2] [image height photo2]
+} -cleanup {
+ imageCleanup
+} -result {20 20}
+test imgPhoto-3.5 {ImgPhotoConfigureMaster: -data <png>} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ photo2 configure -data [photo1 data -format png -from 120 120 140 140]
+ list [image width photo2] [image height photo2]
+} -cleanup {
+ imageCleanup
+} -result {20 20}
+test imgPhoto-3.6 {ImgPhotoConfigureMaster: -data <default>} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ photo2 configure -data [photo1 data -from 80 90 100 110]
+ list [image width photo2] [image height photo2]
+} -cleanup {
+ imageCleanup
+} -result {20 20}
+
test imgPhoto-4.1 {ImgPhotoCmd procedure} -setup {
image create photo photo1
} -body {
@@ -373,16 +493,19 @@ test imgPhoto-4.21 {ImgPhotoCmd procedure: copy option} -constraints {
} -cleanup {
image delete photo1 photo2
} -result {256 256 49 51 49 51 49 51 10 51 10 10}
+# tests for <imageName> data: imgPhoto-4.
test imgPhoto-4.22 {ImgPhotoCmd procedure: get option} -constraints {
- hasTeapotPhoto
+ hasTranspTeapotPhoto
} -setup {
image create photo photo1
} -body {
- photo1 read $teapotPhotoFile
- list [photo1 get 100 100] [photo1 get 150 100] [photo1 get 100 150]
+ photo1 read $transpTeapotPhotoFile
+ list [photo1 get 100 100 -withalpha] \
+ [photo1 get 150 100 -withalpha] \
+ [photo1 get 100 150] [photo1 get 150 150]
} -cleanup {
image delete photo1
-} -result {{169 117 90} {172 115 84} {35 35 35}}
+} -result {{175 71 0 162} {179 73 0 168} {14 8 0} {0 0 0}}
test imgPhoto-4.23 {ImgPhotoCmd procedure: get option} -setup {
image create photo photo1
} -body {
@@ -400,10 +523,12 @@ test imgPhoto-4.24 {ImgPhotoCmd procedure: get option} -setup {
test imgPhoto-4.25 {ImgPhotoCmd procedure: get option} -setup {
image create photo photo1
} -body {
- photo1 get
+ photo1 get 0
} -cleanup {
image delete photo1
-} -returnCodes error -result {wrong # args: should be "photo1 get x y"}
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 get x y ?-withalpha?"}
+# more test for image get: 4.101-4.102
test imgPhoto-4.26 {ImgPhotoCmd procedure: put option} -setup {
image create photo photo1
} -body {
@@ -417,22 +542,28 @@ test imgPhoto-4.27 {ImgPhotoCmd procedure: put option} -setup {
photo1 put {{white} {white white}}
} -returnCodes error -cleanup {
image delete photo1
-} -result {all elements of color list must have the same number of elements}
+} -result {couldn't recognize image data}
test imgPhoto-4.28 {ImgPhotoCmd procedure: put option} -setup {
image create photo photo1
} -body {
photo1 put {{blahgle}}
} -cleanup {
image delete photo1
-} -returnCodes error -result {can't parse color "blahgle"}
+} -returnCodes error -result {couldn't recognize image data}
test imgPhoto-4.29 {ImgPhotoCmd procedure: put option} -setup {
image create photo photo1
} -body {
- photo1 put -to 10 10 20 20 {{white}}
+ # SB: odd thing - this test passed with tk 8.6.6, even if the data
+ # is in the wrong position:
+ #photo1 put -to 10 10 20 20 {{white}}
+
+ # this is how it's supposed to be:
+ photo1 put {{white}} -to 10 10 20 20
photo1 get 19 19
} -cleanup {
image delete photo1
} -result {255 255 255}
+# more tests for image put: 4.90-4.100
test imgPhoto-4.30 {ImgPhotoCmd procedure: read option} -setup {
image create photo photo1
} -body {
@@ -514,6 +645,7 @@ test imgPhoto-4.39 {ImgPhotoCmd procedure: write option} -setup {
} -cleanup {
image delete photo1
} -returnCodes error -result {image file format "bogus" is unknown}
+# more tests on "imageName write": imgPhoto-17.*
test imgPhoto-4.40 {ImgPhotoCmd procedure: transparency option} -setup {
image create photo photo1
} -body {
@@ -527,21 +659,21 @@ test imgPhoto-4.41 {ImgPhotoCmd procedure: transparency get option} -setup {
photo1 transparency get
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency get x y"}
+} -result {wrong # args: should be "photo1 transparency get x y ?-option?"}
test imgPhoto-4.42 {ImgPhotoCmd procedure: transparency get option} -setup {
image create photo photo1
} -body {
photo1 transparency get 0
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency get x y"}
+} -result {wrong # args: should be "photo1 transparency get x y ?-option?"}
test imgPhoto-4.43 {ImgPhotoCmd procedure: transparency get option} -setup {
image create photo photo1
} -body {
- photo1 transparency get 0 0 0
+ photo1 transparency get 0 0 0 -alpha
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency get x y"}
+} -result {wrong # args: should be "photo1 transparency get x y ?-option?"}
test imgPhoto-4.44 {ImgPhotoCmd procedure: transparency get option} -setup {
image create photo photo1
} -body {
@@ -601,34 +733,39 @@ test imgPhoto-4.51 {ImgPhotoCmd procedure: transparency get option} -setup {
} -cleanup {
image delete photo1
} -result 1
+# more tests for transparency get: 4.65, 4.66, 4.76-4.81
test imgPhoto-4.52 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
} -body {
photo1 transparency set
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency set x y boolean"}
+} -result \
+ {wrong # args: should be "photo1 transparency set x y newVal ?-option?"}
test imgPhoto-4.53 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
} -body {
photo1 transparency set 0
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency set x y boolean"}
+} -result \
+ {wrong # args: should be "photo1 transparency set x y newVal ?-option?"}
test imgPhoto-4.54 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
} -body {
photo1 transparency set 0 0
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency set x y boolean"}
+} -result \
+ {wrong # args: should be "photo1 transparency set x y newVal ?-option?"}
test imgPhoto-4.55 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
} -body {
- photo1 transparency set 0 0 0 0
+ photo1 transparency set 0 0 0 0 -alpha
} -returnCodes error -cleanup {
image delete photo1
-} -result {wrong # args: should be "photo1 transparency set x y boolean"}
+} -result \
+ {wrong # args: should be "photo1 transparency set x y newVal ?-option?"}
test imgPhoto-4.56 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
} -body {
@@ -645,6 +782,7 @@ test imgPhoto-4.57 {ImgPhotoCmd procedure: transparency set option} -setup {
} -returnCodes error -result {expected integer but got "bogus"}
test imgPhoto-4.58 {ImgPhotoCmd procedure: transparency set option} -setup {
image create photo photo1
+ photo1 put blue
} -body {
photo1 transparency set 0 0 bogus
} -cleanup {
@@ -696,6 +834,7 @@ test imgPhoto-4.64 {ImgPhotoCmd procedure: transparency set option} -setup {
} -cleanup {
image delete photo1
} -result 1
+# more tests for transparency set: 4.67, 4.68, 4.82-4.89
# Now for some heftier testing, checking that setting and resetting of pixels'
# transparency status doesn't "leak" with any one-off errors.
test imgPhoto-4.65 {ImgPhotoCmd procedure: transparency get option} -setup {
@@ -820,7 +959,411 @@ test imgPhoto-4.75 {<photo> read command: filename starting with '-'} -constrain
image delete photo1
file delete ./-teapotPhotoFile
} -result {}
-
+test imgPhoto-4.76 {ImgPhotoCmd, transparancy get: too many options} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -to 0 0 1 1
+ photo1 transparency get 0 0 -alpha -bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 transparency get x y ?-option?"}
+test imgPhoto-4.77 {ImgPhotoCmd, transparency get: invalid option} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -to 0 0 1 1
+ photo1 transparency get 0 0 -bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {unrecognized option "-bogus": must be -alpha}
+test imgPhoto-4.78 {ImgPhotoCmd, transparency get: normal use} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -to 0 0 1 1
+ set result [photo1 transparency get 0 0]
+ lappend result [photo1 transparency get 0 0 -alpha]
+} -cleanup {
+ imageCleanup
+} -result {0 255}
+test imgPhoto-4.79 {ImgPhotoCmd, transparency get: no option} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+ set result {}
+} -body {
+ set pixelCoords {{156 239} {76 207} {153 213} {139 43} {75 112}}
+ foreach coord $pixelCoords {
+ lappend result [photo1 transparency get {*}$coord]
+ }
+ set result
+} -cleanup {
+ imageCleanup
+} -result {0 1 0 0 0}
+# test imgPhoto-4.80: deleted (was transparency get: -boolean)
+test imgPhoto-4.81 {ImgPhotoCmd, transparency get: -alpha} -constraints {
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo photo1 -file $transpTeapotPhotoFile
+ set result {}
+} -body {
+ set pixelCoords {{156 239} {76 207} {153 213} {139 43} {75 112}}
+ foreach coord $pixelCoords {
+ lappend result [photo1 transparency get {*}$coord -alpha]
+ }
+ set result
+} -cleanup {
+ imageCleanup
+} -result {255 0 1 254 206}
+test imgPhoto-4.82 {ImgPhotoCmd, transparency set: too many opts} -setup {
+ image create photo photo1
+} -body {
+ photo1 transparency set 0 0 -alpha -bogus 1
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 transparency set x y newVal ?-option?"}
+test imgPhoto-4.83 {ImgPhotoCmd, transparency set: invalid opt} -setup {
+ image create photo photo1 -data black
+} -body {
+ photo1 transparency set 0 0 0 -bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {unrecognized option "-bogus": must be -alpha}
+test imgPhoto-4.84 {ImgPhotoCmd, transparency set: invalid newVal} -setup {
+ image create photo photo1 -data white
+} -body {
+ photo1 transparency set 0 0 bogus -alpha
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {expected integer but got "bogus"}
+test imgPhoto-4.85 {ImgPhotoCmd, transparency set: invalid newVal} -setup {
+ image create photo photo1 -data red
+} -body {
+ photo1 transparency set 0 0 -1 -alpha
+} -returnCodes error -result \
+ {invalid alpha value "-1": must be integer between 0 and 255}
+test imgPhoto-4.86 {ImgPhotoCmd, transparency set: invalid newVal} -setup {
+ image create photo photo1 -data green
+} -body {
+ photo1 transparency set 0 0 256 -alpha
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {invalid alpha value "256": must be integer between 0 and 255}
+test imgPhoto-4.87 {ImgPhotoCmd, transparency set: no opt} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -to 0 0 2 1
+ photo1 transparency set 0 0 0
+ photo1 transparency set 1 0 1
+ list [photo1 transparency get 0 0 -alpha] \
+ [photo1 transparency get 1 0 -alpha]
+} -cleanup {
+ imageCleanup
+} -result {255 0}
+# deleted: test imgPhoto-4.88 {ImgPhotoCmd, transparency set: -boolean}
+test imgPhoto-4.89 {ImgPhotoCmd, transparency set: -alpha} -setup {
+ image create photo photo1
+} -body {
+ photo1 put white -to 0 0 2 2
+ photo1 transparency set 0 0 0 -alpha
+ photo1 transparency set 1 0 1 -alpha
+ photo1 transparency set 0 1 254 -alpha
+ photo1 transparency set 1 1 255 -alpha
+ list [photo1 transparency get 0 0] [photo1 transparency get 1 0] \
+ [photo1 transparency get 0 1] [photo1 transparency get 1 1]
+} -cleanup {
+ imageCleanup
+} -result {1 0 0 0}
+test imgPhoto-4.90 {ImgPhotoCmd put: existing but not allowed opt} -setup {
+ image create photo photo1
+} -body {
+ photo1 put yellow -from 0 0 1 1
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {unrecognized option "-from": must be -format, or -to}
+test imgPhoto-4.91 {ImgPhotoCmd put: invalid option} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{0 1 2 3}} -bogus x
+} -returnCodes error -result \
+ {unrecognized option "-bogus": must be -format, or -to}
+test imgPhoto-4.92 {ImgPhotocmd put: missing data} -setup {
+ image create photo photo1
+} -body {
+ photo1 put -to 0 0
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 put data ?-option value ...?"}
+test imgPhoto-4.93 {ImgPhotoCmd put: data in ppm format} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ set imgdata [photo1 data -format ppm]
+ photo2 put $imgdata -format ppm
+ set result {}
+ if {[image width photo1] != [image width photo2] \
+ || [image height photo1] != [image height photo2]} {
+ lappend result [list [image width photo2] [image height photo2]]
+ } else {
+ lappend result 1
+ }
+ foreach point {{206 125} {67 12} {13 46} {19 184}} {
+ if {[photo1 get {*}$point] ne [photo2 get {*}$point]} {
+ lappend result [photo2 get {*}$point]
+ } else {
+ lappend result 1
+ }
+ }
+ set result
+} -cleanup {
+ imageCleanup
+} -result {1 1 1 1 1}
+test imgPhoto-4.94 {ImgPhotoCmd put: unknown format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {no real data} -format bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {image format "bogus" is not supported}
+test imgPhoto-4.95 {ImgPhotoCmd put: default fmt, invalid data} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{red green blue} {red " blue}}
+ #"
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {couldn't recognize image data}
+test imgPhoto-4.96 {ImgPhotoCmd put: "default" handler is selected} -setup {
+ image create photo photo1
+ image create photo photo2
+ set imgData {{{1 2 3 4} {5 6 7 8} {9 10 11 12}}
+ {{13 14 15 15} {17 18 19 20} {21 22 23 24}}}
+} -body {
+ photo1 put $imgData
+ photo2 put $imgData -format default
+ set result {}
+ lappend result [list [image width photo1] [image height photo1]]
+ lappend result [list [image width photo2] [image height photo2]]
+ lappend result [string equal \
+ [photo1 data -format "default -colorformat rgba"] \
+ [photo2 data -format "default -colorformat rgba"]]
+ set result
+} -cleanup {
+ imageCleanup
+ unset result
+ unset imgData
+} -result {{3 2} {3 2} 1}
+test imgPhoto-4.97 {ImgPhotoCmd put: image size} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{red green blue} {blue red green}}
+ list [image width photo1] [image height photo1]
+} -cleanup {
+ imageCleanup
+} -result {3 2}
+test imgPhoto-4.98 {ImgPhotoCmd put: -to with 2 coords} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{"alice blue" "blanched almond"}
+ {"deep sky blue" "ghost white"}
+ {#AABBCC #AABBCCDD}} -to 5 6
+ list [image width photo1] [image height photo1]
+} -cleanup {
+ imageCleanup
+} -result {7 9}
+test imgPhoto-4.99 {ImgPhotoCmd put: -to with 4 coords} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{#123 #456 #678} {#9AB #CDE #F01}} -to 1 2 20 21
+ set result {}
+ lappend result [photo1 get 19 20 -withalpha]
+ lappend result [string equal \
+ [photo1 data -from 1 2 4 4] [photo1 data -from 4 2 7 4]]
+ lappend result [string equal \
+ [photo1 data -from 10 12 13 14] [photo1 data -from 16 16 19 18]]
+ set result
+} -cleanup {
+ imageCleanup
+} -result {{17 34 51 255} 1 1}
+test imgPhoto-4.100 {ImgPhotoCmd put: no changes on empty data} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{brown blue} {cyan coral}}
+ set imgData [photo1 data]
+ photo1 put {}
+ string equal $imgData [photo1 data]
+} -cleanup {
+ imageCleanup
+} -result {1}
+test imgPhoto-4.101 {ImgPhotoCmd get: too many args} -setup {
+ image create photo photo1
+} -body {
+ photo1 get 0 0 -withalpha bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 get x y ?-withalpha?"}
+test imgPhoto-4.102 {ImgPhotoCmd get: invalid option} -setup {
+ image create photo photo1
+} -body {
+ photo1 get 0 0 -bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {unrecognized option "-bogus": must be -withalpha}
+test imgPhoto-4.103 {ImgPhotoCmd data: accepted opts} -setup {
+ image create photo photo1 -data black
+} -body {
+ photo1 data -format default -from 0 0 -grayscale -background blue
+} -cleanup {
+ imageCleanup
+} -result {{#000000}}
+test imgPhoto-4.104 {ImgPhotoCmd data: existing but not accepted opt} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -to
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+{unrecognized option "-to": must be -background, -format, -from, or -grayscale}
+test imgPhoto-4.105 {ImgPhotoCmd data: invalid option} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+{unrecognized option "-bogus": must be -background, -format, -from, or -grayscale}
+test imgPhoto-4.106 {ImgPhotoCmd data: extra arg before options} -setup {
+ image create photo photo1
+} -body {
+ photo1 data bogus -grayscale
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 data ?-option value ...?"}
+test imgPhoto-4.107 {ImgPhotoCmd data: extra arg after options} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format default bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {wrong # args: should be "photo1 data ?-option value ...?"}
+test imgPhoto-4.108 {ImgPhotoCmd data: invalid -from coords #1} -setup {
+ image create photo photo1 -data blue
+} -body {
+ photo1 data -from 2 0
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {coordinates for -from option extend outside image}
+test imgPhoto-4.109 {ImgPhotoCmd data: invalid -from coords #2} -setup {
+ image create photo photo1 -data blue
+} -body {
+ photo1 data -from 0 2
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {coordinates for -from option extend outside image}
+test imgPhoto-4.110 {ImgPhotoCmd data: invalid -from coords #3} -setup {
+ image create photo photo1 -data blue
+} -body {
+ photo1 data -from 0 0 2 1
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {coordinates for -from option extend outside image}
+test imgPhoto-4.111 {ImgPhotoCmd data: invalid -from coords #4} -setup {
+ image create photo photo1 -data blue
+} -body {
+ photo1 data -from 0 0 1 2
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result \
+ {coordinates for -from option extend outside image}
+test imgPhoto-4.112 {ImgPhotoCmd data: -from with 2 coords} -setup {
+ image create photo photo1 -data {
+ {black black black black black}
+ {white white white white white}
+ {green green green green green}}
+} -body {
+ set imgData [photo1 data -from 2 1]
+ list [llength [lindex $imgData 0]] [llength $imgData]
+} -cleanup {
+ imageCleanup
+ unset imgData
+} -result {3 2}
+test imgPhoto-4.113 {ImgPhotoCmd data: default is rgb format} -setup {
+ image create photo photo1 -data red
+} -body {
+ photo1 data
+} -cleanup {
+ imageCleanup
+} -result {{#ff0000}}
+test imgPhoto-4.114 {ImgPhotoCmd data: unknown format} -setup {
+ image create photo photo1
+} -body {
+ photo1 data -format bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {image string format "bogus" is unknown}
+test imgPhoto-4.115 {ImgPhotoCmd data: rgb colorformat} -setup {
+ image create photo photo1 -data {{red#a green#b} {blue#c white}}
+} -body {
+ photo1 data -format {default -colorformat rgb}
+} -result {{#ff0000 #008000} {#0000ff #ffffff}}
+test imgPhoto-4.116 {ImgPhotoCmd data: rgba colorformat} -setup {
+ image create photo photo1 -data {{red green} {blue white}}
+} -body {
+ photo1 data -format {default -colorformat rgba}
+} -result {{#ff0000ff #008000ff} {#0000ffff #ffffffff}}
+test imgPhoto-4.117 {ImgPhotoCmd data: list colorformat} -setup {
+ image create photo photo1 -data {{red#a green} {blue#c white#d}}
+} -body {
+ photo1 data -format {default -colorformat list}
+} -result {{{255 0 0 170} {0 128 0 255}} {{0 0 255 204} {255 255 255 221}}}
+test imgPhoto-4.118 {ImgPhotoCmd data: using data for new image
+ results in same image as orignial } -constraints {
+ hasTeapotPhoto
+ hasTranspTeapotPhoto
+} -setup {
+ image create photo teapot -file $teapotPhotoFile
+ teapot copy teapot -from 50 60 70 80 -shrink
+ image create photo teapotTransp -file $transpTeapotPhotoFile
+ teapotTransp copy teapotTransp -from 100 110 120 130 -shrink
+ image create photo photo1
+} -body {
+ set result {}
+ # We don't test gif here, as there seems to be a problem with
+ # <imgName> data and gif format ("too many colors", probably a bug)
+ foreach fmt {ppm png {default -colorformat rgba} \
+ {default -colorformat list}} {
+ set imgData [teapotTransp data -format $fmt]
+ photo1 blank
+ photo1 put $imgData
+ if { ! [string equal [photo1 data] [teapotTransp data]]} {
+ lappend result $fmt
+ }
+ }
+ set imgData [teapot data -format default]
+ photo1 blank
+ photo1 put $imgData
+ if { ! [string equal [photo1 data] [teapot data]]} {
+ lappend result default
+ }
+ set result
+} -cleanup {
+ unset imgData
+ unset result
+ imageCleanup
+} -result {}
+
test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} -constraints {
hasTeapotPhoto
} -setup {
@@ -843,7 +1386,7 @@ test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} -constraints {
} -cleanup {
destroy .c
} -result {}
-
+
test imgPhoto-6.1 {ImgPhotoDisplay procedure, blank display} -setup {
destroy .c
pack [canvas .c]
@@ -857,7 +1400,7 @@ test imgPhoto-6.1 {ImgPhotoDisplay procedure, blank display} -setup {
destroy .c
image delete photo1
} -result {}
-
+
test imgPhoto-7.1 {ImgPhotoFree procedure, resource freeing} -constraints {
hasTeapotPhoto
} -setup {
@@ -918,7 +1461,7 @@ test imgPhoto-7.3 {ImgPhotoFree procedures, multiple visuals} -constraints {
destroy .f
image delete photo1
} -result {}
-
+
test imgPhoto-8.1 {ImgPhotoDelete procedure} -constraints hasTeapotPhoto -body {
image create photo photo2 -file $teapotPhotoFile
image delete photo2
@@ -942,7 +1485,7 @@ test imgPhoto-8.3 {ImgPhotoDelete procedure, name cleanup} -body {
} -returnCodes error -cleanup {
imageCleanup
} -result {image "photo2" doesn't exist or is not a photo image}
-
+
test imgPhoto-9.1 {ImgPhotoCmdDeletedProc procedure} -constraints {
hasTeapotPhoto
} -body {
@@ -950,7 +1493,7 @@ test imgPhoto-9.1 {ImgPhotoCmdDeletedProc procedure} -constraints {
rename photo2 {}
list [lsearch -exact [imageNames] photo2] [catch {photo2 foo} msg] $msg
} -result {-1 1 {invalid command name "photo2"}}
-
+
test imgPhoto-10.1 {Tk_ImgPhotoPutBlock procedure} -setup {
imageCleanup
} -body {
@@ -997,7 +1540,6 @@ test imgPhoto-10.4 {Tk_ImgPhotoPutBlock, empty image} -setup {
imageCleanup
} -result {0 0}
-
test imgPhoto-11.1 {Tk_FindPhoto} -setup {
imageCleanup
} -body {
@@ -1007,7 +1549,7 @@ test imgPhoto-11.1 {Tk_FindPhoto} -setup {
} -cleanup {
imageCleanup
} -returnCodes error -result {image "i1" doesn't exist or is not a photo image}
-
+
test imgPhoto-12.1 {Tk_PhotoPutZoomedBlock} -constraints hasTeapotPhoto -body {
image create photo p3 -file $teapotPhotoFile
set result [list [p3 get 50 50] [p3 get 100 100]]
@@ -1096,7 +1638,7 @@ test imgPhoto-13.1 {check separation of images in different interpreters} -setup
interp delete x1
interp delete x2
} -result T1_data
-
+
test imgPhoto-14.1 {GIF writes work correctly} -setup {
set data {
R0lGODlhYwA5APcAAAAAAIAAAACAAICAAAAAgIAAgACAgICAgAysnGy8hKzM
@@ -1189,7 +1731,7 @@ test imgPhoto-14.4 {GIF buffer overflow} -setup {
} -cleanup {
image delete $i
} -returnCodes error -result {malformed image}
-
+
test imgPhoto-15.1 {photo images can fail to allocate memory gracefully} -constraints {
nonPortable
} -body {
@@ -1197,7 +1739,7 @@ test imgPhoto-15.1 {photo images can fail to allocate memory gracefully} -constr
# free memory available...
image create photo -width 32000 -height 32000
} -returnCodes error -result {not enough free memory for image buffer}
-
+
test imgPhoto-16.1 {copying to self doesn't access freed memory} -setup {
set i [image create photo]
} -body {
@@ -1208,7 +1750,7 @@ test imgPhoto-16.1 {copying to self doesn't access freed memory} -setup {
} -cleanup {
image delete $i
} -result {}
-
+
# Check that we can guess our supported output formats [Bug 2983824]
test imgPhoto-17.1 {photo write: format guessing from filename} -setup {
set i [image create photo -width 3 -height 3]
@@ -1247,6 +1789,109 @@ test imgPhoto-17.3 {photo write: format guessing from filename} -setup {
image delete $i
catch {removeFile $f}
} -result "P6\n"
+test imgPhoto-17.4 {photo write: default format not supported} -setup {
+ image create photo photo1 -data {{blue blue} {red red} {green green}}
+ set f [makeFile {} test.txt]
+} -body {
+ photo1 write $f -format default
+} -cleanup {
+ imageCleanup
+ catch {removeFile $f}
+ unset f
+} -returnCodes error -result \
+ {image file format "default" has no file writing capability}
+test imgPhoto-17.5 {photo write: file with extension .default} -setup {
+ image create photo photo1 -data {{black}}
+ set f [makeFile {} test.default]
+} -body {
+ photo1 write $f
+} -cleanup {
+ imageCleanup
+ catch {removeFile $f}
+ unset f
+} -returnCodes error -result \
+ {image file format "default" has no file writing capability}
+
+test imgPhoto-18.1 {MatchFileFormat: "default" format not supported} -setup {
+ image create photo photo1
+ set f [makeFile {} test.txt]
+} -body {
+ photo1 read $f -format default
+} -cleanup {
+ imageCleanup
+ catch {removeFile $f}
+ unset f
+} -returnCodes error -result {-file option isn't supported for default images}
+
+test imgPhoto-19.1 {MatchStringFormat: with "-format default"} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {{red blue red} {yellow green yellow}} -format default
+ list [image width photo1] [image height photo1]
+} -cleanup {
+ imageCleanup
+} -result {3 2}
+test imgPhoto-19.2 {MatchStringFormat: without -format option,
+ default fmt} -body {
+ image create photo photo1
+ photo1 put {{red} {green}}
+ list [image width photo1] [image height photo1]
+} -cleanup {
+ imageCleanup
+} -result {1 2}
+test imgPhoto-19.3 {MatchStringFormat: "-format ppm"} -setup {
+ image create photo photo1
+ image create photo photo2
+ photo2 put {cyan cyan}
+ set imgData [photo2 data -format ppm]
+} -body {
+ photo1 put $imgData -format ppm
+ list [image width photo1] [image height photo1]
+} -cleanup {
+ unset imgData
+ imageCleanup
+} -result {1 2}
+test imgPhoto-19.4 {MatchStringFormat: ppm fmt, without opt} -constraints {
+ hasTeapotPhoto
+} -setup {
+ image create photo photo1 -file $teapotPhotoFile
+ image create photo photo2
+} -body {
+ set imgData [photo1 data -format ppm]
+ photo2 put $imgData
+ list [image width photo2] [image height photo2]
+} -cleanup {
+ imageCleanup
+ unset imgData
+} -result {256 256}
+test imgPhoto-19.5 {MatchStirngFormat: unknown -format} -setup {
+ image create photo photo1
+} -body {
+ photo1 put {} -format bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {image format "bogus" is not supported}
+test imgPhoto-19.6 {MatchStringFormat: invalid data for default} -setup {
+ image create photo photo1
+} -body {
+ photo1 put bogus
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {couldn't recognize image data}
+test imgPhoto-19.7 {MatchStringFormat: invalid data for default} -setup {
+ image create photo photo1
+} -body {
+ photo1 put bogus -format dEFault
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {couldn't recognize image data}
+test imgPhoto-19.8 {MatchStirngFormat: invalid data for gif} -setup {
+ image create photo photo1
+} -body {
+ photo1 put bogus -format giF
+} -cleanup {
+ imageCleanup
+} -returnCodes error -result {couldn't recognize image data}
# Reject corrupted or truncated image [Bug b601ce3ab1].
# WARNING - tests 18.1-18.9 will cause a segfault on 8.5.19 and lower,
@@ -1256,7 +1901,7 @@ test imgPhoto-18.1 {Reject corrupted GIF (binary string)} -constraints {
} -setup {
package require base64
set data [base64::decode {
- R0lGODlhwjMz//8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
+ R0lGODlhAAQABP8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
5qpraXIvM1JlNyAgOw==
}]
} -body {
@@ -1266,7 +1911,7 @@ test imgPhoto-18.1 {Reject corrupted GIF (binary string)} -constraints {
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
test imgPhoto-18.2 {Reject corrupted GIF (base 64 string)} -setup {
set data {
- R0lGODlhwjMz//8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
+ R0lGODlhAAQABP8zM/8z/zP/MzP/////M////yH5CiwheLrcLTBCd6Tv2qW16tdK4jhV
5qpraXIvM1JlNyAgOw==
}
} -body {
@@ -1310,8 +1955,12 @@ test imgPhoto-18.6 {Reject truncated GIF (file)} -setup {
catch {image delete gif1}
} -returnCodes error -result {error reading color map}
test imgPhoto-18.7 {Reject corrupted GIF (> 4Gb) (binary string)} -constraints {
- base64PackageNeeded
+ base64PackageNeeded nonPortable
} -setup {
+ # About the non portability constraint of this test: see ticket [cc42cc18a5]
+ # If there is insufficient memory, the error message
+ # {not enough free memory for image buffer} should be returned.
+ # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
package require base64
set data [base64::decode {
R0lGODlhwmYz//8zM/8z/zP/MzP/////M////yH5Ciwhe
@@ -1322,7 +1971,13 @@ test imgPhoto-18.7 {Reject corrupted GIF (> 4Gb) (binary string)} -constraints {
} -cleanup {
catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
-test imgPhoto-18.8 {Reject corrupted GIF (> 4Gb) (base 64 string)} -setup {
+test imgPhoto-18.8 {Reject corrupted GIF (> 4Gb) (base 64 string)} -constraints {
+ nonPortable
+} -setup {
+ # About the non portability constraint of this test: see ticket [cc42cc18a5]
+ # If there is insufficient memory, the error message
+ # {not enough free memory for image buffer} should be returned.
+ # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
set data {
R0lGODlhwmYz//8zM/8z/zP/MzP/////M////yH5Ciwhe
LrcLTBCd6Tv2qW16tdK4jhV5qpraXIvM1JlNyAgOw==
@@ -1332,7 +1987,13 @@ test imgPhoto-18.8 {Reject corrupted GIF (> 4Gb) (base 64 string)} -setup {
} -cleanup {
catch {image delete gif1}
} -returnCodes error -result {error reading color map|not enough free memory for image buffer} -match regexp
-test imgPhoto-18.9 {Reject corrupted GIF (> 4Gb) (file)} -setup {
+test imgPhoto-18.9 {Reject corrupted GIF (> 4Gb) (file)} -constraints {
+ nonPortable
+} -setup {
+ # About the non portability constraint of this test: see ticket [cc42cc18a5]
+ # If there is insufficient memory, the error message
+ # {not enough free memory for image buffer} should be returned.
+ # Instead, some systems (e.g. FreeBSD 11.1) terminate the test interpreter.
set fileName [file join [file dirname [info script]] corruptMangled4G.gif]
} -body {
image create photo gif1 -file $fileName
diff --git a/tests/teapotTransparent.png b/tests/teapotTransparent.png
new file mode 100644