1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! DOC not suitable for 16bits usize
//extern crate core;
pub use crate;
pub use crateChunkDecompressor;
pub use crateParsedPng;
/*
pub type Png<C> = BufferedPng<C>;
pub struct BufferedPng<C> {
pub header: PngHeader,
pub data: Vec<C>,
}
impl<C: PixelColor + Default + From<Rgb888>> BufferedPng<C> {
// TODO from_bytes
pub fn from_slice(bytes: &[u8]) -> Result<Self, DecodeError> {
// TODO decode / uncompress using iterators
let mut undecoded = pre_decode(bytes)?;
// For now, output data is always RGBA, 1 byte per channel.
let mut data = vec![C::default(); undecoded.header.width as usize * undecoded.header.height as usize];
let width = undecoded.header.width as usize;
undecoded.process_scanlines(|scanline_iter,xy_calculator,y| {
for (idx, (r, g, b, a)) in scanline_iter.enumerate() {
let (x, y) = xy_calculator.get_xy(idx, y);
let i = (y * width) + x;
data[i] = C::from(Rgb888::new(r, g, b));
}
},
)?;
Ok(Png {header: undecoded.header, data })
}
}
impl<C: PixelColor> OriginDimensions for BufferedPng<C> {
fn size(&self) -> Size {
Size::new(self.header.width, self.header.height)
}
}
impl<C: PixelColor> ImageDrawable for BufferedPng<C> {
type Color = C;
fn draw<D>(&self, target: &mut D) -> Result<(), D::Error> where D: DrawTarget<Color=Self::Color> {
let area = self.bounding_box();
target.fill_contiguous(&area, self.data.iter().copied())
}
fn draw_sub_image<D>(&self, target: &mut D, area: &Rectangle) -> Result<(), D::Error> where D: DrawTarget<Color=Self::Color> {
let mut index = area.top_left.x + area.top_left.y * self.header.width as i32;
let line_size = Size::new(area.size.width, 1);
for i in 0 .. area.size.height as i32 {
let pos = Point::new(0, i);
let target_area = Rectangle::new(pos, line_size);
let data = &self.data[index as usize .. index as usize + area.size.width as usize];
target.fill_contiguous(&target_area, data.iter().copied())?;
index += self.header.width as i32;
}
Ok(())
}
}
*/