mozilla / mozjpeg

Improved JPEG encoder.
Other
5.44k stars 417 forks source link

Support BMP versions > 3 #190

Open njdoyle opened 8 years ago

njdoyle commented 8 years ago

Mozjpeg supports BMP files as input but not recent versions of the BMP format. It currently supports up to BMP version 3. It would be useful to support versions more recent than that.

In particular, unless specified explicitly, current versions of ImageMagick will make BMPs of version 5.

The following command demonstrates mozjpeg's incompatibility:

$ convert logo: BMP:- | cjpeg  > logo.jpg
Invalid BMP file: bad header length
kornelski commented 8 years ago

For piping from ImageMagick TGA works well.

njdoyle commented 8 years ago

TGA from ImageMagick is super slow to encode. On my newish MBP, a 1733x2376 JPEG (709K) input converts to BMP in 55ms but converts to TGA in 800ms.

Either way, I think the added BMP support in mozjpeg would be worth while and that TGA isn't necessarily the best option.

kornelski commented 8 years ago

Oh, that's surprising. AFAIK TGA is as primitive as BMP, so I've been assuming it's essentially zero overhead.

rfjakob commented 7 years ago

For future me (or other people) finding this ticket: You have to pass "BMP3" to ImageMagick:

convert logo.png BMP3:- | cjpeg > out.jpg
redneb commented 6 years ago

Actually, I found that you also have to add the -compress none option, like so:

convert logo.png -compress none BMP3:- | cjpeg > out.jpg

This is because sometimes imagemagick uses RLE for the output and mozjpeg doesn't like that:

Sorry, compressed BMPs not yet supported