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