Menu

#4218 read_xpm can't handle XPM files generated by ImageMagick and maybe other sources

None
closed
nobody
5
2023-12-12
2023-11-26
No

read_xpm in the share package draw runs into an error when I try to load an XPM file created by ImageMagick. Looks like the .xpm file contains C comments which are unexpected by read_xpm.

The attached file gcl1.xpm-original is the unmodified ImageMagick output. The attached file gcl1.xpm-modified is the same except comments after the first are removed.

read_xpm successfully reads the modified file but not the original.

Not sure how to fix up read_xpm. Since C code is allowed, images are potentially differently arranged line by line. Given that, one approach is to use the Maxima parser to burn off the first several tokens (calling SCAN-ONE-TOKEN-G) and then parser the remaining array of strings, comments and all (calling MREAD). Possibly then rewrite the string array as XPM2 (non-C, simple data file) and then process that.

2 Attachments

Discussion

  • Tomio Arisaka

    Tomio Arisaka - 2023-12-06

    Thanks for updating read_xpm.

    I checked commit 2a673adf8b6a1a7db80cd7152af0f9b88d6874e4.
    Then I noticed the current version of read_xpm does not support RGB format.
    It means that take_channel, negative_picture, and rgb2level are broken.
    See: https://riotorto.users.sourceforge.net/Maxima/gnuplot/image/index.html

    So I hope that a RGB format picture is created when the color table in the XPM file does not include "None" : )

    By the way,

    The source code of libXpm is here:
    https://xorg.freedesktop.org/archive/individual/lib/libXpm-3.5.17.tar.xz

    It includes some XPM files and the next commands:
    * cxpm : check an XPM file, versions XPM 1, 2, or 3.
    * sxpm : show an XPM file and/or convert XPM 1 or 2 files to XPM 3.

     
  • Robert Dodier

    Robert Dodier - 2023-12-06

    Yeah, I think the way to go is to modify take_channel, etc. to handle rgb + alpha in addition to just rgb. They are pretty simple functions, I think it will be easy.

    I looked at libXpm and also ImageMagick which has functions to handle XPM files, and got some inspiration there. I'm not going to try to handle XPM1 or XPM2; maybe someone else will want to work on it.

     
  • Robert Dodier

    Robert Dodier - 2023-12-12
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2023-12-12

    I fixed the original problem by allowing the XPM parser to handle a wider range of inputs (maybe not all, however, I tried read_xpm on all the 100 or so XPM images on my Linux system and it works as expected for all of them). Also I fixed up the other functions for operations on rgb pictures to work with rgb_alpha as returned by read_xpm.

    For the record one can see the changes I made via git log c13151d..5842e95 -- share/draw.

    Closing this issue as fixed. I'm still planning to update the documentation for the picture functions but that's beyond the scope of this ticket.

     

Log in to post a comment.