home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _2a9c45ce3a6448c74724c9029e0733b0 < prev    next >
Encoding:
Text File  |  2004-06-01  |  18.5 KB  |  476 lines

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