Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / sun4-solaris / Tk / Photo.pod
CommitLineData
86530b38
AT
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# Author: Paul Mackerras (paulus@cs.anu.edu.au),
6# Department of Computer Science,
7# Australian National University.
8# RCS: @(#) $Id: photo.n,v 1.2 1998/09/14 18:22:59 stanton Exp $
9#
10
11=head1 NAME
12
13Tk::Photo - Full-color images
14
15=for category Tk Image Classes
16
17=head1 SYNOPSIS
18
19S< >I<$widget>-E<gt>B<Photo>(?I<name>??, I<options>?)
20
21=head1 DESCRIPTION
22
23A photo is an L<image|Tk::Image> whose pixels can display any color or be
24transparent. A photo image is stored internally in full color (32
25bits per pixel), and is displayed using dithering if necessary. Image
26data for a photo image can be obtained from a file or a string, or it
27can be supplied from
28C code through a procedural interface. At present, only GIF and PPM/PGM
29formats are supported, but an interface exists to allow additional
30image file formats to be added easily. A photo image is transparent
31in regions where no image data has been supplied.
32
33=head1 CREATING PHOTOS
34
35Photos are created using the B<Photo> method.
36B<Photo> supports the following I<options>:
37
38=over 4
39
40=item B<-data> =E<gt> I<string>
41
42Specifies the contents of the image as a string. The format of the
43string must be one of those for which there is an image file format
44handler that will accept string data. If both the B<-data>
45and B<-file> options are specified, the B<-file> option takes
46precedence.
47
48=item B<-format> =E<gt> I<format-name>
49
50Specifies the name of the file format for the data specified with the
51B<-data> or B<-file> option.
52
53=item B<-file> =E<gt> I<name>
54
55I<name> gives the name of a file that is to be read to supply data
56for the photo image. The file format must be one of those for which
57there is an image file format handler that can read data.
58
59=item B<-gamma> =E<gt> I<value>
60
61Specifies that the colors allocated for displaying this image in a
62window should be corrected for a non-linear display with the specified
63gamma exponent value. (The intensity produced by most
64CRT displays is a power function of the input value, to a good
65approximation; gamma is the exponent and is typically around 2).
66The value specified must be greater than zero. The default
67value is one (no correction). In general, values greater than one
68will make the image lighter, and values less than one will make it
69darker.
70
71=item B<-height> =E<gt> I<number>
72
73Specifies the height of the image, in pixels. This option is useful
74primarily in situations where the user wishes to build up the contents
75of the image piece by piece. A value of zero (the default) allows the
76image to expand or shrink vertically to fit the data stored in it.
77
78=item B<-palette> =E<gt> I<palette-spec>
79
80Specifies the resolution of the color cube to be allocated for
81displaying this image, and thus the number of colors used from the
82colormaps of the windows where it is displayed. The
83I<palette-spec> string may be either a single decimal number,
84specifying the number of shades of gray to use, or three decimal
85numbers separated by slashes (/), specifying the number of shades of
86red, green and blue to use, respectively. If the first form (a single
87number) is used, the image will be displayed in monochrome (i.e.,
88grayscale).
89
90=item B<-width> =E<gt> I<number>
91
92Specifies the width of the image, in pixels. This option is useful
93primarily in situations where the user wishes to build up the contents
94of the image piece by piece. A value of zero (the default) allows the
95image to expand or shrink horizontally to fit the data stored in it.
96
97=back
98
99=head1 IMAGE METHODS
100
101When a photo image is created, Tk also creates a new object.
102This object supports the B<configure> and B<cget> methods
103described in L<Tk::options> which can be used to enquire and
104modify the options described above.
105
106Those options that write data to the image generally expand the size
107of the image, if necessary, to accommodate the data written to the
108image, unless the user has specified non-zero values for the
109B<-width> and/or B<-height> configuration options, in which
110case the width and/or height, respectively, of the image will not be
111changed.
112
113The following addition methods are available for photo images:
114
115=over 4
116
117=item I<$image>-E<gt>B<blank>
118
119Blank the image; that is, set the entire image to have no data, so it
120will be displayed as transparent, and the background of whatever
121window it is displayed in will show through.
122
123=item I<$image>-E<gt>B<copy>(I<sourceImage> ?,I<option value(s) ...>?)
124
125Copies a region from the image called I<sourceImage> (which must
126be a photo image) to the image called I<$image>, possibly with
127pixel zooming and/or subsampling. If no options are specified, this
128method copies the whole of I<sourceImage> into I<$image>,
129starting at coordinates (0,0) in I<$image>. The following
130options may be specified:
131
132=over 8
133
134=item B<-from> =E<gt> I<x1 y1 ?x2 y2?>
135
136Specifies a rectangular sub-region of the source image to be copied.
137(I<x1,y1>) and (I<x2,y2>) specify diagonally opposite corners of
138the rectangle. If I<x2> and I<y2> are not specified, the
139default value is the bottom-right corner of the source image. The
140pixels copied will include the left and top edges of the specified
141rectangle but not the bottom or right edges. If the B<-from>
142option is not given, the default is the whole source image.
143
144=item B<-to> =E<gt> I<x1 y1 ?x2 y2?>
145
146Specifies a rectangular sub-region of the destination image to be
147affected. (I<x1,y1>) and (I<x2,y2>) specify diagonally opposite
148corners of the rectangle. If I<x2> and I<y2> are not specified,
149the default value is (I<x1,y1>) plus the size of the source
150region (after subsampling and zooming, if specified). If I<x2> and
151I<y2> are specified, the source region will be replicated if
152necessary to fill the destination region in a tiled fashion.
153
154=item B<-shrink>
155
156Specifies that the size of the destination image should be reduced, if
157necessary, so that the region being copied into is at the bottom-right
158corner of the image. This option will not affect the width or height
159of the image if the user has specified a non-zero value for the
160B<-width> or B<-height> configuration option, respectively.
161
162=item B<-zoom> =E<gt> I<x y>
163
164Specifies that the source region should be magnified by a factor of
165I<x> in the X direction and I<y> in the Y direction. If I<y>
166is not given, the default value is the same as I<x>. With this
167option, each pixel in the source image will be expanded into a block
168of I<x> x I<y> pixels in the destination image, all the same
169color. I<x> and I<y> must be greater than 0.
170
171=item B<-subsample> =E<gt> I<x y>
172
173Specifies that the source image should be reduced in size by using
174only every I<x>th pixel in the X direction and I<y>th pixel in
175the Y direction. Negative values will cause the image to be flipped
176about the Y or X axes, respectively. If I<y> is not given, the
177default value is the same as I<x>.
178
179=back
180
181=item I<$image>-E<gt>B<data>(?I<option value(s), ...>?)
182
183returns image data in the form of a string.
184The following options may be specified:
185
186=over 8
187
188=item B<-background> =E<gt> I< color>
189
190If the color is specified, the data will not contain any transparency
191information. In all transparent pixels the color will be replaced by
192the specified color.
193
194=item B<-format> =E<gt> I<format-name>
195
196Specifies the name of the image file format handler to be used to
197convert the data. Specifically, this method searches
198for the first handler whose name matches a initial substring of
199I<format-name> and which has the capability to write an string.
200If this option is not given, the data is returned in the default
201format as accepted by I<$image>-E<gt>B<put>.
202
203=item B<-from> =E<gt> I<x1 y1 ?x2 y2?>
204
205Specifies a rectangular region of I<$image> to be written to the
206string. If only I<x1> and I<y1> are specified, the region
207extends from I<(x1,y1)> to the bottom-right corner of
208I<$image>. If all four coordinates are given, they specify
209diagonally opposite corners of the rectangular region. The default,
210if this option is not given, is the whole image.
211
212=back
213
214=item B<-grayscale>
215
216If this options is specified, the data will not contain color
217information. All pixel data will be transformed into grayscale.
218
219=item I<$image>-E<gt>B<get>(I<x,y>)
220
221Returns the color of the pixel at coordinates (I<x>,I<y>) in the
222image as a list of three integers between 0 and 255, representing the
223red, green and blue components respectively.
224
225=item I<$image>-E<gt>B<put>(I<data> ?,B<-format>=E<gt>I<format-name>? ?,B<-to>=E<gt>I< x1 y1 ?x2 y2?>?)
226
227Sets pixels in I< imageName> to the data specified in
228I<data>. This command first searches the list of image file
229format handlers for a handler that can interpret the data
230in I<data>, and then reads the image in I<filename> into
231I<imageName> (the destination image). The following options
232may be specified:
233
234=over 4
235
236=item B<-format >I<format-name>
237
238Specifies the format of the image data in I<data>.
239Specifically, only image file format handlers whose names begin with
240I<format-name> will be used while searching for an image data
241format handler to read the data. Otherwise I<data> is used to form a two-dimensional array of pixels
242that are then copied into the I<$image>. I<data> is structured
243then as a list of horizontal rows, from top to bottom, each of which is
244a list of colors, listed from left to right. Each color may be specified
245by name (e.g., blue) or in hexadecimal form (e.g., #2376af).
246
247=item B<-from >I<x1 y1 x2 y2>
248
249Specifies a rectangular sub-region of the image file data to be
250returned. If only I<x1> and I<y1> are specified, the region
251extends from (I<x1,y1>) to the bottom-right corner of the image
252in the image file. If all four coordinates are specified, they
253specify diagonally opposite corners or the region. The default,
254if this option is not specified, is the whole of the image.
255
256=item B<-shrink>
257
258If this option, the size of I<imageName> will be reduced, if
259necessary, so that the region into which the image file data are read
260is at the bottom-right corner of the I<imageName>. This option
261will not affect the width or height of the image if the user has
262specified a non-zero value for the B<-width> or B<-height>
263configuration option, respectively.
264
265=item B<-to >I<x y>
266
267Specifies the coordinates of the top-left corner of the region of
268I<imageName> into which data from I<filename> are to be read.
269The default is (0,0).
270
271=back
272
273=item I<$image>-E<gt>B<read>(I<filename> ?,I<option value(s), ...>?)
274
275Reads image data from the file named I<filename> into the image.
276This method first searches the list of
277image file format handlers for a handler that can interpret the data
278in I<filename>, and then reads the image in I<filename> into
279I<$image> (the destination image). The following options may be
280specified:
281
282=over 8
283
284=item B<-format> =E<gt> I<format-name>
285
286Specifies the format of the image data in I<filename>.
287Specifically, only image file format handlers whose names begin with
288I<format-name> will be used while searching for an image data
289format handler to read the data.
290
291=item B<-from> =E<gt> I<x1 y1 ?x2 y2?>
292
293Specifies a rectangular sub-region of the image file data to be copied
294to the destination image. If only I<x1> and I<y1> are
295specified, the region extends from (I<x1,y1>) to the bottom-right
296corner of the image in the image file. If all four coordinates are
297specified, they specify diagonally opposite corners or the region.
298The default, if this option is not specified, is the whole of the
299image in the image file.
300
301=item B<-shrink>
302
303If this option, the size of I<$image> will be reduced, if
304necessary, so that the region into which the image file data are read
305is at the bottom-right corner of the I<$image>. This option
306will not affect the width or height of the image if the user has
307specified a non-zero value for the B<-width> or B<-height>
308configuration option, respectively.
309
310=item B<-to> =E<gt> I<x y>
311
312Specifies the coordinates of the top-left corner of the region of
313I<$image> into which data from I<filename> are to be read.
314The default is (0,0).
315
316=back
317
318=item I<$image>-E<gt>B<redither>
319
320The dithering algorithm used in displaying photo images propagates
321quantization errors from one pixel to its neighbors.
322If the image data for I<$image> is supplied in pieces, the
323dithered image may not be exactly correct. Normally the difference is
324not noticeable, but if it is a problem, this method can be used to
325recalculate the dithered image in each window where the image is
326displayed.
327
328=item I<$image>-E<gt>B<write>(I<filename> ?,I<option value(s), ...>?)
329
330Writes image data from I<$image> to a file named I<filename>.
331The following options may be specified:
332
333=over 8
334
335=item B<-background>I< color>
336
337If the color is specified, the data will not contain any transparency
338information. In all transparent pixels the color will be replaced by
339the specified color.
340
341=item B<-format> =E<gt> I<format-name>
342
343Specifies the name of the image file format handler to be used to
344write the data to the file. Specifically, this subcommand searches
345for the first handler whose name matches a initial substring of
346I<format-name> and which has the capability to write an image
347file. If this option is not given, this subcommand uses the first
348handler that has the capability to write an image file.
349
350=item B<-from> =E<gt> I<x1 y1 ?x2 y2?>
351
352Specifies a rectangular region of I<$image> to be written to the
353image file. If only I<x1> and I<y1> are specified, the region
354extends from I<(x1,y1)> to the bottom-right corner of
355I<$image>. If all four coordinates are given, they specify
356diagonally opposite corners of the rectangular region. The default,
357if this option is not given, is the whole image.
358
359
360=item B<-grayscale>
361
362If this options is specified, the data will not contain color
363information. All pixel data will be transformed into grayscale.
364
365=back
366
367=back
368
369=head1 IMAGE FORMATS
370
371The photo image code is structured to allow handlers for additional
372image file formats to be added easily. The photo image code maintains
373a list of these handlers. Handlers are added to the list by
374registering them with a call to B<Tk_CreatePhotoImageFormat>. The
375standard Tk distribution comes with handlers for PPM/PGM and GIF formats,
376which are automatically registered on initialization.
377
378When reading an image file or processing
379string data specified with the B<-data> configuration option, the
380photo image code invokes each handler in turn until one is
381found that claims to be able to read the data in the file or string.
382Usually this will find the correct handler, but if it doesn't, the
383user may give a format name with the B<-format> option to specify
384which handler to use. In fact the photo image code will try those
385handlers whose names begin with the string specified for the
386B<-format> option (the comparison is case-insensitive). For
387example, if the user specifies B<-format gif>, then a handler
388named GIF87 or GIF89 may be invoked, but a handler
389named JPEG may not (assuming that such handlers had been
390registered).
391
392When writing image data to a file, the processing of the
393B<-format> option is slightly different: the string value given
394for the B<-format> option must begin with the complete name of the
395requested handler, and may contain additional information following
396that, which the handler can use, for example, to specify which variant
397to use of the formats supported by the handler.
398
399=head1 COLOR ALLOCATION
400
401When a photo image is displayed in a window, the photo image code
402allocates colors to use to display the image and dithers the image, if
403necessary, to display a reasonable approximation to the image using
404the colors that are available. The colors are allocated as a color
405cube, that is, the number of colors allocated is the product of the
406number of shades of red, green and blue.
407
408Normally, the number of
409colors allocated is chosen based on the depth of the window. For
410example, in an 8-bit PseudoColor window, the photo image code will
411attempt to allocate seven shades of red, seven shades of green and
412four shades of blue, for a total of 198 colors. In a 1-bit StaticGray
413(monochrome) window, it will allocate two colors, black and white. In
414a 24-bit DirectColor or TrueColor window, it will allocate 256 shades
415each of red, green and blue. Fortunately, because of the way that
416pixel values can be combined in DirectColor and TrueColor windows,
417this only requires 256 colors to be allocated. If not all of the
418colors can be allocated, the photo image code reduces the number of
419shades of each primary color and tries again.
420
421The user can exercise some control over the number of colors that a
422photo image uses with the B<-palette> configuration option. If
423this option is used, it specifies the maximum number of shades of
424each primary color to try to allocate. It can also be used to force
425the image to be displayed in shades of gray, even on a color display,
426by giving a single number rather than three numbers separated by
427slashes.
428
429=head1 CREDITS
430
431The photo image type was designed and implemented by Paul Mackerras,
432based on his earlier photo widget and some suggestions from
433John Ousterhout.
434
435=head1 SEE ALSO
436
437L<Tk::Bitmap|Tk::Bitmap>
438L<Tk::Image|Tk::Image>
439L<Tk::Pixmap|Tk::Pixmap>
440
441=head1 KEYWORDS
442
443photo, image, color
444
445=cut
446
447