Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: tools/render_pictures_main.cpp

Issue 1018953003: Add SkEncodedFormat, used by SkCodec. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use a common enum for SkImageEncoder and SkImageDecoder and SkCodec Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "LazyDecodeBitmap.h" 8 #include "LazyDecodeBitmap.h"
9 #include "CopyTilesRenderer.h" 9 #include "CopyTilesRenderer.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as " 55 DEFINE_bool(validate, false, "Verify that the rendered image contains the same p ixels as "
56 "the picture rendered in simple mode. When used in conjunction with --bbh, results " 56 "the picture rendered in simple mode. When used in conjunction with --bbh, results "
57 "are validated against the picture rendered in the same mode, but wi thout the bbh."); 57 "are validated against the picture rendered in the same mode, but wi thout the bbh.");
58 58
59 //////////////////////////////////////////////////////////////////////////////// //////////////////// 59 //////////////////////////////////////////////////////////////////////////////// ////////////////////
60 60
61 /** 61 /**
62 * Table for translating from format of data to a suffix. 62 * Table for translating from format of data to a suffix.
63 */ 63 */
64 struct Format { 64 struct Format {
65 SkImageDecoder::Format fFormat; 65 SkEncodedFormat fFormat;
66 const char* fSuffix; 66 const char* fSuffix;
67 }; 67 };
68 static const Format gFormats[] = { 68 static const Format gFormats[] = {
69 { SkImageDecoder::kBMP_Format, ".bmp" }, 69 { kBMP_SkEncodedFormat, ".bmp" },
70 { SkImageDecoder::kGIF_Format, ".gif" }, 70 { kGIF_SkEncodedFormat, ".gif" },
71 { SkImageDecoder::kICO_Format, ".ico" }, 71 { kICO_SkEncodedFormat, ".ico" },
72 { SkImageDecoder::kJPEG_Format, ".jpg" }, 72 { kJPEG_SkEncodedFormat, ".jpg" },
73 { SkImageDecoder::kPNG_Format, ".png" }, 73 { kPNG_SkEncodedFormat, ".png" },
74 { SkImageDecoder::kWBMP_Format, ".wbmp" }, 74 { kWBMP_SkEncodedFormat, ".wbmp" },
75 { SkImageDecoder::kWEBP_Format, ".webp" }, 75 { kWEBP_SkEncodedFormat, ".webp" },
76 { SkImageDecoder::kUnknown_Format, "" }, 76 { kUnknown_SkEncodedFormat, "" },
77 }; 77 };
78 78
79 /** 79 /**
80 * Get an appropriate suffix for an image format. 80 * Get an appropriate suffix for an image format.
81 */ 81 */
82 static const char* get_suffix_from_format(SkImageDecoder::Format format) { 82 static const char* get_suffix_from_format(SkEncodedFormat format) {
83 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) { 83 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormats); i++) {
84 if (gFormats[i].fFormat == format) { 84 if (gFormats[i].fFormat == format) {
85 return gFormats[i].fSuffix; 85 return gFormats[i].fSuffix;
86 } 86 }
87 } 87 }
88 return ""; 88 return "";
89 } 89 }
90 90
91 /** 91 /**
92 * Base name for an image file created from the encoded data in an skp. 92 * Base name for an image file created from the encoded data in an skp.
(...skipping 24 matching lines...) Expand all
117 } 117 }
118 } 118 }
119 119
120 /** 120 /**
121 * Write the raw encoded bitmap data to a file. 121 * Write the raw encoded bitmap data to a file.
122 */ 122 */
123 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) { 123 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) {
124 SkASSERT(!FLAGS_writePath.isEmpty()); 124 SkASSERT(!FLAGS_writePath.isEmpty());
125 SkMemoryStream memStream(buffer, size); 125 SkMemoryStream memStream(buffer, size);
126 SkString outPath; 126 SkString outPath;
127 SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&memStream); 127 SkEncodedFormat format = SkImageDecoder::GetStreamFormat(&memStream);
128 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++ , 128 SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++ ,
129 get_suffix_from_format(format)); 129 get_suffix_from_format(format));
130 SkString dir(FLAGS_writePath[0]); 130 SkString dir(FLAGS_writePath[0]);
131 outPath = SkOSPath::Join(dir.c_str(), name.c_str()); 131 outPath = SkOSPath::Join(dir.c_str(), name.c_str());
132 SkFILEWStream fileStream(outPath.c_str()); 132 SkFILEWStream fileStream(outPath.c_str());
133 if (!(fileStream.isValid() && fileStream.write(buffer, size))) { 133 if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
134 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str()); 134 SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
135 } 135 }
136 // Put in a dummy bitmap. 136 // Put in a dummy bitmap.
137 return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType , 137 return SkImageDecoder::DecodeStream(&memStream, bitmap, kUnknown_SkColorType ,
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); 504 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
505 } 505 }
506 return 0; 506 return 0;
507 } 507 }
508 508
509 #if !defined SK_BUILD_FOR_IOS 509 #if !defined SK_BUILD_FOR_IOS
510 int main(int argc, char * const argv[]) { 510 int main(int argc, char * const argv[]) {
511 return tool_main(argc, (char**) argv); 511 return tool_main(argc, (char**) argv);
512 } 512 }
513 #endif 513 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698