MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / load_texture

Method load_texture

canvas/src/primitives.rs:77–94  ·  view source on GitHub ↗
(&mut self, texture_id: TextureId, data: TSrc)

Source from the content-addressed store, hash-verified

75 ///
76 #[cfg(feature = "image-loading")]
77 fn load_texture<TSrc: io::BufRead+io::Read+io::Seek>(&mut self, texture_id: TextureId, data: TSrc) -> Option<(usize, usize)> {
78 // Load the image
79 let img = ImageReader::new(data).with_guessed_format().ok()?;
80 let img = img.decode().ok()?;
81
82 // Convert to 8-bit RGBA
83 let img = img.into_rgba8();
84 let width = img.width();
85 let height = img.height();
86
87 // Load the texture
88 let raw_pixels = Arc::new(img.into_raw());
89 self.create_texture(texture_id, width, height, TextureFormat::Rgba);
90 self.set_texture_bytes(texture_id, 0, 0, width, height, raw_pixels);
91
92 // Result is the image size
93 Some((width as _, height as _))
94 }
95}
96
97///

Callers 3

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Implementers 1

primitives.rscanvas/src/primitives.rs

Calls 3

decodeMethod · 0.80
create_textureMethod · 0.80
set_texture_bytesMethod · 0.80

Tested by

no test coverage detected