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

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

Issue 2630563003: Fix ImageBitmap constructor from ImageData to consider the color space tags (Closed)
Patch Set: Rebaseline Created 3 years, 11 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 | « no previous file | third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp » ('j') | 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/Float32ImageData.h" 7 #include "core/html/Float32ImageData.h"
8 #include "core/html/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/html/ImageData.h" 10 #include "core/html/ImageData.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 DCHECK(options.imageOrientation() == imageBitmapOptionNone); 63 DCHECK(options.imageOrientation() == imageBitmapOptionNone);
64 } 64 }
65 if (options.premultiplyAlpha() == imageBitmapOptionNone) { 65 if (options.premultiplyAlpha() == imageBitmapOptionNone) {
66 parsedOptions.premultiplyAlpha = false; 66 parsedOptions.premultiplyAlpha = false;
67 } else { 67 } else {
68 parsedOptions.premultiplyAlpha = true; 68 parsedOptions.premultiplyAlpha = true;
69 DCHECK(options.premultiplyAlpha() == "default" || 69 DCHECK(options.premultiplyAlpha() == "default" ||
70 options.premultiplyAlpha() == "premultiply"); 70 options.premultiplyAlpha() == "premultiply");
71 } 71 }
72 72
73 if (options.colorSpaceConversion() != "none") { 73 if (options.colorSpaceConversion() != imageBitmapOptionNone) {
Justin Novosad 2017/01/17 20:00:09 Please file a crbug to get rid of all the string l
zakerinasab1 2017/01/18 18:34:21 Done. crbug.com/682321
74 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || 74 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() ||
75 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { 75 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) {
76 DCHECK_EQ(options.colorSpaceConversion(), "default"); 76 DCHECK_EQ(options.colorSpaceConversion(), "default");
77 if (RuntimeEnabledFeatures::colorCorrectRenderingDefaultModeEnabled()) { 77 if (RuntimeEnabledFeatures::colorCorrectRenderingDefaultModeEnabled()) {
78 parsedOptions.dstColorSpace = ColorBehavior::globalTargetColorSpace(); 78 parsedOptions.dstColorSpace = ColorBehavior::globalTargetColorSpace();
79 parsedOptions.dstColorType = SkColorType::kN32_SkColorType; 79 parsedOptions.dstColorType = SkColorType::kN32_SkColorType;
80 } 80 }
81 } else { 81 } else {
82 if (options.colorSpaceConversion() == "default" || 82 if (options.colorSpaceConversion() == "default" ||
83 options.colorSpaceConversion() == "srgb") { 83 options.colorSpaceConversion() == "srgb") {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 305 }
306 306
307 static inline void updateLatestColorInformation(ParsedOptions& options) { 307 static inline void updateLatestColorInformation(ParsedOptions& options) {
308 options.latestColorType = options.dstColorType; 308 options.latestColorType = options.dstColorType;
309 options.latestColorSpace = options.dstColorSpace; 309 options.latestColorSpace = options.dstColorSpace;
310 } 310 }
311 311
312 // TODO (zakrinasab). Rewrite this when SkImage::readPixels() respectes the 312 // TODO (zakrinasab). Rewrite this when SkImage::readPixels() respectes the
313 // color space of the passed SkImageInfo (crbug.com/skia/6021) and SkImage 313 // color space of the passed SkImageInfo (crbug.com/skia/6021) and SkImage
314 // exposes SkColorSpace and SkColorType (crbug.com/skia/6022). 314 // exposes SkColorSpace and SkColorType (crbug.com/skia/6022).
315
316 static void applyColorSpaceConversion(sk_sp<SkImage>& image, 315 static void applyColorSpaceConversion(sk_sp<SkImage>& image,
317 ParsedOptions& options) { 316 ParsedOptions& options) {
318 if (!options.dstColorSpace) 317 if (!options.dstColorSpace)
319 return; 318 return;
320 if (SkColorSpace::Equals(options.latestColorSpace.get(), 319 if (SkColorSpace::Equals(options.latestColorSpace.get(),
321 options.dstColorSpace.get())) 320 options.dstColorSpace.get()))
322 return; 321 return;
323 322
324 // If we have the color space information of the source image, we can use 323 // If we have the color space information of the source image, we can use
325 // SkColorSpaceXform. Otherwise, we need to draw the image on a canvas and 324 // SkColorSpaceXform. Otherwise, we need to draw the image on a canvas and
326 // take a snapshot. 325 // take a snapshot.
327 if (options.latestColorSpace) { 326 if (options.latestColorSpace) {
328 SkImageInfo info = SkImageInfo::Make( 327 SkImageInfo info = SkImageInfo::Make(
329 image->width(), image->height(), options.latestColorType, 328 image->width(), image->height(), options.latestColorType,
330 image->alphaType(), options.latestColorSpace); 329 image->alphaType(), options.latestColorSpace);
331 size_t size = image->width() * image->height() * info.bytesPerPixel(); 330 size_t size = image->width() * image->height() * info.bytesPerPixel();
332 std::unique_ptr<uint8_t[]> srcPixels(new uint8_t[size]()); 331 sk_sp<SkData> srcData = SkData::MakeUninitialized(size);
Justin Novosad 2017/01/17 20:00:09 When out of memory, does this crash or return a nu
zakerinasab1 2017/01/18 18:34:21 When out of memory, it calls SK_ABORT("sk_throw")
333 if (!image->readPixels(info, &srcPixels, 332 if (!image->readPixels(info, srcData->writable_data(),
334 image->width() * info.bytesPerPixel(), 0, 0)) { 333 image->width() * info.bytesPerPixel(), 0, 0)) {
335 return; 334 return;
336 } 335 }
337 336 // Proceed with in-place color correction, if possible.
338 // For in-place color correction, bytes per pixel must be equal for source 337 sk_sp<SkData> dstData = srcData;
339 // and destination color spaces.
340 std::unique_ptr<uint8_t[]> dstPixels = nullptr;
341 if (SkColorTypeBytesPerPixel(options.dstColorType) != 338 if (SkColorTypeBytesPerPixel(options.dstColorType) !=
342 SkColorTypeBytesPerPixel(options.latestColorType)) { 339 SkColorTypeBytesPerPixel(options.latestColorType)) {
343 size = image->width() * image->height() * 340 size = image->width() * image->height() *
344 SkColorTypeBytesPerPixel(options.latestColorType); 341 SkColorTypeBytesPerPixel(options.dstColorType);
345 dstPixels = std::unique_ptr<uint8_t[]>(new uint8_t[size]()); 342 dstData = SkData::MakeUninitialized(size);
346 } 343 }
347
348 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(
349 options.latestColorSpace.get(), options.dstColorSpace.get());
350 xform->apply(getXformFormat(options.dstColorType),
351 dstPixels ? &dstPixels : &srcPixels,
352 getXformFormat(options.latestColorType), &srcPixels,
353 image->width() * image->height(), kUnpremul_SkAlphaType);
354
355 SkImageInfo dstInfo = 344 SkImageInfo dstInfo =
356 SkImageInfo::Make(image->width(), image->height(), options.dstColorType, 345 SkImageInfo::Make(image->width(), image->height(), options.dstColorType,
357 image->alphaType(), options.dstColorSpace); 346 image->alphaType(), options.dstColorSpace);
358 sk_sp<SkData> data(SkData::MakeWithoutCopy(&dstPixels, size)); 347 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(
348 options.latestColorSpace.get(), options.dstColorSpace.get());
349 xform->apply(getXformFormat(options.dstColorType), dstData->writable_data(),
350 getXformFormat(options.latestColorType), srcData->data(),
351 image->width() * image->height(), kUnpremul_SkAlphaType);
359 sk_sp<SkImage> coloredImage = SkImage::MakeRasterData( 352 sk_sp<SkImage> coloredImage = SkImage::MakeRasterData(
360 dstInfo, data, image->width() * dstInfo.bytesPerPixel()); 353 dstInfo, dstData, image->width() * dstInfo.bytesPerPixel());
Justin Novosad 2017/01/17 20:00:09 There is a potential security vulnerability here.
zakerinasab1 2017/01/18 18:34:21 Done.
361 if (coloredImage) { 354 if (coloredImage) {
362 updateLatestColorInformation(options); 355 updateLatestColorInformation(options);
363 image = coloredImage; 356 image = coloredImage;
364 return; 357 return;
365 } 358 }
366 return; 359 return;
367 } 360 }
368 361
369 // Skia does not support drawing to unpremul surfaces/canvases. 362 // Skia does not support drawing to unpremul surfaces/canvases.
370 sk_sp<SkImage> unPremulImage = nullptr; 363 sk_sp<SkImage> unPremulImage = nullptr;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 ImageBitmap::ImageBitmap(HTMLImageElement* image, 545 ImageBitmap::ImageBitmap(HTMLImageElement* image,
553 Optional<IntRect> cropRect, 546 Optional<IntRect> cropRect,
554 Document* document, 547 Document* document,
555 const ImageBitmapOptions& options) { 548 const ImageBitmapOptions& options) {
556 RefPtr<Image> input = image->cachedImage()->getImage(); 549 RefPtr<Image> input = image->cachedImage()->getImage();
557 ParsedOptions parsedOptions = 550 ParsedOptions parsedOptions =
558 parseOptions(options, cropRect, image->bitmapSourceSize()); 551 parseOptions(options, cropRect, image->bitmapSourceSize());
559 if (dstBufferSizeHasOverflow(parsedOptions)) 552 if (dstBufferSizeHasOverflow(parsedOptions))
560 return; 553 return;
561 554
562 if (options.colorSpaceConversion() == "none") { 555 if (options.colorSpaceConversion() == imageBitmapOptionNone) {
563 m_image = cropImageAndApplyColorSpaceConversion( 556 m_image = cropImageAndApplyColorSpaceConversion(
564 input.get(), parsedOptions, PremultiplyAlpha, ColorBehavior::ignore()); 557 input.get(), parsedOptions, PremultiplyAlpha, ColorBehavior::ignore());
565 } else { 558 } else {
566 m_image = cropImageAndApplyColorSpaceConversion( 559 m_image = cropImageAndApplyColorSpaceConversion(
567 input.get(), parsedOptions, PremultiplyAlpha, 560 input.get(), parsedOptions, PremultiplyAlpha,
568 ColorBehavior::transformToGlobalTarget()); 561 ColorBehavior::transformToGlobalTarget());
569 } 562 }
570 563
571 if (!m_image) 564 if (!m_image)
572 return; 565 return;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap)); 724 m_image = StaticBitmapImage::create(SkImage::MakeRasterCopy(pixmap));
732 if (!m_image) 725 if (!m_image)
733 return; 726 return;
734 m_image->setPremultiplied(isImageBitmapPremultiplied); 727 m_image->setPremultiplied(isImageBitmapPremultiplied);
735 m_image->setOriginClean(isImageBitmapOriginClean); 728 m_image->setOriginClean(isImageBitmapOriginClean);
736 } 729 }
737 730
738 static sk_sp<SkImage> scaleSkImage(sk_sp<SkImage> skImage, 731 static sk_sp<SkImage> scaleSkImage(sk_sp<SkImage> skImage,
739 unsigned resizeWidth, 732 unsigned resizeWidth,
740 unsigned resizeHeight, 733 unsigned resizeHeight,
741 SkFilterQuality resizeQuality) { 734 SkFilterQuality resizeQuality,
735 sk_sp<SkColorSpace> colorSpace = nullptr) {
736 SkColorType colorType = kN32_SkColorType;
737 if (colorSpace &&
738 SkColorSpace::Equals(
739 colorSpace.get(),
740 SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named).get()))
741 colorType = kRGBA_F16_SkColorType;
Justin Novosad 2017/01/17 20:00:09 This approach is fragile. You should add a colorT
zakerinasab1 2017/01/18 18:34:21 Done.
742 SkImageInfo resizedInfo = SkImageInfo::Make( 742 SkImageInfo resizedInfo = SkImageInfo::Make(
743 resizeWidth, resizeHeight, kN32_SkColorType, kUnpremul_SkAlphaType); 743 resizeWidth, resizeHeight, colorType, kUnpremul_SkAlphaType, colorSpace);
744 RefPtr<ArrayBuffer> dstBuffer = ArrayBuffer::createOrNull( 744 RefPtr<ArrayBuffer> dstBuffer = ArrayBuffer::createOrNull(
745 resizeWidth * resizeHeight, resizedInfo.bytesPerPixel()); 745 resizeWidth * resizeHeight, resizedInfo.bytesPerPixel());
746 if (!dstBuffer) 746 if (!dstBuffer)
747 return nullptr; 747 return nullptr;
748 RefPtr<Uint8Array> resizedPixels = 748
749 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength()); 749 if (colorType == kN32_SkColorType) {
750 RefPtr<Uint8Array> resizedPixels =
751 Uint8Array::create(dstBuffer, 0, dstBuffer->byteLength());
752 SkPixmap pixmap(
753 resizedInfo, resizedPixels->data(),
754 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel());
755 skImage->scalePixels(pixmap, resizeQuality);
756 return SkImage::MakeFromRaster(pixmap,
757 [](const void*, void* pixels) {
758 static_cast<Uint8Array*>(pixels)->deref();
759 },
760 resizedPixels.release().leakRef());
761 }
762
763 RefPtr<Float32Array> resizedPixels =
764 Float32Array::create(dstBuffer, 0, dstBuffer->byteLength());
750 SkPixmap pixmap( 765 SkPixmap pixmap(
751 resizedInfo, resizedPixels->data(), 766 resizedInfo, resizedPixels->data(),
752 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); 767 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel());
753 skImage->scalePixels(pixmap, resizeQuality); 768 skImage->scalePixels(pixmap, resizeQuality);
754 return SkImage::MakeFromRaster(pixmap, 769 return SkImage::MakeFromRaster(pixmap,
755 [](const void*, void* pixels) { 770 [](const void*, void* pixels) {
756 static_cast<Uint8Array*>(pixels)->deref(); 771 static_cast<Float32Array*>(pixels)->deref();
757 }, 772 },
758 resizedPixels.release().leakRef()); 773 resizedPixels.release().leakRef());
759 } 774 }
760 775
761 // TODO(zakerinasab): Fix this and the constructor from Float32ImageData
762 // when the CL for Float32ImageData landed.
763 ImageBitmap::ImageBitmap(ImageData* data, 776 ImageBitmap::ImageBitmap(ImageData* data,
764 Optional<IntRect> cropRect, 777 Optional<IntRect> cropRect,
765 const ImageBitmapOptions& options) { 778 const ImageBitmapOptions& options) {
766 // TODO(xidachen): implement the resize option 779 // TODO(xidachen): implement the resize option
767 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); 780 IntRect dataSrcRect = IntRect(IntPoint(), data->size());
768 ParsedOptions parsedOptions = 781 ParsedOptions parsedOptions =
769 parseOptions(options, cropRect, data->bitmapSourceSize()); 782 parseOptions(options, cropRect, data->bitmapSourceSize());
770 if (dstBufferSizeHasOverflow(parsedOptions)) 783 if (dstBufferSizeHasOverflow(parsedOptions))
771 return; 784 return;
772 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) 785 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect)
773 : dataSrcRect; 786 : dataSrcRect;
774 787
775 // treat non-premultiplyAlpha as a special case 788 // treat non-premultiplyAlpha as a special case
776 if (!parsedOptions.premultiplyAlpha) { 789 if (!parsedOptions.premultiplyAlpha) {
777 unsigned char* srcAddr = data->data()->data(); 790 unsigned char* srcAddr = data->data()->data();
778 791
779 // Using kN32 type, swizzle input if necessary. 792 // Using kN32 type, swizzle input if necessary.
780 SkImageInfo info = SkImageInfo::Make( 793 SkImageInfo info = SkImageInfo::Make(
781 parsedOptions.cropRect.width(), parsedOptions.cropRect.height(), 794 parsedOptions.cropRect.width(), parsedOptions.cropRect.height(),
782 kN32_SkColorType, kUnpremul_SkAlphaType); 795 kN32_SkColorType, kUnpremul_SkAlphaType, data->getSkColorSpace());
783 unsigned bytesPerPixel = static_cast<unsigned>(info.bytesPerPixel()); 796 unsigned bytesPerPixel = static_cast<unsigned>(info.bytesPerPixel());
784 unsigned srcPixelBytesPerRow = bytesPerPixel * data->size().width(); 797 unsigned srcPixelBytesPerRow = bytesPerPixel * data->size().width();
785 unsigned dstPixelBytesPerRow = 798 unsigned dstPixelBytesPerRow =
786 bytesPerPixel * parsedOptions.cropRect.width(); 799 bytesPerPixel * parsedOptions.cropRect.width();
787 sk_sp<SkImage> skImage; 800 sk_sp<SkImage> skImage;
788 if (parsedOptions.cropRect == IntRect(IntPoint(), data->size())) { 801 if (parsedOptions.cropRect == IntRect(IntPoint(), data->size())) {
789 swizzleImageData(srcAddr, data->size().height(), srcPixelBytesPerRow, 802 swizzleImageData(srcAddr, data->size().height(), srcPixelBytesPerRow,
790 parsedOptions.flipY); 803 parsedOptions.flipY);
791 skImage = 804 skImage =
792 SkImage::MakeRasterCopy(SkPixmap(info, srcAddr, dstPixelBytesPerRow)); 805 SkImage::MakeRasterCopy(SkPixmap(info, srcAddr, dstPixelBytesPerRow));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 srcAddr[srcStartCopyPosition + j]; 862 srcAddr[srcStartCopyPosition + j];
850 } 863 }
851 } 864 }
852 } 865 }
853 } 866 }
854 skImage = newSkImageFromRaster(info, std::move(copiedDataBuffer), 867 skImage = newSkImageFromRaster(info, std::move(copiedDataBuffer),
855 dstPixelBytesPerRow); 868 dstPixelBytesPerRow);
856 } 869 }
857 if (!skImage) 870 if (!skImage)
858 return; 871 return;
859 if (parsedOptions.shouldScaleInput) 872 if (data->getSkColorSpace()) {
873 parsedOptions.latestColorSpace = data->getSkColorSpace();
874 applyColorSpaceConversion(skImage, parsedOptions);
875 }
876 if (parsedOptions.shouldScaleInput) {
860 m_image = StaticBitmapImage::create(scaleSkImage( 877 m_image = StaticBitmapImage::create(scaleSkImage(
861 skImage, parsedOptions.resizeWidth, parsedOptions.resizeHeight, 878 skImage, parsedOptions.resizeWidth, parsedOptions.resizeHeight,
862 parsedOptions.resizeQuality)); 879 parsedOptions.resizeQuality, data->getSkColorSpace()));
863 else 880 } else {
864 m_image = StaticBitmapImage::create(skImage); 881 m_image = StaticBitmapImage::create(skImage);
882 }
865 if (!m_image) 883 if (!m_image)
866 return; 884 return;
867 m_image->setPremultiplied(parsedOptions.premultiplyAlpha); 885 m_image->setPremultiplied(parsedOptions.premultiplyAlpha);
868 return; 886 return;
869 } 887 }
870 888
871 std::unique_ptr<ImageBuffer> buffer = ImageBuffer::create( 889 std::unique_ptr<ImageBuffer> buffer =
872 parsedOptions.cropRect.size(), NonOpaque, DoNotInitializeImagePixels); 890 ImageBuffer::create(parsedOptions.cropRect.size(), NonOpaque,
891 DoNotInitializeImagePixels, data->getSkColorSpace());
873 if (!buffer) 892 if (!buffer)
874 return; 893 return;
875 894
876 if (srcRect.isEmpty()) { 895 if (srcRect.isEmpty()) {
877 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot( 896 m_image = StaticBitmapImage::create(buffer->newSkImageSnapshot(
878 PreferNoAcceleration, SnapshotReasonUnknown)); 897 PreferNoAcceleration, SnapshotReasonUnknown));
879 return; 898 return;
880 } 899 }
881 900
882 IntPoint dstPoint = IntPoint(std::min(0, -parsedOptions.cropRect.x()), 901 IntPoint dstPoint = IntPoint(std::min(0, -parsedOptions.cropRect.x()),
883 std::min(0, -parsedOptions.cropRect.y())); 902 std::min(0, -parsedOptions.cropRect.y()));
884 if (parsedOptions.cropRect.x() < 0) 903 if (parsedOptions.cropRect.x() < 0)
885 dstPoint.setX(-parsedOptions.cropRect.x()); 904 dstPoint.setX(-parsedOptions.cropRect.x());
886 if (parsedOptions.cropRect.y() < 0) 905 if (parsedOptions.cropRect.y() < 0)
887 dstPoint.setY(-parsedOptions.cropRect.y()); 906 dstPoint.setY(-parsedOptions.cropRect.y());
907
888 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(), 908 buffer->putByteArray(Unmultiplied, data->data()->data(), data->size(),
889 srcRect, dstPoint); 909 srcRect, dstPoint);
890 sk_sp<SkImage> skImage = 910 sk_sp<SkImage> skImage =
891 buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown); 911 buffer->newSkImageSnapshot(PreferNoAcceleration, SnapshotReasonUnknown);
912 SkImageInfo imageInfo = SkImageInfo::Make(1, 1, SkColorType::kN32_SkColorType,
Justin Novosad 2017/01/17 20:00:09 This variable appear to be unused.
zakerinasab1 2017/01/18 18:34:21 Ah, that was for debug. Removed.
913 SkAlphaType::kUnpremul_SkAlphaType,
914 data->getSkColorSpace());
915
892 if (parsedOptions.flipY) 916 if (parsedOptions.flipY)
893 skImage = flipSkImageVertically(skImage.get(), EnforceAlphaPremultiply); 917 skImage = flipSkImageVertically(skImage.get(), EnforceAlphaPremultiply);
894 if (!skImage) 918 if (!skImage)
895 return; 919 return;
896 if (parsedOptions.shouldScaleInput) { 920 if (parsedOptions.shouldScaleInput) {
897 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 921 sk_sp<SkSurface> surface = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(
Justin Novosad 2017/01/17 20:00:09 I don'think it is Okay to assume N32 here.
zakerinasab1 2017/01/18 18:34:21 I think it is safe because this constructor always
898 parsedOptions.resizeWidth, parsedOptions.resizeHeight); 922 parsedOptions.resizeWidth, parsedOptions.resizeHeight,
923 data->getSkColorSpace()));
899 if (!surface) 924 if (!surface)
900 return; 925 return;
901 SkPaint paint; 926 SkPaint paint;
902 paint.setFilterQuality(parsedOptions.resizeQuality); 927 paint.setFilterQuality(parsedOptions.resizeQuality);
903 SkRect dstDrawRect = 928 SkRect dstDrawRect =
904 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); 929 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight);
905 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); 930 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint);
906 skImage = surface->makeImageSnapshot(); 931 skImage = surface->makeImageSnapshot();
907 } 932 }
933 if (data->getSkColorSpace()) {
934 parsedOptions.latestColorSpace = data->getSkColorSpace();
935 applyColorSpaceConversion(skImage, parsedOptions);
936 }
908 m_image = StaticBitmapImage::create(std::move(skImage)); 937 m_image = StaticBitmapImage::create(std::move(skImage));
909 } 938 }
910 939
940 // TODO(zakerinasab): Fix the constructor from Float32ImageData.
911 ImageBitmap::ImageBitmap(Float32ImageData* data, 941 ImageBitmap::ImageBitmap(Float32ImageData* data,
912 Optional<IntRect> cropRect, 942 Optional<IntRect> cropRect,
913 const ImageBitmapOptions& options) {} 943 const ImageBitmapOptions& options) {}
914 944
915 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, 945 ImageBitmap::ImageBitmap(ImageBitmap* bitmap,
916 Optional<IntRect> cropRect, 946 Optional<IntRect> cropRect,
917 const ImageBitmapOptions& options) { 947 const ImageBitmapOptions& options) {
918 RefPtr<Image> input = bitmap->bitmapImage(); 948 RefPtr<Image> input = bitmap->bitmapImage();
919 if (!input) 949 if (!input)
920 return; 950 return;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, 1138 void ImageBitmap::adjustDrawRects(FloatRect* srcRect,
1109 FloatRect* dstRect) const {} 1139 FloatRect* dstRect) const {}
1110 1140
1111 FloatSize ImageBitmap::elementSize(const FloatSize&) const { 1141 FloatSize ImageBitmap::elementSize(const FloatSize&) const {
1112 return FloatSize(width(), height()); 1142 return FloatSize(width(), height());
1113 } 1143 }
1114 1144
1115 DEFINE_TRACE(ImageBitmap) {} 1145 DEFINE_TRACE(ImageBitmap) {}
1116 1146
1117 } // namespace blink 1147 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698