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

Side by Side Diff: third_party/WebKit/Source/core/frame/ImageBitmap.cpp

Issue 2192103002: Implement resize option for createImageBitmap(HTMLVideoElement) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make ratio local var Created 4 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "core/frame/ImageBitmap.h" 5 #include "core/frame/ImageBitmap.h"
6 6
7 #include "core/html/HTMLCanvasElement.h" 7 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 8 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 9 #include "core/html/ImageData.h"
10 #include "platform/graphics/skia/SkiaUtils.h" 10 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 301 }
302 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ())); 302 m_image->setOriginClean(!image->wouldTaintOrigin(document->getSecurityOrigin ()));
303 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); 303 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
304 } 304 }
305 305
306 ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do cument* document, const ImageBitmapOptions& options) 306 ImageBitmap::ImageBitmap(HTMLVideoElement* video, Optional<IntRect> cropRect, Do cument* document, const ImageBitmapOptions& options)
307 { 307 {
308 IntSize playerSize; 308 IntSize playerSize;
309 if (video->webMediaPlayer()) 309 if (video->webMediaPlayer())
310 playerSize = video->webMediaPlayer()->naturalSize(); 310 playerSize = video->webMediaPlayer()->naturalSize();
311
312 // TODO(xidachen); implement the resize option.
313 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS ourceSize()); 311 ParsedOptions parsedOptions = parseOptions(options, cropRect, video->bitmapS ourceSize());
314 312
315 IntRect videoRect = IntRect(IntPoint(), playerSize); 313 IntRect videoRect = IntRect(IntPoint(), playerSize);
316 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect); 314 IntRect srcRect = intersection(parsedOptions.cropRect, videoRect);
317 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(parsedOptions.crop Rect.size(), NonOpaque, DoNotInitializeImagePixels); 315 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create(IntSize(parsedOpti ons.resizeWidth, parsedOptions.resizeHeight), NonOpaque, DoNotInitializeImagePix els);
318 if (!buffer) 316 if (!buffer)
319 return; 317 return;
320 318
321 if (parsedOptions.flipY) { 319 if (parsedOptions.flipY) {
322 buffer->canvas()->translate(0, buffer->size().height()); 320 buffer->canvas()->translate(0, buffer->size().height());
323 buffer->canvas()->scale(1, -1); 321 buffer->canvas()->scale(1, -1);
324 } 322 }
325 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std:: max(0, -parsedOptions.cropRect.y())); 323 IntPoint dstPoint = IntPoint(std::max(0, -parsedOptions.cropRect.x()), std:: max(0, -parsedOptions.cropRect.y()));
326 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, srcRect.size()) , nullptr); 324 IntSize dstSize = srcRect.size();
325 SkPaint paint;
326 if (parsedOptions.shouldScaleInput) {
327 float scaleRatioX = static_cast<float>(parsedOptions.resizeWidth) / pars edOptions.cropRect.width();
328 float scaleRatioY = static_cast<float>(parsedOptions.resizeHeight) / par sedOptions.cropRect.height();
329 dstPoint.scale(scaleRatioX, scaleRatioY);
330 paint.setFilterQuality(parsedOptions.resizeQuality);
331 dstSize.scale(scaleRatioX, scaleRatioY);
332 }
333 video->paintCurrentFrame(buffer->canvas(), IntRect(dstPoint, dstSize), parse dOptions.shouldScaleInput ? &paint : nullptr);
327 334
328 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown); 335 RefPtr<SkImage> skiaImage = buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown);
329 if (!parsedOptions.premultiplyAlpha) 336 if (!parsedOptions.premultiplyAlpha)
330 skiaImage = premulSkImageToUnPremul(skiaImage.get()); 337 skiaImage = premulSkImageToUnPremul(skiaImage.get());
331 m_image = StaticBitmapImage::create(skiaImage.release()); 338 m_image = StaticBitmapImage::create(skiaImage.release());
332 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ())); 339 m_image->setOriginClean(!video->wouldTaintOrigin(document->getSecurityOrigin ()));
333 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); 340 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
334 } 341 }
335 342
336 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect, const ImageBitmapOptions& options) 343 ImageBitmap::ImageBitmap(HTMLCanvasElement* canvas, Optional<IntRect> cropRect, const ImageBitmapOptions& options)
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 FloatSize ImageBitmap::elementSize(const FloatSize&) const 648 FloatSize ImageBitmap::elementSize(const FloatSize&) const
642 { 649 {
643 return FloatSize(width(), height()); 650 return FloatSize(width(), height());
644 } 651 }
645 652
646 DEFINE_TRACE(ImageBitmap) 653 DEFINE_TRACE(ImageBitmap)
647 { 654 {
648 } 655 }
649 656
650 } // namespace blink 657 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-createImageBitmap-video-resize.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698