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

Side by Side Diff: third_party/WebKit/Source/core/html/Float32ImageData.cpp

Issue 2555213002: Implement color management for ImageData (Closed)
Patch Set: Fixing ImageData::validateConstructorArguments 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/html/Float32ImageData.h"
6
7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/V8Float32Array.h"
9 #include "core/dom/ExceptionCode.h"
10 #include "core/frame/ImageBitmap.h"
11 #include "core/imagebitmap/ImageBitmapOptions.h"
12 #include "platform/RuntimeEnabledFeatures.h"
13 #include "wtf/CheckedNumeric.h"
14
15 namespace blink {
16
17 bool Float32ImageData::validateConstructorArguments(
18 const unsigned& paramFlags,
19 const IntSize* size,
20 const unsigned& width,
21 const unsigned& height,
22 const DOMFloat32Array* data,
23 const String* colorSpace,
24 ExceptionState* exceptionState) {
25 return ImageData::validateConstructorArguments(
26 paramFlags, size, width, height, data, colorSpace, exceptionState,
27 kFloat32ImageData);
28 }
29
30 DOMFloat32Array* Float32ImageData::allocateAndValidateFloat32Array(
31 const unsigned& length,
32 ExceptionState* exceptionState) {
33 if (!length)
34 return nullptr;
35 DOMFloat32Array* dataArray = DOMFloat32Array::createOrNull(length);
36 if (!dataArray || length != dataArray->length()) {
37 if (exceptionState) {
38 exceptionState->throwDOMException(
39 V8RangeError, "Out of memory at Float32ImageData creation");
40 }
41 return nullptr;
42 }
43 return dataArray;
44 }
45
46 Float32ImageData* Float32ImageData::create(const IntSize& size) {
47 if (!Float32ImageData::validateConstructorArguments(kParamSize, &size))
48 return nullptr;
49 DOMFloat32Array* dataArray =
50 Float32ImageData::allocateAndValidateFloat32Array(4 * size.width() *
51 size.height());
52 return dataArray ? new Float32ImageData(size, dataArray) : nullptr;
53 }
54
55 Float32ImageData* Float32ImageData::create(const IntSize& size,
56 DOMFloat32Array* dataArray) {
57 if (!Float32ImageData::validateConstructorArguments(kParamSize | kParamData,
58 &size, 0, 0, dataArray))
59 return nullptr;
60 return new Float32ImageData(size, dataArray);
61 }
62
63 Float32ImageData* Float32ImageData::create(unsigned width,
64 unsigned height,
65 ExceptionState& exceptionState) {
66 if (!Float32ImageData::validateConstructorArguments(
67 kParamWidth | kParamHeight, nullptr, width, height, nullptr, nullptr,
68 &exceptionState))
69 return nullptr;
70 DOMFloat32Array* dataArray =
71 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height,
72 &exceptionState);
73 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray)
74 : nullptr;
75 }
76
77 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data,
78 unsigned width,
79 ExceptionState& exceptionState) {
80 if (!Float32ImageData::validateConstructorArguments(kParamData | kParamWidth,
81 nullptr, width, 0, data,
82 nullptr, &exceptionState))
83 return nullptr;
84 unsigned height = data->length() / (width * 4);
85 return new Float32ImageData(IntSize(width, height), data);
86 }
87
88 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data,
89 unsigned width,
90 unsigned height,
91 ExceptionState& exceptionState) {
92 if (!Float32ImageData::validateConstructorArguments(
93 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data,
94 nullptr, &exceptionState))
95 return nullptr;
96 return new Float32ImageData(IntSize(width, height), data);
97 }
98
99 Float32ImageData* Float32ImageData::create(unsigned width,
100 unsigned height,
101 String colorSpace,
102 ExceptionState& exceptionState) {
103 if (!Float32ImageData::validateConstructorArguments(
104 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height,
105 nullptr, &colorSpace, &exceptionState))
106 return nullptr;
107
108 DOMFloat32Array* dataArray =
109 Float32ImageData::allocateAndValidateFloat32Array(4 * width * height,
110 &exceptionState);
111 return dataArray ? new Float32ImageData(IntSize(width, height), dataArray,
112 colorSpace)
113 : nullptr;
114 }
115
116 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data,
117 unsigned width,
118 String colorSpace,
119 ExceptionState& exceptionState) {
120 if (!Float32ImageData::validateConstructorArguments(
121 kParamData | kParamWidth | kParamColorSpace, nullptr, width, 0, data,
122 &colorSpace, &exceptionState))
123 return nullptr;
124 unsigned height = data->length() / (width * 4);
125 return new Float32ImageData(IntSize(width, height), data, colorSpace);
126 }
127
128 Float32ImageData* Float32ImageData::create(DOMFloat32Array* data,
129 unsigned width,
130 unsigned height,
131 String colorSpace,
132 ExceptionState& exceptionState) {
133 if (!Float32ImageData::validateConstructorArguments(
134 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr,
135 width, height, data, &colorSpace, &exceptionState))
136 return nullptr;
137 return new Float32ImageData(IntSize(width, height), data, colorSpace);
138 }
139
140 v8::Local<v8::Object> Float32ImageData::associateWithWrapper(
141 v8::Isolate* isolate,
142 const WrapperTypeInfo* wrapperType,
143 v8::Local<v8::Object> wrapper) {
144 wrapper =
145 ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper);
146
147 if (!wrapper.IsEmpty() && m_data.get()) {
148 // Create a V8 Float32Array object and set the "data" property
149 // of the Float32ImageData object to the created v8 object, eliminating the
150 // C++ callback when accessing the "data" property.
151 v8::Local<v8::Value> pixelArray = ToV8(m_data.get(), wrapper, isolate);
152 if (pixelArray.IsEmpty() ||
153 !v8CallBoolean(wrapper->DefineOwnProperty(
154 isolate->GetCurrentContext(), v8AtomicString(isolate, "data"),
155 pixelArray, v8::ReadOnly)))
156 return v8::Local<v8::Object>();
157 }
158 return wrapper;
159 }
160
161 Float32ImageData::Float32ImageData(const IntSize& size,
162 DOMFloat32Array* dataArray,
163 String colorSpaceName)
164 : m_size(size),
165 m_colorSpace(ImageData::getImageDataColorSpace(colorSpaceName)),
166 m_data(dataArray) {
167 DCHECK_GE(size.width(), 0);
168 DCHECK_GE(size.height(), 0);
169 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <=
170 m_data->length());
171 }
172
173 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/Float32ImageData.h ('k') | third_party/WebKit/Source/core/html/Float32ImageData.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698