68 lines
20 KiB
HTML
68 lines
20 KiB
HTML
<!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="A trait for manipulating images."><title>GenericImage in 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="sidebar-items.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 trait"><!--[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"><section id="rustdoc-toc"><h2 class="location"><a href="#">Generic<wbr>Image</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.blend_pixel" title="blend_pixel">blend_pixel</a></li><li><a href="#tymethod.get_pixel_mut" title="get_pixel_mut">get_pixel_mut</a></li><li><a href="#tymethod.put_pixel" title="put_pixel">put_pixel</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.copy_from" title="copy_from">copy_from</a></li><li><a href="#method.copy_within" title="copy_within">copy_within</a></li><li><a href="#method.sub_image" title="sub_image">sub_image</a></li><li><a href="#method.unsafe_put_pixel" title="unsafe_put_pixel">unsafe_put_pixel</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate image</a></h2></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"><span class="rustdoc-breadcrumbs"><a href="index.html">image</a></span><h1>Trait <span class="trait">GenericImage</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/image.rs.html#903-1047">Source</a> </span></div><pre class="rust item-decl"><code>pub trait GenericImage: <a class="trait" href="trait.GenericImageView.html" title="trait image::GenericImageView">GenericImageView</a> {
|
|
// Required methods
|
|
fn <a href="#tymethod.get_pixel_mut" class="fn">get_pixel_mut</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> &mut Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>;
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.put_pixel" class="fn">put_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>);
|
|
<span class="item-spacer"></span> fn <a href="#tymethod.blend_pixel" class="fn">blend_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>);
|
|
|
|
// Provided methods
|
|
unsafe fn <a href="#method.unsafe_put_pixel" class="fn">unsafe_put_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>) { ... }
|
|
<span class="item-spacer"></span> fn <a href="#method.copy_from" class="fn">copy_from</a><O>(&mut self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&O</a>, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> <a class="type" href="error/type.ImageResult.html" title="type image::error::ImageResult">ImageResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a>>
|
|
<span class="where">where O: <a class="trait" href="trait.GenericImageView.html" title="trait image::GenericImageView">GenericImageView</a><Pixel = Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>></span> { ... }
|
|
<span class="item-spacer"></span> fn <a href="#method.copy_within" class="fn">copy_within</a>(&mut self, source: <a class="struct" href="math/struct.Rect.html" title="struct image::math::Rect">Rect</a>, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> { ... }
|
|
<span class="item-spacer"></span> fn <a href="#method.sub_image" class="fn">sub_image</a>(
|
|
&mut self,
|
|
x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
width: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
height: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
) -> <a class="struct" href="struct.SubImage.html" title="struct image::SubImage">SubImage</a><&mut Self>
|
|
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span> { ... }
|
|
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait for manipulating images.</p>
|
|
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.get_pixel_mut" class="method"><a class="src rightside" href="../src/image/image.rs.html#925">Source</a><h4 class="code-header">fn <a href="#tymethod.get_pixel_mut" class="fn">get_pixel_mut</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> &mut Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a></h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.24.0: Use <code>get_pixel</code> and <code>put_pixel</code> instead.</span></div></span></summary><div class="docblock"><p>Gets a reference to the mutable pixel at location <code>(x, y)</code>. Indexed from top left.</p>
|
|
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
|
|
<p>Panics if <code>(x, y)</code> is out of bounds.</p>
|
|
<p>Panics for dynamic images (this method is deprecated and will be removed).</p>
|
|
<h6 id="known-issues"><a class="doc-anchor" href="#known-issues">§</a>Known issues</h6>
|
|
<p>This requires the buffer to contain a unique set of continuous channels in the exact order
|
|
and byte representation that the pixel type requires. This is somewhat restrictive.</p>
|
|
<p>TODO: Maybe use some kind of entry API? this would allow pixel type conversion on the fly
|
|
while still doing only one array lookup:</p>
|
|
|
|
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">let </span>px = image.pixel_entry_at(x,y);
|
|
px.set_from_rgba(rgba)</code></pre></div>
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.put_pixel" class="method"><a class="src rightside" href="../src/image/image.rs.html#932">Source</a><h4 class="code-header">fn <a href="#tymethod.put_pixel" class="fn">put_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>)</h4></section></summary><div class="docblock"><p>Put a pixel at location (x, y). Indexed from top left.</p>
|
|
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
|
|
<p>Panics if <code>(x, y)</code> is out of bounds.</p>
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.blend_pixel" class="method"><a class="src rightside" href="../src/image/image.rs.html#951">Source</a><h4 class="code-header">fn <a href="#tymethod.blend_pixel" class="fn">blend_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>)</h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 0.24.0: Use iterator <code>pixels_mut</code> to blend the pixels directly</span></div></span></summary><div class="docblock"><p>Put a pixel at location (x, y), taking into account alpha channels</p>
|
|
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.unsafe_put_pixel" class="method"><a class="src rightside" href="../src/image/image.rs.html#942-944">Source</a><h4 class="code-header">unsafe fn <a href="#method.unsafe_put_pixel" class="fn">unsafe_put_pixel</a>(&mut self, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, pixel: Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>)</h4></section></summary><div class="docblock"><p>Puts a pixel at location (x, y). Indexed from top left.</p>
|
|
<p>This function can be implemented in a way that ignores bounds checking.</p>
|
|
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
|
|
<p>The coordinates must be <a href="traits.GenericImageView.html#method.in_bounds"><code>in_bounds</code></a> of the image.</p>
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.copy_from" class="method"><a class="src rightside" href="../src/image/image.rs.html#968-987">Source</a><h4 class="code-header">fn <a href="#method.copy_from" class="fn">copy_from</a><O>(&mut self, other: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&O</a>, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> <a class="type" href="error/type.ImageResult.html" title="type image::error::ImageResult">ImageResult</a><<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.unit.html">()</a>><div class="where">where
|
|
O: <a class="trait" href="trait.GenericImageView.html" title="trait image::GenericImageView">GenericImageView</a><Pixel = Self::<a class="associatedtype" href="trait.GenericImageView.html#associatedtype.Pixel" title="type image::GenericImageView::Pixel">Pixel</a>>,</div></h4></section></summary><div class="docblock"><p>Copies all of the pixels from another image into this image.</p>
|
|
<p>The other image is copied with the top-left corner of the
|
|
other image placed at (x, y).</p>
|
|
<p>In order to copy only a piece of the other image, use <a href="trait.GenericImageView.html#method.view"><code>GenericImageView::view</code></a>.</p>
|
|
<p>You can use <a href="flat/struct.FlatSamples.html"><code>FlatSamples</code></a> to source pixels from an arbitrary regular raster of channel
|
|
values, for example from a foreign interface or a fixed image.</p>
|
|
<h5 id="returns"><a class="doc-anchor" href="#returns">§</a>Returns</h5>
|
|
<p>Returns an error if the image is too large to be copied at the given position</p>
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.copy_within" class="method"><a class="src rightside" href="../src/image/image.rs.html#996-1034">Source</a><h4 class="code-header">fn <a href="#method.copy_within" class="fn">copy_within</a>(&mut self, source: <a class="struct" href="math/struct.Rect.html" title="struct image::math::Rect">Rect</a>, x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>, y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Copies all of the pixels from one part of this image to another part of this image.</p>
|
|
<p>The destination rectangle of the copy is specified with the top-left corner placed at (x, y).</p>
|
|
<h5 id="returns-1"><a class="doc-anchor" href="#returns-1">§</a>Returns</h5>
|
|
<p><code>true</code> if the copy was successful, <code>false</code> if the image could not
|
|
be copied due to size constraints.</p>
|
|
</div></details><details class="toggle method-toggle" open><summary><section id="method.sub_image" class="method"><a class="src rightside" href="../src/image/image.rs.html#1039-1046">Source</a><h4 class="code-header">fn <a href="#method.sub_image" class="fn">sub_image</a>(
|
|
&mut self,
|
|
x: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
y: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
width: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
height: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u32.html">u32</a>,
|
|
) -> <a class="struct" href="struct.SubImage.html" title="struct image::SubImage">SubImage</a><&mut Self><div class="where">where
|
|
Self: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns a mutable subimage that is a view into this image.
|
|
If you want an immutable subimage instead, use <a href="trait.GenericImageView.html#method.view" title="method image::GenericImageView::view"><code>GenericImageView::view</code></a>
|
|
The coordinates set the position of the top left corner of the <code>SubImage</code>.</p>
|
|
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-GenericImage-for-DynamicImage" class="impl"><a class="src rightside" href="../src/image/dynimage.rs.html#1050-1093">Source</a><a href="#impl-GenericImage-for-DynamicImage" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.GenericImage.html" title="trait image::GenericImage">GenericImage</a> for <a class="enum" href="enum.DynamicImage.html" title="enum image::DynamicImage">DynamicImage</a></h3></section><section id="impl-GenericImage-for-ViewMut%3CBuffer,+P%3E" class="impl"><a class="src rightside" href="../src/image/flat.rs.html#1462-1486">Source</a><a href="#impl-GenericImage-for-ViewMut%3CBuffer,+P%3E" class="anchor">§</a><h3 class="code-header">impl<Buffer, P: <a class="trait" href="trait.Pixel.html" title="trait image::Pixel">Pixel</a>> <a class="trait" href="trait.GenericImage.html" title="trait image::GenericImage">GenericImage</a> for <a class="struct" href="flat/struct.ViewMut.html" title="struct image::flat::ViewMut">ViewMut</a><Buffer, P><div class="where">where
|
|
Buffer: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/convert/trait.AsMut.html" title="trait core::convert::AsMut">AsMut</a><[P::<a class="associatedtype" href="trait.Pixel.html#associatedtype.Subpixel" title="type image::Pixel::Subpixel">Subpixel</a>]> + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[P::<a class="associatedtype" href="trait.Pixel.html#associatedtype.Subpixel" title="type image::Pixel::Subpixel">Subpixel</a>]>,</div></h3></section><section id="impl-GenericImage-for-ImageBuffer%3CP,+Container%3E" class="impl"><a class="src rightside" href="../src/image/buffer.rs.html#1191-1255">Source</a><a href="#impl-GenericImage-for-ImageBuffer%3CP,+Container%3E" class="anchor">§</a><h3 class="code-header">impl<P, Container> <a class="trait" href="trait.GenericImage.html" title="trait image::GenericImage">GenericImage</a> for <a class="struct" href="struct.ImageBuffer.html" title="struct image::ImageBuffer">ImageBuffer</a><P, Container><div class="where">where
|
|
P: <a class="trait" href="trait.Pixel.html" title="trait image::Pixel">Pixel</a>,
|
|
Container: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = [P::<a class="associatedtype" href="trait.Pixel.html#associatedtype.Subpixel" title="type image::Pixel::Subpixel">Subpixel</a>]> + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a>,</div></h3></section></div><script src="../trait.impl/image/image/trait.GenericImage.js" async></script></section></div></main></body></html> |