Tk Source Code

Changes On Branch tip-714-image-driver-info
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch tip-714-image-driver-info Excluding Merge-Ins

This is equivalent to a diff from 6e560259 to a68b9232

2025-04-24
21:01
Fix [bb5c3d0ecc]: tk print command fails on windows check-in: 8fd0f283 user: fvogel tags: bug-bb5c3d0ecc
11:59
Fix [855ec435ef]: Aqua sometimes fails to set TkEventTarget when a new keyWindow is assigned - breaks BWidget DND. check-in: 87e85a52 user: jan.nijtmans tags: core-9-0-branch
11:52
Merge 9.0 check-in: 43dd3043 user: jan.nijtmans tags: trunk, main
2025-04-23
09:42
Attempt to fix [d2eac285d9]: tk print command fails with canvas widget Closed-Leaf check-in: fada46f6 user: jan.nijtmans tags: bug-d2eac285d9
2025-04-22
22:56
Merge trunk, resolve conflicts in winDialog.test check-in: b5831181 user: erikleunissen tags: tk_collect_test_utils, FINAL_REVIEW
2025-04-18
02:52
Merge trunk check-in: 1b5bbef9 user: kevin_walzer tags: tka11y
2025-04-14
14:01
merge main Leaf check-in: 49cf5954 user: oehhar tags: tip-714-alt
13:56
merge main, minimize diff Leaf check-in: a68b9232 user: oehhar tags: tip-714-image-driver-info
13:52
TIP714: copy "image types photo" syntax from branch [tip-714-alt] check-in: 50d9fd1d user: oehhar tags: tip-714-image-driver-info
2025-04-11
17:33
Fix [855ec435ef]: Aqua sometimes fails to set TkEventTarget when a new keyWindow is assigned - breaks BWidget DND. check-in: 6e560259 user: culler tags: trunk, main
15:57
Move the call to [NSApp setTkEventTarget:] into the windowActivation callback method of NSApp. Closed-Leaf check-in: 82221f8b user: culler tags: bug-855ec435ef
2025-04-10
19:32
WidgetDemo: Minor improvements in knightstour.tcl. check-in: 696a8519 user: csaba tags: trunk, main

Changes to doc/CrtImgType.3.
58
59
60
61
62
63
64


65
66
67
68
69
70
71
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







+
+







typedef struct {
    const char *\fIname\fR;
    Tk_ImageCreateProc *\fIcreateProc\fR;
    Tk_ImageGetProc *\fIgetProc\fR;
    Tk_ImageDisplayProc *\fIdisplayProc\fR;
    Tk_ImageFreeProc *\fIfreeProc\fR;
    Tk_ImageDeleteProc *\fIdeleteProc\fR;
    struct Tk_ImageType *\fInextPtr\fR;
    Tk_ImageInfoProc *\fIinfoProc\fR;
} \fBTk_ImageType\fR;
.CE
The fields of this structure will be described in later subsections
of this entry.
.PP
The second major data structure manipulated by an image manager
is called an \fIimage model\fR;  it contains overall information
221
222
223
224
225
226
227















228
229
230
231
232
233
234
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        void *\fImodelData\fR);
.CE
The \fImodelData\fR argument will be the same as the value
stored in \fI*modelDataPtr\fR by \fIcreateProc\fR when the
image was created.
\fIdeleteProc\fR should release any resources associated with
the image.
.SS NEXTPTR
.PP
This field will be filled out by Tk and is ignored.
.SS INFOPROC
.PP
\fItypePtr->infoProc\fR is a procedure that Tk invokes when the command \fBimage types\fR \fItype\fR is invoked.
The command result is set by the called procedure.
\fItypePtr->infoProc\fR must match the following prototype:
.CS
typedef int \fBTk_ImageInfoProc\fR(
        Tcl_Interp *\fIinterp\fR)
