2
0
mirror of https://github.com/boostorg/gil.git synced 2026-01-23 17:42:30 +00:00
Files
gil/develop/doc/html/reference/iobackend.html
github-actions[bot] 3b73200ee1 deploy: 49d9276706
2025-04-04 16:28:54 +00:00

116 lines
9.4 KiB
HTML

<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Generic Image Library: Adding a new io backend</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-boost.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="boost-header">
<table border="0" cellpadding="7" cellspacing="0" width="100%" summary="header">
<tr>
<td valign="top" width="300">
<h3><a href="../index.html"><img alt="Boost GIL" src="../_static/gil.png" border="0"></a></h3>
</td>
<td ><h1 align="center"><a href="../index.html"></a></h1></td>
<td></td>
</tr>
</table>
</div>
<hr/>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',false,false,'search.php','Search');
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div><div class="header">
<div class="headertitle"><div class="title">Adding a new io backend</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="Overview"></a>
of backend requirements</h1>
<p>To add support for a new IO backend the following is required:</p><ul>
<li>a format tag, to identify the image format, derived from boost::gil::format_tag</li>
<li>boolean meta function is_supported&lt;PixelType,FormatTag&gt; must be implemented for the new format tag</li>
<li>explicit specialisation of image_read_info&lt;FormatTag&gt; must be provided, containing runtime information available before/at reading the image</li>
<li>explicit specialisation of image_write_info&lt;FormatTag&gt; must be provided, containing runtime encoding parameters for writing an image</li>
<li>An image reader must be specialized: <div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> IODevice, <span class="keyword">typename</span> ConversionPolicy&gt;</div>
<div class="line"><span class="keyword">struct </span>boost::gil::reader&lt;IODevice,FormatTag,ConversionPolicy&gt;</div>
<div class="line">{</div>
<div class="line"> reader( IODevice &amp; device )</div>
<div class="line"> reader( IODevice &amp; device, <span class="keyword">typename</span> ConversionPolicy::color_converter_type <span class="keyword">const</span>&amp; cc )</div>
<div class="line"> image_read_info&lt;FormatTag&gt; get_info();</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Image&gt;</div>
<div class="line"> <span class="keywordtype">void</span> <a class="code hl_function" href="group___i_o.html#ga1aa312515256348fcddcebc511971c37">read_image</a>( Image &amp;, point_t <span class="keyword">const</span>&amp; top_left );</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt;</div>
<div class="line"> <span class="keywordtype">void</span> <a class="code hl_function" href="group___i_o.html#gada0413c88413608f4f982ff50edfe0ab">read_view</a>( View &amp;, point_t <span class="keyword">const</span>&amp; top_left );</div>
<div class="line">};</div>
<div class="ttc" id="agroup___i_o_html_ga1aa312515256348fcddcebc511971c37"><div class="ttname"><a href="group___i_o.html#ga1aa312515256348fcddcebc511971c37">boost::gil::read_image</a></div><div class="ttdeci">void read_image(Reader reader, Image &amp;img, typename std::enable_if&lt; mp11::mp_and&lt; detail::is_reader&lt; Reader &gt;, is_format_tag&lt; typename Reader::format_tag_t &gt;, is_read_supported&lt; typename get_pixel_type&lt; typename Image::view_t &gt;::type, typename Reader::format_tag_t &gt; &gt;::value &gt;::type *=nullptr)</div><div class="ttdoc">Reads an image without conversion. Image memory is allocated.</div><div class="ttdef"><b>Definition</b> read_image.hpp:32</div></div>
<div class="ttc" id="agroup___i_o_html_gada0413c88413608f4f982ff50edfe0ab"><div class="ttname"><a href="group___i_o.html#gada0413c88413608f4f982ff50edfe0ab">boost::gil::read_view</a></div><div class="ttdeci">void read_view(Reader reader, View const &amp;view, typename std::enable_if&lt; mp11::mp_and&lt; detail::is_reader&lt; Reader &gt;, typename is_format_tag&lt; typename Reader::format_tag_t &gt;::type, typename is_read_supported&lt; typename get_pixel_type&lt; View &gt;::type, typename Reader::format_tag_t &gt;::type &gt;::value &gt;::type *=nullptr)</div><div class="ttdoc">Reads an image view without conversion. No memory is allocated.</div><div class="ttdef"><b>Definition</b> read_view.hpp:31</div></div>
</div><!-- fragment --></li>
<li>An image writer must be specialized: <div class="fragment"><div class="line">\<span class="keyword">template</span> &lt;<span class="keyword">typename</span> IODevice&gt;</div>
<div class="line"><span class="keyword">struct </span>boost::gil::writer&lt;IODevice,FormatTag&gt;</div>
<div class="line">{</div>
<div class="line"> writer( IODevice &amp; device )</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt;</div>
<div class="line"> <span class="keywordtype">void</span> apply( View <span class="keyword">const</span>&amp;, point_t <span class="keyword">const</span>&amp; top_left );</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> View&gt;</div>
<div class="line"> <span class="keywordtype">void</span> apply( View <span class="keyword">const</span>&amp;, point_t <span class="keyword">const</span>&amp; top_left, image_write_info&lt;FormatTag&gt; <span class="keyword">const</span>&amp; );</div>
<div class="line">};</div>
</div><!-- fragment --></li>
</ul>
<p>Or instead of the items above implement overloads of read_view, read_and_convert_view, read_image, read_and_convert_image, write_view and read_image_info.</p>
<h1><a class="anchor" id="ConversionPolicy"></a>
Interface of the ConversionPolicy</h1>
<p>There are two different conversion policies in use, when reading images: read_and_convert&lt;ColorConverter&gt; and read_and_no_convert. ColorConverter can be a user defined color converter.</p>
<div class="fragment"><div class="line"><span class="keyword">struct </span>ConversionPolicy</div>
<div class="line">{</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> InputIterator,<span class="keyword">typename</span> OutputIterator&gt;</div>
<div class="line"> <span class="keywordtype">void</span> read( InputIterator in_begin, InputIterator in_end,</div>
<div class="line"> OutputIterator out_end );</div>
<div class="line">};</div>
</div><!-- fragment --><p>Methods like read_view and read_image are supposed to bail out with an exception instead of converting the image</p>
<h1><a class="anchor" id="IODevice"></a>
Concept of IO Device</h1>
<p>A Device is simply an object used to read and write data to and from a stream. The IODevice was added as a template parameter to be able to replace the file_name access functionality. This is only an interim solution, as soon as boost provides a good IO library, interfaces/constraints provided by that library could be used.</p>
<div class="fragment"><div class="line"><span class="keyword">concept </span>IODevice</div>
<div class="line">{</div>
<div class="line"> void IODevice::read( unsigned char* data, int count );</div>
<div class="line"> void IODevice::write( unsigned char* data, int count );</div>
<div class="line"> void IODevice::seek(long count, int whence);</div>
<div class="line"> void IODevice::flush();</div>
<div class="line">};</div>
</div><!-- fragment --><p>For the time being a boolean meta function must be specialized: </p><div class="fragment"><div class="line"><span class="keyword">namespace </span><a class="code hl_namespace" href="namespaceboost.html">boost</a>{<span class="keyword">namespace </span>gil{<span class="keyword">namespace </span>detail{</div>
<div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Device&gt;</div>
<div class="line"> <span class="keyword">struct </span>detail::is_input_device;</div>
<div class="line">}}}</div>
<div class="ttc" id="anamespaceboost_html"><div class="ttname"><a href="namespaceboost.html">boost</a></div><div class="ttdoc">defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)</div><div class="ttdef"><b>Definition</b> algorithm.hpp:36</div></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<hr class="footer"/>
<address class="footer">
<small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">doxygen</a> 1.9.8
</small>
</address>
</body>
</html>