skp_parser
compiles with GN. NOTRY=true GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2281733003 Review-Url: https://codereview.chromium.org/2281733003
This commit is contained in:
parent
ea4567c1b0
commit
a73d76af31
12
BUILD.gn
12
BUILD.gn
@ -1084,4 +1084,16 @@ if (skia_enable_tools) {
|
||||
]
|
||||
testonly = true
|
||||
}
|
||||
|
||||
executable("skp_parser") {
|
||||
sources = [
|
||||
"tools/skp_parser.cpp",
|
||||
]
|
||||
deps = [
|
||||
":skia",
|
||||
":tool_utils",
|
||||
"//third_party/jsoncpp",
|
||||
]
|
||||
testonly = true
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "SkDrawCommand.h"
|
||||
|
||||
#include "png.h"
|
||||
|
||||
#include "SkBlurMaskFilter.h"
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkDashPathEffect.h"
|
||||
@ -661,7 +663,7 @@ static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t l
|
||||
out->write(data, length);
|
||||
}
|
||||
|
||||
void SkDrawCommand::WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_32 height,
|
||||
void SkDrawCommand::WritePNG(const uint8_t* rgba, unsigned width, unsigned height,
|
||||
SkWStream& out, bool isOpaque) {
|
||||
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
SkASSERT(png != nullptr);
|
||||
@ -678,7 +680,7 @@ void SkDrawCommand::WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_3
|
||||
png_bytepp rows = (png_bytepp) sk_malloc_throw(height * sizeof(png_byte*));
|
||||
png_bytep pixels = (png_bytep) sk_malloc_throw(width * height * 4);
|
||||
for (png_size_t y = 0; y < height; ++y) {
|
||||
const png_bytep src = rgba + y * width * 4;
|
||||
const uint8_t* src = rgba + y * width * 4;
|
||||
rows[y] = pixels + y * width * 4;
|
||||
for (png_size_t x = 0; x < width; ++x) {
|
||||
rows[y][x * 4] = src[x * 4];
|
||||
@ -714,7 +716,7 @@ bool SkDrawCommand::flatten(const SkImage& image, Json::Value* target,
|
||||
sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bm);
|
||||
|
||||
SkDynamicMemoryWStream out;
|
||||
SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->bytes(), image.width(), image.height(),
|
||||
SkDrawCommand::WritePNG(encodedBitmap->bytes(), image.width(), image.height(),
|
||||
out, false);
|
||||
sk_sp<SkData> encoded = out.detachAsData();
|
||||
Json::Value jsonData;
|
||||
|
@ -8,8 +8,6 @@
|
||||
#ifndef SKDRAWCOMMAND_H_
|
||||
#define SKDRAWCOMMAND_H_
|
||||
|
||||
#include "png.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkTLazy.h"
|
||||
#include "SkPath.h"
|
||||
@ -65,7 +63,7 @@ public:
|
||||
|
||||
static const int kOpTypeCount = kLast_OpType + 1;
|
||||
|
||||
static void WritePNG(const png_bytep rgba, png_uint_32 width, png_uint_32 height,
|
||||
static void WritePNG(const uint8_t* rgba, unsigned width, unsigned height,
|
||||
SkWStream& out, bool isOpaque);
|
||||
|
||||
SkDrawCommand(OpType opType);
|
||||
|
@ -63,7 +63,7 @@ sk_sp<SkData> Request::writeCanvasToPng(SkCanvas* canvas) {
|
||||
|
||||
// write to an opaque png (black background)
|
||||
SkDynamicMemoryWStream buffer;
|
||||
SkDrawCommand::WritePNG((const png_bytep) encodedBitmap->bytes(), bmp->width(), bmp->height(),
|
||||
SkDrawCommand::WritePNG(encodedBitmap->bytes(), bmp->width(), bmp->height(),
|
||||
buffer, true);
|
||||
return buffer.detachAsData();
|
||||
}
|
||||
|
59
tools/skp_parser.cpp
Normal file
59
tools/skp_parser.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "SkDebugCanvas.h"
|
||||
#include "SkNullCanvas.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
SkFILEStream input(argv[1]);
|
||||
if (!input.isValid()) {
|
||||
SkDebugf("Bad file: '%s'\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&input);
|
||||
if (!pic) {
|
||||
SkDebugf("Bad skp: '%s'\n", argv[1]);
|
||||
return 3;
|
||||
}
|
||||
SkISize size = pic->cullRect().roundOut().size();
|
||||
SkDebugCanvas debugCanvas(size.width(), size.height());
|
||||
pic->playback(&debugCanvas);
|
||||
sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
|
||||
UrlDataManager dataManager(SkString("data"));
|
||||
Json::Value json = debugCanvas.toJSON(
|
||||
dataManager, debugCanvas.getSize(), nullCanvas.get());
|
||||
if (argc > 2) {
|
||||
if (UrlDataManager::UrlData* data =
|
||||
dataManager.getDataFromUrl(SkString(argv[2]))) {
|
||||
SkData* skdata = data->fData.get();
|
||||
SkASSERT(skdata);
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
fflush(stdout);
|
||||
(void)_setmode(_fileno(stdout), _O_BINARY);
|
||||
#endif
|
||||
fwrite(skdata->data(), skdata->size(), 1, stdout);
|
||||
} else {
|
||||
SkDebugf("Bad data url.\n");
|
||||
return 4;
|
||||
}
|
||||
} else {
|
||||
Json::StyledStreamWriter(" ").write(std::cout, json);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user