Skip to content

Commit 785b8c3

Browse files
author
HeroicKatora
authored
Merge pull request #140 from lovasoa/improve_idct
small idct code improvement
2 parents 4d7e36d + 76e993a commit 785b8c3

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

examples/decode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern crate jpeg_decoder as jpeg;
22
extern crate png;
33

4-
use png::HasParameters;
54
use std::env;
65
use std::fs::File;
76
use std::io::{self, BufReader, Write};

src/idct.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,7 @@ fn dequantize_and_idct_block_1x1(coefficients: &[i16], quantization_table: &[u16
297297
// take a -128..127 value and stbi__clamp it and convert to 0..255
298298
fn stbi_clamp(x: i32) -> u8
299299
{
300-
// trick to use a single test to catch both cases
301-
if x as u32 > 255 {
302-
if x < 0 { return 0; }
303-
if x > 255 { return 255; }
304-
}
305-
306-
x as u8
300+
x.max(0).min(255) as u8
307301
}
308302

309303
fn stbi_f2f(x: f32) -> i32 {

0 commit comments

Comments
 (0)