1mNAME0m
       photo - Full-color images

1mSYNOPSIS0m
       1mimage create photo 22m?4mname24m? ?4moptions24m?


1mDESCRIPTION0m
       A  photo is an image whose pixels can display any color or be transpar-
       ent.  A photo image is stored internally in full  color  (32  bits  per
       pixel),  and is displayed using dithering if necessary.  Image data for
       a photo image can be obtained from a file or a string,  or  it  can  be
       supplied  from C code through a procedural interface.  At present, only
       GIF and PPM/PGM formats are supported, but an interface exists to allow
       additional  image  file  formats  to be added easily.  A photo image is
       transparent in regions where no image data has been supplied.


1mCREATING PHOTOS0m
       Like all images, photos are created using  the  1mimage  create  22mcommand.
       Photos support the following 4moptions24m:

       1m-data 4m22mstring0m
              Specifies the contents of the image as a string.  The string can
              contain base64 encoded data or binary data.  The format  of  the
              string  must  be  one  of those for which there is an image file
              format handler that will accept string data.  If both the  1m-data0m
              and  1m-file  22moptions are specified, the 1m-file 22moption takes prece-
              dence.

       1m-format 4m22mformat-name0m
              Specifies the name of the file format  for  the  data  specified
              with the 1m-data 22mor 1m-file 22moption.

       1m-file 4m22mname0m
              4mname24m  gives the name of a file that is to be read to supply data
              for the photo image.  The file format must be one of  those  for
              which  there is an image file format handler that can read data.

       1m-gamma 4m22mvalue0m
              Specifies that the colors allocated for displaying this image in
              a  window  should be corrected for a non-linear display with the
              specified gamma exponent value.  (The intensity produced by most
              CRT  displays  is a power function of the input value, to a good
              approximation; gamma is the exponent and is typically around 2).
              The  value  specified  must  be  greater than zero.  The default
              value is one (no correction).  In general, values  greater  than
              one  will  make the image lighter, and values less than one will
              make it darker.

       1m-height 4m22mnumber0m
              Specifies the height of the image, in pixels.   This  option  is
              useful primarily in situations where the user wishes to build up
              the contents of the image piece by piece.  A value of zero  (the
              default)  allows the image to expand or shrink vertically to fit
              the data stored in it.

       1m-palette 4m22mpalette-spec0m
              Specifies the resolution of the color cube to be  allocated  for
              displaying  this  image, and thus the number of colors used from
              the colormaps  of  the  windows  where  it  is  displayed.   The
              4mpalette-spec24m  string  may  be  either  a  single decimal number,
              specifying the number of shades of gray to use, or three decimal
              numbers  separated  by  slashes  (/),  specifying  the number of
              shades of red, green and blue  to  use,  respectively.   If  the
              first  form  (a  single  number) is used, the image will be dis-
              played in monochrome (i.e., grayscale).

       1m-width 4m22mnumber0m
              Specifies the width of the image, in pixels.    This  option  is
              useful primarily in situations where the user wishes to build up
              the contents of the image piece by piece.  A value of zero  (the
              default)  allows  the  image to expand or shrink horizontally to
              fit the data stored in it.


