]> git.imager.perl.org - imager.git/commitdiff
some fixes to double/sample image support
authorTony Cook <tony@develop=help.com>
Thu, 11 Oct 2001 09:52:16 +0000 (09:52 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 11 Oct 2001 09:52:16 +0000 (09:52 +0000)
make $img->bits return "double" for double/sample images

Changes
Imager.pm
image.c
t/t022double.t

diff --git a/Changes b/Changes
index 420acd9bf7ef5b88806fdaeded9ce15cc109963d..69abf5bf39dc7417509aa8cebf9996444406ef07 100644 (file)
--- 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
 
 =================================================================
 
index a6231c718146e7999e6815b17af2b337b589c393..1b811676cc154a38b0018b0cb9695f5eac9ac89f 100644 (file)
--- 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 8b5bf760c4ab0d0496f5cc34a2438e7477466eb2..d4c3f6f400116ef069fce1ed2564088143adfc50 100644 (file)
--- 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;
index 64f9b1f697c8c8195296816f156d00db888bdb23..b9c3dfa6855fc0c59a401f5b5cce00befb3d3837 100644 (file)
@@ -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(@_);