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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 250 } |
251 | 251 |
252 // Returns true if the BGRA 32-bit SkColor specified by |a| is equivalent to the | 252 // Returns true if the BGRA 32-bit SkColor specified by |a| is equivalent to the |
253 // 8-bit Gray color specified by |b|. | 253 // 8-bit Gray color specified by |b|. |
254 bool BGRAGrayEqualsA8Gray(uint32_t a, uint8_t b) { | 254 bool BGRAGrayEqualsA8Gray(uint32_t a, uint8_t b) { |
255 return SkColorGetB(a) == b && SkColorGetG(a) == b && | 255 return SkColorGetB(a) == b && SkColorGetG(a) == b && |
256 SkColorGetR(a) == b && SkColorGetA(a) == 255; | 256 SkColorGetR(a) == b && SkColorGetA(a) == 255; |
257 } | 257 } |
258 | 258 |
259 void MakeTestBGRASkBitmap(int w, int h, SkBitmap* bmp) { | 259 void MakeTestBGRASkBitmap(int w, int h, SkBitmap* bmp) { |
260 bmp->setConfig(SkBitmap::kARGB_8888_Config, w, h); | 260 bmp->allocN32Pixels(w, h); |
261 bmp->allocPixels(); | |
262 | 261 |
263 uint32_t* src_data = bmp->getAddr32(0, 0); | 262 uint32_t* src_data = bmp->getAddr32(0, 0); |
264 for (int i = 0; i < w * h; i++) | 263 for (int i = 0; i < w * h; i++) |
265 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); | 264 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); |
266 } | 265 } |
267 | 266 |
268 void MakeTestA8SkBitmap(int w, int h, SkBitmap* bmp) { | 267 void MakeTestA8SkBitmap(int w, int h, SkBitmap* bmp) { |
269 bmp->setConfig(SkBitmap::kA8_Config, w, h); | 268 bmp->allocPixels(SkImageInfo::MakeA8(w, h)); |
270 bmp->allocPixels(); | |
271 | 269 |
272 uint8_t* src_data = bmp->getAddr8(0, 0); | 270 uint8_t* src_data = bmp->getAddr8(0, 0); |
273 for (int i = 0; i < w * h; i++) | 271 for (int i = 0; i < w * h; i++) |
274 src_data[i] = i % 255; | 272 src_data[i] = i % 255; |
275 } | 273 } |
276 | 274 |
277 TEST(PNGCodec, EncodeDecodeRGB) { | 275 TEST(PNGCodec, EncodeDecodeRGB) { |
278 const int w = 20, h = 20; | 276 const int w = 20, h = 20; |
279 | 277 |
280 // create an image with known values | 278 // create an image with known values |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 } | 985 } |
988 | 986 |
989 TEST(PNGCodec, EncodeBGRASkBitmapStridePadded) { | 987 TEST(PNGCodec, EncodeBGRASkBitmapStridePadded) { |
990 const int kWidth = 20; | 988 const int kWidth = 20; |
991 const int kHeight = 20; | 989 const int kHeight = 20; |
992 const int kPaddedWidth = 32; | 990 const int kPaddedWidth = 32; |
993 const int kBytesPerPixel = 4; | 991 const int kBytesPerPixel = 4; |
994 const int kPaddedSize = kPaddedWidth * kHeight; | 992 const int kPaddedSize = kPaddedWidth * kHeight; |
995 const int kRowBytes = kPaddedWidth * kBytesPerPixel; | 993 const int kRowBytes = kPaddedWidth * kBytesPerPixel; |
996 | 994 |
| 995 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); |
997 SkBitmap original_bitmap; | 996 SkBitmap original_bitmap; |
998 original_bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 997 original_bitmap.setInfo(info, kRowBytes); |
999 kWidth, kHeight, kRowBytes); | |
1000 original_bitmap.allocPixels(); | 998 original_bitmap.allocPixels(); |
1001 | 999 |
1002 // Write data over the source bitmap. | 1000 // Write data over the source bitmap. |
1003 // We write on the pad area here too. | 1001 // We write on the pad area here too. |
1004 // The encoder should ignore the pad area. | 1002 // The encoder should ignore the pad area. |
1005 uint32_t* src_data = original_bitmap.getAddr32(0, 0); | 1003 uint32_t* src_data = original_bitmap.getAddr32(0, 0); |
1006 for (int i = 0; i < kPaddedSize; i++) { | 1004 for (int i = 0; i < kPaddedSize; i++) { |
1007 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); | 1005 src_data[i] = SkPreMultiplyARGB(i % 255, i % 250, i % 245, i % 240); |
1008 } | 1006 } |
1009 | 1007 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 PNGCodec::Decode(&encoded_normal[0], encoded_normal.size(), &decoded)); | 1179 PNGCodec::Decode(&encoded_normal[0], encoded_normal.size(), &decoded)); |
1182 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); | 1180 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); |
1183 | 1181 |
1184 EXPECT_TRUE( | 1182 EXPECT_TRUE( |
1185 PNGCodec::Decode(&encoded_fast[0], encoded_fast.size(), &decoded)); | 1183 PNGCodec::Decode(&encoded_fast[0], encoded_fast.size(), &decoded)); |
1186 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); | 1184 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); |
1187 } | 1185 } |
1188 | 1186 |
1189 | 1187 |
1190 } // namespace gfx | 1188 } // namespace gfx |
OLD | NEW |