]> git.imager.perl.org - imager.git/commitdiff
ascii pbms weren't treated correctly
authorTony Cook <tony@develop=help.com>
Mon, 7 Jan 2002 10:55:50 +0000 (10:55 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 7 Jan 2002 10:55:50 +0000 (10:55 +0000)
Changes
MANIFEST
pnm.c
t/t104ppm.t
testimg/simple.pbm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 31a017349c68160fb45d1b95acb8703b5020aba2..f0db98cf3f34595f8adf7393b3dec69353a70f58 100644 (file)
--- a/Changes
+++ b/Changes
@@ -577,6 +577,7 @@ Revision history for Perl extension Imager.
         - add tests for each type of iolayer in t50basicoo.t
         - read/write multi-image tiff files
         - tests in t50basicoo.t for multi-image/file
+        - ASCII PBM files were reading white as dark gray (255 vs 1)
 
 =================================================================
 
index 30106a410979580442ffdf83cc81d71cc4152d66..2e2ceae54560d3d531a1097766373d55e7a6272b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -133,6 +133,7 @@ testimg/scale.ppm
 testimg/scalei.gif
 testimg/screen2.gif
 testimg/screen3.gif
+testimg/simple.pbm
 testimg/test_gimp_pal   A simple GIMP palette file
 testimg/trimgdesc.gif
 testimg/trmiddesc.gif
diff --git a/pnm.c b/pnm.c
index aff05f8b6ba7bcbc19288dea3060d9616e8e9c3f..a4e1753be5ba237a624a5f6b0914957ab6a9789a 100644 (file)
--- a/pnm.c
+++ b/pnm.c
@@ -354,7 +354,7 @@ i_readpnm_wiol(io_glue *ig, int length) {
     for(y=0;y<height;y++) for(x=0; x<width; x++) {
       for(ch=0; ch<channels; ch++) {
        int t;
-       if (gnum(&buf, &t)) val.channel[ch] = t;
+       if (gnum(&buf, &t)) val.channel[ch] = t * mult;
        else {
          mm_log((1,"i_readpnm: gnum() returned false in data\n"));
          return im;
index d4f3af84b57e5700f148585cdf8931b9d75d76cb..ba07a6022323bf6f38bb986f79320b8930dd9c0b 100644 (file)
@@ -1,6 +1,6 @@
 use Imager ':all';
 
-print "1..8\n";
+print "1..13\n";
 
 init_log("testout/t104ppm.log",1);
 
@@ -65,6 +65,15 @@ print "ok 7\n";
 i_img_diff($gimg, $gcmpimg) == 0 or print "not ";
 print "ok 8\n";
 
+my $ooim = Imager->new;
+$ooim->read(file=>"testimg/simple.pbm") or print "not ";
+print "ok 9\n";
+
+check_gray(10, Imager::i_get_pixel($ooim->{IMG}, 0, 0), 255);
+check_gray(11, Imager::i_get_pixel($ooim->{IMG}, 0, 1), 0);
+check_gray(12, Imager::i_get_pixel($ooim->{IMG}, 1, 0), 0);
+check_gray(13, Imager::i_get_pixel($ooim->{IMG}, 1, 1), 255);
+
 sub openimage {
   my $fname = shift;
   local(*FH);
@@ -80,3 +89,15 @@ sub slurp {
   close($fh);
   return $data;
 }
+
+sub check_gray {
+  my ($num, $c, $gray) = @_;
+
+  my ($g) = $c->rgba;
+  if ($g == $gray) {
+    print "ok $num\n";
+  }
+  else {
+    print "not ok $num # $g doesn't match $gray\n";
+  }
+}
diff --git a/testimg/simple.pbm b/testimg/simple.pbm
new file mode 100644 (file)
index 0000000..794da15
--- /dev/null
@@ -0,0 +1,5 @@
+P1
+# test image
+2 2
+1 0
+0 1