BMP file type version doesn't seem to match with the documentation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
scorpion
Posts: 4
Joined: 2015-05-22T07:25:02-07:00
Authentication code: 6789
Location: United Kingdom
Contact:

BMP file type version doesn't seem to match with the documentation

Post by scorpion »

Hello,

Been trying to save some image data using the Version 4 of the BMP format. The documentation mentions that this is the default format it will save BMP files in. (see http://www.fileformat.info/format/bmp/egff.htm ) + that the header size is always 108 bytes.

Looking at the file however, it seems that it's actually saving it in Version 5 (124 bytes) which would include the ICC Color Profile (see http://en.wikipedia.org/wiki/BMP_file_f ... _header.29 ).

I verified this by saving a file with Gimp and compare it with a hex viewer, which gives me a value of 0x6C (108 bytes) at location 0x0E in the file (the size of the header), where ImageMagick gives me 0x7C (124 bytes) at the same location.

Is the documentation incorrect (since it's saying it's saving it in v4, with a 108 byte header), or am I missing something? Is there a way to force it to save using V4 (108b) instead of V5 (124b)? Do I need to strip something with the convert tool for example?

Cheers!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: BMP file type version doesn't seem to match with the documentation

Post by dlemstra »

What is the version of ImageMagick that you are using and the platform you are on? I did not check this but it might be fixed already.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
scorpion
Posts: 4
Joined: 2015-05-22T07:25:02-07:00
Authentication code: 6789
Location: United Kingdom
Contact:

Re: BMP file type version doesn't seem to match with the documentation

Post by scorpion »

Version: ImageMagick 6.9.1-2 Q16 x64 2015-04-14
Platform: Windows 8
scorpion
Posts: 4
Joined: 2015-05-22T07:25:02-07:00
Authentication code: 6789
Location: United Kingdom
Contact:

Re: BMP file type version doesn't seem to match with the documentation

Post by scorpion »

Some more information on what I'm doing:

I'm slicing an image through "convert input.bmp -colors 16 +gravity -crop 16x16 output.bmp", which gives me a bunch of bmp files.
The input file is a V4 (108b) file, the output a V5 (124b).

A quick glance at the source-code (bmp.c) shows me that if there is a 'rendering_intent' or a 'profile' is present, it will save it as the v5. This almost seems like the code initializes the profile or rendering_intent in a wrong way?
scorpion
Posts: 4
Joined: 2015-05-22T07:25:02-07:00
Authentication code: 6789
Location: United Kingdom
Contact:

Re: BMP file type version doesn't seem to match with the documentation

Post by scorpion »

Ok, I've gotten the svn repro and found out that the default render intent (as seen at bmp.c #546) is always set to PerceptualIntent, but the decision to set it is made later in the code (bmp.c ~#780).

My suggestion is to set the default intent after obtaining the image reference through the AcquireImage(image_info) to UndefinedIntent.

This way, when BMPv4 files are read, it actually has a chance to write them out as BMPv4, without automatically falling through to v5 because of the checks it makes later on (see bmp.c ~#1684).

Patch:

Code: Select all

Index: coders/bmp.c
===================================================================
--- coders/bmp.c	(revision 18604)
+++ coders/bmp.c	(working copy)
@@ -544,6 +544,7 @@
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
   image=AcquireImage(image_info);
+  image->rendering_intent = UndefinedIntent;
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
     {

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18604)
+++ ChangeLog	(working copy)
@@ -1,3 +1,7 @@
+2015-03-22	6.9.0-10 Nerbert <nerbert@gmail...>
+  * Default rendering intent for BMP set to undefined by default, making it
+    possible to save in BMPv4 again.
+
 2015-03-01  6.9.0-10 Cristy  <quetzlzacatenango@image...>
   * New version 6.9.0-10, SVN revision 18299.
 
(or should I post this in the Bugs or Developers sub-forum?)
Post Reply