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

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

Issue 2555213002: Implement color management for ImageData (Closed)
Patch Set: Rebaselining layout tests 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
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/HTMLCanvasElement.h" 8 #include "core/html/HTMLCanvasElement.h"
8 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
9 #include "core/html/ImageData.h" 10 #include "core/html/ImageData.h"
10 #include "core/offscreencanvas/OffscreenCanvas.h" 11 #include "core/offscreencanvas/OffscreenCanvas.h"
11 #include "platform/graphics/skia/SkiaUtils.h" 12 #include "platform/graphics/skia/SkiaUtils.h"
12 #include "platform/image-decoders/ImageDecoder.h" 13 #include "platform/image-decoders/ImageDecoder.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkImageInfo.h" 15 #include "third_party/skia/include/core/SkImageInfo.h"
15 #include "third_party/skia/include/core/SkSurface.h" 16 #include "third_party/skia/include/core/SkSurface.h"
16 #include "wtf/CheckedNumeric.h" 17 #include "wtf/CheckedNumeric.h"
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 resizedInfo, resizedPixels->data(), 751 resizedInfo, resizedPixels->data(),
751 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel()); 752 static_cast<unsigned>(resizeWidth) * resizedInfo.bytesPerPixel());
752 skImage->scalePixels(pixmap, resizeQuality); 753 skImage->scalePixels(pixmap, resizeQuality);
753 return SkImage::MakeFromRaster(pixmap, 754 return SkImage::MakeFromRaster(pixmap,
754 [](const void*, void* pixels) { 755 [](const void*, void* pixels) {
755 static_cast<Uint8Array*>(pixels)->deref(); 756 static_cast<Uint8Array*>(pixels)->deref();
756 }, 757 },
757 resizedPixels.release().leakRef()); 758 resizedPixels.release().leakRef());
758 } 759 }
759 760
761 // TODO(zakerinasab): Fix this and the constructor from Float32ImageData
762 // when the CL for Float32ImageData landed.
760 ImageBitmap::ImageBitmap(ImageData* data, 763 ImageBitmap::ImageBitmap(ImageData* data,
761 Optional<IntRect> cropRect, 764 Optional<IntRect> cropRect,
762 const ImageBitmapOptions& options) { 765 const ImageBitmapOptions& options) {
763 // TODO(xidachen): implement the resize option 766 // TODO(xidachen): implement the resize option
764 IntRect dataSrcRect = IntRect(IntPoint(), data->size()); 767 IntRect dataSrcRect = IntRect(IntPoint(), data->size());
765 ParsedOptions parsedOptions = 768 ParsedOptions parsedOptions =
766 parseOptions(options, cropRect, data->bitmapSourceSize()); 769 parseOptions(options, cropRect, data->bitmapSourceSize());
767 if (dstBufferSizeHasOverflow(parsedOptions)) 770 if (dstBufferSizeHasOverflow(parsedOptions))
768 return; 771 return;
769 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect) 772 IntRect srcRect = cropRect ? intersection(parsedOptions.cropRect, dataSrcRect)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 SkPaint paint; 901 SkPaint paint;
899 paint.setFilterQuality(parsedOptions.resizeQuality); 902 paint.setFilterQuality(parsedOptions.resizeQuality);
900 SkRect dstDrawRect = 903 SkRect dstDrawRect =
901 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight); 904 SkRect::MakeWH(parsedOptions.resizeWidth, parsedOptions.resizeHeight);
902 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint); 905 surface->getCanvas()->drawImageRect(skImage, dstDrawRect, &paint);
903 skImage = surface->makeImageSnapshot(); 906 skImage = surface->makeImageSnapshot();
904 } 907 }
905 m_image = StaticBitmapImage::create(std::move(skImage)); 908 m_image = StaticBitmapImage::create(std::move(skImage));
906 } 909 }
907 910
911 ImageBitmap::ImageBitmap(Float32ImageData* data,
912 Optional<IntRect> cropRect,
913 const ImageBitmapOptions& options) {}
914
908 ImageBitmap::ImageBitmap(ImageBitmap* bitmap, 915 ImageBitmap::ImageBitmap(ImageBitmap* bitmap,
909 Optional<IntRect> cropRect, 916 Optional<IntRect> cropRect,
910 const ImageBitmapOptions& options) { 917 const ImageBitmapOptions& options) {
911 RefPtr<Image> input = bitmap->bitmapImage(); 918 RefPtr<Image> input = bitmap->bitmapImage();
912 if (!input) 919 if (!input)
913 return; 920 return;
914 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size()); 921 ParsedOptions parsedOptions = parseOptions(options, cropRect, input->size());
915 if (dstBufferSizeHasOverflow(parsedOptions)) 922 if (dstBufferSizeHasOverflow(parsedOptions))
916 return; 923 return;
917 924
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 const ImageBitmapOptions& options) { 989 const ImageBitmapOptions& options) {
983 return new ImageBitmap(offscreenCanvas, cropRect, options); 990 return new ImageBitmap(offscreenCanvas, cropRect, options);
984 } 991 }
985 992
986 ImageBitmap* ImageBitmap::create(ImageData* data, 993 ImageBitmap* ImageBitmap::create(ImageData* data,
987 Optional<IntRect> cropRect, 994 Optional<IntRect> cropRect,
988 const ImageBitmapOptions& options) { 995 const ImageBitmapOptions& options) {
989 return new ImageBitmap(data, cropRect, options); 996 return new ImageBitmap(data, cropRect, options);
990 } 997 }
991 998
999 ImageBitmap* ImageBitmap::create(Float32ImageData* data,
1000 Optional<IntRect> cropRect,
1001 const ImageBitmapOptions& options) {
1002 return new ImageBitmap(data, cropRect, options);
1003 }
1004
992 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap, 1005 ImageBitmap* ImageBitmap::create(ImageBitmap* bitmap,
993 Optional<IntRect> cropRect, 1006 Optional<IntRect> cropRect,
994 const ImageBitmapOptions& options) { 1007 const ImageBitmapOptions& options) {
995 return new ImageBitmap(bitmap, cropRect, options); 1008 return new ImageBitmap(bitmap, cropRect, options);
996 } 1009 }
997 1010
998 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image, 1011 ImageBitmap* ImageBitmap::create(PassRefPtr<StaticBitmapImage> image,
999 Optional<IntRect> cropRect, 1012 Optional<IntRect> cropRect,
1000 const ImageBitmapOptions& options) { 1013 const ImageBitmapOptions& options) {
1001 return new ImageBitmap(std::move(image), cropRect, options); 1014 return new ImageBitmap(std::move(image), cropRect, options);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 void ImageBitmap::adjustDrawRects(FloatRect* srcRect, 1108 void ImageBitmap::adjustDrawRects(FloatRect* srcRect,
1096 FloatRect* dstRect) const {} 1109 FloatRect* dstRect) const {}
1097 1110
1098 FloatSize ImageBitmap::elementSize(const FloatSize&) const { 1111 FloatSize ImageBitmap::elementSize(const FloatSize&) const {
1099 return FloatSize(width(), height()); 1112 return FloatSize(width(), height());
1100 } 1113 }
1101 1114
1102 DEFINE_TRACE(ImageBitmap) {} 1115 DEFINE_TRACE(ImageBitmap) {}
1103 1116
1104 } // namespace blink 1117 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698