You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Trac3r-rust/doc/gif/index.html

96 lines
18 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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 `gif` crate."><meta name="keywords" content="rust, rustlang, rust-lang, gif"><title>gif - 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><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="shortcut icon" href="../favicon.ico"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></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><a href='../gif/index.html'><div class='logo-container'><img src='../rust-logo.png' alt='logo'></div></a><p class='location'>Crate gif</p><div class="sidebar-elems"><a id='all-types' href='all.html'><p>See all gif's items</p></a><div class="block items"><ul><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: 'gif', 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"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><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='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/gif/lib.rs.html#1-163' title='goto source code'>[src]</a></span><span class='in-band'>Crate <a class="mod" href=''>gif</a></span></h1><div class='docblock'><h1 id="gif-en--and-decoding-library-build-status" class="section-header"><a href="#gif-en--and-decoding-library-build-status">GIF en- and decoding library <a href="https://travis-ci.org/PistonDevelopers/image-gif"><img src="https://travis-ci.org/PistonDevelopers/image-gif.svg?branch=master" alt="Build Status" /></a></a></h1>
<p>GIF en- and decoder written in Rust (<a href="http://www.piston.rs/image/gif/index.html">API Documentation</a>). </p>
<h1 id="gif-encoding-and-decoding-library" class="section-header"><a href="#gif-encoding-and-decoding-library">GIF encoding and decoding library</a></h1>
<p>This library provides all functions necessary to de- and encode GIF files. </p>
<h2 id="high-level-interface" class="section-header"><a href="#high-level-interface">High level interface</a></h2>
<p>The high level interface consists of the two types
<a href="struct.Encoder.html"><code>Encoder</code></a> and <a href="struct.Decoder.html"><code>Decoder</code></a>.
They as builders for the actual en- and decoders and can be used to set various
options beforehand.</p>
<h3 id="decoding-gif-files" class="section-header"><a href="#decoding-gif-files">Decoding GIF files</a></h3>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="comment">// Open the file</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">gif</span>::<span class="ident">SetParameter</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">decoder</span> <span class="op">=</span> <span class="ident">gif</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/samples/sample_1.gif&quot;</span>).<span class="ident">unwrap</span>());
<span class="comment">// Configure the decoder such that it will expand the image to RGBA.</span>
<span class="ident">decoder</span>.<span class="ident">set</span>(<span class="ident">gif</span>::<span class="ident">ColorOutput</span>::<span class="ident">RGBA</span>);
<span class="comment">// Read the file header</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">decoder</span> <span class="op">=</span> <span class="ident">decoder</span>.<span class="ident">read_info</span>().<span class="ident">unwrap</span>();
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">frame</span>) <span class="op">=</span> <span class="ident">decoder</span>.<span class="ident">read_next_frame</span>().<span class="ident">unwrap</span>() {
<span class="comment">// Process every frame</span>
}</pre></div>
<h3 id="encoding-gif-files" class="section-header"><a href="#encoding-gif-files">Encoding GIF files</a></h3>
<p>The encoder can be used so save simple computer generated images:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">gif</span>::{<span class="ident">Frame</span>, <span class="ident">Encoder</span>, <span class="ident">Repeat</span>, <span class="ident">SetParameter</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">borrow</span>::<span class="ident">Cow</span>;
<span class="kw">let</span> <span class="ident">color_map</span> <span class="op">=</span> <span class="kw-2">&amp;</span>[<span class="number">0xFF</span>, <span class="number">0xFF</span>, <span class="number">0xFF</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>];
<span class="kw">let</span> (<span class="ident">width</span>, <span class="ident">height</span>) <span class="op">=</span> (<span class="number">6</span>, <span class="number">6</span>);
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">beacon_states</span> <span class="op">=</span> [[
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
], [
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">0</span>,
<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>,
]];
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">image</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">&quot;tests/samples/beacon.gif&quot;</span>).<span class="ident">unwrap</span>();;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">encoder</span> <span class="op">=</span> <span class="ident">Encoder</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">image</span>, <span class="ident">width</span>, <span class="ident">height</span>, <span class="ident">color_map</span>).<span class="ident">unwrap</span>();
<span class="ident">encoder</span>.<span class="ident">set</span>(<span class="ident">Repeat</span>::<span class="ident">Infinite</span>).<span class="ident">unwrap</span>();
<span class="kw">for</span> <span class="ident">state</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">beacon_states</span> {
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">frame</span> <span class="op">=</span> <span class="ident">Frame</span>::<span class="ident">default</span>();
<span class="ident">frame</span>.<span class="ident">width</span> <span class="op">=</span> <span class="ident">width</span>;
<span class="ident">frame</span>.<span class="ident">height</span> <span class="op">=</span> <span class="ident">height</span>;
<span class="ident">frame</span>.<span class="ident">buffer</span> <span class="op">=</span> <span class="ident">Cow</span>::<span class="ident">Borrowed</span>(<span class="kw-2">&amp;</span><span class="kw-2">*</span><span class="ident">state</span>);
<span class="ident">encoder</span>.<span class="ident">write_frame</span>(<span class="kw-2">&amp;</span><span class="ident">frame</span>).<span class="ident">unwrap</span>();
}</pre></div>
<p><a href="struct.Frame.html"><code>Frame::from_*</code></a> can be used to convert a true color image to a paletted
image with a maximum of 256 colors:</p>
<div class="example-wrap"><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">// Get pixel data from some source</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">pixels</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">u8</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>; <span class="number">30_000</span>];
<span class="comment">// Create frame from data</span>
<span class="kw">let</span> <span class="ident">frame</span> <span class="op">=</span> <span class="ident">gif</span>::<span class="ident">Frame</span>::<span class="ident">from_rgb</span>(<span class="number">100</span>, <span class="number">100</span>, <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="kw-2">*</span><span class="ident">pixels</span>);
<span class="comment">// Create encoder</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">image</span> <span class="op">=</span> <span class="ident">File</span>::<span class="ident">create</span>(<span class="string">&quot;target/indexed_color.gif&quot;</span>).<span class="ident">unwrap</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">encoder</span> <span class="op">=</span> <span class="ident">gif</span>::<span class="ident">Encoder</span>::<span class="ident">new</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">image</span>, <span class="ident">frame</span>.<span class="ident">width</span>, <span class="ident">frame</span>.<span class="ident">height</span>, <span class="kw-2">&amp;</span>[]).<span class="ident">unwrap</span>();
<span class="comment">// Write frame to file</span>
<span class="ident">encoder</span>.<span class="ident">write_frame</span>(<span class="kw-2">&amp;</span><span class="ident">frame</span>).<span class="ident">unwrap</span>();</pre></div>
<h2 id="c-api" class="section-header"><a href="#c-api">C API</a></h2>
<p>The C API is unstable and widely untested. It can be activated using the feature flag <code>c_api</code>.</p>
</div><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2>
<table><tr class='module-item'><td><a class="struct" href="struct.Decoder.html" title='gif::Decoder struct'>Decoder</a></td><td class='docblock-short'><p>GIF decoder</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Encoder.html" title='gif::Encoder struct'>Encoder</a></td><td class='docblock-short'><p>GIF encoder.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Frame.html" title='gif::Frame struct'>Frame</a></td><td class='docblock-short'><p>A GIF frame</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.MemoryLimit.html" title='gif::MemoryLimit struct'>MemoryLimit</a></td><td class='docblock-short'><p>Memory limit in bytes. <code>MemoryLimit::Some(0)</code> means
that there is no memory limit set.</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.Reader.html" title='gif::Reader struct'>Reader</a></td><td class='docblock-short'><p>GIF decoder</p>
</td></tr><tr class='module-item'><td><a class="struct" href="struct.StreamingDecoder.html" title='gif::StreamingDecoder struct'>StreamingDecoder</a></td><td class='docblock-short'><p>GIF decoder which supports streaming</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.Block.html" title='gif::Block enum'>Block</a></td><td class='docblock-short'><p>Known GIF block types</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ColorOutput.html" title='gif::ColorOutput enum'>ColorOutput</a></td><td class='docblock-short'><p>Output mode for the image data</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Decoded.html" title='gif::Decoded enum'>Decoded</a></td><td class='docblock-short'><p>Indicates whether a certain object has been decoded</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.DecodingError.html" title='gif::DecodingError enum'>DecodingError</a></td><td class='docblock-short'><p>Decoding error.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.DisposalMethod.html" title='gif::DisposalMethod enum'>DisposalMethod</a></td><td class='docblock-short'><p>Disposal method</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Extension.html" title='gif::Extension enum'>Extension</a></td><td class='docblock-short'><p>Known GIF extensions</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.ExtensionData.html" title='gif::ExtensionData enum'>ExtensionData</a></td><td class='docblock-short'><p>Extension data.</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Extensions.html" title='gif::Extensions enum'>Extensions</a></td><td class='docblock-short'><p>Configures how extensions should be handled</p>
</td></tr><tr class='module-item'><td><a class="enum" href="enum.Repeat.html" title='gif::Repeat enum'>Repeat</a></td><td class='docblock-short'><p>Number of repetitions</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.Parameter.html" title='gif::Parameter trait'>Parameter</a></td><td class='docblock-short'><p>Configuration parameter trait.</p>
</td></tr><tr class='module-item'><td><a class="trait" href="trait.SetParameter.html" title='gif::SetParameter trait'>SetParameter</a></td><td class='docblock-short'><p>Implemented for objects that have parameters.</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 = "gif";</script><script src="../aliases.js"></script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>