xref: /haiku/src/libs/icon/IconRenderer.h (revision 0c93c0a807b27096abbfad677436afb7d1712d4a)
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 class BBitmap;
23 class BRect;
24 
25 
26 namespace BPrivate {
27 namespace Icon {
28 
29 class Icon;
30 
31 typedef agg::gamma_lut
32 			<agg::int8u, agg::int8u>		GammaTable;
33 
34 typedef agg::rendering_buffer				RenderingBuffer;
35 typedef agg::pixfmt_bgra32					PixelFormat;
36 typedef agg::pixfmt_bgra32_pre				PixelFormatPre;
37 typedef agg::renderer_base<PixelFormat>		BaseRenderer;
38 typedef agg::renderer_base<PixelFormatPre>	BaseRendererPre;
39 
40 typedef agg::scanline_u8					Scanline;
41 typedef agg::scanline_bin					BinaryScanline;
42 typedef agg::span_allocator<agg::rgba8>		SpanAllocator;
43 typedef agg::rasterizer_compound_aa
44 			<agg::rasterizer_sl_clip_dbl>	CompoundRasterizer;
45 
46 typedef agg::trans_affine					Transformation;
47 
48 class IconRenderer {
49  public:
50 								IconRenderer(BBitmap* bitmap);
51 	virtual						~IconRenderer();
52 
53 			void				SetIcon(const Icon* icon);
54 
55 			void				Render();
56 			void				Render(const BRect& area);
57 
58 			void				SetScale(double scale);
59 			void				SetBackground(const BBitmap* background);
60 									// background is not copied,
61 									// ownership stays with the caller
62 									// colorspace and size need to
63 									// be the same as bitmap passed
64 									// to constructor
65 			void				SetBackground(const agg::rgba8& color);
66 									// used when no background bitmap
67 									// is set
68 
69 			const BPrivate::Icon::GammaTable& GammaTable() const
70 									{ return fGammaTable; }
71 
72 			void				Demultiply();
73 
74  private:
75 			void				_Render(const BRect& area);
76 
77 			BBitmap*			fBitmap;
78 			const BBitmap*		fBackground;
79 			agg::rgba8			fBackgroundColor;
80 			const Icon*			fIcon;
81 
82 			BPrivate::Icon::GammaTable fGammaTable;
83 
84 			RenderingBuffer		fRenderingBuffer;
85 			PixelFormat			fPixelFormat;
86 			PixelFormatPre		fPixelFormatPre;
87 			BaseRenderer		fBaseRenderer;
88 			BaseRendererPre		fBaseRendererPre;
89 
90 			Scanline			fScanline;
91 			BinaryScanline		fBinaryScanline;
92 			SpanAllocator		fSpanAllocator;
93 
94 			CompoundRasterizer	fRasterizer;
95 
96 			Transformation		fGlobalTransform;
97 };
98 
99 }	// namespace Icon
100 }	// namespace BPrivate
101 
102 #endif // ICON_RENDERER_H
103