1mIMAGE COMMAND0m
       When a photo image is created, Tk also creates a new command whose name
       is  the  same as the image.  This command may be used to invoke various
       operations on the image.  It has the following general form:
              4mimageName24m 4moption24m ?4marg24m 4marg24m 4m...24m?
       4mOption24m and the 4marg24ms determine the exact behavior of the command.

       Those options that write data to the image generally expand the size of
       the  image, if necessary, to accommodate the data written to the image,
       unless the user has specified non-zero values  for  the  1m-width  22mand/or
       1m-height  22mconfiguration  options, in which case the width and/or height,
       respectively, of the image will not be changed.

       The following commands are possible for photo images:

       4mimageName24m 1mblank0m
              Blank the image; that is, set the entire image to have no  data,
              so  it  will  be displayed as transparent, and the background of
              whatever window it is displayed in will show through.

       4mimageName24m 1mcget 4m22moption0m
              Returns the current value of the configuration option  given  by
              4moption24m.  4mOption24m may have any of the values accepted by the 1mimage0m
              1mcreate photo 22mcommand.

       4mimageName24m 1mconfigure 22m?4moption24m? ?4mvalue24m 4moption24m 4mvalue24m 4m...24m?
              Query or modify the configuration options for the image.  If  no
              4moption24m is specified, returns a list describing all of the avail-
              able options for 4mimageName24m (see 1mTk_ConfigureInfo 22mfor information
              on  the  format  of  this list).  If 4moption24m is specified with no
              4mvalue24m, then the command returns a list describing the one  named
              option (this list will be identical to the corresponding sublist
              of the value returned if no 4moption24m is  specified).   If  one  or
              more 4moption-value24m pairs are specified, then the command modifies
              the given option(s) to have the given value(s);   in  this  case
              the command returns an empty string.  4mOption24m may have any of the
              values accepted by the 1mimage create photo 22mcommand.

       4mimageName24m 1mcopy 4m22msourceImage24m ?4moption24m 4mvalue(s)24m 4m...24m?
              Copies a region from the image called 4msourceImage24m (which must be
              a  photo  image)  to  the  image called 4mimageName24m, possibly with
              pixel zooming and/or subsampling.  If no options are  specified,
              this  command  copies  the  whole of 4msourceImage24m into 4mimageName24m,
              starting at  coordinates  (0,0)  in  4mimageName24m.   The  following
              options may be specified:

              1m-from 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies a rectangular sub-region of the source image to
                     be copied.  (4mx1,y124m) and (4mx2,y224m) specify diagonally  oppo-
                     site  corners  of  the  rectangle.   If 4mx224m and 4my224m are not
                     specified, the default value is the  bottom-right  corner
                     of  the source image.  The pixels copied will include the
                     left and top edges of the specified rectangle but not the
                     bottom or right edges.  If the 1m-from 22moption is not given,
                     the default is the whole source image.

              1m-to 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies a rectangular  sub-region  of  the  destination
                     image to be affected.  (4mx1,y124m) and (4mx2,y224m) specify diago-
                     nally opposite corners of the rectangle.  If  4mx224m  and  4my20m
                     are  not specified, the default value is (4mx1,y124m) plus the
                     size of the source region (after subsampling and zooming,
                     if  specified).   If  4mx224m and 4my224m are specified, the source
                     region will be replicated if necessary to fill the desti-
                     nation region in a tiled fashion.

              1m-shrink0m
                     Specifies  that  the size of the destination image should
                     be reduced, if necessary, so that the region being copied
                     into  is  at  the bottom-right corner of the image.  This
                     option will not affect the width or height of  the  image
                     if the user has specified a non-zero value for the 1m-width0m
                     or 1m-height 22mconfiguration option, respectively.

              1m-zoom 4m22mx24m 4my0m
                     Specifies that the source region should be magnified by a
                     factor  of 4mx24m in the X direction and 4my24m in the Y direction.
                     If 4my24m is not given, the default value is the  same  as  4mx24m.
                     With  this option, each pixel in the source image will be
                     expanded into a block of 4mx24m x 4my24m pixels in the  destination
                     image,  all the same color.  4mx24m and 4my24m must be greater than
                     0.

              1m-subsample 4m22mx24m 4my0m
                     Specifies that the source image should be reduced in size
                     by  using only every 4mx24mth pixel in the X direction and 4my24mth
                     pixel in the Y direction.  Negative values will cause the
                     image  to be flipped about the Y or X axes, respectively.
                     If 4my24m is not given, the default value is the same as 4mx24m.

       4mimageName24m 1mdata ?4m22moption24m 4mvalue(s)24m 4m...24m?
              Returns image data in  the  form  of  a  string.  The  following
              options may be specified:

              1m-background 4m22mcolor0m
                     If  the color is specified, the data will not contain any
                     transparency information. In all transparent  pixels  the
                     color will be replaced by the specified color.

              1m-format 4m22mformat-name0m
                     Specifies the name of the image file format handler to be
                     used.  Specifically, this  subcommand  searches  for  the
                     first  handler  whose name matches a initial substring of
                     4mformat-name24m and which has the  capability  to  read  this
                     image data.  If this option is not given, this subcommand
                     uses the first handler that has the  capability  to  read
                     the image data.

              1m-from 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies   a  rectangular  region  of  4mimageName24m  to  be
                     returned.  If only 4mx124m and 4my124m are  specified,  the  region
                     extends from 4m(x1,y1)24m to the bottom-right corner of 4mimage-0m
                     4mName24m.  If all four coordinates are  given,  they  specify
                     diagonally  opposite  corners  of the rectangular region,
                     including x1,y1 and excluding  x2,y2.   The  default,  if
                     this option is not given, is the whole image.

              1m-grayscale0m
                     If  this  options is specified, the data will not contain
                     color information. All pixel  data  will  be  transformed
                     into grayscale.

       4mimageName24m 1mget 4m22mx24m 4my0m
              Returns the color of the pixel at coordinates (4mx24m,4my24m) in the image
              as a list of three integers between 0 and 255, representing  the
              red, green and blue components respectively.

       4mimageName24m 1mput 4m22mdata24m ?4moption24m 4mvalue(s)24m 4m...24m?
              Sets  pixels  in   4mimageName24m to the data specified in 4mdata24m. This
              command first searches the list of image  file  format  handlers
              for  a  handler  that  can  interpret the data in 4mdata24m, and then
              reads the image in  4mfilename24m  into  4mimageName24m  (the  destination
              image). The following options may be specified:

              1m-format 4m22mformat-name0m
                     Specifies the format of the image data in 4mdata24m.  Specifi-
                     cally, only image file format handlers whose names  begin
                     with  4mformat-name24m  will  be  used  while searching for an
                     image data format handler to read the data.

              1m-from 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies a rectangular sub-region of the image file data
                     to  be  returned.  If  only  4mx124m and 4my124m are specified, the
                     region extends from (4mx1,y124m) to the bottom-right corner of
                     the image in the image file.  If all four coordinates are
                     specified, they specify diagonally  opposite  corners  or
                     the region. The default, if this option is not specified,
                     is the whole of the image.

              1m-shrink0m
                     If this option, the size of 4mimageName24m will be reduced, if
                     necessary,  so  that the region into which the image file
                     data are read is at the bottom-right corner of the 4mimage-0m
                     4mName24m.  This option will not affect the width or height of
                     the image if the user has specified a non-zero value  for
                     the 1m-width 22mor 1m-height 22mconfiguration option, respectively.

              1m-to 4m22mx24m 4my0m
                     Specifies the coordinates of the top-left corner  of  the
                     region  of 4mimageName24m into which data from 4mfilename24m are to
                     be read.  The default is (0,0).

       4mimageName24m 1mread 4m22mfilename24m ?4moption24m 4mvalue(s)24m 4m...24m?
              Reads image data from the file named 4mfilename24m  into  the  image.
              This  command  first searches the list of image file format han-
              dlers for a handler that can interpret the data in 4mfilename24m, and
              then reads the image in 4mfilename24m into 4mimageName24m (the destination
              image).  The following options may be specified:

              1m-format 4m22mformat-name0m
                     Specifies the format  of  the  image  data  in  4mfilename24m.
                     Specifically, only image file format handlers whose names
                     begin with 4mformat-name24m will be used while  searching  for
                     an image data format handler to read the data.

              1m-from 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies a rectangular sub-region of the image file data
                     to be copied to the destination image.  If only 4mx124m and 4my10m
                     are  specified,  the  region  extends from (4mx1,y124m) to the
                     bottom-right corner of the image in the image  file.   If
                     all  four  coordinates are specified, they specify diago-
                     nally opposite corners or the region.   The  default,  if
                     this  option  is not specified, is the whole of the image
                     in the image file.

              1m-shrink0m
                     If this option, the size of 4mimageName24m will be reduced, if
                     necessary,  so  that the region into which the image file
                     data are read is at the bottom-right corner of the 4mimage-0m
                     4mName24m.  This option will not affect the width or height of
                     the image if the user has specified a non-zero value  for
                     the 1m-width 22mor 1m-height 22mconfiguration option, respectively.

              1m-to 4m22mx24m 4my0m
                     Specifies the coordinates of the top-left corner  of  the
                     region  of 4mimageName24m into which data from 4mfilename24m are to
                     be read.  The default is (0,0).

       4mimageName24m 1mredither0m
              The dithering algorithm used in displaying photo  images  propa-
              gates  quantization  errors from one pixel to its neighbors.  If
              the image data for 4mimageName24m is supplied in pieces, the dithered
              image  may  not  be exactly correct.  Normally the difference is
              not noticeable, but if it is a problem, this command can be used
              to recalculate the dithered image in each window where the image
              is displayed.

       4mimageName24m 1mwrite 4m22mfilename24m ?4moption24m 4mvalue(s)24m 4m...24m?
              Writes image data from 4mimageName24m to a file named 4mfilename24m.   The
              following options may be specified:

              1m-background 4m22mcolor0m
                     If  the color is specified, the data will not contain any
                     transparency information. In all transparent  pixels  the
                     color will be replaced by the specified color.

              1m-format 4m22mformat-name0m
                     Specifies the name of the image file format handler to be
                     used to write the data to the file.   Specifically,  this
                     subcommand  searches  for  the  first  handler whose name
                     matches a initial substring of 4mformat-name24m and which  has
                     the capability to write an image file.  If this option is
                     not given, this subcommand uses the  first  handler  that
                     has the capability to write an image file.

              1m-from 4m22mx124m 4my124m 4mx224m 4my20m
                     Specifies a rectangular region of 4mimageName24m to be written
                     to the image file.  If only 4mx124m and 4my124m are specified,  the
                     region extends from 4m(x1,y1)24m to the bottom-right corner of
                     4mimageName24m.  If all four coordinates are given, they spec-
                     ify   diagonally  opposite  corners  of  the  rectangular
                     region.  The default, if this option is not given, is the
                     whole image.

              1m-grayscale0m
                     If  this  options is specified, the data will not contain
                     color information. All pixel  data  will  be  transformed
                     into grayscale.

