aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-07-10 11:23:07 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-10 16:37:45 +0000
commitda1893fe3a654b551516ce706a363eebf8471511 (patch)
treef56408ee055b827ad7046c361762305bc493e104 /tools
parent5449aade6227a1e701ebc24ee683d94a810c9a70 (diff)
Fixes for get_images_from_skps
Do not consider kErrorInInput a failure. This probably means a corrupted image stored in the SKP. This will fix the buildbot. In addition, fix some other problems: - Return an error when no SkPicture is created, rather than crashing. - Use a different name for failed decodes, so they don't get overwritten by future failed or successful decodes. Bug: skia:6840 Change-Id: Ia1d04e145a58495fb955d4b07dbb260cb7a35809 Reviewed-on: https://skia-review.googlesource.com/22031 Reviewed-by: Ravi Mistry <rmistry@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/get_images_from_skps.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index d9077d7ddc..0debe367bd 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -85,9 +85,9 @@ struct Sniffer : public SkPixelSerializer {
SkASSERT(false);
}
- auto writeImage = [&] {
+ auto writeImage = [&] (const char* name, int num) {
SkString path;
- path.appendf("%s/%d.%s", gOutputDir, gKnown, ext.c_str());
+ path.appendf("%s/%s%d.%s", gOutputDir, name, num, ext.c_str());
SkFILEWStream file(path.c_str());
file.write(ptr, len);
@@ -95,28 +95,31 @@ struct Sniffer : public SkPixelSerializer {
SkDebugf("%s\n", path.c_str());
};
-
if (FLAGS_testDecode) {
SkBitmap bitmap;
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
bitmap.allocPixels(info);
const SkCodec::Result result = codec->getPixels(
info, bitmap.getPixels(), bitmap.rowBytes());
- if (SkCodec::kIncompleteInput != result && SkCodec::kSuccess != result) {
- SkDebugf("Decoding failed for %s\n", skpName.c_str());
- gSkpToUnknownCount[skpName]++;
- if (FLAGS_writeFailedImages) {
- writeImage();
- }
- return;
+ switch (result) {
+ case SkCodec::kSuccess:
+ case SkCodec::kIncompleteInput:
+ case SkCodec::kErrorInInput:
+ break;
+ default:
+ SkDebugf("Decoding failed for %s\n", skpName.c_str());
+ if (FLAGS_writeFailedImages) {
+ writeImage("unknown", gSkpToUnknownCount[skpName]);
+ }
+ gSkpToUnknownCount[skpName]++;
+ return;
}
}
if (FLAGS_writeImages) {
- writeImage();
+ writeImage("", gKnown);
}
-
gKnown++;
}
@@ -127,13 +130,17 @@ struct Sniffer : public SkPixelSerializer {
SkData* onEncode(const SkPixmap&) override { return nullptr; }
};
-static void get_images_from_file(const SkString& file) {
+static bool get_images_from_file(const SkString& file) {
auto stream = SkStream::MakeFromFile(file.c_str());
sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream.get()));
+ if (!picture) {
+ return false;
+ }
SkDynamicMemoryWStream scratch;
Sniffer sniff(file.c_str());
picture->serialize(&scratch, &sniff);
+ return true;
}
int main(int argc, char** argv) {
@@ -153,10 +160,14 @@ int main(int argc, char** argv) {
if (sk_isdir(inputs)) {
SkOSFile::Iter iter(inputs, "skp");
for (SkString file; iter.next(&file); ) {
- get_images_from_file(SkOSPath::Join(inputs, file.c_str()));
+ if (!get_images_from_file(SkOSPath::Join(inputs, file.c_str()))) {
+ return 2;
+ }
}
} else {
- get_images_from_file(SkString(inputs));
+ if (!get_images_from_file(SkString(inputs))) {
+ return 2;
+ }
}
/**
JSON results are written out in the following format: