Magick++ how to read bitmap 256 color, convert to RGBA

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
axisofevil
Posts: 4
Joined: 2019-07-23T09:34:39-07:00
Authentication code: 1152

Magick++ how to read bitmap 256 color, convert to RGBA

Post by axisofevil »

Hi all,

[ somewhat new to IM ]

I need to read in various bitmaps ( 256 color, 16 , mono ) and convert to RGBA programmatically. I have code which works for converting jpeg, png, tiff, and 24 bit per pixel bitmaps; all that code does is pass a filename to image constructor then write out RGBA, but I'm thinking there's more to it for palletized bitmaps as I've had various artifacts with those. I started down a road using blob in the constructor but can't understand how palette gets into IM. Thanks, dB

Using version 7.0.8
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by snibgo »

wrote:... and convert to RGBA programmatically.
What does that mean? What is your output format, eg PNG, TIFF or what?
snibgo's IM pages: im.snibgo.com
axisofevil
Posts: 4
Joined: 2019-07-23T09:34:39-07:00
Authentication code: 1152

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by axisofevil »

output is *.rgba. The 256 bitmap actually looks correct, the 16 is rendered at quarter size - twice - in the upper half of the expected area, the bottom half is some noise pattern. The mono bitmap renders as a thin band across the top of the expected area.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by snibgo »

The round-trip to and from rgba works fine at the command line, eg:

Code: Select all

f:\web\im>%IMG7%magick toes.png x.rgba

f:\web\im>%IMG7%magick -size 267x233 x.rgba t.png
t.png is identical to toes.png.

I suspect you are doing some weird processing. If you post your code, perhaps we can comment further.
snibgo's IM pages: im.snibgo.com
axisofevil
Posts: 4
Joined: 2019-07-23T09:34:39-07:00
Authentication code: 1152

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by axisofevil »

I'll reiterate:
1) Not using command line
2) Problem to be solved is reading in bitmaps, i.e. *.bmp
3) Current code is completely basic - image read in filename.* where * is jpg. png, etc, then write filename.rgba.
4) Code works for jpg. png, tiff, and 24 BPP bitmap files

Problem was with bitmap-16.bmp in here, then I'll try to get bitmap-mono.bmp working.
https://www.dropbox.com/s/f1x6ynahf88o7 ... s.zip?dl=0

It looks like this:
https://www.dropbox.com/s/7ecr6j0jv4jnq ... 9.jpg?dl=0
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by snibgo »

Your output file is very different to the input bitmap-16.bmp. The input has five shapes and a white background. The output also has a grid target and some pens or something in the bottom-right corner.

That output didn't come from that input.

At the command line, we can convert bitmap-16.bmp to 8-bit ("-depth 8") x.rgba, and convert that to PNG, and the result is as expected. Yes, I know you don't use the command line, but I suppose your program is doing something different.

bitmap-16.bmp has 960x540 pixels. With 4 channels, 1 byte/channel/pixel, the RGBA filesize should be 2073600 bytes. Is that your filesize?

EDIT to add: If it isn't, then perhaps you haven't set the depth to 8. Then you write 4 bits/channel/pixel, but your reader probably expects 8 bits/channel/pixel.
snibgo's IM pages: im.snibgo.com
axisofevil
Posts: 4
Joined: 2019-07-23T09:34:39-07:00
Authentication code: 1152

Re: Magick++ how to read bitmap 256 color, convert to RGBA

Post by axisofevil »

Thanks - I have it working using depth 8. File sizes are the expected 2,073,600.

I believe I had some other system related issues - nfs/overlays - which had inhibited the correct file from being used.
Post Reply