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

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

Issue 12313139: captureVisibleTab Extension API producing garbled PNG results (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: re-added properly cast dcheck Created 7 years, 9 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
« no previous file with comments | « 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 c22e7b12b4e7df65e6c8701aca73358758f560db..e3540a27114f930aef9297a6f1c15152b2a4ffc2 100644
--- a/ui/gfx/codec/png_codec_unittest.cc
+++ b/ui/gfx/codec/png_codec_unittest.cc
@@ -970,6 +970,48 @@ TEST(PNGCodec, StripAddAlpha) {
ASSERT_EQ(original_rgb, decoded);
}
+TEST(PNGCodec, EncodeBGRASkBitmapStridePadded) {
+ const int kWidth = 20;
+ const int kHeight = 20;
+ const int kPaddedWidth = 32;
+ const int kBytesPerPixel = 4;
+ const int kPaddedSize = kPaddedWidth * kHeight;
+ const int kRowBytes = kPaddedWidth * kBytesPerPixel;
+
+ SkBitmap original_bitmap;
+ original_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
+ kWidth, kHeight, kRowBytes);
+ original_bitmap.allocPixels();
+
+ // Write data over the source bitmap.
+ // We write on the pad area here too.
+ // The encoder should ignore the pad area.
+ uint32_t* src_data = original_bitmap.getAddr32(0, 0);
+ for (int i = 0; i < kPaddedSize; i++) {
+ src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240);
+ }
+
+ // Encode the bitmap.
+ std::vector<unsigned char> encoded;
+ PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded);
+
+ // Decode the encoded string.
+ SkBitmap decoded_bitmap;
+ EXPECT_TRUE(PNGCodec::Decode(&encoded.front(), encoded.size(),
+ &decoded_bitmap));
+
+ // Compare the original bitmap and the output bitmap. We use ColorsClose
+ // as SkBitmaps are considered to be pre-multiplied, the unpremultiplication
+ // (in Encode) and repremultiplication (in Decode) can be lossy.
+ for (int x = 0; x < kWidth; x++) {
+ for (int y = 0; y < kHeight; y++) {
+ uint32_t original_pixel = original_bitmap.getAddr32(0, y)[x];
+ uint32_t decoded_pixel = decoded_bitmap.getAddr32(0, y)[x];
+ EXPECT_TRUE(ColorsClose(original_pixel, decoded_pixel));
+ }
+ }
+}
+
TEST(PNGCodec, EncodeBGRASkBitmap) {
const int w = 20, h = 20;
« no previous file with comments | « ui/gfx/codec/png_codec.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698