1 /* 2 * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk> 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) 7 * 8 * A class implementing the AGG "pixel format" interface which maintains 9 * a PatternHandler and pointers to blending functions implementing the 10 * different BeOS "drawing_modes". 11 * 12 */ 13 14 #ifndef PIXEL_FORMAT_H 15 #define PIXEL_FORMAT_H 16 17 #include <agg_basics.h> 18 #include <agg_color_rgba.h> 19 #include <agg_rendering_buffer.h> 20 21 #include <GraphicsDefs.h> 22 23 class PatternHandler; 24 25 class PixelFormat { 26 public: 27 typedef agg::rgba8 color_type; 28 typedef agg::rendering_buffer agg_buffer; 29 typedef agg::rendering_buffer::row_data row_data; 30 typedef agg::order_bgra order_type; 31 enum base_scale_e 32 { 33 base_shift = color_type::base_shift, 34 base_scale = color_type::base_scale, 35 base_mask = color_type::base_mask, 36 pix_width = 4, 37 }; 38 39 typedef void (*blend_pixel_f)(int x, int y, const color_type& c, 40 uint8 cover, 41 agg_buffer* buffer, 42 const PatternHandler* pattern); 43 44 typedef void (*blend_line)(int x, int y, unsigned len, 45 const color_type& c, uint8 cover, 46 agg_buffer* buffer, 47 const PatternHandler* pattern); 48 49 typedef void (*blend_solid_span)(int x, int y, unsigned len, 50 const color_type& c, 51 const uint8* covers, 52 agg_buffer* buffer, 53 const PatternHandler* pattern); 54 55 typedef void (*blend_color_span)(int x, int y, unsigned len, 56 const color_type* colors, 57 const uint8* covers, 58 uint8 cover, 59 agg_buffer* buffer, 60 const PatternHandler* pattern); 61 62 // PixelFormat class 63 PixelFormat(agg::rendering_buffer& buffer, 64 const PatternHandler* handler); 65 66 ~PixelFormat(); 67 68 69 void SetDrawingMode(drawing_mode mode, 70 source_alpha alphaSrcMode, 71 alpha_function alphaFncMode, 72 bool text); 73 74 // AGG "pixel format" interface 75 inline unsigned width() const 76 { return fBuffer->width(); } 77 inline unsigned height() const 78 { return fBuffer->height(); } 79 inline int stride() const 80 { return fBuffer->stride(); } 81 82 inline uint8* row_ptr(int y) 83 { return fBuffer->row_ptr(y); } 84 inline const uint8* row_ptr(int y) const 85 { return fBuffer->row_ptr(y); } 86 inline row_data row(int y) const 87 { return fBuffer->row(y); } 88 89 inline uint8* pix_ptr(int x, int y); 90 inline const uint8* pix_ptr(int x, int y) const; 91 92 inline static void make_pix(uint8* p, const color_type& c); 93 // inline color_type pixel(int x, int y) const; 94 95 inline void blend_pixel(int x, int y, 96 const color_type& c, 97 uint8 cover); 98 99 100 inline void blend_hline(int x, int y, 101 unsigned len, 102 const color_type& c, 103 uint8 cover); 104 105 inline void blend_vline(int x, int y, 106 unsigned len, 107 const color_type& c, 108 uint8 cover); 109 110 inline void blend_solid_hspan(int x, int y, 111 unsigned len, 112 const color_type& c, 113 const uint8* covers); 114 115 inline void blend_solid_hspan_subpix(int x, int y, 116 unsigned len, 117 const color_type& c, 118 const uint8* covers); 119 120 inline void blend_solid_vspan(int x, int y, 121 unsigned len, 122 const color_type& c, 123 const uint8* covers); 124 125 inline void blend_color_hspan(int x, int y, 126 unsigned len, 127 const color_type* colors, 128 const uint8* covers, 129 uint8 cover); 130 131 inline void blend_color_vspan(int x, int y, 132 unsigned len, 133 const color_type* colors, 134 const uint8* covers, 135 uint8 cover); 136 137 private: 138 agg::rendering_buffer* fBuffer; 139 const PatternHandler* fPatternHandler; 140 141 blend_pixel_f fBlendPixel; 142 blend_line fBlendHLine; 143 blend_line fBlendVLine; 144 blend_solid_span fBlendSolidHSpan; 145 blend_solid_span fBlendSolidHSpanSubpix; 146 blend_solid_span fBlendSolidVSpan; 147 blend_color_span fBlendColorHSpan; 148 blend_color_span fBlendColorVSpan; 149 }; 150 151 // inlined functions 152 153 // pix_ptr 154 inline uint8* 155 PixelFormat::pix_ptr(int x, int y) 156 { 157 return fBuffer->row_ptr(y) + x * pix_width; 158 } 159 160 // pix_ptr 161 inline const uint8* 162 PixelFormat::pix_ptr(int x, int y) const 163 { 164 return fBuffer->row_ptr(y) + x * pix_width; 165 } 166 167 // make_pix 168 inline void 169 PixelFormat::make_pix(uint8* p, const color_type& c) 170 { 171 p[0] = c.b; 172 p[1] = c.g; 173 p[2] = c.r; 174 p[3] = c.a; 175 } 176 177 //// pixel 178 //inline color_type 179 //PixelFormat::pixel(int x, int y) const 180 //{ 181 // const uint8* p = (const uint8*)fBuffer->row_ptr(y); 182 // if (p) { 183 // p += x << 2; 184 // return color_type(p[2], p[1], p[0], p[3]); 185 // } 186 // return color_type::no_color(); 187 //} 188 189 // blend_pixel 190 inline void 191 PixelFormat::blend_pixel(int x, int y, const color_type& c, uint8 cover) 192 { 193 fBlendPixel(x, y, c, cover, fBuffer, fPatternHandler); 194 } 195 196 // blend_hline 197 inline void 198 PixelFormat::blend_hline(int x, int y, unsigned len, 199 const color_type& c, uint8 cover) 200 { 201 fBlendHLine(x, y, len, c, cover, fBuffer, fPatternHandler); 202 } 203 204 // blend_vline 205 inline void 206 PixelFormat::blend_vline(int x, int y, unsigned len, 207 const color_type& c, uint8 cover) 208 { 209 fBlendVLine(x, y, len, c, cover, fBuffer, fPatternHandler); 210 } 211 212 // blend_solid_hspan 213 inline void 214 PixelFormat::blend_solid_hspan(int x, int y, unsigned len, 215 const color_type& c, const uint8* covers) 216 { 217 fBlendSolidHSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 218 } 219 220 // blend_solid_hspan_subpix 221 inline void 222 PixelFormat::blend_solid_hspan_subpix(int x, int y, unsigned len, 223 const color_type& c, const uint8* covers) 224 { 225 fBlendSolidHSpanSubpix(x, y, len, c, covers, fBuffer, fPatternHandler); 226 } 227 228 // blend_solid_vspan 229 inline void 230 PixelFormat::blend_solid_vspan(int x, int y, unsigned len, 231 const color_type& c, const uint8* covers) 232 { 233 fBlendSolidVSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 234 } 235 236 // blend_color_hspan 237 inline void 238 PixelFormat::blend_color_hspan(int x, int y, unsigned len, 239 const color_type* colors, 240 const uint8* covers, 241 uint8 cover) 242 { 243 fBlendColorHSpan(x, y, len, colors, covers, cover, 244 fBuffer, fPatternHandler); 245 } 246 247 // blend_color_vspan 248 inline void 249 PixelFormat::blend_color_vspan(int x, int y, unsigned len, 250 const color_type* colors, 251 const uint8* covers, 252 uint8 cover) 253 { 254 fBlendColorVSpan(x, y, len, colors, covers, cover, 255 fBuffer, fPatternHandler); 256 } 257 258 #endif // PIXEL_FORMAT_H 259 260