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 class StyleHandler; 76 77 void _Render(const BRect& area); 78 void _CommitRenderPass(StyleHandler& styleHandler, 79 bool reset = true); 80 81 BBitmap* fBitmap; 82 const BBitmap* fBackground; 83 agg::rgba8 fBackgroundColor; 84 const Icon* fIcon; 85 86 BPrivate::Icon::GammaTable fGammaTable; 87 88 RenderingBuffer fRenderingBuffer; 89 PixelFormat fPixelFormat; 90 PixelFormatPre fPixelFormatPre; 91 BaseRenderer fBaseRenderer; 92 BaseRendererPre fBaseRendererPre; 93 94 Scanline fScanline; 95 BinaryScanline fBinaryScanline; 96 SpanAllocator fSpanAllocator; 97 98 CompoundRasterizer fRasterizer; 99 100 Transformation fGlobalTransform; 101 }; 102 103 } // namespace Icon 104 } // namespace BPrivate 105 106 #endif // ICON_RENDERER_H 107