For 16-bit sample PPM images Image::Info returns a SamplesPerPixel of 6.
While there are 6 bytes per pixel, there are only 3 samples, and
BitsPerSample reflects that.
Patch attached.
Subject: | 0001-PPM-files-are-always-3-samples-pixel-even-when-they.patch |
From 15ddd6e40ba3a1c3f7b14fea920a20eccb979974 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 10 Feb 2010 18:59:36 +1100
Subject: [PATCH] PPM files are always 3 samples/pixel, even when they have 2 bytes/sample
---
lib/Image/Info/PPM.pm | 3 +--
t/tiny-pgm.t | 12 ++++++++++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/lib/Image/Info/PPM.pm b/lib/Image/Info/PPM.pm
index 168e4c7..4bfda3d 100644
--- a/lib/Image/Info/PPM.pm
+++ b/lib/Image/Info/PPM.pm
@@ -68,8 +68,7 @@ sub process_file {
$info->push_info(0, "MaxSampleValue", $MSV);
$info->push_info(0, "color_type", "RGB");
- my $double = 1; $double = 2 if $MSV > 256;
- $info->push_info(0, "SamplesPerPixel", $double * 3);
+ $info->push_info(0, "SamplesPerPixel", 3);
if ($binary) {
for (1..3) {
$info->push_info(0, "BitsPerSample", int(log($MSV + 1) / log(2) ) );
diff --git a/t/tiny-pgm.t b/t/tiny-pgm.t
index b62254c..11233a7 100644
--- a/t/tiny-pgm.t
+++ b/t/tiny-pgm.t
@@ -7,7 +7,7 @@ use strict;
BEGIN
{
- plan tests => 4;
+ plan tests => 7;
chdir 't' if -d 't';
use lib '../lib';
use_ok ("Image::Info") or die($@);
@@ -23,5 +23,13 @@ my $h = image_info("../img/tiny.pgm")
is ($h->{file_media_type}, "image/pgm", 'file_media_type');
is ($h->{width}, 1, 'width=1');
-is ($h->{height}, 1, 'height=1');;
+is ($h->{height}, 1, 'height=1');
+
+{
+ my $ppm16data = "P6 1 1 65535\nxxxxxx";
+ my $i = image_info(\$ppm16data);
+ ok($i, "read 16-bit/sample ppm");
+ is_deeply ($i->{BitsPerSample}, [ 16, 16, 16 ], "BitsPerSample=16,16,16");
+ is ($i->{SamplesPerPixel}, 3, "SamplesPerPixel=3");
+}
--
1.5.6.5