Add WEBP, TIFF, ICO, TGA, HDR, and EXR image import and more raster export formats (#4554)

* Add WEBP, TIFF, ICO, TGA, HDR, and EXR image import and more raster export file types

* Try a file as TGA only when no image format is recognized
This commit is contained in:
Keavon Chambers
2026-09-19 18:14:37 -07:00
parent 23e6b0f11d
commit 2ed5e775e5
16 changed files with 373 additions and 122 deletions
+5 -10
View File
@@ -250,7 +250,10 @@ pub fn empty_image(_: impl Ctx, transform: Item<DAffine2>, color: Item<Color>) -
Item::new_from_element(Raster::new_cpu(image)).with_attribute(ATTR_TRANSFORM, transform)
}
#[node_macro::node(category(""))]
/// Displays an image from a file.
///
/// Reads PNG, JPG, GIF, WEBP, TIFF, BMP, TGA, ICO, HDR, and EXR files. Light brighter than white, as HDR and EXR files can hold, is clipped to white.
#[node_macro::node(category("Raster"))]
pub fn image<'a: 'n>(
_: impl Ctx,
_primary: (),
@@ -259,16 +262,8 @@ pub fn image<'a: 'n>(
resource: Item<Resource>,
) -> Item<Raster<CPU>> {
let resource = resource.into_element();
let image_data = resource.as_ref();
let Some(image) = Image::from_encoded(resource.as_ref()) else { return Item::default() };
let Some(image) = ::image::load_from_memory(image_data).ok() else { return Item::default() };
let image = image.to_rgba32f();
let image = Image {
data: image.chunks(4).map(|pixel| Color::from_gamma_srgb_channels(pixel[0], pixel[1], pixel[2], pixel[3])).collect(),
width: image.width(),
height: image.height(),
..Default::default()
};
Item::new_from_element(Raster::new_cpu(image))
}