| 1 |
# Copyright (c) 1994 The Australian National University |
| 2 |
# Copyright (c) 1994-1997 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# Author: Paul Mackerras ([email protected]), |
| 7 |
# Department of Computer Science, |
| 8 |
# Australian National University. |
| 9 |
|
| 10 |
=head1 NAME |
| 11 |
|
| 12 |
Tk_CreatePhotoImageFormat - define new file format for photo images |
| 13 |
|
| 14 |
=for category C Programming |
| 15 |
|
| 16 |
=head1 SYNOPSIS |
| 17 |
|
| 18 |
B<#include E<lt>tk.hE<gt>> |
| 19 |
B<#include E<lt>tkPhoto.hE<gt>> |
| 20 |
|
| 21 |
B<Tk_CreatePhotoImageFormat>(I<formatPtr>) |
| 22 |
|
| 23 |
=head1 ARGUMENTS |
| 24 |
|
| 25 |
=over 4 |
| 26 |
|
| 27 |
=item Tk_PhotoImageFormat *formatPtr (in) |
| 28 |
|
| 29 |
Structure that defines the new file format. |
| 30 |
|
| 31 |
=back |
| 32 |
|
| 33 |
=head1 DESCRIPTION |
| 34 |
|
| 35 |
B<Tk_CreatePhotoImageFormat> is invoked to define a new file format |
| 36 |
for image data for use with photo images. The code that implements an |
| 37 |
image file format is called an image file format handler, or |
| 38 |
handler for short. The photo image code |
| 39 |
maintains a list of handlers that can be used to read and |
| 40 |
write data to or from a file. Some handlers may also |
| 41 |
support reading image data from a string or converting image data to a |
| 42 |
string format. |
| 43 |
The user can specify which handler to use with the B<-format> |
| 44 |
image configuration option or the B<-format> option to the |
| 45 |
B<read> and B<write> photo image subcommands. |
| 46 |
|
| 47 |
An image file format handler consists of a collection of procedures |
| 48 |
plus a Tk_PhotoImageFormat structure, which contains the name of the |
| 49 |
image file format and pointers to six procedures provided by the |
| 50 |
handler to deal with files and strings in this format. The |
| 51 |
Tk_PhotoImageFormat structure contains the following fields: |
| 52 |
|
| 53 |
typedef struct Tk_PhotoImageFormat { |
| 54 |
char *name; |
| 55 |
Tk_ImageFileMatchProc *fileMatchProc; |
| 56 |
Tk_ImageStringMatchProc *stringMatchProc; |
| 57 |
Tk_ImageFileReadProc *fileReadProc; |
| 58 |
Tk_ImageStringReadProc *stringReadProc; |
| 59 |
Tk_ImageFileWriteProc *fileWriteProc; |
| 60 |
Tk_ImageStringWriteProc *stringWriteProc; |
| 61 |
} Tk_PhotoImageFormat; |
| 62 |
|
| 63 |
The handler need not provide implementations of all six procedures. |
| 64 |
For example, the procedures that handle string data would not be |
| 65 |
provided for a format in which the image data are stored in binary, |
| 66 |
and could therefore contain null characters. If any procedure is not |
| 67 |
implemented, the corresponding pointer in the Tk_PhotoImageFormat |
| 68 |
structure should be set to NULL. The handler must provide the |
| 69 |
I<fileMatchProc> procedure if it provides the I<fileReadProc> |
| 70 |
procedure, and the I<stringMatchProc> procedure if it provides the |
| 71 |
I<stringReadProc> procedure. |
| 72 |
|
| 73 |
=head1 B<name> |
| 74 |
|
| 75 |
I<formatPtr-E<gt>name> provides a name for the image type. |
| 76 |
Once B<Tk_CreatePhotoImageFormat> returns, this name may be used |
| 77 |
in the B<-format> photo image configuration and subcommand option. |
| 78 |
The manual page for the photo image (photo(n)) describes how image |
| 79 |
file formats are chosen based on their names and the value given to |
| 80 |
the B<-format> option. |
| 81 |
|
| 82 |
=head1 FILEMATCHPROC |
| 83 |
|
| 84 |
I<formatPtr-E<gt>fileMatchProc> provides the address of a procedure for |
| 85 |
Tk to call when it is searching for an image file format handler |
| 86 |
suitable for reading data in a given file. |
| 87 |
I<formatPtr-E<gt>fileMatchProc> must match the following prototype: |
| 88 |
|
| 89 |
typedef int Tk_ImageFileMatchProc( |
| 90 |
Tcl_Channel chan, |
| 91 |
char *fileName, |
| 92 |
char *formatString, |
| 93 |
int *widthPtr, |
| 94 |
int *heightPtr); |
| 95 |
|
| 96 |
The I<fileName> argument is the name of the file containing the |
| 97 |
image data, which is open for reading as I<chan>. The |
| 98 |
I<formatString> argument contains the value given for the |
| 99 |
B<-format> option, or NULL if the option was not specified. |
| 100 |
If the data in the file appears to be in the format supported by this |
| 101 |
handler, the I<formatPtr-E<gt>fileMatchProc> procedure should store the |
| 102 |
width and height of the image in *I<widthPtr> and *I<heightPtr> |
| 103 |
respectively, and return 1. Otherwise it should return 0. |
| 104 |
|
| 105 |
=head1 STRINGMATCHPROC |
| 106 |
|
| 107 |
I<formatPtr-E<gt>stringMatchProc> provides the address of a procedure for |
| 108 |
Tk to call when it is searching for an image file format handler for |
| 109 |
suitable for reading data from a given string. |
| 110 |
I<formatPtr-E<gt>stringMatchProc> must match the following prototype: |
| 111 |
|
| 112 |
typedef int Tk_ImageStringMatchProc( |
| 113 |
char *string, |
| 114 |
char *formatString, |
| 115 |
int *widthPtr, |
| 116 |
int *heightPtr); |
| 117 |
|
| 118 |
The I<string> argument points to the string containing the image |
| 119 |
data. The I<formatString> argument contains the value given for |
| 120 |
the B<-format> option, or NULL if the option was not specified. |
| 121 |
If the data in the string appears to be in the format supported by |
| 122 |
this handler, the I<formatPtr-E<gt>stringMatchProc> procedure should |
| 123 |
store the width and height of the image in *I<widthPtr> and |
| 124 |
*I<heightPtr> respectively, and return 1. Otherwise it should |
| 125 |
return 0. |
| 126 |
|
| 127 |
=head1 FILEREADPROC |
| 128 |
|
| 129 |
I<formatPtr-E<gt>fileReadProc> provides the address of a procedure for |
| 130 |
Tk to call to read data from an image file into a photo image. |
| 131 |
I<formatPtr-E<gt>fileReadProc> must match the following prototype: |
| 132 |
|
| 133 |
typedef int Tk_ImageFileReadProc( |
| 134 |
Tcl_Interp *interp, |
| 135 |
Tcl_Channel chan, |
| 136 |
char *fileName, |
| 137 |
char *formatString, |
| 138 |
PhotoHandle imageHandle, |
| 139 |
int destX, int destY, |
| 140 |
int width, int height, |
| 141 |
int srcX, int srcY); |
| 142 |
|
| 143 |
The I<interp> argument is the interpreter in which the command was |
| 144 |
invoked to read the image; it should be used for reporting errors. |
| 145 |
The image data is in the file named I<fileName>, which is open for |
| 146 |
reading as I<chan>. The I<formatString> argument contains the |
| 147 |
value given for the B<-format> option, or NULL if the option was |
| 148 |
not specified. The image data in the file, or a subimage of it, is to |
| 149 |
be read into the photo image identified by the handle |
| 150 |
I<imageHandle>. The subimage of the data in the file is of |
| 151 |
dimensions I<width> x I<height> and has its top-left corner at |
| 152 |
coordinates (I<srcX>,I<srcY>). It is to be stored in the photo |
| 153 |
image with its top-left corner at coordinates |
| 154 |
(I<destX>,I<destY>) using the B<Tk_PhotoPutBlock> procedure. |
| 155 |
The return value is a standard Tcl return value. |
| 156 |
|
| 157 |
=head1 STRINGREADPROC |
| 158 |
|
| 159 |
I<formatPtr-E<gt>stringReadProc> provides the address of a procedure for |
| 160 |
Tk to call to read data from a string into a photo image. |
| 161 |
I<formatPtr-E<gt>stringReadProc> must match the following prototype: |
| 162 |
|
| 163 |
typedef int Tk_ImageStringReadProc( |
| 164 |
Tcl_Interp *interp, |
| 165 |
char *string, |
| 166 |
char *formatString, |
| 167 |
PhotoHandle imageHandle, |
| 168 |
int destX, int destY, |
| 169 |
int width, int height, |
| 170 |
int srcX, int srcY); |
| 171 |
|
| 172 |
The I<interp> argument is the interpreter in which the command was |
| 173 |
invoked to read the image; it should be used for reporting errors. |
| 174 |
The I<string> argument points to the image data in string form. |
| 175 |
The I<formatString> argument contains the |
| 176 |
value given for the B<-format> option, or NULL if the option was |
| 177 |
not specified. The image data in the string, or a subimage of it, is to |
| 178 |
be read into the photo image identified by the handle |
| 179 |
I<imageHandle>. The subimage of the data in the string is of |
| 180 |
dimensions I<width> x I<height> and has its top-left corner at |
| 181 |
coordinates (I<srcX>,I<srcY>). It is to be stored in the photo |
| 182 |
image with its top-left corner at coordinates |
| 183 |
(I<destX>,I<destY>) using the B<Tk_PhotoPutBlock> procedure. |
| 184 |
The return value is a standard Tcl return value. |
| 185 |
|
| 186 |
=head1 FILEWRITEPROC |
| 187 |
|
| 188 |
I<formatPtr-E<gt>fileWriteProc> provides the address of a procedure for |
| 189 |
Tk to call to write data from a photo image to a file. |
| 190 |
I<formatPtr-E<gt>fileWriteProc> must match the following prototype: |
| 191 |
|
| 192 |
typedef int Tk_ImageFileWriteProc( |
| 193 |
Tcl_Interp *interp, |
| 194 |
char *fileName, |
| 195 |
char *formatString, |
| 196 |
Tk_PhotoImageBlock *blockPtr); |
| 197 |
|
| 198 |
The I<interp> argument is the interpreter in which the command was |
| 199 |
invoked to write the image; it should be used for reporting errors. |
| 200 |
The image data to be written are in memory and are described by the |
| 201 |
Tk_PhotoImageBlock structure pointed to by I<blockPtr>; see the |
| 202 |
manual page FindPhoto(3) for details. The I<fileName> argument |
| 203 |
points to the string giving the name of the file in which to write the |
| 204 |
image data. The I<formatString> argument contains the |
| 205 |
value given for the B<-format> option, or NULL if the option was |
| 206 |
not specified. The format string can contain extra characters |
| 207 |
after the name of the format. If appropriate, the |
| 208 |
I<formatPtr-E<gt>fileWriteProc> procedure may interpret these |
| 209 |
characters to specify further details about the image file. |
| 210 |
The return value is a standard Tcl return value. |
| 211 |
|
| 212 |
=head1 STRINGWRITEPROC |
| 213 |
|
| 214 |
I<formatPtr-E<gt>stringWriteProc> provides the address of a procedure for |
| 215 |
Tk to call to translate image data from a photo image into a string. |
| 216 |
I<formatPtr-E<gt>stringWriteProc> must match the following prototype: |
| 217 |
|
| 218 |
typedef int Tk_ImageStringWriteProc( |
| 219 |
Tcl_Interp *interp, |
| 220 |
Tcl_DString *dataPtr, |
| 221 |
char *formatString, |
| 222 |
Tk_PhotoImageBlock *blockPtr); |
| 223 |
|
| 224 |
The I<interp> argument is the interpreter in which the command was |
| 225 |
invoked to convert the image; it should be used for reporting errors. |
| 226 |
The image data to be converted are in memory and are described by the |
| 227 |
Tk_PhotoImageBlock structure pointed to by I<blockPtr>; see the |
| 228 |
manual page FindPhoto(3) for details. The data for the string |
| 229 |
should be appended to the dynamic string given by I<dataPtr>. |
| 230 |
The I<formatString> argument contains the |
| 231 |
value given for the B<-format> option, or NULL if the option was |
| 232 |
not specified. The format string can contain extra characters |
| 233 |
after the name of the format. If appropriate, the |
| 234 |
I<formatPtr-E<gt>stringWriteProc> procedure may interpret these |
| 235 |
characters to specify further details about the image file. |
| 236 |
The return value is a standard Tcl return value. |
| 237 |
|
| 238 |
=head1 SEE ALSO |
| 239 |
|
| 240 |
L<Tk::FindPhoto>, L<Tk::FindPhoto> |
| 241 |
|
| 242 |
=head1 KEYWORDS |
| 243 |
|
| 244 |
photo image, image file |