aboutsummaryrefslogtreecommitdiffstats
path: root/components/canvas_traits/lib.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-08-29 22:59:28 -0500
committerGitHub <noreply@github.com>2016-08-29 22:59:28 -0500
commit3a715e5c55962fe88fcb53b4b79d0afe7a5f9003 (patch)
treec49aaa7b4299310ce05096f91e35ef724b65865c /components/canvas_traits/lib.rs
parentc55588d25b6e0390d11b2cb654ccb1f95e16cebb (diff)
parent119716acb230268cefca1319531203efdf0a5579 (diff)
downloadservo-3a715e5c55962fe88fcb53b4b79d0afe7a5f9003.tar.gz
servo-3a715e5c55962fe88fcb53b4b79d0afe7a5f9003.zip
Auto merge of #13114 - glennw:webrender-canvas, r=emilio
Fix canvas image tests when using webrender. When webrender is enabled, image decoding doesn't pre-multiply by alpha, but the canvas code expects the image data to be pre-multiplied form. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13114) <!-- Reviewable:end -->
Diffstat (limited to 'components/canvas_traits/lib.rs')
-rw-r--r--components/canvas_traits/lib.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/components/canvas_traits/lib.rs b/components/canvas_traits/lib.rs
index db945750a0c..d148baf0550 100644
--- a/components/canvas_traits/lib.rs
+++ b/components/canvas_traits/lib.rs
@@ -552,3 +552,21 @@ pub fn byte_swap(data: &mut [u8]) {
i += 4;
}
}
+
+pub fn byte_swap_and_premultiply(data: &mut [u8]) {
+ let length = data.len();
+
+ let mut i = 0;
+ while i < length {
+ let r = data[i + 2];
+ let g = data[i + 1];
+ let b = data[i + 0];
+ let a = data[i + 3];
+
+ data[i + 0] = ((r as u32) * (a as u32) / 255) as u8;
+ data[i + 1] = ((g as u32) * (a as u32) / 255) as u8;
+ data[i + 2] = ((b as u32) * (a as u32) / 255) as u8;
+
+ i += 4;
+ }
+}