Skip to content

Change default upscaling to bilinear interpolation #147

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

tristanphease
Copy link
Contributor

Fixes #142
Changes the default upscaling to instead of just taking the closest u/v chroma value average them out depending on their distance from the pixel, the same way that libwebp does it
Here's the bsk image from the issue decoded with this change
image_output

Still need to work out whether we want the non fancy upscaling as a configuration option in the API (currently have it unused) and also the tests currently fail since the difference between the references and the output is now more than 10%

}
}

fn get_fancy_chroma_value(main: u8, secondary1: u8, secondary2: u8, tertiary: u8) -> u8 {
Copy link

@awxkee awxkee Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to mark all tiny methods as #[inline] in hot points. They may already be inlined, but it's better to explicitly indicate that inlining is desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated some of the small functions with that

@tristanphease
Copy link
Contributor Author

Updated to incorporate some of the buffer changes from the other PR and also updated all the lossy reference images to be decoded with the default dwebp decoding settings and looks like it matches.

Remaining question I have is do we want to incorporate the non-fancy option in the public API for this crate so it's usable? We currently don't have any decoding parameters in decode_frame().

Copy link

@awxkee awxkee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion looks good to me. However, for questions or formal approval, it might be better to ping one of the maintainers.

src/yuv.rs Outdated
}

let remainder = rgb_chunks.into_remainder();
if remainder.len() >= 4 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this method could be called with different BPP values. Is it correct that the indexing in this method is fixed to RGBA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was just a temporary thing leaving the function there for use later. Have changed now to work for both RGB and RGBA

@fintelia
Copy link
Contributor

I'm in favor of switching the default to bilinear interpolation and adding a method WebPDecoder to switch back to the current approach.

Please do update tests/CREDITS.md with the precise command to produce the reference images.

Returns the old tests with the nofancy set for gallery1
@tristanphease tristanphease marked this pull request as ready for review July 30, 2025 09:35
@tristanphease
Copy link
Contributor Author

Okay thanks, have added some options to the decoder so that the user can choose which method to use. Have updated tests/CREDITS.md as well

Copy link
Contributor

@fintelia fintelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just a few minor comments

src/decoder.rs Outdated
/// Sets the upsampling method used in conversion from lossy yuv to rgb
///
/// Defaults to `Bilinear`.
pub fn set_lossy_upsampling(&mut self, lossy_upsampling: UpsamplingMethod) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be preferable to make lossy_upsampling public and not need this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

YUV->RGB conversion matches dwebp -nofancy which is not the default libwebp configuration
3 participants