Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
I
IMGRender
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
IMGRender
Commits
79a0d920
Commit
79a0d920
authored
Jul 29, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Canvas.
parent
c1c62133
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
20 deletions
+81
-20
skia
external/skia
+1
-1
BUILD.bazel
src/BUILD.bazel
+4
-4
canvas.cc
src/canvas.cc
+0
-12
canvas.h
src/canvas.h
+11
-1
try.cc
src/try.cc
+61
-0
try.h
src/try.h
+2
-0
BUILD.bazel
tests/BUILD.bazel
+1
-1
check.cc
tests/check.cc
+1
-1
No files found.
skia
@
6886d924
Subproject commit
f905f5fd8a0634968ed2cf148366cb4f9d47d187
Subproject commit
6886d924a06e06f6a49f95fc4f8e555caa306cd3
src/BUILD.bazel
View file @
79a0d920
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__",
...
...
src/canvas.cc
View file @
79a0d920
#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
;
}
src/canvas.h
View file @
79a0d920
int
example
();
#ifndef CANVAS_H
#define CANVAS_H
enum
PixelTypes
{};
class
Canvas
{
public
:
Canvas
(
int
width
,
int
height
,
PixelTypes
pixType
);
};
#endif
/* CANVAS_H */
src/try.cc
0 → 100644
View file @
79a0d920
#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
;
}
src/try.h
0 → 100644
View file @
79a0d920
int
example
();
tests/BUILD.bazel
View file @
79a0d920
...
...
@@ -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",
...
...
tests/check.cc
View file @
79a0d920
#include "src/
canvas
.h"
#include "src/
try
.h"
#include "gtest/gtest.h"
extern
"C"
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment