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.
|
|
|
|
*/
|
|
|
|
|
2013-07-16 18:21:46 +00:00
|
|
|
#include "LazyDecodeBitmap.h"
|
2012-06-14 18:58:40 +00:00
|
|
|
#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"
|
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);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
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");
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
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-07-16 18:21:46 +00:00
|
|
|
SkPicture* pic = SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap);
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == pic) {
|
2013-06-12 18:28:36 +00:00
|
|
|
SkDebugf("Could not create SkPicture: %s\n", path);
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2013-06-12 18:28:36 +00:00
|
|
|
}
|
2014-08-29 15:03:56 +00:00
|
|
|
printf("picture cullRect: [%f %f %f %f]\n",
|
|
|
|
pic->cullRect().fLeft, pic->cullRect().fTop,
|
|
|
|
pic->cullRect().fRight, pic->cullRect().fBottom);
|
2012-08-31 15:41:37 +00:00
|
|
|
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);
|
2014-06-04 12:40:44 +00:00
|
|
|
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
|