.CE
The \fIinterp\fR argument is the interpreter in which the \fBimage\fR
command was invoked.
Set \fItypePtr->infoProc\fR to NULL to not return any data.
.SH TK_GETIMAGEMODELDATA
.PP
The procedure \fBTk_GetImageModelData\fR may be invoked to retrieve
information about an image.  For example, an image manager can use this
procedure to locate its image model data for an image.
If there exists an image named \fIname\fR
in the interpreter given by \fIinterp\fR, then \fI*typePtrPtr\fR is
Changes to generic/tk.h.
1215
1216
1217
1218
1219
1220
1221

1222
1223
1224
1225
1226
1227
1228
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229







+







typedef void (Tk_ImageFreeProc) (void *clientData, Display *display);
typedef void (Tk_ImageDeleteProc) (void *clientData);
typedef void (Tk_ImageChangedProc) (void *clientData, int x, int y,
	int width, int height, int imageWidth, int imageHeight);
typedef int (Tk_ImagePostscriptProc) (void *clientData,
	Tcl_Interp *interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo,
	int x, int y, int width, int height, int prepass);
typedef int (Tk_ImageInfoProc) (Tcl_Interp *interp);

/*
 * The following structure represents a particular type of image (bitmap, xpm
 * image, etc.). It provides information common to all images of that type,
 * such as the type name and a collection of procedures in the image manager
 * that respond to various events. Each image manager is represented by one of
 * these structures.
1249
1250
1251
1252
1253
1254
1255
1256


1257
1258
1259
1260
1261
1262
1263
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1264
1265







-
+
+







    Tk_ImagePostscriptProc *postscriptProc;
				/* Procedure to call to produce postscript
				 * output for the image. */
    struct Tk_ImageType *nextPtr;
				/* Next in list of all image types currently
				 * known. Filled in by Tk, not by image
				 * manager. */
    char *reserved;		/* reserved for future expansion */
    Tk_ImageInfoProc *infoProc;
				/* Procedure to call to return the image info dict. */
};

/*
 *----------------------------------------------------------------------
 *
 * Additional definitions used to manage images of type "photo".
 *
Changes to generic/tkImage.c.
373
374
375
376
377
378
379
380
381


382
383

384
385
386
387
388
389
390














391
392
393
394
395
396
397
373
374
375
376
377
378
379


380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412







-
-
+
+


+







+
+
+
+
+
+
+
+
+
+
+
+
+
+







	    }
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    (const char *)Tcl_GetHashKey(&winPtr->mainPtr->imageTable, hPtr), TCL_INDEX_NONE));
	}
	Tcl_SetObjResult(interp, resultObj);
	break;
    case IMAGE_TYPES:
	if (objc != 2) {
	    Tcl_WrongNumArgs(interp, 2, objv, NULL);
	if (objc != 2 && objc != 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?type?");
	    return TCL_ERROR;
	}
if (objc == 2) {
	resultObj = Tcl_NewObj();
	for (typePtr = tsdPtr->imageTypeList; typePtr != NULL;
		typePtr = typePtr->nextPtr) {
	    Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj(
		    typePtr->name, TCL_INDEX_NONE));
	}
	Tcl_SetObjResult(interp, resultObj);
} else {
	char *stringArg;
	stringArg = Tcl_GetString(objv[2]);
	for (typePtr = tsdPtr->imageTypeList; typePtr != NULL;
	    typePtr = typePtr->nextPtr) {
	    if (0 == strcmp(stringArg, typePtr->name)
			    && typePtr->infoProc != NULL) {
		int res;
		res = typePtr->infoProc(interp);
		if (res != TCL_OK)
		return res;
	    }
	}
}
	break;

    case IMAGE_HEIGHT:
    case IMAGE_INUSE:
    case IMAGE_TYPE:
    case IMAGE_WIDTH:
	/*
Changes to generic/tkImgBmap.c.
95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109







-
+







    ImgBmapCreate,		/* createProc */
    ImgBmapGet,			/* getProc */
    ImgBmapDisplay,		/* displayProc */
    ImgBmapFree,		/* freeProc */
    ImgBmapDelete,		/* deleteProc */
    ImgBmapPostscript,		/* postscriptProc */
    NULL,			/* nextPtr */
    NULL
    NULL			/* no infoProc */
};

