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