| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 kParamHeight = 1 << 2, | 57 kParamHeight = 1 << 2, |
| 58 kParamData = 1 << 3, | 58 kParamData = 1 << 3, |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 enum ImageDataStorageFormat { | 61 enum ImageDataStorageFormat { |
| 62 kUint8ClampedArrayStorageFormat, | 62 kUint8ClampedArrayStorageFormat, |
| 63 kUint16ArrayStorageFormat, | 63 kUint16ArrayStorageFormat, |
| 64 kFloat32ArrayStorageFormat, | 64 kFloat32ArrayStorageFormat, |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 enum StorageFormatSource { | |
| 68 kStorageFormatFromColorSettings, | |
| 69 kStorageFormatFromBufferType, | |
| 70 }; | |
| 71 | |
| 72 constexpr const char* kUint8ClampedArrayStorageFormatName = "uint8"; | 67 constexpr const char* kUint8ClampedArrayStorageFormatName = "uint8"; |
| 73 constexpr const char* kUint16ArrayStorageFormatName = "uint16"; | 68 constexpr const char* kUint16ArrayStorageFormatName = "uint16"; |
| 74 constexpr const char* kFloat32ArrayStorageFormatName = "float32"; | 69 constexpr const char* kFloat32ArrayStorageFormatName = "float32"; |
| 75 | 70 |
| 76 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, | 71 class CORE_EXPORT ImageData final : public GarbageCollectedFinalized<ImageData>, |
| 77 public ScriptWrappable, | 72 public ScriptWrappable, |
| 78 public ImageBitmapSource { | 73 public ImageBitmapSource { |
| 79 DEFINE_WRAPPERTYPEINFO(); | 74 DEFINE_WRAPPERTYPEINFO(); |
| 80 | 75 |
| 81 public: | 76 public: |
| 82 static ImageData* create(const IntSize&); | 77 static ImageData* create(const IntSize&, |
| 83 static ImageData* create(const IntSize&, DOMUint8ClampedArray*); | 78 const ImageDataColorSettings* = nullptr); |
| 79 static ImageData* create(const IntSize&, |
| 80 DOMArrayBufferView*, |
| 81 const ImageDataColorSettings* = nullptr); |
| 84 | 82 |
| 85 static ImageData* create(unsigned width, unsigned height, ExceptionState&); | 83 static ImageData* create(unsigned width, unsigned height, ExceptionState&); |
| 86 static ImageData* create(DOMUint8ClampedArray*, | 84 static ImageData* create(DOMUint8ClampedArray*, |
| 87 unsigned width, | 85 unsigned width, |
| 88 ExceptionState&); | 86 ExceptionState&); |
| 89 static ImageData* create(DOMUint8ClampedArray*, | 87 static ImageData* create(DOMUint8ClampedArray*, |
| 90 unsigned width, | 88 unsigned width, |
| 91 unsigned height, | 89 unsigned height, |
| 92 ExceptionState&); | 90 ExceptionState&); |
| 93 | 91 |
| 94 static ImageData* createForTest(const IntSize&); | |
| 95 | |
| 96 ImageData* createImageData(unsigned width, | 92 ImageData* createImageData(unsigned width, |
| 97 unsigned height, | 93 unsigned height, |
| 98 const ImageDataColorSettings&, | 94 const ImageDataColorSettings&, |
| 99 ExceptionState&); | 95 ExceptionState&); |
| 100 ImageData* createImageData(ImageDataArray&, | 96 ImageData* createImageData(ImageDataArray&, |
| 101 unsigned width, | 97 unsigned width, |
| 102 unsigned height, | 98 unsigned height, |
| 103 const ImageDataColorSettings&, | 99 ImageDataColorSettings&, |
| 104 ExceptionState&); | 100 ExceptionState&); |
| 105 | 101 |
| 106 static ImageDataStorageFormat getImageDataStorageFormat(const String&); | 102 static ImageData* createForTest(const IntSize&); |
| 103 static ImageData* createForTest(const IntSize&, |
| 104 DOMArrayBufferView*, |
| 105 const ImageDataColorSettings* = nullptr); |
| 106 static sk_sp<SkColorSpace> getSkColorSpaceForTest(const CanvasColorSpace&, |
| 107 const CanvasPixelFormat&); |
| 108 |
| 109 static CanvasColorSpace canvasColorSpace(const String&); |
| 110 static String canvasColorSpaceName(const CanvasColorSpace&); |
| 111 static ImageDataStorageFormat imageDataStorageFormat(const String&); |
| 112 static unsigned storageFormatDataSize(const String&); |
| 113 static DOMArrayBufferView* |
| 114 convertPixelsFromCanvasPixelFormatToImageDataStorageFormat( |
| 115 WTF::ArrayBufferContents&, |
| 116 CanvasPixelFormat, |
| 117 ImageDataStorageFormat); |
| 107 | 118 |
| 108 IntSize size() const { return m_size; } | 119 IntSize size() const { return m_size; } |
| 109 int width() const { return m_size.width(); } | 120 int width() const { return m_size.width(); } |
| 110 int height() const { return m_size.height(); } | 121 int height() const { return m_size.height(); } |
| 111 | 122 |
| 112 DOMUint8ClampedArray* data(); | 123 DOMUint8ClampedArray* data(); |
| 113 const DOMUint8ClampedArray* data() const; | 124 const DOMUint8ClampedArray* data() const; |
| 114 ImageDataArray& dataUnion() { return m_dataUnion; } | 125 ImageDataArray& dataUnion() { return m_dataUnion; } |
| 115 const ImageDataArray& dataUnion() const { return m_dataUnion; } | 126 const ImageDataArray& dataUnion() const { return m_dataUnion; } |
| 116 void dataUnion(ImageDataArray& result) { result = m_dataUnion; }; | 127 void dataUnion(ImageDataArray& result) { result = m_dataUnion; }; |
| 117 const ImageDataColorSettings& colorSettings() const { | 128 const ImageDataColorSettings& colorSettings() const { |
| 118 return m_colorSettings; | 129 return m_colorSettings; |
| 119 } | 130 } |
| 120 void colorSettings(ImageDataColorSettings& result) { | 131 void colorSettings(ImageDataColorSettings& result) { |
| 121 result = m_colorSettings; | 132 result = m_colorSettings; |
| 122 }; | 133 }; |
| 123 | 134 |
| 124 sk_sp<SkColorSpace> getSkColorSpace(); | 135 sk_sp<SkColorSpace> skColorSpace(); |
| 136 bool imageDataInCanvasColorSettings(const CanvasColorSpace&, |
| 137 const CanvasPixelFormat&, |
| 138 std::unique_ptr<uint8_t[]>&); |
| 125 | 139 |
| 126 // ImageBitmapSource implementation | 140 // ImageBitmapSource implementation |
| 127 IntSize bitmapSourceSize() const override { return m_size; } | 141 IntSize bitmapSourceSize() const override { return m_size; } |
| 128 ScriptPromise createImageBitmap(ScriptState*, | 142 ScriptPromise createImageBitmap(ScriptState*, |
| 129 EventTarget&, | 143 EventTarget&, |
| 130 Optional<IntRect> cropRect, | 144 Optional<IntRect> cropRect, |
| 131 const ImageBitmapOptions&, | 145 const ImageBitmapOptions&, |
| 132 ExceptionState&) override; | 146 ExceptionState&) override; |
| 133 | 147 |
| 134 void trace(Visitor*); | 148 void trace(Visitor*); |
| 135 | 149 |
| 136 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( | 150 WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper( |
| 137 v8::Isolate*, | 151 v8::Isolate*, |
| 138 const WrapperTypeInfo*, | 152 const WrapperTypeInfo*, |
| 139 v8::Local<v8::Object> wrapper) override; | 153 v8::Local<v8::Object> wrapper) override; |
| 140 | 154 |
| 141 static bool validateConstructorArguments(const unsigned&, | 155 static bool validateConstructorArguments( |
| 142 const IntSize* = nullptr, | 156 const unsigned&, |
| 143 const unsigned& = 0, | 157 const IntSize* = nullptr, |
| 144 const unsigned& = 0, | 158 const unsigned& = 0, |
| 145 const DOMArrayBufferView* = nullptr, | 159 const unsigned& = 0, |
| 146 ExceptionState* = nullptr); | 160 const DOMArrayBufferView* = nullptr, |
| 161 const ImageDataColorSettings* = nullptr, |
| 162 ExceptionState* = nullptr); |
| 147 | 163 |
| 148 private: | 164 private: |
| 149 ImageData(const IntSize&, | 165 ImageData(const IntSize&, |
| 150 DOMArrayBufferView*, | 166 DOMArrayBufferView*, |
| 151 const ImageDataColorSettings* = nullptr, | 167 const ImageDataColorSettings* = nullptr); |
| 152 StorageFormatSource = kStorageFormatFromColorSettings); | |
| 153 | 168 |
| 154 IntSize m_size; | 169 IntSize m_size; |
| 155 ImageDataColorSettings m_colorSettings; | 170 ImageDataColorSettings m_colorSettings; |
| 156 ImageDataArray m_dataUnion; | 171 ImageDataArray m_dataUnion; |
| 157 Member<DOMUint8ClampedArray> m_data; | 172 Member<DOMUint8ClampedArray> m_data; |
| 158 Member<DOMUint16Array> m_dataU16; | 173 Member<DOMUint16Array> m_dataU16; |
| 159 Member<DOMFloat32Array> m_dataF32; | 174 Member<DOMFloat32Array> m_dataF32; |
| 160 | 175 |
| 161 static DOMArrayBufferView* allocateAndValidateDataArray( | 176 static DOMArrayBufferView* allocateAndValidateDataArray( |
| 162 const unsigned&, | 177 const unsigned&, |
| 163 ImageDataStorageFormat, | 178 ImageDataStorageFormat, |
| 164 ExceptionState* = nullptr); | 179 ExceptionState* = nullptr); |
| 180 |
| 181 static DOMUint8ClampedArray* allocateAndValidateUint8ClampedArray( |
| 182 const unsigned&, |
| 183 ExceptionState* = nullptr); |
| 184 |
| 185 static DOMUint16Array* allocateAndValidateUint16Array( |
| 186 const unsigned&, |
| 187 ExceptionState* = nullptr); |
| 188 |
| 189 static DOMFloat32Array* allocateAndValidateFloat32Array( |
| 190 const unsigned&, |
| 191 ExceptionState* = nullptr); |
| 192 |
| 193 static DOMFloat32Array* convertFloat16ArrayToFloat32Array(const uint16_t*, |
| 194 unsigned); |
| 195 |
| 196 static sk_sp<SkColorSpace> getSkColorSpace(const CanvasColorSpace&, |
| 197 const CanvasPixelFormat&); |
| 165 }; | 198 }; |
| 166 | 199 |
| 167 } // namespace blink | 200 } // namespace blink |
| 168 | 201 |
| 169 #endif // ImageData_h | 202 #endif // ImageData_h |
| OLD | NEW |