Page 1 of 1

Jagged edges after converting to XPM

Posted: 2016-12-02T19:24:55-07:00
by msi
OS: Debian GNU/Linux 8 (Jessie)
ImageMagick version: 6.8.9-9 Q16

I'm trying to put together a reasonably looking Devuan GNU/Linux logo for X Display Manager (XDM) which needs to be in the XPM format. So, I tried using convert to create the xpm file from the original I had compiled with GIMP:

Code: Select all

convert devuan-logo-xdm-purpy.xcf devuan-logo-xdm-purpy.xpm
This works, but the resulting xpm file displays a logo considerably grainy where color borders onto transparency. See here: https://git.devuan.org/devuan-editors/d ... -purpy.xpm

Searching these forums for a solution, I found out that the problem is that "the alpha becomes binary, ie on or off, and loses any graduation".
Now I'm looking for a way to prevent that. I tried tinkering with convert's -alpha parameter already, but that didn't make any visible difference.

Re: Jagged edges after converting to XPM

Posted: 2016-12-02T19:58:21-07:00
by fmw42
There is no way to prevent that with raster images. The best I know is to extract the alpha channel, then blur it slightly so the edges are smooth, then replace the old alpha channel with the new one. This has been covered in the forum recently. You can search to see examples.

Also see
http://www.imagemagick.org/Usage/blur/#feathering
http://www.fmwconcepts.com/imagemagick/ ... composite2

Re: Jagged edges after converting to XPM

Posted: 2016-12-02T20:09:32-07:00
by snibgo
When an image contains continuous transparency but you need to convert it to binary transparency, you can decide what should happen to semi-transparent pixels.

The default action is to threshold the transparency at 50%. Another option is to flatten the image against a particular background colour, eg:

Code: Select all

convert in.png -background White -layers flatten out.xpm
The result will have no transparency. A more complex command will retain full transparency, but only for the pixels that started with full transparency.

Re: Jagged edges after converting to XPM

Posted: 2016-12-09T15:29:22-07:00
by msi
snibgo wrote:A more complex command will retain full transparency, but only for the pixels that started with full transparency.
Right. I'm getting a thin whitish edge around the logo, doing that.
fmw42 wrote:The best I know is to extract the alpha channel, then blur it slightly so the edges are smooth, then replace the old alpha channel with the new one. This has been covered in the forum recently.
Ok, I managed to extract the alpha channel and then blur that with:

Code: Select all

convert -alpha extract devuan-logo-xdm-purpy.xcf devuan-logo-xdm-purpy-alpha.xpm
convert -blur 0x0.4 devuan-logo-xdm-purpy-alpha.xpm devuan-logo-xdm-purpy-alpha-blurred.xpm
There's probably a way to do that in one complex command. But I prefer to do things step by step for now, so I don't get confused.

What I still don't understand is how to actually replace the old alpha channel with the new one. Do I first have to create a version of the image with the alpha channel switched off and then apply the blurred alpha to that? If so, how would the last part be done?

Re: Jagged edges after converting to XPM

Posted: 2016-12-09T16:10:55-07:00
by fmw42
First, proper IM 6 and 7 syntax reads the image first before blurring or any other processing. See http://www.imagemagick.org/Usage/basics/#why

if image1 has an alpha and image2 is the new alpha, then

convert image1 image2 -alpha off -compose copy_opacity -composite result

will replace the old alpha channel with the new one.

See http://www.imagemagick.org/Usage/compose/#copyopacity

Re: Jagged edges after converting to XPM

Posted: 2016-12-10T17:06:48-07:00
by msi
Well, the results of replacing the alpha channel weren't really satisfactory, maybe because I'm still doing something wrong.

Then I thought, what if I simply flattened the image using XDM's standard background color (#bebebe) as the canvas color and then made that transparent again. Sure, there would be greyish edges in the resulting image, but you probably wouldn't recognize that on a #bebebe-colored background. Then I had a good look at the original Debian logo again and saw that it had greyish edges too. So it has probably been created exactly that way.

Now, I simply did this:

Code: Select all

convert devuan-logo-xdm-purpy.tif -background "#bebebe" -flatten devuan-logo-xdm-purpy-pre.xpm
convert devuan-logo-xdm-purpy-pre.xpm -transparent "#bebebe" devuan-logo-xdm-purpy.xpm
The result looks flawless in XDM.

However, the xpm file created by the first command is sometimes being displayed with a grey background darker than #bebebe (e. g. in the thumbnail in my file manager or when I open it in my image viewer). When I opened the file in a text editor, I saw that instead of using the notation "#bebebe", it uses the color name "gray". But "gray" or "grey" in X11 is something else than in the definition of the W3C (see: https://en.wikipedia.org/wiki/X11_color ... lor_scheme). So maybe there's a bug there.