From af3c245023f33e40cf904a5e4f20886ea6f1f8dd Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 11 Oct 2001 09:52:16 +0000 Subject: [PATCH 1/1] some fixes to double/sample image support make $img->bits return "double" for double/sample images --- Changes | 1 + Imager.pm | 9 +++++++-- image.c | 16 +++++++++++++--- t/t022double.t | 14 ++++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Changes b/Changes index 420acd9b..69abf5bf 100644 --- a/Changes +++ b/Changes @@ -523,6 +523,7 @@ Revision history for Perl extension Imager. - Added tga.c to read targa images - Added i_bumpmap_complex to do more accurate bumpmapping - added an image type with doubles as samples + - change i_copy() and i_sametype() to handle double/sample images ================================================================= diff --git a/Imager.pm b/Imager.pm index a6231c71..1b811676 100644 --- a/Imager.pm +++ b/Imager.pm @@ -686,7 +686,11 @@ sub findcolor { sub bits { my $self = shift; - $self->{IMG} and i_img_bits($self->{IMG}); + my $bits = $self->{IMG} && i_img_bits($self->{IMG}); + if ($bits && $bits == length(pack("d", 1)) * 8) { + $bits = 'double'; + } + $bits; } sub type { @@ -2807,7 +2811,8 @@ the function return undef. Examples: } The bits() method retrieves the number of bits used to represent each -channel in a pixel, typically 8. The type() method returns either +channel in a pixel, 8 for a normal image, 16 for 16-bit image and +'double' for a double/channel image. The type() method returns either 'direct' for truecolor images or 'paletted' for paletted images. The virtual() method returns non-zero if the image contains no actual pixels, for example masked images. diff --git a/image.c b/image.c index 8b5bf760..d4c3f6f4 100644 --- a/image.c +++ b/image.c @@ -647,9 +647,16 @@ i_copy(i_img *im, i_img *src) { myfree(pv); } else { - /* currently the only other depth is 16 */ i_fcolor *pv; - i_img_16_new_low(im, x1, y1, src->channels); + if (src->bits == i_16_bits) + i_img_16_new_low(im, x1, y1, src->channels); + else if (src->bits == i_double_bits) + i_img_double_new_low(im, x1, y1, src->channels); + else { + fprintf(stderr, "i_copy(): Unknown image bit size %d\n", src->bits); + return; /* I dunno */ + } + pv = mymalloc(sizeof(i_fcolor) * x1); for (y = 0; y < y1; ++y) { i_glinf(src, 0, x1, y, pv); @@ -1063,9 +1070,12 @@ i_img *i_sametype(i_img *src, int xsize, int ysize) { if (src->bits == 8) { return i_img_empty_ch(NULL, xsize, ysize, src->channels); } - else if (src->bits == 16) { + else if (src->bits == i_16_bits) { return i_img_16_new(xsize, ysize, src->channels); } + else if (src->bits == i_double_bits) { + return i_img_double_new(xsize, ysize, src->channels); + } else { i_push_error(0, "Unknown image bits"); return NULL; diff --git a/t/t022double.t b/t/t022double.t index 64f9b1f6..b9c3dfa6 100644 --- a/t/t022double.t +++ b/t/t022double.t @@ -1,6 +1,6 @@ #!perl -w use strict; -BEGIN { $| = 1; print "1..29\n"; } +BEGIN { $| = 1; print "1..30\n"; } my $loaded; END {print "not ok 1\n" unless $loaded;} use Imager qw(:all :handy); @@ -19,6 +19,7 @@ ok(3, Imager::i_img_getmask($im_g) & 1, "1 channel image bad mask"); ok(4, Imager::i_img_virtual($im_g) == 0, "1 channel image thinks it is virtual"); my $double_bits = length(pack("d", 1)) * 8; +print "# $double_bits double bits\n"; ok(5, Imager::i_img_bits($im_g) == $double_bits, "1 channel image has bits != $double_bits"); ok(6, Imager::i_img_type($im_g) == 0, "1 channel image isn't direct"); @@ -60,12 +61,13 @@ test_colorf_glin(26, $im_rgb, 0, 1, ($redf) x 20, ($greenf) x 60, ($redf) x 20); # basic OO tests -my $oo16img = Imager->new(xsize=>200, ysize=>201, bits=>16) - or print "not "; -print "ok 28\n"; -$oo16img->bits == 16 or print "not "; -print "ok 29\n"; +my $ooimg = Imager->new(xsize=>200, ysize=>201, bits=>'double'); +ok(28, $ooimg, "couldn't make double image"); +ok(29, $ooimg->bits eq 'double', "oo didn't give double image"); +# check that the image is copied correctly +my $oocopy = $ooimg->copy; +ok(30, $oocopy->bits eq 'double', "oo copy didn't give double image"); sub NCF { return Imager::Color::Float->new(@_); -- 2.39.5