-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
core: Fix wrong blend_over()
- but with failing tests.
#11038
core: Fix wrong blend_over()
- but with failing tests.
#11038
Conversation
CC @n0samu @adrian17 . (Also informing @Dinnerbone ). |
Can you please split this into "refactor" + "change" commits? It's hard to tell what changed when you refactor at the same time What exactly is the issue you fixed? Were there values that the blend was wrong for? If so can you add those to the test? It's likely if some values were right and some wrong, and now a different set is right and wrong, then the method used to calculate the values is wrong. Floating point math may be more correct, or something akin to the unpremultiply LUT, but we have to check with tests. |
As far as I can tell, the previous function implementation is obviously wrong, since it can result in values that are considerably larger than 255 despite being casted to source.red() + ((self.red() as u16 * (255 - sa as u16)) >> 8) as u8; If What I did is what in my experience is usually done with blending, namely where you take some proportion of one color, and take |
Yep, good catch! I'd still like to amend the test with new values, to prove this and guard against regressions. We do all blending in premultiplied alpha, so the formula in normalized 0..1 values would be |
I do not feel that it was a good catch, since it seems like an obvious error, that either should have been caught in review or with unit testing. But, it was early in Ruffle's development, and you cannot expect to unit test or carefully code review everything when the code is presumably changing a lot - development-wise, it is less likely to be cost-efficient (though it of course depends on the kind of technology and quality level you are seeking and the goals - at places like NASA, there are of course other priorities). The code currently fails, and I do not understand why. But, while the new fix visually works with the two SWFs I tested, I have not tested them specifically, so you are right that the new implementation, while not being obviously wrong, may not be accurate to the behavior of the Flash Player, and I agree (if I understand you correctly) that I do not quite understand what you mean by premultiplied alpha, but I think I will have to ponder it a bit before I get it. |
Attaching the test result output when running with
|
I do not understand this part. It would explain some cases where |
Like, in this code piece, it is clear that ruffle/core/src/bitmap/operations.rs Lines 1329 to 1333 in 476ff4a
But in this code piece below, I am not certain whether ruffle/core/src/bitmap/operations.rs Lines 1342 to 1355 in 476ff4a
As well as here: ruffle/core/src/bitmap/operations.rs Lines 1235 to 1245 in 476ff4a
ruffle/core/src/bitmap/operations.rs Lines 1286 to 1298 in 476ff4a
But I am not certain about those places, I have not looked into them carefully. But; does this mean that the real fix is not this PR, but to carefully ensure that wherever |
@Dinnerbone I think that I will make a new PR, and in that PR, I will not touch the implementation of In either case, thank you very much for the help and guidance. |
Superseded by #11044 . |
This change seemingly fixes the new bug related to the SWF in #10954 (the issue in #10954 describes a previous, already fixed bug, the new bug has not been described in any issue, but described and investigated on Discord). This new bug came to surface with the latest nightly (2023-05-13), for the SWF in #10954 , where the bug causes flashing with crazy colors once the game is started from the game's main menu (the bug was expressed and came to surface, but not introduced as far as I can tell, with the changes in #11006 ). This PR is not regressing neither the panic bug nor the visual issue for #10955 and #11007 .
Superseded by: #11044 .
The apparent cause of the bug is #2488 , made some two years ago. Ruffle was much less mature back then (the code likely changed much more and unit tests were likely less cost-efficient overall development-wise), and it in my opinion makes sense that there were fewer unit tests back then for new code.I believe that the primary cause of the bug was a lack of unit tests, which is understandable given that Ruffle was much newer back then. I suspect that a secondary cause of the bug was all the type-casts, which made the code more obscure and difficult to comprehend. I have made the code clearer, at the cost of making it more verbose, which I think is justified in this case.For some reason, two tests are failing, so all the automatically run tests will presumably fail. I do not understand or know why they fail, I will need help from you to figure that out.There are twoTODO
s in the code, which I would like to request reviewers to also consider.Finally, I feel that it would be prudent for me to write some unit tests forblend_over()
. Or at least create an issue, since it would be nice if this PR was figured out before the next nightly release. Though this fix is not that urgent, I believe, and it might be better to wait for the next nightly instead of hurrying.