OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/frame/ImageBitmap.h" | 31 #include "core/frame/ImageBitmap.h" |
32 | 32 |
33 #include "SkPixelRef.h" // FIXME: qualify this skia header file. | 33 #include "SkPixelRef.h" // FIXME: qualify this skia header file. |
34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
35 #include "core/fetch/MemoryCache.h" | 35 #include "core/fetch/MemoryCache.h" |
36 #include "core/frame/FrameView.h" | |
36 #include "core/html/HTMLCanvasElement.h" | 37 #include "core/html/HTMLCanvasElement.h" |
37 #include "core/html/HTMLImageElement.h" | 38 #include "core/html/HTMLImageElement.h" |
38 #include "core/html/HTMLVideoElement.h" | 39 #include "core/html/HTMLVideoElement.h" |
39 #include "core/loader/resource/ImageResourceContent.h" | 40 #include "core/loader/resource/ImageResourceContent.h" |
40 #include "platform/graphics/StaticBitmapImage.h" | 41 #include "platform/graphics/StaticBitmapImage.h" |
41 #include "platform/graphics/skia/SkiaUtils.h" | 42 #include "platform/graphics/skia/SkiaUtils.h" |
42 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
43 #include "platform/image-decoders/ImageDecoder.h" | 44 #include "platform/image-decoders/ImageDecoder.h" |
44 #include "platform/network/ResourceRequest.h" | 45 #include "platform/network/ResourceRequest.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 enum class ColorSpaceConversion : uint8_t { | 208 enum class ColorSpaceConversion : uint8_t { |
208 NONE = 0, | 209 NONE = 0, |
209 DEFAULT_NOT_COLOR_CORRECTED = 1, | 210 DEFAULT_NOT_COLOR_CORRECTED = 1, |
210 DEFAULT_COLOR_CORRECTED = 2, | 211 DEFAULT_COLOR_CORRECTED = 2, |
211 SRGB = 3, | 212 SRGB = 3, |
212 LINEAR_RGB = 4, | 213 LINEAR_RGB = 4, |
213 | 214 |
214 LAST = LINEAR_RGB | 215 LAST = LINEAR_RGB |
215 }; | 216 }; |
216 | 217 |
217 static ImageBitmap* createImageBitmapWithColorSpaceConversion( | 218 static ImageBitmapOptions prepareBitmapOptionsAndSetRuntimeFlags( |
218 HTMLImageElement* image, | |
219 Optional<IntRect>& cropRect, | |
220 Document* document, | |
221 const ColorSpaceConversion& colorSpaceConversion) { | 219 const ColorSpaceConversion& colorSpaceConversion) { |
222 // Set the color space conversion in ImageBitmapOptions | 220 // Set the color space conversion in ImageBitmapOptions |
223 ImageBitmapOptions options; | 221 ImageBitmapOptions options; |
224 static const Vector<String> conversions = {"none", "default", "default", | 222 static const Vector<String> conversions = {"none", "default", "default", |
225 "srgb", "linear-rgb"}; | 223 "srgb", "linear-rgb"}; |
226 options.setColorSpaceConversion( | 224 options.setColorSpaceConversion( |
227 conversions[static_cast<uint8_t>(colorSpaceConversion)]); | 225 conversions[static_cast<uint8_t>(colorSpaceConversion)]); |
228 | 226 |
229 // Set the runtime flags | 227 // Set the runtime flags |
230 bool flag = (colorSpaceConversion != | 228 bool flag = (colorSpaceConversion != |
231 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); | 229 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); |
232 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true); | 230 RuntimeEnabledFeatures::setExperimentalCanvasFeaturesEnabled(true); |
233 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag); | 231 RuntimeEnabledFeatures::setColorCorrectRenderingEnabled(flag); |
234 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(!flag); | 232 RuntimeEnabledFeatures::setColorCorrectRenderingDefaultModeEnabled(!flag); |
Justin Novosad
2016/12/14 20:53:46
Need to reset flags when done.
zakerinasab1
2016/12/16 20:25:35
Fixed to store and reset the state of the flags at
| |
235 | 233 |
236 // Create and return the ImageBitmap | 234 return options; |
237 return ImageBitmap::create(image, cropRect, &(image->document()), options); | |
238 } | 235 } |
239 | 236 |
240 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversion) { | 237 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionHTMLImageElement) { |
241 HTMLImageElement* imageElement = | 238 HTMLImageElement* imageElement = |
242 HTMLImageElement::create(*Document::create()); | 239 HTMLImageElement::create(*Document::create()); |
243 | 240 |
244 SkPaint p; | 241 SkPaint p; |
245 p.setColor(SK_ColorRED); | 242 p.setColor(SK_ColorRED); |
246 sk_sp<SkColorSpace> srcRGBColorSpace = | 243 sk_sp<SkColorSpace> srcRGBColorSpace = |
247 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | 244 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
248 | 245 |
249 SkImageInfo rasterImageInfo = | 246 SkImageInfo rasterImageInfo = |
250 SkImageInfo::MakeN32Premul(100, 100, srcRGBColorSpace); | 247 SkImageInfo::MakeN32Premul(10, 10, srcRGBColorSpace); |
251 sk_sp<SkSurface> surface(SkSurface::MakeRaster(rasterImageInfo)); | 248 sk_sp<SkSurface> surface(SkSurface::MakeRaster(rasterImageInfo)); |
252 surface->getCanvas()->drawCircle(50, 50, 50, p); | 249 surface->getCanvas()->drawCircle(5, 5, 5, p); |
253 sk_sp<SkImage> image = surface->makeImageSnapshot(); | 250 sk_sp<SkImage> image = surface->makeImageSnapshot(); |
254 | 251 |
255 std::unique_ptr<uint8_t[]> srcPixel( | 252 std::unique_ptr<uint8_t[]> srcPixel( |
256 new uint8_t[rasterImageInfo.bytesPerPixel()]()); | 253 new uint8_t[rasterImageInfo.bytesPerPixel()]()); |
257 image->readPixels(rasterImageInfo.makeWH(1, 1), srcPixel.get(), | 254 image->readPixels(rasterImageInfo.makeWH(1, 1), srcPixel.get(), |
258 image->width() * rasterImageInfo.bytesPerPixel(), 50, 50); | 255 image->width() * rasterImageInfo.bytesPerPixel(), 5, 5); |
259 | 256 |
260 ImageResourceContent* originalImageResource = | 257 ImageResourceContent* originalImageResource = |
261 ImageResourceContent::create(StaticBitmapImage::create(image).get()); | 258 ImageResourceContent::create(StaticBitmapImage::create(image).get()); |
262 imageElement->setImageResource(originalImageResource); | 259 imageElement->setImageResource(originalImageResource); |
263 | 260 |
264 Optional<IntRect> cropRect = IntRect(0, 0, image->width(), image->height()); | 261 Optional<IntRect> cropRect = IntRect(0, 0, image->width(), image->height()); |
265 | 262 |
266 // Create and test the ImageBitmap objects. | 263 // Create and test the ImageBitmap objects. |
267 // We don't check "none" color space conversion as it requires the encoded | 264 // We don't check "none" color space conversion as it requires the encoded |
268 // data in a format readable by ImageDecoder. Furthermore, the code path for | 265 // data in a format readable by ImageDecoder. Furthermore, the code path for |
269 // "none" color space conversion is not affected by this CL. | 266 // "none" color space conversion is not affected by this CL. |
270 | 267 |
271 sk_sp<SkColorSpace> colorSpace = nullptr; | 268 sk_sp<SkColorSpace> colorSpace = nullptr; |
272 SkColorType colorType = SkColorType::kN32_SkColorType; | 269 SkColorType colorType = SkColorType::kN32_SkColorType; |
273 SkColorSpaceXform::ColorFormat colorFormat32 = | 270 SkColorSpaceXform::ColorFormat colorFormat32 = |
274 (colorType == kBGRA_8888_SkColorType) | 271 (colorType == kBGRA_8888_SkColorType) |
275 ? SkColorSpaceXform::ColorFormat::kBGRA_8888_ColorFormat | 272 ? SkColorSpaceXform::ColorFormat::kBGRA_8888_ColorFormat |
276 : SkColorSpaceXform::ColorFormat::kRGBA_8888_ColorFormat; | 273 : SkColorSpaceXform::ColorFormat::kRGBA_8888_ColorFormat; |
277 SkColorSpaceXform::ColorFormat colorFormat = colorFormat32; | 274 SkColorSpaceXform::ColorFormat colorFormat = colorFormat32; |
278 | 275 |
279 for (uint8_t i = static_cast<uint8_t>( | 276 for (uint8_t i = static_cast<uint8_t>( |
280 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); | 277 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); |
281 i <= static_cast<uint8_t>(ColorSpaceConversion::LAST); i++) { | 278 i <= static_cast<uint8_t>(ColorSpaceConversion::LAST); i++) { |
282 ColorSpaceConversion colorSpaceConversion = | 279 ColorSpaceConversion colorSpaceConversion = |
283 static_cast<ColorSpaceConversion>(i); | 280 static_cast<ColorSpaceConversion>(i); |
284 ImageBitmap* imageBitmap = createImageBitmapWithColorSpaceConversion( | 281 ImageBitmapOptions options = |
285 imageElement, cropRect, &(imageElement->document()), | 282 prepareBitmapOptionsAndSetRuntimeFlags(colorSpaceConversion); |
286 colorSpaceConversion); | 283 ImageBitmap* imageBitmap = ImageBitmap::create( |
284 imageElement, cropRect, &(imageElement->document()), options); | |
285 | |
287 SkImage* convertedImage = | 286 SkImage* convertedImage = |
288 imageBitmap->bitmapImage() | 287 imageBitmap->bitmapImage() |
289 ->imageForCurrentFrame(ColorBehavior::ignore()) | 288 ->imageForCurrentFrame(ColorBehavior::ignore()) |
Justin Novosad
2016/12/14 20:53:46
Add a comment to explain why the "ignore" is impor
zakerinasab1
2016/12/16 20:25:35
Done.
| |
289 .get(); | |
290 | |
291 switch (colorSpaceConversion) { | |
292 case ColorSpaceConversion::NONE: | |
293 NOTREACHED(); | |
294 break; | |
295 case ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED: | |
296 // TODO(zakerinasab): Replace sRGB with a call to | |
297 // ImageDecoder::globalTargetColorSpace() when the crash problem on Mac | |
298 // is fixed. crbug.com/668546. | |
299 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
300 colorFormat = colorFormat32; | |
301 break; | |
302 case ColorSpaceConversion::DEFAULT_COLOR_CORRECTED: | |
303 case ColorSpaceConversion::SRGB: | |
304 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
305 colorFormat = colorFormat32; | |
306 break; | |
307 case ColorSpaceConversion::LINEAR_RGB: | |
308 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); | |
309 colorType = SkColorType::kRGBA_F16_SkColorType; | |
310 colorFormat = SkColorSpaceXform::ColorFormat::kRGBA_F16_ColorFormat; | |
311 break; | |
312 default: | |
313 NOTREACHED(); | |
314 } | |
315 | |
316 SkImageInfo imageInfo = SkImageInfo::Make( | |
317 1, 1, colorType, SkAlphaType::kPremul_SkAlphaType, colorSpace); | |
318 std::unique_ptr<uint8_t[]> convertedPixel( | |
319 new uint8_t[imageInfo.bytesPerPixel()]()); | |
320 convertedImage->readPixels( | |
321 imageInfo, convertedPixel.get(), | |
322 convertedImage->width() * imageInfo.bytesPerPixel(), 5, 5); | |
323 | |
324 // Transform the source pixel and check if the image bitmap color conversion | |
325 // is done correctly. | |
326 std::unique_ptr<SkColorSpaceXform> colorSpaceXform = | |
327 SkColorSpaceXform::New(srcRGBColorSpace.get(), colorSpace.get()); | |
328 std::unique_ptr<uint8_t[]> transformedPixel( | |
329 new uint8_t[imageInfo.bytesPerPixel()]()); | |
330 colorSpaceXform->apply(colorFormat, transformedPixel.get(), colorFormat32, | |
331 srcPixel.get(), 1, SkAlphaType::kPremul_SkAlphaType); | |
332 | |
333 int compare = std::memcmp(convertedPixel.get(), transformedPixel.get(), | |
334 imageInfo.bytesPerPixel()); | |
335 ASSERT_EQ(compare, 0); | |
336 } | |
337 } | |
338 | |
339 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionImageBitmap) { | |
340 HTMLImageElement* imageElement = | |
341 HTMLImageElement::create(*Document::create()); | |
342 | |
343 SkPaint p; | |
344 p.setColor(SK_ColorRED); | |
345 sk_sp<SkColorSpace> srcRGBColorSpace = | |
346 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
347 | |
348 SkImageInfo rasterImageInfo = | |
349 SkImageInfo::MakeN32Premul(10, 10, srcRGBColorSpace); | |
350 sk_sp<SkSurface> surface(SkSurface::MakeRaster(rasterImageInfo)); | |
351 surface->getCanvas()->drawCircle(5, 5, 5, p); | |
352 sk_sp<SkImage> image = surface->makeImageSnapshot(); | |
353 | |
354 std::unique_ptr<uint8_t[]> srcPixel( | |
355 new uint8_t[rasterImageInfo.bytesPerPixel()]()); | |
356 image->readPixels(rasterImageInfo.makeWH(1, 1), srcPixel.get(), | |
357 image->width() * rasterImageInfo.bytesPerPixel(), 5, 5); | |
358 | |
359 ImageResourceContent* sourceImageResource = | |
360 ImageResourceContent::create(StaticBitmapImage::create(image).get()); | |
361 imageElement->setImageResource(sourceImageResource); | |
362 | |
363 Optional<IntRect> cropRect = IntRect(0, 0, image->width(), image->height()); | |
364 ImageBitmapOptions options = | |
365 prepareBitmapOptionsAndSetRuntimeFlags(ColorSpaceConversion::SRGB); | |
366 ImageBitmap* sourceImageBitmap = ImageBitmap::create( | |
367 imageElement, cropRect, &(imageElement->document()), options); | |
368 | |
369 sk_sp<SkColorSpace> colorSpace = nullptr; | |
370 SkColorType colorType = SkColorType::kN32_SkColorType; | |
371 SkColorSpaceXform::ColorFormat colorFormat32 = | |
372 (colorType == kBGRA_8888_SkColorType) | |
373 ? SkColorSpaceXform::ColorFormat::kBGRA_8888_ColorFormat | |
374 : SkColorSpaceXform::ColorFormat::kRGBA_8888_ColorFormat; | |
375 SkColorSpaceXform::ColorFormat colorFormat = colorFormat32; | |
376 | |
377 for (uint8_t i = static_cast<uint8_t>( | |
378 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); | |
379 i <= static_cast<uint8_t>(ColorSpaceConversion::LAST); i++) { | |
380 ColorSpaceConversion colorSpaceConversion = | |
381 static_cast<ColorSpaceConversion>(i); | |
382 options = prepareBitmapOptionsAndSetRuntimeFlags(colorSpaceConversion); | |
383 ImageBitmap* imageBitmap = | |
384 ImageBitmap::create(sourceImageBitmap, cropRect, options); | |
385 SkImage* convertedImage = | |
386 imageBitmap->bitmapImage() | |
387 ->imageForCurrentFrame(ColorBehavior::ignore()) | |
388 .get(); | |
389 | |
390 switch (colorSpaceConversion) { | |
391 case ColorSpaceConversion::NONE: | |
392 NOTREACHED(); | |
393 break; | |
394 case ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED: | |
395 // TODO(zakerinasab): Replace sRGB with a call to | |
396 // ImageDecoder::globalTargetColorSpace() when the crash problem on Mac | |
397 // is fixed. crbug.com/668546. | |
398 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
399 colorFormat = colorFormat32; | |
400 break; | |
401 case ColorSpaceConversion::DEFAULT_COLOR_CORRECTED: | |
402 case ColorSpaceConversion::SRGB: | |
403 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
404 colorFormat = colorFormat32; | |
405 break; | |
406 case ColorSpaceConversion::LINEAR_RGB: | |
407 colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); | |
408 colorType = SkColorType::kRGBA_F16_SkColorType; | |
409 colorFormat = SkColorSpaceXform::ColorFormat::kRGBA_F16_ColorFormat; | |
410 break; | |
411 default: | |
412 NOTREACHED(); | |
413 } | |
414 | |
415 SkImageInfo imageInfo = SkImageInfo::Make( | |
416 1, 1, colorType, SkAlphaType::kPremul_SkAlphaType, colorSpace); | |
417 std::unique_ptr<uint8_t[]> convertedPixel( | |
418 new uint8_t[imageInfo.bytesPerPixel()]()); | |
419 convertedImage->readPixels( | |
420 imageInfo, convertedPixel.get(), | |
421 convertedImage->width() * imageInfo.bytesPerPixel(), 5, 5); | |
422 | |
423 // Transform the source pixel and check if the image bitmap color conversion | |
424 // is done correctly. | |
425 std::unique_ptr<SkColorSpaceXform> colorSpaceXform = | |
426 SkColorSpaceXform::New(srcRGBColorSpace.get(), colorSpace.get()); | |
427 std::unique_ptr<uint8_t[]> transformedPixel( | |
428 new uint8_t[imageInfo.bytesPerPixel()]()); | |
429 colorSpaceXform->apply(colorFormat, transformedPixel.get(), colorFormat32, | |
430 srcPixel.get(), 1, SkAlphaType::kPremul_SkAlphaType); | |
431 | |
432 int compare = std::memcmp(convertedPixel.get(), transformedPixel.get(), | |
433 imageInfo.bytesPerPixel()); | |
434 ASSERT_EQ(compare, 0); | |
435 } | |
436 } | |
437 | |
438 TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionStaticBitmapImage) { | |
439 SkPaint p; | |
440 p.setColor(SK_ColorRED); | |
441 sk_sp<SkColorSpace> srcRGBColorSpace = | |
442 SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); | |
443 | |
444 SkImageInfo rasterImageInfo = | |
445 SkImageInfo::MakeN32Premul(10, 10, srcRGBColorSpace); | |
446 sk_sp<SkSurface> surface(SkSurface::MakeRaster(rasterImageInfo)); | |
447 surface->getCanvas()->drawCircle(5, 5, 5, p); | |
448 sk_sp<SkImage> image = surface->makeImageSnapshot(); | |
449 | |
450 std::unique_ptr<uint8_t[]> srcPixel( | |
451 new uint8_t[rasterImageInfo.bytesPerPixel()]()); | |
452 image->readPixels(rasterImageInfo.makeWH(1, 1), srcPixel.get(), | |
453 image->width() * rasterImageInfo.bytesPerPixel(), 5, 5); | |
454 | |
455 Optional<IntRect> cropRect = IntRect(0, 0, image->width(), image->height()); | |
456 | |
457 sk_sp<SkColorSpace> colorSpace = nullptr; | |
458 SkColorType colorType = SkColorType::kN32_SkColorType; | |
459 SkColorSpaceXform::ColorFormat colorFormat32 = | |
460 (colorType == kBGRA_8888_SkColorType) | |
461 ? SkColorSpaceXform::ColorFormat::kBGRA_8888_ColorFormat | |
462 : SkColorSpaceXform::ColorFormat::kRGBA_8888_ColorFormat; | |
463 SkColorSpaceXform::ColorFormat colorFormat = colorFormat32; | |
464 | |
465 for (uint8_t i = static_cast<uint8_t>( | |
466 ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED); | |
467 i <= static_cast<uint8_t>(ColorSpaceConversion::LAST); i++) { | |
468 ColorSpaceConversion colorSpaceConversion = | |
469 static_cast<ColorSpaceConversion>(i); | |
470 ImageBitmapOptions options = | |
471 prepareBitmapOptionsAndSetRuntimeFlags(colorSpaceConversion); | |
472 ImageBitmap* imageBitmap = ImageBitmap::create( | |
473 StaticBitmapImage::create(image), cropRect, options); | |
474 SkImage* convertedImage = | |
475 imageBitmap->bitmapImage() | |
476 ->imageForCurrentFrame(ColorBehavior::ignore()) | |
290 .get(); | 477 .get(); |
291 | 478 |
292 switch (colorSpaceConversion) { | 479 switch (colorSpaceConversion) { |
293 case ColorSpaceConversion::NONE: | 480 case ColorSpaceConversion::NONE: |
294 NOTREACHED(); | 481 NOTREACHED(); |
295 break; | 482 break; |
296 case ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED: | 483 case ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED: |
297 // TODO(zakerinasab): Replace sRGB with a call to | 484 // TODO(zakerinasab): Replace sRGB with a call to |
298 // ImageDecoder::globalTargetColorSpace() when the crash problem on Mac | 485 // ImageDecoder::globalTargetColorSpace() when the crash problem on Mac |
299 // is fixed. crbug.com/668546. | 486 // is fixed. crbug.com/668546. |
(...skipping 13 matching lines...) Expand all Loading... | |
313 default: | 500 default: |
314 NOTREACHED(); | 501 NOTREACHED(); |
315 } | 502 } |
316 | 503 |
317 SkImageInfo imageInfo = SkImageInfo::Make( | 504 SkImageInfo imageInfo = SkImageInfo::Make( |
318 1, 1, colorType, SkAlphaType::kPremul_SkAlphaType, colorSpace); | 505 1, 1, colorType, SkAlphaType::kPremul_SkAlphaType, colorSpace); |
319 std::unique_ptr<uint8_t[]> convertedPixel( | 506 std::unique_ptr<uint8_t[]> convertedPixel( |
320 new uint8_t[imageInfo.bytesPerPixel()]()); | 507 new uint8_t[imageInfo.bytesPerPixel()]()); |
321 convertedImage->readPixels( | 508 convertedImage->readPixels( |
322 imageInfo, convertedPixel.get(), | 509 imageInfo, convertedPixel.get(), |
323 convertedImage->width() * imageInfo.bytesPerPixel(), 50, 50); | 510 convertedImage->width() * imageInfo.bytesPerPixel(), 5, 5); |
324 | 511 |
325 // Transform the source pixel and check if the image bitmap color conversion | 512 // Transform the source pixel and check if the image bitmap color conversion |
326 // is done correctly. | 513 // is done correctly. |
327 std::unique_ptr<SkColorSpaceXform> colorSpaceXform = | 514 std::unique_ptr<SkColorSpaceXform> colorSpaceXform = |
328 SkColorSpaceXform::New(srcRGBColorSpace.get(), colorSpace.get()); | 515 SkColorSpaceXform::New(srcRGBColorSpace.get(), colorSpace.get()); |
329 std::unique_ptr<uint8_t[]> transformedPixel( | 516 std::unique_ptr<uint8_t[]> transformedPixel( |
330 new uint8_t[imageInfo.bytesPerPixel()]()); | 517 new uint8_t[imageInfo.bytesPerPixel()]()); |
331 colorSpaceXform->apply(colorFormat, transformedPixel.get(), colorFormat32, | 518 colorSpaceXform->apply(colorFormat, transformedPixel.get(), colorFormat32, |
332 srcPixel.get(), 1, SkAlphaType::kPremul_SkAlphaType); | 519 srcPixel.get(), 1, SkAlphaType::kPremul_SkAlphaType); |
333 | 520 |
334 int compare = std::memcmp(convertedPixel.get(), transformedPixel.get(), | 521 int compare = std::memcmp(convertedPixel.get(), transformedPixel.get(), |
335 imageInfo.bytesPerPixel()); | 522 imageInfo.bytesPerPixel()); |
336 ASSERT_EQ(compare, 0); | 523 ASSERT_EQ(compare, 0); |
337 } | 524 } |
338 } | 525 } |
339 | 526 |
340 } // namespace blink | 527 } // namespace blink |
OLD | NEW |