| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef ImageData_h | 29 #ifndef ImageData_h |
| 30 #define ImageData_h | 30 #define ImageData_h |
| 31 | 31 |
| 32 #include "bindings/core/v8/ScriptWrappable.h" | 32 #include "bindings/core/v8/ScriptWrappable.h" |
| 33 #include "bindings/core/v8/Uint8ClampedArrayOrUint16ArrayOrFloat32Array.h" |
| 33 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
| 34 #include "core/dom/DOMArrayBufferView.h" | |
| 35 #include "core/dom/DOMTypedArray.h" | 35 #include "core/dom/DOMTypedArray.h" |
| 36 #include "core/html/ImageDataColorSettings.h" |
| 37 #include "core/html/canvas/CanvasRenderingContext.h" |
| 36 #include "core/imagebitmap/ImageBitmapSource.h" | 38 #include "core/imagebitmap/ImageBitmapSource.h" |
| 37 #include "platform/geometry/IntRect.h" | 39 #include "platform/geometry/IntRect.h" |
| 38 #include "platform/geometry/IntSize.h" | 40 #include "platform/geometry/IntSize.h" |
| 39 #include "platform/heap/Handle.h" | 41 #include "platform/heap/Handle.h" |
| 40 #include "third_party/skia/include/core/SkColorSpace.h" | 42 #include "third_party/skia/include/core/SkColorSpace.h" |
| 41 #include "wtf/CheckedNumeric.h" | 43 #include "wtf/CheckedNumeric.h" |
| 42 #include "wtf/Compiler.h" | 44 #include "wtf/Compiler.h" |
| 43 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
| 44 | 46 |
| 45 namespace blink { | 47 namespace blink { |
| 46 | 48 |
| 47 class ExceptionState; | 49 class ExceptionState; |
| 48 class ImageBitmapOptions; | 50 class ImageBitmapOptions; |
| 49 | 51 |
| 52 typedef Uint8ClampedArrayOrUint16ArrayOrFloat32Array ImageDataArray; |
| 53 |
| 50 enum ConstructorParams { | 54 enum ConstructorParams { |
| 51 kParamSize = 1, | 55 kParamSize = 1, |
| 52 kParamWidth = 1 << 1, | 56 kParamWidth = 1 << 1, |
| 53 kParamHeight = 1 << 2, | 57 kParamHeight = 1 << 2, |
| 54 kParamData = 1 << 3, | 58 kParamData = 1 << 3, |
| 55 kParamColorSpace = 1 << 4, | |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 enum ImageDataType { | 61 enum ImageDataStorageFormat { |
| 59 kUint8ClampedImageData, | 62 kUint8ClampedArrayStorageFormat, |
| 60 kFloat32ImageData, | 63 kUint16ArrayStorageFormat, |
| 64 kFloat32ArrayStorageFormat, |
| 61 }; | 65 }; |
| 62 | 66 |
| 63 enum ImageDataColorSpace { | 67 constexpr const char* kUint8ClampedArrayStorageFormatName = "uint8"; |
| 64 kLegacyImageDataColorSpace, | 68 constexpr const char* kUint16ArrayStorageFormatName = "uint16"; |
| 65 kSRGBImageDataColorSpace, | 69 constexpr const char* kFloat32ArrayStorageFormatName = "float32"; |
| 66 kLinearRGBImageDataColorSpace, | |
| 67 }; | |
| 68 | |
| 69 const char* const kLinearRGBImageDataColorSpaceName = "linear-rgb"; | |
| 70 const char* const kSRGBImageDataColorSpaceName = "srgb"; | |
| 71 const char* const kLegacyImageDataColorSpaceName = "legacy-srgb"; | |
| 72 | 70 |
| 73 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, | 71 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, |
| 74 public ScriptWrappable, | 72 public ScriptWrappable, |
| 75 public ImageBitmapSource { | 73 public ImageBitmapSource { |
| 76 DEFINE_WRAPPERTYPEINFO(); | 74 DEFINE_WRAPPERTYPEINFO(); |
| 77 | 75 |
| 78 public: | 76 public: |
| 79 static ImageData* create(const IntSize&); | 77 static ImageData* create(const IntSize&); |
| 80 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); | 78 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); |
| 81 static ImageData* create(const IntSize&, | 79 |
| 82 DOMUint8ClampedArray*, | |
| 83 const String&); | |
| 84 static ImageData* create(unsigned width, unsigned height, ExceptionState&); | 80 static ImageData* create(unsigned width, unsigned height, ExceptionState&); |
| 85 static ImageData* create(DOMUint8ClampedArray*, | 81 static ImageData* create(DOMUint8ClampedArray*, |
| 86 unsigned width, | 82 unsigned width, |
| 87 ExceptionState&); | 83 ExceptionState&); |
| 88 static ImageData* create(DOMUint8ClampedArray*, | 84 static ImageData* create(DOMUint8ClampedArray*, |
| 89 unsigned width, | 85 unsigned width, |
| 90 unsigned height, | 86 unsigned height, |
| 91 ExceptionState&); | 87 ExceptionState&); |
| 92 | 88 |
| 93 static ImageData* createForTest(const IntSize&); | 89 static ImageData* createForTest(const IntSize&); |
| 94 | 90 |
| 95 ImageData* createImageData(unsigned width, | 91 ImageData* createImageData(unsigned width, |
| 96 unsigned height, | 92 unsigned height, |
| 97 String colorSpace, | 93 const ImageDataColorSettings&, |
| 98 ExceptionState&); | 94 ExceptionState&); |
| 99 ImageData* createImageData(DOMUint8ClampedArray*, | 95 ImageData* createImageData(ImageDataArray&, |
| 100 unsigned width, | |
| 101 String colorSpace, | |
| 102 ExceptionState&); | |
| 103 ImageData* createImageData(DOMUint8ClampedArray*, | |
| 104 unsigned width, | 96 unsigned width, |
| 105 unsigned height, | 97 unsigned height, |
| 106 String colorSpace, | 98 const ImageDataColorSettings&, |
| 107 ExceptionState&); | 99 ExceptionState&); |
| 108 | 100 |
| 109 static ImageDataColorSpace getImageDataColorSpace(String); | 101 static ImageDataStorageFormat getImageDataStorageFormat(const String&); |
| 110 static String getImageDataColorSpaceName(ImageDataColorSpace); | |
| 111 static sk_sp<SkColorSpace> imageDataColorSpaceToSkColorSpace( | |
| 112 ImageDataColorSpace); | |
| 113 | 102 |
| 114 IntSize size() const { return m_size; } | 103 IntSize size() const { return m_size; } |
| 115 int width() const { return m_size.width(); } | 104 int width() const { return m_size.width(); } |
| 116 int height() const { return m_size.height(); } | 105 int height() const { return m_size.height(); } |
| 117 String colorSpace() const { return getImageDataColorSpaceName(m_colorSpace); } | 106 |
| 118 ImageDataColorSpace imageDataColorSpace() { return m_colorSpace; } | 107 DOMUint8ClampedArray* data(); |
| 119 const DOMUint8ClampedArray* data() const { return m_data.get(); } | 108 const DOMUint8ClampedArray* data() const; |
| 120 DOMUint8ClampedArray* data() { return m_data.get(); } | 109 ImageDataArray& dataUnion() { return m_dataUnion; } |
| 110 const ImageDataArray& dataUnion() const { return m_dataUnion; } |
| 111 void dataUnion(ImageDataArray& result) { result = m_dataUnion; }; |
| 112 const ImageDataColorSettings& colorSettings() const { |
| 113 return m_colorSettings; |
| 114 } |
| 115 void colorSettings(ImageDataColorSettings& result) { |
| 116 result = m_colorSettings; |
| 117 }; |
| 121 | 118 |
| 122 sk_sp<SkColorSpace> getSkColorSpace(); | 119 sk_sp<SkColorSpace> getSkColorSpace(); |
| 123 | 120 |
| 124 // ImageBitmapSource implementation | 121 // ImageBitmapSource implementation |
| 125 IntSize bitmapSourceSize() const override { return m_size; } | 122 IntSize bitmapSourceSize() const override { return m_size; } |
| 126 ScriptPromise createImageBitmap(ScriptState*, | 123 ScriptPromise createImageBitmap(ScriptState*, |
| 127 EventTarget&, | 124 EventTarget&, |
| 128 Optional<IntRect> cropRect, | 125 Optional<IntRect> cropRect, |
| 129 const ImageBitmapOptions&, | 126 const ImageBitmapOptions&, |
| 130 ExceptionState&) override; | 127 ExceptionState&) override; |
| 131 | 128 |
| 132 DEFINE_INLINE_TRACE() { visitor->trace(m_data); } | 129 void trace(Visitor*); |
| 133 | 130 |
| 134 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( | 131 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( |
| 135 v8::Isolate*, | 132 v8::Isolate*, |
| 136 const WrapperTypeInfo*, | 133 const WrapperTypeInfo*, |
| 137 v8::Local<v8::Object> wrapper) override; | 134 v8::Local<v8::Object> wrapper) override; |
| 138 | 135 |
| 139 static bool validateConstructorArguments( | 136 static bool validateConstructorArguments(const unsigned&, |
| 140 const unsigned&, | 137 const IntSize* = nullptr, |
| 141 const IntSize* = nullptr, | 138 const unsigned& = 0, |
| 142 const unsigned& = 0, | 139 const unsigned& = 0, |
| 143 const unsigned& = 0, | 140 const DOMArrayBufferView* = nullptr, |
| 144 const DOMArrayBufferView* = nullptr, | 141 ExceptionState* = nullptr); |
| 145 const String* = nullptr, | |
| 146 ExceptionState* = nullptr, | |
| 147 ImageDataType = kUint8ClampedImageData); | |
| 148 | 142 |
| 149 private: | 143 private: |
| 150 ImageData(const IntSize&, | 144 ImageData(const IntSize&, |
| 151 DOMUint8ClampedArray*, | 145 DOMArrayBufferView*, |
| 152 String = kLegacyImageDataColorSpaceName); | 146 const ImageDataColorSettings* = nullptr); |
| 153 | 147 |
| 154 IntSize m_size; | 148 IntSize m_size; |
| 155 ImageDataColorSpace m_colorSpace; | 149 ImageDataColorSettings m_colorSettings; |
| 150 ImageDataArray m_dataUnion; |
| 156 Member<DOMUint8ClampedArray> m_data; | 151 Member<DOMUint8ClampedArray> m_data; |
| 152 Member<DOMUint16Array> m_dataU16; |
| 153 Member<DOMFloat32Array> m_dataF32; |
| 157 | 154 |
| 158 static DOMUint8ClampedArray* allocateAndValidateUint8ClampedArray( | 155 static DOMArrayBufferView* allocateAndValidateDataArray( |
| 159 const unsigned&, | 156 const unsigned&, |
| 157 ImageDataStorageFormat, |
| 160 ExceptionState* = nullptr); | 158 ExceptionState* = nullptr); |
| 161 }; | 159 }; |
| 162 | 160 |
| 163 } // namespace blink | 161 } // namespace blink |
| 164 | 162 |
| 165 #endif // ImageData_h | 163 #endif // ImageData_h |
| OLD | NEW |