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 #if defined(USE_SYSTEM_LIBPNG) | 5 #if defined(USE_SYSTEM_LIBPNG) |
6 #include <png.h> | 6 #include <png.h> |
7 #else | 7 #else |
8 #include "third_party/libpng/png.h" | 8 #include "third_party/libpng/png.h" |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 } | 902 } |
903 | 903 |
904 // Test that corrupted data decompression causes failures. | 904 // Test that corrupted data decompression causes failures. |
905 TEST(PNGCodec, DecodeCorrupted) { | 905 TEST(PNGCodec, DecodeCorrupted) { |
906 int w = 20, h = 20; | 906 int w = 20, h = 20; |
907 | 907 |
908 // Make some random data (an uncompressed image). | 908 // Make some random data (an uncompressed image). |
909 std::vector<unsigned char> original; | 909 std::vector<unsigned char> original; |
910 MakeRGBImage(w, h, &original); | 910 MakeRGBImage(w, h, &original); |
911 | 911 |
912 // It should fail when given non-JPEG compressed data. | 912 // It should fail when given non-PNG compressed data. |
913 std::vector<unsigned char> output; | 913 std::vector<unsigned char> output; |
914 int outw, outh; | 914 int outw, outh; |
915 EXPECT_FALSE(PNGCodec::Decode(&original[0], original.size(), | 915 EXPECT_FALSE(PNGCodec::Decode(&original[0], original.size(), |
916 PNGCodec::FORMAT_RGB, &output, | 916 PNGCodec::FORMAT_RGB, &output, |
917 &outw, &outh)); | 917 &outw, &outh)); |
918 | 918 |
919 // Make some compressed data. | 919 // Make some compressed data. |
920 std::vector<unsigned char> compressed; | 920 std::vector<unsigned char> compressed; |
921 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, | 921 ASSERT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, |
922 Size(w, h), w * 3, false, | 922 Size(w, h), w * 3, false, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 PNGCodec::FORMAT_RGBA, &decoded, | 1122 PNGCodec::FORMAT_RGBA, &decoded, |
1123 &outw, &outh)); | 1123 &outw, &outh)); |
1124 ASSERT_EQ(w, outw); | 1124 ASSERT_EQ(w, outw); |
1125 ASSERT_EQ(h, outh); | 1125 ASSERT_EQ(h, outh); |
1126 ASSERT_EQ(original.size(), decoded.size()); | 1126 ASSERT_EQ(original.size(), decoded.size()); |
1127 | 1127 |
1128 // Images must be exactly equal | 1128 // Images must be exactly equal |
1129 ASSERT_TRUE(original == decoded); | 1129 ASSERT_TRUE(original == decoded); |
1130 } | 1130 } |
1131 | 1131 |
| 1132 TEST(PNGCodec, CustomScaleChunkDetection) { |
| 1133 const int w = 20, h = 20; |
| 1134 static const unsigned char png_scale_chunk[12] = |
| 1135 { 0, 0, 0, 0, 'c', 's', 'C', 'l', 0xc1, 0x30, 0x60, 0x4d }; |
| 1136 |
| 1137 // Compress some random data. |
| 1138 SkBitmap original; |
| 1139 std::vector<unsigned char> compressed; |
| 1140 MakeTestSkBitmap(w, h, &original); |
| 1141 PNGCodec::EncodeBGRASkBitmap(original, false, &compressed); |
| 1142 |
| 1143 // Without the custom chunk, fell_back_to_1x should be false. |
| 1144 SkBitmap decompressed; |
| 1145 bool fell_back_to_1x = true; |
| 1146 EXPECT_TRUE(PNGCodec::Decode(&compressed[0], compressed.size(), |
| 1147 &decompressed, &fell_back_to_1x)); |
| 1148 EXPECT_FALSE(fell_back_to_1x); |
| 1149 |
| 1150 // With the custom chunk, fell_back_to_1x should be true. |
| 1151 compressed.insert(compressed.end() - 12, |
| 1152 png_scale_chunk, png_scale_chunk + sizeof(png_scale_chunk)); |
| 1153 fell_back_to_1x = false; |
| 1154 EXPECT_TRUE(PNGCodec::Decode(&compressed[0], compressed.size(), |
| 1155 &decompressed, &fell_back_to_1x)); |
| 1156 EXPECT_TRUE(fell_back_to_1x); |
| 1157 } |
| 1158 |
1132 | 1159 |
1133 } // namespace gfx | 1160 } // namespace gfx |
OLD | NEW |