1mIMAGE FORMATS0m
       The  photo  image  code  is structured to allow handlers for additional
       image file formats to be added easily.  The photo image code  maintains
       a  list of these handlers.  Handlers are added to the list by register-
       ing them with a call to  1mTk_CreatePhotoImageFormat22m.   The  standard  Tk
       distribution comes with handlers for PPM/PGM and GIF formats, which are
       automatically registered on initialization.

       When reading an image file or processing string data specified with the
       1m-data  22mconfiguration  option, the photo image code invokes each handler
       in turn until one is found that claims to be able to read the  data  in
       the file or string.  Usually this will find the correct handler, but if
       it doesn't, the user may give a format name with the 1m-format 22moption  to
       specify  which  handler  to use.  In fact the photo image code will try
       those handlers whose names begin with  the  string  specified  for  the
       1m-format  22moption  (the comparison is case-insensitive).  For example, if
       the user specifies 1m-format gif22m, then a handler named GIF87 or GIF89 may
       be  invoked,  but a handler named JPEG may not (assuming that such han-
       dlers had been registered).

       When writing image data to a file, the processing of the 1m-format 22moption
       is  slightly  different:  the string value given for the 1m-format 22moption
       must begin with the complete name of the  requested  handler,  and  may
       contain  additional  information  following that, which the handler can
       use, for example, to specify which variant to use of the  formats  sup-
       ported by the handler.


