Imager::TrimColorList(3pm) | User Contributed Perl Documentation | Imager::TrimColorList(3pm) |
Imager::TrimColorList - represent a list of color ranges for Imager's trim() method.
use Imager::TrimColorList; # empty list my $tcl = Imager::TrimColorList->new; # add an entry in a variety of forms $tcl->add($entry); # add an explicit color object entry $tcl->add_color($c1, $c2); # add an explicit floating color object entry $tcl->add_fcolor($cf1, $cf2); # number of entries my $count = $tcl->count; # fetch an entry my $entry = $tcl->get($index); # fetch all entries my @all = $tcl->all; # make a list and populate it my $tcl = Imager::TrimColorList->new($entry1, $entry2, ...); # dump contents of the list as a string print $tcl->describe;
An Imager::TrimColorList represents a list of color ranges to supply to the trim() method.
Each range can be either an 8-bit color range, ie. Imager::Color objects, or a floating point color range, ie. Imager::Color::Float objects, these can be mixed freely in a single list but each range must be 8-bit or floating point.
You can supply an entry in a small variety of forms:
$tcl->add("#000"); $tcl->add(Imager::Color->new(0, 0, 0)); $tcl->add(Imager::Color::Float->new(0, 0, 0));
$tcl->add([ "#000" ]); $tcl->add([ Imager::Color->new(0, 0, 0) ]); $tcl->add([ Imager::Color::Float->new(0, 0, 0) ]);
$tcl->add([ "#000", "#002" ]); $tcl->add([ Imager::Color->new(0, 0, 0), Imager::Color->new(0, 0, 2) ]); $tcl->add([ Imager::Color::Float->new(0, 0, 0), Imager::Color::Float->new(0, 0, 2/255) ]);
$tcl->add([ "#000", 0.01 ]) $tcl->add([ Imager::Color->new(0, 0, 0), 0.01 ]); $tcl->add([ Imager::Color::Float->new(0, 0, 0), 0.01 ]);
A range specified this way with an 8-bit color clips at the top and bottom of the sample ranges, so the example 8-bit range above goes from (0, 0, 0) to (2, 2, 2) inclusive, while the floating point range isn't clipped and results in the floating color range (-0.01, -0.01, -0.01) to (0.01, 0.01, 0.01) inclusive.
Returns an optionally populated Imager::TrimColorList object, or an empty list (or undef) or failure.
Returns a true value on success and a false value on failure.
Returns undef if $index is out of range and does not set "Imager->errstr".
This is used to implement 'auto' for image trim() and trim_rect() methods.
Parameters:
Default: 1.
If any method returns an error you can fetch a diagnostic from "Imager->errstr".
Imager::TrimColorList objects are properly duplicated when new perl threads are created.
Tony Cook <tonyc@cpan.org>
Originally the range handling for this was going to be embedded in the trim() method, but this meant that every called that used color ranges would pay some cost as the range list was checked for names (vs color objects) and non-standard forms such as single colors and the color plus variance.
The object allows a simple test for the trim() "colors" parameter that doesn't pay that cost, and still allows a caller to use the explicit convention.
2023-01-11 | perl v5.36.0 |