OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / doc / photo.n
1 '\"
2 '\" Copyright (c) 1994 The Australian National University
3 '\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 '\" Author: Paul Mackerras (paulus@cs.anu.edu.au),
9 '\"         Department of Computer Science,
10 '\"         Australian National University.
11 '\"
12 .TH photo n 4.0 Tk "Tk Built-In Commands"
13 .so man.macros
14 .BS
15 '\" Note:  do not modify the .SH NAME line immediately below!
16 .SH NAME
17 photo \- Full-color images
18 .SH SYNOPSIS
19 .nf
20 \fBimage create photo \fR?\fIname\fR? ?\fIoptions\fR?
21
22 \fIimageName \fBblank\fR
23 \fIimageName \fBcget \fIoption\fR
24 \fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
25 \fIimageName \fBcopy \fIsourceImage\fR ?\fIoption value(s) ...\fR?
26 \fIimageName \fBdata\fR ?\fIoption value(s) ...\fR?
27 \fIimageName \fBget \fIx y\fR
28 \fIimageName \fBput \fIdata\fR ?\fIoption value(s) ...\fR?
29 \fIimageName \fBread \fIfilename\fR ?\fIoption value(s) ...\fR?
30 \fIimageName \fBredither\fR
31 \fIimageName \fBtransparency \fIsubcommand \fR?\fIarg arg ...\fR?
32 \fIimageName \fBwrite \fIfilename\fR ?\fIoption value(s) ...\fR?
33 .fi
34 .BE
35 .SH DESCRIPTION
36 .PP
37 A photo is an image whose pixels can display any color or be
38 transparent.  A photo image is stored internally in full color (32
39 bits per pixel), and is displayed using dithering if necessary.  Image
40 data for a photo image can be obtained from a file or a string, or it
41 can be supplied from
42 C code through a procedural interface.  At present, only
43 .VS 8.6
44 PNG,
45 .VE 8.6
46 GIF and PPM/PGM
47 formats are supported, but an interface exists to allow additional
48 image file formats to be added easily.  A photo image is transparent
49 in regions where no image data has been supplied
50 or where it has been set transparent by the \fBtransparency set\fR
51 subcommand.
52 .SH "CREATING PHOTOS"
53 .PP
54 Like all images, photos are created using the \fBimage create\fR
55 command.
56 Photos support the following \fIoptions\fR:
57 .TP
58 \fB\-data \fIstring\fR
59 .
60 Specifies the contents of the image as a string.  The string should
61 contain binary data or, for some formats, base64-encoded data (this is
62 currently guaranteed to be supported for PNG and GIF images). The
63 format of the
64 string must be one of those for which there is an image file format
65 handler that will accept string data.  If both the \fB\-data\fR
66 and \fB\-file\fR options are specified, the \fB\-file\fR option takes
67 precedence.
68 .TP
69 \fB\-format \fIformat-name\fR
70 .
71 Specifies the name of the file format for the data specified with the
72 \fB\-data\fR or \fB\-file\fR option.
73 .TP
74 \fB\-file \fIname\fR
75 .
76 \fIname\fR gives the name of a file that is to be read to supply data
77 for the photo image.  The file format must be one of those for which
78 there is an image file format handler that can read data.
79 .TP
80 \fB\-gamma \fIvalue\fR
81 .
82 Specifies that the colors allocated for displaying this image in a
83 window should be corrected for a non-linear display with the specified
84 gamma exponent value.  (The intensity produced by most
85 CRT displays is a power function of the input value, to a good
86 approximation; gamma is the exponent and is typically around 2).
87 The value specified must be greater than zero.  The default
88 value is one (no correction).  In general, values greater than one
89 will make the image lighter, and values less than one will make it
90 darker.
91 .TP
92 \fB\-height \fInumber\fR
93 .
94 Specifies the height of the image, in pixels.  This option is useful
95 primarily in situations where the user wishes to build up the contents
96 of the image piece by piece.  A value of zero (the default) allows the
97 image to expand or shrink vertically to fit the data stored in it.
98 .TP
99 \fB\-palette \fIpalette-spec\fR
100 .
101 Specifies the resolution of the color cube to be allocated for
102 displaying this image, and thus the number of colors used from the
103 colormaps of the windows where it is displayed.  The
104 \fIpalette-spec\fR string may be either a single decimal number,
105 specifying the number of shades of gray to use, or three decimal
106 numbers separated by slashes (/), specifying the number of shades of
107 red, green and blue to use, respectively.  If the first form (a single
108 number) is used, the image will be displayed in monochrome (i.e.,
109 grayscale).
110 .TP
111 \fB\-width \fInumber\fR
112 .
113 Specifies the width of the image, in pixels.    This option is useful
114 primarily in situations where the user wishes to build up the contents
115 of the image piece by piece.  A value of zero (the default) allows the
116 image to expand or shrink horizontally to fit the data stored in it.
117 .SH "IMAGE COMMAND"
118 .PP
119 When a photo image is created, Tk also creates a new command
120 whose name is the same as the image.
121 This command may be used to invoke various operations
122 on the image.
123 It has the following general form:
124 .CS
125 \fIimageName option \fR?\fIarg arg ...\fR?
126 .CE
127 \fIOption\fR and the \fIarg\fRs
128 determine the exact behavior of the command.
129 .PP
130 Those options that write data to the image generally expand the size
131 of the image, if necessary, to accommodate the data written to the
132 image, unless the user has specified non-zero values for the
133 \fB\-width\fR and/or \fB\-height\fR configuration options, in which
134 case the width and/or height, respectively, of the image will not be
135 changed.
136 .PP
137 The following commands are possible for photo images:
138 .TP
139 \fIimageName \fBblank\fR
140 .
141 Blank the image; that is, set the entire image to have no data, so it
142 will be displayed as transparent, and the background of whatever
143 window it is displayed in will show through.
144 .TP
145 \fIimageName \fBcget\fR \fIoption\fR
146 .
147 Returns the current value of the configuration option given
148 by \fIoption\fR.
149 \fIOption\fR may have any of the values accepted by the
150 \fBimage create\fR \fBphoto\fR command.
151 .TP
152 \fIimageName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR?
153 .
154 Query or modify the configuration options for the image.
155 If no \fIoption\fR is specified, returns a list describing all of
156 the available options for \fIimageName\fR (see \fBTk_ConfigureInfo\fR for
157 information on the format of this list).  If \fIoption\fR is specified
158 with no \fIvalue\fR, then the command returns a list describing the
159 one named option (this list will be identical to the corresponding
160 sublist of the value returned if no \fIoption\fR is specified).  If
161 one or more \fIoption\-value\fR pairs are specified, then the command
162 modifies the given option(s) to have the given value(s);  in
163 this case the command returns an empty string.
164 \fIOption\fR may have any of the values accepted by the
165 \fBimage create\fR \fBphoto\fR command.
166 .TP
167 \fIimageName \fBcopy\fR \fIsourceImage\fR ?\fIoption value(s) ...\fR?
168 .
169 Copies a region from the image called \fIsourceImage\fR (which must
170 be a photo image) to the image called \fIimageName\fR, possibly with
171 pixel zooming and/or subsampling.  If no options are specified, this
172 command copies the whole of \fIsourceImage\fR into \fIimageName\fR,
173 starting at coordinates (0,0) in \fIimageName\fR.  The following
174 options may be specified:
175 .RS
176 .TP
177 \fB\-from \fIx1 y1 x2 y2\fR
178 .
179 Specifies a rectangular sub-region of the source image to be copied.
180 (\fIx1,y1\fR) and (\fIx2,y2\fR) specify diagonally opposite corners of
181 the rectangle.  If \fIx2\fR and \fIy2\fR are not specified, the
182 default value is the bottom-right corner of the source image.  The
183 pixels copied will include the left and top edges of the specified
184 rectangle but not the bottom or right edges.  If the \fB\-from\fR
185 option is not given, the default is the whole source image.
186 .TP
187 \fB\-to \fIx1 y1 x2 y2\fR
188 .
189 Specifies a rectangular sub-region of the destination image to be
190 affected.  (\fIx1,y1\fR) and (\fIx2,y2\fR) specify diagonally opposite
191 corners of the rectangle.  If \fIx2\fR and \fIy2\fR are not specified,
192 the default value is (\fIx1,y1\fR) plus the size of the source
193 region (after subsampling and zooming, if specified).  If \fIx2\fR and
194 \fIy2\fR are specified, the source region will be replicated if
195 necessary to fill the destination region in a tiled fashion.
196 .TP
197 \fB\-shrink\fR
198 .
199 Specifies that the size of the destination image should be reduced, if
200 necessary, so that the region being copied into is at the bottom-right
201 corner of the image.  This option will not affect the width or height
202 of the image if the user has specified a non-zero value for the
203 \fB\-width\fR or \fB\-height\fR configuration option, respectively.
204 .TP
205 \fB\-zoom \fIx y\fR
206 .
207 Specifies that the source region should be magnified by a factor of
208 \fIx\fR in the X direction and \fIy\fR in the Y direction.  If \fIy\fR
209 is not given, the default value is the same as \fIx\fR.  With this
210 option, each pixel in the source image will be expanded into a block
211 of \fIx\fR x \fIy\fR pixels in the destination image, all the same
212 color.  \fIx\fR and \fIy\fR must be greater than 0.
213 .TP
214 \fB\-subsample \fIx y\fR
215 .
216 Specifies that the source image should be reduced in size by using
217 only every \fIx\fRth pixel in the X direction and \fIy\fRth pixel in
218 the Y direction.  Negative values will cause the image to be flipped
219 about the Y or X axes, respectively.  If \fIy\fR is not given, the
220 default value is the same as \fIx\fR.
221 .TP
222 \fB\-compositingrule \fIrule\fR
223 .
224 Specifies how transparent pixels in the source image are combined with
225 the destination image.  When a compositing rule of \fIoverlay\fR is
226 set, the old contents of the destination image are visible, as if the
227 source image were printed on a piece of transparent film and placed
228 over the top of the destination.  When a compositing rule of \fIset\fR
229 is set, the old contents of the destination image are discarded and
230 the source image is used as-is.  The default compositing rule is
231 \fIoverlay\fR.
232 .RE
233 .TP
234 \fIimageName \fBdata\fR ?\fIoption value(s) ...\fR?
235 .
236 Returns image data in the form of a string. The following options
237 may be specified:
238 .RS
239 .TP
240 \fB\-background\fI color\fR
241 .
242 If the color is specified, the data will not contain any transparency
243 information. In all transparent pixels the color will be replaced by
244 the specified color.
245 .TP
246 \fB\-format\fI format-name\fR
247 .
248 Specifies the name of the image file format handler to be used.
249 Specifically, this subcommand searches
250 for the first handler whose name matches an initial substring of
251 \fIformat-name\fR and which has the capability to write a string
252 containing this image data.
253 If this option is not given, this subcommand uses a format that
254 consists of a list (one element per row) of lists (one element per
255 pixel/column) of colors in
256 .QW \fB#\fIrrggbb\fR
257 format (where \fIrr\fR is a pair of hexadecimal digits for the red
258 channel, \fIgg\fR for green, and \fIbb\fR for blue).
259 .TP
260 \fB\-from \fIx1 y1 x2 y2\fR
261 .
262 Specifies a rectangular region of \fIimageName\fR to be returned.
263 If only \fIx1\fR and \fIy1\fR are specified, the region
264 extends from \fI(x1,y1)\fR to the bottom-right corner of
265 \fIimageName\fR.  If all four coordinates are given, they specify
266 diagonally opposite corners of the rectangular region, including x1,y1
267 and excluding x2,y2.  The default, if this option is not given, is the
268 whole image.
269 .TP
270 \fB\-grayscale\fR
271 .
272 If this options is specified, the data will not contain color
273 information. All pixel data will be transformed into grayscale.
274 .RE
275 .TP
276 \fIimageName \fBget\fR \fIx y\fR
277 .
278 Returns the color of the pixel at coordinates (\fIx\fR,\fIy\fR) in the
279 image as a list of three integers between 0 and 255, representing the
280 red, green and blue components respectively.
281 .TP
282 \fIimageName \fBput\fR \fIdata\fR ?\fIoption value(s) ...\fR?
283 .
284 Sets pixels in \fI imageName\fR to the data specified in \fIdata\fR.
285 This command first searches the list of image file format handlers for
286 a handler that can interpret the data in \fIdata\fR, and then reads
287 the image encoded within into \fIimageName\fR (the destination image).
288 If \fIdata\fR does not match any known format, an attempt to interpret
289 it as a (top-to-bottom) list of scan-lines is made, with each
290 scan-line being a (left-to-right) list of pixel colors (see
291 \fBTk_GetColor\fR for a description of valid colors.)  Every scan-line
292 must be of the same length.  Note that when \fIdata\fR is a single
293 color name, you are instructing Tk to fill a rectangular region with
294 that color.  The following options may be specified:
295 .RS
296 .TP
297 \fB\-format \fIformat-name\fR
298 .
299 Specifies the format of the image data in \fIdata\fR.
300 Specifically, only image file format handlers whose names begin with
301 \fIformat-name\fR will be used while searching for an image data
302 format handler to read the data.
303 .TP
304 \fB\-to \fIx1 y1\fR ?\fIx2 y2\fR?
305 .
306 Specifies the coordinates of the top-left corner (\fIx1\fR,\fIy1\fR)
307 of the region of \fIimageName\fR into which the image data will be
308 copied.  The default position is (0,0).  If \fIx2\fR,\fIy2\fR is given
309 and \fIdata\fR is not large enough to cover the rectangle specified by
310 this option, the image data extracted will be tiled so it covers the
311 entire destination rectangle.  Note that if \fIdata\fR specifies a
312 single color value, then a region extending to the bottom-right corner
313 represented by (\fIx2\fR,\fIy2\fR) will be filled with that color.
314 .RE
315 .TP
316 \fIimageName \fBread\fR \fIfilename\fR ?\fIoption value(s) ...\fR?
317 .
318 Reads image data from the file named \fIfilename\fR into the image.
319 This command first searches the list of
320 image file format handlers for a handler that can interpret the data
321 in \fIfilename\fR, and then reads the image in \fIfilename\fR into
322 \fIimageName\fR (the destination image).  The following options may be
323 specified:
324 .RS
325 .TP
326 \fB\-format \fIformat-name\fR
327 .
328 Specifies the format of the image data in \fIfilename\fR.
329 Specifically, only image file format handlers whose names begin with
330 \fIformat-name\fR will be used while searching for an image data
331 format handler to read the data.
332 .TP
333 \fB\-from \fIx1 y1 x2 y2\fR
334 .
335 Specifies a rectangular sub-region of the image file data to be copied
336 to the destination image.  If only \fIx1\fR and \fIy1\fR are
337 specified, the region extends from (\fIx1,y1\fR) to the bottom-right
338 corner of the image in the image file.  If all four coordinates are
339 specified, they specify diagonally opposite corners or the region.
340 The default, if this option is not specified, is the whole of the
341 image in the image file.
342 .TP
343 \fB\-shrink\fR
344 .
345 If this option, the size of \fIimageName\fR will be reduced, if
346 necessary, so that the region into which the image file data are read
347 is at the bottom-right corner of the \fIimageName\fR.  This option
348 will not affect the width or height of the image if the user has
349 specified a non-zero value for the \fB\-width\fR or \fB\-height\fR
350 configuration option, respectively.
351 .TP
352 \fB\-to \fIx y\fR
353 .
354 Specifies the coordinates of the top-left corner of the region of
355 \fIimageName\fR into which data from \fIfilename\fR are to be read.
356 The default is (0,0).
357 .RE
358 .TP
359 \fIimageName \fBredither\fR
360 .
361 The dithering algorithm used in displaying photo images propagates
362 quantization errors from one pixel to its neighbors.
363 If the image data for \fIimageName\fR is supplied in pieces, the
364 dithered image may not be exactly correct.  Normally the difference is
365 not noticeable, but if it is a problem, this command can be used to
366 recalculate the dithered image in each window where the image is
367 displayed.
368 .TP
369 \fIimageName \fBtransparency \fIsubcommand \fR?\fIarg arg ...\fR?
370 .
371 Allows examination and manipulation of the transparency information in
372 the photo image.  Several subcommands are available:
373 .RS
374 .TP
375 \fIimageName \fBtransparency get \fIx y\fR
376 .
377 Returns a boolean indicating if the pixel at (\fIx\fR,\fIy\fR) is
378 transparent.
379 .TP
380 \fIimageName \fBtransparency set \fIx y boolean\fR
381 .
382 Makes the pixel at (\fIx\fR,\fIy\fR) transparent if \fIboolean\fR is
383 true, and makes that pixel opaque otherwise.
384 .RE
385 .TP
386 \fIimageName \fBwrite \fIfilename\fR ?\fIoption value(s) ...\fR?
387 .
388 Writes image data from \fIimageName\fR to a file named \fIfilename\fR.
389 The following options may be specified:
390 .RS
391 .TP
392 \fB\-background\fI color\fR
393 .
394 If the color is specified, the data will not contain any transparency
395 information. In all transparent pixels the color will be replaced by
396 the specified color.
397 .TP
398 \fB\-format\fI format-name\fR
399 .
400 Specifies the name of the image file format handler to be used to
401 write the data to the file.  Specifically, this subcommand searches
402 for the first handler whose name matches an initial substring of
403 \fIformat-name\fR and which has the capability to write an image
404 file.  If this option is not given, the format is guessed from
405 the file extension. If that cannot be determined, this subcommand
406 uses the first handler that has the capability to write an image file.
407 .TP
408 \fB\-from \fIx1 y1 x2 y2\fR
409 .
410 Specifies a rectangular region of \fIimageName\fR to be written to the
411 image file.  If only \fIx1\fR and \fIy1\fR are specified, the region
412 extends from \fI(x1,y1)\fR to the bottom-right corner of
413 \fIimageName\fR.  If all four coordinates are given, they specify
414 diagonally opposite corners of the rectangular region.  The default,
415 if this option is not given, is the whole image.
416 .TP
417 \fB\-grayscale\fR
418 .
419 If this options is specified, the data will not contain color
420 information. All pixel data will be transformed into grayscale.
421 .RE
422 .SH "IMAGE FORMATS"
423 .PP
424 The photo image code is structured to allow handlers for additional
425 image file formats to be added easily.  The photo image code maintains
426 a list of these handlers.  Handlers are added to the list by
427 registering them with a call to \fBTk_CreatePhotoImageFormat\fR.  The
428 standard Tk distribution comes with handlers for PPM/PGM, PNG and GIF
429 formats, which are automatically registered on initialization.
430 .PP
431 When reading an image file or processing
432 string data specified with the \fB\-data\fR configuration option, the
433 photo image code invokes each handler in turn until one is
434 found that claims to be able to read the data in the file or string.
435 Usually this will find the correct handler, but if it does not, the
436 user may give a format name with the \fB\-format\fR option to specify
437 which handler to use.  In fact the photo image code will try those
438 handlers whose names begin with the string specified for the
439 \fB\-format\fR option (the comparison is case-insensitive).  For
440 example, if the user specifies \fB\-format gif\fR, then a handler
441 named GIF87 or GIF89 may be invoked, but a handler
442 named JPEG may not (assuming that such handlers had been
443 registered).
444 .PP
445 When writing image data to a file, the processing of the
446 \fB\-format\fR option is slightly different: the string value given
447 for the \fB\-format\fR option must begin with the complete name of the
448 requested handler, and may contain additional information following
449 that, which the handler can use, for example, to specify which variant
450 to use of the formats supported by the handler.
451 Note that not all image handlers may support writing transparency data
452 to a file, even where the target image format does.
453 .SS "FORMAT SUBOPTIONS"
454 .PP
455 .VS 8.6
456 Some image formats support sub-options, which are specified at the time that
457 the image is loaded using additional words in the \fB\-format\fR option. At
458 the time of writing, the following are supported:
459 .TP
460 \fBgif \-index\fI indexValue\fR
461 .
462 When parsing a multi-part GIF image, Tk normally only accesses the first
463 image. By giving the \fB\-index\fR sub-option, the \fIindexValue\fR'th value
464 may be used instead. The \fIindexValue\fR must be an integer from 0 up to the
465 number of image parts in the GIF data.
466 .TP
467 \fBpng \-alpha\fI alphaValue\fR
468 .
469 An additional alpha filtering for the overall image, which allows the
470 background on which the image is displayed to show through. This usually also
471 has the effect of desaturating the image. The \fIalphaValue\fR must be between
472 0.0 and 1.0.
473 .VE 8.6
474 .SH "COLOR ALLOCATION"
475 .PP
476 When a photo image is displayed in a window, the photo image code
477 allocates colors to use to display the image and dithers the image, if
478 necessary, to display a reasonable approximation to the image using
479 the colors that are available.  The colors are allocated as a color
480 cube, that is, the number of colors allocated is the product of the
481 number of shades of red, green and blue.
482 .PP
483 Normally, the number of
484 colors allocated is chosen based on the depth of the window.  For
485 example, in an 8-bit PseudoColor window, the photo image code will
486 attempt to allocate seven shades of red, seven shades of green and
487 four shades of blue, for a total of 198 colors.  In a 1-bit StaticGray
488 (monochrome) window, it will allocate two colors, black and white.  In
489 a 24-bit DirectColor or TrueColor window, it will allocate 256 shades
490 each of red, green and blue.  Fortunately, because of the way that
491 pixel values can be combined in DirectColor and TrueColor windows,
492 this only requires 256 colors to be allocated.  If not all of the
493 colors can be allocated, the photo image code reduces the number of
494 shades of each primary color and tries again.
495 .PP
496 The user can exercise some control over the number of colors that a
497 photo image uses with the \fB\-palette\fR configuration option.  If
498 this option is used, it specifies the maximum number of shades of
499 each primary color to try to allocate.  It can also be used to force
500 the image to be displayed in shades of gray, even on a color display,
501 by giving a single number rather than three numbers separated by
502 slashes.
503 .SH CREDITS
504 .PP
505 The photo image type was designed and implemented by Paul Mackerras,
506 based on his earlier photo widget and some suggestions from
507 John Ousterhout.
508 .SH EXAMPLE
509 .PP
510 Load an image from a file and tile it to the size of a window, which
511 is useful for producing a tiled background:
512 .PP
513 .CS
514 # These lines should be called once
515 \fBimage create photo\fR untiled \-file "theFile.ppm"
516 \fBimage create photo\fR tiled
517
518 # These lines should be called whenever .someWidget changes
519 # size; a <Configure> binding is useful here
520 set width  [winfo width .someWidget]
521 set height [winfo height .someWidget]
522 tiled \fBcopy\fR untiled \-to 0 0 $width $height \-shrink
523 .CE
524 .PP
525 .VS 8.6
526 The PNG image loader allows the application of an additional alpha factor
527 during loading, which is useful for generating images suitable for disabled
528 buttons:
529 .PP
530 .CS
531 \fBimage create photo\fR icon \-file "icon.png"
532 \fBimage create photo\fR iconDisabled \-file "icon.png" \e
533         \-format "png \-alpha 0.5"
534 button .b \-image icon \-disabledimage iconDisabled
535 .CE
536 .VE 8.6
537 .SH "SEE ALSO"
538 image(n)
539 .SH KEYWORDS
540 photo, image, color
541 '\" Local Variables:
542 '\" mode: nroff
543 '\" End: