| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 ImageData* ImageData::create(const IntSize& size, | 208 ImageData* ImageData::create(const IntSize& size, |
| 209 DOMUint8ClampedArray* byteArray) { | 209 DOMUint8ClampedArray* byteArray) { |
| 210 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, | 210 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, |
| 211 0, 0, byteArray)) | 211 0, 0, byteArray)) |
| 212 return nullptr; | 212 return nullptr; |
| 213 return new ImageData(size, byteArray); | 213 return new ImageData(size, byteArray); |
| 214 } | 214 } |
| 215 | 215 |
| 216 ImageData* ImageData::create(const IntSize& size, |
| 217 DOMUint8ClampedArray* byteArray, |
| 218 const String& colorSpace) { |
| 219 if (!ImageData::validateConstructorArguments( |
| 220 kParamSize | kParamData | kParamColorSpace, &size, 0, 0, byteArray, |
| 221 &colorSpace)) |
| 222 return nullptr; |
| 223 return new ImageData(size, byteArray, colorSpace); |
| 224 } |
| 225 |
| 216 ImageData* ImageData::create(unsigned width, | 226 ImageData* ImageData::create(unsigned width, |
| 217 unsigned height, | 227 unsigned height, |
| 218 ExceptionState& exceptionState) { | 228 ExceptionState& exceptionState) { |
| 219 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, | 229 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, |
| 220 nullptr, width, height, nullptr, | 230 nullptr, width, height, nullptr, |
| 221 nullptr, &exceptionState)) | 231 nullptr, &exceptionState)) |
| 222 return nullptr; | 232 return nullptr; |
| 223 DOMUint8ClampedArray* byteArray = | 233 DOMUint8ClampedArray* byteArray = |
| 224 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, | 234 ImageData::allocateAndValidateUint8ClampedArray(4 * width * height, |
| 225 &exceptionState); | 235 &exceptionState); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 241 unsigned width, | 251 unsigned width, |
| 242 unsigned height, | 252 unsigned height, |
| 243 ExceptionState& exceptionState) { | 253 ExceptionState& exceptionState) { |
| 244 if (!ImageData::validateConstructorArguments( | 254 if (!ImageData::validateConstructorArguments( |
| 245 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, | 255 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, |
| 246 nullptr, &exceptionState)) | 256 nullptr, &exceptionState)) |
| 247 return nullptr; | 257 return nullptr; |
| 248 return new ImageData(IntSize(width, height), data); | 258 return new ImageData(IntSize(width, height), data); |
| 249 } | 259 } |
| 250 | 260 |
| 251 ImageDataColorSpace ImageData::getImageDataColorSpace(String colorSpaceName) { | |
| 252 if (colorSpaceName == kLegacyImageDataColorSpaceName) | |
| 253 return kLegacyImageDataColorSpace; | |
| 254 if (colorSpaceName == kSRGBImageDataColorSpaceName) | |
| 255 return kSRGBImageDataColorSpace; | |
| 256 if (colorSpaceName == kLinearRGBImageDataColorSpaceName) | |
| 257 return kLinearRGBImageDataColorSpace; | |
| 258 NOTREACHED(); | |
| 259 return kLegacyImageDataColorSpace; | |
| 260 } | |
| 261 | |
| 262 String ImageData::getImageDataColorSpaceName(ImageDataColorSpace colorSpace) { | |
| 263 switch (colorSpace) { | |
| 264 case kLegacyImageDataColorSpace: | |
| 265 return kLegacyImageDataColorSpaceName; | |
| 266 case kSRGBImageDataColorSpace: | |
| 267 return kSRGBImageDataColorSpaceName; | |
| 268 case kLinearRGBImageDataColorSpace: | |
| 269 return kLinearRGBImageDataColorSpaceName; | |
| 270 } | |
| 271 NOTREACHED(); | |
| 272 return String(); | |
| 273 } | |
| 274 | |
| 275 ImageData* ImageData::createImageData(unsigned width, | 261 ImageData* ImageData::createImageData(unsigned width, |
| 276 unsigned height, | 262 unsigned height, |
| 277 String colorSpace, | 263 String colorSpace, |
| 278 ExceptionState& exceptionState) { | 264 ExceptionState& exceptionState) { |
| 279 if (!ImageData::validateConstructorArguments( | 265 if (!ImageData::validateConstructorArguments( |
| 280 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, | 266 kParamWidth | kParamHeight | kParamColorSpace, nullptr, width, height, |
| 281 nullptr, &colorSpace, &exceptionState)) | 267 nullptr, &colorSpace, &exceptionState)) |
| 282 return nullptr; | 268 return nullptr; |
| 283 | 269 |
| 284 DOMUint8ClampedArray* byteArray = | 270 DOMUint8ClampedArray* byteArray = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 306 unsigned height, | 292 unsigned height, |
| 307 String colorSpace, | 293 String colorSpace, |
| 308 ExceptionState& exceptionState) { | 294 ExceptionState& exceptionState) { |
| 309 if (!ImageData::validateConstructorArguments( | 295 if (!ImageData::validateConstructorArguments( |
| 310 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, | 296 kParamData | kParamWidth | kParamHeight | kParamColorSpace, nullptr, |
| 311 width, height, data, &colorSpace, &exceptionState)) | 297 width, height, data, &colorSpace, &exceptionState)) |
| 312 return nullptr; | 298 return nullptr; |
| 313 return new ImageData(IntSize(width, height), data, colorSpace); | 299 return new ImageData(IntSize(width, height), data, colorSpace); |
| 314 } | 300 } |
| 315 | 301 |
| 316 // TODO(zakerinasab): Fix this when ImageBitmap color correction code is landed. | |
| 317 // Tip: If the source Image Data has a color space, createImageBitmap must | |
| 318 // respect this color space even when no color space tag is passed to it. | |
| 319 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, | 302 ScriptPromise ImageData::createImageBitmap(ScriptState* scriptState, |
| 320 EventTarget& eventTarget, | 303 EventTarget& eventTarget, |
| 321 Optional<IntRect> cropRect, | 304 Optional<IntRect> cropRect, |
| 322 const ImageBitmapOptions& options, | 305 const ImageBitmapOptions& options, |
| 323 ExceptionState& exceptionState) { | 306 ExceptionState& exceptionState) { |
| 324 if ((cropRect && | 307 if ((cropRect && |
| 325 !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect->height(), | 308 !ImageBitmap::isSourceSizeValid(cropRect->width(), cropRect->height(), |
| 326 exceptionState)) || | 309 exceptionState)) || |
| 327 !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), | 310 !ImageBitmap::isSourceSizeValid(bitmapSourceSize().width(), |
| 328 bitmapSourceSize().height(), | 311 bitmapSourceSize().height(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 353 v8::Local<v8::Value> pixelArray = ToV8(m_data.get(), wrapper, isolate); | 336 v8::Local<v8::Value> pixelArray = ToV8(m_data.get(), wrapper, isolate); |
| 354 if (pixelArray.IsEmpty() || | 337 if (pixelArray.IsEmpty() || |
| 355 !v8CallBoolean(wrapper->DefineOwnProperty( | 338 !v8CallBoolean(wrapper->DefineOwnProperty( |
| 356 isolate->GetCurrentContext(), v8AtomicString(isolate, "data"), | 339 isolate->GetCurrentContext(), v8AtomicString(isolate, "data"), |
| 357 pixelArray, v8::ReadOnly))) | 340 pixelArray, v8::ReadOnly))) |
| 358 return v8::Local<v8::Object>(); | 341 return v8::Local<v8::Object>(); |
| 359 } | 342 } |
| 360 return wrapper; | 343 return wrapper; |
| 361 } | 344 } |
| 362 | 345 |
| 346 ImageDataColorSpace ImageData::getImageDataColorSpace(String colorSpaceName) { |
| 347 if (colorSpaceName == kLegacyImageDataColorSpaceName) |
| 348 return kLegacyImageDataColorSpace; |
| 349 if (colorSpaceName == kSRGBImageDataColorSpaceName) |
| 350 return kSRGBImageDataColorSpace; |
| 351 if (colorSpaceName == kLinearRGBImageDataColorSpaceName) |
| 352 return kLinearRGBImageDataColorSpace; |
| 353 NOTREACHED(); |
| 354 return kLegacyImageDataColorSpace; |
| 355 } |
| 356 |
| 357 String ImageData::getImageDataColorSpaceName(ImageDataColorSpace colorSpace) { |
| 358 switch (colorSpace) { |
| 359 case kLegacyImageDataColorSpace: |
| 360 return kLegacyImageDataColorSpaceName; |
| 361 case kSRGBImageDataColorSpace: |
| 362 return kSRGBImageDataColorSpaceName; |
| 363 case kLinearRGBImageDataColorSpace: |
| 364 return kLinearRGBImageDataColorSpaceName; |
| 365 } |
| 366 NOTREACHED(); |
| 367 return String(); |
| 368 } |
| 369 |
| 370 sk_sp<SkColorSpace> ImageData::imageDataColorSpaceToSkColorSpace( |
| 371 ImageDataColorSpace colorSpace) { |
| 372 switch (colorSpace) { |
| 373 case kLegacyImageDataColorSpace: |
| 374 return ColorBehavior::globalTargetColorSpace(); |
| 375 case kSRGBImageDataColorSpace: |
| 376 return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
| 377 case kLinearRGBImageDataColorSpace: |
| 378 return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); |
| 379 } |
| 380 NOTREACHED(); |
| 381 return nullptr; |
| 382 } |
| 383 |
| 384 sk_sp<SkColorSpace> ImageData::getSkColorSpace() { |
| 385 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() || |
| 386 !RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) |
| 387 return nullptr; |
| 388 return ImageData::imageDataColorSpaceToSkColorSpace(m_colorSpace); |
| 389 } |
| 390 |
| 363 ImageData::ImageData(const IntSize& size, | 391 ImageData::ImageData(const IntSize& size, |
| 364 DOMUint8ClampedArray* byteArray, | 392 DOMUint8ClampedArray* byteArray, |
| 365 String colorSpaceName) | 393 String colorSpaceName) |
| 366 : m_size(size), | 394 : m_size(size), |
| 367 m_colorSpace(getImageDataColorSpace(colorSpaceName)), | 395 m_colorSpace(getImageDataColorSpace(colorSpaceName)), |
| 368 m_data(byteArray) { | 396 m_data(byteArray) { |
| 369 DCHECK_GE(size.width(), 0); | 397 DCHECK_GE(size.width(), 0); |
| 370 DCHECK_GE(size.height(), 0); | 398 DCHECK_GE(size.height(), 0); |
| 371 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= | 399 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= |
| 372 m_data->length()); | 400 m_data->length()); |
| 373 } | 401 } |
| 374 | 402 |
| 375 } // namespace blink | 403 } // namespace blink |
| OLD | NEW |