return $result;
}
+# convert a paletted (or any image) to an 8-bit/channel RGB images
+sub to_rgb16 {
+ my $self = shift;
+ my $result;
+
+ unless (defined wantarray) {
+ my @caller = caller;
+ warn "to_rgb16() called in void context - to_rgb8() returns the converted image at $caller[1] line $caller[2]\n";
+ return;
+ }
+
+ if ($self->{IMG}) {
+ $result = Imager->new;
+ $result->{IMG} = i_img_to_rgb16($self->{IMG})
+ or undef $result;
+ }
+
+ return $result;
+}
+
sub addcolors {
my $self = shift;
my %opts = (colors=>[], @_);
if (ref $x && ref $y) {
unless (@$x == @$y) {
$self->{ERRSTR} = 'length of x and y mismatch';
- return undef;
+ return;
}
+ my $set = 0;
if ($color->isa('Imager::Color')) {
for my $i (0..$#{$opts{'x'}}) {
- i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color);
+ i_ppix($self->{IMG}, $x->[$i], $y->[$i], $color)
+ or ++$set;
}
}
else {
for my $i (0..$#{$opts{'x'}}) {
- i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color);
+ i_ppixf($self->{IMG}, $x->[$i], $y->[$i], $color)
+ or ++$set;
}
}
+ $set or return;
+ return $set;
}
else {
if ($color->isa('Imager::Color')) {
- i_ppix($self->{IMG}, $x, $y, $color);
+ i_ppix($self->{IMG}, $x, $y, $color)
+ and return;
}
else {
- i_ppixf($self->{IMG}, $x, $y, $color);
+ i_ppixf($self->{IMG}, $x, $y, $color)
+ and return;
}
}
static int i_ppix_d16(i_img *im, int x, int y, const i_color *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_gpix_d16(i_img *im, int x, int y, i_color *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_ppixf_d16(i_img *im, int x, int y, const i_fcolor *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_gpixf_d16(i_img *im, int x, int y, i_fcolor *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_ppix_ddoub(i_img *im, int x, int y, const i_color *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_gpix_ddoub(i_img *im, int x, int y, i_color *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_ppixf_ddoub(i_img *im, int x, int y, const i_fcolor *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
static int i_gpixf_ddoub(i_img *im, int x, int y, i_fcolor *val) {
int off, ch;
- if (x < 0 || x >= im->xsize || y < 0 || y > im->ysize)
+ if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize)
return -1;
off = (x + y * im->xsize) * im->channels;
require Exporter;
use vars qw(@ISA @EXPORT_OK);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(diff_text_with_nul test_image_raw test_image_16 test_image is_color3 is_color1 is_image is_image_similar);
+@EXPORT_OK = qw(diff_text_with_nul test_image_raw test_image_16 test_image is_color3 is_color1 is_image is_image_similar image_bounds_checks);
sub diff_text_with_nul {
my ($desc, $text1, $text2, @params) = @_;
return is_image_similar($left, $right, 0, $comment);
}
+sub image_bounds_checks {
+ my $im = shift;
+
+ my $builder = Test::Builder->new;
+
+ $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0)');
+ $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0)');
+ $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1)');
+ $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10)');
+ $builder->ok(!$im->getpixel(x => -1, y => 0), 'bounds check get (-1, 0) float');
+ $builder->ok(!$im->getpixel(x => 10, y => 0), 'bounds check get (10, 0) float');
+ $builder->ok(!$im->getpixel(x => 0, y => -1), 'bounds check get (0, -1) float');
+ $builder->ok(!$im->getpixel(x => 0, y => 10), 'bounds check get (0, 10) float');
+ my $black = Imager::Color->new(0, 0, 0);
+ require Imager::Color::Float;
+ my $blackf = Imager::Color::Float->new(0, 0, 0);
+ $builder->ok(!$im->setpixel(x => -1, y => 0, color => $black), 'bounds check set (-1, 0)');
+ $builder->ok(!$im->setpixel(x => 10, y => 0, color => $black), 'bounds check set (10, 0)');
+ $builder->ok(!$im->setpixel(x => 0, y => -1, color => $black), 'bounds check set (0, -1)');
+ $builder->ok(!$im->setpixel(x => 0, y => 10, color => $black), 'bounds check set (0, 10)');
+ $builder->ok(!$im->setpixel(x => -1, y => 0, color => $blackf), 'bounds check set (-1, 0) float');
+ $builder->ok(!$im->setpixel(x => 10, y => 0, color => $blackf), 'bounds check set (10, 0) float');
+ $builder->ok(!$im->setpixel(x => 0, y => -1, color => $blackf), 'bounds check set (0, -1) float');
+ $builder->ok(!$im->setpixel(x => 0, y => 10, color => $blackf), 'bounds check set (0, 10) float');
+}
1;
# to make sure we get expected values
use strict;
-use Test::More tests=>196;
+use Test::More tests => 212;
BEGIN { use_ok(Imager => qw(:handy :all)) }
require "t/testtools.pl";
+use Imager::Test qw(image_bounds_checks);
+
init_log("testout/t01introvert.log",1);
my $im_g = Imager::ImgRaw::new(100, 101, 1);
mask_tests($im, 0.005);
}
+{ # check bounds checking
+ my $im = Imager->new(xsize => 10, ysize => 10);
+
+ image_bounds_checks($im);
+}
+
sub check_add {
my ($im, $color, $expected) = @_;
my $index = Imager::i_addcolors($im, $color);
#!perl -w
use strict;
-use Test::More tests => 87;
+use Test::More tests => 103;
BEGIN { use_ok(Imager=>qw(:all :handy)) }
require "t/testtools.pl";
use Imager::Color::Float;
-use Imager::Test qw(test_image is_image);
+use Imager::Test qw(test_image is_image image_bounds_checks);
my $im_g = Imager::i_img_16_new(100, 101, 1);
is($im16->bits, 16, "check bits");
is_image($im, $im16, "check image data matches");
}
+
+{ # bounds checks
+ my $im = Imager->new(xsize => 10, ysize => 10, bits => 16);
+ image_bounds_checks($im);
+}
#!perl -w
use strict;
-use Test::More tests => 81;
+use Test::More tests => 97;
BEGIN { use_ok(Imager => qw(:all :handy)) }
require "t/testtools.pl";
init_log("testout/t022double.log", 1);
+use Imager::Test qw(image_bounds_checks);
+
use Imager::Color::Float;
my $im_g = Imager::i_img_double_new(100, 101, 1);
mask_tests($im);
}
-
+{ # bounds checking
+ my $im = Imager->new(xsize => 10, ysize=>10, bits=>'double');
+ image_bounds_checks($im);
+}
#!perl -w
# some of this is tested in t01introvert.t too
use strict;
-use Test::More tests => 90;
+use Test::More tests => 107;
BEGIN { use_ok("Imager"); }
+use Imager::Test qw(image_bounds_checks);
+
sub isbin($$$);
my $img = Imager->new(xsize=>50, ysize=>50, type=>'paletted');
is($pixels[2], 0, "check black pixel");
}
+{ # check bounds checking
+ my $im = Imager->new(xsize => 10, ysize => 10, type=>'paletted');
+ ok($im->addcolors(colors => [ $black ]), "add color of pixel bounds check writes");
+
+ image_bounds_checks($im);
+}
+
sub iscolor {
my ($c1, $c2, $msg) = @_;