[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling downwards #267

Open
Cthutu opened this issue Mar 24, 2022 · 3 comments
Open

Scaling downwards #267

Cthutu opened this issue Mar 24, 2022 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Cthutu
Copy link
Cthutu commented Mar 24, 2022

While writing a simple image viewer, I discovered that scaling down is not supported. That is, if the pixel buffer is larger than the surface texture. Would it be difficult to scale an image to fit the surface texture, adding borders horizontally or vertically as appropriate to keep the aspect ratio?

@parasyte parasyte added enhancement New feature or request good first issue Good for newcomers labels Mar 24, 2022
@parasyte
Copy link
Owner
parasyte commented Mar 24, 2022

It would not be too difficult to add this. The main pieces of the puzzle are:

  1. Changing the min-filter to Linear so that scaling down retains some image quality.
    min_filter: wgpu::FilterMode::Nearest,
  2. Updating the resize constraints when creating the scaling matrix. The primary constraint is the max(1.0).floor() call here:

    pixels/src/renderers.rs

    Lines 233 to 237 in 94b8749

    // Get smallest scale size
    let scale = (screen_width / texture_width)
    .min(screen_height / texture_height)
    .max(1.0)
    .floor();

There are probably some other things that also need to be updated along the way. But these are the most prominent in my mind.

I initially thought that using mipmapping would also help with quality and efficiency when scaling below the texture's native resolution. But it would add some complexity by requiring each mip level to be regenerated on every frame. That would definitely have a negative impact on efficiency. Mipmaps are beneficial for static textures, not dynamic textures.

@snylonue
Copy link

@parasyte

Updating the resize constraints when creating the scaling matrix. The primary constraint is the max(1.0).floor() call here:

Can you tell how to update it? I copied the renderer.rs in the fill-window branch and removed .max(1.0) but it doesn't work

@parasyte
Copy link
Owner

I copied the renderer.rs in the fill-window branch and removed .max(1.0) but it doesn't work

Did you also remove it in the default renderer? The default renderer is run first, followed by the custom renderer in the fill-window example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants