Page 1 of 1

Problem converting grayscale PNG to XPM

Posted: 2013-10-14T06:06:42-07:00
by lithopsian
I have some icons in PNG format and many of them are greyscale with transparency. They are entirely compatible with ImageMagick and I've run them through mogrify which saved them as "grayscale+alpha". Here is an example:
http://nartowicz.webspace.virginmedia.com/vcard.png

When I attempt to mogrify these to XPM files, a bizarre file is created like this:
http://nartowicz.webspace.virginmedia.com/vcard.xpm

It apparently has a full palette, but everything colour is black, except for the first pixel. Although it conforms to the basic XPM file format, it does not represent the icon image from the PNG file. It can be displayed, but is entirely black except for the first pixel. mogrify to XPM works on those icons that are saved in an RGB PNG format, but forcing the PNG file into RGB format before converting to XPM doesn't help, it is still saved in the odd format.

Verbose output is:

Code: Select all

vcard.png PNG 16x16 16x16+0+0 8-bit DirectClass 107B 0.000u 0:00.000
vcard.png=>vcard.xpm PNG 16x16 16x16+0+0 8-bit PaletteBilevelAlpha PseudoClass 256c 4.1KB 0.000u 0:00.000

Re: Problem converting grayscale PNG to XPM

Posted: 2013-10-14T06:25:58-07:00
by snibgo
On IM v6.8.7-0 on Windows 7, "convert vcard.png vcard.xpm" gives the following result, which looks correct to me:

Code: Select all

/* XPM */
static char *vcard[] =
/* columns rows colors
"16 16 2 1 ",
"  c black",
". c None",
/* pixels */
"................",
"................",
"................",
"..      ........",
".        .......",
"   ....         ",
"  ......        ",
"  ..   .......  ",
"  ............  ",
"  ..  .   ....  ",
"  ............  ",
"  ............  ",
"                ",
"                ",
"................",
"................"
};
What version IM are you on? If older than 6.8.7, an upgrade might fix the problem.

Re: Problem converting grayscale PNG to XPM

Posted: 2013-10-14T08:20:19-07:00
by lithopsian
Looks about right. I'm on Debian using IM 6.7.7. I tried to grab 6.8.5 from the Debian experimental repository but It had too many unmet dependencies to be practical. The other alternative would be to compile from source, but I'm not that desperate. I am able to convert files using Gimp and script-fu, but it isn't quite as convenient. Ubuntu is even worse which is unusual. Even their pre-release Saucy is stuck on 6.7.7.

If this has been fixed in the latest version, then so be it. The difficulty appears to be related to setting the alpha threshold on greyscale (and indexed?) files to meet the all-or-nothing transparency requirement for XPM files.

Re: Problem converting grayscale PNG to XPM

Posted: 2013-10-14T08:38:05-07:00
by snibgo
Testing some old versions I happen to have: v6.6.2 returns a bad result (like yours, just the top-left is transparent), and v6.7.9 and onwards return a good result.

Re: Problem converting grayscale PNG to XPM

Posted: 2013-10-14T16:37:22-07:00
by lithopsian
snibgo wrote:Testing some old versions I happen to have: v6.6.2 returns a bad result (like yours, just the top-left is transparent), and v6.7.9 and onwards return a good result.
Oh, I'm so close :lol: