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