Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 TEST(PNGCodec, EncodeDecodeRGBA) { | 279 TEST(PNGCodec, EncodeDecodeRGBA) { |
| 280 const int w = 20, h = 20; | 280 const int w = 20, h = 20; |
| 281 | 281 |
| 282 // create an image with known values, a must be opaque because it will be | 282 // create an image with known values, a must be opaque because it will be |
| 283 // lost during encoding | 283 // lost during encoding |
| 284 std::vector<unsigned char> original; | 284 std::vector<unsigned char> original; |
| 285 MakeRGBAImage(w, h, true, &original); | 285 MakeRGBAImage(w, h, true, &original); |
| 286 | 286 |
| 287 // encode | 287 // encode |
| 288 std::vector<unsigned char> encoded; | 288 std::vector<unsigned char> encoded; |
| 289 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGBA, | 289 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGBA, Size(w, h), |
|
msarett1
2017/06/23 22:50:32
Why is this file changed?
liyuqian
2017/07/05 15:59:40
I've reverted the change. I think it's because tha
| |
| 290 Size(w, h), w * 4, false, | 290 w * 4, false, std::vector<PNGCodec::Comment>(), |
| 291 std::vector<PNGCodec::Comment>(), | |
| 292 &encoded)); | 291 &encoded)); |
| 293 | 292 |
| 294 // decode, it should have the same size as the original | 293 // decode, it should have the same size as the original |
| 295 std::vector<unsigned char> decoded; | 294 std::vector<unsigned char> decoded; |
| 296 int outw, outh; | 295 int outw, outh; |
| 297 ASSERT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), | 296 ASSERT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), |
| 298 PNGCodec::FORMAT_RGBA, &decoded, | 297 PNGCodec::FORMAT_RGBA, &decoded, |
| 299 &outw, &outh)); | 298 &outw, &outh)); |
| 300 ASSERT_EQ(w, outw); | 299 ASSERT_EQ(w, outw); |
| 301 ASSERT_EQ(h, outh); | 300 ASSERT_EQ(h, outh); |
| 302 ASSERT_EQ(original.size(), decoded.size()); | 301 ASSERT_EQ(original.size(), decoded.size()); |
| 303 | 302 |
| 304 // Images must be exactly equal | 303 // Images must be exactly equal |
| 305 ASSERT_TRUE(original == decoded); | 304 ASSERT_TRUE(original == decoded); |
| 306 } | 305 } |
| 307 | 306 |
| 308 TEST(PNGCodec, EncodeDecodeBGRA) { | 307 TEST(PNGCodec, EncodeDecodeBGRA) { |
| 309 const int w = 20, h = 20; | 308 const int w = 20, h = 20; |
| 310 | 309 |
| 311 // Create an image with known values, alpha must be opaque because it will be | 310 // Create an image with known values, alpha must be opaque because it will be |
| 312 // lost during encoding. | 311 // lost during encoding. |
| 313 std::vector<unsigned char> original; | 312 std::vector<unsigned char> original; |
| 314 MakeRGBAImage(w, h, true, &original); | 313 MakeRGBAImage(w, h, true, &original); |
| 315 | 314 |
| 316 // Encode. | 315 // Encode. |
| 317 std::vector<unsigned char> encoded; | 316 std::vector<unsigned char> encoded; |
| 318 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_BGRA, | 317 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_BGRA, Size(w, h), |
| 319 Size(w, h), w * 4, false, | 318 w * 4, false, std::vector<PNGCodec::Comment>(), |
| 320 std::vector<PNGCodec::Comment>(), | |
| 321 &encoded)); | 319 &encoded)); |
| 322 | 320 |
| 323 // Decode, it should have the same size as the original. | 321 // Decode, it should have the same size as the original. |
| 324 std::vector<unsigned char> decoded; | 322 std::vector<unsigned char> decoded; |
| 325 int outw, outh; | 323 int outw, outh; |
| 326 ASSERT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), | 324 ASSERT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(), |
| 327 PNGCodec::FORMAT_BGRA, &decoded, | 325 PNGCodec::FORMAT_BGRA, &decoded, |
| 328 &outw, &outh)); | 326 &outw, &outh)); |
| 329 ASSERT_EQ(w, outw); | 327 ASSERT_EQ(w, outw); |
| 330 ASSERT_EQ(h, outh); | 328 ASSERT_EQ(h, outh); |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 PNGCodec::Decode(&encoded_normal[0], encoded_normal.size(), &decoded)); | 957 PNGCodec::Decode(&encoded_normal[0], encoded_normal.size(), &decoded)); |
| 960 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); | 958 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); |
| 961 | 959 |
| 962 EXPECT_TRUE( | 960 EXPECT_TRUE( |
| 963 PNGCodec::Decode(&encoded_fast[0], encoded_fast.size(), &decoded)); | 961 PNGCodec::Decode(&encoded_fast[0], encoded_fast.size(), &decoded)); |
| 964 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); | 962 EXPECT_TRUE(BitmapsAreEqual(decoded, original_bitmap)); |
| 965 } | 963 } |
| 966 | 964 |
| 967 | 965 |
| 968 } // namespace gfx | 966 } // namespace gfx |
| OLD | NEW |