web_image/
format.rs

1//! Image format magic numbers
2
3use image::ImageFormat;
4use wasm_bindgen::prelude::wasm_bindgen;
5
6#[wasm_bindgen]
7#[derive(Copy, Clone, Eq, PartialEq)]
8/// Provides integer values corresponding to all supported image formats.
9pub enum ImageFormatInt {
10    Png = 1,
11    Jpeg = 2,
12    Gif = 3,
13    WebP = 4,
14    Pnm = 5,
15    Tiff = 6,
16    Tga = 7,
17    Dds = 8,
18    Bmp = 9,
19    Ico = 10,
20    Hdr = 11,
21    OpenExr = 12,
22    Farbfeld = 13,
23    Avif = 14,
24    Qoi = 15,
25}
26
27impl From<ImageFormatInt> for ImageFormat {
28    fn from(value: ImageFormatInt) -> Self {
29        match value {
30            ImageFormatInt::Png => ImageFormat::Png,
31            ImageFormatInt::Jpeg => ImageFormat::Jpeg,
32            ImageFormatInt::Gif => ImageFormat::Gif,
33            ImageFormatInt::WebP => ImageFormat::WebP,
34            ImageFormatInt::Pnm => ImageFormat::Pnm,
35            ImageFormatInt::Tiff => ImageFormat::Tiff,
36            ImageFormatInt::Tga => ImageFormat::Tga,
37            ImageFormatInt::Dds => ImageFormat::Dds,
38            ImageFormatInt::Bmp => ImageFormat::Bmp,
39            ImageFormatInt::Ico => ImageFormat::Ico,
40            ImageFormatInt::Hdr => ImageFormat::Hdr,
41            ImageFormatInt::OpenExr => ImageFormat::OpenExr,
42            ImageFormatInt::Farbfeld => ImageFormat::Farbfeld,
43            ImageFormatInt::Avif => ImageFormat::Avif,
44            ImageFormatInt::Qoi => ImageFormat::Qoi,
45        }
46    }
47}
48
49impl From<ImageFormat> for ImageFormatInt {
50    fn from(value: ImageFormat) -> Self {
51        match value {
52            ImageFormat::Png => ImageFormatInt::Png,
53            ImageFormat::Jpeg => ImageFormatInt::Jpeg,
54            ImageFormat::Gif => ImageFormatInt::Gif,
55            ImageFormat::WebP => ImageFormatInt::WebP,
56            ImageFormat::Pnm => ImageFormatInt::Pnm,
57            ImageFormat::Tiff => ImageFormatInt::Tiff,
58            ImageFormat::Tga => ImageFormatInt::Tga,
59            ImageFormat::Dds => ImageFormatInt::Dds,
60            ImageFormat::Bmp => ImageFormatInt::Bmp,
61            ImageFormat::Ico => ImageFormatInt::Ico,
62            ImageFormat::Hdr => ImageFormatInt::Hdr,
63            ImageFormat::OpenExr => ImageFormatInt::OpenExr,
64            ImageFormat::Farbfeld => ImageFormatInt::Farbfeld,
65            ImageFormat::Avif => ImageFormatInt::Avif,
66            ImageFormat::Qoi => ImageFormatInt::Qoi,
67            _ => unimplemented!("Unknown image format"),
68        }
69    }
70}