SymbolArtDrawer

Struct SymbolArtDrawer 

Source
pub struct SymbolArtDrawer { /* private fields */ }
Expand description

A drawer that renders SymbolArt compositions into images

The SymbolArtDrawer is responsible for converting SymbolArt compositions into raster images. It handles the rendering of individual layers, applying transformations, and compositing them into a final image.

§Examples

use sar_core::{SymbolArtDrawer, parse};
use sar_core::renderer::draw::Drawer;

// Parse a SAR file into a SymbolArt instance
let bytes = include_bytes!("../../../fixture/sa0a1d081b8a108bb8c9847c4cd83db662.sar");
let symbol_art = parse(Vec::from(*bytes)).unwrap();

// Create a drawer and render the SymbolArt
let drawer = SymbolArtDrawer::new();
let image = drawer.draw(&symbol_art).unwrap();

§Configuration

The drawer can be configured with various options:

  • with_raise_error: Controls whether rendering errors should be raised or suppressed
  • Canvas size: Default is 256x256 pixels
  • with_chunk_size: Controls parallel processing of layers (default: 10)

§Performance

The drawer uses parallel processing to render layers efficiently. The chunk size can be adjusted to balance between parallelization overhead and throughput.

§Error Handling

By default, the drawer suppresses rendering errors and continues processing. This can be changed using with_raise_error(true) to make errors fatal.

§Resource Management

The drawer maintains a cache of symbol resources to improve rendering performance. These resources are loaded when the drawer is created and shared across all rendering operations.

Implementations§

Source§

impl SymbolArtDrawer

Source

pub fn new() -> Self

Examples found in repository?
examples/parse.rs (line 10)
4fn main() {
5    let current_dir = std::env::current_dir().unwrap();
6    let examples_dir = current_dir.join("fixture");
7    let target_dir = current_dir.join("sar-core").join("examples").join("result");
8
9    let files = std::fs::read_dir(&examples_dir).unwrap();
10    let drawer = sar_core::SymbolArtDrawer::new();
11    files.par_bridge().for_each(|file| {
12        let file = match file {
13            Ok(file) => file,
14            Err(_) => return,
15        };
16        if file.path().is_dir() || file.path().extension().unwrap() != "sar" {
17            return;
18        }
19
20        let buff = std::fs::read(file.path()).unwrap();
21        let sar = match sar_core::parse(buff) {
22            Ok(sar) => sar,
23            Err(e) => {
24                println!(
25                    "Error parsing {}: {}",
26                    file.file_name().to_str().unwrap(),
27                    e
28                );
29                return;
30            }
31        };
32
33        let image = match drawer.draw(&sar) {
34            Ok(image) => image,
35            Err(e) => {
36                println!("Error drawing {}: {}", file.path().display(), e);
37                return;
38            }
39        };
40        image
41            .save(target_dir.join(format!("{}.png", file.file_name().to_str().unwrap())))
42            .unwrap();
43        println!(
44            "Saved to {}",
45            target_dir
46                .join(format!("{}.png", file.file_name().to_str().unwrap()))
47                .display()
48        );
49    })
50}
Source

pub fn with_raise_error(self, raise_error: bool) -> Self

Source

pub fn with_chunk_size(self, chunk_size: usize) -> Self

Trait Implementations§

Source§

impl Default for SymbolArtDrawer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S, L> Drawer<S, L> for SymbolArtDrawer
where S: SymbolArt<Layer = L>, L: SymbolArtLayer + Sync,

Source§

fn draw(&self, sa: &S) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>>

Source§

fn draw_with_scale( &self, sa: &S, scale: f32, ) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V