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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/codec/png_codec.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <cmath> 6 #include <cmath>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/libpng/png.h" 10 #include "third_party/libpng/png.h"
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 PNGCodec::FORMAT_RGB, &decoded, 963 PNGCodec::FORMAT_RGB, &decoded,
964 &outw, &outh)); 964 &outw, &outh));
965 965
966 // It should be the same as our non-alpha-channel reference. 966 // It should be the same as our non-alpha-channel reference.
967 ASSERT_EQ(w, outw); 967 ASSERT_EQ(w, outw);
968 ASSERT_EQ(h, outh); 968 ASSERT_EQ(h, outh);
969 ASSERT_EQ(original_rgb.size(), decoded.size()); 969 ASSERT_EQ(original_rgb.size(), decoded.size());
970 ASSERT_EQ(original_rgb, decoded); 970 ASSERT_EQ(original_rgb, decoded);
971 } 971 }
972 972
973 TEST(PNGCodec, EncodeBGRASkBitmapStridePadded) {
974 const int kWidth = 20;
975 const int kHeight = 20;
976 const int kPaddedWidth = 32;
977 const int kBytesPerPixel = 4;
978 const int kPaddedSize = kPaddedWidth * kHeight;
979 const int kRowBytes = kPaddedWidth * kBytesPerPixel;
980
981 SkBitmap original_bitmap;
982 original_bitmap.setConfig(SkBitmap::kARGB_8888_Config,
983 kWidth, kHeight, kRowBytes);
984 original_bitmap.allocPixels();
985
986 // Write data over the source bitmap.
987 // We write on the pad area here too.
988 // The encoder should ignore the pad area.
989 uint32_t* src_data = original_bitmap.getAddr32(0, 0);
990 for (int i = 0; i < kPaddedSize; i++) {
991 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240);
992 }
993
994 // Encode the bitmap.
995 std::vector<unsigned char> encoded;
996 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded);
997
998 // Decode the encoded string.
999 SkBitmap decoded_bitmap;
1000 EXPECT_TRUE(PNGCodec::Decode(&encoded.front(), encoded.size(),
1001 &decoded_bitmap));
1002
1003 // Compare the original bitmap and the output bitmap. We use ColorsClose
1004 // as SkBitmaps are considered to be pre-multiplied, the unpremultiplication
1005 // (in Encode) and repremultiplication (in Decode) can be lossy.
1006 for (int x = 0; x < kWidth; x++) {
1007 for (int y = 0; y < kHeight; y++) {
1008 uint32_t original_pixel = original_bitmap.getAddr32(0, y)[x];
1009 uint32_t decoded_pixel = decoded_bitmap.getAddr32(0, y)[x];
1010 EXPECT_TRUE(ColorsClose(original_pixel, decoded_pixel));
1011 }
1012 }
1013 }
1014
973 TEST(PNGCodec, EncodeBGRASkBitmap) { 1015 TEST(PNGCodec, EncodeBGRASkBitmap) {
974 const int w = 20, h = 20; 1016 const int w = 20, h = 20;
975 1017
976 SkBitmap original_bitmap; 1018 SkBitmap original_bitmap;
977 MakeTestSkBitmap(w, h, &original_bitmap); 1019 MakeTestSkBitmap(w, h, &original_bitmap);
978 1020
979 // Encode the bitmap. 1021 // Encode the bitmap.
980 std::vector<unsigned char> encoded; 1022 std::vector<unsigned char> encoded;
981 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded); 1023 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded);
982 1024
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 ASSERT_EQ(w, outw); 1153 ASSERT_EQ(w, outw);
1112 ASSERT_EQ(h, outh); 1154 ASSERT_EQ(h, outh);
1113 ASSERT_EQ(original.size(), decoded.size()); 1155 ASSERT_EQ(original.size(), decoded.size());
1114 1156
1115 // Images must be exactly equal 1157 // Images must be exactly equal
1116 ASSERT_TRUE(original == decoded); 1158 ASSERT_TRUE(original == decoded);
1117 } 1159 }
1118 1160
1119 1161
1120 } // namespace gfx 1162 } // namespace gfx
OLDNEW
« 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