blob: 306bf6f6a04c1efad874ebe8b7766cb529111b87 [file] [log] [blame]
reed@google.com1bdf7fe2012-06-14 18:58:40 +00001/*
2 * Copyright 2012 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 */
7
commit-bot@chromium.org56799e22013-07-16 18:21:46 +00008#include "LazyDecodeBitmap.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +00009#include "SkBitmap.h"
10#include "SkCanvas.h"
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000011#include "SkGraphics.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000012#include "SkOSFile.h"
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000013#include "SkImageDecoder.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000014#include "SkPicture.h"
15#include "SkStream.h"
16#include "SkString.h"
reed@google.comb1d47e22012-08-31 15:41:37 +000017#include "SkDumpCanvas.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000018
reed@google.comb1d47e22012-08-31 15:41:37 +000019static SkPicture* inspect(const char path[]) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000020 SkFILEStream stream(path);
21 if (!stream.isValid()) {
22 printf("-- Can't open '%s'\n", path);
reed@google.comb1d47e22012-08-31 15:41:37 +000023 return NULL;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000024 }
25
26 printf("Opening '%s'...\n", path);
27
28 {
29 int32_t header[3];
30 if (stream.read(header, sizeof(header)) != sizeof(header)) {
31 printf("-- Failed to read header (12 bytes)\n");
reed@google.comb1d47e22012-08-31 15:41:37 +000032 return NULL;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000033 }
34 printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
35 }
36
37 stream.rewind();
commit-bot@chromium.org56799e22013-07-16 18:21:46 +000038 SkPicture* pic = SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap);
scroggo@google.comf1754ec2013-06-28 21:32:00 +000039 if (NULL == pic) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000040 SkDebugf("Could not create SkPicture: %s\n", path);
scroggo@google.comf1754ec2013-06-28 21:32:00 +000041 return NULL;
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000042 }
reed@google.comb1d47e22012-08-31 15:41:37 +000043 printf("picture size:[%d %d]\n", pic->width(), pic->height());
44 return pic;
45}
46
47static void dumpOps(SkPicture* pic) {
robertphillips@google.com76f9e932013-01-15 20:17:47 +000048#ifdef SK_DEVELOPER
reed@google.comb1d47e22012-08-31 15:41:37 +000049 SkDebugfDumper dumper;
50 SkDumpCanvas canvas(&dumper);
51 canvas.drawPicture(*pic);
robertphillips@google.com76f9e932013-01-15 20:17:47 +000052#else
53 printf("SK_DEVELOPER mode not enabled\n");
54#endif
reed@google.com1bdf7fe2012-06-14 18:58:40 +000055}
56
caryclark@google.com5987f582012-10-02 18:33:14 +000057int tool_main(int argc, char** argv);
58int tool_main(int argc, char** argv) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000059 SkAutoGraphics ag;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000060 if (argc < 2) {
fmalita@google.comc6157be2012-09-27 13:09:58 +000061 printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
62 return 1;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000063 }
reed@google.comb1d47e22012-08-31 15:41:37 +000064
65 bool doDumpOps = false;
66
67 int index = 1;
68 if (!strcmp(argv[index], "--dump-ops")) {
69 index += 1;
70 doDumpOps = true;
71 }
72
73 for (; index < argc; ++index) {
74 SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
75 if (doDumpOps) {
76 dumpOps(pic);
77 }
78 if (index < argc - 1) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000079 printf("\n");
80 }
81 }
82 return 0;
83}
caryclark@google.com5987f582012-10-02 18:33:14 +000084
85#if !defined SK_BUILD_FOR_IOS
86int main(int argc, char * const argv[]) {
87 return tool_main(argc, (char**) argv);
88}
89#endif