xref: /haiku/src/libs/icon/IconRenderer.h (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
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 
25 class BBitmap;
26 class BRect;
27 
28 
29 _BEGIN_ICON_NAMESPACE
30 
31 
32 class Icon;
33 
34 typedef agg::gamma_lut
35 			<agg::int8u, agg::int8u>		GammaTable;
36 
37 typedef agg::rendering_buffer				RenderingBuffer;
38 typedef agg::pixfmt_bgra32					PixelFormat;
39 typedef agg::pixfmt_bgra32_pre				PixelFormatPre;
40 typedef agg::renderer_base<PixelFormat>		BaseRenderer;
41 typedef agg::renderer_base<PixelFormatPre>	BaseRendererPre;
42 
43 typedef agg::scanline_u8					Scanline;
44 typedef agg::scanline_bin					BinaryScanline;
45 typedef agg::span_allocator<agg::rgba8>		SpanAllocator;
46 typedef agg::rasterizer_compound_aa
47 			<agg::rasterizer_sl_clip_dbl>	CompoundRasterizer;
48 
49 typedef agg::trans_affine					Transformation;
50 
51 class 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