Implement BitmapData.scroll() #2190
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes the right-scrolling background particles of z0r.de/7463 work, fixing 1/3 of #2073.
I've tested this code manually with a couple different parametrizations, the visual results always exactly matched that of Adobe Flash Player.
I'm not sure if any of this is supposed to be added as some actual test cases, and if so, exactly how - I personally used
mtasc
to build the.swf
s.Performance-wise I tried to avoid any redundant range checks (hence the
unwrap
), and conversions to/from premultiplied alpha format.(There might be faster ways to do this, especially if there is something of a
memcpy
-like intrinsic onVec
s of simple types, with selectable operation order, but I'm not aware of anything like that (yet), nor do I think it is that critical. [Perhaps the compiler recognizes some data access patterns even, and optimizes the pixel-wise iteration into something more batched, but I haven't checked the generated code.])Since I'm not that experienced with Rust, I struggled a bit with conditionally reversing the coordinate ranges (and reusing the one for the
x
dimension, within they
loop), that's why there is some clumsy setup with theIterator
trait object bindings in there. If there is a simpler way to do this, I'd be happy to hear about it.BTW, @CUB3D, may I ask, what was the reason for putting
32
in the name of some of the pixel-manipulating functions on BitmapData? To me, it seems that the 'exact pair' (with the most direct access to thepixels
field) ofget_pixel_raw
isset_pixel32_raw
, and I found this inconsistency slightly strange.