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_rgba.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 typedef agg::rendering_buffer::row_data row_data; 29 typedef agg::order_bgra order_type; 30 enum base_scale_e 31 { 32 base_shift = color_type::base_shift, 33 base_scale = color_type::base_scale, 34 base_mask = color_type::base_mask, 35 pix_width = 4, 36 }; 37 38 typedef void (*blend_pixel_f)(int x, int y, const color_type& c, 39 uint8 cover, 40 agg_buffer* buffer, 41 const PatternHandler* pattern); 42 43 typedef void (*blend_line)(int x, int y, unsigned len, 44 const color_type& c, uint8 cover, 45 agg_buffer* buffer, 46 const PatternHandler* pattern); 47 48 typedef void (*blend_solid_span)(int x, int y, unsigned len, 49 const color_type& c, 50 const uint8* covers, 51 agg_buffer* buffer, 52 const PatternHandler* pattern); 53 54 typedef void (*blend_color_span)(int x, int y, unsigned len, 55 const color_type* colors, 56 const uint8* covers, 57 uint8 cover, 58 agg_buffer* buffer, 59 const PatternHandler* pattern); 60 61 // PixelFormat class 62 PixelFormat(agg::rendering_buffer& buffer, 63 const PatternHandler* handler); 64 65 ~PixelFormat(); 66 67 68 void SetDrawingMode(drawing_mode mode, 69 source_alpha alphaSrcMode, 70 alpha_function alphaFncMode, 71 bool text); 72 73 inline bool UsesOpCopyForText() const 74 { return fUsesOpCopyForText; } 75 76 // AGG "pixel format" interface 77 inline unsigned width() const 78 { return fBuffer->width(); } 79 inline unsigned height() const 80 { return fBuffer->height(); } 81 inline int stride() const 82 { return fBuffer->stride(); } 83 84 inline uint8* row_ptr(int y) 85 { return fBuffer->row_ptr(y); } 86 inline const uint8* row_ptr(int y) const 87 { return fBuffer->row_ptr(y); } 88 inline row_data row(int y) const 89 { return fBuffer->row(y); } 90 91 inline uint8* pix_ptr(int x, int y); 92 inline const uint8* pix_ptr(int x, int y) const; 93 94 inline static void make_pix(uint8* p, const color_type& c); 95 // inline color_type pixel(int x, int y) const; 96 97 inline void blend_pixel(int x, int y, 98 const color_type& c, 99 uint8 cover); 100 101 102 inline void blend_hline(int x, int y, 103 unsigned len, 104 const color_type& c, 105 uint8 cover); 106 107 inline void blend_vline(int x, int y, 108 unsigned len, 109 const color_type& c, 110 uint8 cover); 111 112 inline void blend_solid_hspan(int x, int y, 113 unsigned len, 114 const color_type& c, 115 const uint8* covers); 116 117 inline void blend_solid_vspan(int x, int y, 118 unsigned len, 119 const color_type& c, 120 const uint8* covers); 121 122 inline void blend_color_hspan(int x, int y, 123 unsigned len, 124 const color_type* colors, 125 const uint8* covers, 126 uint8 cover); 127 128 inline void blend_color_vspan(int x, int y, 129 unsigned len, 130 const color_type* colors, 131 const uint8* covers, 132 uint8 cover); 133 134 private: 135 agg::rendering_buffer* fBuffer; 136 const PatternHandler* fPatternHandler; 137 bool fUsesOpCopyForText; 138 139 blend_pixel_f fBlendPixel; 140 blend_line fBlendHLine; 141 blend_line fBlendVLine; 142 blend_solid_span fBlendSolidHSpan; 143 blend_solid_span fBlendSolidVSpan; 144 blend_color_span fBlendColorHSpan; 145 blend_color_span fBlendColorVSpan; 146 }; 147 148 // inlined functions 149 150 // pix_ptr 151 inline uint8* 152 PixelFormat::pix_ptr(int x, int y) 153 { 154 return fBuffer->row_ptr(y) + x * pix_width; 155 } 156 157 // pix_ptr 158 inline const uint8* 159 PixelFormat::pix_ptr(int x, int y) const 160 { 161 return fBuffer->row_ptr(y) + x * pix_width; 162 } 163 164 // make_pix 165 inline void 166 PixelFormat::make_pix(uint8* p, const color_type& c) 167 { 168 p[0] = c.b; 169 p[1] = c.g; 170 p[2] = c.r; 171 p[3] = c.a; 172 } 173 174 //// pixel 175 //inline color_type 176 //PixelFormat::pixel(int x, int y) const 177 //{ 178 // const uint8* p = (const uint8*)fBuffer->row_ptr(y); 179 // if (p) { 180 // p += x << 2; 181 // return color_type(p[2], p[1], p[0], p[3]); 182 // } 183 // return color_type::no_color(); 184 //} 185 186 // blend_pixel 187 inline void 188 PixelFormat::blend_pixel(int x, int y, const color_type& c, uint8 cover) 189 { 190 fBlendPixel(x, y, c, cover, fBuffer, fPatternHandler); 191 } 192 193 // blend_hline 194 inline void 195 PixelFormat::blend_hline(int x, int y, unsigned len, 196 const color_type& c, uint8 cover) 197 { 198 fBlendHLine(x, y, len, c, cover, fBuffer, fPatternHandler); 199 } 200 201 // blend_vline 202 inline void 203 PixelFormat::blend_vline(int x, int y, unsigned len, 204 const color_type& c, uint8 cover) 205 { 206 fBlendVLine(x, y, len, c, cover, fBuffer, fPatternHandler); 207 } 208 209 // blend_solid_hspan 210 inline void 211 PixelFormat::blend_solid_hspan(int x, int y, unsigned len, 212 const color_type& c, const uint8* covers) 213 { 214 fBlendSolidHSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 215 } 216 217 // blend_solid_vspan 218 inline void 219 PixelFormat::blend_solid_vspan(int x, int y, unsigned len, 220 const color_type& c, const uint8* covers) 221 { 222 fBlendSolidVSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 223 } 224 225 // blend_color_hspan 226 inline void 227 PixelFormat::blend_color_hspan(int x, int y, unsigned len, 228 const color_type* colors, 229 const uint8* covers, 230 uint8 cover) 231 { 232 fBlendColorHSpan(x, y, len, colors, covers, cover, 233 fBuffer, fPatternHandler); 234 } 235 236 // blend_color_vspan 237 inline void 238 PixelFormat::blend_color_vspan(int x, int y, unsigned len, 239 const color_type* colors, 240 const uint8* covers, 241 uint8 cover) 242 { 243 fBlendColorVSpan(x, y, len, colors, covers, cover, 244 fBuffer, fPatternHandler); 245 } 246 247 #endif // PIXEL_FORMAT_H 248 249