Skip to content

Commit

Permalink
+0.5 Rounding fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Nov 29, 2024
1 parent 8724cee commit 949ab0d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/codecs/jpeg/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,11 @@ fn rgb_to_ycbcr<P: Pixel>(pixel: P) -> (u8, u8, u8) {
const C_YR: i32 = 19595; // 0.29900 = 19595 * 2^-16
const C_YG: i32 = 38469; // 0.58700 = 38469 * 2^-16
const C_YB: i32 = 7471; // 0.11400 = 7471 * 2^-16
const Y_ROUNDING: i32 = 1 << 15; // + 0.5 to perform rounding shift right in-place
const Y_ROUNDING: i32 = (1 << 15) - 1; // + 0.5 to perform rounding shift right in-place
const C_UR: i32 = 11059; // 0.16874 = 11059 * 2^-16
const C_UG: i32 = 21709; // 0.33126 = 21709 * 2^-16
const C_UB: i32 = 32768; // 0.5 = 32768 * 2^-16
const UV_BIAS_ROUNDING: i32 = (128 * (1 << 16)) + (1 << 15); // 128 + 0.5 = ((128 * (1 << 16)) + (1 << 15)) * 2^-16 ; + 0.5 to perform rounding shift right in-place
const UV_BIAS_ROUNDING: i32 = (128 * (1 << 16)) + ((1 << 15) - 1); // 128 + 0.5 = ((128 * (1 << 16)) + ((1 << 15) - 1)) * 2^-16 ; + 0.5 to perform rounding shift right in-place
const C_VR: i32 = C_UB; // 0.5 = 32768 * 2^-16
const C_VG: i32 = 27439; // 0.41869 = 27439 * 2^-16
const C_VB: i32 = 5329; // 0.08131409 = 5329 * 2^-16
Expand Down Expand Up @@ -897,6 +897,7 @@ mod tests {
// note that, even with the encode quality set to 100, we do not get the same image
// back. Therefore, we're going to assert that it's at least red-ish:
assert_eq!(3, decoded.len());
println!("{:?}", &decoded[0..3]);
assert!(decoded[0] > 0x80);
assert!(decoded[1] < 0x80);
assert!(decoded[2] < 0x80);
Expand Down

0 comments on commit 949ab0d

Please sign in to comment.