view release on metacpan or search on metacpan
Changes.old view on Meta::CPAN
reading a gif file will now read the first image from the file rather
than the a consolidated image. If you want the old behaviour supply
C<< gif_consolidate=>1 >> to the read() method. Older versions of
Imager will accept this parameter and produce the same result.
- you can now supply a page parameter to read() to read a given page
from a GIF file.
- reading a multi-image GIF was leaking memory (a line buffer per file)
- maxcolors now must be at least 1 when creating a paletted image.
- converted t/t022double.t to use Test::More
- t1 library re-initialization modified to support T1Lib 5.1.0
- setmask() now returns true on success and reports a missing mask
parameter.
- double per sample images were ignoring the channel mask.
- converted t/t021sixteen.t to use Test::More
- 16-bit per sample images were ignoring the channel mask
- added t/t91pod.t
- expand Imager::ImageTypes:
- make all methods into =items
- document parameters
- more examples
- add AUTHOR/REVISION/SEE ALSO
unload_plugin
i_list_formats
i_color_new
i_color_set
i_color_info
i_img_info
i_img_setmask
i_img_getmask
i_line
i_line_aa
i_box
i_box_filled
i_arc
i_circle_aa
i_bezier_multi
my $self = shift;
$self->_valid_image("getmask")
or return;
return i_img_getmask($self->{IMG});
}
# Set channel mask
sub setmask {
my $self = shift;
my %opts = @_;
warnings::warnif("Imager::channelmask", "setmask: image channel masks are deprecated")
if $] >= 5.014;
$self->_valid_image("setmask")
or return;
unless (defined $opts{mask}) {
$self->_set_error("mask parameter required");
return;
}
i_img_setmask( $self->{IMG} , $opts{mask} );
1;
}
# Get number of colors in an image
sub getcolorcount {
my $self=shift;
my %opts=('maxcolors'=>2**30,@_);
scaleX() - L<Imager::Transformations/scaleX()>
scaleY() - L<Imager::Transformations/scaleY()>
setcolors() - L<Imager::ImageTypes/setcolors()> - set palette colors
in a paletted image
set_file_limits() - L<Imager::Files/set_file_limits()>
setmask() - L<Imager::ImageTypes/setmask()>
setpixel() - L<Imager::Draw/setpixel()>
setsamples() - L<Imager::Draw/setsamples()>
setscanline() - L<Imager::Draw/setscanline()>
settag() - L<Imager::ImageTypes/settag()>
string() - L<Imager::Draw/string()> - draw text on an image
EXTEND(SP, 4);
PUSHs(sv_2mortal(newSViv(info[0])));
PUSHs(sv_2mortal(newSViv(info[1])));
PUSHs(sv_2mortal(newSViv(info[2])));
PUSHs(sv_2mortal(newSViv(info[3])));
void
i_img_setmask(im,ch_mask)
Imager::ImgRaw im
int ch_mask
int
i_img_getmask(im)
Imager::ImgRaw im
int
i_img_getchannels(im)
Imager::ImgRaw im
SGI/imsgi.c view on Meta::CPAN
int pixmin = header->pixmin;
int pixmax = header->pixmax;
int outmax = pixmax - pixmin;
linebuf = mymalloc(width * sizeof(i_color)); /* checked 31Jul07 TonyC */
databuf = mymalloc(width); /* checked 31Jul07 TonyC */
savemask = i_img_getmask(img);
for(c = 0; c < channels; c++) {
i_img_setmask(img, 1<<c);
for(y = 0; y < height; y++) {
int x;
if (i_io_read(ig, databuf, width) != width) {
i_push_error(0, "SGI image: cannot read image data");
i_img_destroy(img);
myfree(linebuf);
myfree(databuf);
return NULL;
}
SGI/imsgi.c view on Meta::CPAN
else
sample -= pixmin;
linebuf[x].channel[c] = sample * 255 / outmax;
}
}
i_plin(img, 0, width, height-1-y, linebuf);
}
}
i_img_setmask(img, savemask);
myfree(linebuf);
myfree(databuf);
return img;
}
static int
read_rle_tables(io_glue *ig, i_img *img,
unsigned long **pstart_tab, unsigned long **plength_tab,
SGI/imsgi.c view on Meta::CPAN
int pixmin = header->pixmin;
int pixmax = header->pixmax;
int outmax = pixmax - pixmin;
linebuf = mymalloc(width * sizeof(i_fcolor)); /* checked 31Jul07 TonyC */
databuf = mymalloc(width * 2); /* checked 31Jul07 TonyC */
savemask = i_img_getmask(img);
for(c = 0; c < channels; c++) {
i_img_setmask(img, 1<<c);
for(y = 0; y < height; y++) {
int x;
if (i_io_read(ig, databuf, width*2) != width*2) {
i_push_error(0, "SGI image: cannot read image data");
i_img_destroy(img);
myfree(linebuf);
myfree(databuf);
return NULL;
}
SGI/imsgi.c view on Meta::CPAN
else
sample -= pixmin;
linebuf[x].channel[c] = (double)sample / outmax;
}
}
i_plinf(img, 0, width, height-1-y, linebuf);
}
}
i_img_setmask(img, savemask);
myfree(linebuf);
myfree(databuf);
return img;
}
static i_img *
read_rgb_16_rle(i_img *img, io_glue *ig, rgb_header const *header) {
i_fcolor *linebuf = NULL;
static symbol_table_t symbol_table=
{
i_has_format,
ICL_set_internal,
ICL_info,
do_get_context,
im_img_empty_ch,
i_img_exorcise,
i_img_info,
i_img_setmask,
i_img_getmask,
i_box,
i_line,
i_arc,
i_copyto,
i_copyto_trans,
i_rubthru
};
undef_int (*i_has_format)(char *frmt);
i_color*(*ICL_set)(i_color *cl,unsigned char r,unsigned char g,unsigned char b,unsigned char a);
void (*ICL_info)(const i_color *cl);
im_context_t (*im_get_context_f)(void);
i_img*(*im_img_empty_ch_f)(im_context_t, i_img *im,i_img_dim x,i_img_dim y,int ch);
void(*i_img_exorcise_f)(i_img *im);
void(*i_img_info_f)(i_img *im,i_img_dim *info);
void(*i_img_setmask_f)(i_img *im,int ch_mask);
int (*i_img_getmask_f)(i_img *im);
/*
int (*i_ppix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
int (*i_gpix)(i_img *im,i_img_dim x,i_img_dim y,i_color *val);
*/
void(*i_box)(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val);
void(*i_line)(i_img *im,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,const i_color *val,int endp);
void(*i_arc)(i_img *im,i_img_dim x,i_img_dim y,double rad,double d1,double d2,const i_color *val);
void(*i_copyto)(i_img *im,i_img *src,i_img_dim x1,i_img_dim y1,i_img_dim x2,i_img_dim y2,i_img_dim tx,i_img_dim ty);
"mask=%ud\n",
i_DFc(im->xsize), i_DFc(im->ysize), im->channels,im->ch_mask));
im_log((aIMCTX,1,"i_img_info: idata=%p\n",im->idata));
info[0] = im->xsize;
info[1] = im->ysize;
info[2] = im->channels;
info[3] = im->ch_mask;
}
/*
=item i_img_setmask(C<im>, C<ch_mask>)
=category Image Information
=synopsis // only channel 0 writable
=synopsis i_img_setmask(img, 0x01);
Set the image channel mask for C<im> to C<ch_mask>.
The image channel mask gives some control over which channels can be
written to in the image.
=cut
*/
void
i_img_setmask(i_img *im,int ch_mask) { im->ch_mask=ch_mask; }
/*
=item i_img_getmask(C<im>)
=category Image Information
=synopsis int mask = i_img_getmask(img);
Get the image channel mask for C<im>.
=cut
i_img *im_img_alloc(pIMCTX);
void im_img_init(pIMCTX, i_img *im);
void i_img_info(i_img *im,i_img_dim *info);
extern i_img *i_sametype(i_img *im, i_img_dim xsize, i_img_dim ysize);
extern i_img *i_sametype_chans(i_img *im, i_img_dim xsize, i_img_dim ysize, int channels);
/* Image feature settings */
void i_img_setmask (i_img *im,int ch_mask);
int i_img_getmask (i_img *im);
int i_img_getchannels(i_img *im);
i_img_dim i_img_get_width(i_img *im);
i_img_dim i_img_get_height(i_img *im);
i_color_model_t i_img_color_model(i_img *im);
int i_img_alpha_channel(i_img *im, int *channel);
int i_img_color_channels(i_img *im);
/* Base functions */
/* IMAGER_API_LEVEL 2 functions */
mathom_i_set_image_file_limits,
mathom_i_get_image_file_limits,
mathom_i_int_check_image_file_limits,
i_flood_fill_border,
i_flood_cfill_border,
/* IMAGER_API_LEVEL 3 functions */
i_img_setmask,
i_img_getmask,
i_img_getchannels,
i_img_get_width,
i_img_get_height,
i_lhead,
i_loog,
/* IMAGER_API_LEVEL 4 functions */
mathom_i_img_alloc,
mathom_i_img_init,
#define i_rubthru(im, src, tx, ty, src_minx, src_miny, src_maxx, src_maxy) \
((im_extt->f_i_rubthru)((im), (src), (tx), (ty), (src_minx), (src_miny), (src_maxx), (src_maxy)))
#define im_set_image_file_limits(ctx, max_width, max_height, max_bytes) \
((im_extt->f_im_set_image_file_limits)((max_width), (max_height), (max_bytes)))
#define im_get_image_file_limits(ctx, pmax_width, pmax_height, pmax_bytes) \
((im_extt->f_im_get_image_file_limits)((ctx), (pmax_width), (pmax_height), (pmax_bytes)))
#define im_int_check_image_file_limits(ctx, width, height, channels, sample_size) \
((im_extt->f_im_int_check_image_file_limits)((ctx), (width), (height), (channels), (sample_size)))
#define i_img_setmask(img, mask) ((im_extt->f_i_img_setmask)((img), (mask)))
#define i_img_getmask(img) ((im_extt->f_i_img_getmask)(img))
#define i_img_getchannels(img) ((im_extt->f_i_img_getchannels)(img))
#define i_img_get_width(img) ((im_extt->f_i_img_get_width)(img))
#define i_img_get_height(img) ((im_extt->f_i_img_get_height)(img))
#define i_lhead(file, line) ((im_extt->f_i_lhead)((file), (line)))
#define i_loog (im_extt->f_i_loog)
#define im_lhead(ctx, file, line) ((im_extt->f_im_lhead)((ctx), (file), (line)))
#define im_loog (im_extt->f_im_loog)
#define im_img_alloc(ctx) ((im_extt->f_im_img_alloc)(ctx))
imexttypes.h view on Meta::CPAN
int (*f_i_rubthru)(i_img *im, i_img *src, i_img_dim tx, i_img_dim ty, i_img_dim src_minx, i_img_dim src_miny, i_img_dim src_maxx, i_img_dim src_maxy);
/* IMAGER_API_LEVEL 2 functions */
int (*f_i_set_image_file_limits)(i_img_dim width, i_img_dim height, size_t bytes); /* SKIP */
int (*f_i_get_image_file_limits)(i_img_dim *width, i_img_dim *height, size_t *bytes); /* SKIP */
int (*f_i_int_check_image_file_limits)(i_img_dim width, i_img_dim height, int channels, size_t sample_size); /* SKIP */
int (*f_i_flood_fill_border)(i_img *im, i_img_dim seedx, i_img_dim seedy, const i_color *dcol, const i_color *border);
int (*f_i_flood_cfill_border)(i_img *im, i_img_dim seedx, i_img_dim seedy, i_fill_t *fill, const i_color *border);
/* IMAGER_API_LEVEL 3 functions */
void (*f_i_img_setmask)(i_img *im, int ch_mask);
int (*f_i_img_getmask)(i_img *im);
int (*f_i_img_getchannels)(i_img *im);
i_img_dim (*f_i_img_get_width)(i_img *im);
i_img_dim (*f_i_img_get_height)(i_img *im);
void (*f_i_lhead)(const char *file, int line_number);
void (*f_i_loog)(int level, const char *msg, ...) I_FORMAT_ATTR(2,3);
/* IMAGER_API_LEVEL 4 functions will be added here */
i_img *(*f_i_img_alloc)(void); /* SKIP */
void (*f_i_img_init)(i_img *); /* SKIP */
lib/Imager/APIRef.pod view on Meta::CPAN
i_img_destroy(img)
# Image Implementation
i_img *im = im_img_alloc(aIMCTX);
i_img *im = i_img_alloc();
im_img_init(aIMCTX, im);
i_img_init(im);
# Image Information
// only channel 0 writable
i_img_setmask(img, 0x01);
int mask = i_img_getmask(img);
int channels = i_img_getchannels(img);
i_img_dim width = i_img_get_width(im);
i_img_dim height = i_img_get_height(im);
i_color_model_t cm = i_img_color_model(im);
int alpha_channel;
int has_alpha = i_img_alpha_channel(im, &alpha_channel);
int color_channels = i_img_color_channels(im);
# Image quantization
lib/Imager/APIRef.pod view on Meta::CPAN
C<(255,255,255)> in either order.
=back
C<zero_is_white> is set to non-zero if the first palette entry is white.
=for comment
From: File image.c
=item i_img_setmask(C<im>, C<ch_mask>)
// only channel 0 writable
i_img_setmask(img, 0x01);
Set the image channel mask for C<im> to C<ch_mask>.
The image channel mask gives some control over which channels can be
written to in the image.
=for comment
From: File image.c
lib/Imager/ImageTypes.pod view on Meta::CPAN
=for stopwords th
C<getmask()> is used to fetch the current channel mask. The mask
determines what channels are currently modifiable in the image. The
channel mask is an integer value, if the C<i-th> least significant bit
is set the C<i-th> channel is modifiable. eg. a channel mask of 0x5
means only channels 0 and 2 are writable.
Channel masks are deprecated.
=item setmask()
$mask = $img->getmask();
$img->setmask(mask=>8); # modify alpha only
...
$img->setmask(mask=>$mask); # restore previous mask
C<setmask()> is used to set the channel mask of the image. See
L</getmask()> for details.
Channel masks are deprecated.
=back
=head2 Palette Type Images
Paletted images keep an array of up to 256 colors, and each pixel is
stored as an index into that array.
lib/Imager/Test.pm view on Meta::CPAN
# set mask to skip a channel, set to grey
# make sure only the right channels set
print "# channel mask tests\n";
# 8-bit color tests
my $white = Imager::NC(255, 255, 255);
my $grey = Imager::NC(128, 128, 128);
my $white_grey = Imager::NC(128, 255, 128);
print "# with ppix\n";
$builder->ok($im->setmask(mask=>~0), "set to default mask");
$builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$white), "set to white all channels");
test_color_gpix($im->{IMG}, 0, 0, $white, "ppix");
$builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
$builder->ok($im->setpixel(x=>0, 'y'=>0, color=>$grey), "set to grey, no channel 2");
test_color_gpix($im->{IMG}, 0, 0, $white_grey, "ppix masked");
print "# with plin\n";
$builder->ok($im->setmask(mask=>~0), "set to default mask");
$builder->ok($im->setscanline(x=>0, 'y'=>1, pixels => [$white]),
"set to white all channels");
test_color_gpix($im->{IMG}, 0, 1, $white, "plin");
$builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
$builder->ok($im->setscanline(x=>0, 'y'=>1, pixels=>[$grey]),
"set to grey, no channel 2");
test_color_gpix($im->{IMG}, 0, 1, $white_grey, "plin masked");
# float color tests
my $whitef = Imager::NCF(1.0, 1.0, 1.0);
my $greyf = Imager::NCF(0.5, 0.5, 0.5);
my $white_greyf = Imager::NCF(0.5, 1.0, 0.5);
print "# with ppixf\n";
$builder->ok($im->setmask(mask=>~0), "set to default mask");
$builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$whitef), "set to white all channels");
test_colorf_gpix($im->{IMG}, 0, 2, $whitef, $epsilon, "ppixf");
$builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
$builder->ok($im->setpixel(x=>0, 'y'=>2, color=>$greyf), "set to grey, no channel 2");
test_colorf_gpix($im->{IMG}, 0, 2, $white_greyf, $epsilon, "ppixf masked");
print "# with plinf\n";
$builder->ok($im->setmask(mask=>~0), "set to default mask");
$builder->ok($im->setscanline(x=>0, 'y'=>3, pixels => [$whitef]),
"set to white all channels");
test_colorf_gpix($im->{IMG}, 0, 3, $whitef, $epsilon, "plinf");
$builder->ok($im->setmask(mask=>0xF-0x2), "set channel to exclude channel1");
$builder->ok($im->setscanline(x=>0, 'y'=>3, pixels=>[$greyf]),
"set to grey, no channel 2");
test_colorf_gpix($im->{IMG}, 0, 3, $white_greyf, $epsilon, "plinf masked");
}
sub std_font_test_count {
return 21;
}
#define getOBJ(k,t,s) (util_table->getobj(INP,k,t,(void**)s))
#define i_color_set(cl,r,g,b,a) (symbol_table->i_color_set(cl,r,g,b,a))
#define i_color_info(cl) (symbol_table->i_color_info(cl))
#define im_get_context() (symbol_table->im_get_context_f())
#define i_img_empty_ch(im,x,y,ch) ((symbol_table->i_img_empty_ch_f(im_get_context(), im,x,y,ch))
#define i_img_exorcise(im) (symbol_table->i_img_exorcise_f(im))
#define i_img_info(im,info) (symbol_table->i_img_info_f(im,info))
#define i_img_setmask(im,ch_mask) (symbol_table->i_img_setmask_f(im,ch_mask))
#define i_img_getmask(im) (symbol_table->i_img_getmask_f(im))
/*
Not needed? The i_gpix() macro in image.h will call the right function
directly.
#define i_ppix(im,x,y,val) (symbol_table->i_ppix(im,x,y,val))
#define i_gpix(im,x,y,val) (symbol_table->i_gpix(im,x,y,val))
*/
#define i_box(im, x1, y1, x2, y2,val) (symbol_table->i_box(im, x1, y1, x2, y2,val))
t/100-base/010-introvert.t view on Meta::CPAN
is($im->getwidth, undef, "can't get width of empty image");
is($im->errstr, "getwidth: empty input image", "check message");
is($im->getheight, undef, "can't get height of empty image");
is($im->errstr, "getheight: empty input image", "check message");
is($im->getchannels, undef, "can't get channels of empty image");
is($im->errstr, "getchannels: empty input image", "check message");
is($im->getmask, undef, "can't get mask of empty image");
is($im->errstr, "getmask: empty input image", "check message");
{
no if $] >= 5.014, warnings => 'Imager::channelmask';
is($im->setmask, undef, "can't set mask of empty image");
is($im->errstr, "setmask: empty input image", "check message");
}
is($im->colorchannels, undef, "can't get colorchannels of empty image");
is($im->errstr, "colorchannels: empty input image", "check message");
is($im->alphachannel, undef, "can't get alphachannel of empty image");
is($im->errstr, "alphachannel: empty input image", "check message");
is($im->colormodel, undef, "can't get colormodel of empty image");
is($im->errstr, "colormodel: empty input image", "check message");
}
{ # basic checks, 8-bit direct images
t/100-base/010-introvert.t view on Meta::CPAN
my $psamp_outside_error = "Image position outside of image";
{ # psamp
print "# psamp\n";
my $imraw = Imager::ImgRaw::new(10, 20, 3);
{
is(Imager::i_psamp($imraw, 0, 2, undef, [ 255, 128, 64 ]), 3,
"i_psamp def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psamp($imraw, 1, 3, undef, [ 64, 128, 192 ]), 3,
"i_psamp def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 192,
"check color written");
is(Imager::i_psamp($imraw, 1, 7, [ 0, 1, 2 ], [ 64, 128, 192 ]), 3,
"i_psamp channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 192,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psamp($imraw, 2, 4, [ 0, 1 ], [ 255, 128, 64, 32 ]), 4,
"i_psamp channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psamp($imraw, 0, 5, [ 0, 1, 2 ], [ (128, 63, 32) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 63, 32) x 10 ],
t/100-base/010-introvert.t view on Meta::CPAN
}
{ # psampf
print "# psampf\n";
my $imraw = Imager::ImgRaw::new(10, 20, 3);
{
is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
"i_psampf def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
"check color written");
is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
"i_psampf channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 64, 32) x 10 ],
t/100-base/010-introvert.t view on Meta::CPAN
like($warn[0], qr/addtag: code parameter is deprecated/,
"check message for addtag");
@warn = ();
{
no if $] >= 5.014, warnings => 'Imager::tagcodes';
$im->addtag(code => 12, value => 12);
}
is(scalar @warn, 0, "addtag with code with warning disabled doesn't warn");
# setmask
@warn = ();
$im->setmask(mask => 0xFF);
is(scalar @warn, 1, "warned on setmask");
like($warn[0], qr/setmask: image channel masks are deprecated/,
"check setmask warning message");
@warn = ();
{
no if $] >= 5.014, warnings => 'Imager::channelmask';
$im->setmask(mask => 0xFF);
}
is(scalar @warn, 0, "setmask with warning disabled doesn't warn");
}
{
my @tests =
(
[ "gray", 1, undef ],
[ "graya", 1, 1 ],
[ "rgb", 3, undef ],
[ "rgba", 3, 3 ],
);
t/150-type/020-sixteen.t view on Meta::CPAN
my $psamp_outside_error = "Image position outside of image";
{ # psamp
print "# psamp\n";
my $imraw = Imager::i_img_16_new(10, 10, 3);
{
is(Imager::i_psamp($imraw, 0, 2, undef, [ 255, 128, 64 ]), 3,
"i_psamp def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psamp($imraw, 1, 3, undef, [ 64, 128, 192 ]), 3,
"i_psamp def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 192,
"check color written");
is(Imager::i_psamp($imraw, 1, 7, [ 0, 1, 2 ], [ 64, 128, 192 ]), 3,
"i_psamp channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 192,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psamp($imraw, 2, 4, [ 0, 1 ], [ 255, 128, 64, 32 ]), 4,
"i_psamp channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psamp($imraw, 0, 5, [ 0, 1, 2 ], [ (128, 63, 32) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 63, 32) x 10 ],
t/150-type/020-sixteen.t view on Meta::CPAN
}
{ # psampf
print "# psampf\n";
my $imraw = Imager::i_img_16_new(10, 10, 3);
{
is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
"i_psampf def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 127, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
"check color written");
is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
"i_psampf channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 127, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (127, 64, 32) x 10 ],
t/150-type/030-double.t view on Meta::CPAN
my $psamp_outside_error = "Image position outside of image";
{ # psamp
print "# psamp\n";
my $imraw = Imager::i_img_double_new(10, 10, 3);
{
is(Imager::i_psamp($imraw, 0, 2, undef, [ 255, 128, 64 ]), 3,
"i_psamp def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psamp($imraw, 1, 3, undef, [ 64, 128, 192 ]), 3,
"i_psamp def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 192,
"check color written");
is(Imager::i_psamp($imraw, 1, 7, [ 0, 1, 2 ], [ 64, 128, 192 ]), 3,
"i_psamp channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 192,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psamp($imraw, 2, 4, [ 0, 1 ], [ 255, 128, 64, 32 ]), 4,
"i_psamp channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psamp($imraw, 0, 5, [ 0, 1, 2 ], [ (128, 63, 32) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 63, 32) x 10 ],
t/150-type/030-double.t view on Meta::CPAN
}
{ # psampf
print "# psampf\n";
my $imraw = Imager::i_img_double_new(10, 10, 3);
{
is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
"i_psampf def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
"check color written");
is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
"i_psampf channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 64, 32) x 10 ],
t/150-type/040-palette.t view on Meta::CPAN
NC(64, 0, 192), NC(255, 128, 0), NC(64, 32, 0),
NC(128, 63, 32), NC(255, 128, 32), NC(64, 32, 16),
);
is(Imager::i_addcolors($imraw, @colors), "0 but true",
"add colors needed for testing");
{
is(Imager::i_psamp($imraw, 0, 2, undef, [ 255, 128, 64 ]), 3,
"i_psamp def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psamp($imraw, 1, 3, undef, [ 64, 128, 192 ]), 3,
"i_psamp def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 192,
"check color written");
is(Imager::i_psamp($imraw, 1, 7, [ 0, 1, 2 ], [ 64, 128, 192 ]), 3,
"i_psamp channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 192,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psamp($imraw, 2, 4, [ 0, 1 ], [ 255, 128, 64, 32 ]), 4,
"i_psamp channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psamp($imraw, 0, 5, [ 0, 1, 2 ], [ (128, 63, 32) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 63, 32) x 10 ],
t/150-type/040-palette.t view on Meta::CPAN
NC(64, 0, 191), NC(255, 128, 0), NC(64, 32, 0),
NC(128, 64, 32), NC(255, 128, 32), NC(64, 32, 16),
);
is(Imager::i_addcolors($imraw, @colors), "0 but true",
"add colors needed for testing");
{
is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
"i_psampf def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
"check color written");
is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
"i_psampf channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 64, 32) x 10 ],
t/150-type/100-masked.t view on Meta::CPAN
my $mask;
if ($masked) {
$mask = $full_mask->{IMG};
}
my $imraw = Imager::i_img_masked_new($imback, $mask, 3, 4, 10, 10);
{
is(Imager::i_psamp($imraw, 0, 2, undef, [ 255, 128, 64 ]), 3,
"i_psamp def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psamp($imraw, 1, 3, undef, [ 64, 128, 192 ]), 3,
"i_psamp def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 192,
"check color written");
is(Imager::i_psamp($imraw, 1, 7, [ 0, 1, 2 ], [ 64, 128, 192 ]), 3,
"i_psamp channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 192,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psamp($imraw, 2, 4, [ 0, 1 ], [ 255, 128, 64, 32 ]), 4,
"i_psamp channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psamp($imraw, 0, 5, [ 0, 1, 2 ], [ (128, 63, 32) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 63, 32) x 10 ],
t/150-type/100-masked.t view on Meta::CPAN
my $mask;
if ($masked) {
$mask = $full_mask->{IMG};
}
my $imraw = Imager::i_img_masked_new($imback, $mask, 3, 4, 10, 10);
{
is(Imager::i_psampf($imraw, 0, 2, undef, [ 1, 0.5, 0.25 ]), 3,
"i_psampf def channels, 3 samples");
is_color3(Imager::i_get_pixel($imraw, 0, 2), 255, 128, 64,
"check color written");
Imager::i_img_setmask($imraw, 5);
is(Imager::i_psampf($imraw, 1, 3, undef, [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf def channels, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 3), 64, 0, 191,
"check color written");
is(Imager::i_psampf($imraw, 1, 7, [ 0, 1, 2 ], [ 0.25, 0.5, 0.75 ]), 3,
"i_psampf channels listed, 3 samples, masked");
is_color3(Imager::i_get_pixel($imraw, 1, 7), 64, 0, 191,
"check color written");
Imager::i_img_setmask($imraw, ~0);
is(Imager::i_psampf($imraw, 2, 4, [ 0, 1 ], [ 1, 0.5, 0.25, 0.125 ]), 4,
"i_psampf channels [0, 1], 4 samples");
is_color3(Imager::i_get_pixel($imraw, 2, 4), 255, 128, 0,
"check first color written");
is_color3(Imager::i_get_pixel($imraw, 3, 4), 64, 32, 0,
"check second color written");
is(Imager::i_psampf($imraw, 0, 5, [ 0, 1, 2 ], [ (0.5, 0.25, 0.125) x 10 ]), 30,
"write a full row");
is_deeply([ Imager::i_gsamp($imraw, 0, 10, 5, [ 0, 1, 2 ]) ],
[ (128, 64, 32) x 10 ],
t/300-transform/060-map.t view on Meta::CPAN
my $out = $im->map(maps => [ \@map, \@map, \@map ]);
ok($out, "map()");
is_image($out, $cmp, "test map output");
}
{
# test with zero mask: coverity detected a bad channel index problem
# that only applies in this case
no if $] >= 5.014, warnings => 'Imager::channelmask';
my $im = test_image();
$im->setmask(mask => 0x80);
is($im->getmask, 0x80, "check we set mask");
my @map = ( map int $_ / 2, 0 .. 255 );
my $out = $im->map(maps => [ (undef) x 3 ]);
ok($out, "map done");
}
{ # CID 185300
# the check for whether a map() channel was used was incorrect
my @map1 = ( 0 .. 255 );
my $im = test_image;