1/*
2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus <superstippi@gmx.de>
7 */
8#ifndef ICON_RENDERER_H
9#define ICON_RENDERER_H
10
11
12#include <agg_gamma_lut.h>
13#include <agg_pixfmt_rgba.h>
14#include <agg_rasterizer_compound_aa.h>
15#include <agg_rendering_buffer.h>
16#include <agg_renderer_scanline.h>
17#include <agg_scanline_bin.h>
18#include <agg_scanline_u.h>
19#include <agg_span_allocator.h>
20#include <agg_trans_affine.h>
21
22#include "IconBuild.h"
23
24
25class BBitmap;
26class BRect;
27
28
29_BEGIN_ICON_NAMESPACE
30
31
32class Icon;
33
34typedef agg::gamma_lut
35			<agg::int8u, agg::int8u>		GammaTable;
36
37typedef agg::rendering_buffer				RenderingBuffer;
38typedef agg::pixfmt_bgra32					PixelFormat;
39typedef agg::pixfmt_bgra32_pre				PixelFormatPre;
40typedef agg::renderer_base<PixelFormat>		BaseRenderer;
41typedef agg::renderer_base<PixelFormatPre>	BaseRendererPre;
42
43typedef agg::scanline_u8					Scanline;
44typedef agg::scanline_bin					BinaryScanline;
45typedef agg::span_allocator<agg::rgba8>		SpanAllocator;
46typedef agg::rasterizer_compound_aa
47			<agg::rasterizer_sl_clip_dbl>	CompoundRasterizer;
48
49typedef agg::trans_affine					Transformation;
50
51class IconRenderer {
52 public:
53								IconRenderer(BBitmap* bitmap);
54	virtual						~IconRenderer();
55
56			void				SetIcon(const Icon* icon);
57
58			void				Render();
59			void				Render(const BRect& area);
60
61			void				SetScale(double scale);
62			void				SetBackground(const BBitmap* background);
63									// background is not copied,
64									// ownership stays with the caller
65									// colorspace and size need to
66									// be the same as bitmap passed
67									// to constructor
68			void				SetBackground(const agg::rgba8& color);
69									// used when no background bitmap
70									// is set
71
72			const _ICON_NAMESPACE GammaTable& GammaTable() const
73									{ return fGammaTable; }
74
75			void				Demultiply();
76
77 private:
78		class StyleHandler;
79
80			void				_Render(const BRect& area);
81			void				_CommitRenderPass(StyleHandler& styleHandler,
82									bool reset = true);
83
84			BBitmap*			fBitmap;
85			const BBitmap*		fBackground;
86			agg::rgba8			fBackgroundColor;
87			const Icon*			fIcon;
88
89			_ICON_NAMESPACE GammaTable fGammaTable;
90
91			RenderingBuffer		fRenderingBuffer;
92			PixelFormat			fPixelFormat;
93			PixelFormatPre		fPixelFormatPre;
94			BaseRenderer		fBaseRenderer;
95			BaseRendererPre		fBaseRendererPre;
96
97			Scanline			fScanline;
98			BinaryScanline		fBinaryScanline;
99			SpanAllocator		fSpanAllocator;
100
101			CompoundRasterizer	fRasterizer;
102
103			Transformation		fGlobalTransform;
104};
105
106
107_END_ICON_NAMESPACE
108
109
110#endif // ICON_RENDERER_H
111