| OLD | NEW |
| 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 "CopyTilesRenderer.h" | 8 #include "CopyTilesRenderer.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 SkString inputFilename; | 142 SkString inputFilename; |
| 143 sk_tools::get_basename(&inputFilename, inputPath); | 143 sk_tools::get_basename(&inputFilename, inputPath); |
| 144 | 144 |
| 145 SkFILEStream inputStream; | 145 SkFILEStream inputStream; |
| 146 inputStream.setPath(inputPath.c_str()); | 146 inputStream.setPath(inputPath.c_str()); |
| 147 if (!inputStream.isValid()) { | 147 if (!inputStream.isValid()) { |
| 148 SkDebugf("Could not open file %s\n", inputPath.c_str()); | 148 SkDebugf("Could not open file %s\n", inputPath.c_str()); |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool success = false; | 152 SkPicture::InstallPixelRefProc proc; |
| 153 SkPicture* picture; | |
| 154 if (FLAGS_deferImageDecoding) { | 153 if (FLAGS_deferImageDecoding) { |
| 155 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi
tmap)); | 154 proc = &lazy_decode_bitmap; |
| 156 } else if (FLAGS_writeEncodedImages) { | 155 } else if (FLAGS_writeEncodedImages) { |
| 157 SkASSERT(!FLAGS_writePath.isEmpty()); | 156 SkASSERT(!FLAGS_writePath.isEmpty()); |
| 158 reset_image_file_base_name(inputFilename); | 157 reset_image_file_base_name(inputFilename); |
| 159 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &write_image_to
_file)); | 158 proc = &write_image_to_file; |
| 160 } else { | 159 } else { |
| 161 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder
::DecodeMemory)); | 160 proc = &SkImageDecoder::DecodeMemory; |
| 162 } | 161 } |
| 163 | 162 |
| 164 if (!success) { | 163 SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc); |
| 164 |
| 165 if (NULL == picture) { |
| 165 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); | 166 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 166 return false; | 167 return false; |
| 167 } | 168 } |
| 168 | 169 |
| 169 for (int i = 0; i < FLAGS_clone; ++i) { | 170 for (int i = 0; i < FLAGS_clone; ++i) { |
| 170 SkPicture* clone = picture->clone(); | 171 SkPicture* clone = picture->clone(); |
| 171 SkDELETE(picture); | 172 SkDELETE(picture); |
| 172 picture = clone; | 173 picture = clone; |
| 173 } | 174 } |
| 174 | 175 |
| 175 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), | 176 SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(), |
| 176 inputPath.c_str()); | 177 inputPath.c_str()); |
| 177 | 178 |
| 178 renderer.init(picture); | 179 renderer.init(picture); |
| 179 renderer.setup(); | 180 renderer.setup(); |
| 180 | 181 |
| 181 SkString* outputPath = NULL; | 182 SkString* outputPath = NULL; |
| 182 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages)
{ | 183 if (NULL != outputDir && outputDir->size() > 0 && !FLAGS_writeEncodedImages)
{ |
| 183 outputPath = SkNEW(SkString); | 184 outputPath = SkNEW(SkString); |
| 184 make_output_filepath(outputPath, *outputDir, inputFilename); | 185 make_output_filepath(outputPath, *outputDir, inputFilename); |
| 185 } | 186 } |
| 186 | 187 |
| 187 success = renderer.render(outputPath, out); | 188 bool success = renderer.render(outputPath, out); |
| 188 if (outputPath) { | 189 if (outputPath) { |
| 189 if (!success) { | 190 if (!success) { |
| 190 SkDebugf("Could not write to file %s\n", outputPath->c_str()); | 191 SkDebugf("Could not write to file %s\n", outputPath->c_str()); |
| 191 } | 192 } |
| 192 SkDELETE(outputPath); | 193 SkDELETE(outputPath); |
| 193 } | 194 } |
| 194 | 195 |
| 195 renderer.end(); | 196 renderer.end(); |
| 196 | 197 |
| 197 SkDELETE(picture); | 198 SkDELETE(picture); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 #endif | 441 #endif |
| 441 #endif | 442 #endif |
| 442 return 0; | 443 return 0; |
| 443 } | 444 } |
| 444 | 445 |
| 445 #if !defined SK_BUILD_FOR_IOS | 446 #if !defined SK_BUILD_FOR_IOS |
| 446 int main(int argc, char * const argv[]) { | 447 int main(int argc, char * const argv[]) { |
| 447 return tool_main(argc, (char**) argv); | 448 return tool_main(argc, (char**) argv); |
| 448 } | 449 } |
| 449 #endif | 450 #endif |
| OLD | NEW |