| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkMD5.h" | 11 #include "SkMD5.h" |
| 12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 13 #include "SkPicture.h" | 13 #include "SkPicture.h" |
| 14 #include "SkPixelSerializer.h" | 14 #include "SkPixelSerializer.h" |
| 15 #include "SkStream.h" | 15 #include "SkStream.h" |
| 16 #include "SkTHash.h" | 16 #include "SkTHash.h" |
| 17 | 17 |
| 18 DEFINE_string2(skps, s, "skps", "A path to a directory of skps."); | 18 DEFINE_string2(skps, s, "skps", "A path to a directory of skps."); |
| 19 DEFINE_string2(out, o, "img-out", "A path to an output directory."); | 19 DEFINE_string2(out, o, "img-out", "A path to an output directory."); |
| 20 DEFINE_bool(test, false, "Indicates if we want to test that the images decode su
ccessfully."); |
| 20 | 21 |
| 21 static int gKnown; | 22 static int gKnown; |
| 22 static int gUnknown; | 23 static int gUnknown; |
| 23 static const char* gOutputDir; | 24 static const char* gOutputDir; |
| 24 | 25 |
| 25 static SkTHashSet<SkMD5::Digest> gSeen; | 26 static SkTHashSet<SkMD5::Digest> gSeen; |
| 26 | 27 |
| 27 struct Sniffer : public SkPixelSerializer { | 28 struct Sniffer : public SkPixelSerializer { |
| 28 | 29 |
| 29 void sniff(const void* ptr, size_t len) { | 30 void sniff(const void* ptr, size_t len) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 case SkEncodedFormat::kGIF_SkEncodedFormat: ext = "gif"; break; | 50 case SkEncodedFormat::kGIF_SkEncodedFormat: ext = "gif"; break; |
| 50 case SkEncodedFormat::kICO_SkEncodedFormat: ext = "ico"; break; | 51 case SkEncodedFormat::kICO_SkEncodedFormat: ext = "ico"; break; |
| 51 case SkEncodedFormat::kJPEG_SkEncodedFormat: ext = "jpg"; break; | 52 case SkEncodedFormat::kJPEG_SkEncodedFormat: ext = "jpg"; break; |
| 52 case SkEncodedFormat::kPNG_SkEncodedFormat: ext = "png"; break; | 53 case SkEncodedFormat::kPNG_SkEncodedFormat: ext = "png"; break; |
| 53 case SkEncodedFormat::kDNG_SkEncodedFormat: ext = "dng"; break; | 54 case SkEncodedFormat::kDNG_SkEncodedFormat: ext = "dng"; break; |
| 54 case SkEncodedFormat::kWBMP_SkEncodedFormat: ext = "wbmp"; break; | 55 case SkEncodedFormat::kWBMP_SkEncodedFormat: ext = "wbmp"; break; |
| 55 case SkEncodedFormat::kWEBP_SkEncodedFormat: ext = "webp"; break; | 56 case SkEncodedFormat::kWEBP_SkEncodedFormat: ext = "webp"; break; |
| 56 default: gUnknown++; return; | 57 default: gUnknown++; return; |
| 57 } | 58 } |
| 58 | 59 |
| 60 if (FLAGS_test) { |
| 61 SkBitmap bitmap; |
| 62 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); |
| 63 bitmap.allocPixels(info); |
| 64 if (SkCodec::kSuccess != codec->getPixels(info, bitmap.getPixels(),
bitmap.rowBytes())) |
| 65 { |
| 66 gUnknown++; |
| 67 return; |
| 68 } |
| 69 } |
| 70 |
| 59 SkString path; | 71 SkString path; |
| 60 path.appendf("%s/%d.%s", gOutputDir, gKnown++, ext.c_str()); | 72 path.appendf("%s/%d.%s", gOutputDir, gKnown++, ext.c_str()); |
| 61 | 73 |
| 62 SkFILEWStream file(path.c_str()); | 74 SkFILEWStream file(path.c_str()); |
| 63 file.write(ptr, len); | 75 file.write(ptr, len); |
| 64 | 76 |
| 65 SkDebugf("%s\n", path.c_str()); | 77 SkDebugf("%s\n", path.c_str()); |
| 66 } | 78 } |
| 67 | 79 |
| 68 bool onUseEncodedData(const void* ptr, size_t len) override { | 80 bool onUseEncodedData(const void* ptr, size_t len) override { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream)); | 105 sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream)); |
| 94 | 106 |
| 95 SkDynamicMemoryWStream scratch; | 107 SkDynamicMemoryWStream scratch; |
| 96 Sniffer sniff; | 108 Sniffer sniff; |
| 97 picture->serialize(&scratch, &sniff); | 109 picture->serialize(&scratch, &sniff); |
| 98 } | 110 } |
| 99 SkDebugf("%d known, %d unknown\n", gKnown, gUnknown); | 111 SkDebugf("%d known, %d unknown\n", gKnown, gUnknown); |
| 100 | 112 |
| 101 return 0; | 113 return 0; |
| 102 } | 114 } |
| OLD | NEW |