180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkBitmap.h" 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkCanvas.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkOSFile.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPicture.h" 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkStream.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkString.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDumpCanvas.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic SkPicture* inspect(const char path[]) { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkFILEStream stream(path); 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!stream.isValid()) { 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("-- Can't open '%s'\n", path); 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("Opening '%s'...\n", path); 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru { 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int32_t header[3]; 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (stream.read(header, sizeof(header)) != sizeof(header)) { 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("-- Failed to read header (12 bytes)\n"); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return NULL; 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]); 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru stream.rewind(); 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream)); 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("picture size:[%d %d]\n", pic->width(), pic->height()); 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return pic; 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustatic void dumpOps(SkPicture* pic) { 42d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger#ifdef SK_DEVELOPER 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugfDumper dumper; 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDumpCanvas canvas(&dumper); 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru canvas.drawPicture(*pic); 46d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger#else 47d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger printf("SK_DEVELOPER mode not enabled\n"); 48d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger#endif 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint tool_main(int argc, char** argv); 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint tool_main(int argc, char** argv) { 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (argc < 2) { 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("Usage: pinspect [--dump-ops] filename [filename ...]\n"); 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return 1; 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru bool doDumpOps = false; 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru int index = 1; 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!strcmp(argv[index], "--dump-ops")) { 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru index += 1; 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru doDumpOps = true; 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru for (; index < argc; ++index) { 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkAutoTUnref<SkPicture> pic(inspect(argv[index])); 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (doDumpOps) { 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpOps(pic); 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (index < argc - 1) { 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru printf("\n"); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return 0; 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if !defined SK_BUILD_FOR_IOS 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruint main(int argc, char * const argv[]) { 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return tool_main(argc, (char**) argv); 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 83