Image downscaling

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Instant

Re: Image downscaling

Unread post by Instant » 2014-09-06, 21:17

Just wondering, isn't this sort of things what GPU excel at. Can Pale Moon use the GPU for scaling?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2014-09-06, 21:55

Instant wrote:Just wondering, isn't this sort of things what GPU excel at. Can Pale Moon use the GPU for scaling?
It does for a few things that require very fast scaling (if available), but using the GPU has a lot of overhead and in the end for image scaling you can get unpredictable results if you use the GPU. It's often more economical and faster to use the CPU in-memory than to create a texture, send it to the GPU, tell the GPU to scale, get it back from the GPU only to send it right back out to it afterwards to composite the page.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

Instant

Re: Image downscaling

Unread post by Instant » 2014-09-07, 11:34

Wow, didn't expect such a fast response. And thanks for the info.

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2015-07-24, 07:22

Apologies for the bump, but I've run into an image that's giving some nearest neighbor-like artifacts when scaled. Before I jump to any conclusions, I'd like to ask for clarification on what Pale Moon does regarding the zooming of images...


From what it sounds like, any zoom level between 33%-100% should be resized with Lanczos (presumably Lanczos3) - is this accurate?

If that's the case, would it not be accurate to say that, if I resize an image via Lanczos3 to, say, 44% in a program like XnView and then zoom the same image in Pale Moon to 44%, the image in Pale Moon and XnView should look identical, correct?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2015-07-24, 07:47

No, it's not using Lanczos3 because that would be much too slow for on-the-fly resizing. It uses Lanczos2, which uses a smaller box and to keep scaling speedily, at the trade-off of some aliasing artifacts. It's a browser, not an image viewer, so trade-offs must be made for web-embedded scaled images to keep things speedy.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2015-07-24, 07:51

Moonchild wrote:It uses Lanczos2
That's all you had to say, and is why I asked before I jumped to any conclusion - no need to say anything about it not being an image viewer and such.

So that's all then, no problem here - carry on with your day.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2015-07-24, 08:06

Nintendo Maniac 64 wrote:That's all you had to say
For you maybe, but not for the casual reader who may not know the difference between the two who stumbles across this thread ;)
Then again, I realize I just repeated myself :P So.. sorry!
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2015-07-31, 05:42

I'm not sure if I should make a new thread, but I figured it was moderately related and I had already recently bumped this thread...

What does Pale Moon do for upscaling? Does it use the same algorithm for all upscaling?

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2015-11-15, 04:44

My last question regarding upscaling never got answered, but I did just find out something interesting...


You know how some large images can give aliasing artifacts when resized to fit the screen due to the use of Lanczos2? Well it turns out that these artifacts don't happen when the image's native resolution is an exact multiple of the downscaled size. Therefore, I did a test and it turns out that if Pale Moon first upscales an image to an exact multiple of the target size and then downscales the image, the resulting quality is much better.

In other words, if the target height is 749px (which is what it is for me), you get a better result taking a 2000px high image, upscaling it to 2247px high, and then downscaling it to 749px high rather than trying to downscale from 2000px directly to 749px.


However, this completely ignores the possibility that doing an upscale followed by a downscale may in fact take more processing time than simply using a higher-quality downscaling algorithm such as Laczos3 or the like.

petrus

Re: Image downscaling

Unread post by petrus » 2017-01-04, 15:18

To not open a new thread, is there a config line which disables all interpolation to get crisp images at all sizes?
I googled around and it should be image.high_quality_downscaling, but with this disabled they are still blurry.

Unlike when you put into userContent.css: img { image-rendering: -moz-crisp-edges; } which does make them pixel perfect.

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2017-06-12, 01:42

petrus wrote:To not open a new thread, is there a config line which disables all interpolation to get crisp images at all sizes?
Kind of late on this, but you may be looking for the setting "image.high_quality_downscaling.min_factor".

Depending on what it is you're looking to achieve, you'll want to set that to either a value of "-1" or "1".

petrus

Re: Image downscaling

Unread post by petrus » 2017-06-16, 20:26

Are you sure? Doesn't seem to work, just tried both values with restarts, yet images remain interpolated.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2017-06-17, 12:54

Disabling HQ image downscaling doesn't remove interpolation, it will just switch to a much faster (lanczos2) algorithm which doesn't work well on very large scale factors.
Pixel-resizing is never used unless forced, because it is a bad scaling method for just about all web content.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

petrus

Re: Image downscaling

Unread post by petrus » 2017-06-17, 14:31

I'm a retro gamer who likes his pixels cutting edge! :)

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2017-06-17, 20:15

Moonchild wrote:Pixel-resizing is never used unless forced, because it is a bad scaling method for just about all web content.
Would it not at least make sense for ratios like 200%, 300%, etc? I mean, it's what both Apple and Microsoft do on the OS level when DPI scaling is set to such values.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2017-06-18, 00:50

No, it doesn't make sense on integer scale factors either. Microsoft and Apple might use it on UPscaling, perhaps. But that's not what we're talking about here.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2017-06-18, 00:55

Moonchild wrote:No, it doesn't make sense on integer scale factors either. Microsoft and Apple might use it on UPscaling, perhaps. But that's not what we're talking about here.
Oh, right - for downscaling it's really quite illogical even for 8bit NES game sprites.

...though technically the best way to handle such sprites if you were downscaling to something like 70% would be to do 700% nearest neighbor upscaling and then downscale *that* to the original 70% (which would really be 10% after the upsample) using your typical image downscaling algorithm, but presumably the performance hit from doing all that would presumably be too great.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2017-06-18, 01:00

Not just the performance hit, but also the required buffer to hold that 700% upscaled image.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
__NM64__
Lunatic
Lunatic
Posts: 366
Joined: 2013-10-17, 05:29
Location: Northeast Ohio

Re: Image downscaling

Unread post by __NM64__ » 2017-06-18, 01:32

Moonchild wrote:Not just the performance hit, but also the required buffer to hold that 700% upscaled image.
Would it still be a bad performance hit if it first upscaled to something like 105% and *then* downscaled it to 35%?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35640
Joined: 2011-08-28, 17:27
Location: Motala, SE

Re: Image downscaling

Unread post by Moonchild » 2017-06-18, 07:46

Nintendo Maniac 64 wrote:Would it still be a bad performance hit if it first upscaled to something like 105% and *then* downscaled it to 35%?
That's not going to help your end result. All these scaling hoops to jump through are simply not going to be efficient and look well at the same time.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite