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 13 matching lines...) Expand all Loading... |
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 "core/CoreExport.h" | 33 #include "core/CoreExport.h" |
| 34 #include "core/dom/DOMArrayBufferView.h" |
34 #include "core/dom/DOMTypedArray.h" | 35 #include "core/dom/DOMTypedArray.h" |
35 #include "core/imagebitmap/ImageBitmapSource.h" | 36 #include "core/imagebitmap/ImageBitmapSource.h" |
36 #include "platform/geometry/IntRect.h" | 37 #include "platform/geometry/IntRect.h" |
37 #include "platform/geometry/IntSize.h" | 38 #include "platform/geometry/IntSize.h" |
38 #include "platform/heap/Handle.h" | 39 #include "platform/heap/Handle.h" |
| 40 #include "wtf/CheckedNumeric.h" |
39 #include "wtf/Compiler.h" | 41 #include "wtf/Compiler.h" |
| 42 #include "wtf/text/WTFString.h" |
40 | 43 |
41 namespace blink { | 44 namespace blink { |
42 | 45 |
43 class ExceptionState; | 46 class ExceptionState; |
44 class ImageBitmapOptions; | 47 class ImageBitmapOptions; |
45 | 48 |
| 49 enum ConstructorParams { |
| 50 kParamSize = 1, |
| 51 kParamWidth = 1 << 1, |
| 52 kParamHeight = 1 << 2, |
| 53 kParamData = 1 << 3, |
| 54 kParamColorSpace = 1 << 4, |
| 55 }; |
| 56 |
| 57 enum ImageDataType { |
| 58 kUint8ClampedImageData, |
| 59 kFloat32ImageData, |
| 60 }; |
| 61 |
| 62 enum ImageDataColorSpace { |
| 63 kLegacyImageDataColorSpace, |
| 64 kSRGBImageDataColorSpace, |
| 65 kLinearRGBImageDataColorSpace, |
| 66 }; |
| 67 |
| 68 const char* const kLinearRGBImageDataColorSpaceName = "linear-rgb"; |
| 69 const char* const kSRGBImageDataColorSpaceName = "srgb"; |
| 70 const char* const kLegacyImageDataColorSpaceName = "legacy-srgb"; |
| 71 |
46 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, | 72 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, |
47 public ScriptWrappable, | 73 public ScriptWrappable, |
48 public ImageBitmapSource { | 74 public ImageBitmapSource { |
49 DEFINE_WRAPPERTYPEINFO(); | 75 DEFINE_WRAPPERTYPEINFO(); |
50 | 76 |
51 public: | 77 public: |
52 static ImageData* create(const IntSize&); | 78 static ImageData* create(const IntSize&); |
53 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); | 79 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); |
54 static ImageData* create(unsigned width, unsigned height, ExceptionState&); | 80 static ImageData* create(unsigned width, unsigned height, ExceptionState&); |
55 static ImageData* create(DOMUint8ClampedArray*, | 81 static ImageData* create(DOMUint8ClampedArray*, |
56 unsigned width, | 82 unsigned width, |
57 ExceptionState&); | 83 ExceptionState&); |
58 static ImageData* create(DOMUint8ClampedArray*, | 84 static ImageData* create(DOMUint8ClampedArray*, |
59 unsigned width, | 85 unsigned width, |
60 unsigned height, | 86 unsigned height, |
61 ExceptionState&); | 87 ExceptionState&); |
62 | 88 |
| 89 static ImageData* createForTest(const IntSize&); |
| 90 |
| 91 ImageData* createImageData(unsigned width, |
| 92 unsigned height, |
| 93 String colorSpace, |
| 94 ExceptionState&); |
| 95 ImageData* createImageData(DOMUint8ClampedArray*, |
| 96 unsigned width, |
| 97 String colorSpace, |
| 98 ExceptionState&); |
| 99 ImageData* createImageData(DOMUint8ClampedArray*, |
| 100 unsigned width, |
| 101 unsigned height, |
| 102 String colorSpace, |
| 103 ExceptionState&); |
| 104 |
| 105 static ImageDataColorSpace getImageDataColorSpace(String); |
| 106 static String getImageDataColorSpaceName(ImageDataColorSpace); |
| 107 |
63 IntSize size() const { return m_size; } | 108 IntSize size() const { return m_size; } |
64 int width() const { return m_size.width(); } | 109 int width() const { return m_size.width(); } |
65 int height() const { return m_size.height(); } | 110 int height() const { return m_size.height(); } |
| 111 String colorSpace() const { return getImageDataColorSpaceName(m_colorSpace); } |
| 112 ImageDataColorSpace imageDataColorSpace() { return m_colorSpace; } |
66 const DOMUint8ClampedArray* data() const { return m_data.get(); } | 113 const DOMUint8ClampedArray* data() const { return m_data.get(); } |
67 DOMUint8ClampedArray* data() { return m_data.get(); } | 114 DOMUint8ClampedArray* data() { return m_data.get(); } |
68 | 115 |
69 // ImageBitmapSource implementation | 116 // ImageBitmapSource implementation |
70 IntSize bitmapSourceSize() const override { return m_size; } | 117 IntSize bitmapSourceSize() const override { return m_size; } |
71 ScriptPromise createImageBitmap(ScriptState*, | 118 ScriptPromise createImageBitmap(ScriptState*, |
72 EventTarget&, | 119 EventTarget&, |
73 Optional<IntRect> cropRect, | 120 Optional<IntRect> cropRect, |
74 const ImageBitmapOptions&, | 121 const ImageBitmapOptions&, |
75 ExceptionState&) override; | 122 ExceptionState&) override; |
76 | 123 |
77 DEFINE_INLINE_TRACE() { visitor->trace(m_data); } | 124 DEFINE_INLINE_TRACE() { visitor->trace(m_data); } |
78 | 125 |
79 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( | 126 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( |
80 v8::Isolate*, | 127 v8::Isolate*, |
81 const WrapperTypeInfo*, | 128 const WrapperTypeInfo*, |
82 v8::Local<v8::Object> wrapper) override; | 129 v8::Local<v8::Object> wrapper) override; |
83 | 130 |
| 131 static bool validateConstructorArguments( |
| 132 const unsigned&, |
| 133 const IntSize* = nullptr, |
| 134 const unsigned& = 0, |
| 135 const unsigned& = 0, |
| 136 const DOMArrayBufferView* = nullptr, |
| 137 const String* = nullptr, |
| 138 ExceptionState* = nullptr, |
| 139 ImageDataType = kUint8ClampedImageData); |
| 140 |
84 private: | 141 private: |
85 ImageData(const IntSize&, DOMUint8ClampedArray*); | 142 ImageData(const IntSize&, |
86 | 143 DOMUint8ClampedArray*, |
87 static bool validateConstructorArguments(DOMUint8ClampedArray*, | 144 String = kLegacyImageDataColorSpaceName); |
88 unsigned width, | |
89 unsigned&, | |
90 ExceptionState&); | |
91 | 145 |
92 IntSize m_size; | 146 IntSize m_size; |
| 147 ImageDataColorSpace m_colorSpace; |
93 Member<DOMUint8ClampedArray> m_data; | 148 Member<DOMUint8ClampedArray> m_data; |
| 149 |
| 150 static DOMUint8ClampedArray* allocateAndValidateUint8ClampedArray( |
| 151 const unsigned&, |
| 152 ExceptionState* = nullptr); |
94 }; | 153 }; |
95 | 154 |
96 } // namespace blink | 155 } // namespace blink |
97 | 156 |
98 #endif // ImageData_h | 157 #endif // ImageData_h |
OLD | NEW |