SYNOPSIS
#include <tk.h>
Tk_CreatePhotoImageFormat(formatPtr)
ARGUMENTS
-
Tk_PhotoImageFormat *formatPtr (in)
Structure that defines the new file format.
DESCRIPTION
Tk_CreatePhotoImageFormat is invoked 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 handler for short. The photo image code maintains a list of handlers that can be used to read and write data to or from a file. Some handlers may also support reading image data from a string or converting image data to a string format. The user can specify which handler to use with the -format image configuration option or the -format option to the read and write photo image subcommands.
An image file format handler consists of a collection of procedures plus a Tk_PhotoImageFormat structure, which contains 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_PhotoImageFormat structure contains the following fields:
-
typedef struct Tk_PhotoImageFormat { char *name; Tk_ImageFileMatchProc *fileMatchProc; Tk_ImageStringMatchProc *stringMatchProc; Tk_ImageFileReadProc *fileReadProc; Tk_ImageStringReadProc *stringReadProc; Tk_ImageFileWriteProc *fileWriteProc; Tk_ImageStringWriteProc *stringWriteProc; } Tk_PhotoImageFormat;
The handler need not provide implementations of all six procedures. For example, the procedures that handle string data would not be provided for a format in which the image data are stored in binary, and could therefore contain null characters. If any procedure is not implemented, the corresponding pointer in the Tk_PhotoImageFormat structure should be set to NULL. The handler must provide the fileMatchProc procedure if it provides the fileReadProc procedure, and the stringMatchProc procedure if it provides the stringReadProc procedure.
PORTABILITY
In Tk 8.2 and earlier, a different interface was used. Tk 8.3 will still support the old format handlers if the format name is in upper case. If you still want to compile old format handlers with Tk8.3, use the flag -DUSE_OLD_IMAGE. This will restore all function prototypes to match the pre-8.3 situation.
NAME
formatPtr->name provides a name for the image type. Once Tk_CreatePhotoImageFormat 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. For new format handlers, the name should be in lower case. Pre-8.3 format handlers are assumed to be in upper case.
FILEMATCHPROC
formatPtr->fileMatchProc provides the address of a procedure for Tk to call when it is 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_ImageFileMatchProc( Tcl_Channel chan, CONST char *fileName, Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp);
STRINGMATCHPROC
formatPtr->stringMatchProc provides the address of a procedure for Tk to call when it is searching for an image file format handler for suitable for reading data from a given string. formatPtr->stringMatchProc must match the following prototype:-
typedef int Tk_ImageStringMatchProc( Tcl_Obj *data, Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp);
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_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 provides the address of a procedure for Tk to call to read data from a string into a photo image. formatPtr->stringReadProc must match the following prototype:-
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 provides the address of a procedure for Tk to call to write data from a photo image to a file. formatPtr->fileWriteProc must match the following prototype:-
typedef int Tk_ImageFileWriteProc( Tcl_Interp *interp, CONST char *fileName, Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
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 the following prototype:-
typedef int Tk_ImageStringWriteProc( Tcl_Interp *interp, Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
KEYWORDS
photo image, image file