Commit 79a0d920 authored by Linshizhi's avatar Linshizhi

Add Canvas.

parent c1c62133
skia @ 6886d924
Subproject commit f905f5fd8a0634968ed2cf148366cb4f9d47d187
Subproject commit 6886d924a06e06f6a49f95fc4f8e555caa306cd3
cc_library(
name = "render",
srcs = ["canvas.cc"],
hdrs = ["canvas.h"],
name = "try",
srcs = ["try.cc"],
hdrs = ["try.h"],
deps = [
"@skia//:skia_svg",
"@skia//:skia",
],
copts = [
"-I./external/ffmpeg/include",
"-std=c++2a"
"-std=c++2a",
],
visibility = [
"//app:__pkg__",
......
#include <stdio.h>
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "include/core/SkRefCnt.h"
#include "modules/svg/include/SkSVGDOM.h"
int example(void) {
SkCanvas canvas = SkCanvas();
SkFILEStream svgStream("./example");
sk_sp<SkSVGDOM> fDom = SkSVGDOM::MakeFromStream(svgStream);
return 0;
}
int example();
#ifndef CANVAS_H
#define CANVAS_H
enum PixelTypes {};
class Canvas {
public:
Canvas(int width, int height, PixelTypes pixType);
};
#endif /* CANVAS_H */
#include <iostream>
#include <fstream>
#include <string>
#include "include/core/SkSurface.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "include/core/SkRefCnt.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkColorType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkImage.h"
#include "include/core/SkEncodedImageFormat.h"
#include "include/core/SkData.h"
int example(void) {
const int width = 1920;
const int height = 1080;
const int pixelBytes = 4;
SkImageInfo imgInfo = SkImageInfo::Make(
width, height, kBGRA_8888_SkColorType, kOpaque_SkAlphaType);
size_t size = 1920 * 1080 * 4;
uint8_t *buffer = new uint8_t[size];
auto canvas = SkCanvas::MakeRasterDirect(
imgInfo, buffer, imgInfo.width() * pixelBytes);
SkFILEStream svgStream("/home/aydenlin/Downloads/example.svg");
if (!svgStream.isValid()) {
return 1;
}
auto fDom = SkSVGDOM::MakeFromStream(svgStream);
fDom->setContainerSize(SkSize::Make(width, height));
fDom->render(canvas.get());
SkBitmap bitmap{};
bitmap.allocPixels(imgInfo, width * pixelBytes);
if (canvas->readPixels(bitmap, 0, 0) == false) {
return 2;
}
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
if (image == nullptr) {
return 1;
}
sk_sp<SkData> data = image->encodeToData(SkEncodedImageFormat::kPNG, 100);
uint8_t *dataPtr = const_cast<uint8_t*>(data->bytes());
std::ofstream out("/home/aydenlin/Downloads/out.png", std::ios::binary);
for (int i = 0; i < data->size(); ++i) {
out.write(reinterpret_cast<char*>(&dataPtr[i]), 1);
}
out.close();
return 0;
}
int example();
......@@ -10,7 +10,7 @@ cc_test(
"-lz", "-llzma", "-ljpeg", "-lfreetype",
"-lpng", "-lfontconfig", "-lGLX", "-lexpat -lm"],
deps = [
"//src:render",
"//src:try",
"@theft//:theft",
"@gtest//:gtest",
"@gtest//:gtest_main",
......
#include "src/canvas.h"
#include "src/try.h"
#include "gtest/gtest.h"
extern "C" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment