pub struct Tee {
pub body: WithShadow,
pub feet: WithShadow,
pub eye: [EyeTypeData; 6],
pub hand: WithShadow,
pub used_uv: UV,
}Expand description
Represents a parsed Tee character, containing all its visual components.
The Tee struct holds all the necessary parts to render a character, including body parts, feet, hands, and various eye states. Each part is stored separately from its shadow to allow for independent manipulation.
Fields§
§body: WithShadowThe body part of the character, including both the main body and its shadow
feet: WithShadowThe feet parts of the character, including both the main feet and their shadow
eye: [EyeTypeData; 6]An array of eye images, ordered as follows:
[Normal, Angry, Pain, Happy, Empty, Surprise]
hand: WithShadowThe hand parts of the character, including both the main hand and its shadow
used_uv: UVThe UV mapping used to extract parts from the source image
Implementations§
Source§impl Tee
impl Tee
Sourcepub fn new(data: Bytes, format: ImageFormat) -> Result<Self>
pub fn new(data: Bytes, format: ImageFormat) -> Result<Self>
Parses a Tee struct from raw image data with default uv::TEE_UV_LAYOUT.
§Arguments
data- The raw bytes of an image containing the Tee parts.format- The ImageFormat of the input data (e.g., PNG, JPEG).
§Returns
A Result which is Ok(Tee) on successful parsing, or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::Tee;
use image::ImageFormat;
let image_data = std::fs::read("tee_parts.png")?;
let tee = Tee::new(image_data.into(), ImageFormat::Png)?;Sourcepub fn new_with_uv(data: Bytes, uv: UV, format: ImageFormat) -> Result<Self>
pub fn new_with_uv(data: Bytes, uv: UV, format: ImageFormat) -> Result<Self>
Parses a Tee struct from raw image data with a custom UV layout.
§Arguments
data- The raw bytes of an image containing the Tee parts.uv- A UV struct containing the coordinates and dimensions for each part on the source image.format- The ImageFormat of the input data (e.g., PNG, JPEG).
§Returns
A Result which is Ok(Tee) on successful parsing, or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::{Tee, uv::UV};
use image::ImageFormat;
let image_data = std::fs::read("custom_tee_parts.png")?;
let custom_uv = UV { /* custom layout */ };
let tee = Tee::new_with_uv(image_data.into(), custom_uv, ImageFormat::Png)?;Sourcepub async fn new_from_url_with_uv(url: &str, uv: UV) -> Result<Self>
Available on crate feature net only.
pub async fn new_from_url_with_uv(url: &str, uv: UV) -> Result<Self>
net only.Asynchronously fetches a Tee skin from a URL and parses it with a custom UV layout.
The image format is determined from the Content-Type header of the response.
§Arguments
url- A string slice that holds the URL of the skin image.uv- A UV struct containing the coordinates and dimensions for each part.
§Returns
A Result which is Ok(Tee) on successful fetching and parsing, or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::{Tee, uv::UV};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let custom_uv = UV { /* custom layout */ };
let tee = Tee::new_from_url_with_uv("https://example.com/tee.png", custom_uv).await?;
Ok(())
}Sourcepub async fn new_from_url(url: &str) -> Result<Self>
Available on crate feature net only.
pub async fn new_from_url(url: &str) -> Result<Self>
net only.Asynchronously fetches a Tee skin from a URL and parses it with the default UV layout.
The image format is determined from the Content-Type header of the response.
§Arguments
url- A string slice that holds the URL of the skin image.
§Returns
A Result which is Ok(Tee) on successful fetching and parsing, or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::Tee;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tee = Tee::new_from_url("https://example.com/tee.png").await?;
Ok(())
}Sourcepub fn apply_hsl_to_parts(&mut self, hsl: (f32, f32, f32), parts: &[TeePart])
pub fn apply_hsl_to_parts(&mut self, hsl: (f32, f32, f32), parts: &[TeePart])
Applies HSL color transformation to specific parts of the Tee.
§Arguments
hls- A tuple of (hue, saturation, value) values, each in the range [0.0, 1.0].parts- A slice ofTeePartspecifying which parts to apply the transformation to.
§Example
use tee_morphosis::tee::{Tee, parts::TeePart};
use tee_morphosis::tee:hsl::ddnet_color_to_hsl;
let mut tee = Tee::new(/* ... */)?;
let hsl = ddnet_color_to_hsl(1900500);
tee.apply_hsl_to_parts(hsl, &[TeePart::Body]);Sourcepub fn apply_hsl_to_all(&mut self, hls: HSL)
pub fn apply_hsl_to_all(&mut self, hls: HSL)
Applies HSL color transformation to all parts of the Tee.
§Arguments
hls- A tuple of (hue, saturation, value) values, each in the range [0.0, 1.0].
§Example
use tee_morphosis::tee::Tee;
use tee_morphosis::tee:hsl::ddnet_color_to_hsl;
let mut tee = Tee::new(/* ... */)?;
let hsl = ddnet_color_to_hsl(1900500);
tee.apply_hsl_to_all(hsl);Sourcepub fn compose(
&self,
skin: Skin,
eye_type: EyeType,
img_format: ImageFormat,
) -> Result<Bytes>
pub fn compose( &self, skin: Skin, eye_type: EyeType, img_format: ImageFormat, ) -> Result<Bytes>
Composites the Tee parts onto a base skin image to create a final character portrait.
§Arguments
skin- The baseSkinto draw the Tee parts onto.eye_type- TheEyeTypeto use for the eyes in the final image.img_format- The desiredImageFormatfor the output bytes (e.g., PNG, JPEG).
§Returns
A Result which is Ok(Bytes) containing the final image data on success,
or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::{Tee, parts::EyeType, skin::TEE_SKIN_LAYOUT};
use image::ImageFormat;
let tee = Tee::new(/* ... */)?;
let result = tee.compose(TEE_SKIN_LAYOUT, EyeType::Happy, ImageFormat::Png)?;
std::fs::write("output.png", result)?;Sourcepub fn compose_png(&self, skin: Skin, eye_type: EyeType) -> Result<Bytes>
pub fn compose_png(&self, skin: Skin, eye_type: EyeType) -> Result<Bytes>
Composites the Tee with PNG format.
§Arguments
skin- The baseSkinto draw the Tee parts onto.eye_type- The type of eyes to use.
§Returns
A Result which is Ok(Bytes) containing the final image data on success,
or Err(TeeError) on failure.
§Example
use tee_morphosis::tee::{Tee, skin::TEE_SKIN_LAYOUT};
let tee = Tee::new(/* ... */)?;
let result = tee.compose_png(TEE_SKIN_LAYOUT, EyeType::Happy)?;
std::fs::write("output.png", result)?;Sourcepub fn get_eye(&self, type: EyeType) -> &RgbaImage
pub fn get_eye(&self, type: EyeType) -> &RgbaImage
Retrieves the image for a specific eye type.
§Arguments
type- TheEyeTypeto retrieve.
§Returns
A reference to the RgbaImage corresponding to the requested eye type.
This function will panic if the internal state is inconsistent, which is
prevented by the construction logic in Tee::new.
§Example
use tee_morphosis::tee::{Tee, parts::EyeType};
let tee = Tee::new(/* ... */)?;
let happy_eye = tee.get_eye(EyeType::Happy);Sourcepub fn get_all_parts(&self) -> HashMap<TeePart, &WithShadow>
pub fn get_all_parts(&self) -> HashMap<TeePart, &WithShadow>
Returns all parts of the Tee as a HashMap.
note: does not include eyes. Use Tee::get_all_eyes instead
§Returns
A HashMap<TeePart, &WithShadow> containing all parts of the Tee.
§Example
use tee_morphosis::tee::{Tee, parts::TeePart};
let tee = Tee::new(/* ... */)?;
let all_parts = tee.get_all_parts();
let body_image = all_parts.get(&TeePart::Body).unwrap();Sourcepub fn get_all_eyes(&self) -> HashMap<EyeType, &RgbaImage>
pub fn get_all_eyes(&self) -> HashMap<EyeType, &RgbaImage>
Returns all eye types of the Tee as a HashMap.
for specific one, use Tee::get_eye
§Returns
A HashMap<EyeType, &RgbaImage> containing all eye types of the Tee.
§Example
use tee_morphosis::tee::{Tee, parts::EyeType};
let tee = Tee::new(/* ... */)?;
let all_eyes = tee.get_all_eyes();
let happy_eye = all_eyes.get(&EyeType::Happy).unwrap();Trait Implementations§
impl StructuralPartialEq for Tee
Auto Trait Implementations§
impl Freeze for Tee
impl RefUnwindSafe for Tee
impl Send for Tee
impl Sync for Tee
impl Unpin for Tee
impl UnwindSafe for Tee
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more