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

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

Issue 1696753002: Change createImageBitmap(Blob) to use ImageDecoder instead of ImageSource (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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
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/image-decoders/ImageDecoder.h" 10 #include "platform/image-decoders/ImageDecoder.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return newSkImageFromRaster(info, imagePixels.release(), imageRowBytes); 82 return newSkImageFromRaster(info, imagePixels.release(), imageRowBytes);
83 } 83 }
84 84
85 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input) 85 static PassRefPtr<SkImage> premulSkImageToUnPremul(SkImage* input)
86 { 86 {
87 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S kColorType, kUnpremul_SkAlphaType); 87 SkImageInfo info = SkImageInfo::Make(input->width(), input->height(), kN32_S kColorType, kUnpremul_SkAlphaType);
88 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info); 88 OwnPtr<uint8_t[]> dstPixels = copySkImageData(input, info);
89 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info .bytesPerPixel()); 89 return newSkImageFromRaster(info, dstPixels.release(), input->width() * info .bytesPerPixel());
90 } 90 }
91 91
92 PassRefPtr<SkImage> ImageBitmap::getSkImageFromDecoder(PassOwnPtr<ImageDecoder> decoder)
93 {
94 if (!decoder->frameCount())
95 return nullptr;
96 ImageFrame* frame = decoder->frameBufferAtIndex(0);
97 if (!frame || frame->status() != ImageFrame::FrameComplete)
98 return nullptr;
99 SkBitmap bitmap = frame->bitmap();
100 if (!frameIsValid(bitmap))
101 return nullptr;
102 return adoptRef(SkImage::NewFromBitmap(bitmap));
103 }
104
92 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, bool isBitmapPremultiplied = true) 105 static PassRefPtr<StaticBitmapImage> cropImage(Image* image, const IntRect& crop Rect, bool flipY, bool premultiplyAlpha, bool isBitmapPremultiplied = true)
93 { 106 {
94 ASSERT(image); 107 ASSERT(image);
95 108
96 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height())); 109 IntRect imgRect(IntPoint(), IntSize(image->width(), image->height()));
97 const IntRect srcRect = intersection(imgRect, cropRect); 110 const IntRect srcRect = intersection(imgRect, cropRect);
98 111
99 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image 112 // In the case when cropRect doesn't intersect the source image and it requi res a umpremul image
100 // We immediately return a transparent black image with cropRect.size() 113 // We immediately return a transparent black image with cropRect.size()
101 if (srcRect.isEmpty() && !premultiplyAlpha) { 114 if (srcRect.isEmpty() && !premultiplyAlpha) {
102 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType); 115 SkImageInfo info = SkImageInfo::Make(cropRect.width(), cropRect.height() , kN32_SkColorType, kUnpremul_SkAlphaType);
103 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[cropRect.width() * cropRect.height() * info.bytesPerPixel()]()); 116 OwnPtr<uint8_t[]> dstPixels = adoptArrayPtr(new uint8_t[cropRect.width() * cropRect.height() * info.bytesPerPixel()]());
104 return StaticBitmapImage::create(newSkImageFromRaster(info, dstPixels.re lease(), cropRect.width() * info.bytesPerPixel())); 117 return StaticBitmapImage::create(newSkImageFromRaster(info, dstPixels.re lease(), cropRect.width() * info.bytesPerPixel()));
105 } 118 }
106 119
107 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame(); 120 RefPtr<SkImage> skiaImage = image->imageForCurrentFrame();
108 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied. 121 // Attempt to get raw unpremultiplied image data, executed only when skiaIma ge is premultiplied.
109 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && isBitmapPremultiplied) { 122 if (((!premultiplyAlpha && !skiaImage->isOpaque()) || !skiaImage) && image-> data() && isBitmapPremultiplied) {
110 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion 123 // TODO(xidachen): GammaAndColorProfileApplied needs to be changed when working on color-space conversion
111 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( 124 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(
112 *(image->data()), ImageDecoder::AlphaNotPremultiplied, 125 *(image->data()), ImageDecoder::AlphaNotPremultiplied,
113 ImageDecoder::GammaAndColorProfileApplied)); 126 ImageDecoder::GammaAndColorProfileApplied));
114 if (!decoder) 127 if (!decoder)
115 return nullptr; 128 return nullptr;
116 decoder->setData(image->data(), true); 129 decoder->setData(image->data(), true);
117 if (!decoder->frameCount()) 130 skiaImage = ImageBitmap::getSkImageFromDecoder(decoder.release());
131 if (!skiaImage)
118 return nullptr; 132 return nullptr;
119 ImageFrame* frame = decoder->frameBufferAtIndex(0);
120 if (!frame || frame->status() != ImageFrame::FrameComplete)
121 return nullptr;
122 SkBitmap bitmap = frame->bitmap();
123 if (!frameIsValid(bitmap))
124 return nullptr;
125 skiaImage = adoptRef(SkImage::NewFromBitmap(bitmap));
126 } 133 }
127 134
128 if (cropRect == srcRect) { 135 if (cropRect == srcRect) {
129 if (flipY) 136 if (flipY)
130 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne wSubset(srcRect))); 137 return StaticBitmapImage::create(flipSkImageVertically(skiaImage->ne wSubset(srcRect)));
131 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect)) ); 138 return StaticBitmapImage::create(adoptRef(skiaImage->newSubset(srcRect)) );
132 } 139 }
133 140
134 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect. width(), cropRect.height())); 141 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(cropRect. width(), cropRect.height()));
135 if (!surface) 142 if (!surface)
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 FloatSize ImageBitmap::elementSize() const 446 FloatSize ImageBitmap::elementSize() const
440 { 447 {
441 return FloatSize(width(), height()); 448 return FloatSize(width(), height());
442 } 449 }
443 450
444 DEFINE_TRACE(ImageBitmap) 451 DEFINE_TRACE(ImageBitmap)
445 { 452 {
446 } 453 }
447 454
448 } // namespace blink 455 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/ImageBitmap.h ('k') | third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698