Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
/enginePublic archive

Expand FilterQuality API docs#24582

Merged
fluttergithubbot merged 2 commits intoflutter:masterfromyjbanov:filter-quality-docs
Mar 10, 2021

Conversation

@yjbanov
Copy link
Contributor

Document more precisely the effects of theFilterQuality enum values with a focus on relative quality when scaling imagesup vs scaling themdown. It turns out that the algorithm used forhigh is frequentlyworse thanmedium when scaling down. Only when scaling images up do you get increase in quality as you go none => low => medium => high.

This PR depends onflutter/assets-for-api-docs#134.

Fixesflutter/flutter#76187

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel inChat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read theTree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flar
Copy link
Contributor

I feel like these clarifications are more of a report card for the implementation rather than documentation of the intention. The way they are phrased could end up cementing the expectation of the results in lieu of fixing the underlying problems.

@yjbanov
Copy link
ContributorAuthor

@flar

I feel like these clarifications are more of a report card for the implementation rather than documentation of the intention.

I think it's still better to have them than not, but...

in lieu of fixing the underlying problems.

...I agree that we should fix it eventually. Based on the cases I've seen so far, I would just removelow altogether and remap all options as follows:

ValueOld semanticActionNew semantic
nonelow qualityno changelow quality
mediumsmoothremapped to whatlow does todaymedium quality, default in framework
highwho knows?remapped to whatmedium does todayhigh quality, opt-in
lowsmoothishdeprecate itgone

Implicitly, the current algorithm used byhigh is gone too. I haven't seen any examples where it would produce a better result compared tomedium.

For advanced use-cases the Skia team tells me we can provide an explicit sampler. This way users can have a high degree of control. That would require an extension in ourdart:ui API.

It would be a breaking change, so I wouldn't rush just yet.

@flar
Copy link
Contributor

We have the following possible techniques that can be applied at a quality vs performance tradeoff:

nearest neighbor (none)
bilinear (low)
bicubic ()
mipmap (
)

The last 2 aren't mutually exclusive since you could apply nn/bilinear/bicubic even while doing mipmapping. There are also other filter algorighms, but we don't really embrace those. Also, mipmap is targeted at improving quality while reducing and just looks like bilinear (or bicubic potentially) while enlarging.

If I'd get rid of any of the names I'd probably get rid of "none" as it is just such a bad name. It implies that nothing will happen if taken out of context and it falls out of the spectrum of "low/med/hi". I might have named it "fastest" or "lowest" originally, ignoring whether 3 or 4 constants are useful for Flutter apps.

@yjbanov
Copy link
ContributorAuthor

Yeah, so a more advanced API for picking a sampling matrix and/or mipmapping can be provided separately from theFilterQuality enum.FilterQuality could be the "non-advanced" API, with simple explanations and unsurprising behavior. Currently, it requires elaborate explanations (as you can see from this PR) and surprising behavior (e.g.medium is better quality thanhigh, what?!). I think none (or low)/medium/high is good enough for the simple case. The sampling algorithm behind today'shigh does not qualify as "simple" and should be moved to the advanced API (which I wouldn't rush to add until users ask for it).

@flar
Copy link
Contributor

flar commentedFeb 24, 2021
edited
Loading

To that end, Skia is moving to SkSamplingOptions, of which SkFilterQuality is just a legacy value with which to construct the sampling options.

https://api.skia.org/SkSamplingOptions_8h.html

Cubic is its own sampling method which does not appear to use mipmaps.
Within a texture you can have nearest neighbor or bilinear blending
On top of that you can separately control mipmap level selection to any of None, Nearest, or Linear

The SkFilterQuality options now map to:

  • none - Nearest/None
  • low - Linear/None
  • medium - Linear/Linear
  • high - Cubic (does not mipmap)

which is essentially as it was before

///
/// Example:
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/filter_quality.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should offer some alternative text that can take the place of (be an alternative to) the image for when people don't have images enabled. (Or, alternatively, rephrase the text to not refer to the example, such that it reads naturally with or without the image.) Seehttps://html.spec.whatwg.org/multipage/images.html#alt

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I followed the other examples in our code and rephrased the text to not refer to the example.

Hixie reacted with thumbs up emoji
@yjbanov
Copy link
ContributorAuthor

I turned the discussion about actually changing the API into a separate feature request:flutter/flutter#76737

@yjbanovyjbanov requested a review fromHixieFebruary 24, 2021 23:41
@chinmaygarde
Copy link
Member

Ping@Hixie for followup.

@flar
Copy link
Contributor

flar commentedMar 5, 2021

See also#24797

Copy link
Contributor

@HixieHixie left a comment

Choose a reason for hiding this comment

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

I guess LGTM since accurate documentation is better than inaccurate documentation, but I agree that it seems the real fix here is fixing the implementation.

Can't we just make the implementation of "high" act like "medium" when shrinking, if that's really better?

@yjbanov
Copy link
ContributorAuthor

Can't we just make the implementation of "high" act like "medium" when shrinking, if that's really better?

This may be doable in Skia, but it's probably quite difficult to do on the Flutter side (engine or framework). The issue is that we don't have a way to tell if we're shrinking the image or magnifying it. It depends on the aggregate transform matrix that includes all layers as well as transforms inside the picture. Pictures are opaque andas of today backed bySkPicture directly. There's no way for us to intercept the rendering process and switch the sampling algorithm. I'm guessing Skia can probably do this, or perhaps provide an API for us to customize image rendering. If we go the custom recording format route we may not need anything extra from Skia (Android and Chrome went this route). However, if we want to keep the direct link toSkPicture we need more features from Skia.

@yjbanovyjbanov added the waiting for tree to go greenThis PR is approved and tested, but waiting for the tree to be green to land. labelMar 10, 2021
@flar
Copy link
Contributor

OpenGL and Metal have concepts of min and mag filters, but I don't see them exposed in Skia unless I'm missing something.

@Hixie
Copy link
Contributor

I meant in Skia, yes.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

1 more reviewer

@HixieHixieHixie approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

cla: yeswaiting for tree to go greenThis PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Web]: Difference in asset rendering using canvasKit and html on Windows

6 participants

@yjbanov@flar@chinmaygarde@Hixie@googlebot@fluttergithubbot

[8]ページ先頭

©2009-2025 Movatter.jp