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
pub extern crate turbojpeg_sys as sys;
pub extern crate libc;
pub use common::{PixelFormat, Subsamp, Colorspace, Result, Error};
pub use compress::Compressor;
pub use decompress::{Decompressor, DecompressHeader};
mod common;
mod compress;
mod decompress;
#[derive(Debug, Copy, Clone)]
pub struct Image<T> {
pub pixels: T,
pub width: usize,
pub pitch: usize,
pub height: usize,
pub format: PixelFormat,
}
impl<T> Image<T> {
pub(crate) fn assert_valid(&self, pixels_len: usize) {
let Image { pixels: _, width, pitch, height, format } = *self;
assert!(pitch >= width*format.size(),
"pitch {} is too small for width {} and pixel format {:?}", pitch, width, format);
assert!(height == 0 || pitch*(height - 1) + width*format.size() <= pixels_len,
"pixels length {} is too small for width {}, height {}, pitch {} and pixel format {:?}",
pixels_len, width, height, pitch, format);
}
}