blob: 2e3a940179ab65feb5aab4b2faafe5742db7ea71 [file] [log] [blame]
<!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="Overview"><meta name="keywords" content="rust, rustlang, rust-lang, image"><title>image - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../image/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../image/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate image</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.23.14</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#reexports">Re-exports</a></li><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><li><a href="#functions">Functions</a></li><li><a href="#types">Type Definitions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">image</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/image/lib.rs.html#1-395">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="overview"><a href="#overview">Overview</a></h2>
<p>This crate provides native rust implementations of image encoding and decoding as well as some
basic image manipulation functions. Additional documentation can currently also be found in the
<a href="https://github.com/image-rs/image/blob/master/README.md">README.md file which is most easily viewed on
github</a>.</p>
<p>There are two core problems for which this library provides solutions: a unified interface for image
encodings and simple generic buffers for their content. It’s possible to use either feature
without the other. The focus is on a small and stable set of common operations that can be
supplemented by other specialized crates. The library also prefers safe solutions with few
dependencies.</p>
<h2 id="high-level-api"><a href="#high-level-api">High level API</a></h2>
<p>Load images using <a href="io/struct.Reader.html"><code>io::Reader</code></a>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>image::io::Reader <span class="kw">as </span>ImageReader;
<span class="kw">let </span>img = ImageReader::open(<span class="string">&quot;myimage.png&quot;</span>)<span class="question-mark">?</span>.decode()<span class="question-mark">?</span>;
<span class="kw">let </span>img2 = ImageReader::new(Cursor::new(bytes)).decode()<span class="question-mark">?</span>;</code></pre></div>
<p>And save them using <a href="enum.DynamicImage.html#method.save"><code>save</code></a> or <a href="enum.DynamicImage.html#method.write_to"><code>write_to</code></a> methods:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>img.save(<span class="string">&quot;empty.jpg&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>bytes: Vec&lt;u8&gt; = Vec::new();
img2.write_to(<span class="kw-2">&amp;mut </span>bytes, image::ImageOutputFormat::Png)<span class="question-mark">?</span>;</code></pre></div>
<p>With default features, the crate includes support for <a href="codecs/index.html#supported-formats">many common image formats</a>.</p>
<h2 id="image-buffers"><a href="#image-buffers">Image buffers</a></h2>
<p>The two main types for storing images:</p>
<ul>
<li><a href="struct.ImageBuffer.html"><code>ImageBuffer</code></a> which holds statically typed image contents.</li>
<li><a href="enum.DynamicImage.html"><code>DynamicImage</code></a> which is an enum over the supported ImageBuffer formats
and supports conversions between them.</li>
</ul>
<p>As well as a few more specialized options:</p>
<ul>
<li><a href="trait.GenericImage.html"><code>GenericImage</code></a> trait for a mutable image buffer.</li>
<li><a href="trait.GenericImageView.html"><code>GenericImageView</code></a> trait for read only references to a GenericImage.</li>
<li><a href="flat/index.html"><code>flat</code></a> module containing types for interoperability with generic channel
matrices and foreign interfaces.</li>
</ul>
<h2 id="low-level-encodingdecoding-api"><a href="#low-level-encodingdecoding-api">Low level encoding/decoding API</a></h2>
<p>The <a href="trait.ImageDecoder.html"><code>ImageDecoder</code></a> and <a href="trait.ImageDecoderExt.html"><code>ImageDecoderExt</code></a> traits are implemented for many image file
formats. They decode image data by directly on raw byte slices. Given an ImageDecoder, you can
produce a DynamicImage via <a href="enum.DynamicImage.html#method.from_decoder"><code>DynamicImage::from_decoder</code></a>.</p>
<p><a href="trait.ImageEncoder.html"><code>ImageEncoder</code></a> provides the analogous functionality for encoding image data.</p>
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><div class="item-table"><div class="item-row"><div class="item-left import-item" id="reexport.ImageError"><code>pub use crate::error::<a class="enum" href="error/enum.ImageError.html" title="enum image::error::ImageError">ImageError</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.ImageResult"><code>pub use crate::error::<a class="type" href="error/type.ImageResult.html" title="type image::error::ImageResult">ImageResult</a>;</code></div></div><div class="item-row"><div class="item-left import-item" id="reexport.FlatSamples"><code>pub use crate::flat::<a class="struct" href="flat/struct.FlatSamples.html" title="struct image::flat::FlatSamples">FlatSamples</a>;</code></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="buffer/index.html" title="image::buffer mod">buffer</a></div><div class="item-right docblock-short">Iterators and other auxiliary structure for the <code>ImageBuffer</code> type.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="codecs/index.html" title="image::codecs mod">codecs</a></div><div class="item-right docblock-short">Encoding and decoding for various image file formats.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="error/index.html" title="image::error mod">error</a></div><div class="item-right docblock-short">Contains detailed error representation.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="flat/index.html" title="image::flat mod">flat</a></div><div class="item-right docblock-short">Image representations for ffi.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="imageops/index.html" title="image::imageops mod">imageops</a></div><div class="item-right docblock-short">Image Processing Functions</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="io/index.html" title="image::io mod">io</a></div><div class="item-right docblock-short">Input and output of images.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="jpeg/index.html" title="image::jpeg mod">jpeg</a><span class="stab deprecated" title="">Deprecated</span></div><div class="item-right docblock-short">Decoding and Encoding of JPEG Images</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="math/index.html" title="image::math mod">math</a></div><div class="item-right docblock-short">Mathematical helper functions and types.</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Bgr.html" title="image::Bgr struct">Bgr</a></div><div class="item-right docblock-short">BGR colors</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Bgra.html" title="image::Bgra struct">Bgra</a></div><div class="item-right docblock-short">BGR colors + alpha channel</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Delay.html" title="image::Delay struct">Delay</a></div><div class="item-right docblock-short">The delay of a frame relative to the previous one.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Frame.html" title="image::Frame struct">Frame</a></div><div class="item-right docblock-short">A single animation frame</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Frames.html" title="image::Frames struct">Frames</a></div><div class="item-right docblock-short">An implementation dependent iterator, reading the frames as requested</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.ImageBuffer.html" title="image::ImageBuffer struct">ImageBuffer</a></div><div class="item-right docblock-short">Generic image buffer</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Luma.html" title="image::Luma struct">Luma</a></div><div class="item-right docblock-short">Grayscale colors</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.LumaA.html" title="image::LumaA struct">LumaA</a></div><div class="item-right docblock-short">Grayscale colors + alpha channel</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Pixels.html" title="image::Pixels struct">Pixels</a></div><div class="item-right docblock-short">Immutable pixel iterator</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Progress.html" title="image::Progress struct">Progress</a></div><div class="item-right docblock-short">Represents the progress of an image operation.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Rgb.html" title="image::Rgb struct">Rgb</a></div><div class="item-right docblock-short">RGB colors</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Rgba.html" title="image::Rgba struct">Rgba</a></div><div class="item-right docblock-short">RGB colors + alpha channel</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.SubImage.html" title="image::SubImage struct">SubImage</a></div><div class="item-right docblock-short">A View into another image</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.ColorType.html" title="image::ColorType enum">ColorType</a></div><div class="item-right docblock-short">An enumeration over supported color types and bit depths</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.DynamicImage.html" title="image::DynamicImage enum">DynamicImage</a></div><div class="item-right docblock-short">A Dynamic Image</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.ExtendedColorType.html" title="image::ExtendedColorType enum">ExtendedColorType</a></div><div class="item-right docblock-short">An enumeration of color types encountered in image formats.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.ImageFormat.html" title="image::ImageFormat enum">ImageFormat</a></div><div class="item-right docblock-short">An enumeration of supported image formats.
Not all formats support both encoding and decoding.</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.ImageOutputFormat.html" title="image::ImageOutputFormat enum">ImageOutputFormat</a></div><div class="item-right docblock-short">An enumeration of supported image formats for encoding.</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.AnimationDecoder.html" title="image::AnimationDecoder trait">AnimationDecoder</a></div><div class="item-right docblock-short">AnimationDecoder trait</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.EncodableLayout.html" title="image::EncodableLayout trait">EncodableLayout</a></div><div class="item-right docblock-short">Types which are safe to treat as an immutable byte slice in a pixel layout
for image encoding.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.GenericImage.html" title="image::GenericImage trait">GenericImage</a></div><div class="item-right docblock-short">A trait for manipulating images.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.GenericImageView.html" title="image::GenericImageView trait">GenericImageView</a></div><div class="item-right docblock-short">Trait to inspect an image.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ImageDecoder.html" title="image::ImageDecoder trait">ImageDecoder</a></div><div class="item-right docblock-short">The trait that all decoders implement</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ImageDecoderExt.html" title="image::ImageDecoderExt trait">ImageDecoderExt</a></div><div class="item-right docblock-short">Specialized image decoding not be supported by all formats</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ImageEncoder.html" title="image::ImageEncoder trait">ImageEncoder</a></div><div class="item-right docblock-short">The trait all encoders implement</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Pixel.html" title="image::Pixel trait">Pixel</a></div><div class="item-right docblock-short">A generalized pixel.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Primitive.html" title="image::Primitive trait">Primitive</a></div><div class="item-right docblock-short">Primitive trait from old stdlib</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.guess_format.html" title="image::guess_format fn">guess_format</a></div><div class="item-right docblock-short">Guess image format from memory block</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.image_dimensions.html" title="image::image_dimensions fn">image_dimensions</a></div><div class="item-right docblock-short">Read the dimensions of the image located at the specified path.
This is faster than fully loading the image and then getting its dimensions.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.load.html" title="image::load fn">load</a></div><div class="item-right docblock-short">Create a new image from a Reader</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.load_from_memory.html" title="image::load_from_memory fn">load_from_memory</a></div><div class="item-right docblock-short">Create a new image from a byte slice</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.load_from_memory_with_format.html" title="image::load_from_memory_with_format fn">load_from_memory_with_format</a></div><div class="item-right docblock-short">Create a new image from a byte slice</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.open.html" title="image::open fn">open</a></div><div class="item-right docblock-short">Open the image located at the path specified.
The image’s format is determined from the path’s file extension.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.save_buffer.html" title="image::save_buffer fn">save_buffer</a></div><div class="item-right docblock-short">Saves the supplied buffer to a file at the path specified.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.save_buffer_with_format.html" title="image::save_buffer_with_format fn">save_buffer_with_format</a></div><div class="item-right docblock-short">Saves the supplied buffer to a file at the path specified
in the specified format.</div></div></div><h2 id="types" class="small-section-header"><a href="#types">Type Definitions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="type" href="type.GrayAlphaImage.html" title="image::GrayAlphaImage type">GrayAlphaImage</a></div><div class="item-right docblock-short">Sendable grayscale + alpha channel image buffer</div></div><div class="item-row"><div class="item-left module-item"><a class="type" href="type.GrayImage.html" title="image::GrayImage type">GrayImage</a></div><div class="item-right docblock-short">Sendable grayscale image buffer</div></div><div class="item-row"><div class="item-left module-item"><a class="type" href="type.RgbImage.html" title="image::RgbImage type">RgbImage</a></div><div class="item-right docblock-short">Sendable Rgb image buffer</div></div><div class="item-row"><div class="item-left module-item"><a class="type" href="type.RgbaImage.html" title="image::RgbaImage type">RgbaImage</a></div><div class="item-right docblock-short">Sendable Rgb + alpha channel image buffer</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="image" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>