Convert to 32-bit depth BMP

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
wsielski
Posts: 6
Joined: 2016-09-22T03:37:03-07:00
Authentication code: 1151

Convert to 32-bit depth BMP

Post by wsielski »

Hi I'm trying to convert png file to BMP 32-bit depth.

Unfortunately all my tests ends with 8-bit BMP file. What am I doing wrong?

Code: Select all

$ convert image.jpg -verbose test_clean.bmp
image.jpg=>test_clean.bmp JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.640u 0:00.680
$ convert image.jpg -verbose -depth 32 test_clean32.bmp
image.jpg=>test_clean32.bmp JPEG 4032x3024 4032x3024+0+0 32-bit sRGB 36.58MB 0.690u 0:00.740
$ identify test_clean.bmp
test_clean.bmp BMP 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.140u 0:00.140
$ identify test_clean32.bmp
test_clean32.bmp BMP 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.140u 0:00.129
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert to 32-bit depth BMP

Post by snibgo »

I think your are confusing two measurements. An image that has 8 bits/channel/pixel, and 4 channels, has 32 bits per pixel in total.
snibgo's IM pages: im.snibgo.com
wsielski
Posts: 6
Joined: 2016-09-22T03:37:03-07:00
Authentication code: 1151

Re: Convert to 32-bit depth BMP

Post by wsielski »

Well I'm not really sure then how to test if it's 8bit/24bit/32bit depth.

The result of generating and identifying 24bit generation returns same results:

Code: Select all

$ convert image.jpg -verbose -depth 24 test_clean24.bmp
image.jpg=>test_clean24.bmp JPEG 4032x3024 4032x3024+0+0 24-bit sRGB 36.58MB 0.750u 0:00.869
$ identify test_clean24.bmp
test_clean24.bmp BMP 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.140u 0:00.149
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert to 32-bit depth BMP

Post by snibgo »

In the first command, you ask for "-depth 24", which is 24 bits per channel per pixel (total 72 bits per pixel). IM gives you that. Then it saves to a BMP file.

Then you read back the BMP file, and now you have 8 bits/channel/pixel (total 24 bits/pixel).
snibgo's IM pages: im.snibgo.com
wsielski
Posts: 6
Joined: 2016-09-22T03:37:03-07:00
Authentication code: 1151

Re: Convert to 32-bit depth BMP

Post by wsielski »

But there is no difference between:

Code: Select all

$ identify test_clean32.bmp
test_clean32.bmp BMP 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.140u 0:00.130
$ identify test_clean24.bmp
test_clean24.bmp BMP 4032x3024 4032x3024+0+0 8-bit sRGB 36.58MB 0.140u 0:00.129
Which I suppose should differ when test_clean32.bmp was created with '-depth 32' and test_clean24.bmp was created with '-depth 24'

Code: Select all

$ identify -format "%[bit-depth]\n"  test_clean32.bmp
8
$ identify -format "%[bit-depth]\n"  test_clean24.bmp
8
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert to 32-bit depth BMP

Post by snibgo »

No. See above. "-depth 32" means 32 bits per channel per pixel, NOT a total of 32 bits.
snibgo's IM pages: im.snibgo.com
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Convert to 32-bit depth BMP

Post by Jason S »

BMP is limited to around 10 bits per channel (and more than 8 is rarely supported), so if you really want 32, you can't use BMP format. Assuming you want 32 bits per pixel:

Most full-color BMP images have 24 bits per pixel, not 32. A 32-bit BMP could mean (1) there are 8 unused bits per pixel, or (2) there is an 8-bit alpha channel, or (3) all 32 bits are used by the color channels, for example R11/G11/B10 format. I think that ImageMagick only supports possibility (2) when writing BMP files.

I think that ImageMagick won't write a 32-bit BMP image unless it thinks there is an alpha channel, and for the usual BMPv3 format you also need "-define bmp3:alpha=true". Adding an alpha channel probably won't have any bad side effects, so you could try:

Code: Select all

$ convert rose: -alpha set -define bmp:format=bmp4 test.bmp
$ file test.bmp
test.bmp: PC bitmap, Windows 98/2000 and newer format, 70 x 46 x 32
or:

Code: Select all

$ convert rose: -alpha set -define bmp:format=bmp3 -define bmp3:alpha=true test.bmp
$ file test.bmp
test.bmp: PC bitmap, Windows 3.x format, 70 x 46 x 32
edwpang
Posts: 1
Joined: 2019-05-30T08:04:39-07:00
Authentication code: 1152

Re: Convert to 32-bit depth BMP

Post by edwpang »

This works for me:
$ convert rose: -alpha set -define bmp:format=bmp3 -define bmp3:alpha=true test.bmp
$ file test.bmp
test.bmp: PC bitmap, Windows 3.x format, 70 x 46 x 32


But I don't why bmp4 one doesn't work.
Post Reply