| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 | 735 |
| 736 SkDynamicMemoryWStream wStream; | 736 SkDynamicMemoryWStream wStream; |
| 737 png_set_write_fn(png, (void*) (&wStream), codex_test_write_fn, nullptr); | 737 png_set_write_fn(png, (void*) (&wStream), codex_test_write_fn, nullptr); |
| 738 | 738 |
| 739 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, | 739 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 740 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, | 740 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 741 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 741 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 742 | 742 |
| 743 // Create some chunks that match the Android framework's use. | 743 // Create some chunks that match the Android framework's use. |
| 744 static png_unknown_chunk gUnknowns[] = { | 744 static png_unknown_chunk gUnknowns[] = { |
| 745 { "npOl", (png_byte*)"outline", sizeof("outline"), PNG_HAVE_PLTE }, | 745 { "npOl", (png_byte*)"outline", sizeof("outline"), PNG_HAVE_IHDR }, |
| 746 { "npLb", (png_byte*)"layoutBounds", sizeof("layoutBounds"), PNG_HAVE_PL
TE }, | 746 { "npLb", (png_byte*)"layoutBounds", sizeof("layoutBounds"), PNG_HAVE_IH
DR }, |
| 747 { "npTc", (png_byte*)"ninePatchData", sizeof("ninePatchData"), PNG_HAVE_
PLTE }, | 747 { "npTc", (png_byte*)"ninePatchData", sizeof("ninePatchData"), PNG_HAVE_
IHDR }, |
| 748 }; | 748 }; |
| 749 | 749 |
| 750 png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"npOl\0
npLb\0npTc\0", 3); | 750 png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"npOl\0
npLb\0npTc\0", 3); |
| 751 png_set_unknown_chunks(png, info, gUnknowns, SK_ARRAY_COUNT(gUnknowns)); | 751 png_set_unknown_chunks(png, info, gUnknowns, SK_ARRAY_COUNT(gUnknowns)); |
| 752 #if PNG_LIBPNG_VER < 10600 | 752 #if PNG_LIBPNG_VER < 10600 |
| 753 /* Deal with unknown chunk location bug in 1.5.x and earlier */ | 753 /* Deal with unknown chunk location bug in 1.5.x and earlier */ |
| 754 png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_PLTE); | 754 png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_IHDR); |
| 755 png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_PLTE); | 755 png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_IHDR); |
| 756 #endif | 756 #endif |
| 757 | 757 |
| 758 png_write_info(png, info); | 758 png_write_info(png, info); |
| 759 | 759 |
| 760 for (int j = 0; j < h; j++) { | 760 for (int j = 0; j < h; j++) { |
| 761 png_bytep row = (png_bytep)(bm.getAddr(0, j)); | 761 png_bytep row = (png_bytep)(bm.getAddr(0, j)); |
| 762 png_write_rows(png, &row, 1); | 762 png_write_rows(png, &row, 1); |
| 763 } | 763 } |
| 764 png_write_end(png, info); | 764 png_write_end(png, info); |
| 765 png_destroy_write_struct(&png, &info); | 765 png_destroy_write_struct(&png, &info); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 // Now test an image which is too big. Any image with a larger header (i.e. | 947 // Now test an image which is too big. Any image with a larger header (i.e. |
| 948 // has bigger width/height) is also too big. | 948 // has bigger width/height) is also too big. |
| 949 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 949 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
| 950 0x84, 0x80, 0x00, // W: 65536 | 950 0x84, 0x80, 0x00, // W: 65536 |
| 951 0x84, 0x80, 0x00 }; // H: 65536 | 951 0x84, 0x80, 0x00 }; // H: 65536 |
| 952 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 952 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
| 953 codec.reset(SkCodec::NewFromStream(stream.detach())); | 953 codec.reset(SkCodec::NewFromStream(stream.detach())); |
| 954 | 954 |
| 955 REPORTER_ASSERT(r, !codec); | 955 REPORTER_ASSERT(r, !codec); |
| 956 } | 956 } |
| OLD | NEW |