From 15905644e6e7a56b0d84f2e60e555c892fdafed8 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:25:50 +0000 Subject: [PATCH 1/6] Added JPEG YUV Fixed point encoding with benchmark --- Cargo.toml | 4 +++ benches/fixed_point.rs | 74 ++++++++++++++++++++++++++++++++++++++ src/codecs/jpeg/encoder.rs | 47 ++++++++++++++++-------- 3 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 benches/fixed_point.rs diff --git a/Cargo.toml b/Cargo.toml index aa88c9ea0d..c3f5a9e7c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,3 +115,7 @@ harness = false path = "benches/blur.rs" name = "blur" harness = false + +[[bench]] +name = "fixed_point" +harness = false diff --git a/benches/fixed_point.rs b/benches/fixed_point.rs new file mode 100644 index 0000000000..25f06bcbdb --- /dev/null +++ b/benches/fixed_point.rs @@ -0,0 +1,74 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use image::{ImageBuffer, Rgb}; + +pub fn bench_jpeg_fixed_point(c: &mut Criterion) { + let width = 1920; + let height = 1920; + let src = ImageBuffer::from_pixel(width, height, Rgb([213u8, 156, 64])); + + c.bench_function("Test JPEG floating point", |b| { + let mut y_plane = vec![0u8; width as usize * height as usize]; + let mut u_plane = vec![0u8; width as usize * height as usize]; + let mut v_plane = vec![0u8; width as usize * height as usize]; + b.iter(|| { + for (((rgb, y_dst), u_dst), v_dst) in src + .chunks_exact(3) + .zip(y_plane.iter_mut()) + .zip(u_plane.iter_mut()) + .zip(v_plane.iter_mut()) + { + let r: f32 = rgb[0] as f32; + let g: f32 = rgb[1] as f32; + let b: f32 = rgb[2] as f32; + + // Coefficients from JPEG File Interchange Format (Version 1.02), multiplied for 255 maximum. + let y = 0.299 * r + 0.587 * g + 0.114 * b; + let cb = -0.1687 * r - 0.3313 * g + 0.5 * b + 128.; + let cr = 0.5 * r - 0.4187 * g - 0.0813 * b + 128.; + *y_dst = y as u8; + *u_dst = cb as u8; + *v_dst = cr as u8; + } + }); + }); + + c.bench_function("Test JPEG fixed point", |b| { + let mut y_plane = vec![0u8; width as usize * height as usize]; + let mut u_plane = vec![0u8; width as usize * height as usize]; + let mut v_plane = vec![0u8; width as usize * height as usize]; + b.iter(|| { + for (((rgb, y_dst), u_dst), v_dst) in src + .chunks_exact(3) + .zip(y_plane.iter_mut()) + .zip(u_plane.iter_mut()) + .zip(v_plane.iter_mut()) + { + let r = rgb[0] as i32; + let g = rgb[1] as i32; + let b = rgb[2] as i32; + 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 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 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 + + let y = (C_YR * r + C_YG * g + C_YB * b + Y_ROUNDING) >> 16; + let cb = (-C_UR * r - C_UG * g + C_UB * b + UV_BIAS_ROUNDING) >> 16; + let cr = (C_VR * r - C_VG * g - C_VB * b + UV_BIAS_ROUNDING) >> 16; + + *y_dst = y as u8; + *u_dst = cb as u8; + *v_dst = cr as u8; + } + }); + }); +} + +criterion_group!(benches, bench_jpeg_fixed_point); +criterion_main!(benches); diff --git a/src/codecs/jpeg/encoder.rs b/src/codecs/jpeg/encoder.rs index d641b44bb2..5af0433809 100644 --- a/src/codecs/jpeg/encoder.rs +++ b/src/codecs/jpeg/encoder.rs @@ -1,8 +1,5 @@ #![allow(clippy::too_many_arguments)] -use std::borrow::Cow; -use std::io::{self, Write}; - use crate::error::{ ImageError, ImageResult, ParameterError, ParameterErrorKind, UnsupportedError, UnsupportedErrorKind, @@ -10,6 +7,9 @@ use crate::error::{ use crate::image::{ImageEncoder, ImageFormat}; use crate::utils::clamp; use crate::{ExtendedColorType, GenericImageView, ImageBuffer, Luma, Pixel, Rgb}; +use num_traits::ToPrimitive; +use std::borrow::Cow; +use std::io::{self, Write}; use super::entropy::build_huff_lut_const; use super::transform; @@ -771,19 +771,36 @@ fn encode_coefficient(coefficient: i32) -> (u8, u16) { #[inline] fn rgb_to_ycbcr(pixel: P) -> (u8, u8, u8) { - use crate::traits::Primitive; - use num_traits::cast::ToPrimitive; - let [r, g, b] = pixel.to_rgb().0; - let max: f32 = P::Subpixel::DEFAULT_MAX_VALUE.to_f32().unwrap(); - let r: f32 = r.to_f32().unwrap(); - let g: f32 = g.to_f32().unwrap(); - let b: f32 = b.to_f32().unwrap(); - - // Coefficients from JPEG File Interchange Format (Version 1.02), multiplied for 255 maximum. - let y = 76.245 / max * r + 149.685 / max * g + 29.07 / max * b; - let cb = -43.0185 / max * r - 84.4815 / max * g + 127.5 / max * b + 128.; - let cr = 127.5 / max * r - 106.7685 / max * g - 20.7315 / max * b + 128.; + let r: i32 = r.to_u8().unwrap() as i32; + let g: i32 = g.to_u8().unwrap() as i32; + let b: i32 = b.to_u8().unwrap() as i32; + + /* + JPEG RGB -> YCbCr is defined as following equations using Bt.601 Full Range matrix: + Y = 0.29900 * R + 0.58700 * G + 0.11400 * B + Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + 128 + Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + 128 + + To avoid using slow floating point conversion is done in fixed point, + using following coefficients with rounding to nearest integer mode: + */ + + 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 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 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 + + let y = (C_YR * r + C_YG * g + C_YB * b + Y_ROUNDING) >> 16; + let cb = (-C_UR * r - C_UG * g + C_UB * b + UV_BIAS_ROUNDING) >> 16; + let cr = (C_VR * r - C_VG * g - C_VB * b + UV_BIAS_ROUNDING) >> 16; (y as u8, cb as u8, cr as u8) } From 8724cee61c56edfc76ed2de9a55d83a046d303a5 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:26:32 +0000 Subject: [PATCH 2/6] Dropped JPEG YUV benchmark --- Cargo.toml | 6 +--- benches/fixed_point.rs | 74 ------------------------------------------ 2 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 benches/fixed_point.rs diff --git a/Cargo.toml b/Cargo.toml index c3f5a9e7c9..379cd3d6a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,8 +114,4 @@ harness = false [[bench]] path = "benches/blur.rs" name = "blur" -harness = false - -[[bench]] -name = "fixed_point" -harness = false +harness = false \ No newline at end of file diff --git a/benches/fixed_point.rs b/benches/fixed_point.rs deleted file mode 100644 index 25f06bcbdb..0000000000 --- a/benches/fixed_point.rs +++ /dev/null @@ -1,74 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use image::{ImageBuffer, Rgb}; - -pub fn bench_jpeg_fixed_point(c: &mut Criterion) { - let width = 1920; - let height = 1920; - let src = ImageBuffer::from_pixel(width, height, Rgb([213u8, 156, 64])); - - c.bench_function("Test JPEG floating point", |b| { - let mut y_plane = vec![0u8; width as usize * height as usize]; - let mut u_plane = vec![0u8; width as usize * height as usize]; - let mut v_plane = vec![0u8; width as usize * height as usize]; - b.iter(|| { - for (((rgb, y_dst), u_dst), v_dst) in src - .chunks_exact(3) - .zip(y_plane.iter_mut()) - .zip(u_plane.iter_mut()) - .zip(v_plane.iter_mut()) - { - let r: f32 = rgb[0] as f32; - let g: f32 = rgb[1] as f32; - let b: f32 = rgb[2] as f32; - - // Coefficients from JPEG File Interchange Format (Version 1.02), multiplied for 255 maximum. - let y = 0.299 * r + 0.587 * g + 0.114 * b; - let cb = -0.1687 * r - 0.3313 * g + 0.5 * b + 128.; - let cr = 0.5 * r - 0.4187 * g - 0.0813 * b + 128.; - *y_dst = y as u8; - *u_dst = cb as u8; - *v_dst = cr as u8; - } - }); - }); - - c.bench_function("Test JPEG fixed point", |b| { - let mut y_plane = vec![0u8; width as usize * height as usize]; - let mut u_plane = vec![0u8; width as usize * height as usize]; - let mut v_plane = vec![0u8; width as usize * height as usize]; - b.iter(|| { - for (((rgb, y_dst), u_dst), v_dst) in src - .chunks_exact(3) - .zip(y_plane.iter_mut()) - .zip(u_plane.iter_mut()) - .zip(v_plane.iter_mut()) - { - let r = rgb[0] as i32; - let g = rgb[1] as i32; - let b = rgb[2] as i32; - 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 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 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 - - let y = (C_YR * r + C_YG * g + C_YB * b + Y_ROUNDING) >> 16; - let cb = (-C_UR * r - C_UG * g + C_UB * b + UV_BIAS_ROUNDING) >> 16; - let cr = (C_VR * r - C_VG * g - C_VB * b + UV_BIAS_ROUNDING) >> 16; - - *y_dst = y as u8; - *u_dst = cb as u8; - *v_dst = cr as u8; - } - }); - }); -} - -criterion_group!(benches, bench_jpeg_fixed_point); -criterion_main!(benches); From 949ab0d99cb7a0542de958c3fe81123f36ddaf14 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:38:15 +0000 Subject: [PATCH 3/6] +0.5 Rounding fixed --- src/codecs/jpeg/encoder.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/codecs/jpeg/encoder.rs b/src/codecs/jpeg/encoder.rs index 5af0433809..6a16365c81 100644 --- a/src/codecs/jpeg/encoder.rs +++ b/src/codecs/jpeg/encoder.rs @@ -789,11 +789,11 @@ fn rgb_to_ycbcr(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 @@ -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); From feed4be00c2a922f0ff9e48ab0ef80c34998f0ac Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:41:44 +0000 Subject: [PATCH 4/6] Benchmark with fixed rounding --- Cargo.toml | 6 +++- benches/fixed_point.rs | 74 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 benches/fixed_point.rs diff --git a/Cargo.toml b/Cargo.toml index 379cd3d6a2..c3f5a9e7c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,4 +114,8 @@ harness = false [[bench]] path = "benches/blur.rs" name = "blur" -harness = false \ No newline at end of file +harness = false + +[[bench]] +name = "fixed_point" +harness = false diff --git a/benches/fixed_point.rs b/benches/fixed_point.rs new file mode 100644 index 0000000000..7c4e3b12f0 --- /dev/null +++ b/benches/fixed_point.rs @@ -0,0 +1,74 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use image::{ImageBuffer, Rgb}; + +pub fn bench_jpeg_fixed_point(c: &mut Criterion) { + let width = 1920; + let height = 1920; + let src = ImageBuffer::from_pixel(width, height, Rgb([213u8, 156, 64])); + + c.bench_function("Test JPEG floating point", |b| { + let mut y_plane = vec![0u8; width as usize * height as usize]; + let mut u_plane = vec![0u8; width as usize * height as usize]; + let mut v_plane = vec![0u8; width as usize * height as usize]; + b.iter(|| { + for (((rgb, y_dst), u_dst), v_dst) in src + .chunks_exact(3) + .zip(y_plane.iter_mut()) + .zip(u_plane.iter_mut()) + .zip(v_plane.iter_mut()) + { + let r: f32 = rgb[0] as f32; + let g: f32 = rgb[1] as f32; + let b: f32 = rgb[2] as f32; + + // Coefficients from JPEG File Interchange Format (Version 1.02), multiplied for 255 maximum. + let y = 0.299 * r + 0.587 * g + 0.114 * b; + let cb = -0.1687 * r - 0.3313 * g + 0.5 * b + 128.; + let cr = 0.5 * r - 0.4187 * g - 0.0813 * b + 128.; + *y_dst = y as u8; + *u_dst = cb as u8; + *v_dst = cr as u8; + } + }); + }); + + c.bench_function("Test JPEG fixed point", |b| { + let mut y_plane = vec![0u8; width as usize * height as usize]; + let mut u_plane = vec![0u8; width as usize * height as usize]; + let mut v_plane = vec![0u8; width as usize * height as usize]; + b.iter(|| { + for (((rgb, y_dst), u_dst), v_dst) in src + .chunks_exact(3) + .zip(y_plane.iter_mut()) + .zip(u_plane.iter_mut()) + .zip(v_plane.iter_mut()) + { + let r = rgb[0] as i32; + let g = rgb[1] as i32; + let b = rgb[2] as i32; + 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) - 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) - 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 + + let y = (C_YR * r + C_YG * g + C_YB * b + Y_ROUNDING) >> 16; + let cb = (-C_UR * r - C_UG * g + C_UB * b + UV_BIAS_ROUNDING) >> 16; + let cr = (C_VR * r - C_VG * g - C_VB * b + UV_BIAS_ROUNDING) >> 16; + + *y_dst = y as u8; + *u_dst = cb as u8; + *v_dst = cr as u8; + } + }); + }); +} + +criterion_group!(benches, bench_jpeg_fixed_point); +criterion_main!(benches); \ No newline at end of file From dd391fedb73ced50ea2815023044f64a8f024644 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:42:07 +0000 Subject: [PATCH 5/6] Dropped benchmark again --- Cargo.toml | 6 +--- benches/fixed_point.rs | 74 ------------------------------------------ 2 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 benches/fixed_point.rs diff --git a/Cargo.toml b/Cargo.toml index c3f5a9e7c9..379cd3d6a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,8 +114,4 @@ harness = false [[bench]] path = "benches/blur.rs" name = "blur" -harness = false - -[[bench]] -name = "fixed_point" -harness = false +harness = false \ No newline at end of file diff --git a/benches/fixed_point.rs b/benches/fixed_point.rs deleted file mode 100644 index 7c4e3b12f0..0000000000 --- a/benches/fixed_point.rs +++ /dev/null @@ -1,74 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use image::{ImageBuffer, Rgb}; - -pub fn bench_jpeg_fixed_point(c: &mut Criterion) { - let width = 1920; - let height = 1920; - let src = ImageBuffer::from_pixel(width, height, Rgb([213u8, 156, 64])); - - c.bench_function("Test JPEG floating point", |b| { - let mut y_plane = vec![0u8; width as usize * height as usize]; - let mut u_plane = vec![0u8; width as usize * height as usize]; - let mut v_plane = vec![0u8; width as usize * height as usize]; - b.iter(|| { - for (((rgb, y_dst), u_dst), v_dst) in src - .chunks_exact(3) - .zip(y_plane.iter_mut()) - .zip(u_plane.iter_mut()) - .zip(v_plane.iter_mut()) - { - let r: f32 = rgb[0] as f32; - let g: f32 = rgb[1] as f32; - let b: f32 = rgb[2] as f32; - - // Coefficients from JPEG File Interchange Format (Version 1.02), multiplied for 255 maximum. - let y = 0.299 * r + 0.587 * g + 0.114 * b; - let cb = -0.1687 * r - 0.3313 * g + 0.5 * b + 128.; - let cr = 0.5 * r - 0.4187 * g - 0.0813 * b + 128.; - *y_dst = y as u8; - *u_dst = cb as u8; - *v_dst = cr as u8; - } - }); - }); - - c.bench_function("Test JPEG fixed point", |b| { - let mut y_plane = vec![0u8; width as usize * height as usize]; - let mut u_plane = vec![0u8; width as usize * height as usize]; - let mut v_plane = vec![0u8; width as usize * height as usize]; - b.iter(|| { - for (((rgb, y_dst), u_dst), v_dst) in src - .chunks_exact(3) - .zip(y_plane.iter_mut()) - .zip(u_plane.iter_mut()) - .zip(v_plane.iter_mut()) - { - let r = rgb[0] as i32; - let g = rgb[1] as i32; - let b = rgb[2] as i32; - 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) - 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) - 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 - - let y = (C_YR * r + C_YG * g + C_YB * b + Y_ROUNDING) >> 16; - let cb = (-C_UR * r - C_UG * g + C_UB * b + UV_BIAS_ROUNDING) >> 16; - let cr = (C_VR * r - C_VG * g - C_VB * b + UV_BIAS_ROUNDING) >> 16; - - *y_dst = y as u8; - *u_dst = cb as u8; - *v_dst = cr as u8; - } - }); - }); -} - -criterion_group!(benches, bench_jpeg_fixed_point); -criterion_main!(benches); \ No newline at end of file From 7b8f79a2483df5004a0e2cbb2d818f793f04863d Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Fri, 29 Nov 2024 15:42:32 +0000 Subject: [PATCH 6/6] Removed test values --- src/codecs/jpeg/encoder.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/codecs/jpeg/encoder.rs b/src/codecs/jpeg/encoder.rs index 6a16365c81..0c1f074985 100644 --- a/src/codecs/jpeg/encoder.rs +++ b/src/codecs/jpeg/encoder.rs @@ -897,7 +897,6 @@ 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);