Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
matplotlib/src/agg_workaround.h at main · matplotlib/matplotlib · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
matplotlib
matplotlib
Repository navigation
Code
Issues
1k
(1k)
Pull requests
424
(424)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
matplotlib
/
src
/
agg_workaround.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
199 lines (171 loc) · 6.98 KB
main
Breadcrumbs
matplotlib
/
src
/
agg_workaround.h
Copy path
Top
File metadata and controls
Code
Blame
199 lines (171 loc) · 6.98 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#
ifndef
MPL_AGG_WORKAROUND_H
#
define
MPL_AGG_WORKAROUND_H
#
include
"
agg_pixfmt_rgba.h
"
#
include
"
agg_trans_affine.h
"
/*
*********************************************************************
WORKAROUND: This class is to workaround a bug in Agg SVN where the
blending of RGBA8 pixels does not preserve enough precision
*/
template
<
class
ColorT
,
class
Order
>
struct
fixed_blender_rgba_plain
: agg::conv_rgba_plain<ColorT, Order>
{
typedef
ColorT color_type;
typedef
Order order_type;
typedef
typename
color_type::value_type value_type;
typedef
typename
color_type::calc_type calc_type;
typedef
typename
color_type::long_type long_type;
enum
base_scale_e { base_shift = color_type::base_shift };
//
--------------------------------------------------------------------
static
AGG_INLINE
void
blend_pix
(value_type* p,
value_type cr, value_type cg, value_type cb, value_type alpha, agg::cover_type cover)
{
blend_pix
(p, cr, cg, cb,
color_type::mult_cover
(alpha, cover));
}
//
--------------------------------------------------------------------
static
AGG_INLINE
void
blend_pix
(value_type* p,
value_type cr, value_type cg, value_type cb, value_type alpha)
{
if
(alpha ==
0
)
return
;
//
The following code does not accurately transform to higher bit depth
//
TODO: Improve the accuracy of this code when we are prepared to regenerate all baseline images
calc_type a = p[Order::A];
calc_type r = p[Order::R] * a;
calc_type g = p[Order::G] * a;
calc_type b = p[Order::B] * a;
a = ((alpha + a) << base_shift) - alpha * a;
p[Order::A] = (value_type)(a >> base_shift);
p[Order::R] = (value_type)((((cr << base_shift) - r) * alpha + (r << base_shift)) / a);
p[Order::G] = (value_type)((((cg << base_shift) - g) * alpha + (g << base_shift)) / a);
p[Order::B] = (value_type)((((cb << base_shift) - b) * alpha + (b << base_shift)) / a);
}
};
/*
*********************************************************************
WORKAROUND: As above, this class is to workaround a bug in Agg where
the plain->plain blending of RGBA8 pixels is forced back to 8-bit
values between steps, which degrades the calculation. This class
supports compositing operators (aka blend modes), and falls back to
the above class for normal alpha blending.
*/
template
<
class
Order
>
struct
fixed_comp_op_adaptor_rgba8_plain
{
typedef
agg::rgba8 color_type;
typedef
Order order_type;
typedef
typename
color_type::value_type value_type;
typedef
typename
color_type::calc_type calc_type;
typedef
typename
color_type::long_type long_type;
static
AGG_INLINE
void
blend_pix
(
unsigned
op, value_type* p,
value_type r, value_type g, value_type b, value_type a, agg::cover_type cover)
{
if
(op == agg::comp_op_src_over)
{
//
This operator is simply normal alpha blending, so fall back to the above class
//
We need to special-case fully opaque to maintain past behavior
if
(a ==
255
&& cover == agg::cover_full) {
p[Order::A] = a;
p[Order::R] = r;
p[Order::G] = g;
p[Order::B] = b;
return
;
}
fixed_blender_rgba_plain<agg::rgba8, Order>::
blend_pix
(p, r, g, b, a, cover);
}
else
{
if
(a ==
0
|| cover ==
0
)
return
;
//
Convert to RGBA32 (floats) and premultiply
float
d[
4
];
for
(
int
i =
0
; i <
4
; i++) d[i] =
agg::rgba8::to_double
(p[i]);
agg::multiplier_rgba<agg::rgba32, Order>::
premultiply
(d);
double
sa =
agg::rgba8::to_double
(a);
double
sr =
agg::rgba8::to_double
(r) * sa;
double
sg =
agg::rgba8::to_double
(g) * sa;
double
sb =
agg::rgba8::to_double
(b) * sa;
//
Blend as floats (internally, doubles)
agg::comp_op_table_rgba<agg::rgba32, Order>::g_comp_op_func[op](d, sr, sg, sb, sa, cover);
//
Demultiply and return to RGBA8 space
agg::multiplier_rgba<agg::rgba32, Order>::
demultiply
(d);
for
(
int
i =
0
; i <
4
; i++) p[i] =
agg::rgba8::from_double
(d[i]);
}
}
};
/*
*********************************************************************
This class provides higher-accuracy nearest-neighbor interpolation for
affine transforms than span_interpolator_linear by using
floating-point-based interpolation instead of integer-based
*/
template
<
class
Transformer
= agg::trans_affine,
unsigned
SubpixelShift =
8
>
class
accurate_interpolator_affine_nn
{
public:
typedef
Transformer trans_type;
enum
subpixel_scale_e
{
subpixel_shift = SubpixelShift,
subpixel_scale =
1
<< subpixel_shift
};
//
--------------------------------------------------------------------
accurate_interpolator_affine_nn
() {}
accurate_interpolator_affine_nn
(trans_type& trans) : m_trans(&trans) {}
accurate_interpolator_affine_nn
(trans_type& trans,
double
x,
double
y,
unsigned
len) :
m_trans
(&trans)
{
begin
(x, y, len);
}
//
----------------------------------------------------------------
const
trans_type&
transformer
()
const
{
return
*m_trans; }
void
transformer
(trans_type& trans) { m_trans = &trans; }
//
----------------------------------------------------------------
void
begin
(
double
x,
double
y,
unsigned
len)
{
m_len = len -
1
;
m_cur =
0
;
m_stx1 = x;
m_sty1 = y;
m_trans->
transform
(&m_stx1, &m_sty1);
m_stx1 *= subpixel_scale;
m_sty1 *= subpixel_scale;
m_stx2 = x + m_len;
m_sty2 = y;
m_trans->
transform
(&m_stx2, &m_sty2);
m_stx2 *= subpixel_scale;
m_sty2 *= subpixel_scale;
}
//
----------------------------------------------------------------
void
resynchronize
(
double
xe,
double
ye,
unsigned
len)
{
m_len = len -
1
;
m_cur =
0
;
m_trans->
transform
(&xe, &ye);
m_stx2 = xe * subpixel_scale;
m_sty2 = ye * subpixel_scale;
}
//
----------------------------------------------------------------
void
operator
++()
{
m_cur++;
}
//
----------------------------------------------------------------
void
coordinates
(
int
* x,
int
* y)
const
{
//
Truncate instead of round because this interpolator needs to
//
match the definitions for nearest-neighbor interpolation
if
(m_cur == m_len)
{
*x =
int
(m_stx2);
*y =
int
(m_sty2);
}
else
{
//
Add a tiny fudge amount to account for numerical precision loss
*x =
int
(m_stx1 + (m_stx2 - m_stx1) * m_cur / m_len +
1e-8
);
*y =
int
(m_sty1 + (m_sty2 - m_sty1) * m_cur / m_len +
1e-8
);
}
}
private:
trans_type* m_trans;
unsigned
m_len, m_cur;
double
m_stx1, m_sty1, m_stx2, m_sty2;
};
#
endif
You can’t perform that action at this time.