6
$\begingroup$

Mathematica includes RegisterImport to setup custom functions which read and translate file data for Import, effectively allowing it to be extended for any format. One can get a list of information that Import can return for a file type like so:

Import["ExampleData/lena.tif", {"TIFF", "Elements"}]
(* {Animation,Author,BitDepth,CameraTopOrientation,<<22>>,Thumbnail,ThumbnailList,TileSize} *)

This listing behavior is set up automatically by RegisterImport for correctly specified elements.

Options for functions registered to Import can be set up in the standard way and passed through the options given to the Import command:

Import["ExampleData/lena.tif", {"TIFF", "Image"}, ImageSize -> Tiny]

There's a similar syntax to see available options specific to the specified file format:

Import["ExampleData/lena.tif", {"TIFF", "Options"}]
(* {"BitDepth" -> 8, "ColorSpace" -> RGBColor, "Comments" -> None, "ImageSize" -> {150, 116}} *)

What needs to be done so that options for user-specified functions registered to Import appear in this listing?

So far I haven't been able to find any help docs or discussion on this topic.

$\endgroup$
  • $\begingroup$ Interesting question. It appears that the element "Options" is itself reserved, i.e. returning element rules like {"dummy" -> 1, "Options" -> Options[foo`import]} does not work, whereas {"dummy" -> 1, "Opts" -> Options[foo`import]} works for "Opts". $\endgroup$ – Mr.Wizard Dec 12 '16 at 10:03
  • $\begingroup$ @Mr.Wizard Yes, the call to RegisterImport seems to set up "Rules", "Elements", and "Options" on it own based on input. I think "Rules" comes from the default function (specified in the call to RegisterImport), but I don't see where "Options" come in. $\endgroup$ – dionys Dec 12 '16 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.