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

Unified Diff: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp

Issue 2596833002: Add unit test for color managed ImageBitamp::create(StaticBitmapImage) (Closed)
Patch Set: Minor corrections Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
index a4a56df96947dc41231d836a34e48e863331158e..6f54c5e19e83c894c6ace67cced25660411cf99b 100644
--- a/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
+++ b/third_party/WebKit/Source/core/frame/ImageBitmapTest.cpp
@@ -66,10 +66,7 @@ class ImageBitmapTest : public ::testing::Test {
m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
// Save the state of experimental canvas features and color correct
- // rendering flags to restore them on teardown. Each test that changes the
- // flags must restore them to prevent affecting other ImageBitmap tests.
- // This is an extra safety precaution to prevent such an error to leak from
- // this test suite.
+ // rendering flags to restore them on teardown.
experimentalCanvasFeatures =
RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled();
colorCorrectRendering =
@@ -446,4 +443,98 @@ TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionImageBitmap) {
}
}
+TEST_F(ImageBitmapTest, ImageBitmapColorSpaceConversionStaticBitmapImage) {
+ SkPaint p;
+ p.setColor(SK_ColorRED);
+ sk_sp<SkColorSpace> srcRGBColorSpace =
+ SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+
+ SkImageInfo rasterImageInfo =
+ SkImageInfo::MakeN32Premul(10, 10, srcRGBColorSpace);
+ sk_sp<SkSurface> surface(SkSurface::MakeRaster(rasterImageInfo));
+ surface->getCanvas()->drawCircle(5, 5, 5, p);
+ sk_sp<SkImage> image = surface->makeImageSnapshot();
+
+ std::unique_ptr<uint8_t[]> srcPixel(
+ new uint8_t[rasterImageInfo.bytesPerPixel()]());
+ image->readPixels(rasterImageInfo.makeWH(1, 1), srcPixel.get(),
+ image->width() * rasterImageInfo.bytesPerPixel(), 5, 5);
+
+ Optional<IntRect> cropRect = IntRect(0, 0, image->width(), image->height());
+
+ sk_sp<SkColorSpace> colorSpace = nullptr;
+ SkColorType colorType = SkColorType::kN32_SkColorType;
+ SkColorSpaceXform::ColorFormat colorFormat32 =
+ (colorType == kBGRA_8888_SkColorType)
+ ? SkColorSpaceXform::ColorFormat::kBGRA_8888_ColorFormat
+ : SkColorSpaceXform::ColorFormat::kRGBA_8888_ColorFormat;
+ SkColorSpaceXform::ColorFormat colorFormat = colorFormat32;
+
+ for (uint8_t i = static_cast<uint8_t>(
+ ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED);
+ i <= static_cast<uint8_t>(ColorSpaceConversion::LAST); i++) {
+ ColorSpaceConversion colorSpaceConversion =
+ static_cast<ColorSpaceConversion>(i);
+ ImageBitmapOptions options =
+ prepareBitmapOptionsAndSetRuntimeFlags(colorSpaceConversion);
+ ImageBitmap* imageBitmap = ImageBitmap::create(
+ StaticBitmapImage::create(image), cropRect, options);
+
+ // ColorBehavior::ignore() is used instead of
+ // ColorBehavior::transformToTargetForTesting() to avoid color conversion to
+ // display color profile, as we want to solely rely on the color correction
+ // that happens in ImageBitmap create method.
+ SkImage* convertedImage =
+ imageBitmap->bitmapImage()
+ ->imageForCurrentFrame(ColorBehavior::ignore())
+ .get();
+
+ switch (colorSpaceConversion) {
+ case ColorSpaceConversion::NONE:
+ NOTREACHED();
+ break;
+ case ColorSpaceConversion::DEFAULT_NOT_COLOR_CORRECTED:
+ // TODO(zakerinasab): Replace sRGB with a call to
+ // ImageDecoder::globalTargetColorSpace() when the crash problem on Mac
+ // is fixed. crbug.com/668546.
+ colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+ colorFormat = colorFormat32;
+ break;
+ case ColorSpaceConversion::DEFAULT_COLOR_CORRECTED:
+ case ColorSpaceConversion::SRGB:
+ colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+ colorFormat = colorFormat32;
+ break;
+ case ColorSpaceConversion::LINEAR_RGB:
+ colorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
+ colorType = SkColorType::kRGBA_F16_SkColorType;
+ colorFormat = SkColorSpaceXform::ColorFormat::kRGBA_F16_ColorFormat;
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ SkImageInfo imageInfo = SkImageInfo::Make(
+ 1, 1, colorType, SkAlphaType::kPremul_SkAlphaType, colorSpace);
+ std::unique_ptr<uint8_t[]> convertedPixel(
+ new uint8_t[imageInfo.bytesPerPixel()]());
+ convertedImage->readPixels(
+ imageInfo, convertedPixel.get(),
+ convertedImage->width() * imageInfo.bytesPerPixel(), 5, 5);
+
+ // Transform the source pixel and check if the image bitmap color conversion
+ // is done correctly.
+ std::unique_ptr<SkColorSpaceXform> colorSpaceXform =
+ SkColorSpaceXform::New(srcRGBColorSpace.get(), colorSpace.get());
+ std::unique_ptr<uint8_t[]> transformedPixel(
+ new uint8_t[imageInfo.bytesPerPixel()]());
+ colorSpaceXform->apply(colorFormat, transformedPixel.get(), colorFormat32,
+ srcPixel.get(), 1, SkAlphaType::kPremul_SkAlphaType);
+
+ int compare = std::memcmp(convertedPixel.get(), transformedPixel.get(),
+ imageInfo.bytesPerPixel());
+ ASSERT_EQ(compare, 0);
+ }
+}
+
} // namespace blink
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698