OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 ImageData::GetImageDataStorageFormat(color_settings->storageFormat()); | 222 ImageData::GetImageDataStorageFormat(color_settings->storageFormat()); |
223 } | 223 } |
224 DOMArrayBufferView* data_array = | 224 DOMArrayBufferView* data_array = |
225 AllocateAndValidateDataArray(4 * static_cast<unsigned>(size.Width()) * | 225 AllocateAndValidateDataArray(4 * static_cast<unsigned>(size.Width()) * |
226 static_cast<unsigned>(size.Height()), | 226 static_cast<unsigned>(size.Height()), |
227 storage_format); | 227 storage_format); |
228 return data_array ? new ImageData(size, data_array, color_settings) : nullptr; | 228 return data_array ? new ImageData(size, data_array, color_settings) : nullptr; |
229 } | 229 } |
230 | 230 |
231 ImageData* ImageData::Create(const IntSize& size, | 231 ImageData* ImageData::Create(const IntSize& size, |
232 NotShared<DOMArrayBufferView> data_array, | 232 DOMArrayBufferView* data_array, |
233 const ImageDataColorSettings* color_settings) { | 233 const ImageDataColorSettings* color_settings) { |
234 if (!ImageData::ValidateConstructorArguments(kParamSize | kParamData, &size, | 234 if (!ImageData::ValidateConstructorArguments( |
235 0, 0, data_array.View(), | 235 kParamSize | kParamData, &size, 0, 0, data_array, color_settings)) |
236 color_settings)) | |
237 return nullptr; | 236 return nullptr; |
238 return new ImageData(size, data_array.View(), color_settings); | 237 return new ImageData(size, data_array, color_settings); |
239 } | 238 } |
240 | 239 |
241 ImageData* ImageData::Create(unsigned width, | 240 ImageData* ImageData::Create(unsigned width, |
242 unsigned height, | 241 unsigned height, |
243 ExceptionState& exception_state) { | 242 ExceptionState& exception_state) { |
244 if (!ImageData::ValidateConstructorArguments(kParamWidth | kParamHeight, | 243 if (!ImageData::ValidateConstructorArguments(kParamWidth | kParamHeight, |
245 nullptr, width, height, nullptr, | 244 nullptr, width, height, nullptr, |
246 nullptr, &exception_state)) | 245 nullptr, &exception_state)) |
247 return nullptr; | 246 return nullptr; |
248 | 247 |
249 DOMArrayBufferView* byte_array = AllocateAndValidateDataArray( | 248 DOMArrayBufferView* byte_array = AllocateAndValidateDataArray( |
250 4 * width * height, kUint8ClampedArrayStorageFormat, &exception_state); | 249 4 * width * height, kUint8ClampedArrayStorageFormat, &exception_state); |
251 return byte_array ? new ImageData(IntSize(width, height), byte_array) | 250 return byte_array ? new ImageData(IntSize(width, height), byte_array) |
252 : nullptr; | 251 : nullptr; |
253 } | 252 } |
254 | 253 |
255 ImageData* ImageData::Create(NotShared<DOMUint8ClampedArray> data, | 254 ImageData* ImageData::Create(DOMUint8ClampedArray* data, |
256 unsigned width, | 255 unsigned width, |
257 ExceptionState& exception_state) { | 256 ExceptionState& exception_state) { |
258 if (!ImageData::ValidateConstructorArguments(kParamData | kParamWidth, | 257 if (!ImageData::ValidateConstructorArguments(kParamData | kParamWidth, |
259 nullptr, width, 0, data.View(), | 258 nullptr, width, 0, data, nullptr, |
260 nullptr, &exception_state)) | 259 &exception_state)) |
261 return nullptr; | 260 return nullptr; |
262 | 261 |
263 unsigned height = data.View()->length() / (width * 4); | 262 unsigned height = data->length() / (width * 4); |
264 return new ImageData(IntSize(width, height), data.View()); | 263 return new ImageData(IntSize(width, height), data); |
265 } | 264 } |
266 | 265 |
267 ImageData* ImageData::Create(NotShared<DOMUint8ClampedArray> data, | 266 ImageData* ImageData::Create(DOMUint8ClampedArray* data, |
268 unsigned width, | 267 unsigned width, |
269 unsigned height, | 268 unsigned height, |
270 ExceptionState& exception_state) { | 269 ExceptionState& exception_state) { |
271 if (!ImageData::ValidateConstructorArguments( | 270 if (!ImageData::ValidateConstructorArguments( |
272 kParamData | kParamWidth | kParamHeight, nullptr, width, height, | 271 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, |
273 data.View(), nullptr, &exception_state)) | 272 nullptr, &exception_state)) |
274 return nullptr; | 273 return nullptr; |
275 | 274 |
276 return new ImageData(IntSize(width, height), data.View()); | 275 return new ImageData(IntSize(width, height), data); |
277 } | 276 } |
278 | 277 |
279 ImageData* ImageData::createImageData( | 278 ImageData* ImageData::createImageData( |
280 unsigned width, | 279 unsigned width, |
281 unsigned height, | 280 unsigned height, |
282 const ImageDataColorSettings& color_settings, | 281 const ImageDataColorSettings& color_settings, |
283 ExceptionState& exception_state) { | 282 ExceptionState& exception_state) { |
284 if (!ImageData::ValidateConstructorArguments( | 283 if (!ImageData::ValidateConstructorArguments( |
285 kParamWidth | kParamHeight, nullptr, width, height, nullptr, | 284 kParamWidth | kParamHeight, nullptr, width, height, nullptr, |
286 &color_settings, &exception_state)) | 285 &color_settings, &exception_state)) |
(...skipping 15 matching lines...) Expand all Loading... |
302 unsigned height, | 301 unsigned height, |
303 ImageDataColorSettings& color_settings, | 302 ImageDataColorSettings& color_settings, |
304 ExceptionState& exception_state) { | 303 ExceptionState& exception_state) { |
305 DOMArrayBufferView* buffer_view = nullptr; | 304 DOMArrayBufferView* buffer_view = nullptr; |
306 // When pixels data is provided, we need to override the storage format of | 305 // When pixels data is provided, we need to override the storage format of |
307 // ImageDataColorSettings with the one that matches the data type of the | 306 // ImageDataColorSettings with the one that matches the data type of the |
308 // pixels. | 307 // pixels. |
309 String storage_format_name; | 308 String storage_format_name; |
310 | 309 |
311 if (data.isUint8ClampedArray()) { | 310 if (data.isUint8ClampedArray()) { |
312 buffer_view = data.getAsUint8ClampedArray().View(); | 311 buffer_view = data.getAsUint8ClampedArray(); |
313 storage_format_name = kUint8ClampedArrayStorageFormatName; | 312 storage_format_name = kUint8ClampedArrayStorageFormatName; |
314 } else if (data.isUint16Array()) { | 313 } else if (data.isUint16Array()) { |
315 buffer_view = data.getAsUint16Array().View(); | 314 buffer_view = data.getAsUint16Array(); |
316 storage_format_name = kUint16ArrayStorageFormatName; | 315 storage_format_name = kUint16ArrayStorageFormatName; |
317 } else if (data.isFloat32Array()) { | 316 } else if (data.isFloat32Array()) { |
318 buffer_view = data.getAsFloat32Array().View(); | 317 buffer_view = data.getAsFloat32Array(); |
319 storage_format_name = kFloat32ArrayStorageFormatName; | 318 storage_format_name = kFloat32ArrayStorageFormatName; |
320 } else { | 319 } else { |
321 NOTREACHED(); | 320 NOTREACHED(); |
322 } | 321 } |
323 | 322 |
324 if (storage_format_name != color_settings.storageFormat()) | 323 if (storage_format_name != color_settings.storageFormat()) |
325 color_settings.setStorageFormat(storage_format_name); | 324 color_settings.setStorageFormat(storage_format_name); |
326 | 325 |
327 if (!ImageData::ValidateConstructorArguments( | 326 if (!ImageData::ValidateConstructorArguments( |
328 kParamData | kParamWidth | kParamHeight, nullptr, width, height, | 327 kParamData | kParamWidth | kParamHeight, nullptr, width, height, |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 SECURITY_CHECK(static_cast<unsigned>(size.Width() * size.Height() * 4) <= | 759 SECURITY_CHECK(static_cast<unsigned>(size.Width() * size.Height() * 4) <= |
761 data_f32_->length()); | 760 data_f32_->length()); |
762 break; | 761 break; |
763 | 762 |
764 default: | 763 default: |
765 NOTREACHED(); | 764 NOTREACHED(); |
766 } | 765 } |
767 } | 766 } |
768 | 767 |
769 } // namespace blink | 768 } // namespace blink |
OLD | NEW |