]> git.imager.perl.org - imager.git/blob - lib/Imager/ImageTypes.pod
allow box() to accept floating colors for filling areas
[imager.git] / lib / Imager / ImageTypes.pod
1 =head1 NAME
2
3 Imager::ImageTypes - image models for Imager
4
5 =head1 SYNOPSIS
6
7   use Imager;
8
9   $img = Imager->new(); #  Empty image (size is 0 by 0)
10   $img->open(file=>'lena.png',type=>'png'); # Read image from file
11
12   $img = Imager->new(xsize=>400, ysize=>300); # RGB data
13
14   $img = Imager->new(xsize=>400, ysize=>300,  # Grayscale
15                      channels=>1);            #
16
17   $img = Imager->new(xsize=>400, ysize=>300,  # RGB with alpha
18                      channels=>4);            #
19                                               
20   $img = Imager->new(xsize=>200, ysize=>200,  
21                      type=>'paletted');       # paletted image
22                                               
23   $img = Imager->new(xsize=>200, ysize=>200,  
24                      bits=>16);               # 16 bits/channel rgb
25                                               
26   $img = Imager->new(xsize=>200, ysize=>200,  
27                      bits=>'double');         # 'double' floating point
28                                               #  per channel
29
30   $img->img_set(xsize=>500, ysize=>500,       # reset the image object
31                 channels=>4);
32
33
34   # Example getting information about an Imager object
35
36   print "Image information:\n";
37   print "Width:        ", $img->getwidth(),    "\n";
38   print "Height:       ", $img->getheight(),   "\n";
39   print "Channels:     ", $img->getchannels(), "\n";
40   print "Bits/Channel: ", $img->bits(),        "\n";
41   print "Virtual:      ", $img->virtual() ? "Yes" : "No", "\n";
42   my $colorcount = $img->getcolorcount(maxcolors=>512);
43         print "Actual number of colors in image: ";
44   print defined($colorcount) ? $colorcount : ">512", "\n";
45   print "Type:         ", $img->type(),        "\n";
46
47   if ($img->type() eq 'direct') {
48     print "Modifiable Channels: ";
49     print join " ", map {
50       ($img->getmask() & 1<<$_) ? $_ : ()
51     } 0..$img->getchannels();
52     print "\n";
53   
54   } else {
55     # palette info
56     my $count = $img->colorcount;  
57     @colors = $img->getcolors();
58     print "Palette size: $count\n";
59     my $mx = @colors > 4 ? 4 : 0+@colors;
60     print "First $mx entries:\n";
61     for (@colors[0..$mx-1]) {
62       my @res = $_->rgba();
63       print "(", join(", ", @res[0..$img->getchannels()-1]), ")\n";
64     }
65   }
66   
67   my @tags = $img->tags();
68   if (@tags) {
69     print "Tags:\n";
70     for(@tags) {
71       print shift @$_, ": ", join " ", @$_, "\n";
72     }
73   } else {
74     print "No tags in image\n";
75   }
76   
77 =head1 DESCRIPTION
78
79 Imager supports two basic models of image:
80
81 =over
82
83 =item *
84
85 direct color - all samples are stored for every pixel.  eg. for an
86 8-bit/sample RGB image, 24 bits are stored for each pixel.
87
88 =item *
89
90 paletted - an index into a table of colors is stored for each pixel.
91
92 =back
93
94 Direct color or paletted images can have 1 to 4 samples per color
95 stored.  Imager treats these as follows:
96
97 =over
98
99 =item *
100
101 1 sample per color - gray scale image.
102
103 =item *
104
105 2 samples per color - gray scale image with alpha channel, allowing
106 transparency.
107
108 =item *
109
110 3 samples per color - RGB image.
111
112 =item *
113
114 4 samples per color - RGB image with alpha channel, allowing
115 transparency.
116
117 =back
118
119 Direct color images can have sample sizes of 8-bits per sample,
120 16-bits per sample or a double precision floating point number per
121 sample (64-bits on many systems).
122
123 Paletted images are always 8-bits/sample.
124
125 To query an existing image about it's parameters see the C<bits()>,
126 C<type()>, C<getwidth()>, C<getheight()>, C<getchannels()> and
127 C<virtual()> methods.
128
129 The coordinate system in Imager has the origin in the upper left
130 corner, see L<Imager::Draw> for details.
131
132 The alpha channel when one is present is considered unassociated -
133 ie the color data has not been scaled by the alpha channel.  Note
134 that not all code follows this (recent) rule, but will over time.
135
136 =head2 Creating Imager Objects
137
138 =over
139
140 =item new()
141
142   $img = Imager->new();
143   $img->read(file=>"alligator.ppm") or die $img->errstr;
144
145 Here C<new()> creates an empty image with width and height of zero.
146 It's only useful for creating an Imager object to call the read()
147 method on later.
148
149   %opts = (xsize=>300, ysize=>200);
150   $img = Imager->new(%opts); # create direct mode RGBA image
151   $img = Imager->new(%opts, channels=>4); # create direct mode RGBA image
152
153 You can also read a file from new():
154
155   $img = Imager->new(file => "someimage.png");
156
157 The parameters for new are:
158
159 =over
160
161 =item *
162
163 C<xsize>, C<ysize> - Defines the width and height in pixels of the
164 image.  These must be positive.
165
166 If not supplied then only placeholder object is created, which can be
167 supplied to the C<read()> or C<img_set()> methods.
168
169 =item *
170
171 C<channels> - The number of channels for the image.  Default 3.  Valid
172 values are from 1 to 4.
173
174 =item *
175
176 C<bits> - The storage type for samples in the image.  Default: 8.
177 Valid values are:
178
179 =over
180
181 =item *
182
183 C<8> - One byte per sample.  256 discrete values.
184
185 =item *
186
187 C<16> - 16-bits per sample, 65536 discrete values.
188
189 =item *
190
191 C<double> - one C double per sample.
192
193 =back
194
195 Note: you can use any Imager function on any sample size image.
196
197 Paletted images always use 8 bits/sample.
198
199 =item *
200
201 C<type> - either C<'direct'> or C<'paletted'>.  Default: C<'direct'>.
202
203 Direct images store color values for each pixel.  
204
205 Paletted images keep a table of up to 256 colors called the palette,
206 each pixel is represented as an index into that table.
207
208 In most cases when working with Imager you will want to use the
209 C<direct> image type.
210
211 If you draw on a C<paletted> image with a color not in the image's
212 palette then Imager will transparently convert it to a C<direct>
213 image.
214
215 =item *
216
217 C<maxcolors> - the maximum number of colors in a paletted image.
218 Default: 256.  This must be in the range 1 through 256.
219
220 =item *
221
222 C<file>, C<fh>, C<fd>, C<callback>, C<readcb> - specify a file name,
223 filehandle, file descriptor or callback to read image data from.  See
224 L<Imager::Files> for details.  The typical use is:
225
226   my $im = Imager->new(file => $filename);
227
228 =item *
229
230 C<filetype> - treated as the file format parameter, as for C<type>
231 with the read() method, eg:
232
233   my $im = Imager->new(file => $filename, filetype => "gif");
234
235 In most cases Imager will detect the file's format itself.
236
237 =back
238
239 In the simplest case just supply the width and height of the image:
240
241   # 8 bit/sample, RGB image
242   my $img = Imager->new(xsize => $width, ysize => $height);
243
244 or if you want an alpha channel:
245
246   # 8 bits/sample, RGBA image
247   my $img = Imager->new(xsize => $width, ysize => $height, channels=>4);
248
249 Note that it I<is> possible for image creation to fail, for example if
250 channels is out of range, or if the image would take too much memory.
251
252 To create paletted images, set the 'type' parameter to 'paletted':
253
254   $img = Imager->new(xsize=>200, ysize=>200, type=>'paletted');
255
256 which creates an image with a maximum of 256 colors, which you can
257 change by supplying the C<maxcolors> parameter.
258
259 For improved color precision you can use the bits parameter to specify
260 16 bit per channel:
261
262   $img = Imager->new(xsize=>200, ysize=>200,
263                      channels=>3, bits=>16);
264
265 or for even more precision:
266
267   $img = Imager->new(xsize=>200, ysize=>200,
268                      channels=>3, bits=>'double');
269
270 to get an image that uses a double for each channel.
271
272 Note that as of this writing all functions should work on images with
273 more than 8-bits/channel, but many will only work at only
274 8-bit/channel precision.
275
276 If you want an empty Imager object to call the read() method on, just
277 call new() with no parameters:
278
279   my $img = Imager->new;
280   $img->read(file=>$filename)
281     or die $img->errstr;
282
283 Though it's much easier now to just call new() with a C<file>
284 parameter:
285
286   my $img = Imager->new(file => $filename)
287     or die Imager->errstr;
288
289 =item img_set()
290
291 img_set destroys the image data in the object and creates a new one
292 with the given dimensions and channels.  For a way to convert image
293 data between formats see the C<convert()> method.
294
295   $img->img_set(xsize=>500, ysize=>500, channels=>4);
296
297 This takes exactly the same parameters as the new() method.
298
299 =back
300
301 =head2 Image Attribute functions
302
303 These return basic attributes of an image object.
304
305 =over
306
307 =item getwidth()
308
309   print "Image width: ", $img->getwidth(), "\n";
310
311 The C<getwidth()> method returns the width of the image.  This value
312 comes either from C<new()> with C<xsize>, C<ysize> parameters or from
313 reading data from a file with C<read()>.  If called on an image that
314 has no valid data in it like C<Imager-E<gt>new()> returns, the return
315 value of C<getwidth()> is undef.
316
317 =item getheight()
318
319   print "Image height: ", $img->getheight(), "\n";
320
321 Same details apply as for L</getwidth()>.
322
323 =item getchannels()
324
325   print "Image has ",$img->getchannels(), " channels\n";
326
327 To get the number of channels in an image C<getchannels()> is used.
328
329
330 =item bits()
331
332 The bits() method retrieves the number of bits used to represent each
333 channel in a pixel, 8 for a normal image, 16 for 16-bit image and
334 'double' for a double/channel image.
335
336   if ($img->bits eq 8) {
337     # fast but limited to 8-bits/sample
338   }
339   else {
340     # slower but more precise
341   }
342
343 =item type()
344
345 The type() method returns either 'direct' for direct color images or
346 'paletted' for paletted images.
347
348   if ($img->type eq 'paletted') {
349     # print the palette
350     for my $color ($img->getcolors) {
351       print join(",", $color->rgba), "\n";
352     }
353   }
354
355 =item virtual()
356
357 The virtual() method returns non-zero if the image contains no actual
358 pixels, for example masked images.
359
360 =for stopwords SDL
361
362 This may also be used for non-native Imager images in the future, for
363 example, for an Imager object that draws on an SDL surface.
364
365 =item is_bilevel()
366
367 Tests if the image will be written as a monochrome or bi-level image
368 for formats that support that image organization.
369
370 In scalar context, returns true if the image is bi-level.
371
372 In list context returns a list:
373
374   ($is_bilevel, $zero_is_white) = $img->is_bilevel;
375
376 An image is considered bi-level, if all of the following are true:
377
378 =over
379
380 =item *
381
382 the image is a paletted image
383
384 =item *
385
386 the image has 1 or 3 channels
387
388 =item *
389
390 the image has only 2 colors in the palette
391
392 =item *
393
394 those 2 colors are black and white, in either order.
395
396 =back
397
398 If a real bi-level organization image is ever added to Imager, this
399 function will return true for that too.
400
401 =back
402
403 =head2 Direct Type Images
404
405 Direct images store the color value directly for each pixel in the
406 image.
407
408 =over
409
410 =item getmask()
411
412   @rgbanames = qw( red green blue alpha );
413   my $mask = $img->getmask();
414   print "Modifiable channels:\n";
415   for (0..$img->getchannels()-1) {
416     print $rgbanames[$_],"\n" if $mask & 1<<$_;
417   }
418
419 =for stopwords th
420
421 C<getmask()> is used to fetch the current channel mask.  The mask
422 determines what channels are currently modifiable in the image.  The
423 channel mask is an integer value, if the C<i-th> least significant bit
424 is set the C<i-th> channel is modifiable.  eg. a channel mask of 0x5
425 means only channels 0 and 2 are writable.
426
427 =item setmask()
428
429   $mask = $img->getmask();
430   $img->setmask(mask=>8);     # modify alpha only
431
432     ...
433
434   $img->setmask(mask=>$mask); # restore previous mask
435
436 C<setmask()> is used to set the channel mask of the image.  See
437 L</getmask()> for details.
438
439 =back
440
441 =head2 Palette Type Images
442
443 Paletted images keep an array of up to 256 colors, and each pixel is
444 stored as an index into that array.
445
446 In general you can work with paletted images in the same way as RGB
447 images, except that if you attempt to draw to a paletted image with a
448 color that is not in the image's palette, the image will be converted
449 to an RGB image.  This means that drawing on a paletted image with
450 anti-aliasing enabled will almost certainly convert the image to RGB.
451
452 Palette management takes place through C<addcolors()>, C<setcolors()>,
453 C<getcolors()> and C<findcolor()>:
454
455 =over
456
457 =item addcolors()
458
459 You can add colors to a paletted image with the addcolors() method:
460
461    my @colors = ( Imager::Color->new(255, 0, 0), 
462                   Imager::Color->new(0, 255, 0) );
463    my $index = $img->addcolors(colors=>\@colors);
464
465 The return value is the index of the first color added, or undef if
466 adding the colors would overflow the palette.
467
468 The only parameter is C<colors> which must be a reference to an array
469 of Imager::Color objects.
470
471 =item setcolors()
472
473   $img->setcolors(start=>$start, colors=>\@colors);
474
475 Once you have colors in the palette you can overwrite them with the
476 C<setcolors()> method:  C<setcolors()> returns true on success.
477
478 Parameters:
479
480 =over
481
482 =item *
483
484 start - the first index to be set.  Default: 0
485
486 =item *
487
488 colors - reference to an array of Imager::Color objects.
489
490 =back
491
492 =item getcolors()
493
494 To retrieve existing colors from the palette use the getcolors() method:
495
496   # get the whole palette
497   my @colors = $img->getcolors();
498   # get a single color
499   my $color = $img->getcolors(start=>$index);
500   # get a range of colors
501   my @colors = $img->getcolors(start=>$index, count=>$count);
502
503 =item findcolor()
504
505 To quickly find a color in the palette use findcolor():
506
507   my $index = $img->findcolor(color=>$color);
508
509 which returns undef on failure, or the index of the color.
510
511 Parameter:
512
513 =over
514
515 =item *
516
517 color - an Imager::Color object.
518
519 =back
520
521 =item colorcount()
522
523 Returns the number of colors in the image's palette:
524
525   my $count = $img->colorcount;
526
527 =item maxcolors()
528
529 Returns the maximum size of the image's palette.
530
531   my $maxcount = $img->maxcolors;
532
533 =back
534
535 =head2 Color Distribution
536
537 =over
538
539 =item getcolorcount()
540
541 Calculates the number of colors in an image.
542
543 The amount of memory used by this is proportional to the number of
544 colors present in the image, so to avoid using too much memory you can
545 supply a maxcolors() parameter to limit the memory used.
546
547 Note: getcolorcount() treats the image as an 8-bit per sample image.
548
549 =over
550
551 =item *
552
553 X<maxcolors!getcolorcount>C<maxcolors> - the maximum number of colors to
554 return.  Default: unlimited.
555
556 =back
557
558   if (defined($img->getcolorcount(maxcolors=>512)) {
559     print "Less than 512 colors in image\n";
560   }
561
562 =item getcolorusagehash()
563
564 Calculates a histogram of colors used by the image.
565
566 =over
567
568 =item *
569
570 X<maxcolors!getcolorusagehash>C<maxcolors> - the maximum number of colors
571 to return.  Default: unlimited.
572
573 =back
574
575 Returns a reference to a hash where the keys are the raw color as
576 bytes, and the values are the counts for that color.
577
578 The alpha channel of the image is ignored.  If the image is gray scale
579 then the hash keys will each be a single character.
580
581   my $colors = $img->getcolorusagehash;
582   my $blue_count = $colors->{pack("CCC", 0, 0, 255)} || 0;
583   print "#0000FF used $blue_count times\n";
584
585 =item getcolorusage()
586
587 Calculates color usage counts and returns just the counts.
588
589 =over
590
591 =item *
592
593 X<maxcolors!getcolorusage>C<maxcolors> - the maximum number of colors
594 to return.  Default: unlimited.
595
596 =back
597
598 Returns a list of the color frequencies in ascending order.
599
600   my @counts = $img->getcolorusage;
601   print "The most common color is used $counts[0] times\n";
602
603 =back
604
605 =head2 Conversion Between Image Types
606
607 Warning: if you draw on a paletted image with colors that aren't in
608 the palette, the image will be internally converted to a normal image.
609
610 =over
611
612 =item to_paletted()
613
614 You can create a new paletted image from an existing image using the
615 to_paletted() method:
616
617  $palimg = $img->to_paletted(\%opts)
618
619 where %opts contains the options specified under L</Quantization options>.
620
621   # convert to a paletted image using the web palette
622   # use the closest color to each pixel
623   my $webimg = $img->to_paletted({ make_colors => 'webmap' });
624
625   # convert to a paletted image using a fairly optimal palette
626   # use an error diffusion dither to try to reduce the average error
627   my $optimag = $img->to_paletted({ make_colors => 'mediancut',
628                                     translate => 'errdiff' });
629
630 =item to_rgb8()
631
632 You can convert a paletted image (or any image) to an 8-bit/channel
633 RGB image with:
634
635   $rgbimg = $img->to_rgb8;
636
637 No parameters.
638
639 =item to_rgb16()
640
641 You can convert a paletted image (or any image) to an 16-bit/channel
642 RGB image with:
643
644   $rgbimg = $img->to_rgb16;
645
646 No parameters.
647
648 =item masked()
649
650 Creates a masked image.  A masked image lets you create an image proxy
651 object that protects parts of the underlying target image.
652
653 In the discussion below there are 3 image objects involved:
654
655 =over
656
657 =item *
658
659 the masked image - the return value of the masked() method.  Any
660 writes to this image are written to the target image, assuming the
661 mask image allows it.
662
663 =item *
664
665 the mask image - the image that protects writes to the target image.
666 Supplied as the C<mask> parameter to the masked() method.
667
668 =item *
669
670 the target image - the image you called the masked() method on.  Any
671 writes to the masked image end up on this image.
672
673 =back
674
675 Parameters:
676
677 =over
678
679 =item *
680
681 mask - the mask image.  If not supplied then all pixels in the target
682 image are writable.  On each write to the masked image, only pixels
683 that have non-zero in channel 0 of the mask image will be written to
684 the original image.  Default: none, if not supplied then no masking is
685 done, but the other parameters are still honored.
686
687 =item *
688
689 left, top - the offset of writes to the target image.  eg. if you
690 attempt to set pixel (x,y) in the masked image, then pixel (x+left,
691 y+top) will be written to in the original image.
692
693 =item *
694
695 bottom, right - the bottom right of the area in the target available
696 from the masked image.
697
698 =back
699
700 Masked images let you control which pixels are modified in an
701 underlying image.  Where the first channel is completely black in the
702 mask image, writes to the underlying image are ignored.
703
704 For example, given a base image called $img:
705
706   my $mask = Imager->new(xsize=>$img->getwidth, ysize=>$img->getheight,
707                          channels=>1);
708   # ... draw something on the mask
709   my $maskedimg = $img->masked(mask=>$mask);
710
711   # now draw on $maskedimg and it will only draw on areas of $img 
712   # where $mask is non-zero in channel 0.
713
714 You can specify the region of the underlying image that is masked
715 using the left, top, right and bottom options.
716
717 If you just want a subset of the image, without masking, just specify
718 the region without specifying a mask.  For example:
719
720   # just work with a 100x100 region of $img
721   my $maskedimg = $img->masked(left => 100, top=>100,
722                                right=>200, bottom=>200);
723
724 =back
725
726 =head2 Tags
727
728 Image tags contain meta-data about the image, ie. information not
729 stored as pixels of the image.
730
731 At the perl level each tag has a name or code and a value, which is an
732 integer or an arbitrary string.  An image can contain more than one
733 tag with the same name or code, but having more than one tag with the
734 same name is discouraged.
735
736 You can retrieve tags from an image using the tags() method, you can
737 get all of the tags in an image, as a list of array references, with
738 the code or name of the tag followed by the value of the tag.
739
740 =over
741
742 =item tags()
743
744 Retrieve tags from the image.
745
746 With no parameters, retrieves a list array references, each containing
747 a name and value: all tags in the image:
748
749   # get a list of ( [ name1 => value1 ], [ name2 => value2 ] ... )
750   my @alltags = $img->tags;
751   print $_->[0], ":", $_->[1], "\n" for @all_tags;
752
753   # or put it in a hash, but this will lose duplicates
754   my %alltags = map @$_, $img->tags;
755
756 in scalar context this returns the number of tags:
757
758   my $num_tags = $img->tags;
759
760 or you can get all tags values for the given name:
761
762   my @namedtags = $img->tags(name => $name);
763
764 in scalar context this returns the first tag of that name:
765
766   my $firstnamed = $img->tags(name => $name);
767
768 or a given code:
769
770   my @tags = $img->tags(code=>$code);
771
772 =item addtag()
773
774 You can add tags using the addtag() method, either by name:
775
776   my $index = $img->addtag(name=>$name, value=>$value);
777
778 or by code:
779
780   my $index = $img->addtag(code=>$code, value=>$value);
781
782 =item deltag()
783
784 You can remove tags with the deltag() method, either by index:
785
786   $img->deltag(index=>$index);
787
788 or by name:
789
790   $img->deltag(name=>$name);
791
792 or by code:
793
794   $img->deltag(code=>$code);
795
796 In each case deltag() returns the number of tags deleted.
797
798 =item settag()
799
800 settag() replaces any existing tags with a new tag.  This is
801 equivalent to calling deltag() then addtag().
802
803 =back
804
805 =head2 Common Tags
806
807 Many tags are only meaningful for one format.  GIF looping information
808 is pretty useless for JPEG for example.  Thus, many tags are set by
809 only a single reader or used by a single writer.  For a complete list
810 of format specific tags see L<Imager::Files>.
811
812 Since tags are a relatively new addition their use is not wide spread
813 but eventually we hope to have all the readers for various formats set
814 some standard information.
815
816 =over
817
818 =item *
819
820 X<i_xres tag>X<i_yres tag>X<tags, i_xres>X<tags, i_yres>C<i_xres>, C<i_yres>
821 - The spatial resolution of the image in pixels per inch.  If the
822 image format uses a different scale, eg. pixels per meter, then this
823 value is converted.  A floating point number stored as a string.
824
825   # our image was generated as a 300 dpi image
826   $img->settag(name => 'i_xres', value => 300);
827   $img->settag(name => 'i_yres', value => 300);
828
829   # 100 pixel/cm for a TIFF image
830   $img->settag(name => 'tiff_resolutionunit', value => 3); # RESUNIT_CENTIMETER
831   # convert to pixels per inch, Imager will convert it back
832   $img->settag(name => 'i_xres', value => 100 * 2.54);
833   $img->settag(name => 'i_yres', value => 100 * 2.54);
834
835 =item *
836
837 X<i_aspect_only tag>X<tags, i_aspect_only>C<i_aspect_only> - If this is
838 non-zero then the values in i_xres and i_yres are treated as a ratio
839 only.  If the image format does not support aspect ratios then this is
840 scaled so the smaller value is 72 DPI.
841
842 =item *
843
844 X<i_incomplete tag>X<tags, i_incomplete>C<i_incomplete> - If this tag is
845 present then the whole image could not be read.  This isn't
846 implemented for all images yet, and may not be.
847
848 =item *
849
850 X<i_lines_read tag>X<tags, i_lines_read>C<i_lines_read> - If
851 C<i_incomplete> is set then this tag may be set to the number of
852 scan lines successfully read from the file.  This can be used to decide
853 whether an image is worth processing.
854
855 =item *
856
857 X<i_format tag>X<tags, i_format>i_format - The file format this file
858 was read from.
859
860 =item *
861
862 X<i_background>X<tags, i_background>i_background - used when writing
863 an image with an alpha channel to a file format that doesn't support
864 alpha channels.  The C<write> method will convert a normal color
865 specification like "#FF0000" into a color object for you, but if you
866 set this as a tag you will need to format it like
867 C<color(>I<red>C<,>I<green>C<,>I<blue>C<)>, eg color(255,0,0).
868
869 =back
870
871 =head2 Quantization options
872
873 These options can be specified when calling
874 L<Imager::ImageTypes/to_paletted()>, write_multi() for GIF files, when
875 writing a single image with the C<gifquant> option set to C<gen>, or for
876 direct calls to i_writegif_gen() and i_writegif_callback().
877
878 =over
879
880 =item *
881
882 C<colors> - An arrayref of colors that are fixed.  Note that some
883 color generators will ignore this.  If this is supplied it will be
884 filled with the color table generated for the image.
885
886 =item *
887
888 C<transp> - The type of transparency processing to perform for images
889 with an alpha channel where the output format does not have a proper
890 alpha channel (eg. GIF).  This can be any of:
891
892 =over
893
894 =item *
895
896 C<none> - No transparency processing is done. (default)
897
898 =item *
899
900 C<threshold> - pixels more transparent than C<tr_threshold> are
901 rendered as transparent.
902
903 =item *
904
905 C<errdiff> - An error diffusion dither is done on the alpha channel.
906 Note that this is independent of the translation performed on the
907 color channels, so some combinations may cause undesired artifacts.
908
909 =item *
910
911 C<ordered> - the ordered dither specified by tr_orddith is performed
912 on the alpha channel.
913
914 =back
915
916 This will only be used if the image has an alpha channel, and if there
917 is space in the palette for a transparency color.
918
919 =item *
920
921 C<tr_threshold> - the highest alpha value at which a pixel will be
922 made transparent when C<transp> is 'threshold'. (0-255, default 127)
923
924 =item *
925
926 C<tr_errdiff> - The type of error diffusion to perform on the alpha
927 channel when C<transp> is C<errdiff>.  This can be any defined error
928 diffusion type except for custom (see C<errdiff> below).
929
930 =item *
931
932 C<tr_orddith> - The type of ordered dither to perform on the alpha
933 channel when C<transp> is 'ordered'.  Possible values are:
934
935 =over
936
937 =item *
938
939 C<random> - A semi-random map is used.  The map is the same each time.
940
941 =item *
942
943 C<dot8> - 8x8 dot dither.
944
945 =item *
946
947 C<dot4> - 4x4 dot dither
948
949 =item *
950
951 C<hline> - horizontal line dither.
952
953 =item *
954
955 C<vline> - vertical line dither.
956
957 =item *
958
959 C</line>, C<slashline> - diagonal line dither
960
961 =item *
962
963 C<\line>, C<backline> - diagonal line dither
964
965 =item *
966
967 C<tiny> - dot matrix dither (currently the default).  This is probably
968 the best for displays (like web pages).
969
970 =item *
971
972 C<custom> - A custom dither matrix is used - see C<tr_map>.
973
974 =back
975
976 =item *
977
978 C<tr_map> - When tr_orddith is custom this defines an 8 x 8 matrix of
979 integers representing the transparency threshold for pixels
980 corresponding to each position.  This should be a 64 element array
981 where the first 8 entries correspond to the first row of the matrix.
982 Values should be between 0 and 255.
983
984 =item *
985
986 C<make_colors> - Defines how the quantization engine will build the
987 palette(s).  Currently this is ignored if C<translate> is C<giflib>,
988 but that may change.  Possible values are:
989
990 =over
991
992 =item *
993
994 C<none> - only colors supplied in 'colors' are used.
995
996 =item *
997
998 C<webmap> - the web color map is used (need URL here.)
999
1000 =item *
1001
1002 C<addi> - The original code for generating the color map (Addi's code) is
1003 used.
1004
1005 =item *
1006
1007 C<mediancut> - Uses a median-cut algorithm, faster than C<addi>, but not
1008 as good a result.
1009
1010 =item *
1011
1012 C<mono>, C<monochrome> - a fixed black and white palette, suitable for
1013 producing bi-level images (eg. facsimile)
1014
1015 =back
1016
1017 Other methods may be added in the future.
1018
1019 =item *
1020
1021 C<colors> - an arrayref containing Imager::Color objects, which
1022 represents the starting set of colors to use in translating the
1023 images.  C<webmap> will ignore this.  On return the final colors used
1024 are copied back into this array (which is expanded if necessary.)
1025
1026 =item *
1027
1028 C<max_colors> - the maximum number of colors to use in the image.
1029
1030 =item *
1031
1032 C<translate> - The method used to translate the RGB values in the
1033 source image into the colors selected by make_colors.  Note that
1034 make_colors is ignored when C<translate> is C<giflib>.
1035
1036 Possible values are:
1037
1038 =over
1039
1040 =item *
1041
1042 C<giflib> - the C<giflib> native quantization function is used.
1043
1044 =item *
1045
1046 C<closest> - the closest color available is used.
1047
1048 =item *
1049
1050 C<perturb> - the pixel color is modified by C<perturb>, and the
1051 closest color is chosen.
1052
1053 =item *
1054
1055 C<errdiff> - an error diffusion dither is performed.
1056
1057 =back
1058
1059 It's possible other C<translate> values will be added.
1060
1061 =item *
1062
1063 C<errdiff> - The type of error diffusion dither to perform.  These
1064 values (except for custom) can also be used in tr_errdif.
1065
1066 =for stopwords Floyd-Steinberg Jarvis Judice Ninke Stucki
1067
1068 =over
1069
1070 =item *
1071
1072 C<floyd> - Floyd-Steinberg dither
1073
1074 =item *
1075
1076 C<jarvis> - Jarvis, Judice and Ninke dither
1077
1078 =item *
1079
1080 C<stucki> - Stucki dither
1081
1082 =item *
1083
1084 C<custom> - custom.  If you use this you must also set C<errdiff_width>,
1085 C<errdiff_height> and C<errdiff_map>.
1086
1087 =back
1088
1089 =item *
1090
1091 C<errdiff_width>, C<errdiff_height>, C<errdiff_orig>, C<errdiff_map> -
1092 When C<translate> is C<errdiff> and C<errdiff> is C<custom> these
1093 define a custom error diffusion map.  C<errdiff_width> and
1094 C<errdiff_height> define the size of the map in the arrayref in
1095 C<errdiff_map>.  C<errdiff_orig> is an integer which indicates the
1096 current pixel position in the top row of the map.
1097
1098 =item *
1099
1100 C<perturb> - When translate is C<perturb> this is the magnitude of the
1101 random bias applied to each channel of the pixel before it is looked
1102 up in the color table.
1103
1104 =back
1105
1106 =head1 INITIALIZATION
1107
1108 This documents the Imager initialization function, which you will
1109 almost never need to call.
1110
1111 =over
1112
1113 =item init()
1114
1115 This is a function, not a method.
1116
1117 This function is a mess, it can take the following named parameters:
1118
1119 =over
1120
1121 =item *
1122
1123 C<log> - name of a log file to log Imager's actions to.  Not all actions
1124 are logged, but the debugging memory allocator does log allocations
1125 here.  Ignored if Imager has been built without logging support.
1126
1127 =item *
1128
1129 C<loglevel> - the maximum level of message to log.  Default: 1.
1130
1131 =item *
1132
1133 C<warn_obsolete> - if this is non-zero then Imager will warn when you
1134 attempt to use obsoleted parameters or functionality.  This currently
1135 only includes the old GIF output options instead of tags.
1136
1137 =item *
1138
1139 C<t1log> - if non-zero then T1lib will be configured to produce a log
1140 file.  This will fail if there are any existing T1lib font objects.
1141
1142 =back
1143
1144 Example:
1145
1146   Imager::init(log => 'trace.log', loglevel => 9);
1147
1148 =back
1149
1150 =head1 REVISION
1151
1152 $Revision$
1153
1154 =head1 AUTHORS
1155
1156 Tony Cook, Arnar M. Hrafnkelsson
1157
1158 =head1 SEE ALSO
1159
1160 Imager(3), Imager::Files(3), Imager::Draw(3),
1161 Imager::Color(3), Imager::Fill(3), Imager::Font(3),
1162 Imager::Transformations(3), Imager::Engines(3), Imager::Filters(3),
1163 Imager::Expr(3), Imager::Matrix2d(3), Imager::Fountain(3)
1164
1165 =cut