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