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

Unified Diff: ui/gfx/codec/png_codec_unittest.cc

Issue 136453009: Fix for Issue 331895: Make gesturenav screenshot greyscale (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing a failing assert Created 6 years, 11 months 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
« ui/gfx/codec/png_codec.cc ('K') | « ui/gfx/codec/png_codec.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/codec/png_codec_unittest.cc
diff --git a/ui/gfx/codec/png_codec_unittest.cc b/ui/gfx/codec/png_codec_unittest.cc
index f1654d9d363bfbf15a5594c6ea3cfa9b66067a2e..f332173d6f9458ce37cd944adc039e6bab7c3c32 100644
--- a/ui/gfx/codec/png_codec_unittest.cc
+++ b/ui/gfx/codec/png_codec_unittest.cc
@@ -249,7 +249,15 @@ bool NonAlphaColorsClose(uint32_t a, uint32_t b) {
abs(static_cast<int>(SkColorGetR(a) - SkColorGetR(b))) < 2;
}
-void MakeTestSkBitmap(int w, int h, SkBitmap* bmp) {
+// Returns true if the BGRA 4-bit SkColor is "close" to the Gray 8-bit SkColor.
Peter Kasting 2014/02/04 01:37:15 Nit: Don't you mean 32-bit (or 4-byte)?
+bool BGRAGrayColorsClose(uint32_t a, uint8_t b) {
+ return abs(static_cast<int>(SkColorGetB(a) - b)) < 2 &&
+ abs(static_cast<int>(SkColorGetG(a) - b)) < 2 &&
+ abs(static_cast<int>(SkColorGetR(a) - b)) < 2 &&
+ abs(static_cast<int>(SkColorGetA(a) - 255)) < 2;
+}
+
+void MakeTestBGRASkBitmap(int w, int h, SkBitmap* bmp) {
bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h);
bmp->allocPixels();
@@ -259,6 +267,16 @@ void MakeTestSkBitmap(int w, int h, SkBitmap* bmp) {
}
}
+void MakeTestA8SkBitmap(int w, int h, SkBitmap* bmp) {
+ bmp->setConfig(SkBitmap::kA8_Config, w, h);
+ bmp->allocPixels();
+
+ uint8_t* src_data = bmp->getAddr8(0, 0);
+ for (int i = 0; i < w * h; i++) {
Peter Kasting 2014/02/04 01:37:15 Nit: {} unnecessary
+ src_data[i] = i % 255;
+ }
+}
+
TEST(PNGCodec, EncodeDecodeRGB) {
const int w = 20, h = 20;
@@ -1017,7 +1035,7 @@ TEST(PNGCodec, EncodeBGRASkBitmap) {
const int w = 20, h = 20;
SkBitmap original_bitmap;
- MakeTestSkBitmap(w, h, &original_bitmap);
+ MakeTestBGRASkBitmap(w, h, &original_bitmap);
// Encode the bitmap.
std::vector<unsigned char> encoded;
@@ -1040,11 +1058,35 @@ TEST(PNGCodec, EncodeBGRASkBitmap) {
}
}
+TEST(PNGCodec, EncodeA8SkBitmap) {
+ const int w = 20, h = 20;
+
+ SkBitmap original_bitmap;
+ MakeTestA8SkBitmap(w, h, &original_bitmap);
+
+ // Encode the bitmap.
+ std::vector<unsigned char> encoded;
+ EXPECT_TRUE(PNGCodec::EncodeA8SkBitmap(original_bitmap, &encoded));
+
+ // Decode the encoded string.
+ SkBitmap decoded_bitmap;
+ EXPECT_TRUE(PNGCodec::Decode(&encoded.front(), encoded.size(),
+ &decoded_bitmap));
+
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ uint8_t original_pixel = *original_bitmap.getAddr8(x, y);
+ uint32_t decoded_pixel = *decoded_bitmap.getAddr32(x, y);
+ EXPECT_TRUE(BGRAGrayColorsClose(decoded_pixel, original_pixel));
Peter Kasting 2014/02/04 01:37:15 How come we can't just check for direct equality?
+ }
+ }
+}
+
TEST(PNGCodec, EncodeBGRASkBitmapDiscardTransparency) {
const int w = 20, h = 20;
SkBitmap original_bitmap;
- MakeTestSkBitmap(w, h, &original_bitmap);
+ MakeTestBGRASkBitmap(w, h, &original_bitmap);
// Encode the bitmap.
std::vector<unsigned char> encoded;
@@ -1121,7 +1163,7 @@ TEST(PNGCodec, EncodeDecodeWithVaryingCompressionLevels) {
// create an image with known values, a must be opaque because it will be
// lost during encoding
SkBitmap original_bitmap;
- MakeTestSkBitmap(w, h, &original_bitmap);
+ MakeTestBGRASkBitmap(w, h, &original_bitmap);
// encode
std::vector<unsigned char> encoded_normal;
« ui/gfx/codec/png_codec.cc ('K') | « ui/gfx/codec/png_codec.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698