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
b8f3f49d
Commit
b8f3f49d
authored
Aug 03, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement Canvas.
parent
507026b6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
5 deletions
+61
-5
canvas.cc
src/canvas.cc
+41
-1
canvas.h
src/canvas.h
+7
-4
pixelTypes.h
src/pixelTypes.h
+13
-0
No files found.
src/canvas.cc
View file @
b8f3f49d
#include <exception>
#include "canvas.h"
#include "pixelTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkColorType.h"
std
::
shared_ptr
<
Canvas
>
Canvas
::
MakeCanvas
(
int
width
,
int
height
,
PixelTypes
pixType
)
{
namespace
{
SkColorType
pixelTypeConvert
(
PixelType
type
)
{
switch
(
type
)
{
case
RGBA
:
return
kRGBA_8888_SkColorType
;
default
:
throw
std
::
runtime_error
(
"invalid pixel type"
);
}
}
SkAlphaType
alphaTypeConvert
(
AlphaType
alpha
)
{
switch
(
alpha
)
{
case
PREMUL
:
return
kPremul_SkAlphaType
;
default
:
throw
std
::
runtime_error
(
"invalid alpha type"
);
}
}
};
std
::
unique_ptr
<
Canvas
>
Canvas
::
MakeCanvas
(
int
width
,
int
height
,
PixelType
pixType
,
AlphaType
alpha
)
{
std
::
unique_ptr
<
Canvas
>
canvas
=
std
::
make_unique
<
Canvas
>
(
width
,
height
,
pixType
);
return
canvas
;
}
Canvas
::
Canvas
(
int
width
,
int
height
,
PixelType
pixType
,
AlphaType
alpha
)
:
canvas_
(
nullptr
)
{
SkImageInfo
imgInfo
=
SkImageInfo
::
Make
(
width
,
height
,
pixelTypeConvert
(
pixType
),
alphaTypeConvert
(
alpha
));
uint8_t
*
buffer
=
new
uint8_t
[
width
*
height
*
4
];
canvas_
=
SkCanvas
::
MakeRasterDirect
(
imgInfo
,
buffer
,
width
*
4
);
}
src/canvas.h
View file @
b8f3f49d
#include <memory>
#include "pixelTypes.h"
#include "include/core/SkCanvas.h"
#include "Drawable.h"
#ifndef CANVAS_H
#define CANVAS_H
enum
PixelTypes
{};
class
Canvas
{
public
:
static
std
::
shared_ptr
<
Canvas
>
MakeCanvas
(
int
width
,
int
height
,
PixelTypes
pixType
);
static
std
::
unique_ptr
<
Canvas
>
MakeCanvas
(
int
width
,
int
height
,
PixelType
pixType
,
AlphaType
alpha
);
template
<
typename
T
>
bool
draw
(
Drawable
<
T
>*
drawable
);
protected
:
Canvas
(
int
width
,
int
height
,
PixelTypes
pixType
);
Canvas
(
int
width
,
int
height
,
PixelType
pixType
,
AlphaType
alpha
);
private
:
std
::
unique_ptr
<
SkCanvas
>
canvas_
;
};
#endif
/* CANVAS_H */
src/pixelTypes.h
0 → 100644
View file @
b8f3f49d
#ifndef PIXELTYPES_H
#define PIXELTYPES_H
enum
PixelType
{
RGBA
=
0
,
};
enum
AlphaType
{
PREMUL
,
};
#endif
/* PIXELTYPES_H */
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