Skip to content

Commit

Permalink
Merge pull request #93 from helmerapp/fix/windows-scale-factor
Browse files Browse the repository at this point in the history
fix: minor change for scale factor
  • Loading branch information
clearlysid authored Jun 25, 2024
2 parents 8c1b76e + 0b2de3c commit 1b7c70d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/capturer/engine/win/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
capturer::{Area, Options, Point, Resolution, Size},
frame::{BGRAFrame, Frame, FrameType},
targets::{self, Target},
targets::{self, get_scale_factor, Target},
};
use std::cmp;
use std::sync::mpsc;
Expand Down Expand Up @@ -191,12 +191,10 @@ pub fn get_output_frame_size(options: &Options) -> [u32; 2] {
.clone()
.unwrap_or_else(|| Target::Display(targets::get_main_display()));

let scale_factor = targets::get_scale_factor(&target);

let crop_area = get_crop_area(options);

let mut output_width = (crop_area.size.width * scale_factor) as u32;
let mut output_height = (crop_area.size.height * scale_factor) as u32;
let mut output_width = (crop_area.size.width) as u32;
let mut output_height = (crop_area.size.height) as u32;

match options.output_resolution {
Resolution::Captured => {}
Expand All @@ -216,6 +214,11 @@ pub fn get_output_frame_size(options: &Options) -> [u32; 2] {
[output_width, output_height]
}

fn get_absolute_value(value: f64, scale_factor: f64) -> f64 {
let value = (value * scale_factor).floor();
value + value % 2.0
}

pub fn get_crop_area(options: &Options) -> Area {
let target = options
.target
Expand All @@ -224,17 +227,20 @@ pub fn get_crop_area(options: &Options) -> Area {

let (width, height) = targets::get_target_dimensions(&target);

let scale_factor = targets::get_scale_factor(&target);
options
.crop_area
.as_ref()
.map(|val| {
let input_width = val.size.width + val.size.width % 2.0;
let input_height = val.size.height + val.size.height % 2.0;
// WINDOWS: limit values [input-width, input-height] = [146, 50]
Area {
origin: val.origin.clone(),
origin: Point {
x: get_absolute_value(val.origin.x, scale_factor),
y: get_absolute_value(val.origin.y, scale_factor),
},
size: Size {
width: input_width as f64,
height: input_height as f64,
width: get_absolute_value(val.size.width, scale_factor),
height: get_absolute_value(val.size.height, scale_factor),
},
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/targets/win/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn get_scale_factor(target: &Target) -> f64 {
},
};

let scale_factor = dpi / BASE_DPI;
let scale_factor = dpi as f64 / BASE_DPI as f64;
scale_factor as f64
}

Expand Down

0 comments on commit 1b7c70d

Please sign in to comment.