19 #ifndef BACKEND_RENDER_HANDLER_AGG_STYLE_H
20 #define BACKEND_RENDER_HANDLER_AGG_STYLE_H
27 #include <boost/ptr_container/ptr_vector.hpp>
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
30 #include <agg_gradient_lut.h>
31 #include <agg_color_rgba.h>
32 #include <agg_color_gray.h>
33 #include <agg_image_accessors.h>
34 #include <agg_span_allocator.h>
35 #include <agg_span_gradient.h>
36 #include <agg_span_interpolator_linear.h>
37 #include <agg_image_filters.h>
38 #include <agg_span_image_filter_rgb.h>
39 #include <agg_span_image_filter_rgba.h>
40 #include <agg_pixfmt_rgb.h>
41 #include <agg_pixfmt_rgba.h>
42 #pragma GCC diagnostic pop
59 template<
typename FillMode,
typename Pixel>
60 void storeBitmap(
StyleHandler& st,
const agg_bitmap_info* bi,
61 const SWFMatrix& mat,
const SWFCxForm& cx,
63 template<
typename FillMode>
void storeBitmap(
StyleHandler& st,
64 const agg_bitmap_info* bi,
const SWFMatrix& mat,
const SWFCxForm& cx,
68 void storeGradient(
StyleHandler& st,
const GradientFill& fs,
69 const SWFMatrix& mat,
const SWFCxForm& cx);
70 template<
typename Spread>
void storeGradient(
StyleHandler& st,
71 const GradientFill& fs,
const SWFMatrix& mat,
const SWFCxForm& cx);
72 template<
typename Spread,
typename Interpolation>
73 void storeGradient(
StyleHandler& st,
const GradientFill& fs,
74 const SWFMatrix& mat,
const SWFCxForm& cx);
96 bool solid()
const {
return _solid; }
97 agg::rgba8
color()
const {
return _color; }
106 const agg::rgba8 _color;
114 template<
typename P>
struct Type {
115 typedef agg::wrap_mode_repeat Wrap;
116 typedef agg::image_accessor_wrap<P, Wrap, Wrap>
type;
123 template<
typename P>
struct Type {
124 typedef agg::image_accessor_clone<P>
type;
129 template<
typename P,
typename W>
132 typedef typename P::PixelFormat PixelFormat;
134 typedef agg::span_allocator<PixelFormat> Allocator;
135 typedef agg::span_interpolator_linear<agg::trans_affine>
142 typedef agg::pixfmt_rgba32_pre PixelFormat;
144 template<
typename SourceType,
typename Interpolator>
146 typedef agg::span_image_filter_rgba_nn<SourceType, Interpolator>
type;
149 template<
typename SourceType,
typename Interpolator>
151 typedef agg::span_image_filter_rgba_bilinear<SourceType, Interpolator>
159 typedef agg::pixfmt_rgb24_pre PixelFormat;
161 template<
typename SourceType,
typename Interpolator>
163 typedef agg::span_image_filter_rgb_nn<SourceType, Interpolator>
type;
166 template<
typename SourceType,
typename Interpolator>
168 typedef agg::span_image_filter_rgb_bilinear<SourceType, Interpolator>
174 template<
typename P,
typename W>
175 struct NN :
public FilterType<P, W>
177 typedef FilterType<P, W> BaseType;
178 typedef typename P::template Simple<
179 typename BaseType::SourceType,
180 typename BaseType::Interpolator>
::type Generator;
184 template<
typename P,
typename W>
185 struct AA :
public FilterType<P, W>
187 typedef FilterType<P, W> BaseType;
188 typedef typename P::template AntiAlias<
189 typename BaseType::SourceType,
190 typename BaseType::Interpolator>
::type Generator;
196 template<
typename T>
struct Type {
197 typedef agg::gradient_reflect_adaptor<T>
type;
204 template<
typename T>
struct Type {
205 typedef agg::gradient_repeat_adaptor<T>
type;
212 template<
typename T>
struct Type {
218 struct InterpolatorLinearRGB
220 template<
typename Pixel>
struct Type {
221 typedef agg::gradient_lut<linear_rgb_interpolator<Pixel>, 256>
type;
226 struct InterpolatorRGB
228 template<
typename Pixel>
struct Type {
229 typedef agg::gradient_lut<agg::color_interpolator<Pixel>, 256>
type;
238 template <
class Color,
class Allocator,
class Interpolator,
class GradientType,
239 class Adaptor,
class ColorInterpolator,
class SpanGenerator>
240 class GradientStyle :
public AggStyle
244 GradientStyle(
const GradientFill& fs,
const SWFMatrix& mat,
245 const SWFCxForm& cx,
int norm_size, GradientType gr = GradientType())
249 m_tr(mat.
a() / 65536.0, mat.
b() / 65536.0, mat.
c() / 65536.0,
250 mat.
d() / 65536.0, mat.tx(), mat.ty()),
260 const size_t size = fs.recordCount();
266 for (
size_t i = 0;
i != size; ++
i) {
267 const GradientRecord& gr = fs.record(
i);
268 const rgba tr =
m_cx.transform(gr.color);
271 agg::rgba8(tr.m_r, tr.m_g, tr.m_b, tr.m_a));
277 virtual ~GradientStyle() { }
279 void generate_span(Color* span,
int x,
int y,
unsigned len) {
280 m_sg.generate(span, x, y, len);
321 template<
typename G,
typename A,
typename I>
324 typedef agg::rgba8 Color;
325 typedef G GradientType;
328 typedef agg::span_allocator<Color> Allocator;
329 typedef agg::span_interpolator_linear<agg::trans_affine> Interpolator;
330 typedef agg::span_gradient<Color, Interpolator, Adaptor,
331 ColorInterpolator> Generator;
332 typedef GradientStyle<Color, Allocator, Interpolator, GradientType,
333 Adaptor, ColorInterpolator, Generator>
Type;
339 class SolidStyle :
public AggStyle
343 SolidStyle(
const agg::rgba8&
color)
345 AggStyle(true, color)
349 void generate_span(agg::rgba8* ,
int ,
int ,
361 template <
class PixelFormat,
class Allocator,
class SourceType,
362 class Interpolator,
class Generator>
363 class BitmapStyle :
public AggStyle
368 const SWFMatrix& mat,
const SWFCxForm& cx)
372 m_rbuf(data, width, height, rowlen),
375 m_tr(mat.
a() / 65535.0, mat.
b() / 65535.0, mat.
c() / 65535.0,
376 mat.
d() / 65535.0, mat.tx(), mat.ty()),
382 virtual ~BitmapStyle() {
385 void generate_span(agg::rgba8* span,
int x,
int y,
unsigned len)
387 m_sg.generate(span, x, y, len);
389 const bool transform = (
m_cx != SWFCxForm());
391 for (
size_t i = 0;
i < len; ++
i) {
394 span->r = std::min(span->r, span->a);
395 span->g = std::min(span->g, span->a);
396 span->b = std::min(span->b, span->a);
398 m_cx.transform(span->r, span->g, span->b, span->a);
421 agg::trans_affine
m_tr;
451 assert(style <
_styles.size());
457 SolidStyle *st =
new SolidStyle(color);
463 const SWFCxForm& cx,
bool repeat,
bool smooth) {
469 storeBitmap<Tile>(*
this, bi, mat, cx, smooth);
473 storeBitmap<Clip>(*
this, bi, mat, cx, smooth);
490 typename T::GradientType gr;
494 typename T::Type* st =
new typename T::Type(fs, mat, cx, 32.0, gr);
515 agg::rgba8
color(
unsigned style)
const
525 unsigned len,
unsigned style)
527 _styles[style].generate_span(span,x,y,len);
535 template<
typename Filter>
void
539 typedef typename Filter::PixelFormat PixelFormat;
540 typedef typename Filter::Generator Generator;
541 typedef typename Filter::Allocator Allocator;
542 typedef typename Filter::SourceType SourceType;
543 typedef typename Filter::Interpolator Interpolator;
545 typedef BitmapStyle<PixelFormat, Allocator,
546 SourceType, Interpolator, Generator> Style;
573 const agg::gray8&
color(
unsigned )
const
597 _stageMatrix(stage.invert()),
598 _fillMatrix(fill.invert()),
609 storeGradient(_sh, f, m, _cx);
655 _sh.
add_color(agg::rgba8_pre(255,0,0,255));
662 _sh.
add_bitmap(dynamic_cast<const agg_bitmap_info*>(bm),
663 m, _cx, tiled, smooth);
681 template<
typename FillMode,
typename Pixel>
683 storeBitmap(StyleHandler& st,
const agg_bitmap_info* bi,
684 const SWFMatrix& mat,
const SWFCxForm& cx,
bool smooth)
687 st.addBitmap<AA<Pixel, FillMode> >(bi, mat, cx);
690 st.addBitmap<NN<Pixel, FillMode> >(bi, mat, cx);
693 template<
typename FillMode>
695 storeBitmap(StyleHandler& st,
const agg_bitmap_info* bi,
696 const SWFMatrix& mat,
const SWFCxForm& cx,
bool smooth)
699 if (bi->get_bpp() == 24) {
700 storeBitmap<FillMode, RGB>(st, bi, mat, cx, smooth);
703 storeBitmap<FillMode, RGBA>(st, bi, mat, cx, smooth);
706 template<
typename Spread,
typename Interpolation>
708 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
712 typedef agg::gradient_x Linear;
713 typedef agg::gradient_radial Radial;
714 typedef agg::gradient_radial_focus Focal;
716 typedef Gradient<Linear, Spread, Interpolation> LinearGradient;
717 typedef Gradient<Focal, Spread, Interpolation> FocalGradient;
718 typedef Gradient<Radial, Spread, Interpolation> RadialGradient;
722 st.addLinearGradient<LinearGradient>(fs, mat, cx);
726 if (fs.focalPoint()) {
727 st.addFocalGradient<FocalGradient>(fs, mat, cx);
730 st.addRadialGradient<RadialGradient>(fs, mat, cx);
734 template<
typename Spread>
736 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
739 switch (fs.interpolation) {
741 storeGradient<Spread, InterpolatorRGB>(st, fs, mat, cx);
744 storeGradient<Spread, InterpolatorLinearRGB>(st, fs, mat, cx);
751 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
755 switch (fs.spreadMode) {
757 storeGradient<Pad>(st, fs, mat, cx);
760 storeGradient<Reflect>(st, fs, mat, cx);
763 storeGradient<Repeat>(st, fs, mat, cx);
772 #endif // BACKEND_RENDER_HANDLER_AGG_STYLE_H
Definition: GnashKey.h:147
SpanGenerator m_sg
Definition: Renderer_agg_style.h:310
agg::rgba8 color() const
Definition: Renderer_agg_style.h:97
AggStyle(bool solid, const agg::rgba8 &color=agg::rgba8(0, 0, 0, 0))
Definition: Renderer_agg_style.h:84
Definition: GnashKey.h:150
agg::rgba8 m_transparent
Definition: Renderer_agg_style.h:555
bool m_need_premultiply
Definition: Renderer_agg_style.h:313
Definition: Renderer_agg_bitmap.h:31
const SWFMatrix & matrix() const
Definition: FillStyle.h:191
Definition: FillStyle.h:76
virtual void generate_span(agg::rgba8 *span, int x, int y, unsigned len)=0
const CachedBitmap * bitmap() const
Get the actual Bitmap data.
Definition: FillStyle.cpp:182
Definition: FillStyle.h:162
VGPaint fill
Definition: testr_gtk.cpp:86
~StyleHandler()
Definition: Renderer_agg_style.h:446
Interpolator m_interpolator
Definition: Renderer_agg_style.h:424
Definition: Renderer_agg_style.h:438
virtual bool disposed() const =0
Whether the CachedBitmap has been disposed.
Definition: SWFMatrix.h:53
SWFCxForm m_cx
Definition: Renderer_agg_style.h:292
Definition: Renderer_agg_style.h:559
rgba color() const
Get the color of the fill.
Definition: FillStyle.h:268
boost::uint8_t m_a
Definition: RGBA.h:113
A SolidFill containing one color.
Definition: FillStyle.h:246
StyleHandler()
Definition: Renderer_agg_style.h:442
Definition: GnashKey.h:163
Definition: GnashKey.h:119
SourceType m_img_src
Definition: Renderer_agg_style.h:418
void operator()(const SolidFill &f) const
Definition: Renderer_agg_style.h:612
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Quality
Definition: GnashEnums.h:34
Style handler.
Definition: Renderer_agg_style.h:592
type
Definition: GnashKey.h:329
ColorInterpolator m_gradient_lut
Definition: Renderer_agg_style.h:307
agg_mask_style_handler()
Definition: Renderer_agg_style.h:563
bool is_solid(unsigned) const
Definition: Renderer_agg_style.h:568
PixelFormat m_pixf
Definition: Renderer_agg_style.h:412
Definition: klash_part.cpp:329
Definition: GnashKey.h:149
Definition: GnashKey.h:152
agg::trans_affine m_tr
Definition: Renderer_agg_style.h:298
void addRadialGradient(const GradientFill &fs, const SWFMatrix &mat, const SWFCxForm &cx)
Definition: Renderer_agg_style.h:502
Definition: FillStyle.h:161
int get_rowlen() const
Definition: Renderer_agg_bitmap.h:58
int get_height() const
Definition: Renderer_agg_bitmap.h:56
Definition: FillStyle.h:167
const VGfloat color[4]
Definition: testr_gtk.cpp:82
A GradientFill.
Definition: FillStyle.h:153
void generate_span(agg::rgba8 *span, int x, int y, unsigned len, unsigned style)
Called by AGG to generate a scanline span for non-solid fills.
Definition: Renderer_agg_style.h:524
agg::rendering_buffer m_rbuf
Definition: Renderer_agg_style.h:411
Definition: FillStyle.h:166
void addBitmap(const agg_bitmap_info *bi, const SWFMatrix &mat, const SWFCxForm &cx)
Add a bitmap with the specified filter.
Definition: Renderer_agg_style.h:536
Definition: klash_part.cpp:329
Definition: FillStyle.h:168
const SWFMatrix & matrix() const
Get the matrix of this BitmapFill.
Definition: FillStyle.h:130
void operator()(const GradientFill &f) const
Definition: Renderer_agg_style.h:605
void addFocalGradient(const GradientFill &fs, const SWFMatrix &mat, const SWFCxForm &cx)
Definition: Renderer_agg_style.h:487
int get_width() const
Definition: Renderer_agg_bitmap.h:55
void generate_span(agg::gray8 *, int, int, int, unsigned)
Definition: Renderer_agg_style.h:578
boost::uint8_t * get_data() const
Definition: Renderer_agg_bitmap.h:59
bool solid() const
Definition: Renderer_agg_style.h:96
boost::int32_t x
Definition: BitmapData_as.cpp:434
boost::ptr_vector< AggStyle > _styles
Definition: Renderer_agg_style.h:554
Definition: GnashKey.h:148
void add_color(const agg::rgba8 &color)
Adds a new solid fill color style.
Definition: Renderer_agg_style.h:456
Definition: GnashEnums.h:36
const agg::gray8 & color(unsigned) const
Definition: Renderer_agg_style.h:573
Adaptor m_gradient_adaptor
Definition: Renderer_agg_style.h:304
agg::rgba8 color(unsigned style) const
Returns the color of a certain fill style (solid)
Definition: Renderer_agg_style.h:515
Definition: GnashKey.h:132
Definition: FillStyle.h:77
boost::int32_t y
Definition: BitmapData_as.cpp:435
void add_bitmap(const agg_bitmap_info *bi, const SWFMatrix &mat, const SWFCxForm &cx, bool repeat, bool smooth)
Adds a new bitmap fill style.
Definition: Renderer_agg_style.h:462
Definition: GnashKey.h:155
Definition: GnashEnums.h:39
Allocator m_sa
Definition: Renderer_agg_style.h:295
Type type() const
Get the Type of this BitmapFill.
Definition: FillStyle.h:117
void operator()(const BitmapFill &f) const
Definition: Renderer_agg_style.h:621
boost::uint8_t m_b
Definition: RGBA.h:113
Definition: GnashKey.h:159
void concatenate(const SWFMatrix &m)
Concatenate m's transform onto ours.
Definition: SWFMatrix.cpp:148
boost::uint8_t m_r
Definition: RGBA.h:113
A CachedBitmap is created by the renderer in a format of its choosing.
Definition: CachedBitmap.h:37
virtual ~AggStyle()
Definition: Renderer_agg_style.h:95
SmoothingPolicy smoothingPolicy() const
Get the smoothing policy of this BitmapFill.
Definition: FillStyle.h:122
A BitmapFill.
Definition: FillStyle.h:70
AddStyles(SWFMatrix stage, SWFMatrix fill, const SWFCxForm &c, StyleHandler &sh, Quality q)
Definition: Renderer_agg_style.h:594
Definition: Renderer_agg_style.h:81
double focalPoint() const
Get the focal point of this GradientFill.
Definition: FillStyle.h:228
Definition: FillStyle.h:87
bool is_solid(unsigned style) const
Called by AGG to ask if a certain style is a solid color.
Definition: Renderer_agg_style.h:450
boost::uint8_t m_g
Definition: RGBA.h:113
Interpolator m_span_interpolator
Definition: Renderer_agg_style.h:301
void addLinearGradient(const GradientFill &fs, const SWFMatrix &mat, const SWFCxForm &cx)
Definition: Renderer_agg_style.h:477
A basic RGBA type.
Definition: RGBA.h:35