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 | |
msarett
2016/01/07 17:43:01
While we do want Skia to work for any version of l
scroggo
2016/01/07 18:04:43
You don't think we should just change it to PNG_HA
msarett
2016/01/07 18:20:48
Hmmm ok - I went back and forth on this anyway. I
| |
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); | |
755 png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_PLTE); | |
756 #endif | |
757 | 752 |
758 png_write_info(png, info); | 753 png_write_info(png, info); |
759 | 754 |
760 for (int j = 0; j < h; j++) { | 755 for (int j = 0; j < h; j++) { |
761 png_bytep row = (png_bytep)(bm.getAddr(0, j)); | 756 png_bytep row = (png_bytep)(bm.getAddr(0, j)); |
762 png_write_rows(png, &row, 1); | 757 png_write_rows(png, &row, 1); |
763 } | 758 } |
764 png_write_end(png, info); | 759 png_write_end(png, info); |
765 png_destroy_write_struct(&png, &info); | 760 png_destroy_write_struct(&png, &info); |
766 | 761 |
(...skipping 180 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. | 942 // 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. | 943 // has bigger width/height) is also too big. |
949 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header | 944 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header |
950 0x84, 0x80, 0x00, // W: 65536 | 945 0x84, 0x80, 0x00, // W: 65536 |
951 0x84, 0x80, 0x00 }; // H: 65536 | 946 0x84, 0x80, 0x00 }; // H: 65536 |
952 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); | 947 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); |
953 codec.reset(SkCodec::NewFromStream(stream.detach())); | 948 codec.reset(SkCodec::NewFromStream(stream.detach())); |
954 | 949 |
955 REPORTER_ASSERT(r, !codec); | 950 REPORTER_ASSERT(r, !codec); |
956 } | 951 } |
OLD | NEW |