| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/shapedetection/ShapeDetector.h" | 5 #include "modules/shapedetection/ShapeDetector.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/DOMRect.h" | 8 #include "core/dom/DOMRect.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/fetch/ImageResource.h" | 10 #include "core/fetch/ImageResource.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 resolver->reject( | 102 resolver->reject( |
| 103 DOMException::create(InvalidStateError, "Invalid element or state.")); | 103 DOMException::create(InvalidStateError, "Invalid element or state.")); |
| 104 return promise; | 104 return promise; |
| 105 } | 105 } |
| 106 | 106 |
| 107 SkPixmap pixmap; | 107 SkPixmap pixmap; |
| 108 RefPtr<Uint8Array> pixelData; | 108 RefPtr<Uint8Array> pixelData; |
| 109 uint8_t* pixelDataPtr = nullptr; | 109 uint8_t* pixelDataPtr = nullptr; |
| 110 WTF::CheckedNumeric<int> allocationSize = 0; | 110 WTF::CheckedNumeric<int> allocationSize = 0; |
| 111 | 111 |
| 112 sk_sp<SkImage> skImage = image->imageForCurrentFrame(); | 112 // TODO(ccameron): ShapeDetector can ignore color conversion. |
| 113 sk_sp<SkImage> skImage = |
| 114 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
| 113 // Use |skImage|'s pixels if it has direct access to them. | 115 // Use |skImage|'s pixels if it has direct access to them. |
| 114 if (skImage->peekPixels(&pixmap)) { | 116 if (skImage->peekPixels(&pixmap)) { |
| 115 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 117 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 116 allocationSize = pixmap.getSafeSize(); | 118 allocationSize = pixmap.getSafeSize(); |
| 117 } else if (imageSource.isImageBitmap()) { | 119 } else if (imageSource.isImageBitmap()) { |
| 118 ImageBitmap* imageBitmap = imageSource.getAsImageBitmap(); | 120 ImageBitmap* imageBitmap = imageSource.getAsImageBitmap(); |
| 119 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied() | 121 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied() |
| 120 ? PremultiplyAlpha | 122 ? PremultiplyAlpha |
| 121 : DontPremultiplyAlpha, | 123 : DontPremultiplyAlpha, |
| 122 N32ColorType); | 124 N32ColorType); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 return promise; | 158 return promise; |
| 157 } | 159 } |
| 158 | 160 |
| 159 Image* const blinkImage = imageResource->getImage(); | 161 Image* const blinkImage = imageResource->getImage(); |
| 160 if (!blinkImage) { | 162 if (!blinkImage) { |
| 161 resolver->reject(DOMException::create( | 163 resolver->reject(DOMException::create( |
| 162 InvalidStateError, "Failed to get image from resource.")); | 164 InvalidStateError, "Failed to get image from resource.")); |
| 163 return promise; | 165 return promise; |
| 164 } | 166 } |
| 165 | 167 |
| 166 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame(); | 168 // TODO(ccameron): ShapeDetector can ignore color conversion. |
| 169 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame( |
| 170 ColorBehavior::transformToGlobalTarget()); |
| 167 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width())); | 171 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width())); |
| 168 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height())); | 172 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height())); |
| 169 | 173 |
| 170 if (!image) { | 174 if (!image) { |
| 171 resolver->reject(DOMException::create( | 175 resolver->reject(DOMException::create( |
| 172 InvalidStateError, "Failed to get image from current frame.")); | 176 InvalidStateError, "Failed to get image from current frame.")); |
| 173 return promise; | 177 return promise; |
| 174 } | 178 } |
| 175 | 179 |
| 176 const SkImageInfo skiaInfo = | 180 const SkImageInfo skiaInfo = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 InvalidStateError, | 204 InvalidStateError, |
| 201 "Failed to read pixels: Unable to decompress or unsupported format.")); | 205 "Failed to read pixels: Unable to decompress or unsupported format.")); |
| 202 return promise; | 206 return promise; |
| 203 } | 207 } |
| 204 | 208 |
| 205 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), | 209 return doDetect(resolver, std::move(sharedBufferHandle), img->naturalWidth(), |
| 206 img->naturalHeight()); | 210 img->naturalHeight()); |
| 207 } | 211 } |
| 208 | 212 |
| 209 } // namespace blink | 213 } // namespace blink |
| OLD | NEW |