File format detection problem

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
epi
Posts: 5
Joined: 2011-04-04T13:36:26-07:00
Authentication code: 8675308

File format detection problem

Post by epi »

Hi,
I'm developing an ImageMagick coder for decoding Atari XL/XE images (sources and example images are at http://fail.sourceforge.net/), which handles about 50 different (sometimes rare) image formats. Some file name extensions that are supported by FAIL coder (they are registered in the coder.xml file) are also supported by other coders, installed with standard installation of IM. This causes conflicts when I try to open files like RGB, CIN or CCI, for example:

Code: Select all

display: must specify image size `ASTROS.RGB' @ error/rgb.c/ReadRGBImage/142.
display: length and filesize do not match `DRACONUS.CCI' @ error/bmp.c/ReadBMPImage/785.
display: static planes value not equal to 1 `DRACONUS.CCI' @ error/bmp.c/ReadBMPImage/797.
display: length and filesize do not match `KILLER.CCI' @ error/bmp.c/ReadBMPImage/785.
display: negative or zero image size `KILLER.CCI' @ error/bmp.c/ReadBMPImage/793.
display: improper image header `TITUS.CIN' @ error/cin.c/ReadCINImage/443.
display: improper image header `VIDOL_DUPLAND.CIN' @ error/cin.c/ReadCINImage/443.
Oddly enough, they are opened correctly if I specify also a file in an unambiguously identified format in display's command line, e.g.:

Code: Select all

$ display COYOTE.RIP ASTROS.RGB
(displays COYOTE.RIP, then I press space bar, then it displays ASTROS.RGB without errors)

Is it possible to make IM retry opening file with other coders if it fails to open it with the first one?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: File format detection problem

Post by magick »

One solution is to use an explicit format. Assume your coder is Atari, your command then becomes:
  • display atari:ASTROS.RGB
However, ImageMagick should detect its in the Atari format if you include a IsArari() method in your coder and register it with
  • entry->magick=(IsImageFormatHandler *) IsAtari;
The method returns MagickTrue if the the signature is unique and matches the Atari image file format signature.
epi
Posts: 5
Joined: 2011-04-04T13:36:26-07:00
Authentication code: 8675308

Re: File format detection problem

Post by epi »

Thanks for the answer.
My coder uses module name "FAIL" (First Atari Image Library), and the function is "IsFAIL". However, it doesn't get called (neither do analogous functions in other coders, like IsBMP or IsCIN), at least when using display.

Using explicit format as you suggested also does not work (or am I doing something wrong?):

Code: Select all

$ display TITUS.CIN 
display: improper image header `TITUS.CIN' @ error/cin.c/ReadCINImage/443.
$ display fail:TITUS.CIN 
display: no decode delegate for this image format `TITUS.CIN' @ error/constitute.c/ReadImage/532.
$ display FAIL:TITUS.CIN 
display: no decode delegate for this image format `TITUS.CIN' @ error/constitute.c/ReadImage/532.
$ display Fail:TITUS.CIN 
display: no decode delegate for this image format `TITUS.CIN' @ error/constitute.c/ReadImage/532.
$ display COYOTE.RIP TITUS.CIN
(space bar in the display window opened after the last command causes TITUS.CIN to be displayed, as expected).

Another thing is that "identify -list format" does not show formats supported by my coder. Is this what I should expect? Or do I have to register it somewhere else besides the coder.xml file?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: File format detection problem

Post by magick »

Your coder must be declared in magick/static.h and called from magic/static.c. You must also add your coder to coders/Makefile.am and regenerate the Makefiles. If you have a dynamic build, make sure your coder is in the modules folder normally @ /usr/local/lib/ImageMagick-6.7.4-0/modules-Q16/coders.
epi
Posts: 5
Joined: 2011-04-04T13:36:26-07:00
Authentication code: 8675308

Re: File format detection problem

Post by epi »

I'm trying only with dynamic build. Coder path is what you gave, and, as I mentioned at the beginning, most formats are detected properly. The problem exists only for extensions that are supported by other coders, i.e. CIN (coders/cin.c), CCI (coders/bmp.c), RGB (coders/rgb.c).
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: File format detection problem

Post by magick »

For now, use an explicit format, eg. fail:titus.cin. We have a few hard-coded disambiguation filters in ImageMagick. We currently do not have a configurable disambiguation filter framework. It is something we would need to write and include in a future version of ImageMagick.
Post Reply