Optimising BMP size
Optimising BMP size
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 ).
-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 .
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 ).
-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 .
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Optimising BMP size
see the only notes I know about for BMP in IM at http://www.imagemagick.org/Usage/formats/#bmp
Re: Optimising BMP size
Ah . That means photoshop will get me lighter files.ImageMagick supports 8, 24, and 32-bit BMP images.
Anyway, Imagemagick will still be usefull for -trim
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Optimising BMP size
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.
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
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 ? (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
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 ? (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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Optimising BMP size
This is a waste as it changes nothing unless you change the values from 0. It is basically a no-op.-brightness-contrast 0x0
Not sure what your question is at this time? Does it help or not? Is there still an issue?
- 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
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.
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
Re: Optimising BMP size
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":
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
- By default the BMP format is version 4. Use BMP3 and BMP2 to write versions 3 and 2 respectively.
- 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
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".
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Optimising BMP size
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
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.phpwhugemann wrote:OK, -list formats work's fine. But what "formats" document do you mean?
Of course. But it's always available in the last resort.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).
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!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".
Glenn
Last edited by glennrp on 2011-12-09T12:59:24-07:00, edited 1 time in total.
Re: Optimising BMP size
What I don't understand is the size of the output files (I mentioned them at the end of the lines). its quite weird.fmw42 wrote:Not sure what your question is at this time? Does it help or not? Is there still an issue?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Optimising BMP size
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
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