Skip to content

Commit 4313dc2

Browse files
author
kmgx
committed
Fix typos
1 parent 3488119 commit 4313dc2

File tree

12 files changed

+43
-43
lines changed

12 files changed

+43
-43
lines changed
Binary file not shown.
Binary file not shown.

Error-Diffused Block-Truncation-Coding/Cargo.lock Order-Dithered Block-Truncation-Coding/Cargo.lock

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Error-Diffused Block-Truncation-Coding/Cargo.toml Order-Dithered Block-Truncation-Coding/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "edbtc"
2+
name = "odbtc"
33
version = "0.1.0"
44
authors = ["kmgx <[email protected]>"]
55
edition = "2018"
Loading
Loading

Error-Diffused Block-Truncation-Coding/src/main.rs Order-Dithered Block-Truncation-Coding/src/main.rs

+30-30
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ struct Opt {
1515
file: String
1616
}
1717

18-
#[derive(Clone)]
18+
#[derive(Clone, Debug)]
1919
struct VecBlock {
2020
width : usize, height : usize,
2121
pixels : Vec<u8>
2222
}
2323

2424
#[derive(Debug, Clone)]
25-
struct EdbtcBlock {
25+
struct OdbtcBlock {
2626
high_color: u8, low_color: u8,
2727
pixels: Vec<u8>,
2828
width: usize, height : usize
2929
}
3030

31-
impl fmt::Display for EdbtcBlock { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32-
return write!(f, "EdbtcBlock with a = {}, b = {} has pixels {:?}", self.high_color, self.low_color, self.pixels);
31+
impl fmt::Display for OdbtcBlock { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32+
return write!(f, "OdbtcBlock with a = {}, b = {} has pixels {:?}", self.high_color, self.low_color, self.pixels);
3333
}}
3434

35-
struct EdbtcImage {
35+
struct OdbtcImage {
3636
block_count_x: usize,
3737
width : usize, height : usize,
38-
blocks: Vec<EdbtcBlock>
38+
blocks: Vec<OdbtcBlock>
3939
}
4040

4141
fn get_block_nb(i : usize, img_width : usize, block_width : usize, block_height : usize, block_count_x : usize) -> (usize, usize, usize){
@@ -100,14 +100,13 @@ fn build_blocks(pixels : &Vec<u8>, img_width: usize, img_height: usize, block_si
100100
block.pixels.push(pixels[i]);
101101
}
102102

103-
// println!("{:?}, {:?}", blocks[0].len(), blocks[0]);
104-
// println!("{:?}", pixels.len());
103+
// println!("Generated {:?} VecBlocks", blocks.len());
105104

106105
return (blocks, block_count_x, block_count_y);
107106
}
108107

109-
fn encode_blocks(blocks : &Vec<VecBlock>, block_size: usize, block_count_x: usize, img_width: usize, img_height: usize) -> EdbtcImage {
110-
let mut result : EdbtcImage = EdbtcImage{block_count_x: block_count_x, blocks: vec![], width: img_width, height: img_height};
108+
fn encode_blocks(blocks : &Vec<VecBlock>, block_size: usize, block_count_x: usize, img_width: usize, img_height: usize) -> OdbtcImage {
109+
let mut result : OdbtcImage = OdbtcImage{block_count_x: block_count_x, blocks: vec![], width: img_width, height: img_height};
111110
for i in 0..blocks.len() {
112111
let block = &blocks[i];
113112

@@ -125,29 +124,32 @@ fn encode_blocks(blocks : &Vec<VecBlock>, block_size: usize, block_count_x: usiz
125124
}
126125

127126

128-
let newblock = EdbtcBlock{pixels: pix, low_color: min, high_color: max, width: block.width, height : block.height};
129-
println!("newblock : {}", newblock);
127+
let newblock = OdbtcBlock{pixels: pix, low_color: min, high_color: max, width: block.width, height : block.height};
128+
// println!("newblock : {}", newblock);
130129
result.blocks.push(newblock);
131130

132131
}
133132

133+
// println!("Generated {:?} blocks", result.blocks.len());
134+
134135
return result;
135136
}
136137

137-
fn edbtc_encode(image: image::DynamicImage, block_size : usize) -> EdbtcImage {
138+
fn odbtc_encode(image: image::DynamicImage, block_size : usize) -> OdbtcImage {
138139
println!("Encoding...");
139140

140141
let pixels : Vec<u8> = image.raw_pixels();
141142
let size = image.dimensions();
142143
let width = size.0 as usize;
143144
let height = size.1 as usize;
145+
println!("{:?} {:?}", width, height);
144146

145-
let (blocks, block_count_x, block_count_y) = build_blocks(&pixels, width, height, block_size);
146-
return encode_blocks(&blocks, block_size, block_count_x, block_count_y, width);
147+
let (blocks, block_count_x, _) = build_blocks(&pixels, width, height, block_size);
148+
return encode_blocks(&blocks, block_size, block_count_x, width, height);
147149

148150
}
149151

150-
fn edbtc_decode(image: EdbtcImage) -> image::DynamicImage {
152+
fn odbtc_decode(image: OdbtcImage) -> image::DynamicImage {
151153
println!("Decoding...");
152154

153155
let mut pixels : Vec<u8> = vec![];
@@ -158,6 +160,7 @@ fn edbtc_decode(image: EdbtcImage) -> image::DynamicImage {
158160

159161

160162
// println!("{:?}, {:?}", basewidth, baseheight);
163+
// println!("{:?} {:?} {:?}", image.width, image.height, fullsize);
161164

162165
for i in 0..fullsize {
163166

@@ -200,23 +203,20 @@ fn main() {
200203
println!("Saving input image");
201204
img.save("./input.png").unwrap();
202205

203-
let output_4 = edbtc_decode(edbtc_encode(img.clone(), 4));
204-
let output_8 = edbtc_decode(edbtc_encode(img.clone(), 8));
205-
//let output_16 = edbtc_decode(edbtc_encode(img.clone(), 16));
206-
//let output_32 = edbtc_decode(edbtc_encode(img.clone(), 32));
207-
208-
println!("HPSNR 4x4 : {}", img_quality::hpsnr(&img, &output_4).unwrap());
209-
println!("HPSNR 8x8 : {}", img_quality::hpsnr(&img, &output_8).unwrap());
210-
//println!("HPSNR 16x16 : {}", img_quality::hpsnr(&img, &output_16).unwrap());
211-
//println!("HPSNR 32x32 : {}", img_quality::hpsnr(&img, &output_32).unwrap());
212-
213-
206+
let output_4 = odbtc_decode(odbtc_encode(img.clone(), 4));
207+
let output_8 = odbtc_decode(odbtc_encode(img.clone(), 8));
208+
let output_16 = odbtc_decode(odbtc_encode(img.clone(), 16));
209+
let output_32 = odbtc_decode(odbtc_encode(img.clone(), 32));
214210

215211
println!("Saving results");
216-
output_4.save("./output4.png").unwrap();
217212
output_8.save("./output8.png").unwrap();
218-
//output_16.save("./output16.png").unwrap();
219-
//output_32.save("./output32.png").unwrap();
213+
output_4.save("./output4.png").unwrap();
214+
output_16.save("./output16.png").unwrap();
215+
output_32.save("./output32.png").unwrap();
220216

217+
println!("HPSNR 4x4 : {}", img_quality::hpsnr(&img, &output_4).unwrap());
218+
println!("HPSNR 8x8 : {}", img_quality::hpsnr(&img, &output_8).unwrap());
219+
println!("HPSNR 16x16 : {}", img_quality::hpsnr(&img, &output_16).unwrap());
220+
println!("HPSNR 32x32 : {}", img_quality::hpsnr(&img, &output_32).unwrap());
221221

222222
}

img-quality/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn hpsnr(original_img : &image::DynamicImage, new_img : &image::DynamicImage
4141
let (filter, hvf_size) = get_hvf();
4242

4343
// Dimensions check
44-
if original_img.dimensions() != new_img.dimensions() { return Err("Size doesn't match".to_string()); }
44+
if original_img.dimensions() != new_img.dimensions() { return Err(format!("Size doesn't match : {:?} vs {:?}", original_img.dimensions(), new_img.dimensions())); }
4545
let img_width = original_img.dimensions().0 as usize;
4646
let img_height = original_img.dimensions().1 as usize;
4747
let original = original_img.raw_pixels();

0 commit comments

Comments
 (0)