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 #include <agg_gradient_lut.h>
29 #include <agg_color_rgba.h>
30 #include <agg_color_gray.h>
31 #include <agg_image_accessors.h>
32 #include <agg_span_allocator.h>
33 #include <agg_span_gradient.h>
34 #include <agg_span_interpolator_linear.h>
35 #include <agg_image_filters.h>
36 #include <agg_span_image_filter_rgb.h>
37 #include <agg_span_image_filter_rgba.h>
38 #include <agg_pixfmt_rgb.h>
39 #include <agg_pixfmt_rgba.h>
57 template<
typename FillMode,
typename Pixel>
58 void storeBitmap(
StyleHandler& st,
const agg_bitmap_info* bi,
59 const SWFMatrix& mat,
const SWFCxForm& cx,
61 template<
typename FillMode>
void storeBitmap(
StyleHandler& st,
62 const agg_bitmap_info* bi,
const SWFMatrix& mat,
const SWFCxForm& cx,
66 void storeGradient(
StyleHandler& st,
const GradientFill& fs,
67 const SWFMatrix& mat,
const SWFCxForm& cx);
68 template<
typename Spread>
void storeGradient(
StyleHandler& st,
69 const GradientFill& fs,
const SWFMatrix& mat,
const SWFCxForm& cx);
70 template<
typename Spread,
typename Interpolation>
71 void storeGradient(
StyleHandler& st,
const GradientFill& fs,
72 const SWFMatrix& mat,
const SWFCxForm& cx);
94 bool solid()
const {
return _solid; }
95 agg::rgba8
color()
const {
return _color; }
104 const agg::rgba8 _color;
112 template<
typename P>
struct Type {
113 typedef agg::wrap_mode_repeat Wrap;
114 typedef agg::image_accessor_wrap<P, Wrap, Wrap>
type;
121 template<
typename P>
struct Type {
122 typedef agg::image_accessor_clone<P>
type;
127 template<
typename P,
typename W>
130 typedef typename P::PixelFormat PixelFormat;
132 typedef agg::span_allocator<PixelFormat> Allocator;
133 typedef agg::span_interpolator_linear<agg::trans_affine>
140 typedef agg::pixfmt_rgba32_pre PixelFormat;
142 template<
typename SourceType,
typename Interpolator>
144 typedef agg::span_image_filter_rgba_nn<SourceType, Interpolator>
type;
147 template<
typename SourceType,
typename Interpolator>
149 typedef agg::span_image_filter_rgba_bilinear<SourceType, Interpolator>
157 typedef agg::pixfmt_rgb24_pre PixelFormat;
159 template<
typename SourceType,
typename Interpolator>
161 typedef agg::span_image_filter_rgb_nn<SourceType, Interpolator>
type;
164 template<
typename SourceType,
typename Interpolator>
166 typedef agg::span_image_filter_rgb_bilinear<SourceType, Interpolator>
172 template<
typename P,
typename W>
173 struct NN :
public FilterType<P, W>
175 typedef FilterType<P, W> BaseType;
176 typedef typename P::template Simple<
177 typename BaseType::SourceType,
178 typename BaseType::Interpolator>
::type Generator;
182 template<
typename P,
typename W>
183 struct AA :
public FilterType<P, W>
185 typedef FilterType<P, W> BaseType;
186 typedef typename P::template AntiAlias<
187 typename BaseType::SourceType,
188 typename BaseType::Interpolator>
::type Generator;
194 template<
typename T>
struct Type {
195 typedef agg::gradient_reflect_adaptor<T>
type;
202 template<
typename T>
struct Type {
203 typedef agg::gradient_repeat_adaptor<T>
type;
210 template<
typename T>
struct Type {
216 struct InterpolatorLinearRGB
218 template<
typename Pixel>
struct Type {
219 typedef agg::gradient_lut<linear_rgb_interpolator<Pixel>, 256>
type;
224 struct InterpolatorRGB
226 template<
typename Pixel>
struct Type {
227 typedef agg::gradient_lut<agg::color_interpolator<Pixel>, 256>
type;
236 template <
class Color,
class Allocator,
class Interpolator,
class GradientType,
237 class Adaptor,
class ColorInterpolator,
class SpanGenerator>
238 class GradientStyle :
public AggStyle
242 GradientStyle(
const GradientFill& fs,
const SWFMatrix& mat,
243 const SWFCxForm& cx,
int norm_size, GradientType gr = GradientType())
247 m_tr(mat.
a() / 65536.0, mat.
b() / 65536.0, mat.
c() / 65536.0,
248 mat.
d() / 65536.0, mat.tx(), mat.ty()),
258 const size_t size = fs.recordCount();
264 for (
size_t i = 0;
i != size; ++
i) {
265 const GradientRecord& gr = fs.record(
i);
266 const rgba tr =
m_cx.transform(gr.color);
269 agg::rgba8(tr.m_r, tr.m_g, tr.m_b, tr.m_a));
275 virtual ~GradientStyle() { }
277 void generate_span(Color* span,
int x,
int y,
unsigned len) {
278 m_sg.generate(span, x, y, len);
319 template<
typename G,
typename A,
typename I>
322 typedef agg::rgba8 Color;
323 typedef G GradientType;
326 typedef agg::span_allocator<Color> Allocator;
327 typedef agg::span_interpolator_linear<agg::trans_affine> Interpolator;
328 typedef agg::span_gradient<Color, Interpolator, Adaptor,
329 ColorInterpolator> Generator;
330 typedef GradientStyle<Color, Allocator, Interpolator, GradientType,
331 Adaptor, ColorInterpolator, Generator>
Type;
337 class SolidStyle :
public AggStyle
341 SolidStyle(
const agg::rgba8&
color)
343 AggStyle(true, color)
347 void generate_span(agg::rgba8* ,
int ,
int ,
359 template <
class PixelFormat,
class Allocator,
class SourceType,
360 class Interpolator,
class Generator>
361 class BitmapStyle :
public AggStyle
366 const SWFMatrix& mat,
const SWFCxForm& cx)
370 m_rbuf(data, width, height, rowlen),
373 m_tr(mat.
a() / 65535.0, mat.
b() / 65535.0, mat.
c() / 65535.0,
374 mat.
d() / 65535.0, mat.tx(), mat.ty()),
380 virtual ~BitmapStyle() {
383 void generate_span(agg::rgba8* span,
int x,
int y,
unsigned len)
385 m_sg.generate(span, x, y, len);
387 const bool transform = (
m_cx != SWFCxForm());
389 for (
size_t i = 0;
i < len; ++
i) {
392 span->r = std::min(span->r, span->a);
393 span->g = std::min(span->g, span->a);
394 span->b = std::min(span->b, span->a);
396 m_cx.transform(span->r, span->g, span->b, span->a);
419 agg::trans_affine
m_tr;
455 SolidStyle *st =
new SolidStyle(color);
461 const SWFCxForm& cx,
bool repeat,
bool smooth) {
467 storeBitmap<Tile>(*
this, bi, mat, cx, smooth);
471 storeBitmap<Clip>(*
this, bi, mat, cx, smooth);
488 typename T::GradientType gr;
492 typename T::Type* st =
new typename T::Type(fs, mat, cx, 32.0, gr);
513 agg::rgba8
color(
unsigned style)
const
523 unsigned len,
unsigned style)
525 _styles[style].generate_span(span,x,y,len);
533 template<
typename Filter>
void
537 typedef typename Filter::PixelFormat PixelFormat;
538 typedef typename Filter::Generator Generator;
539 typedef typename Filter::Allocator Allocator;
540 typedef typename Filter::SourceType SourceType;
541 typedef typename Filter::Interpolator Interpolator;
543 typedef BitmapStyle<PixelFormat, Allocator,
544 SourceType, Interpolator, Generator> Style;
571 const agg::gray8&
color(
unsigned )
const
595 _stageMatrix(stage.invert()),
596 _fillMatrix(fill.invert()),
607 storeGradient(_sh, f, m, _cx);
653 _sh.
add_color(agg::rgba8_pre(255,0,0,255));
660 _sh.
add_bitmap(dynamic_cast<const agg_bitmap_info*>(bm),
661 m, _cx, tiled, smooth);
679 template<
typename FillMode,
typename Pixel>
681 storeBitmap(StyleHandler& st,
const agg_bitmap_info* bi,
682 const SWFMatrix& mat,
const SWFCxForm& cx,
bool smooth)
685 st.addBitmap<AA<Pixel, FillMode> >(bi, mat, cx);
688 st.addBitmap<NN<Pixel, FillMode> >(bi, mat, cx);
691 template<
typename FillMode>
693 storeBitmap(StyleHandler& st,
const agg_bitmap_info* bi,
694 const SWFMatrix& mat,
const SWFCxForm& cx,
bool smooth)
697 if (bi->get_bpp() == 24) {
698 storeBitmap<FillMode, RGB>(st, bi, mat, cx, smooth);
701 storeBitmap<FillMode, RGBA>(st, bi, mat, cx, smooth);
704 template<
typename Spread,
typename Interpolation>
706 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
710 typedef agg::gradient_x Linear;
711 typedef agg::gradient_radial Radial;
712 typedef agg::gradient_radial_focus Focal;
714 typedef Gradient<Linear, Spread, Interpolation> LinearGradient;
715 typedef Gradient<Focal, Spread, Interpolation> FocalGradient;
716 typedef Gradient<Radial, Spread, Interpolation> RadialGradient;
720 st.addLinearGradient<LinearGradient>(fs, mat, cx);
724 if (fs.focalPoint()) {
725 st.addFocalGradient<FocalGradient>(fs, mat, cx);
728 st.addRadialGradient<RadialGradient>(fs, mat, cx);
732 template<
typename Spread>
734 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
737 switch (fs.interpolation) {
739 storeGradient<Spread, InterpolatorRGB>(st, fs, mat, cx);
742 storeGradient<Spread, InterpolatorLinearRGB>(st, fs, mat, cx);
749 storeGradient(StyleHandler& st,
const GradientFill& fs,
const SWFMatrix& mat,
753 switch (fs.spreadMode) {
755 storeGradient<Pad>(st, fs, mat, cx);
758 storeGradient<Reflect>(st, fs, mat, cx);
761 storeGradient<Repeat>(st, fs, mat, cx);
770 #endif // BACKEND_RENDER_HANDLER_AGG_STYLE_H