OLD | NEW |
---|---|
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 Loading... | |
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 w = 20, h = 20, padded_w = 32; | |
Alexei Svitkine (slow)
2013/03/05 18:29:26
Separate lines please.
I suggest using constant n
Sam Larison
2013/03/05 20:30:41
I have changed the naming conventions... except I
Alexei Svitkine (slow)
2013/03/05 21:35:23
Each on a separate line, please.
| |
975 | |
976 SkBitmap original_bitmap; | |
977 original_bitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h, padded_w * 4); | |
978 original_bitmap.allocPixels(); | |
979 | |
980 // Write data over the source bitmap. | |
981 // We write on the pad area here too. | |
982 // The encoder should ignore the pad area. | |
983 uint32_t* src_data = original_bitmap.getAddr32(0, 0); | |
984 for (int i = 0; i < padded_w * h; i++) { | |
Alexei Svitkine (slow)
2013/03/05 18:29:26
Extract padded_w * h into a variable, e.g.
const
| |
985 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); | |
986 } | |
987 | |
988 // Encode the bitmap. | |
989 std::vector<unsigned char> encoded; | |
990 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded); | |
991 | |
992 // Decode the encoded string. | |
993 SkBitmap decoded_bitmap; | |
994 EXPECT_TRUE(PNGCodec::Decode(&encoded.front(), encoded.size(), | |
995 &decoded_bitmap)); | |
996 | |
997 // Compare the original bitmap and the output bitmap. We use ColorsClose | |
998 // as SkBitmaps are considered to be pre-multiplied, the unpremultiplication | |
999 // (in Encode) and repremultiplication (in Decode) can be lossy. | |
1000 for (int x = 0; x < w; x++) { | |
1001 for (int y = 0; y < h; y++) { | |
1002 uint32_t original_pixel = original_bitmap.getAddr32(0, y)[x]; | |
Alexei Svitkine (slow)
2013/03/05 18:29:26
Can you do *original_bitmap.getAddr32(x, y) here?
Sam Larison
2013/03/05 20:30:41
I attempted doing so however this produced unsatis
Alexei Svitkine (slow)
2013/03/05 21:35:23
Okay, that's fine then.
| |
1003 uint32_t decoded_pixel = decoded_bitmap.getAddr32(0, y)[x]; | |
Alexei Svitkine (slow)
2013/03/05 18:29:26
ditto
| |
1004 EXPECT_TRUE(ColorsClose(original_pixel, decoded_pixel)); | |
1005 } | |
1006 } | |
1007 } | |
1008 | |
973 TEST(PNGCodec, EncodeBGRASkBitmap) { | 1009 TEST(PNGCodec, EncodeBGRASkBitmap) { |
974 const int w = 20, h = 20; | 1010 const int w = 20, h = 20; |
975 | 1011 |
976 SkBitmap original_bitmap; | 1012 SkBitmap original_bitmap; |
977 MakeTestSkBitmap(w, h, &original_bitmap); | 1013 MakeTestSkBitmap(w, h, &original_bitmap); |
978 | 1014 |
979 // Encode the bitmap. | 1015 // Encode the bitmap. |
980 std::vector<unsigned char> encoded; | 1016 std::vector<unsigned char> encoded; |
981 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded); | 1017 PNGCodec::EncodeBGRASkBitmap(original_bitmap, false, &encoded); |
982 | 1018 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 ASSERT_EQ(w, outw); | 1147 ASSERT_EQ(w, outw); |
1112 ASSERT_EQ(h, outh); | 1148 ASSERT_EQ(h, outh); |
1113 ASSERT_EQ(original.size(), decoded.size()); | 1149 ASSERT_EQ(original.size(), decoded.size()); |
1114 | 1150 |
1115 // Images must be exactly equal | 1151 // Images must be exactly equal |
1116 ASSERT_TRUE(original == decoded); | 1152 ASSERT_TRUE(original == decoded); |
1117 } | 1153 } |
1118 | 1154 |
1119 | 1155 |
1120 } // namespace gfx | 1156 } // namespace gfx |
OLD | NEW |