XPM and read of color "purple"

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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

XPM and read of color "purple"

Post by anthony »

This is an old problem but one that bit me again recently in some image file format conversions...

IM normally uses SVG colorname before X11 colornames.
Unfortunately there are a few colornames that are conflicting between the two color systems
See IM Examples, Color Basices, Color Name Conflicts
http://www.imagemagick.org/Usage/color_ ... _conflicts

The problem...

The XPM image file format must use X11 color names for both read and write, and not SVG colornames.

When reading in a XPM image using of the the conflict colors (such as "purple") for example...

Code: Select all

/* XPM */
static char *purple_xpm[] = {
/* width height ncolors chars_per_pixel */
"1 1 1 1",
/* colors */
"a c purple",
/* pixels */
"a"
};

Code: Select all

convert purple.xpm xpm:-

Code: Select all

/* XPM */
static char *xpm__[] = {
/* columns rows colors chars-per-pixel */
"1 1 1 1 ",
"  c #808000008080",
/* pixels */
" "
};
when reading the "purple" color was read as color #800080" whcih is SVG purple. This is not X11 purple, whcih is "#a020f0", As such it read the color WRONG, and the image did not convert properly.


It is however smart enough to know that when writing not to use SVG "purple" so it output #808000008080"
so the write is good.

Quick test for writing a correct X11 "purple"

Code: Select all

convert xc:'#a020f0' xpm:-
/* XPM */
static char *xpm__[] = {
/* columns rows colors chars-per-pixel */
"1 1 1 1 ",
"  c purple",
/* pixels */
" "
};
So write is good. Just the XPM read of colorname is wrong.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: XPM and read of color "purple"

Post by anthony »

Bump.... No feedback...

Reading "purple" in a XPM image returns a SVG purple, not a X11 Purple.
The write of a X11 purple in XPM image is good. Only read goes bad.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: XPM and read of color "purple"

Post by magick »

Check 6.8.5-0 Beta. It reads X11 purple as expected.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: XPM and read of color "purple"

Post by anthony »

Updated IMv6 (working on IMv7 at the moment)

Generate and read/write....

Code: Select all

convert xc:'#a020f0' xpm:- | tee /dev/tty | convert xpm:- xpm:- 

/* XPM */
static char *xpm__[] = {
/* columns rows colors chars-per-pixel */
"1 1 1 1 ",
"  c purple",
/* pixels */
" "
};

/* XPM */
static char *xpm__[] = {
/* columns rows colors chars-per-pixel */
"1 1 1 1 ",
"  c purple",
/* pixels */
" "
};
The first is what was written, (correct)
the second is a read and write, also now correct.

Check on actual pixel value as being a X11 color for XPM...

Code: Select all

convert xc:'#a020f0' xpm:- | convert xpm:- txt:

# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (41120, 8224,61680)  #A0A02020F0F0  srgb(160,32,240)
Yeap good..

Fix verified.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply