Struct observation_tools_client::artifacts::Image2Builder
source · pub struct Image2Builder { /* private fields */ }
Expand description
An image.
§Example
use observation_tools_client::artifacts::Image2Builder;
use observation_tools_client::artifacts::Object2Builder;
use observation_tools_client::artifacts::PerPixelTransformBuilder;
use observation_tools_client::artifacts::Point2Builder;
use observation_tools_client::artifacts::Rect2Builder;
use observation_tools_client::artifacts::Segment2Builder;
use observation_tools_client::artifacts::Transform2Builder;
#[tokio::main]
async fn main() -> Result<(), observation_tools_client::ClientError> {
tracing_subscriber::fmt::init();
let client = observation_tools_client::test_utils::create_doc_test_client()?;
// Set up a 2D group:
let run = client.create_run("create_image2")?;
let group2d = run.child_uploader_2d("image2_world")?;
// Basic usage:
group2d.create_object2(
"my_image",
Image2Builder::new(include_bytes!("../testdata/logo_dark.png"), "image/png"),
)?;
// Single-channel images:
let width = 64;
let height = 64;
let mut image = vec![0u8; width * height];
for y in 0..height {
for x in 0..width {
// Make a diagonal pattern
image[(y * width + x)] = ((x + y) / 8) as u8;
}
}
let mut single_channel_image =
Image2Builder::from_grayscale_pixels(&image, width as u32, height as u32)?;
// Optionally set a per-pixel transform to colorize the image:
single_channel_image
.set_per_pixel_transform(PerPixelTransformBuilder::random_distinct_color());
group2d.create_object2("single_channel_image", single_channel_image)?;
client.shutdown().await?;
Ok(())
}
Implementations§
source§impl Image2Builder
impl Image2Builder
pub fn new(data: &[u8], mime_type: &str) -> Self
pub fn from_grayscale_pixels( data: &[u8], width: u32, height: u32 ) -> Result<Image2Builder, ClientError>
pub fn set_per_pixel_transform(&mut self, transform: PerPixelTransformBuilder)
Trait Implementations§
source§impl Clone for Image2Builder
impl Clone for Image2Builder
source§fn clone(&self) -> Image2Builder
fn clone(&self) -> Image2Builder
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl From<Image2Builder> for JsValue
impl From<Image2Builder> for JsValue
source§fn from(value: Image2Builder) -> Self
fn from(value: Image2Builder) -> Self
Converts to this type from the input type.
source§impl FromWasmAbi for Image2Builder
impl FromWasmAbi for Image2Builder
source§impl Into<Geometry2Builder> for Image2Builder
impl Into<Geometry2Builder> for Image2Builder
source§fn into(self) -> Geometry2Builder
fn into(self) -> Geometry2Builder
Converts this type into the (usually inferred) input type.
source§impl Into<Object2Builder> for Image2Builder
impl Into<Object2Builder> for Image2Builder
source§fn into(self) -> Object2Builder
fn into(self) -> Object2Builder
Converts this type into the (usually inferred) input type.
source§impl IntoWasmAbi for Image2Builder
impl IntoWasmAbi for Image2Builder
source§impl LongRefFromWasmAbi for Image2Builder
impl LongRefFromWasmAbi for Image2Builder
source§impl OptionFromWasmAbi for Image2Builder
impl OptionFromWasmAbi for Image2Builder
source§impl OptionIntoWasmAbi for Image2Builder
impl OptionIntoWasmAbi for Image2Builder
source§impl RefFromWasmAbi for Image2Builder
impl RefFromWasmAbi for Image2Builder
§type Anchor = Ref<'static, Image2Builder>
type Anchor = Ref<'static, Image2Builder>
The type that holds the reference to
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.source§impl RefMutFromWasmAbi for Image2Builder
impl RefMutFromWasmAbi for Image2Builder
source§impl TryFromJsValue for Image2Builder
impl TryFromJsValue for Image2Builder
source§impl VectorFromWasmAbi for Image2Builder
impl VectorFromWasmAbi for Image2Builder
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Image2Builder]>
source§impl VectorIntoWasmAbi for Image2Builder
impl VectorIntoWasmAbi for Image2Builder
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[Image2Builder]>) -> Self::Abi
source§impl WasmDescribeVector for Image2Builder
impl WasmDescribeVector for Image2Builder
Auto Trait Implementations§
impl RefUnwindSafe for Image2Builder
impl Send for Image2Builder
impl Sync for Image2Builder
impl Unpin for Image2Builder
impl UnwindSafe for Image2Builder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
Same as
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
Same as
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.