i_color_set
i_color_info
- i_img_empty
- i_img_empty_ch
- i_img_exorcise
- i_img_destroy
-
i_img_info
i_img_setmask
if ($ex_version < 5.57) {
@ISA = qw(Exporter);
}
- $VERSION = '0.87';
- eval {
- require XSLoader;
- XSLoader::load(Imager => $VERSION);
- 1;
- } or do {
- require DynaLoader;
- push @ISA, 'DynaLoader';
- bootstrap Imager $VERSION;
- }
+ $VERSION = '0.92';
+ require XSLoader;
+ XSLoader::load(Imager => $VERSION);
}
my %formats_low;
}
sub _valid_image {
- my ($self) = @_;
+ my ($self, $method) = @_;
$self->{IMG} and return 1;
- $self->_set_error('empty input image');
+ my $msg = 'empty input image';
+ $msg = "$method: $msg" if $method;
+ $self->_set_error($msg);
return;
}
$self->{IMG} = i_img_16_new($hsh{xsize}, $hsh{ysize}, $hsh{channels});
}
else {
- $self->{IMG}=Imager::ImgRaw::new($hsh{'xsize'}, $hsh{'ysize'},
- $hsh{'channels'});
+ $self->{IMG}= i_img_8_new($hsh{'xsize'}, $hsh{'ysize'},
+ $hsh{'channels'});
}
unless ($self->{IMG}) {
return 1;
}
else {
- my $work = $@ || "Unknown error loading $file";
+ my $work = $@ || "Unknown error";
chomp $work;
$work =~ s/\n?Compilation failed in require at .*Imager\.pm line .*\z//m;
$work =~ s/\n/\\n/g;
+ $work =~ s/\s*\.?\z/ loading $file/;
$file_load_errors{$file} = $work;
$$error = $work;
return 0;
}
}
elsif (defined $opts{radians} || defined $opts{degrees}) {
- my $amount = $opts{radians} || $opts{degrees} * 3.1415926535 / 180;
+ my $amount = $opts{radians} || $opts{degrees} * 3.14159265358979 / 180;
my $back = $opts{back};
my $result = Imager->new;
sub setpixel {
my ($self, %opts) = @_;
+ $self->_valid_image("setpixel")
+ or return;
+
my $color = $opts{color};
unless (defined $color) {
$color = $self->{fg};
}
unless (ref $color && UNIVERSAL::isa($color, "Imager::Color")) {
- $color = _color($color)
- or return undef;
+ unless ($color = _color($color, 'setpixel')) {
+ $self->_set_error("setpixel: " . Imager->errstr);
+ return;
+ }
}
unless (exists $opts{'x'} && exists $opts{'y'}) {
- $self->{ERRSTR} = 'missing x and y parameters';
- return undef;
+ $self->_set_error('setpixel: missing x or y parameter');
+ return;
}
my $x = $opts{'x'};
my $y = $opts{'y'};
- if (ref $x && ref $y) {
- unless (@$x == @$y) {
- $self->{ERRSTR} = 'length of x and y mismatch';
+ if (ref $x || ref $y) {
+ $x = ref $x ? $x : [ $x ];
+ $y = ref $y ? $y : [ $y ];
+ unless (@$x) {
+ $self->_set_error("setpixel: x is a reference to an empty array");
return;
}
+ unless (@$y) {
+ $self->_set_error("setpixel: y is a reference to an empty array");
+ return;
+ }
+
+ # make both the same length, replicating the last element
+ if (@$x < @$y) {
+ $x = [ @$x, ($x->[-1]) x (@$y - @$x) ];
+ }
+ elsif (@$y < @$x) {
+ $y = [ @$y, ($y->[-1]) x (@$x - @$y) ];
+ }
+
my $set = 0;
if ($color->isa('Imager::Color')) {
- for my $i (0..$#{$opts{'x'}}) {
+ for my $i (0..$#$x) {
i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color)
or ++$set;
}
}
else {
- for my $i (0..$#{$opts{'x'}}) {
+ for my $i (0..$#$x) {
i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color)
or ++$set;
}
}
- $set or return;
+
return $set;
}
else {
}
}
- $self;
+ return $self;
}
sub getpixel {
my %opts = ( "type"=>'8bit', @_);
+ $self->_valid_image("getpixel")
+ or return;
+
unless (exists $opts{'x'} && exists $opts{'y'}) {
- $self->{ERRSTR} = 'missing x and y parameters';
- return undef;
+ $self->_set_error('getpixel: missing x or y parameter');
+ return;
}
my $x = $opts{'x'};
my $y = $opts{'y'};
- if (ref $x && ref $y) {
- unless (@$x == @$y) {
- $self->{ERRSTR} = 'length of x and y mismatch';
- return undef;
+ my $type = $opts{'type'};
+ if (ref $x || ref $y) {
+ $x = ref $x ? $x : [ $x ];
+ $y = ref $y ? $y : [ $y ];
+ unless (@$x) {
+ $self->_set_error("getpixel: x is a reference to an empty array");
+ return;
}
+ unless (@$y) {
+ $self->_set_error("getpixel: y is a reference to an empty array");
+ return;
+ }
+
+ # make both the same length, replicating the last element
+ if (@$x < @$y) {
+ $x = [ @$x, ($x->[-1]) x (@$y - @$x) ];
+ }
+ elsif (@$y < @$x) {
+ $y = [ @$y, ($y->[-1]) x (@$x - @$y) ];
+ }
+
my @result;
- if ($opts{"type"} eq '8bit') {
- for my $i (0..$#{$opts{'x'}}) {
+ if ($type eq '8bit') {
+ for my $i (0..$#$x) {
push(@result, i_get_pixel($self->{IMG}, $x->[$i], $y->[$i]));
}
}
- else {
- for my $i (0..$#{$opts{'x'}}) {
+ elsif ($type eq 'float' || $type eq 'double') {
+ for my $i (0..$#$x) {
push(@result, i_gpixf($self->{IMG}, $x->[$i], $y->[$i]));
}
}
+ else {
+ $self->_set_error("getpixel: type must be '8bit' or 'float'");
+ return;
+ }
return wantarray ? @result : \@result;
}
else {
- if ($opts{"type"} eq '8bit') {
+ if ($type eq '8bit') {
return i_get_pixel($self->{IMG}, $x, $y);
}
- else {
+ elsif ($type eq 'float' || $type eq 'double') {
return i_gpixf($self->{IMG}, $x, $y);
}
+ else {
+ $self->_set_error("getpixel: type must be '8bit' or 'float'");
+ return;
+ }
}
-
- $self;
}
sub getscanline {
my $count;
if ($type eq '8bit') {
$count = i_psamp($self->{IMG}, $opts{x}, $opts{y}, $opts{channels},
- $data);
+ $data, $opts{offset}, $width);
}
elsif ($type eq 'float') {
$count = i_psampf($self->{IMG}, $opts{x}, $opts{y}, $opts{channels},
- $opts{data});
+ $data, $opts{offset}, $width);
}
elsif ($type =~ /^([0-9]+)bit$/) {
my $bits = $1;
}
$count = i_psamp_bits($self->{IMG}, $opts{x}, $opts{y}, $bits,
- $opts{channels}, $opts{data}, $opts{offset},
+ $opts{channels}, $data, $opts{offset},
$width);
}
else {
i_get_image_file_limits();
}
+my @check_args = qw(width height channels sample_size);
+
+sub check_file_limits {
+ my $class = shift;
+
+ my %opts =
+ (
+ channels => 3,
+ sample_size => 1,
+ @_,
+ );
+
+ if ($opts{sample_size} && $opts{sample_size} eq 'float') {
+ $opts{sample_size} = length(pack("d", 0));
+ }
+
+ for my $name (@check_args) {
+ unless (defined $opts{$name}) {
+ $class->_set_error("check_file_limits: $name must be defined");
+ return;
+ }
+ unless ($opts{$name} == int($opts{$name})) {
+ $class->_set_error("check_file_limits: $name must be a positive integer");
+ return;
+ }
+ }
+
+ my $result = i_int_check_image_file_limits(@opts{@check_args});
+ unless ($result) {
+ $class->_set_error($class->_error_as_msg());
+ }
+
+ return $result;
+}
+
# Shortcuts that can be exported
sub newcolor { Imager::Color->new(@_); }
L<Imager::ExtUtils> - tools to get access to Imager's C API.
+=item *
+
+L<Imager::Security> - brief security notes.
+
=back
=head2 Basic Overview
box() - L<Imager::Draw/box()> - draw a filled or outline box.
+check_file_limits() - L<Imager::Files/check_file_limits()>
+
circle() - L<Imager::Draw/circle()> - draw a filled circle
close_log() - L<Imager::ImageTypes/close_log()> - close the Imager
getcolorusagehash() - L<Imager::ImageTypes/getcolorusagehash()>
-get_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
+get_file_limits() - L<Imager::Files/get_file_limits()>
getheight() - L<Imager::ImageTypes/getheight()> - height of the image in
pixels
make_palette() - L<Imager::ImageTypes/make_palette()> - produce a
color palette from one or more input images.
-map() - L<Imager::Transformations/"Color Mappings"> - remap color
+map() - L<Imager::Transformations/map()> - remap color
channel values
masked() - L<Imager::ImageTypes/masked()> - make a masked image
NF() - L<Imager::Handy/NF()>
-open() - L<Imager::Files> - an alias for read()
+open() - L<Imager::Files/read()> - an alias for read()
open_log() - L<Imager::ImageTypes/open_log()> - open the debug log.
setcolors() - L<Imager::ImageTypes/setcolors()> - set palette colors
in a paletted image
-set_file_limits() - L<Imager::Files/"Limiting the sizes of images you read">
+set_file_limits() - L<Imager::Files/set_file_limits()>
setmask() - L<Imager::ImageTypes/setmask()>
scaling - L<Imager::Transformations/scale()>
+security - L<Imager::Security>
+
SGI files - L<Imager::Files/"SGI (RGB, BW)">
sharpen - L<Imager::Filters/unsharpmask>, L<Imager::Filters/conv>