Problem converting grayscale PNG to XPM

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
lithopsian
Posts: 3
Joined: 2013-10-14T05:54:32-07:00
Authentication code: 6789

Problem converting grayscale PNG to XPM

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

Re: Problem converting grayscale PNG to XPM

Post 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.
snibgo's IM pages: im.snibgo.com
lithopsian
Posts: 3
Joined: 2013-10-14T05:54:32-07:00
Authentication code: 6789

Re: Problem converting grayscale PNG to XPM

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

Re: Problem converting grayscale PNG to XPM

Post 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.
snibgo's IM pages: im.snibgo.com
lithopsian
Posts: 3
Joined: 2013-10-14T05:54:32-07:00
Authentication code: 6789

Re: Problem converting grayscale PNG to XPM

Post 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:
Post Reply