Files
phy/image/index.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

58 lines
20 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="Overview"><title>image - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="image" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../image/index.html">image</a><span class="version">0.25.2</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#overview" title="Overview">Overview</a></li><li><a href="#high-level-api" title="High level API">High level API</a></li><li><a href="#image-buffers" title="Image buffers">Image buffers</a></li><li><a href="#low-level-encodingdecoding-api" title="Low level encoding/decoding API">Low level encoding/decoding API</a></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>image</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/image/lib.rs.html#1-325">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="overview"><a class="doc-anchor" href="#overview">§</a>Overview</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. Its 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 class="doc-anchor" href="#high-level-api">§</a>High level API</h2>
<p>Load images using <a href="struct.Reader.html"><code>ImageReader</code></a>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::io::Cursor;
<span class="kw">use </span>image::ImageReader;
<span class="kw">let </span>img = ImageReader::open(<span class="string">"myimage.png"</span>)<span class="question-mark">?</span>.decode()<span class="question-mark">?</span>;
<span class="kw">let </span>img2 = ImageReader::new(Cursor::new(bytes)).with_guessed_format()<span class="question-mark">?</span>.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">"empty.jpg"</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>Cursor::new(<span class="kw-2">&amp;mut </span>bytes), image::ImageFormat::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 class="doc-anchor" href="#image-buffers">§</a>Image buffers</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 <code>ImageBuffer</code> 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 <code>GenericImage</code>.</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 class="doc-anchor" href="#low-level-encodingdecoding-api">§</a>Low level encoding/decoding API</h2>
<p>Implementations of <a href="trait.ImageEncoder.html"><code>ImageEncoder</code></a> provides low level control over encoding:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>encoder = JpegEncoder::new_with_quality(<span class="kw-2">&amp;mut </span>writer, <span class="number">95</span>);
img.write_with_encoder(encoder)<span class="question-mark">?</span>;</code></pre></div>
<p>While <a href="trait.ImageDecoder.html"><code>ImageDecoder</code></a> and <a href="trait.ImageDecoderRect.html"><code>ImageDecoderRect</code></a> give access to more advanced decoding options:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>decoder = PngDecoder::new(<span class="kw-2">&amp;mut </span>reader)<span class="question-mark">?</span>;
<span class="kw">let </span>icc = decoder.icc_profile();
<span class="kw">let </span>img = DynamicImage::from_decoder(decoder)<span class="question-mark">?</span>;</code></pre></div>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" 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></li><li><div class="item-name" 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></li><li><div class="item-name" 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></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="buffer/index.html" title="mod image::buffer">buffer</a></div><div class="desc docblock-short">Iterators and other auxiliary structure for the <code>ImageBuffer</code> type.</div></li><li><div class="item-name"><a class="mod" href="codecs/index.html" title="mod image::codecs">codecs</a></div><div class="desc docblock-short">Encoding and decoding for various image file formats.</div></li><li><div class="item-name"><a class="mod" href="error/index.html" title="mod image::error">error</a></div><div class="desc docblock-short">Contains detailed error representation.</div></li><li><div class="item-name"><a class="mod" href="flat/index.html" title="mod image::flat">flat</a></div><div class="desc docblock-short">Image representations for ffi.</div></li><li><div class="item-name"><a class="mod" href="imageops/index.html" title="mod image::imageops">imageops</a></div><div class="desc docblock-short">Image Processing Functions</div></li><li><div class="item-name"><a class="mod" href="io/index.html" title="mod image::io">io</a></div><div class="desc docblock-short">deprecated io module the original io module has been renamed to <code>image_reader</code></div></li><li><div class="item-name"><a class="mod" href="math/index.html" title="mod image::math">math</a></div><div class="desc docblock-short">Mathematical helper functions and types.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Delay.html" title="struct image::Delay">Delay</a></div><div class="desc docblock-short">The delay of a frame relative to the previous one.</div></li><li><div class="item-name"><a class="struct" href="struct.Frame.html" title="struct image::Frame">Frame</a></div><div class="desc docblock-short">A single animation frame</div></li><li><div class="item-name"><a class="struct" href="struct.Frames.html" title="struct image::Frames">Frames</a></div><div class="desc docblock-short">An implementation dependent iterator, reading the frames as requested</div></li><li><div class="item-name"><a class="struct" href="struct.ImageBuffer.html" title="struct image::ImageBuffer">Image<wbr>Buffer</a></div><div class="desc docblock-short">Generic image buffer</div></li><li><div class="item-name"><a class="struct" href="struct.ImageReader.html" title="struct image::ImageReader">Image<wbr>Reader</a></div><div class="desc docblock-short">A multi-format image reader.</div></li><li><div class="item-name"><a class="struct" href="struct.LimitSupport.html" title="struct image::LimitSupport">Limit<wbr>Support</a></div><div class="desc docblock-short">Set of supported strict limits for a decoder.</div></li><li><div class="item-name"><a class="struct" href="struct.Limits.html" title="struct image::Limits">Limits</a></div><div class="desc docblock-short">Resource limits for decoding.</div></li><li><div class="item-name"><a class="struct" href="struct.Luma.html" title="struct image::Luma">Luma</a></div><div class="desc docblock-short">Grayscale colors.</div></li><li><div class="item-name"><a class="struct" href="struct.LumaA.html" title="struct image::LumaA">LumaA</a></div><div class="desc docblock-short">Grayscale colors + alpha channel</div></li><li><div class="item-name"><a class="struct" href="struct.Pixels.html" title="struct image::Pixels">Pixels</a></div><div class="desc docblock-short">Immutable pixel iterator</div></li><li><div class="item-name"><a class="struct" href="struct.Rgb.html" title="struct image::Rgb">Rgb</a></div><div class="desc docblock-short">RGB colors.</div></li><li><div class="item-name"><a class="struct" href="struct.Rgba.html" title="struct image::Rgba">Rgba</a></div><div class="desc docblock-short">RGB colors + alpha channel</div></li><li><div class="item-name"><a class="struct" href="struct.SubImage.html" title="struct image::SubImage">SubImage</a></div><div class="desc docblock-short">A View into another image</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.ColorType.html" title="enum image::ColorType">Color<wbr>Type</a></div><div class="desc docblock-short">An enumeration over supported color types and bit depths</div></li><li><div class="item-name"><a class="enum" href="enum.DynamicImage.html" title="enum image::DynamicImage">Dynamic<wbr>Image</a></div><div class="desc docblock-short">A Dynamic Image</div></li><li><div class="item-name"><a class="enum" href="enum.ExtendedColorType.html" title="enum image::ExtendedColorType">Extended<wbr>Color<wbr>Type</a></div><div class="desc docblock-short">An enumeration of color types encountered in image formats.</div></li><li><div class="item-name"><a class="enum" href="enum.ImageFormat.html" title="enum image::ImageFormat">Image<wbr>Format</a></div><div class="desc docblock-short">An enumeration of supported image formats.
Not all formats support both encoding and decoding.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.AnimationDecoder.html" title="trait image::AnimationDecoder">Animation<wbr>Decoder</a></div><div class="desc docblock-short"><code>AnimationDecoder</code> trait</div></li><li><div class="item-name"><a class="trait" href="trait.EncodableLayout.html" title="trait image::EncodableLayout">Encodable<wbr>Layout</a></div><div class="desc docblock-short">Types which are safe to treat as an immutable byte slice in a pixel layout
for image encoding.</div></li><li><div class="item-name"><a class="trait" href="trait.GenericImage.html" title="trait image::GenericImage">Generic<wbr>Image</a></div><div class="desc docblock-short">A trait for manipulating images.</div></li><li><div class="item-name"><a class="trait" href="trait.GenericImageView.html" title="trait image::GenericImageView">Generic<wbr>Image<wbr>View</a></div><div class="desc docblock-short">Trait to inspect an image.</div></li><li><div class="item-name"><a class="trait" href="trait.ImageDecoder.html" title="trait image::ImageDecoder">Image<wbr>Decoder</a></div><div class="desc docblock-short">The trait that all decoders implement</div></li><li><div class="item-name"><a class="trait" href="trait.ImageDecoderRect.html" title="trait image::ImageDecoderRect">Image<wbr>Decoder<wbr>Rect</a></div><div class="desc docblock-short">Specialized image decoding not be supported by all formats</div></li><li><div class="item-name"><a class="trait" href="trait.ImageEncoder.html" title="trait image::ImageEncoder">Image<wbr>Encoder</a></div><div class="desc docblock-short">The trait all encoders implement</div></li><li><div class="item-name"><a class="trait" href="trait.Pixel.html" title="trait image::Pixel">Pixel</a></div><div class="desc docblock-short">A generalized pixel.</div></li><li><div class="item-name"><a class="trait" href="trait.PixelWithColorType.html" title="trait image::PixelWithColorType">Pixel<wbr>With<wbr>Color<wbr>Type</a></div><div class="desc docblock-short">The pixel with an associated <code>ColorType</code>.
Not all possible pixels represent one of the predefined <code>ColorType</code>s.</div></li><li><div class="item-name"><a class="trait" href="trait.Primitive.html" title="trait image::Primitive">Primitive</a></div><div class="desc docblock-short">The type of each channel in a pixel. For example, this can be <code>u8</code>, <code>u16</code>, <code>f32</code>.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.guess_format.html" title="fn image::guess_format">guess_<wbr>format</a></div><div class="desc docblock-short">Guess image format from memory block</div></li><li><div class="item-name"><a class="fn" href="fn.image_dimensions.html" title="fn image::image_dimensions">image_<wbr>dimensions</a></div><div class="desc docblock-short">Read a tuple containing the (width, height) of the image located at the specified path.
This is faster than fully loading the image and then getting its dimensions.</div></li><li><div class="item-name"><a class="fn" href="fn.load.html" title="fn image::load">load</a></div><div class="desc docblock-short">Create a new image from a Reader.</div></li><li><div class="item-name"><a class="fn" href="fn.load_from_memory.html" title="fn image::load_from_memory">load_<wbr>from_<wbr>memory</a></div><div class="desc docblock-short">Create a new image from a byte slice</div></li><li><div class="item-name"><a class="fn" href="fn.load_from_memory_with_format.html" title="fn image::load_from_memory_with_format">load_<wbr>from_<wbr>memory_<wbr>with_<wbr>format</a></div><div class="desc docblock-short">Create a new image from a byte slice</div></li><li><div class="item-name"><a class="fn" href="fn.open.html" title="fn image::open">open</a></div><div class="desc docblock-short">Open the image located at the path specified.
The images format is determined from the paths file extension.</div></li><li><div class="item-name"><a class="fn" href="fn.save_buffer.html" title="fn image::save_buffer">save_<wbr>buffer</a></div><div class="desc docblock-short">Saves the supplied buffer to a file at the path specified.</div></li><li><div class="item-name"><a class="fn" href="fn.save_buffer_with_format.html" title="fn image::save_buffer_with_format">save_<wbr>buffer_<wbr>with_<wbr>format</a></div><div class="desc docblock-short">Saves the supplied buffer to a file at the path specified
in the specified format.</div></li><li><div class="item-name"><a class="fn" href="fn.write_buffer_with_format.html" title="fn image::write_buffer_with_format">write_<wbr>buffer_<wbr>with_<wbr>format</a></div><div class="desc docblock-short">Writes the supplied buffer to a writer in the specified format.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.GrayAlphaImage.html" title="type image::GrayAlphaImage">Gray<wbr>Alpha<wbr>Image</a></div><div class="desc docblock-short">Sendable grayscale + alpha channel image buffer</div></li><li><div class="item-name"><a class="type" href="type.GrayImage.html" title="type image::GrayImage">Gray<wbr>Image</a></div><div class="desc docblock-short">Sendable grayscale image buffer</div></li><li><div class="item-name"><a class="type" href="type.Rgb32FImage.html" title="type image::Rgb32FImage">Rgb32F<wbr>Image</a></div><div class="desc docblock-short">An image buffer for 32-bit float RGB pixels,
where the backing container is a flattened vector of floats.</div></li><li><div class="item-name"><a class="type" href="type.RgbImage.html" title="type image::RgbImage">RgbImage</a></div><div class="desc docblock-short">Sendable Rgb image buffer</div></li><li><div class="item-name"><a class="type" href="type.Rgba32FImage.html" title="type image::Rgba32FImage">Rgba32F<wbr>Image</a></div><div class="desc docblock-short">An image buffer for 32-bit float RGBA pixels,
where the backing container is a flattened vector of floats.</div></li><li><div class="item-name"><a class="type" href="type.RgbaImage.html" title="type image::RgbaImage">Rgba<wbr>Image</a></div><div class="desc docblock-short">Sendable Rgb + alpha channel image buffer</div></li></ul></section></div></main></body></html>