aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/imagedata.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-10-07 02:52:06 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2018-10-07 02:52:06 +0200
commite62dbabb46b8c5b6a5fc3dc6188976cbf2039d75 (patch)
tree39f62d51bec93921aae3790d472c71eaaa5d1306 /components/script/dom/imagedata.rs
parent241dba064ded04b3b2f97b098db637ce58cf9e19 (diff)
downloadservo-e62dbabb46b8c5b6a5fc3dc6188976cbf2039d75.tar.gz
servo-e62dbabb46b8c5b6a5fc3dc6188976cbf2039d75.zip
Handle some transparent black cases in ctx.getImageData
Diffstat (limited to 'components/script/dom/imagedata.rs')
-rw-r--r--components/script/dom/imagedata.rs22
1 files changed, 2 insertions, 20 deletions
diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs
index 7e615c0e5da..f72ea49c0ff 100644
--- a/components/script/dom/imagedata.rs
+++ b/components/script/dom/imagedata.rs
@@ -13,6 +13,7 @@ use euclid::{Rect, Size2D};
use js::jsapi::{Heap, JSContext, JSObject};
use js::rust::Runtime;
use js::typedarray::{Uint8ClampedArray, CreateWith};
+use pixels;
use std::borrow::Cow;
use std::default::Default;
use std::ptr;
@@ -162,31 +163,12 @@ impl ImageData {
#[allow(unsafe_code)]
pub unsafe fn get_rect(&self, rect: Rect<u32>) -> Cow<[u8]> {
- assert!(!rect.is_empty());
- assert!(self.rect().contains_rect(&rect));
- let slice = self.as_slice();
- let area = rect.size.area() as usize;
- let first_column_start = rect.origin.x as usize * 4;
- let row_length = self.width as usize * 4;
- let first_row_start = rect.origin.y as usize * row_length;
- if rect.origin.x == 0 && rect.size.width == self.width || rect.size.height == 1 {
- let start = first_column_start + first_row_start;
- return Cow::Borrowed(&slice[start..start + area * 4]);
- }
- let mut data = Vec::with_capacity(area * 4);
- for row in slice[first_row_start..].chunks(row_length).take(rect.size.height as usize) {
- data.extend_from_slice(&row[first_column_start..][..rect.size.width as usize * 4]);
- }
- data.into()
+ pixels::get_rect(self.as_slice(), self.get_size(), rect)
}
pub fn get_size(&self) -> Size2D<u32> {
Size2D::new(self.Width(), self.Height())
}
-
- pub fn rect(&self) -> Rect<u32> {
- Rect::from_size(self.get_size())
- }
}
impl ImageDataMethods for ImageData {