equal
deleted
inserted
replaced
32 |
32 |
33 const PREVIEW_WIDTH: u32 = 256; |
33 const PREVIEW_WIDTH: u32 = 256; |
34 const PREVIEW_HEIGHT: u32 = 128; |
34 const PREVIEW_HEIGHT: u32 = 128; |
35 const PREVIEW_NPIXELS: usize = (PREVIEW_WIDTH * PREVIEW_HEIGHT) as usize; |
35 const PREVIEW_NPIXELS: usize = (PREVIEW_WIDTH * PREVIEW_HEIGHT) as usize; |
36 const SCALE_FACTOR: u32 = 16; |
36 const SCALE_FACTOR: u32 = 16; |
|
37 const VALUE_PER_INPIXEL: u8 = 1; |
37 |
38 |
38 fn resize_mono_preview(mono_pixels: &[u8], in_width: u32, in_height: u32, preview_pixels: &mut [u8]) { |
39 fn resize_mono_preview(mono_pixels: &[u8], in_width: u32, in_height: u32, preview_pixels: &mut [u8]) { |
39 |
40 |
40 assert!(mono_pixels.len() == (in_width * in_height) as usize); |
41 assert!(mono_pixels.len() == (in_width * in_height) as usize); |
41 |
42 |
49 for x in h_offset..(PREVIEW_WIDTH - h_offset) { |
50 for x in h_offset..(PREVIEW_WIDTH - h_offset) { |
50 |
51 |
51 let in_x = h_offset + (x * SCALE_FACTOR); |
52 let in_x = h_offset + (x * SCALE_FACTOR); |
52 |
53 |
53 let out_px_address = (PREVIEW_WIDTH * y + x) as usize; |
54 let out_px_address = (PREVIEW_WIDTH * y + x) as usize; |
54 let in_px_address = (in_width * in_y + in_x) as usize; |
|
55 |
55 |
56 preview_pixels[out_px_address] = mono_pixels[in_px_address]; |
56 let mut in_px_address = (in_width * in_y + in_x) as usize; |
|
57 |
|
58 let mut value = 0; |
|
59 |
|
60 for i in 0..SCALE_FACTOR as usize { |
|
61 for j in 0..SCALE_FACTOR as usize { |
|
62 if (value < 0xff) && (mono_pixels[in_px_address + j] != 0) { |
|
63 value += VALUE_PER_INPIXEL; |
|
64 } |
|
65 } |
|
66 in_px_address += in_width as usize; |
|
67 } |
|
68 |
|
69 preview_pixels[out_px_address] = value; |
57 } |
70 } |
58 } |
71 } |
59 } |
72 } |
60 |
73 |
61 fn main() { |
74 fn main() { |