Skip to content

Commit

Permalink
Fix color conversion for generic capture.
Browse files Browse the repository at this point in the history
  • Loading branch information
H-M-H committed Jun 10, 2020
1 parent 4415c7b commit cbda371
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 11 additions & 21 deletions src/screen_capture/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ pub struct ScreenCaptureGeneric {

impl ScreenCaptureGeneric {
pub fn new() -> Self {
Self {
img: None,
}
Self { img: None }
}
}

Expand Down Expand Up @@ -53,28 +51,20 @@ impl ScreenCapture for ScreenCaptureGeneric {
// Cb and Cr
for yy in 0..(height / 2) {
for xx in 0..(width / 2) {
let p11 = img
.get_pixel(2 * xx as u32, 2 * yy as u32)
.to_rgb();
let p11 = img.get_pixel(2 * xx as u32, 2 * yy as u32).to_rgb();
let p11 = p11.channels();
let p12 = img
.get_pixel(2 * xx as u32 + 1, 2 * yy as u32)
.to_rgb();
let p12 = img.get_pixel(2 * xx as u32 + 1, 2 * yy as u32).to_rgb();
let p12 = p12.channels();
let p21 = img
.get_pixel(2 * xx as u32, 2 * yy as u32 + 1)
.to_rgb();
let p21 = img.get_pixel(2 * xx as u32, 2 * yy as u32 + 1).to_rgb();
let p21 = p21.channels();
let p22 = img
.get_pixel(2 * xx as u32 + 1, 2 * yy as u32 + 1)
.to_rgb();
let p22 = img.get_pixel(2 * xx as u32 + 1, 2 * yy as u32 + 1).to_rgb();
let p22 = p22.channels();
let mut r = (p11[0] + p12[0] + p21[0] + p22[0]) as i32;
let mut g = (p11[1] + p12[1] + p21[1] + p22[1]) as i32;
let mut b = (p11[2] + p12[2] + p21[2] + p22[2]) as i32;
r /= 4;
g /= 4;
b /= 4;
let mut r = p11[0] as i32 + p12[0] as i32 + p21[0] as i32 + p22[0] as i32;
let mut g = p11[1] as i32 + p12[1] as i32 + p21[1] as i32 + p22[1] as i32;
let mut b = p11[2] as i32 + p12[2] as i32 + p21[2] as i32 + p22[2] as i32;
r >>= 2;
g >>= 2;
b >>= 2;
u[yy * u_line_size + xx] = (((128 + 112 * b - 38 * r - 74 * g) >> 8) + 128) as u8;
v[yy * v_line_size + xx] = (((128 + 112 * r - 94 * g - 18 * b) >> 8) + 128) as u8;
}
Expand Down
6 changes: 3 additions & 3 deletions src/screen_capture/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ impl ScreenCapture for ScreenCaptureX11 {
+ data[8 * (yy * width + xx) + 1 + 4 + 4 * width] as i32;
r += data[8 * (yy * width + xx) + 2 + 4 * width] as i32
+ data[8 * (yy * width + xx) + 2 + 4 + 4 * width] as i32;
r /= 4;
g /= 4;
b /= 4;
r >>= 2;
g >>= 2;
b >>= 2;
u[yy * u_line_size + xx] = (((128 + 112 * b - 38 * r - 74 * g) >> 8) + 128) as u8;
v[yy * v_line_size + xx] = (((128 + 112 * r - 94 * g - 18 * b) >> 8) + 128) as u8;
}
Expand Down

0 comments on commit cbda371

Please sign in to comment.