1/*
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
8#include "LazyDecodeBitmap.h"
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkGraphics.h"
12#include "SkOSFile.h"
13#include "SkImageDecoder.h"
14#include "SkPicture.h"
15#include "SkStream.h"
16#include "SkString.h"
17#include "SkDumpCanvas.h"
18
19static SkPicture* inspect(const char path[]) {
20    SkFILEStream stream(path);
21    if (!stream.isValid()) {
22        printf("-- Can't open '%s'\n", path);
23        return NULL;
24    }
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");
32            return NULL;
33        }
34        printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
35    }
36
37    stream.rewind();
38    SkPicture* pic = SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap);
39    if (NULL == pic) {
40        SkDebugf("Could not create SkPicture: %s\n", path);
41        return NULL;
42    }
43    printf("picture cullRect: [%f %f %f %f]\n",
44           pic->cullRect().fLeft, pic->cullRect().fTop,
45           pic->cullRect().fRight, pic->cullRect().fBottom);
46    return pic;
47}
48
49static void dumpOps(SkPicture* pic) {
50#ifdef SK_DEVELOPER
51    SkDebugfDumper dumper;
52    SkDumpCanvas canvas(&dumper);
53    canvas.drawPicture(pic);
54#else
55    printf("SK_DEVELOPER mode not enabled\n");
56#endif
57}
58
59int tool_main(int argc, char** argv);
60int tool_main(int argc, char** argv) {
61    SkAutoGraphics ag;
62    if (argc < 2) {
63        printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
64        return 1;
65    }
66
67    bool doDumpOps = false;
68
69    int index = 1;
70    if (!strcmp(argv[index], "--dump-ops")) {
71        index += 1;
72        doDumpOps = true;
73    }
74
75    for (; index < argc; ++index) {
76        SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
77        if (doDumpOps) {
78            dumpOps(pic);
79        }
80        if (index < argc - 1) {
81            printf("\n");
82        }
83    }
84    return 0;
85}
86
87#if !defined SK_BUILD_FOR_IOS
88int main(int argc, char * const argv[]) {
89    return tool_main(argc, (char**) argv);
90}
91#endif
92