Page 1 of 1

Optimising BMP size

Posted: 2011-12-07T09:13:47-07:00
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 :).

Re: Optimising BMP size

Posted: 2011-12-07T10:43:07-07:00
by fmw42
see the only notes I know about for BMP in IM at http://www.imagemagick.org/Usage/formats/#bmp

Re: Optimising BMP size

Posted: 2011-12-07T10:47:34-07:00
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 :)

Re: Optimising BMP size

Posted: 2011-12-07T17:38:01-07:00
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.

Re: Optimising BMP size

Posted: 2011-12-08T12:36:12-07:00
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

Re: Optimising BMP size

Posted: 2011-12-08T15:46:29-07:00
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?

Re: Optimising BMP size

Posted: 2011-12-09T01:37:02-07:00
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.

Re: Optimising BMP size

Posted: 2011-12-09T06:49:34-07:00
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.

Re: Optimising BMP size

Posted: 2011-12-09T09:08:39-07:00
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".

Re: Optimising BMP size

Posted: 2011-12-09T10:36:05-07:00
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.

Re: Optimising BMP size

Posted: 2011-12-09T10:44:09-07:00
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

Re: Optimising BMP size

Posted: 2011-12-09T11:27:06-07:00
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.

Re: Optimising BMP size

Posted: 2011-12-09T12:20:58-07:00
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