New to this.
Need to convert a PNG image (of a mouse cursor, 32x32 pixels) into two C arrays, one with just the Alpha, and one with the RGB8.
How do I get just the Alpha into one .h file, and just the RGB into the other .h file?
I have tried: convert foo.png -channel RGB foo_rgb.h
I have tried: convert foo.png -channel ALPHA foo_a.h
Thanks!
Using: Centos 6.5, Code::Blocks 98xx, wxWidgets 2.8.12, ImageMagick 6.5.4-7
Convert PNG to C Source .h file
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert PNG to C Source .h file
Note: I am not a software engineer so I am not sure if you want ASCII or binary data. If ASCII, then I think you will need to convert the image to txt: format and then extract the channels as you need them as ASCII. Or separate the alpha channel from the image and write them NetPBM format -- the alpha to ASCII pgm and the rgb to ASCII ppm.
To separate the alpha channel use
convert image -alpha extract P2:image.pgm
convert image -alpha off P3:image.ppm
see
http://netpbm.sourceforge.net/doc/ppm.html
http://netpbm.sourceforge.net/doc/pgm.html
http://www.imagemagick.org/Usage/files/#txt
EDIT: the P2: and P3: prefix to these outputs do not seem to work. I was sure there was a way to force the PBM images to ascii format.
If you want just binary data (no headers), I believe you can use .gray and .rgb
convert image -alpha extract GRAY:alpha.gray
convert image -alpha off RGB:rgb.rgb
see http://www.imagemagick.org/script/formats.php (the prefixes may not be necessary).
To separate the alpha channel use
convert image -alpha extract P2:image.pgm
convert image -alpha off P3:image.ppm
see
http://netpbm.sourceforge.net/doc/ppm.html
http://netpbm.sourceforge.net/doc/pgm.html
http://www.imagemagick.org/Usage/files/#txt
EDIT: the P2: and P3: prefix to these outputs do not seem to work. I was sure there was a way to force the PBM images to ascii format.
If you want just binary data (no headers), I believe you can use .gray and .rgb
convert image -alpha extract GRAY:alpha.gray
convert image -alpha off RGB:rgb.rgb
see http://www.imagemagick.org/script/formats.php (the prefixes may not be necessary).
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert PNG to C Source .h file
You'll need to check this, but I think:
The second gives one byte per pixel, ie PNM "P5".
(Your version of IM is very old. Very very old.)
Code: Select all
convert in.png out_rgb.h
Code: Select all
convert in.png -alpha extract out_alpha.h
(Your version of IM is very old. Very very old.)
"-compress none".fmw42 wrote:I was sure there was a way to force the PBM images to ascii format.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert PNG to C Source .h file
Thanks. That was it. I will modify the IM formats page to add this note.snibgo wrote:"-compress none".
Is there documentation on using .h suffix to get PBM format images?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert PNG to C Source .h file
I'm fairly sure .h is documented somewhere, but I can't find where. Maybe it isn't.
It isn't on the pages you linked to, nor "convert -list format". It should be.
It isn't on the pages you linked to, nor "convert -list format". It should be.
snibgo's IM pages: im.snibgo.com
Re: Convert PNG to C Source .h file
Thanks folks. I appreciate the help. As a follow up, how would I mogrify multiple png files into a single .h? And did anyone find the documentation support for .h output?
mogrify -format h *.png
... creates one .h for each png. This is time consuming.
Thanks again!]]
centos 6.5 (which is where IM is built into command line, which is why it's such an old build)
Code::Blocks
wxWidgetpalooza
PB&J.
mogrify -format h *.png
... creates one .h for each png. This is time consuming.
Thanks again!]]
centos 6.5 (which is where IM is built into command line, which is why it's such an old build)
Code::Blocks
wxWidgetpalooza
PB&J.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert PNG to C Source .h file
mogrify only works by reading one image at a time and outputting one image for each input image.
What do you mean by reading multiple images and writing out only one? How do you want to combine the output images from each input image? Do you want layers/frames/pages in one file or do you want to append all the images side-by-side?
What do you mean by reading multiple images and writing out only one? How do you want to combine the output images from each input image? Do you want layers/frames/pages in one file or do you want to append all the images side-by-side?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert PNG to C Source .h file
I don't know about montage[*]. With convert, you can:
to get two images inside one H file, but then you have a name clash within abcd.h.
[*]EDIT: I meant mogrify. Sorry.
Code: Select all
convert bw*.png h:- >abcd.h
[*]EDIT: I meant mogrify. Sorry.
snibgo's IM pages: im.snibgo.com