Page 1 of 1

Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-08T07:33:09-07:00
by mch
IUsing IM 7.0.4-6 Q16 on Windows platform.

I have a 16 bit BMP which is RGB 5:6:5 file and I want to crop an area from it, I use the command:

magick convert -crop 72x66+16+62 "GPS ICONS Total FINAL_42.bmp" cam1.bmp

which produces a file cam1.bmp file with the correct image in it, however it now is saved as a 24bit .BMP file ie rgb 8:8:8. Image size is a factor for me so i want to maintain the image with only 2 bytes per pixel rather than 3, is it possible to do this and if so how?

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-08T07:51:58-07:00
by snibgo
I don't think IM can save as BMP 5:6:5.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-08T12:11:37-07:00
by mch
That would be a real shame, It seems it can do everything else!!

It can read the BMP file in 5:6:5!!

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T02:12:10-07:00
by mch
If it cant, is there an official way to suggest an enhancement to IM?

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T02:51:51-07:00
by snibgo
Post an entry in the Developers forum: viewforum.php?f=2

You can include a link to this thread: viewtopic.php?f=1&t=33334&sid=6ceff1fda ... 1a38826f62

It would probably help the developers if you include a link to a sample 5:6:5 file.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T09:40:15-07:00
by Jason S
There is already an option to write RGB565:

Code: Select all

-define bmp:subtype=RGB565
It seems to work okay with the default BMP version, but I think there's a bug that prevents it from working properly with BMPv3 ("BMP3:" or "-define bmp:format=bmp3").

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T15:40:37-07:00
by snibgo
Well-spotted, Jason.

@Fred: that define isn't in http://www.imagemagick.org/script/comma ... ptions.php . Can it be added?

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T15:54:09-07:00
by fmw42
Yes, I already noticed that and have to ask Dirk about the BMP3 issue before adding the define to the docs. Waiting on an answer.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-09T16:30:39-07:00
by fmw42
I have updated the docs. Note that this -define is only for BMP (BMP4). It is the only BMP format that supports arguments in the header for such options, according to Dirk.

It might take a day for them to pull over.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-20T04:42:04-07:00
by mch
so it was there just not documented!!

I have tried this and it works great.

-define bmp:subtype=RGB565

Not satisfied with that I tried:

-define bmp:subtype=ARGB1555

And that did not seem to work, it produced a file with 24 bits per pixel, I thought that ARGB1555 should fit in 16 bits?

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-20T09:40:05-07:00
by Jason S
I haven't looked at this closely, but I confirm that the ARGB1555 option seems to write a 24bpp image if the image has no transparency (and more than 256 colors). If the image has transparency, then it writes a 16bpp image as expected. Looks like a bug to me.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-20T11:00:37-07:00
by fmw42
-define bmp:subtype=ARGB1555

And that did not seem to work, it produced a file with 24 bits per pixel, I thought that ARGB1555 should fit in 16 bits?
Top
What happens if you add -type palettealpha to your command.

Re: Cropping 16 bit .BMP files and maintaining pixel size

Posted: 2018-01-23T03:07:38-07:00
by mch
With -type palettealpha it produces an image with 32 bits per pixel, although it does have an alpha channel now.