1 /* 2 * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 6 * 7 * A class implementing the AGG "pixel format" interface which maintains 8 * a PatternHandler and pointers to blending functions implementing the 9 * different BeOS "drawing_modes". 10 * 11 */ 12 13 #ifndef PIXEL_FORMAT_H 14 #define PIXEL_FORMAT_H 15 16 #include <agg_basics.h> 17 #include <agg_color_rgba8.h> 18 #include <agg_rendering_buffer.h> 19 20 #include <GraphicsDefs.h> 21 22 class PatternHandler; 23 24 class PixelFormat { 25 public: 26 typedef agg::rgba8 color_type; 27 typedef agg::rendering_buffer agg_buffer; 28 29 typedef void (*blend_pixel_f)(int x, int y, const color_type& c, 30 uint8 cover, 31 agg_buffer* buffer, 32 const PatternHandler* pattern); 33 34 typedef void (*blend_line)(int x, int y, unsigned len, 35 const color_type& c, uint8 cover, 36 agg_buffer* buffer, 37 const PatternHandler* pattern); 38 39 typedef void (*blend_solid_span)(int x, int y, unsigned len, 40 const color_type& c, 41 const uint8* covers, 42 agg_buffer* buffer, 43 const PatternHandler* pattern); 44 45 typedef void (*blend_color_span)(int x, int y, unsigned len, 46 const color_type* colors, 47 const uint8* covers, 48 uint8 cover, 49 agg_buffer* buffer, 50 const PatternHandler* pattern); 51 52 // PixelFormat class 53 PixelFormat(agg::rendering_buffer& buffer, 54 const PatternHandler* handler); 55 56 ~PixelFormat(); 57 58 59 void SetDrawingMode(drawing_mode mode, 60 source_alpha alphaSrcMode, 61 alpha_function alphaFncMode, 62 bool text); 63 64 inline bool UsesOpCopyForText() const 65 { return fUsesOpCopyForText; } 66 67 // AGG "pixel format" interface 68 unsigned width() const { return fBuffer->width(); } 69 unsigned height() const { return fBuffer->height(); } 70 71 void blend_pixel(int x, int y, 72 const color_type& c, 73 uint8 cover); 74 75 76 void blend_hline(int x, int y, 77 unsigned len, 78 const color_type& c, 79 uint8 cover); 80 81 void blend_vline(int x, int y, 82 unsigned len, 83 const color_type& c, 84 uint8 cover); 85 86 void blend_solid_hspan(int x, int y, 87 unsigned len, 88 const color_type& c, 89 const uint8* covers); 90 91 void blend_solid_vspan(int x, int y, 92 unsigned len, 93 const color_type& c, 94 const uint8* covers); 95 96 void blend_color_hspan(int x, int y, 97 unsigned len, 98 const color_type* colors, 99 const uint8* covers, 100 uint8 cover); 101 102 void blend_color_vspan(int x, int y, 103 unsigned len, 104 const color_type* colors, 105 const uint8* covers, 106 uint8 cover); 107 108 private: 109 agg::rendering_buffer* fBuffer; 110 const PatternHandler* fPatternHandler; 111 bool fUsesOpCopyForText; 112 113 blend_pixel_f fBlendPixel; 114 blend_line fBlendHLine; 115 blend_line fBlendVLine; 116 blend_solid_span fBlendSolidHSpan; 117 blend_solid_span fBlendSolidVSpan; 118 blend_color_span fBlendColorHSpan; 119 blend_color_span fBlendColorVSpan; 120 }; 121 122 // inlined functions 123 124 // blend_pixel 125 inline void 126 PixelFormat::blend_pixel(int x, int y, const color_type& c, uint8 cover) 127 { 128 fBlendPixel(x, y, c, cover, fBuffer, fPatternHandler); 129 } 130 131 // blend_hline 132 inline void 133 PixelFormat::blend_hline(int x, int y, unsigned len, 134 const color_type& c, uint8 cover) 135 { 136 fBlendHLine(x, y, len, c, cover, fBuffer, fPatternHandler); 137 } 138 139 // blend_vline 140 inline void 141 PixelFormat::blend_vline(int x, int y, unsigned len, 142 const color_type& c, uint8 cover) 143 { 144 fBlendVLine(x, y, len, c, cover, fBuffer, fPatternHandler); 145 } 146 147 // blend_solid_hspan 148 inline void 149 PixelFormat::blend_solid_hspan(int x, int y, unsigned len, 150 const color_type& c, const uint8* covers) 151 { 152 fBlendSolidHSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 153 } 154 155 // blend_solid_vspan 156 inline void 157 PixelFormat::blend_solid_vspan(int x, int y, unsigned len, 158 const color_type& c, const uint8* covers) 159 { 160 fBlendSolidVSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 161 } 162 163 // blend_color_hspan 164 inline void 165 PixelFormat::blend_color_hspan(int x, int y, unsigned len, 166 const color_type* colors, 167 const uint8* covers, 168 uint8 cover) 169 { 170 fBlendColorHSpan(x, y, len, colors, covers, cover, 171 fBuffer, fPatternHandler); 172 } 173 174 // blend_color_vspan 175 inline void 176 PixelFormat::blend_color_vspan(int x, int y, unsigned len, 177 const color_type* colors, 178 const uint8* covers, 179 uint8 cover) 180 { 181 fBlendColorVSpan(x, y, len, colors, covers, cover, 182 fBuffer, fPatternHandler); 183 } 184 185 #endif // PIXEL_FORMAT_H 186 187