2012-06-14 18:58:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
2013-06-12 18:28:36 +00:00
|
|
|
#include "SkGraphics.h"
|
2012-06-14 18:58:40 +00:00
|
|
|
#include "SkOSFile.h"
|
2013-06-12 18:28:36 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2012-06-14 18:58:40 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
2012-08-31 15:41:37 +00:00
|
|
|
#include "SkDumpCanvas.h"
|
2013-06-12 18:28:36 +00:00
|
|
|
#include "SkForceLinking.h"
|
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
// Defined in PictureRenderingFlags.cpp
|
|
|
|
extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
|
2012-06-14 18:58:40 +00:00
|
|
|
|
2012-08-31 15:41:37 +00:00
|
|
|
static SkPicture* inspect(const char path[]) {
|
2012-06-14 18:58:40 +00:00
|
|
|
SkFILEStream stream(path);
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
printf("-- Can't open '%s'\n", path);
|
2012-08-31 15:41:37 +00:00
|
|
|
return NULL;
|
2012-06-14 18:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Opening '%s'...\n", path);
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t header[3];
|
|
|
|
if (stream.read(header, sizeof(header)) != sizeof(header)) {
|
|
|
|
printf("-- Failed to read header (12 bytes)\n");
|
2012-08-31 15:41:37 +00:00
|
|
|
return NULL;
|
2012-06-14 18:58:40 +00:00
|
|
|
}
|
|
|
|
printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.rewind();
|
2013-06-28 21:32:00 +00:00
|
|
|
SkPicture* pic = SkPicture::CreateFromStream(&stream, &lazy_decode_bitmap);
|
|
|
|
if (NULL == pic) {
|
2013-06-12 18:28:36 +00:00
|
|
|
SkDebugf("Could not create SkPicture: %s\n", path);
|
2013-06-28 21:32:00 +00:00
|
|
|
return NULL;
|
2013-06-12 18:28:36 +00:00
|
|
|
}
|
2012-08-31 15:41:37 +00:00
|
|
|
printf("picture size:[%d %d]\n", pic->width(), pic->height());
|
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpOps(SkPicture* pic) {
|
2013-01-15 20:17:47 +00:00
|
|
|
#ifdef SK_DEVELOPER
|
2012-08-31 15:41:37 +00:00
|
|
|
SkDebugfDumper dumper;
|
|
|
|
SkDumpCanvas canvas(&dumper);
|
|
|
|
canvas.drawPicture(*pic);
|
2013-01-15 20:17:47 +00:00
|
|
|
#else
|
|
|
|
printf("SK_DEVELOPER mode not enabled\n");
|
|
|
|
#endif
|
2012-06-14 18:58:40 +00:00
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
2013-06-12 18:28:36 +00:00
|
|
|
SkAutoGraphics ag;
|
2012-06-14 18:58:40 +00:00
|
|
|
if (argc < 2) {
|
2012-09-27 13:09:58 +00:00
|
|
|
printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
|
|
|
|
return 1;
|
2012-06-14 18:58:40 +00:00
|
|
|
}
|
2012-08-31 15:41:37 +00:00
|
|
|
|
|
|
|
bool doDumpOps = false;
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
if (!strcmp(argv[index], "--dump-ops")) {
|
|
|
|
index += 1;
|
|
|
|
doDumpOps = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; index < argc; ++index) {
|
|
|
|
SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
|
|
|
|
if (doDumpOps) {
|
|
|
|
dumpOps(pic);
|
|
|
|
}
|
|
|
|
if (index < argc - 1) {
|
2012-06-14 18:58:40 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|