- write out the image size in bytes field of a BMP correctly.
authorTony Cook <tony@develop=help.com>
Fri, 12 Dec 2008 08:49:27 +0000 (08:49 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 12 Dec 2008 08:49:27 +0000 (08:49 +0000)
   http://rt.cpan.org/Ticket/Display.html?id=41406

Changes
bmp.c
t/t107bmp.t

diff --git a/Changes b/Changes
index 7847ac6..9c19a32 100644 (file)
--- a/Changes
+++ b/Changes
@@ -12,6 +12,9 @@ Bug fixes:
    tests for it.
    http://rt.cpan.org/Ticket/Display.html?id=41028
 
+ - write out the image size in bytes field of a BMP correctly.
+   http://rt.cpan.org/Ticket/Display.html?id=41406
+
 Imager 0.66 - 22 April 2008
 ===========
 
diff --git a/bmp.c b/bmp.c
index 76c7e60..8f37d32 100644 (file)
--- a/bmp.c
+++ b/bmp.c
@@ -367,7 +367,7 @@ int write_bmphead(io_glue *ig, i_img *im, int bit_count, int data_size) {
 
   if (!write_packed(ig, "CCVvvVVVVvvVVVVVV", 'B', 'M', data_size+offset, 
                    0, 0, offset, INFOHEAD_SIZE, im->xsize, im->ysize, 1, 
-                   bit_count, BI_RGB, 0, (int)(xres+0.5), (int)(yres+0.5), 
+                   bit_count, BI_RGB, data_size, (int)(xres+0.5), (int)(yres+0.5), 
                    colors_used, colors_used)){
     i_push_error(0, "cannot write bmp header");
     return 0;
index 6a9496a..e8db5da 100644 (file)
@@ -1,8 +1,8 @@
 #!perl -w
 use strict;
-use Test::More tests => 211;
+use Test::More tests => 213;
 use Imager qw(:all);
-use Imager::Test qw(test_image_raw is_image is_color3);
+use Imager::Test qw(test_image_raw is_image is_color3 test_image);
 init_log("testout/t107bmp.log",1);
 
 my $debug_writes = 0;
@@ -647,6 +647,14 @@ for my $comp (@comp) {
            "check translucent came through");
 }
 
+{ # RT 41406
+  my $data;
+  my $im = test_image();
+  ok($im->write(data => \$data, type => 'bmp'), "write using OO");
+  my $size = unpack("V", substr($data, 34, 4));
+  is($size, 67800, "check data size");
+}
+
 sub write_test {
   my ($im, $filename) = @_;
   local *FH;