1mCOLOR ALLOCATION0m
       When a photo image is displayed in a window, the photo image code allo-
       cates colors to use to display the image and dithers the image, if nec-
       essary,  to  display  a reasonable approximation to the image using the
       colors that are available.  The colors are allocated as a  color  cube,
       that is, the number of colors allocated is the product of the number of
       shades of red, green and blue.

       Normally, the number of colors allocated is chosen based on  the  depth
       of  the window.  For example, in an 8-bit PseudoColor window, the photo
       image code will attempt to allocate seven shades of red,  seven  shades
       of  green  and  four  shades  of blue, for a total of 198 colors.  In a
       1-bit StaticGray (monochrome) window,  it  will  allocate  two  colors,
       black  and white.  In a 24-bit DirectColor or TrueColor window, it will
       allocate 256 shades each of red, green and blue.  Fortunately,  because
       of  the  way that pixel values can be combined in DirectColor and True-
       Color windows, this only requires 256 colors to be allocated.   If  not
       all  of  the  colors can be allocated, the photo image code reduces the
       number of shades of each primary color and tries again.

       The user can exercise some control over the number  of  colors  that  a
       photo  image  uses  with  the  1m-palette  22mconfiguration option.  If this
       option is used, it specifies the maximum number of shades of each  pri-
       mary  color to try to allocate.  It can also be used to force the image
       to be displayed in shades of gray, even on a color display, by giving a
       single number rather than three numbers separated by slashes.


1mCREDITS0m
       The  photo  image  type was designed and implemented by Paul Mackerras,
       based on his earlier  photo  widget  and  some  suggestions  from  John
       Ousterhout.


1mKEYWORDS0m
