Tk_Create...mageFormat(3tk)
β¨ Tk_CreatePhotoImageFormat β Tk Library Procedures β¨
okay bestie, welcome to the Tk_Create...mageFormat(3tk) manual page π this one is a whole journey β it's the tea on how you teach Tk a brand-new image file format. buckle up.
π NAME π
Tk_CreatePhotoImageFormat β define a new file format for photo images. slay.
π SYNOPSIS π
#include <tk.h>
Tk_CreatePhotoImageFormatVersion3(formatVersion3Ptr)
Tk_CreatePhotoImageFormat(formatPtr)
π¦ ARGUMENTS π¦
const Tk_PhotoImageFormatVersion3 *formatVersion3Ptr(in) β a structure that defines the new file format, including the metadata functionality. the full package fr fr.const Tk_PhotoImageFormat *formatPtr(in) β a structure that defines the new file format. that's it, that's the vibe.
π DESCRIPTION π
so Tk_CreatePhotoImageFormatVersion3 is what you invoke to define a new file format for image data, for use with photo images. the code that implements an image file format is called an image file format handler, or just handler for short. iconic name, no notes.
the photo image code keeps a whole list of handlers that can be used to read and write data to or from a file. some handlers can also support reading image data from a string, or converting image data into a string format. π
and how does the user pick which handler to use? with the -format image configuration option, or the -format option to the read and write photo image subcommands. iykyk.
the alternate version 2 function Tk_CreatePhotoImageFormat has identical functionality, but it does not let the handler get or return the metadata dictionary of the image. it's described down in section VERSION 2 INTERFACE below β we'll get there, don't worry.
an image file format handler is a collection of procedures plus a Tk_PhotoImageFormatVersion3 structure, which holds the name of the image file format and pointers to six procedures provided by the handler, to deal with files and strings in this format. the Tk_PhotoImageFormatVersion3 structure contains the following fields:
typedef struct {
const char *name;
Tk_ImageFileMatchProcVersion3 *fileMatchProc;
Tk_ImageStringMatchProcVersion3 *stringMatchProc;
Tk_ImageFileReadProcVersion3 *fileReadProc;
Tk_ImageStringReadProcVersion3 *stringReadProc;
Tk_ImageFileWriteProcVersion3 *fileWriteProc;
Tk_ImageStringWriteProcVersion3 *stringWriteProc;
} Tk_PhotoImageFormatVersion3;
the handler does not need to implement all six procedures. for example, the procedures that handle string data wouldn't be provided for a format where the image data are stored in binary and could therefore contain null characters. if any procedure isn't implemented, the corresponding pointer in the Tk_PhotoImageFormat structure should be set to NULL.
π¨ but listen β the handler must provide thefileMatchProcprocedure if it provides thefileReadProcprocedure, and it must provide thestringMatchProcprocedure if it provides thestringReadProcprocedure. no matchy, no ready. periodt.
π NAME π
formatPtr->name provides a name for the image type. once Tk_CreatePhotoImageFormatVersion3 returns, this name may be used in the -format photo image configuration and subcommand option. the manual page for the photo image (photo(3tk)) describes how image file formats are chosen based on their names and the value given to the -format option.
and here's a lil rule: the first character of formatPtr->name must not be an uppercase character from the ASCII character set β that is, one of the characters A-Z. those names are used only for legacy interface support (see below). π
πΈ FILEMATCHPROC πΈ
formatPtr->fileMatchProc provides the address of a procedure for Tk to call when it's searching for an image file format handler suitable for reading data in a given file. formatPtr->fileMatchProc must match the following prototype:
typedef int Tk_ImageFileMatchProcVersion3(
Tcl_Interp *interp,
Tcl_Channel chan,
const char *fileName,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
int *widthPtr,
int *heightPtr,
Tcl_Obj *metadataOut);
the fileName argument is the name of the file containing the image data, which is open for reading as chan. the format argument contains the value given for the -format option, or NULL if the option was not specified. metadataIn and metadataOut inputs and returns a metadata dictionary as described in section METADATA INTERFACE below.
if the data in the file appears to be in the format supported by this handler, the formatPtr->fileMatchProc procedure should store the width and height of the image in *widthPtr and *heightPtr respectively, and return 1. otherwise it should return 0. simple as that π«Ά
π§ STRINGMATCHPROC π§
formatPtr->stringMatchProc provides the address of a procedure for Tk to call when it's searching for an image file format handler suitable for reading data from a given string. formatPtr->stringMatchProc must match the following prototype:
typedef int Tk_ImageStringMatchProcVersion3(
Tcl_Interp *interp,
Tcl_Obj *data,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
int *widthPtr,
int *heightPtr,
Tcl_Obj *metadataOut);
the data argument points to the object containing the image data. the format argument contains the value given for the -format option, or NULL if the option was not specified. metadataIn and metadataOut inputs and returns a metadata dictionary as described in section METADATA INTERFACE below.
if the data in the string appears to be in the format supported by this handler, the formatPtr->stringMatchProc procedure should store the width and height of the image in *widthPtr and *heightPtr respectively, and return 1. otherwise it should return 0. β¨
π FILEREADPROC π
formatPtr->fileReadProc provides the address of a procedure for Tk to call to read data from an image file into a photo image. formatPtr->fileReadProc must match the following prototype:
typedef int Tk_ImageFileReadProcVersion3(
Tcl_Interp *interp,
Tcl_Channel chan,
const char *fileName,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
PhotoHandle imageHandle,
int destX, int destY,
int width, int height,
int srcX, int srcY,
Tcl_Obj *metadataOut);
the interp argument is the interpreter in which the command was invoked to read the image; it should be used for reporting errors. the image data is in the file named fileName, which is open for reading as chan. the format argument contains the value given for the -format option, or NULL if the option was not specified.
the image data in the file, or a subimage of it, is to be read into the photo image identified by the handle imageHandle. the subimage of the data in the file is of dimensions width x height and has its top-left corner at coordinates (srcX,srcY). it is to be stored in the photo image with its top-left corner at coordinates (destX,destY) using the Tk_PhotoPutBlock procedure. metadataIn and metadataOut inputs and returns a metadata dictionary as described in section METADATA INTERFACE below. the return value is a standard Tcl return value. π
π STRINGREADPROC
formatPtr->stringReadProc is the address of a procedure that Tk calls when it needs to read data from a string into a photo image. β¨
It's gotta match this prototype, exactly, no edits bestie:
typedef int Tk_ImageStringReadProcVersion3(
Tcl_Interp *interp,
Tcl_Obj *data,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
PhotoHandle imageHandle,
int destX, int destY,
int width, int height,
int srcX, int srcY,
Tcl_Obj *metadataOut);
The interp argument is the interpreter in which the command was invoked to read the image β use it for reporting errors, that's literally its whole job. The data argument points to the image data in object form. The format argument holds the value given for the -format option, or NULL if the option wasn't specified at all.
The image data in the string, or a subimage of it, gets read into the photo image identified by the handle imageHandle. That subimage of the data in the string is width x height in dimensions and its top-left corner sits at coordinates (srcX,srcY). It's to be stored in the photo image with its top-left corner at coordinates (destX,destY) using the Tk_PhotoPutBlock procedure. π
metadataIn and metadataOut input and return a metadata dictionary, as described in section METADATA INTERFACE below. The return value is a standard Tcl return value. π
π FILEWRITEPROC
formatPtr->fileWriteProc gives the address of a procedure for Tk to call when it needs to write data from a photo image to a file. π¦
formatPtr->fileWriteProc must match this prototype:
typedef int Tk_ImageFileWriteProcVersion3(
Tcl_Interp *interp,
const char *fileName,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
Tk_PhotoImageBlock *blockPtr);
The interp argument is the interpreter in which the command was invoked to write the image; use it for reporting errors. The image data to be written are in memory and are described by the Tk_PhotoImageBlock structure pointed to by blockPtr β go check the manual page FindPhoto(3tk) for the details, iykyk. The fileName argument points to the string giving the name of the file in which to write the image data.
The format argument contains the value given for the -format option, or NULL if the option wasn't specified. Heads up: the format string can contain extra characters after the name of the format. If appropriate, the formatPtr->fileWriteProc procedure may interpret those characters to specify further details about the image file. π
metadataIn may contain metadata keys that a driver may include into the output data. The return value is a standard Tcl return value. πΈ
πΎ STRINGWRITEPROC
formatPtr->stringWriteProc provides the address of a procedure for Tk to call to translate image data from a photo image into a string. β¨
formatPtr->stringWriteProc must match this prototype:
typedef int Tk_ImageStringWriteProcVersion3(
Tcl_Interp *interp,
Tcl_Obj *format,
Tcl_Obj *metadataIn,
Tk_PhotoImageBlock *blockPtr);
The interp argument is the interpreter in which the command was invoked to convert the image; use it for reporting errors. The image data to be converted are in memory and are described by the Tk_PhotoImageBlock structure pointed to by blockPtr; see the manual page FindPhoto(3tk) for details. The data for the string should be put in the interpreter interp result. π«Ά
The format argument contains the value given for the -format option, or NULL if the option wasn't specified. And yes, same deal as before: the format string can contain extra characters after the name of the format, and if appropriate the formatPtr->stringWriteProc procedure may interpret those characters to specify further details about the image file. metadataIn may contain metadata keys that a driver may include into the output data. The return value is a standard Tcl return value. π
ποΈ METADATA INTERFACE
Image formats contain a description of the image bitmap and may contain additional info like image resolution or comments. Image metadata may be read from image files and passed to the script level by including dictionary keys into the metadata property of the image. Image metadata may be written to image data on file write or image data output. π₯
π METADATA KEYS
The metadata may contain any key. A driver will handle only a set of dictionary keys documented in the documentation. See the photo image manual page for currently defined keys for the system drivers. π
These rules may give you guidance when naming metadata keys:
- Abbreviations are in upper case.
- Words are in US English in small case (except proper nouns).
- Vertical DPI is expressed as
DPI/aspect. The reason is, that some image formats may feature aspect and no resolution value.
π₯ METADATA INPUT
Each driver function gets a Tcl object pointer metadataIn as a parameter. This parameter serves to input a metadata dict to the driver function. It may be NULL to flag that the metadata dict is empty. π
A typical driver code snipped to check for a metadata key is:
if (NULL != metadataIn) {
Tcl_Obj *itemData;
Tcl_DictObjGet(interp, metadataIn, Tcl_NewStringObj("Comment",-1),
&itemData));
// use value reference in itemData
}
The -metadata command option data of the following commands is passed to the driver: image create, configure, put, read, data and write. If no -metadata command option available or not given, the metadata property of the image is passed to the driver using the following commands: cget, configure, data and write. π
Note that setting the-metadataproperty of an image usingconfigurewithout any other option does not invoke any driver function. π
The metadata dictionary is not suited to pass options to the driver related to the bitmap representation, as the image bitmap is not recreated on a metadata change. The format string should be used for this purpose. π
π€ METADATA OUTPUT
The image match and read driver functions may set keys in a prepared metadata dict to return them. Those functions get a Tcl object pointer metadataOut as parameter. metadataOut may be NULL to indicate, that no metadata return is required (put, read subcommands). The variable pointed to by metadataOut is initialized to an empty unshared dict object if metadata return is attended (image create command, configure subcommand). The driver may set dict keys in this object to return metadata. If a match function succeeds, the metadataOut pointer is passed to the corresponding read function. π¦
A sample driver code snippet is:
if (NULL != metadataOut) {
Tcl_DictObjPut(NULL, metadataOut, Tcl_NewStringObj("XMP",-1),
Tcl_NewStringObj(xmpMetadata));
}
The metadata keys returned by the driver are merged into the present metadata property of the image or into the metadata dict given by the -metadata command line option. At the script level, the command image create and the configure method may return metadata from the driver. β
Format string options or metadata keys may influence the creation of metadata within the driver. For example, the creation of an expensive metadata key may depend on a format string option or on a metadata input key. π
π°οΈ VERSION 2 INTERFACE
Version 2 Interface does not include the possibility for the driver to use the metadata dict for input or output. π
π SYNOPSIS
#include <tk.h>
Tk_CreatePhotoImageFormat(formatPtr)
π§Ύ ARGUMENTS
const Tk_PhotoImageFormat *formatPtr(in) β Structure that defines the new file format. π
okay so continuing bestie, no cap π
a driver using the version 2 interface invokes Tk_CreatePhotoImageFormat for driver registration. and the Tk_PhotoImageFormat structure contains these fields, periodt:
typedef struct {
const char *name;
Tk_ImageFileMatchProc *fileMatchProc;
Tk_ImageStringMatchProc *stringMatchProc;
Tk_ImageFileReadProc *fileReadProc;
Tk_ImageStringReadProc *stringReadProc;
Tk_ImageFileWriteProc *fileWriteProc;
Tk_ImageStringWriteProc *stringWriteProc;
} Tk_PhotoImageFormat;
π FILEMATCHPROC π
formatPtr->fileMatchProc must match the following prototype, fr fr β no improvising:
typedef int Tk_ImageFileMatchProc(
Tcl_Channel chan,
const char *fileName,
Tcl_Obj *format,
int *widthPtr,
int *heightPtr,
Tcl_Interp *interp);
πΈ STRINGMATCHPROC πΈ
formatPtr->stringMatchProc must match the following prototype, iykyk:
typedef int Tk_ImageStringMatchProc(
Tcl_Obj *data,
Tcl_Obj *format,
int *widthPtr,
int *heightPtr,
Tcl_Interp *interp);
β¨ FILEREADPROC β¨
formatPtr->fileReadProc must match the following prototype β and yes, every argument is giving exactly this energy:
typedef int Tk_ImageFileReadProc(
Tcl_Interp *interp,
Tcl_Channel chan,
const char *fileName,
Tcl_Obj *format,
PhotoHandle imageHandle,
int destX, int destY,
int width, int height,
int srcX, int srcY);
π¦ STRINGREADPROC π¦
formatPtr->stringReadProc must match the following prototype, bestie:
typedef int Tk_ImageStringReadProc(
Tcl_Interp *interp,
Tcl_Obj *data,
Tcl_Obj *format,
PhotoHandle imageHandle,
int destX, int destY,
int width, int height,
int srcX, int srcY);
π FILEWRITEPROC π
formatPtr->fileWriteProc must match the following prototype, and it's iconic:
typedef int Tk_ImageFileWriteProc(
Tcl_Interp *interp,
const char *fileName,
Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr);
π STRINGWRITEPROC π
formatPtr->stringWriteProc must match the following prototype, periodt:
typedef int Tk_ImageStringWriteProc(
Tcl_Interp *interp,
Tcl_Obj *format,
Tk_PhotoImageBlock *blockPtr);
π SEE ALSO π
Tk_FindPhotoTk_PhotoPutBlock
π KEYWORDS π
- photo image
- image file
xoxo, this page is serving Tk 9.0 energy and it's literally Tk_Create...mageFormat(3tk) β go off, you got this π«Άβ¨
π¦ where this page comes from
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1994 The Australian National University
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms