Optimising BMP size

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
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Optimising BMP size

Post by Excale »

Hi,

I have a bunch on pdf files I converted in black and white (real black en white, not grey...) PNG files (one by page).

I want to put them on a device that can only read BMP files (so I want to convert from PNG to BMP). As this device only have small memory, I want to optimise the size of the files as much as I can.

I thought to a few thigs to optimise it:
-Convert to 4bit-RLE BMP (but only having 2 colors in the image so RLE works better)
-Remove the white border using -trim
-Resize it to get smaller images (but still readable :D).
-Any other idea :) ?

If you have any other ideas, i'll take them. I also don't know in which order I should do these steps.

Thanks :).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimising BMP size

Post by fmw42 »

see the only notes I know about for BMP in IM at http://www.imagemagick.org/Usage/formats/#bmp
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Optimising BMP size

Post by Excale »

ImageMagick supports 8, 24, and 32-bit BMP images.
Ah :( . That means photoshop will get me lighter files.

Anyway, Imagemagick will still be usefull for -trim :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimising BMP size

Post by fmw42 »

Did you see the older formats supported:


The header for a BMP2: format only allows the description of the width,
height and bit depth (bits per pixel) of an image. The bit depth can be one of
1, 4, 8 or 24.

For comparison, the bmp3: format allows bit depths of 0, 1, 4, 8 ,16, 24 and
32 and has extra fields which specify x and y resolution (in pixels per metre)
and compression of the image data.

Just put BMP2:resultimage.bmp for your ouput with whatever -depth from the above supported. I presume IM can read any of these formats.
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Optimising BMP size

Post by Excale »

I thought BMP2/3 was some kind a weird format, but it seems it's just "usual" BMP :).

I'll try it then...

Ok, this is what I get:

convert A.png -trim -compress RLE -depth 4 BMP3:A.bmp ==> 159Ko
convert A.png -trim -compress RLE -resize 25% -depth 4 BMP3:A2.bmp ==> 561Ko
(-verbose for both of them: convert.exe: no decode delegate for this image format `A.bmp' @ error/constitute.c/ReadImage/532.)

What is this :D? (EDIT: looks like there is no RLE)

Png: http://www.mirari.fr/dD0a
Bmp 1 : http://www.mirari.fr/zlRQ
Bmp 2 : http://www.mirari.fr/mCPD

Thanks :) .


Edit:
convert A.png -trim -depth 4 -compress RLE BMP3:A.bmp ==> 159Ko
convert A.png -trim -brightness-contrast 0x0 -depth 4 -compress RLE BMP3:A2.bmp ==> 8942Ko
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimising BMP size

Post by fmw42 »

-brightness-contrast 0x0
This is a waste as it changes nothing unless you change the values from 0. It is basically a no-op.

Not sure what your question is at this time? Does it help or not? Is there still an issue?
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Optimising BMP size

Post by whugemann »

Fred,

from where did you get this hint on RGB2 and RGB3?

On my Windows XP computer, setting BMP2:output.bmp has apparantly no effect. I couldn't find any hints on BMP2/3 in the official documentation; there are just discussions in the forum. http://www.imagemagick.org/script/formats.php only mentions BMP.

RLE works perfectly, though. I took my information on colour depth / colour count by the help of IrfanView.
Wolfgang Hugemann
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Optimising BMP size

Post by glennrp »

I didn't remember BMP2: or BMP3: either, but ImageMagick is open-source code. Indeed you can see that "BMP2" and "BMP3" are used to set the value of "type" in coders/bmp.c, and "type" controls the compression.

There's already a hint in "-list format":
  • $ identify -list format | grep BMP
    BMP* rw- Microsoft Windows bitmap image
    BMP2* -w- Microsoft Windows bitmap image (V2)
    BMP3* -w- Microsoft Windows bitmap image (V3)
    WBMP* rw- Wireless Bitmap (level 0) image
and the formats document says
  • By default the BMP format is version 4. Use BMP3 and BMP2 to write versions 3 and 2 respectively.
D'oh.
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Optimising BMP size

Post by whugemann »

OK, -list formats work's fine. But what "formats" document do you mean? On my Wndows installation formats.html is an exact copy of the online version I mentioned. And yes, you can look it up in the source code, I guess. But this is a rather complicated way to find out about things (at least if your new to the source code).

Please remember that not all of us are native English speakers. I had to consult at http://en.wikipedia.org/wiki/D%27oh!#Usage to find out that your last phrase is meant to be "mildly derogatory".
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimising BMP size

Post by fmw42 »

whugemann wrote:Fred,

from where did you get this hint on RGB2 and RGB3?

On my Windows XP computer, setting BMP2:output.bmp has apparantly no effect. I couldn't find any hints on BMP2/3 in the official documentation; there are just discussions in the forum. http://www.imagemagick.org/script/formats.php only mentions BMP.

RLE works perfectly, though. I took my information on colour depth / colour count by the help of IrfanView.

Wolfgang,

it is for BMP not RGB and is at the bottom of the section at http://www.imagemagick.org/Usage/formats/#bmp that Anthony wrote in his Usage pages.

P.S.

Glenn's usage of D'OH comes from the Simpson's Cartoon from Homer, who is rather dumb. That is an expression that people use now to represent situations where they realize they have done or forgotten something obvious. So I believe Glenn was just commenting on the fact that he forgot about BMP2 and BMP3. Glenn, correct me if I am wrong.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Optimising BMP size

Post by glennrp »

whugemann wrote:OK, -list formats work's fine. But what "formats" document do you mean?
On the Imagemagick.org front page, first line under "a few examples" is a link to the formats page http://www.imagemagick.org/script/formats.php
On my Wndows installation formats.html is an exact copy of the online version I mentioned. And yes, you can look it up in the source code, I guess. But this is a rather complicated way to find out about things (at least if your new to the source code).
Of course. But it's always available in the last resort.
Please remember that not all of us are native English speakers. I had to consult at http://en.wikipedia.org/wiki/D%27oh!#Usage to find out that your last phrase is meant to be "mildly derogatory".
Sorry. I always understood the expression to be self-deprecatory, and it was a followup to my remark, "I didn't remember BMP2: or BMP3:", because after all, it's likely that I wrote the code in question!

Glenn
Last edited by glennrp on 2011-12-09T12:59:24-07:00, edited 1 time in total.
Excale
Posts: 13
Joined: 2010-12-05T23:39:53-07:00
Authentication code: 8675308

Re: Optimising BMP size

Post by Excale »

fmw42 wrote:Not sure what your question is at this time? Does it help or not? Is there still an issue?
What I don't understand is the size of the output files (I mentioned them at the end of the lines). its quite weird.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimising BMP size

Post by fmw42 »

With the -brightness-contrast 0,0 you are not getting a no-op exactly as the output is directclass not pseudoclass. See the identify -verbose on your two results. Also best to add +repage in case BMP allows virtual canvas. If not, then it is ok to leave off.

So try the following


convert logo: -trim +repage -depth 4 -compress RLE BMP3:A.bmp
identify -verbose A.bmp
52KB


convert logo: -trim +repage -brightness-contrast 0,0 -depth 4 -compress RLE -type palette BMP3:B.bmp
identify -verbose B.bmp
44.8KB
Post Reply