Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp

Issue 2550413005: ShapeDetection: use ImageBitmapSource as input and support ImageData (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
diff --git a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
index a574933828cdd82b3196d42c231462206a67bff0..ed761c3ca159a16bdc4967929a9ba50eb575bad6 100644
--- a/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
+++ b/third_party/WebKit/Source/modules/shapedetection/ShapeDetector.cpp
@@ -11,7 +11,7 @@
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLVideoElement.h"
-#include "core/html/canvas/CanvasImageSource.h"
+#include "core/html/ImageData.h"
#include "core/loader/resource/ImageResourceContent.h"
#include "platform/graphics/Image.h"
#include "third_party/skia/include/core/SkImage.h"
@@ -53,10 +53,13 @@ ShapeDetector::ShapeDetector(LocalFrame& frame) {
}
ScriptPromise ShapeDetector::detect(ScriptState* scriptState,
- const CanvasImageSourceUnion& imageSource) {
+ const ImageBitmapSourceUnion& imageSource) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
+ if (imageSource.isImageData())
+ return detectShapesOnImageData(resolver, imageSource.getAsImageData());
+
CanvasImageSource* canvasImageSource;
if (imageSource.isHTMLImageElement()) {
canvasImageSource = imageSource.getAsHTMLImageElement();
@@ -141,6 +144,23 @@ ScriptPromise ShapeDetector::detect(ScriptState* scriptState,
image->height());
}
+ScriptPromise ShapeDetector::detectShapesOnImageData(
+ ScriptPromiseResolver* resolver,
+ ImageData* imageData) {
+ ScriptPromise promise = resolver->promise();
xianglu 2016/12/14 22:32:28 Should we check origin for ImageData as well?
mcasas 2016/12/14 23:37:42 [1] tells us that ImageDatas can not be created fr
+
+ uint8_t* const data = imageData->data()->data();
+ WTF::CheckedNumeric<int> allocationSize = imageData->size().area() * 4;
+
+ mojo::ScopedSharedBufferHandle sharedBufferHandle =
+ getSharedBufferOnData(resolver, data, allocationSize.ValueOrDefault(0));
+ if (!sharedBufferHandle->is_valid())
+ return promise;
+
+ return doDetect(resolver, std::move(sharedBufferHandle), imageData->width(),
+ imageData->height());
+}
+
ScriptPromise ShapeDetector::detectShapesOnImageElement(
ScriptPromiseResolver* resolver,
const HTMLImageElement* img) {
« no previous file with comments | « third_party/WebKit/Source/modules/shapedetection/ShapeDetector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698