]> git.imager.perl.org - imager.git/commitdiff
add to_rgb16 method
authorTony Cook <tony@develop=help.com>
Sun, 8 Apr 2007 00:22:50 +0000 (00:22 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 8 Apr 2007 00:22:50 +0000 (00:22 +0000)
Imager.xs
imager.h
img16.c
lib/Imager/Test.pm
t/t021sixteen.t

index 32abacc93fd947a49e4354b3da9733616c159017..45c9cc0453aec38ec1ab9118487b3af82d8e08d6 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -1698,10 +1698,10 @@ i_matrix_transform(im, xsize, ysize, matrix, ...)
       OUTPUT:
         RETVAL
 
-void
+undef_int
 i_gaussian(im,stdev)
     Imager::ImgRaw     im
-            float     stdev
+           double     stdev
 
 void
 i_unsharp_mask(im,stdev,scale)
@@ -4022,6 +4022,10 @@ i_img_16_new(x, y, ch)
         int y
         int ch
 
+Imager::ImgRaw
+i_img_to_rgb16(im)
+       Imager::ImgRaw im
+
 Imager::ImgRaw
 i_img_double_new(x, y, ch)
         int x
index b9c6c03e1552bfc5858aede6fb9dd17e61f7cabb..eb3d92eafeb9c892275cce44df3cf89024d8361b 100644 (file)
--- a/imager.h
+++ b/imager.h
@@ -187,7 +187,7 @@ undef_int i_flood_cfill_border(i_img *im, int seedx, int seedy, i_fill_t *fill,
 
 /* image processing functions */
 
-void i_gaussian    (i_img *im,float stdev);
+int i_gaussian    (i_img *im, double stdev);
 void i_conv        (i_img *im,const float *coeff,int len);
 void i_unsharp_mask(i_img *im, double stddev, double scale);
 
@@ -349,6 +349,7 @@ extern i_img *i_img_masked_new(i_img *targ, i_img *mask, int x, int y,
                                int w, int h);
 extern i_img *i_img_16_new(int x, int y, int ch);
 extern i_img *i_img_16_new_low(i_img *im, int x, int y, int ch);
+extern i_img *i_img_to_rgb16(i_img *im);
 extern i_img *i_img_double_new(int x, int y, int ch);
 extern i_img *i_img_double_new_low(i_img *im, int x, int y, int ch);
 
diff --git a/img16.c b/img16.c
index 78c02dde6f9589667d04137532c5191dc542a5fe..4ef1b89381c4679f2e2bbd76f7f5d0ea7837dbf8 100644 (file)
--- a/img16.c
+++ b/img16.c
@@ -218,6 +218,38 @@ i_img *i_img_16_new(int x, int y, int ch) {
   return im;
 }
 
+/*
+=item i_img_to_rgb16(im)
+
+=category Image creation
+
+Returns a 16-bit/sample version of the supplied image.
+
+Returns the image on success, or NULL on failure.
+
+=cut
+*/
+
+i_img *
+i_img_to_rgb16(i_img *im) {
+  i_img *targ;
+  i_fcolor *line;
+  int y;
+
+  targ = i_img_16_new(im->xsize, im->ysize, im->channels);
+  if (!targ)
+    return NULL;
+  line = mymalloc(sizeof(i_fcolor) * im->xsize);
+  for (y = 0; y < im->ysize; ++y) {
+    i_glinf(im, 0, im->xsize, y, line);
+    i_plinf(targ, 0, im->xsize, y, line);
+  }
+
+  myfree(line);
+
+  return targ;
+}
+
 static int i_ppix_d16(i_img *im, int x, int y, const i_color *val) {
   int off, ch;
 
index f914f2ca05434b32787346a5884e59feb6647412..181c8b3bc0ab65bb53096048df91755bcdea314f 100644 (file)
@@ -4,7 +4,7 @@ use Test::Builder;
 require Exporter;
 use vars qw(@ISA @EXPORT_OK);
 @ISA = qw(Exporter);
-@EXPORT_OK = qw(diff_text_with_nul test_image_raw test_image_16 is_color3 is_color1 is_image);
+@EXPORT_OK = qw(diff_text_with_nul test_image_raw test_image_16 test_image is_color3 is_color1 is_image is_image_similar);
 
 sub diff_text_with_nul {
   my ($desc, $text1, $text2, @params) = @_;
@@ -98,6 +98,19 @@ sub test_image_raw {
   $img;
 }
 
+sub test_image {
+  my $green = Imager::Color->new(0, 255, 0, 255);
+  my $blue  = Imager::Color->new(0, 0, 255, 255);
+  my $red   = Imager::Color->new(255, 0, 0, 255);
+  my $img = Imager->new(xsize => 150, ysize => 150);
+  $img->box(filled => 1, color => $green, box => [ 70, 25, 130, 125 ]);
+  $img->box(filled => 1, color => $blue,  box => [ 20, 25, 80, 125 ]);
+  $img->arc(x => 75, y => 75, r => 30, color => $red);
+  $img->filter(type => 'conv', coef => [ 0.1, 0.2, 0.4, 0.2, 0.1 ]);
+
+  $img;
+}
+
 sub test_image_16 {
   my $green = Imager::Color->new(0, 255, 0, 255);
   my $blue  = Imager::Color->new(0, 0, 255, 255);
@@ -111,8 +124,8 @@ sub test_image_16 {
   $img;
 }
 
-sub is_image($$$) {
-  my ($left, $right, $comment) = @_;
+sub is_image_similar($$$$) {
+  my ($left, $right, $limit, $comment) = @_;
 
   my $builder = Test::Builder->new;
 
@@ -155,15 +168,24 @@ sub is_image($$$) {
     return;
   }
   my $diff = Imager::i_img_diff($left->{IMG}, $right->{IMG});
-  unless ($diff == 0) {
+  if ($diff > $limit) {
     $builder->ok(0, $comment);
-    $builder->diag("image data different - $diff");
+    $builder->diag("image data difference > $limit - $diff");
     return;
   }
   
   return $builder->ok(1, $comment);
 }
 
+sub is_image($$$) {
+  my ($left, $right, $comment) = @_;
+
+  local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+  return is_image_similar($left, $right, 0, $comment);
+}
+
+
 1;
 
 __END__
index 44e46f631168b83e3bbf6debae04cc80f028bd78..c0686383436c2baee540a0e31a92f578e8ce7dd3 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 85;
+use Test::More tests => 87;
 
 BEGIN { use_ok(Imager=>qw(:all :handy)) }
 
@@ -9,6 +9,7 @@ init_log("testout/t021sixteen.log", 1);
 require "t/testtools.pl";
 
 use Imager::Color::Float;
+use Imager::Test qw(test_image is_image);
 
 my $im_g = Imager::i_img_16_new(100, 101, 1);
 
@@ -151,3 +152,11 @@ cmp_ok(Imager->errstr, '=~', qr/channels must be between 1 and 4/,
 
   mask_tests($im, 1.0/65535);
 }
+
+{ # convert to rgb16
+  my $im = test_image();
+  my $im16 = $im->to_rgb16;
+  print "# check conversion to 16 bit\n";
+  is($im16->bits, 16, "check bits");
+  is_image($im, $im16, "check image data matches");
+}