| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return promise; | 124 return promise; |
| 125 } | 125 } |
| 126 | 126 |
| 127 Image* const blinkImage = imageResource->getImage(); | 127 Image* const blinkImage = imageResource->getImage(); |
| 128 if (!blinkImage) { | 128 if (!blinkImage) { |
| 129 resolver->reject(DOMException::create( | 129 resolver->reject(DOMException::create( |
| 130 InvalidStateError, "Failed to get image from resource.")); | 130 InvalidStateError, "Failed to get image from resource.")); |
| 131 return promise; | 131 return promise; |
| 132 } | 132 } |
| 133 | 133 |
| 134 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame(); | 134 // TODO(ccameron): ShapeDetector can ignore color conversion. |
| 135 const sk_sp<SkImage> image = blinkImage->imageForCurrentFrame( |
| 136 ColorBehavior::transformToGlobalTarget()); |
| 135 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width())); | 137 DCHECK_EQ(img->naturalWidth(), static_cast<unsigned>(image->width())); |
| 136 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height())); | 138 DCHECK_EQ(img->naturalHeight(), static_cast<unsigned>(image->height())); |
| 137 | 139 |
| 138 if (!image) { | 140 if (!image) { |
| 139 resolver->reject(DOMException::create( | 141 resolver->reject(DOMException::create( |
| 140 InvalidStateError, "Failed to get image from current frame.")); | 142 InvalidStateError, "Failed to get image from current frame.")); |
| 141 return promise; | 143 return promise; |
| 142 } | 144 } |
| 143 | 145 |
| 144 const SkImageInfo skiaInfo = | 146 const SkImageInfo skiaInfo = |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 resolver->resolve(HeapVector<Member<DOMRect>>()); | 219 resolver->resolve(HeapVector<Member<DOMRect>>()); |
| 218 return promise; | 220 return promise; |
| 219 } | 221 } |
| 220 | 222 |
| 221 SkPixmap pixmap; | 223 SkPixmap pixmap; |
| 222 RefPtr<Uint8Array> pixelData; | 224 RefPtr<Uint8Array> pixelData; |
| 223 uint8_t* pixelDataPtr = nullptr; | 225 uint8_t* pixelDataPtr = nullptr; |
| 224 WTF::CheckedNumeric<int> allocationSize = 0; | 226 WTF::CheckedNumeric<int> allocationSize = 0; |
| 225 // Use |skImage|'s pixels if it has direct access to them, otherwise retrieve | 227 // Use |skImage|'s pixels if it has direct access to them, otherwise retrieve |
| 226 // them from elsewhere via copyBitmapData(). | 228 // them from elsewhere via copyBitmapData(). |
| 227 sk_sp<SkImage> skImage = imageBitmap->bitmapImage()->imageForCurrentFrame(); | 229 // TODO(ccameron): ShapeDetector can ignore color conversion. |
| 230 sk_sp<SkImage> skImage = imageBitmap->bitmapImage()->imageForCurrentFrame( |
| 231 ColorBehavior::transformToGlobalTarget()); |
| 228 if (skImage->peekPixels(&pixmap)) { | 232 if (skImage->peekPixels(&pixmap)) { |
| 229 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 233 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 230 allocationSize = pixmap.getSafeSize(); | 234 allocationSize = pixmap.getSafeSize(); |
| 231 } else { | 235 } else { |
| 232 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied() | 236 pixelData = imageBitmap->copyBitmapData(imageBitmap->isPremultiplied() |
| 233 ? PremultiplyAlpha | 237 ? PremultiplyAlpha |
| 234 : DontPremultiplyAlpha, | 238 : DontPremultiplyAlpha, |
| 235 N32ColorType); | 239 N32ColorType); |
| 236 pixelDataPtr = pixelData->data(); | 240 pixelDataPtr = pixelData->data(); |
| 237 allocationSize = imageBitmap->size().area() * 4 /* bytes per pixel */; | 241 allocationSize = imageBitmap->size().area() * 4 /* bytes per pixel */; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 266 video->getSourceImageForCanvas(&sourceImageStatus, PreferNoAcceleration, | 270 video->getSourceImageForCanvas(&sourceImageStatus, PreferNoAcceleration, |
| 267 SnapshotReasonDrawImage, videoSize); | 271 SnapshotReasonDrawImage, videoSize); |
| 268 | 272 |
| 269 DCHECK_EQ(NormalSourceImageStatus, sourceImageStatus); | 273 DCHECK_EQ(NormalSourceImageStatus, sourceImageStatus); |
| 270 | 274 |
| 271 SkPixmap pixmap; | 275 SkPixmap pixmap; |
| 272 RefPtr<Uint8Array> pixelData; | 276 RefPtr<Uint8Array> pixelData; |
| 273 uint8_t* pixelDataPtr = nullptr; | 277 uint8_t* pixelDataPtr = nullptr; |
| 274 WTF::CheckedNumeric<int> allocationSize = 0; | 278 WTF::CheckedNumeric<int> allocationSize = 0; |
| 275 // Use |skImage|'s pixels if it has direct access to them. | 279 // Use |skImage|'s pixels if it has direct access to them. |
| 276 sk_sp<SkImage> skImage = image->imageForCurrentFrame(); | 280 // TODO(ccameron): ShapeDetector can ignore color conversion. |
| 281 sk_sp<SkImage> skImage = |
| 282 image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget()); |
| 277 if (skImage->peekPixels(&pixmap)) { | 283 if (skImage->peekPixels(&pixmap)) { |
| 278 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); | 284 pixelDataPtr = static_cast<uint8_t*>(pixmap.writable_addr()); |
| 279 allocationSize = pixmap.getSafeSize(); | 285 allocationSize = pixmap.getSafeSize(); |
| 280 } else { | 286 } else { |
| 281 // TODO(mcasas): retrieve the pixels from elsewhere. | 287 // TODO(mcasas): retrieve the pixels from elsewhere. |
| 282 NOTREACHED(); | 288 NOTREACHED(); |
| 283 resolver->reject(DOMException::create( | 289 resolver->reject(DOMException::create( |
| 284 InvalidStateError, "Failed to get pixels for current frame.")); | 290 InvalidStateError, "Failed to get pixels for current frame.")); |
| 285 return promise; | 291 return promise; |
| 286 } | 292 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 m_barcodeServiceRequests.clear(); | 402 m_barcodeServiceRequests.clear(); |
| 397 m_barcodeService.reset(); | 403 m_barcodeService.reset(); |
| 398 } | 404 } |
| 399 | 405 |
| 400 DEFINE_TRACE(ShapeDetector) { | 406 DEFINE_TRACE(ShapeDetector) { |
| 401 visitor->trace(m_faceServiceRequests); | 407 visitor->trace(m_faceServiceRequests); |
| 402 visitor->trace(m_barcodeServiceRequests); | 408 visitor->trace(m_barcodeServiceRequests); |
| 403 } | 409 } |
| 404 | 410 |
| 405 } // namespace blink | 411 } // namespace blink |
| OLD | NEW |