| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 7 | |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 9 | #include "SkColorPriv.h" |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 10 | #include "SkCommandLineFlags.h" |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 11 | #include "SkData.h" |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 12 | #include "SkGraphics.h" |
| 13 | #include "SkImageDecoder.h" |
| 14 | #include "SkImageEncoder.h" |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 15 | #include "SkOSFile.h" |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 16 | #include "SkRandom.h" |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 17 | #include "SkStream.h" |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 18 | #include "SkTArray.h" |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 19 | #include "SkTemplates.h" |
| 20 | |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 21 | DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required."); |
| 22 | DEFINE_string2(writePath, w, "", "Write rendered images into this directory."); |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 23 | DEFINE_bool(reencode, true, "Reencode the images to test encoding."); |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 24 | DEFINE_bool(testSubsetDecoding, true, "Test decoding subsets of images."); |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 25 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 26 | struct Format { |
| 27 | SkImageEncoder::Type fType; |
| 28 | SkImageDecoder::Format fFormat; |
| 29 | const char* fSuffix; |
| 30 | }; |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 31 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 32 | static const Format gFormats[] = { |
| 33 | { SkImageEncoder::kBMP_Type, SkImageDecoder::kBMP_Format, ".bmp" }, |
| 34 | { SkImageEncoder::kGIF_Type, SkImageDecoder::kGIF_Format, ".gif" }, |
| 35 | { SkImageEncoder::kICO_Type, SkImageDecoder::kICO_Format, ".ico" }, |
| 36 | { SkImageEncoder::kJPEG_Type, SkImageDecoder::kJPEG_Format, ".jpg" }, |
| 37 | { SkImageEncoder::kPNG_Type, SkImageDecoder::kPNG_Format, ".png" }, |
| 38 | { SkImageEncoder::kWBMP_Type, SkImageDecoder::kWBMP_Format, ".wbmp" }, |
| 39 | { SkImageEncoder::kWEBP_Type, SkImageDecoder::kWEBP_Format, ".webp" } |
| 40 | }; |
| 41 | |
| 42 | static SkImageEncoder::Type format_to_type(SkImageDecoder::Format format) { |
| 43 | for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
| 44 | if (gFormats[i].fFormat == format) { |
| 45 | return gFormats[i].fType; |
| 46 | } |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 47 | } |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 48 | return SkImageEncoder::kUnknown_Type; |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 51 | static const char* suffix_for_type(SkImageEncoder::Type type) { |
| 52 | for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
| 53 | if (gFormats[i].fType == type) { |
| 54 | return gFormats[i].fSuffix; |
| 55 | } |
| 56 | } |
| 57 | return ""; |
| 58 | } |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 59 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 60 | static SkImageDecoder::Format guess_format_from_suffix(const char suffix[]) { |
| 61 | for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { |
| 62 | if (strcmp(suffix, gFormats[i].fSuffix) == 0) { |
| 63 | return gFormats[i].fFormat; |
| 64 | } |
| 65 | } |
| 66 | return SkImageDecoder::kUnknown_Format; |
| 67 | } |
| 68 | |
| 69 | static void make_outname(SkString* dst, const char outDir[], const char src[], |
| 70 | const char suffix[]) { |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 71 | dst->set(outDir); |
| 72 | const char* start = strrchr(src, '/'); |
| 73 | if (start) { |
| 74 | start += 1; // skip the actual last '/' |
| 75 | } else { |
| 76 | start = src; |
| 77 | } |
| 78 | dst->append(start); |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 79 | if (!dst->endsWith(suffix)) { |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 80 | const char* cstyleDst = dst->c_str(); |
| 81 | const char* dot = strrchr(cstyleDst, '.'); |
| 82 | if (dot != NULL) { |
| 83 | int32_t index = SkToS32(dot - cstyleDst); |
| 84 | dst->remove(index, dst->size() - index); |
| 85 | } |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 86 | dst->append(suffix); |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 90 | // Store the names of the filenames to report later which ones failed, succeeded, and were |
| 91 | // invalid. |
| 92 | static SkTArray<SkString, false> gInvalidStreams; |
| 93 | static SkTArray<SkString, false> gMissingCodecs; |
| 94 | static SkTArray<SkString, false> gDecodeFailures; |
| 95 | static SkTArray<SkString, false> gEncodeFailures; |
| 96 | static SkTArray<SkString, false> gSuccessfulDecodes; |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 97 | static SkTArray<SkString, false> gSuccessfulSubsetDecodes; |
| 98 | static SkTArray<SkString, false> gFailedSubsetDecodes; |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 99 | |
| 100 | static bool write_bitmap(const char outName[], SkBitmap* bm) { |
| 101 | SkBitmap bitmap8888; |
| 102 | if (SkBitmap::kARGB_8888_Config != bm->config()) { |
| 103 | if (!bm->copyTo(&bitmap8888, SkBitmap::kARGB_8888_Config)) { |
| 104 | return false; |
| 105 | } |
| 106 | bm = &bitmap8888; |
| 107 | } |
| 108 | // FIXME: This forces all pixels to be opaque, like the many implementations |
| 109 | // of force_all_opaque. These should be unified if they cannot be eliminated. |
| 110 | SkAutoLockPixels lock(*bm); |
| 111 | for (int y = 0; y < bm->height(); y++) { |
| 112 | for (int x = 0; x < bm->width(); x++) { |
| 113 | *bm->getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 114 | } |
| 115 | } |
| 116 | return SkImageEncoder::EncodeFile(outName, *bm, SkImageEncoder::kPNG_Type, 100); |
| 117 | } |
| 118 | |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 119 | /** |
| 120 | * Return a random SkIRect inside the range specified. |
| 121 | * @param rand Random number generator. |
| 122 | * @param maxX Exclusive maximum x-coordinate. SkIRect's fLeft and fRight will be |
| 123 | * in the range [0, maxX) |
| 124 | * @param maxY Exclusive maximum y-coordinate. SkIRect's fTop and fBottom will be |
| 125 | * in the range [0, maxY) |
| 126 | * @return SkIRect Non-empty, non-degenerate rectangle. |
| 127 | */ |
| 128 | static SkIRect generate_random_rect(SkRandom* rand, int32_t maxX, int32_t maxY) { |
| 129 | SkASSERT(maxX > 1 && maxY > 1); |
| 130 | int32_t left = rand->nextULessThan(maxX); |
| 131 | int32_t right = rand->nextULessThan(maxX); |
| 132 | int32_t top = rand->nextULessThan(maxY); |
| 133 | int32_t bottom = rand->nextULessThan(maxY); |
| 134 | SkIRect rect = SkIRect::MakeLTRB(left, top, right, bottom); |
| 135 | rect.sort(); |
| 136 | // Make sure rect is not empty. |
| 137 | if (rect.fLeft == rect.fRight) { |
| 138 | if (rect.fLeft > 0) { |
| 139 | rect.fLeft--; |
| 140 | } else { |
| 141 | rect.fRight++; |
| 142 | // This branch is only taken if 0 == rect.fRight, and |
| 143 | // maxX must be at least 2, so it must still be in |
| 144 | // range. |
| 145 | SkASSERT(rect.fRight < maxX); |
| 146 | } |
| 147 | } |
| 148 | if (rect.fTop == rect.fBottom) { |
| 149 | if (rect.fTop > 0) { |
| 150 | rect.fTop--; |
| 151 | } else { |
| 152 | rect.fBottom++; |
| 153 | // Again, this must be in range. |
| 154 | SkASSERT(rect.fBottom < maxY); |
| 155 | } |
| 156 | } |
| 157 | return rect; |
| 158 | } |
| 159 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 160 | static void decodeFileAndWrite(const char srcPath[], const SkString* writePath) { |
| 161 | SkBitmap bitmap; |
| 162 | SkFILEStream stream(srcPath); |
| 163 | if (!stream.isValid()) { |
| 164 | gInvalidStreams.push_back().set(srcPath); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
| 169 | if (NULL == codec) { |
| 170 | gMissingCodecs.push_back().set(srcPath); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | SkAutoTDelete<SkImageDecoder> ad(codec); |
| 175 | |
| 176 | stream.rewind(); |
| 177 | if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config, |
| 178 | SkImageDecoder::kDecodePixels_Mode)) { |
| 179 | gDecodeFailures.push_back().set(srcPath); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | gSuccessfulDecodes.push_back().printf("%s [%d %d]", srcPath, bitmap.width(), bitmap.height()); |
| 184 | |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 185 | if (FLAGS_testSubsetDecoding) { |
| 186 | bool couldRewind = stream.rewind(); |
| 187 | SkASSERT(couldRewind); |
| 188 | int width, height; |
| 189 | // Build the tile index for decoding subsets. If the image is 1x1, skip subset |
| 190 | // decoding since there are no smaller subsets. |
| 191 | if (codec->buildTileIndex(&stream, &width, &height) && width > 1 && height > 1) { |
| 192 | SkASSERT(bitmap.width() == width && bitmap.height() == height); |
| 193 | // Call decodeSubset multiple times: |
| 194 | SkRandom rand(0); |
| 195 | for (int i = 0; i < 5; i++) { |
| 196 | SkBitmap bitmapFromDecodeSubset; |
| 197 | // FIXME: Come up with a more representative set of rectangles. |
| 198 | SkIRect rect = generate_random_rect(&rand, width, height); |
| 199 | SkString subsetDim = SkStringPrintf("[%d,%d,%d,%d]", rect.fLeft, rect.fTop, |
| 200 | rect.fRight, rect.fBottom); |
| 201 | if (codec->decodeSubset(&bitmapFromDecodeSubset, rect, SkBitmap::kNo_Config)) { |
| 202 | gSuccessfulSubsetDecodes.push_back().printf("Decoded subset %s from %s", |
| 203 | subsetDim.c_str(), srcPath); |
| 204 | if (writePath != NULL) { |
| 205 | // Write the region to a file whose name includes the dimensions. |
| 206 | SkString suffix = SkStringPrintf("_%s.png", subsetDim.c_str()); |
| 207 | SkString outPath; |
| 208 | make_outname(&outPath, writePath->c_str(), srcPath, suffix.c_str()); |
| scroggo@google.com | 8b5ff5c | 2013-05-03 20:21:17 +0000 | [diff] [blame^] | 209 | SkDEBUGCODE(bool success =) |
| 210 | write_bitmap(outPath.c_str(), &bitmapFromDecodeSubset); |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 211 | SkASSERT(success); |
| 212 | gSuccessfulSubsetDecodes.push_back().printf("\twrote %s", outPath.c_str()); |
| 213 | // Also use extractSubset from the original for visual comparison. |
| 214 | SkBitmap extractedSubset; |
| 215 | if (bitmap.extractSubset(&extractedSubset, rect)) { |
| 216 | suffix.printf("_%s_extracted.png", subsetDim.c_str()); |
| 217 | make_outname(&outPath, writePath->c_str(), srcPath, suffix.c_str()); |
| 218 | success = write_bitmap(outPath.c_str(), &extractedSubset); |
| 219 | SkASSERT(success); |
| 220 | } |
| 221 | } |
| 222 | } else { |
| 223 | gFailedSubsetDecodes.push_back().printf("Failed to decode region %s from %s\n", |
| 224 | subsetDim.c_str(), srcPath); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 229 | if (FLAGS_reencode) { |
| 230 | // Encode to the format the file was originally in, or PNG if the encoder for the same |
| 231 | // format is unavailable. |
| 232 | SkImageDecoder::Format format = codec->getFormat(); |
| 233 | if (SkImageDecoder::kUnknown_Format == format) { |
| 234 | if (stream.rewind()) { |
| 235 | format = SkImageDecoder::GetStreamFormat(&stream); |
| 236 | } |
| 237 | if (SkImageDecoder::kUnknown_Format == format) { |
| 238 | const char* dot = strrchr(srcPath, '.'); |
| 239 | if (NULL != dot) { |
| 240 | format = guess_format_from_suffix(dot); |
| 241 | } |
| 242 | if (SkImageDecoder::kUnknown_Format == format) { |
| 243 | SkDebugf("Could not determine type for '%s'\n", srcPath); |
| 244 | format = SkImageDecoder::kPNG_Format; |
| 245 | } |
| 246 | |
| 247 | } |
| 248 | } else { |
| 249 | SkASSERT(!stream.rewind() || SkImageDecoder::GetStreamFormat(&stream) == format); |
| 250 | } |
| 251 | SkImageEncoder::Type type = format_to_type(format); |
| 252 | // format should never be kUnknown_Format, so type should never be kUnknown_Type. |
| 253 | SkASSERT(type != SkImageEncoder::kUnknown_Type); |
| 254 | |
| 255 | SkImageEncoder* encoder = SkImageEncoder::Create(type); |
| 256 | if (NULL == encoder) { |
| 257 | type = SkImageEncoder::kPNG_Type; |
| 258 | encoder = SkImageEncoder::Create(type); |
| 259 | SkASSERT(encoder); |
| 260 | } |
| 261 | SkAutoTDelete<SkImageEncoder> ade(encoder); |
| 262 | // Encode to a stream. |
| 263 | SkDynamicMemoryWStream wStream; |
| 264 | if (!encoder->encodeStream(&wStream, bitmap, 100)) { |
| 265 | gEncodeFailures.push_back().printf("Failed to reencode %s to type '%s'", srcPath, |
| 266 | suffix_for_type(type)); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | SkAutoTUnref<SkData> data(wStream.copyToData()); |
| 271 | if (writePath != NULL && type != SkImageEncoder::kPNG_Type) { |
| 272 | // Write the encoded data to a file. Do not write to PNG, which will be written later, |
| 273 | // regardless of the input format. |
| 274 | SkString outPath; |
| 275 | make_outname(&outPath, writePath->c_str(), srcPath, suffix_for_type(type)); |
| 276 | SkFILEWStream file(outPath.c_str()); |
| 277 | if(file.write(data->data(), data->size())) { |
| 278 | gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str()); |
| 279 | } else { |
| 280 | gEncodeFailures.push_back().printf("Failed to write %s", outPath.c_str()); |
| 281 | } |
| 282 | } |
| 283 | // Ensure that the reencoded data can still be decoded. |
| 284 | SkMemoryStream memStream(data); |
| 285 | SkBitmap redecodedBitmap; |
| 286 | SkImageDecoder::Format formatOnSecondDecode; |
| 287 | if (SkImageDecoder::DecodeStream(&memStream, &redecodedBitmap, SkBitmap::kNo_Config, |
| 288 | SkImageDecoder::kDecodePixels_Mode, |
| 289 | &formatOnSecondDecode)) { |
| 290 | SkASSERT(format_to_type(formatOnSecondDecode) == type); |
| 291 | } else { |
| 292 | gDecodeFailures.push_back().printf("Failed to redecode %s after reencoding to '%s'", |
| 293 | srcPath, suffix_for_type(type)); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (writePath != NULL) { |
| 298 | SkString outPath; |
| 299 | make_outname(&outPath, writePath->c_str(), srcPath, ".png"); |
| 300 | if (write_bitmap(outPath.c_str(), &bitmap)) { |
| 301 | gSuccessfulDecodes.push_back().appendf("\twrote %s", outPath.c_str()); |
| 302 | } else { |
| 303 | gEncodeFailures.push_back().set(outPath); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /////////////////////////////////////////////////////////////////////////////// |
| 309 | |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 310 | // If strings is not empty, print title, followed by each string on its own line starting |
| 311 | // with a tab. |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 312 | // @return bool True if strings had at least one entry. |
| 313 | static bool print_strings(const char* title, const SkTArray<SkString, false>& strings) { |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 314 | if (strings.count() > 0) { |
| 315 | SkDebugf("%s:\n", title); |
| 316 | for (int i = 0; i < strings.count(); i++) { |
| 317 | SkDebugf("\t%s\n", strings[i].c_str()); |
| 318 | } |
| 319 | SkDebugf("\n"); |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 320 | return true; |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 321 | } |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 322 | return false; |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 325 | int tool_main(int argc, char** argv); |
| 326 | int tool_main(int argc, char** argv) { |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 327 | SkCommandLineFlags::SetUsage("Decode files, and optionally write the results to files."); |
| 328 | SkCommandLineFlags::Parse(argc, argv); |
| 329 | |
| 330 | if (FLAGS_readPath.count() < 1) { |
| 331 | SkDebugf("Folder(s) or image(s) to decode are required.\n"); |
| 332 | return -1; |
| 333 | } |
| 334 | |
| 335 | |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 336 | SkAutoGraphics ag; |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 337 | |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 338 | SkString outDir; |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 339 | SkString* outDirPtr; |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 340 | |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 341 | if (FLAGS_writePath.count() == 1) { |
| 342 | outDir.set(FLAGS_writePath[0]); |
| 343 | if (outDir.c_str()[outDir.size() - 1] != '/') { |
| 344 | outDir.append("/"); |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 345 | } |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 346 | outDirPtr = &outDir; |
| 347 | } else { |
| 348 | outDirPtr = NULL; |
| 349 | } |
| 350 | |
| 351 | for (int i = 0; i < FLAGS_readPath.count(); i++) { |
| 352 | if (strlen(FLAGS_readPath[i]) < 1) { |
| 353 | break; |
| 354 | } |
| 355 | SkOSFile::Iter iter(FLAGS_readPath[i]); |
| 356 | SkString filename; |
| 357 | if (iter.next(&filename)) { |
| 358 | SkString directory(FLAGS_readPath[i]); |
| 359 | if (directory[directory.size() - 1] != '/') { |
| 360 | directory.append("/"); |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 361 | } |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 362 | do { |
| 363 | SkString fullname(directory); |
| 364 | fullname.append(filename); |
| 365 | decodeFileAndWrite(fullname.c_str(), outDirPtr); |
| 366 | } while (iter.next(&filename)); |
| 367 | } else { |
| 368 | decodeFileAndWrite(FLAGS_readPath[i], outDirPtr); |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| scroggo@google.com | b41ff95 | 2013-04-11 15:53:35 +0000 | [diff] [blame] | 372 | // Add some space, since codecs may print warnings without newline. |
| 373 | SkDebugf("\n\n"); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 374 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 375 | bool failed = print_strings("Invalid files", gInvalidStreams); |
| 376 | failed |= print_strings("Missing codec", gMissingCodecs); |
| 377 | failed |= print_strings("Failed to decode", gDecodeFailures); |
| 378 | failed |= print_strings("Failed to encode", gEncodeFailures); |
| 379 | print_strings("Decoded", gSuccessfulDecodes); |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 380 | |
| scroggo@google.com | 7e6fcee | 2013-05-03 20:14:28 +0000 | [diff] [blame] | 381 | if (FLAGS_testSubsetDecoding) { |
| 382 | failed |= print_strings("Failed subset decodes", gFailedSubsetDecodes); |
| 383 | print_strings("Decoded subsets", gSuccessfulSubsetDecodes); |
| 384 | } |
| 385 | |
| scroggo@google.com | 39edf4c | 2013-04-25 17:33:51 +0000 | [diff] [blame] | 386 | return failed ? -1 : 0; |
| reed@android.com | af45979 | 2009-04-24 19:52:53 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 389 | #if !defined SK_BUILD_FOR_IOS |
| 390 | int main(int argc, char * const argv[]) { |
| 391 | return tool_main(argc, (char**) argv); |
| 392 | } |
| 393 | #endif |