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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return nullptr; | 198 return nullptr; |
199 | 199 |
200 DOMUint8ClampedArray* byteArray = | 200 DOMUint8ClampedArray* byteArray = |
201 DOMUint8ClampedArray::createOrNull(dataSize.ValueOrDie()); | 201 DOMUint8ClampedArray::createOrNull(dataSize.ValueOrDie()); |
202 if (!byteArray) | 202 if (!byteArray) |
203 return nullptr; | 203 return nullptr; |
204 | 204 |
205 return new ImageData(size, byteArray); | 205 return new ImageData(size, byteArray); |
206 } | 206 } |
207 | 207 |
208 ImageData* ImageData::create(const IntSize& size, | 208 ImageData* ImageData::create( |
209 DOMUint8ClampedArray* byteArray) { | 209 const IntSize& size, |
| 210 const MaybeShared<DOMUint8ClampedArray>& maybeShared) { |
| 211 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 212 return nullptr; |
| 213 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
210 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, | 214 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, |
211 0, 0, byteArray)) | 215 0, 0, data)) |
212 return nullptr; | 216 return nullptr; |
213 return new ImageData(size, byteArray); | 217 return new ImageData(size, data); |
214 } | 218 } |
215 | 219 |
216 ImageData* ImageData::create(const IntSize& size, | 220 ImageData* ImageData::create( |
217 DOMUint8ClampedArray* byteArray, | 221 const IntSize& size, |
218 const String& colorSpace) { | 222 const MaybeShared<DOMUint8ClampedArray>& maybeShared, |
| 223 const String& colorSpace) { |
| 224 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, nullptr)) |
| 225 return nullptr; |
| 226 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
219 if (!ImageData::validateConstructorArguments( | 227 if (!ImageData::validateConstructorArguments( |
220 kParamSize | kParamData | kParamColorSpace, &size, 0, 0, byteArray, | 228 kParamSize | kParamData | kParamColorSpace, &size, 0, 0, data, |
221 &colorSpace)) | 229 &colorSpace)) |
222 return nullptr; | 230 return nullptr; |
223 return new ImageData(size, byteArray, colorSpace); | 231 return new ImageData(size, data, colorSpace); |
224 } | 232 } |
225 | 233 |
226 ImageData* ImageData::create(unsigned width, | 234 ImageData* ImageData::create(unsigned width, |
227 unsigned height, | 235 unsigned height, |
228 ExceptionState& exceptionState) { | 236 ExceptionState& exceptionState) { |
229 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, | 237 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, |
230 nullptr, width, height, nullptr, | 238 nullptr, width, height, nullptr, |
231 nullptr, &exceptionState)) | 239 nullptr, &exceptionState)) |
232 return nullptr; | 240 return nullptr; |
233 DOMUint8ClampedArray* byteArray = | 241 DOMUint8ClampedArray* byteArray = |
234 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, | 242 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, |
235 &exceptionState); | 243 &exceptionState); |
236 return byteArray ? new ImageData(IntSize(width, height), byteArray) : nullptr; | 244 return byteArray ? new ImageData(IntSize(width, height), byteArray) : nullptr; |
237 } | 245 } |
238 | 246 |
239 ImageData* ImageData::create(DOMUint8ClampedArray* data, | 247 ImageData* ImageData::create( |
240 unsigned width, | 248 const MaybeShared<DOMUint8ClampedArray>& maybeShared, |
241 ExceptionState& exceptionState) { | 249 unsigned width, |
| 250 ExceptionState& exceptionState) { |
| 251 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, &exceptionState)) |
| 252 return nullptr; |
| 253 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
242 if (!ImageData::validateConstructorArguments(kParamData | kParamWidth, | 254 if (!ImageData::validateConstructorArguments(kParamData | kParamWidth, |
243 nullptr, width, 0, data, nullptr, | 255 nullptr, width, 0, data, nullptr, |
244 &exceptionState)) | 256 &exceptionState)) |
245 return nullptr; | 257 return nullptr; |
246 unsigned height = data->length() / (width * 4); | 258 unsigned height = data->length() / (width * 4); |
247 return new ImageData(IntSize(width, height), data); | 259 return new ImageData(IntSize(width, height), data); |
248 } | 260 } |
249 | 261 |
250 ImageData* ImageData::create(DOMUint8ClampedArray* data, | 262 ImageData* ImageData::create( |
251 unsigned width, | 263 const MaybeShared<DOMUint8ClampedArray>& maybeShared, |
252 unsigned height, | 264 unsigned width, |
253 ExceptionState& exceptionState) { | 265 unsigned height, |
| 266 ExceptionState& exceptionState) { |
| 267 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, &exceptionState)) |
| 268 return nullptr; |
| 269 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
254 if (!ImageData::validateConstructorArguments( | 270 if (!ImageData::validateConstructorArguments( |
255 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, | 271 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, |
256 nullptr, &exceptionState)) | 272 nullptr, &exceptionState)) |
257 return nullptr; | 273 return nullptr; |
258 return new ImageData(IntSize(width, height), data); | 274 return new ImageData(IntSize(width, height), data); |
259 } | 275 } |
260 | 276 |
261 ImageData* ImageData::createImageData(unsigned width, | 277 ImageData* ImageData::createImageData(unsigned width, |
262 unsigned height, | 278 unsigned height, |
263 String colorSpace, | 279 String colorSpace, |
264 ExceptionState& exceptionState) { | 280 ExceptionState& exceptionState) { |
265 if (!ImageData::validateConstructorArguments( | 281 if (!ImageData::validateConstructorArguments( |
266 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, | 282 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, |
267 nullptr, &colorSpace, &exceptionState)) | 283 nullptr, &colorSpace, &exceptionState)) |
268 return nullptr; | 284 return nullptr; |
269 | 285 |
270 DOMUint8ClampedArray* byteArray = | 286 DOMUint8ClampedArray* byteArray = |
271 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, | 287 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, |
272 &exceptionState); | 288 &exceptionState); |
273 return byteArray | 289 return byteArray |
274 ? new ImageData(IntSize(width, height), byteArray, colorSpace) | 290 ? new ImageData(IntSize(width, height), byteArray, colorSpace) |
275 : nullptr; | 291 : nullptr; |
276 } | 292 } |
277 | 293 |
278 ImageData* ImageData::createImageData(DOMUint8ClampedArray* data, | 294 ImageData* ImageData::createImageData( |
279 unsigned width, | 295 const MaybeShared<DOMUint8ClampedArray>& maybeShared, |
280 String colorSpace, | 296 unsigned width, |
281 ExceptionState& exceptionState) { | 297 String colorSpace, |
| 298 ExceptionState& exceptionState) { |
| 299 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, &exceptionState)) |
| 300 return nullptr; |
| 301 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
282 if (!ImageData::validateConstructorArguments( | 302 if (!ImageData::validateConstructorArguments( |
283 kParamData | kParamWidth | kParamColorSpace, nullptr, width, 0, data, | 303 kParamData | kParamWidth | kParamColorSpace, nullptr, width, 0, data, |
284 &colorSpace, &exceptionState)) | 304 &colorSpace, &exceptionState)) |
285 return nullptr; | 305 return nullptr; |
286 unsigned height = data->length() / (width * 4); | 306 unsigned height = data->length() / (width * 4); |
287 return new ImageData(IntSize(width, height), data, colorSpace); | 307 return new ImageData(IntSize(width, height), data, colorSpace); |
288 } | 308 } |
289 | 309 |
290 ImageData* ImageData::createImageData(DOMUint8ClampedArray* data, | 310 ImageData* ImageData::createImageData( |
291 unsigned width, | 311 const MaybeShared<DOMUint8ClampedArray>& maybeShared, |
292 unsigned height, | 312 unsigned width, |
293 String colorSpace, | 313 unsigned height, |
294 ExceptionState& exceptionState) { | 314 String colorSpace, |
| 315 ExceptionState& exceptionState) { |
| 316 if (!ImageData::validateDataArgumentIsNotShared(maybeShared, &exceptionState)) |
| 317 return nullptr; |
| 318 DOMUint8ClampedArray* data = maybeShared.viewNotShared(); |
295 if (!ImageData::validateConstructorArguments( | 319 if (!ImageData::validateConstructorArguments( |
296 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, | 320 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, |
297 width, height, data, &colorSpace, &exceptionState)) | 321 width, height, data, &colorSpace, &exceptionState)) |
298 return nullptr; | 322 return nullptr; |
299 return new ImageData(IntSize(width, height), data, colorSpace); | 323 return new ImageData(IntSize(width, height), data, colorSpace); |
300 } | 324 } |
301 | 325 |
302 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, | 326 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, |
303 EventTarget& eventTarget, | 327 EventTarget& eventTarget, |
304 Optional<IntRect> cropRect, | 328 Optional<IntRect> cropRect, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 : m_size(size), | 418 : m_size(size), |
395 m_colorSpace(getImageDataColorSpace(colorSpaceName)), | 419 m_colorSpace(getImageDataColorSpace(colorSpaceName)), |
396 m_data(byteArray) { | 420 m_data(byteArray) { |
397 DCHECK_GE(size.width(), 0); | 421 DCHECK_GE(size.width(), 0); |
398 DCHECK_GE(size.height(), 0); | 422 DCHECK_GE(size.height(), 0); |
399 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= | 423 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= |
400 m_data->length()); | 424 m_data->length()); |
401 } | 425 } |
402 | 426 |
403 } // namespace blink | 427 } // namespace blink |
OLD | NEW |