FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/src/_backend_agg.cpp at main · commit-0/matplotlib · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
commit-0
/
matplotlib
Public
forked from
matplotlib/matplotlib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
src
/
_backend_agg.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
166 lines (138 loc) · 5.48 KB
Breadcrumbs
matplotlib
/
src
/
_backend_agg.cpp
Copy path
File metadata and controls
166 lines (138 loc) · 5.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
-*- mode: c++; c-basic-offset: 4 -*-
*/
#
define
NO_IMPORT_ARRAY
#
include
<
Python.h
>
#
include
"
_backend_agg.h
"
RendererAgg::RendererAgg
(
unsigned
int
width,
unsigned
int
height,
double
dpi)
: width(width),
height(height),
dpi(dpi),
NUMBYTES((
size_t
)width * (
size_t
)height * 4),
pixBuffer(
NULL
),
renderingBuffer(),
alphaBuffer(
NULL
),
alphaMaskRenderingBuffer(),
alphaMask(alphaMaskRenderingBuffer),
pixfmtAlphaMask(alphaMaskRenderingBuffer),
rendererBaseAlphaMask(),
rendererAlphaMask(),
scanlineAlphaMask(),
slineP8(),
slineBin(),
pixFmt(),
rendererBase(),
rendererAA(),
rendererBin(),
theRasterizer(
32768
),
lastclippath(
NULL
),
_fill_color(agg::rgba(
1
,
1
,
1
,
0
))
{
if
(dpi <=
0.0
) {
throw
std::range_error
(
"
dpi must be positive
"
);
}
if
(width >=
1
<<
23
|| height >=
1
<<
23
) {
throw
std::range_error
(
"
Image size of
"
+
std::to_string
(width) +
"
x
"
+
std::to_string
(height) +
"
pixels is too large. It must be less than 2^23 in each direction.
"
);
}
unsigned
stride
(width *
4
);
pixBuffer =
new
agg::int8u[
NUMBYTES
];
renderingBuffer.
attach
(pixBuffer, width, height, stride);
pixFmt.
attach
(renderingBuffer);
rendererBase.
attach
(pixFmt);
rendererBase.
clear
(_fill_color);
rendererAA.
attach
(rendererBase);
rendererBin.
attach
(rendererBase);
hatch_size =
int
(dpi);
hatchBuffer =
new
agg::int8u[hatch_size * hatch_size *
4
];
hatchRenderingBuffer.
attach
(hatchBuffer, hatch_size, hatch_size, hatch_size *
4
);
}
RendererAgg::~RendererAgg
()
{
delete[]
hatchBuffer;
delete[]
alphaBuffer;
delete[]
pixBuffer;
}
void
RendererAgg::create_alpha_buffers
()
{
if
(!alphaBuffer) {
alphaBuffer =
new
agg::int8u[width * height];
alphaMaskRenderingBuffer.
attach
(alphaBuffer, width, height, width);
rendererBaseAlphaMask.
attach
(pixfmtAlphaMask);
rendererAlphaMask.
attach
(rendererBaseAlphaMask);
}
}
BufferRegion *
RendererAgg::copy_from_bbox
(agg::rect_d in_rect)
{
agg::rect_i
rect
(
(
int
)in_rect.
x1
, height - (
int
)in_rect.
y2
, (
int
)in_rect.
x2
, height - (
int
)in_rect.
y1
);
BufferRegion *reg =
NULL
;
reg =
new
BufferRegion
(rect);
agg::rendering_buffer rbuf;
rbuf.
attach
(reg->
get_data
(), reg->
get_width
(), reg->
get_height
(), reg->
get_stride
());
pixfmt
pf
(rbuf);
renderer_base
rb
(pf);
rb.
copy_from
(renderingBuffer, &rect, -rect.
x1
, -rect.
y1
);
return
reg;
}
void
RendererAgg::restore_region
(BufferRegion ®ion)
{
if
(region.
get_data
() ==
NULL
) {
throw
std::runtime_error
(
"
Cannot restore_region from NULL data
"
);
}
agg::rendering_buffer rbuf;
rbuf.
attach
(region.
get_data
(), region.
get_width
(), region.
get_height
(), region.
get_stride
());
rendererBase.
copy_from
(rbuf,
0
, region.
get_rect
().
x1
, region.
get_rect
().
y1
);
}
//
Restore the part of the saved region with offsets
void
RendererAgg::restore_region
(BufferRegion ®ion,
int
xx1,
int
yy1,
int
xx2,
int
yy2,
int
x,
int
y )
{
if
(region.
get_data
() ==
NULL
) {
throw
std::runtime_error
(
"
Cannot restore_region from NULL data
"
);
}
agg::rect_i &rrect = region.
get_rect
();
agg::rect_i
rect
(xx1 - rrect.
x1
, (yy1 - rrect.
y1
), xx2 - rrect.
x1
, (yy2 - rrect.
y1
));
agg::rendering_buffer rbuf;
rbuf.
attach
(region.
get_data
(), region.
get_width
(), region.
get_height
(), region.
get_stride
());
rendererBase.
copy_from
(rbuf, &rect, x, y);
}
bool
RendererAgg::render_clippath
(mpl::PathIterator &clippath,
const
agg::trans_affine &clippath_trans,
e_snap_mode snap_mode)
{
typedef
agg::conv_transform<mpl::PathIterator>
transformed_path_t
;
typedef
PathNanRemover<
transformed_path_t
>
nan_removed_t
;
/*
Unlike normal Paths, the clip path cannot be clipped to the Figure bbox,
* because it needs to remain a complete closed path, so there is no
* PathClipper<nan_removed_t> step.
*/
typedef
PathSnapper<
nan_removed_t
>
snapped_t
;
typedef
PathSimplifier<
snapped_t
>
simplify_t
;
typedef
agg::conv_curve<
simplify_t
>
curve_t
;
bool
has_clippath = (clippath.
total_vertices
() !=
0
);
if
(has_clippath &&
(clippath.
get_id
() != lastclippath || clippath_trans != lastclippath_transform)) {
create_alpha_buffers
();
agg::trans_affine
trans
(clippath_trans);
trans *=
agg::trans_affine_scaling
(
1.0
, -
1.0
);
trans *=
agg::trans_affine_translation
(
0.0
, (
double
)height);
rendererBaseAlphaMask.
clear
(
agg::gray8
(
0
,
0
));
transformed_path_t
transformed_clippath
(clippath, trans);
nan_removed_t
nan_removed_clippath
(transformed_clippath,
true
, clippath.
has_codes
());
snapped_t
snapped_clippath
(nan_removed_clippath, snap_mode, clippath.
total_vertices
(),
0.0
);
simplify_t
simplified_clippath
(snapped_clippath,
clippath.
should_simplify
() && !clippath.
has_codes
(),
clippath.
simplify_threshold
());
curve_t
curved_clippath
(simplified_clippath);
theRasterizer.
add_path
(curved_clippath);
rendererAlphaMask.
color
(
agg::gray8
(
255
,
255
));
agg::render_scanlines
(theRasterizer, scanlineAlphaMask, rendererAlphaMask);
lastclippath = clippath.
get_id
();
lastclippath_transform = clippath_trans;
}
return
has_clippath;
}
void
RendererAgg::clear
()
{
//
"clear the rendered buffer";
rendererBase.
clear
(_fill_color);
}
Back
|
FazBrowse Home
|
New Git URL