2018-10-28 21:14:05 -05:00

202 lines
17 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `png` crate."><meta name="keywords" content="rust, rustlang, rust-lang, png"><title>png - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../dark.css"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script src="../storage.js"></script></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><p class='location'>Crate png</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#traits">Traits</a></li></ul></div><p class='location'></p><script>window.sidebarCurrent = {name: 'png', ty: 'mod', relpath: '../'};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press S to search, ? for more options…" type="search"><a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Crate <a class="mod" href=''>png</a></span><span class='out-of-band'><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../src/png/lib.rs.html#1-64' title='goto source code'>[src]</a></span></h1><div class='docblock'><h1 id="png-encoder-and-decoder" class="section-header"><a href="#png-encoder-and-decoder">PNG encoder and decoder</a></h1>
<p>This crate contains a PNG encoder and decoder. It supports reading of single lines or whole frames.</p>
<h2 id="the-decoder" class="section-header"><a href="#the-decoder">The decoder</a></h2>
<p>The most important types for decoding purposes are <a href="struct.Decoder.html"><code>Decoder</code></a> and
<a href="struct.Reader.html"><code>Reader</code></a>. They both wrap a <code>std::io::Read</code>.
<code>Decoder</code> serves as a builder for <code>Reader</code>. Calling <code>Decoder::read_info</code> reads from the <code>Read</code> until the
image data is reached.</p>
<h3 id="using-the-decoder" class="section-header"><a href="#using-the-decoder">Using the decoder</a></h3>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">File</span>;
<span class="comment">// The decoder is a build for reader and can be used to set various decoding options</span>
<span class="comment">// via `Transformations`. The default output transformation is `Transformations::EXPAND</span>
<span class="comment">// | Transformations::STRIP_ALPHA`.</span>
<span class="kw">let</span> <span class="ident">decoder</span> <span class="op">=</span> <span class="ident">png</span>::<span class="ident">Decoder</span>::<span class="ident">new</span>(<span class="ident">File</span>::<span class="ident">open</span>(<span class="string">&quot;tests/pngsuite/basi0g01.png&quot;</span>).<span class="ident">unwrap</span>());
<span class="kw">let</span> (<span class="ident">info</span>, <span class="kw-2">mut</span> <span class="ident">reader</span>) <span class="op">=</span> <span class="ident">decoder</span>.<span class="ident">read_info</span>().<span class="ident">unwrap</span>();
<span class="comment">// Allocate the output buffer.</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buf</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>; <span class="ident">info</span>.<span class="ident">buffer_size</span>()];
<span class="comment">// Read the next frame. Currently this function should only called once.</span>
<span class="comment">// The default options</span>
<span class="ident">reader</span>.<span class="ident">next_frame</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">buf</span>).<span class="ident">unwrap</span>();</pre>
<h2 id="encoder" class="section-header"><a href="#encoder">Encoder</a></h2><h3 id="using-the-encoder" class="section-header"><a href="#using-the-encoder">Using the encoder</a></h3>
<div class='information'><div class='tooltip ignore'><span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
<span class="comment">// For reading and opening files</span>
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">path</span>::<span class="ident">Path</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>::<span class="ident">File</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>::<span class="ident">BufWriter</span>;
<span class="comment">// To use encoder.set()</span>
<span class="kw">use</span> <span class="ident">png</span>::<span class="ident">HasParameters</span>;
<span class="kw">let</span> <span class="ident">path</span> <span class="op">=</span> <span class="ident">Path</span>::<span class="ident">new</span>(<span class="string">r&quot;/path/to/image.png&quot;</span>);
<span class="kw">let</span> <span class="ident">file</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">create</span>(<span class="ident">path</span>).<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="kw-2">ref</span> <span class="kw-2">mut</span> <span class="ident">w</span> <span class="op">=</span> <span class="ident">BufWriter</span>::<span class="ident">new</span>(<span class="ident">file</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">encoder</span> <span class="op">=</span> <span class="ident">png</span>::<span class="ident">Encoder</span>::<span class="ident">new</span>(<span class="ident">w</span>, <span class="number">2</span>, <span class="number">1</span>); <span class="comment">// Width is 2 pixels and height is 1.</span>
<span class="ident">encoder</span>.<span class="ident">set</span>(<span class="ident">png</span>::<span class="ident">ColorType</span>::<span class="ident">RGBA</span>).<span class="ident">set</span>(<span class="ident">png</span>::<span class="ident">BitDepth</span>::<span class="ident">Eight</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">writer</span> <span class="op">=</span> <span class="ident">encoder</span>.<span class="ident">write_header</span>().<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="ident">data</span> <span class="op">=</span> [<span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>]; <span class="comment">// An array containing a RGBA sequence. First pixel is red and second pixel is black.</span>
<span class="ident">writer</span>.<span class="ident">write_image_data</span>(<span class="kw-2">&amp;</span><span class="ident">data</span>).<span class="ident">unwrap</span>(); <span class="comment">// Save</span></pre>
</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2>
<table>
<tr class=' module-item'>
<td><a class="mod" href="chunk/index.html"
title='mod png::chunk'>chunk</a></td>
<td class='docblock-short'>
<p>Chunk types and functions</p>
</td>
</tr></table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table>
<tr class=' module-item'>
<td><a class="struct" href="struct.AnimationControl.html"
title='struct png::AnimationControl'>AnimationControl</a></td>
<td class='docblock-short'>
<p>Animation control information</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Decoder.html"
title='struct png::Decoder'>Decoder</a></td>
<td class='docblock-short'>
<p>PNG Decoder</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Encoder.html"
title='struct png::Encoder'>Encoder</a></td>
<td class='docblock-short'>
<p>PNG Encoder</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.FrameControl.html"
title='struct png::FrameControl'>FrameControl</a></td>
<td class='docblock-short'>
<p>Frame control information</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Info.html"
title='struct png::Info'>Info</a></td>
<td class='docblock-short'>
<p>PNG info struct</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.OutputInfo.html"
title='struct png::OutputInfo'>OutputInfo</a></td>
<td class='docblock-short'>
<p>Output info</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.PixelDimensions.html"
title='struct png::PixelDimensions'>PixelDimensions</a></td>
<td class='docblock-short'>
<p>Pixel dimensions information</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Reader.html"
title='struct png::Reader'>Reader</a></td>
<td class='docblock-short'>
<p>PNG reader (mostly high-level interface)</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.StreamingDecoder.html"
title='struct png::StreamingDecoder'>StreamingDecoder</a></td>
<td class='docblock-short'>
<p>PNG StreamingDecoder (low-level interface)</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Transformations.html"
title='struct png::Transformations'>Transformations</a></td>
<td class='docblock-short'>
<p>Output transformations</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="struct" href="struct.Writer.html"
title='struct png::Writer'>Writer</a></td>
<td class='docblock-short'>
<p>PNG writer</p>
</td>
</tr></table><h2 id='enums' class='section-header'><a href="#enums">Enums</a></h2>
<table>
<tr class=' module-item'>
<td><a class="enum" href="enum.BitDepth.html"
title='enum png::BitDepth'>BitDepth</a></td>
<td class='docblock-short'>
<p>Bit depth of the png file</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.ColorType.html"
title='enum png::ColorType'>ColorType</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.Decoded.html"
title='enum png::Decoded'>Decoded</a></td>
<td class='docblock-short'>
<p>Result of the decoding process</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.DecodingError.html"
title='enum png::DecodingError'>DecodingError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.EncodingError.html"
title='enum png::EncodingError'>EncodingError</a></td>
<td class='docblock-short'>
</td>
</tr>
<tr class=' module-item'>
<td><a class="enum" href="enum.Unit.html"
title='enum png::Unit'>Unit</a></td>
<td class='docblock-short'>
<p>Physical unit of the pixel dimensions</p>
</td>
</tr></table><h2 id='traits' class='section-header'><a href="#traits">Traits</a></h2>
<table>
<tr class=' module-item'>
<td><a class="trait" href="trait.HasParameters.html"
title='trait png::HasParameters'>HasParameters</a></td>
<td class='docblock-short'>
<p>Object has parameters</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class="trait" href="trait.Parameter.html"
title='trait png::Parameter'>Parameter</a></td>
<td class='docblock-short'>
<p>Configuration parameter trait</p>
</td>
</tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd></kbd></dt><dd>Move up in search results</dd><dt><kbd></kbd></dt><dd>Move down in search results</dd><dt><kbd></kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../";window.currentCrate = "png";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>