Debian Codegraph @

src/formats/mod.rs

raw symbols SCIP
1 pub mod aespriterust-analyzer cargo imagesize 0.13.0 formats/aesprite/;
2 pub mod bmprust-analyzer cargo imagesize 0.13.0 formats/bmp/;
3 pub mod ddsrust-analyzer cargo imagesize 0.13.0 formats/dds/;
4 pub mod exrrust-analyzer cargo imagesize 0.13.0 formats/exr/;
5 pub mod farbfeldrust-analyzer cargo imagesize 0.13.0 formats/farbfeld/;
6 pub mod gifrust-analyzer cargo imagesize 0.13.0 formats/gif/;
7 pub mod hdrrust-analyzer cargo imagesize 0.13.0 formats/hdr/;
8 pub mod icorust-analyzer cargo imagesize 0.13.0 formats/ico/;
9 pub mod ilbmrust-analyzer cargo imagesize 0.13.0 formats/ilbm/;
10 pub mod jpegrust-analyzer cargo imagesize 0.13.0 formats/jpeg/;
11 pub mod jxlrust-analyzer cargo imagesize 0.13.0 formats/jxl/;
12 pub mod ktx2rust-analyzer cargo imagesize 0.13.0 formats/ktx2/;
13 pub mod pngrust-analyzer cargo imagesize 0.13.0 formats/png/;
14 pub mod pnmrust-analyzer cargo imagesize 0.13.0 formats/pnm/;
15 pub mod psdrust-analyzer cargo imagesize 0.13.0 formats/psd/;
16 pub mod qoirust-analyzer cargo imagesize 0.13.0 formats/qoi/;
17 pub mod tgarust-analyzer cargo imagesize 0.13.0 formats/tga/;
18 pub mod tiffrust-analyzer cargo imagesize 0.13.0 formats/tiff/;
19 pub mod vtfrust-analyzer cargo imagesize 0.13.0 formats/vtf/;
20 pub mod webprust-analyzer cargo imagesize 0.13.0 formats/webp/;
21
22 use craterust-analyzer cargo imagesize 0.13.0 crate/::{containerrust-analyzer cargo imagesize 0.13.0 container/, ImageErrorrust-analyzer cargo imagesize 0.13.0 ImageError#, ImageResultrust-analyzer cargo imagesize 0.13.0 ImageResult#, ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#};
23 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#};
24
25 pub fn image_typerust-analyzer cargo imagesize 0.13.0 formats/image_type().<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#>(reader: &mut R) -> ImageResultrust-analyzer cargo imagesize 0.13.0 ImageResult#<ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#> {
26 let mut header = [0; 12];
27 reader.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut header)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
28
29 // Currently there are no formats where 1 byte is enough to determine format
30 if header.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 {
31 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
32 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#, "Not enough data").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
33 );
34 }
35
36 // This is vaguely organized in what I assume are the most commonly used formats.
37 // I don't know how much this matters for actual execution time.
38 if jpegrust-analyzer cargo imagesize 0.13.0 formats/jpeg/::matchesrust-analyzer cargo imagesize 0.13.0 formats/jpeg/matches().(&header) {
39 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Jpegrust-analyzer cargo imagesize 0.13.0 ImageType#Jpeg#);
40 }
41
42 if pngrust-analyzer cargo imagesize 0.13.0 formats/png/::matchesrust-analyzer cargo imagesize 0.13.0 formats/png/matches().(&header) {
43 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Pngrust-analyzer cargo imagesize 0.13.0 ImageType#Png#);
44 }
45
46 if gifrust-analyzer cargo imagesize 0.13.0 formats/gif/::matchesrust-analyzer cargo imagesize 0.13.0 formats/gif/matches().(&header) {
47 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Gifrust-analyzer cargo imagesize 0.13.0 ImageType#Gif#);
48 }
49
50 if tiffrust-analyzer cargo imagesize 0.13.0 formats/tiff/::matchesrust-analyzer cargo imagesize 0.13.0 formats/tiff/matches().(&header) {
51 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Tiffrust-analyzer cargo imagesize 0.13.0 ImageType#Tiff#);
52 }
53
54 if webprust-analyzer cargo imagesize 0.13.0 formats/webp/::matchesrust-analyzer cargo imagesize 0.13.0 formats/webp/matches().(&header) {
55 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Webprust-analyzer cargo imagesize 0.13.0 ImageType#Webp#);
56 }
57
58 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c) = containerrust-analyzer cargo imagesize 0.13.0 container/::heifrust-analyzer cargo imagesize 0.13.0 container/heif/::matchesrust-analyzer cargo imagesize 0.13.0 container/heif/matches().(&header, reader) {
59 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Heifrust-analyzer cargo imagesize 0.13.0 ImageType#Heif#(c));
60 }
61
62 if jxlrust-analyzer cargo imagesize 0.13.0 formats/jxl/::matchesrust-analyzer cargo imagesize 0.13.0 formats/jxl/matches().(&header) {
63 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Jxlrust-analyzer cargo imagesize 0.13.0 ImageType#Jxl#);
64 }
65
66 if bmprust-analyzer cargo imagesize 0.13.0 formats/bmp/::matchesrust-analyzer cargo imagesize 0.13.0 formats/bmp/matches().(&header) {
67 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Bmprust-analyzer cargo imagesize 0.13.0 ImageType#Bmp#);
68 }
69
70 if psdrust-analyzer cargo imagesize 0.13.0 formats/psd/::matchesrust-analyzer cargo imagesize 0.13.0 formats/psd/matches().(&header) {
71 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Psdrust-analyzer cargo imagesize 0.13.0 ImageType#Psd#);
72 }
73
74 if icorust-analyzer cargo imagesize 0.13.0 formats/ico/::matchesrust-analyzer cargo imagesize 0.13.0 formats/ico/matches().(&header) {
75 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Icorust-analyzer cargo imagesize 0.13.0 ImageType#Ico#);
76 }
77
78 if aespriterust-analyzer cargo imagesize 0.13.0 formats/aesprite/::matchesrust-analyzer cargo imagesize 0.13.0 formats/aesprite/matches().(&header) {
79 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Asepriterust-analyzer cargo imagesize 0.13.0 ImageType#Aseprite#);
80 }
81
82 if exrrust-analyzer cargo imagesize 0.13.0 formats/exr/::matchesrust-analyzer cargo imagesize 0.13.0 formats/exr/matches().(&header) {
83 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Exrrust-analyzer cargo imagesize 0.13.0 ImageType#Exr#);
84 }
85
86 if hdrrust-analyzer cargo imagesize 0.13.0 formats/hdr/::matchesrust-analyzer cargo imagesize 0.13.0 formats/hdr/matches().(&header) {
87 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Hdrrust-analyzer cargo imagesize 0.13.0 ImageType#Hdr#);
88 }
89
90 if ddsrust-analyzer cargo imagesize 0.13.0 formats/dds/::matchesrust-analyzer cargo imagesize 0.13.0 formats/dds/matches().(&header) {
91 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Ddsrust-analyzer cargo imagesize 0.13.0 ImageType#Dds#);
92 }
93
94 if ktx2rust-analyzer cargo imagesize 0.13.0 formats/ktx2/::matchesrust-analyzer cargo imagesize 0.13.0 formats/ktx2/matches().(&header) {
95 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Ktx2rust-analyzer cargo imagesize 0.13.0 ImageType#Ktx2#);
96 }
97
98 if qoirust-analyzer cargo imagesize 0.13.0 formats/qoi/::matchesrust-analyzer cargo imagesize 0.13.0 formats/qoi/matches().(&header) {
99 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Qoirust-analyzer cargo imagesize 0.13.0 ImageType#Qoi#);
100 }
101
102 if farbfeldrust-analyzer cargo imagesize 0.13.0 formats/farbfeld/::matchesrust-analyzer cargo imagesize 0.13.0 formats/farbfeld/matches().(&header) {
103 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Farbfeldrust-analyzer cargo imagesize 0.13.0 ImageType#Farbfeld#);
104 }
105
106 if pnmrust-analyzer cargo imagesize 0.13.0 formats/pnm/::matchesrust-analyzer cargo imagesize 0.13.0 formats/pnm/matches().(&header) {
107 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Pnmrust-analyzer cargo imagesize 0.13.0 ImageType#Pnm#);
108 }
109
110 if vtfrust-analyzer cargo imagesize 0.13.0 formats/vtf/::matchesrust-analyzer cargo imagesize 0.13.0 formats/vtf/matches().(&header) {
111 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Vtfrust-analyzer cargo imagesize 0.13.0 ImageType#Vtf#);
112 }
113
114 if ilbmrust-analyzer cargo imagesize 0.13.0 formats/ilbm/::matchesrust-analyzer cargo imagesize 0.13.0 formats/ilbm/matches().(&header) {
115 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Ilbmrust-analyzer cargo imagesize 0.13.0 ImageType#Ilbm#);
116 }
117
118 // Keep TGA last because it has the highest probability of false positives
119 if tgarust-analyzer cargo imagesize 0.13.0 formats/tga/::matchesrust-analyzer cargo imagesize 0.13.0 formats/tga/matches().(&header, reader) {
120 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageTyperust-analyzer cargo imagesize 0.13.0 ImageType#::Tgarust-analyzer cargo imagesize 0.13.0 ImageType#Tga#);
121 }
122
123 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ImageErrorrust-analyzer cargo imagesize 0.13.0 ImageError#::NotSupportedrust-analyzer cargo imagesize 0.13.0 ImageError#NotSupported#)
124 }