Page 1 of 1

Compress BMP with RLE

Posted: 2018-04-22T17:04:49-07:00
by qwermike
Hello,
I'm trying to compress bmp image using RLE into bmp.
I don't know what I'm doing wrong. The compression does nothing.

So I'm using the command:

Code: Select all

magick convert .\matterhorn.bmp -compress RLE BMP3:mt_rle.bmp
After this I check the images with:

Code: Select all

magick identify .\matterhorn.bmp .\mt_rle.bmp
And the result is:
.\matterhorn.bmp BMP3 1280x720 1280x720+0+0 8-bit sRGB 2.63677MiB 0.016u 0:00.013
.\mt_rle.bmp        BMP3 1280x720 1280x720+0+0 8-bit sRGB 2.63677MiB 0.016u 0:00.013

Any help would be appreciated.
____________________________________________________
I'm using PowerShell on Windows 10.
Version: ImageMagick 7.0.7-28 Q16 x64 2018-03-25
Visual C++: 180040629

Re: Compress BMP with RLE

Posted: 2018-04-22T17:29:35-07:00
by 246246
As far as I know RLE compression for bmp is only applicable for 4-bit or 8-bit bitmap (unless it is OS/2 format).
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
https://en.wikipedia.org/wiki/BMP_file_ ... ompression
From file size, your matterhorn.bmp is 24-bit RGB bitmap, not an indexed color.
If your matterhorn.bmp has less than or equal to 256 colors, you can convert it to 8-bit indexed color, then can compress with RLE.

Code: Select all

magick matterhorn.bmp -type Palette -compress RLE BMP3:mt_rle.bmp

Re: Compress BMP with RLE

Posted: 2018-04-22T17:32:24-07:00
by fmw42
try

Code: Select all

magick identify -verbose .\mt_rle.bmp
and see what the compress lists. I do not think it shows in a simple magick identify

or

Code: Select all

magick identify .\mt_rle.bmp -format "%C" info:

Re: Compress BMP with RLE

Posted: 2018-04-23T00:49:25-07:00
by qwermike
fmw42 wrote: 2018-04-22T17:32:24-07:00 try

Code: Select all

magick identify -verbose .\mt_rle.bmp
and see what the compress lists. I do not think it shows in a simple magick identify

or

Code: Select all

magick identify .\mt_rle.bmp -format "%C" info:
I used 1st command. Here is what I got: https://pastecode.xyz/view/659328d8

But seems like user 246246 found what I'm doing wrong. Now I'm curious can ImageMagick convert my bmp to OS/2 format?
P.S. I tried to compress OS/2 24bit image, but no effect. And identify shows that it is BMP2.

Re: Compress BMP with RLE

Posted: 2018-04-23T06:08:39-07:00
by 246246
qwermike wrote: 2018-04-23T00:49:25-07:00 But seems like user 246246 found what I'm doing wrong. Now I'm curious can ImageMagick convert my bmp to OS/2 format?
P.S. I tried to compress OS/2 24bit image, but no effect. And identify shows that it is BMP2.
I think you tried to read OS/2 BMP v1, which is practically identical to Windows bitmap v2. See http://fileformats.archiveteam.org/wiki/BMP. (Propably you see the following message when you read the file:

Code: Select all

identify: length and filesize do not match `fv200.bmp' @ warning/bmp.c/ReadBMPImage/842.
). I checked the current source code, and I can say IM does not support OS/2 v2 bitmap as far as compression types "Huffman 1D" and "RLE24".

Re: Compress BMP with RLE

Posted: 2018-04-23T10:28:47-07:00
by qwermike
246246 wrote: 2018-04-23T06:08:39-07:00 I think you tried to read OS/2 BMP v1, which is practically identical to Windows bitmap v2. See http://fileformats.archiveteam.org/wiki/BMP. (Propably you see the following message when you read the file:

Code: Select all

identify: length and filesize do not match `fv200.bmp' @ warning/bmp.c/ReadBMPImage/842.
). I checked the source code, and I can say IM does not support OS/2 v2 bitmap as far as compression types "Huffman 1D" and "RLE24".
Thanks for explanation.
Maybe You know a utility that can compress OS/2 v2 24bit BMP with RLE?
or library for C or Python or else?
or where to find the source code of implemented algorithm?

Re: Compress BMP with RLE

Posted: 2018-04-23T17:03:10-07:00
by 246246
I have not found such program yet, or even have not found RLE24 compressed bitmap sample file.
Some products may read/write such files, for example https://www.leadtools.com/help/leadtool ... rmats.html, but i'm not tried it yet. I guess most software ignore RLE compression option for RGB24 because it is unlikely to be readable from other application. You can see the detail of OS/2 bmp include RLE24 compression here: http://www.fileformat.info/format/os2bmp/egff.htm

PS. I just found this one: https://sourceforge.net/projects/bmp2rle/

Re: Compress BMP with RLE

Posted: 2018-04-23T23:27:30-07:00
by qwermike
I've tried Photoshop(not the newest), and I can save image to BMP in Windows or OS/2 mode, and there is also a checkbox for RLE compression, but this checkbox can't be enabled :|.

I need it just to compare times for different compression algorithms. Since OS/2 v2 bmp is unreadable without special software, I guess I will write code for simple RLE for file, or split my 24bit BMP into 3 (R,G,B) 8 bit BMPs and convert it.

Thank you for help.

Re: Compress BMP with RLE

Posted: 2018-04-24T05:09:02-07:00
by 246246
qwermike wrote: 2018-04-23T23:27:30-07:00 I need it just to compare times for different compression algorithms.
Then, I think tiff is proper format. It support RLE, LZW, Zip, Jpeg compression with libtiff.

Re: Compress BMP with RLE

Posted: 2018-04-24T11:19:50-07:00
by qwermike
Yea and I can just use Image Magick.
P.S. Will hope that professor let me use only .tiff because in the task I need to convert 24bit BMP to BMP(RLE), TIFF(LZW), JPEG(Standard Encoding).
P.P.S. Thanks again!