/*
 * Information used for parsing configuration specs:
 */

static const Tk_ConfigSpec configSpecs[] = {
Changes to generic/tkImgPhoto.c.
114
115
116
117
118
119
120

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
143







+














-
+







			    const Tk_ImageType *typePtr, Tk_ImageModel model,
			    void **clientDataPtr);
static void		ImgPhotoDelete(void *clientData);
static int		ImgPhotoPostscript(void *clientData,
			    Tcl_Interp *interp, Tk_Window tkwin,
			    Tk_PostscriptInfo psInfo, int x, int y, int width,
			    int height, int prepass);
static int		ImgPhotoInfoProc(Tcl_Interp *interp);

/*
 * The type record itself for photo images:
 */

Tk_ImageType tkPhotoImageType = {
    "photo",			/* name */
    ImgPhotoCreate,		/* createProc */
    TkImgPhotoGet,		/* getProc */
    TkImgPhotoDisplay,		/* displayProc */
    TkImgPhotoFree,		/* freeProc */
    ImgPhotoDelete,		/* deleteProc */
    ImgPhotoPostscript,		/* postscriptProc */
    NULL,			/* nextPtr */
    NULL
    ImgPhotoInfoProc		/* infoProc */
};

typedef struct {
    Tk_PhotoImageFormat *formatList;
				/* Pointer to the first in the list of known
				 * photo image formats.*/
    Tk_PhotoImageFormatVersion3 *formatListVersion3;
4373
4374
4375
4376
4377
4378
4379
4380
4381



































































































4382
4383
4384
4385
4386
4387
4388
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488









+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    Tk_PhotoImageBlock block;

    Tk_PhotoGetImage(clientData, &block);
    block.pixelPtr += y * block.pitch + x * block.pixelSize;

    return Tk_PostscriptPhoto(interp, &block, psInfo, width, height);
}

/*
 *--------------------------------------------------------------
 *
 * TkPhotoInfoProc --
 *
 *	This function is called to return an information dict on
 *	all photo images.
 *	It is called by the command "image types photo".
 *
 * Results:
 *	Returns a standard Tcl return value.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

static int
ImgPhotoInfoProc(Tcl_Interp *interp) {

    Tcl_Obj *resultObj, *formatValueObj, *fileValueObj, *writeValueObj;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tk_PhotoImageFormat *formatPtr;
    Tk_PhotoImageFormatVersion3 *formatVersion3Ptr;
    const char * defaultFormatName = NULL;

    formatValueObj = Tcl_NewListObj(0, NULL);
    fileValueObj = Tcl_NewListObj(0, NULL);
    writeValueObj = Tcl_NewListObj(0, NULL);

    /*
     * Scan through the table of file format handlers and collect the
     * data.
     */

    for (formatPtr = tsdPtr->formatList; formatPtr != NULL;
	    formatPtr = formatPtr->nextPtr) {

	/*
	 * Default will be evaluated last, so put it at the end of the
	 * evaluation list
	 */

	if (strncasecmp("default", formatPtr->name,
		strlen(formatPtr->name)) == 0) {
	    defaultFormatName = formatPtr->name;

	    /*
	     * The default format does not implement any file operations.
	     * So no need to check for fileMatchProc or fileWriteProc
	     */

	} else {
	    Tcl_Obj *formatNameObj = Tcl_NewStringObj(formatPtr->name,-1);
	    Tcl_ListObjAppendElement(NULL, formatValueObj, formatNameObj);
	    if (NULL != formatPtr->fileMatchProc) {
		Tcl_ListObjAppendElement(NULL, fileValueObj, formatNameObj);
	    }
	    if (NULL != formatPtr->fileWriteProc) {
		Tcl_ListObjAppendElement(NULL, writeValueObj, formatNameObj);
	    }
	}
    }

    for (formatVersion3Ptr = tsdPtr->formatListVersion3;
	    formatVersion3Ptr != NULL;
	    formatVersion3Ptr = formatVersion3Ptr->nextPtr) {
	Tcl_Obj *formatNameObj = Tcl_NewStringObj(formatVersion3Ptr->name,-1);
	Tcl_ListObjAppendElement(NULL, formatValueObj, formatNameObj);
	if (NULL != formatVersion3Ptr->fileMatchProc) {
	    Tcl_ListObjAppendElement(NULL, fileValueObj, formatNameObj);
	}
	if (NULL != formatVersion3Ptr->fileWriteProc) {
	    Tcl_ListObjAppendElement(NULL, writeValueObj, formatNameObj);
	}
    }

    if (NULL != defaultFormatName) {
	Tcl_ListObjAppendElement(interp, formatValueObj,
		Tcl_NewStringObj(defaultFormatName, -1));
    }

    /*
     * set the format key in the result dictionary
     */

    resultObj = Tcl_NewObj();
    Tcl_DictObjPut(NULL, resultObj, Tcl_NewStringObj("format", -1),
	    formatValueObj);
    Tcl_DictObjPut(NULL, resultObj, Tcl_NewStringObj("file", -1),
	    fileValueObj);
    Tcl_DictObjPut(NULL, resultObj, Tcl_NewStringObj("write", -1),
	    writeValueObj);
    Tcl_SetObjResult(interp, resultObj);
    return TCL_OK;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * tab-width: 8
 * End:
 */
