+
Skip to content

Monitor downsampling logic is incorrect #64

@THEGOLDENPRO

Description

@THEGOLDENPRO

Pretty sure I wrote this logic mistakenly wrong when I re-wrote it in ImageHandler for v1.0-alpha.15.

This was how it was before in v1.0-alpha.14:

roseate/src/image.rs

Lines 155 to 192 in 429bbf8

let all_display_infos = DisplayInfo::all().expect(
"Failed to get information about your display monitor!"
);
// NOTE: I don't think the first monitor is always the primary and
// if that is the case then we're gonna have a problem. (i.e images overly downsampled or not at all)
let primary_display_maybe = all_display_infos.first().expect(
"Uhhhhh, you don't have a monitor. WHAT!"
);
let marginal_allowance: f32 = 1.3; // TODO: Make this adjustable in the config too as down sample strength.
let (width, height) = (
primary_display_maybe.width as f32 * marginal_allowance,
primary_display_maybe.height as f32 * marginal_allowance
);
debug!(
"Display Size: {} x {}",
primary_display_maybe.width,
primary_display_maybe.height
);
debug!(
"Display Size + Downsample Marginal Allowance: {} x {}", width, height
);
debug!(
"Image Size: {} x {}",
image_size.width,
image_size.height
);
// If the image is a lot bigger than the user's monitor
// then apply the downsample optimization for this image.
if image_size.width > width as usize && image_size.height > height as usize {
optimizations.push(ImageOptimization::Downsample(width as u32, height as u32));
}
optimizations

This is how it is now in v1.0-alpha.15:

if let Some(ImageOptimizations::MonitorDownsampling(marginal_allowance)) = self.has_optimization(
&ImageOptimizations::MonitorDownsampling(u32::default())
) {
let (monitor_width, monitor_height) = monitor_size.get();
// If the image is a lot bigger than the user's
// monitor then apply monitor downsample, if not we shouldn't.
if image.image_size.width as u32 > monitor_width as u32 && image.image_size.height as u32 > monitor_height as u32 {
debug!(
"Image is significantly bigger than system's \
display monitor so monitor downsampling will be applied..."
);
let image_size = (image.image_size.width, image.image_size.height);
debug!(
"Image Size: {} x {}", image_size.0, image_size.1
);
let (monitor_width, monitor_height) = monitor_size.get();
debug!(
"Display (Monitor) Size: {} x {}", monitor_width, monitor_height
);
let (width, height) = get_monitor_downsampling_size(
*marginal_allowance, monitor_size
);
debug!(
"Display + Monitor Downsample Marginal Allowance ({}): {} x {}",
marginal_allowance, width, height
);
image_modifications.replace(ImageModifications::Resize((width, height)));
}
}

I think I forgot to apply marginal allowance to monitor width and height.

This should be before we check the image size:

let (width, height) = get_monitor_downsampling_size(
*marginal_allowance, monitor_size
);

like this:

- let (monitor_width, monitor_height) = monitor_size.get();

+ let (width, height) = get_monitor_downsampling_size(
+    *marginal_allowance, monitor_size
+ );

// If the image is a lot bigger than the user's 
// monitor then apply monitor downsample, if not we shouldn't.
- if image.image_size.width as u32 > monitor_width as u32 && image.image_size.height as u32 > monitor_height as u32 {
+ if image.image_size.width as u32 > width as u32 && image.image_size.height as u32 > height as u32 {

-    let (width, height) = get_monitor_downsampling_size(
-        *marginal_allowance, monitor_size
-    );

    // other code...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载