Cropping 16 bit .BMP files and maintaining pixel size

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
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

Cropping 16 bit .BMP files and maintaining pixel size

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

I don't think IM can save as BMP 5:6:5.
snibgo's IM pages: im.snibgo.com
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

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

Post 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!!
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

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

Post by mch »

If it cant, is there an official way to suggest an enhancement to IM?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

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

Post 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").
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Well-spotted, Jason.

@Fred: that define isn't in http://www.imagemagick.org/script/comma ... ptions.php . Can it be added?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

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

Post 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?
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
mch
Posts: 8
Joined: 2018-01-08T07:25:30-07:00
Authentication code: 1152

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

Post by mch »

With -type palettealpha it produces an image with 32 bits per pixel, although it does have an alpha channel now.
Post Reply