Changes to tests/image.test.
283
284
285
286
287
288
289
290
291


292
293
294



295
296
297
298
299
300
301
283
284
285
286
287
288
289


290
291
292
293
294
295
296
297
298
299
300
301
302
303
304







-
-
+
+



+
+
+







    imageCleanup
} -returnCodes error -result {image "myimage" does not exist}


test image-6.1 {Tk_ImageCmd procedure, "types" option} -constraints {
    testImageType
} -body {
    image types x
} -returnCodes error -result {wrong # args: should be "image types"}
    image types x y
} -returnCodes error -result {wrong # args: should be "image types ?type?"}
test image-6.2 {Tk_ImageCmd procedure, "types" option} -body {
    lsort [image types]
} -match glob -result {bitmap*photo test}
test image-6.3 {Tk_ImageCmd procedure, "types" argument} -body {
    image types x
} -result {}


test image-7.1 {Tk_ImageCmd procedure, "width" option} -body {
    image width
} -returnCodes error -result {wrong # args: should be "image width name"}
test image-7.2 {Tk_ImageCmd procedure, "width" option} -body {
    image width a b
Changes to tests/imgPhoto.test.
2695
2696
2697
2698
2699
2700
2701
















2702
2703
2704
2705
2706
2707
2708
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    image create photo png1
    catch {png1 read $ousterPhotoFile -from 102 62 2000 1000} msg
    list $msg [image width png1] [image height png1]
} -cleanup {
    catch {image delete png1}
} -result {{coordinates for -from option extend outside source image} 0 0}
unset ousterPhotoFile

# test 26.x: ImgPhotoInfo, command "image types photo"

test image-26.1 {ImgPhotoDriver/image types photo: format key} -body {
    dict get [image types photo] format
} -match glob -result {svg ppm png gif *default}
# take into account, that the list of formats may extend
# Any new format may be inserted between our own ones and the default format.

test image-26.2 {ImgPhotoDriver/image types photo: format file} -body {
    dict get [image types photo] file
} -match glob -result {svg ppm png gif*}

test image-26.3 {ImgPhotoDriver/image types photo: format write} -body {
    dict get [image types photo] write
} -match glob -result {ppm png gif*}

catch {rename foreachPixel {}}
catch {rename checkImgTrans {}}
catch {rename checkImgTransLoop {}}
imageFinish

# cleanup