Compress BMP with RLE

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
qwermike
Posts: 5
Joined: 2018-04-22T16:43:20-07:00
Authentication code: 1152

Compress BMP with RLE

Post 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
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Compress BMP with RLE

Post 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
Last edited by 246246 on 2018-04-22T17:47:36-07:00, edited 4 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compress BMP with RLE

Post 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:
qwermike
Posts: 5
Joined: 2018-04-22T16:43:20-07:00
Authentication code: 1152

Re: Compress BMP with RLE

Post 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.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Compress BMP with RLE

Post 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".
Last edited by 246246 on 2018-04-23T19:02:43-07:00, edited 1 time in total.
qwermike
Posts: 5
Joined: 2018-04-22T16:43:20-07:00
Authentication code: 1152

Re: Compress BMP with RLE

Post 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?
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Compress BMP with RLE

Post 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/
qwermike
Posts: 5
Joined: 2018-04-22T16:43:20-07:00
Authentication code: 1152

Re: Compress BMP with RLE

Post 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.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Compress BMP with RLE

Post 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.
qwermike
Posts: 5
Joined: 2018-04-22T16:43:20-07:00
Authentication code: 1152

Re: Compress BMP with RLE

Post 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!
Post Reply