<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://stlab.adobe.com/wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://stlab.adobe.com/wiki/index.php?title=GIL_File_Format_Import/Export_Factory&amp;feed=atom&amp;action=history</id>
		<title>GIL File Format Import/Export Factory - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://stlab.adobe.com/wiki/index.php?title=GIL_File_Format_Import/Export_Factory&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://stlab.adobe.com/wiki/index.php?title=GIL_File_Format_Import/Export_Factory&amp;action=history"/>
		<updated>2013-05-19T19:29:25Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.0</generator>

	<entry>
		<id>http://stlab.adobe.com/wiki/index.php?title=GIL_File_Format_Import/Export_Factory&amp;diff=1431&amp;oldid=prev</id>
		<title>FosterBrereton: initial population</title>
		<link rel="alternate" type="text/html" href="http://stlab.adobe.com/wiki/index.php?title=GIL_File_Format_Import/Export_Factory&amp;diff=1431&amp;oldid=prev"/>
				<updated>2006-06-21T19:19:05Z</updated>
		
		<summary type="html">&lt;p&gt;initial population&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Basic Description==&lt;br /&gt;
&lt;br /&gt;
The GIL IO Factory is intended to be a generic way of:&lt;br /&gt;
* Detecting the image file format of a given file on disk (detection)&lt;br /&gt;
* Loading the image data from an on-disk file into an &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; image or &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; variant (import)&lt;br /&gt;
* Saving an &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; image or &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; variant to a file (of specific format) on-disk (export)&lt;br /&gt;
&lt;br /&gt;
==API==&lt;br /&gt;
&lt;br /&gt;
===Location===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;adobe/gil/extension/io/io_factory.hpp&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===ASL Public Interface===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
template &amp;lt;typename ViewType&amp;gt;&lt;br /&gt;
class image_factory_t&lt;br /&gt;
{&lt;br /&gt;
    typedef ViewType                  view_type;&lt;br /&gt;
    typedef GIL::image&amp;lt;view_type&amp;gt;     image_type;&lt;br /&gt;
    typedef image_format_t&amp;lt;view_type&amp;gt; image_format_type;&lt;br /&gt;
&lt;br /&gt;
    void register_format(const image_format_type&amp;amp; format)&lt;br /&gt;
&lt;br /&gt;
    bool is_registered(adobe::name_t format_tag);&lt;br /&gt;
&lt;br /&gt;
    void unregister_format(adobe::name_t format_tag)&lt;br /&gt;
&lt;br /&gt;
    template &amp;lt;typename O&amp;gt;&lt;br /&gt;
    O detect_all_for(std::streambuf&amp;amp; stream_buffer,&lt;br /&gt;
                     O               output) const;&lt;br /&gt;
&lt;br /&gt;
    adobe::name_t read(image_type&amp;amp;          image,&lt;br /&gt;
                       std::streambuf&amp;amp;      stream_buffer,&lt;br /&gt;
                       adobe::dictionary_t&amp;amp; parameters,&lt;br /&gt;
                       adobe::name_t        format_tag = adobe::name_t())&lt;br /&gt;
&lt;br /&gt;
    void write(const view_type&amp;amp;     image_view,&lt;br /&gt;
               std::streambuf&amp;amp;      stream_buffer,&lt;br /&gt;
               adobe::name_t        format_tag,&lt;br /&gt;
               adobe::dictionary_t  parameters = adobe::dictionary_t())&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Notes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;image_format_t&amp;lt;view_type&amp;gt;&amp;lt;/code&amp;gt; is a runtime-polymorphic API that leverages &amp;lt;code&amp;gt;adobe::regular_object&amp;lt;/code&amp;gt; under the hood to maintain a list of possible io format factories. This gives each factory the ability to be implemented separately from the IO factory as a whole, who then can be registered with the factory with no intrusiveness into the module's implementation.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;register_format&amp;lt;/code&amp;gt; takes an &amp;lt;code&amp;gt;adobe::regular_object&amp;lt;/code&amp;gt;-wrapped IO factory module and stores it as a candidate for future file detection, reading and writing. Each &amp;lt;code&amp;gt;image_format_t&amp;lt;/code&amp;gt; registered with the IO factory needs to have a unique tag (stored as an &amp;lt;code&amp;gt;adobe::name_t&amp;lt;/code&amp;gt;) for identification purposes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;is_registered&amp;lt;/code&amp;gt; will return whether or not an IO factory module has already been registered under a specified tag name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;unregister_format&amp;lt;/code&amp;gt; will disconnect the IO factory module registered under a specified tag name from the IO factory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;detect_all_for&amp;lt;/code&amp;gt; is a means by which one can obtain all the possible registered IO module tags for which the &amp;lt;code&amp;gt;detect&amp;lt;/code&amp;gt; call over a specified stream returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. These tags can be used later to perform &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; operations using a specific registered IO module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt; will take in image data from a std::streambuf and inject it into an &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; image as specified by the template type of the IO factory. The &amp;lt;code&amp;gt;format_tag&amp;lt;/code&amp;gt; parameter can be used to explicitly identify the UI module the client would like to use in order to perform the read operation. In the case when this is not supplied, the IO factory will first traverse the list of IO modules for the first candidate for whom their &amp;lt;code&amp;gt;detect&amp;lt;/code&amp;gt; API returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;, and use that module for the read. The &amp;lt;code&amp;gt;parameters&amp;lt;/code&amp;gt; parameter is an &amp;lt;code&amp;gt;adobe::dictionary_t&amp;lt;/code&amp;gt; that, upon return, will contain metadata about the file that was read. The contents of this dictionary are implementation-defined according to the IO module specification. The return value of the &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt; API will be the tag of the IO module used to perform the read.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;write&amp;lt;/code&amp;gt; will take in image data from an &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; image and inject it into a &amp;lt;code&amp;gt;std::streambuf&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;format_tag&amp;lt;/code&amp;gt; parameter can be used to explicitly identify the UI module the client would like to use in order to perform the write operation, and is required. The &amp;lt;code&amp;gt;parameters&amp;lt;/code&amp;gt; parameter is an &amp;lt;code&amp;gt;adobe::dictionary_t&amp;lt;/code&amp;gt; that can be used to supply metadata to the IO module to assist in saving the file format.&lt;br /&gt;
&lt;br /&gt;
When the &amp;lt;code&amp;gt;image_factory_t::read&amp;lt;/code&amp;gt; API is invoked, the factory will iterate through the registered file format IO modules to find the first one whose &amp;lt;code&amp;gt;detect&amp;lt;/code&amp;gt; function returns &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. Once this candidate is found, it is given the path to the file on which the import needs to be done, and the IO module returns the &amp;lt;code&amp;gt;adobe::gil&amp;lt;/code&amp;gt; image as a result. This result can then be fed into the &amp;lt;code&amp;gt;adobe::image_t&amp;lt;/code&amp;gt; widget.&lt;br /&gt;
&lt;br /&gt;
==Issues and Future Considerations==&lt;br /&gt;
&lt;br /&gt;
* Can the IO Factory leverage GIL more throughly?&lt;br /&gt;
* What about file metadata?&lt;br /&gt;
** We might be able to leverage XMP for that&lt;br /&gt;
** Can we preserve what's in the file so that round-trips through the IO Factory don't strip the metadata out?&lt;br /&gt;
* What about parameter blocks for scripting import/export?&lt;br /&gt;
** What about the case when more information is needed than what the param block provides?&lt;br /&gt;
** We might be able to leverage the ASL modal dialog interface for that&lt;br /&gt;
* The detect call should return an adobe::dictionary_t filled with metadata discovered about the image during the time of detection, if applicable. The contents of the adobe::dictionary_t are implementation-defined based on the io module that handled the detection. A common set of keys should be defined to help the client of the IO factory discern what metadata values are present. Keys might be some of:&lt;br /&gt;
** height&lt;br /&gt;
** width&lt;br /&gt;
** bits_per_channel&lt;br /&gt;
** bits_per_pixel&lt;br /&gt;
** xmp (and/or other metadata format names (exif, etc.))&lt;br /&gt;
** channel_count&lt;br /&gt;
** colorspace (with specific valid enumerations as possible values)&lt;br /&gt;
* The IO Factory needs to be templated based on the ImageType, not the ViewType, of the image format with which we are dealing. This is because the ViewType can be derived from the ImageType, but not the other way around.&lt;br /&gt;
* We should move away from &amp;lt;code&amp;gt;std::streambuf&amp;lt;/code&amp;gt; in the API and to &amp;lt;code&amp;gt;boost::filesystem::path&amp;lt;/code&amp;gt;, as some IO modules will have internal libraries that want file names to open, not buffers from which to read. By &amp;lt;code&amp;gt;using boost::filesystem::path&amp;lt;/code&amp;gt; we concede to a specification that is a superset over std::streambuf.&lt;br /&gt;
* The file's extension should also be passed through the API (NOTE: this will be fixed by the fix to migrate from std::streambuf to boost::filesystem::path.)&lt;/div&gt;</summary>
		<author><name>FosterBrereton</name></author>	</entry>

	</feed>