pixels icon indicating copy to clipboard operation
pixels copied to clipboard

Scaling downwards

Open Cthutu opened this issue 3 years ago • 3 comments

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?

Cthutu avatar Mar 24 '22 12:03 Cthutu

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. https://github.com/parasyte/pixels/blob/94b87496c3715b6fcc4541c6a9370a5544569c7b/src/renderers.rs#L38
  2. Updating the resize constraints when creating the scaling matrix. The primary constraint is the max(1.0).floor() call here: https://github.com/parasyte/pixels/blob/94b87496c3715b6fcc4541c6a9370a5544569c7b/src/renderers.rs#L233-L237

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.

parasyte avatar Mar 24 '22 16:03 parasyte

@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

snylonue avatar Mar 28 '22 08:03 snylonue

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.

parasyte avatar Mar 28 '22 21:03 parasyte