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 23class PatternHandler; 24 25class 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 inline bool UsesOpCopyForText() const 75 { return fUsesOpCopyForText; } 76 77 // AGG "pixel format" interface 78 inline unsigned width() const 79 { return fBuffer->width(); } 80 inline unsigned height() const 81 { return fBuffer->height(); } 82 inline int stride() const 83 { return fBuffer->stride(); } 84 85 inline uint8* row_ptr(int y) 86 { return fBuffer->row_ptr(y); } 87 inline const uint8* row_ptr(int y) const 88 { return fBuffer->row_ptr(y); } 89 inline row_data row(int y) const 90 { return fBuffer->row(y); } 91 92 inline uint8* pix_ptr(int x, int y); 93 inline const uint8* pix_ptr(int x, int y) const; 94 95 inline static void make_pix(uint8* p, const color_type& c); 96// inline color_type pixel(int x, int y) const; 97 98 inline void blend_pixel(int x, int y, 99 const color_type& c, 100 uint8 cover); 101 102 103 inline void blend_hline(int x, int y, 104 unsigned len, 105 const color_type& c, 106 uint8 cover); 107 108 inline void blend_vline(int x, int y, 109 unsigned len, 110 const color_type& c, 111 uint8 cover); 112 113 inline void blend_solid_hspan(int x, int y, 114 unsigned len, 115 const color_type& c, 116 const uint8* covers); 117 118 inline void blend_solid_hspan_subpix(int x, int y, 119 unsigned len, 120 const color_type& c, 121 const uint8* covers); 122 123 inline void blend_solid_vspan(int x, int y, 124 unsigned len, 125 const color_type& c, 126 const uint8* covers); 127 128 inline void blend_color_hspan(int x, int y, 129 unsigned len, 130 const color_type* colors, 131 const uint8* covers, 132 uint8 cover); 133 134 inline void blend_color_vspan(int x, int y, 135 unsigned len, 136 const color_type* colors, 137 const uint8* covers, 138 uint8 cover); 139 140 private: 141 agg::rendering_buffer* fBuffer; 142 const PatternHandler* fPatternHandler; 143 bool fUsesOpCopyForText; 144 145 blend_pixel_f fBlendPixel; 146 blend_line fBlendHLine; 147 blend_line fBlendVLine; 148 blend_solid_span fBlendSolidHSpan; 149 blend_solid_span fBlendSolidHSpanSubpix; 150 blend_solid_span fBlendSolidVSpan; 151 blend_color_span fBlendColorHSpan; 152 blend_color_span fBlendColorVSpan; 153}; 154 155// inlined functions 156 157// pix_ptr 158inline uint8* 159PixelFormat::pix_ptr(int x, int y) 160{ 161 return fBuffer->row_ptr(y) + x * pix_width; 162} 163 164// pix_ptr 165inline const uint8* 166PixelFormat::pix_ptr(int x, int y) const 167{ 168 return fBuffer->row_ptr(y) + x * pix_width; 169} 170 171// make_pix 172inline void 173PixelFormat::make_pix(uint8* p, const color_type& c) 174{ 175 p[0] = c.b; 176 p[1] = c.g; 177 p[2] = c.r; 178 p[3] = c.a; 179} 180 181//// pixel 182//inline color_type 183//PixelFormat::pixel(int x, int y) const 184//{ 185// const uint8* p = (const uint8*)fBuffer->row_ptr(y); 186// if (p) { 187// p += x << 2; 188// return color_type(p[2], p[1], p[0], p[3]); 189// } 190// return color_type::no_color(); 191//} 192 193// blend_pixel 194inline void 195PixelFormat::blend_pixel(int x, int y, const color_type& c, uint8 cover) 196{ 197 fBlendPixel(x, y, c, cover, fBuffer, fPatternHandler); 198} 199 200// blend_hline 201inline void 202PixelFormat::blend_hline(int x, int y, unsigned len, 203 const color_type& c, uint8 cover) 204{ 205 fBlendHLine(x, y, len, c, cover, fBuffer, fPatternHandler); 206} 207 208// blend_vline 209inline void 210PixelFormat::blend_vline(int x, int y, unsigned len, 211 const color_type& c, uint8 cover) 212{ 213 fBlendVLine(x, y, len, c, cover, fBuffer, fPatternHandler); 214} 215 216// blend_solid_hspan 217inline void 218PixelFormat::blend_solid_hspan(int x, int y, unsigned len, 219 const color_type& c, const uint8* covers) 220{ 221 fBlendSolidHSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 222} 223 224// blend_solid_hspan_subpix 225inline void 226PixelFormat::blend_solid_hspan_subpix(int x, int y, unsigned len, 227 const color_type& c, const uint8* covers) 228{ 229 fBlendSolidHSpanSubpix(x, y, len, c, covers, fBuffer, fPatternHandler); 230} 231 232// blend_solid_vspan 233inline void 234PixelFormat::blend_solid_vspan(int x, int y, unsigned len, 235 const color_type& c, const uint8* covers) 236{ 237 fBlendSolidVSpan(x, y, len, c, covers, fBuffer, fPatternHandler); 238} 239 240// blend_color_hspan 241inline void 242PixelFormat::blend_color_hspan(int x, int y, unsigned len, 243 const color_type* colors, 244 const uint8* covers, 245 uint8 cover) 246{ 247 fBlendColorHSpan(x, y, len, colors, covers, cover, 248 fBuffer, fPatternHandler); 249} 250 251// blend_color_vspan 252inline void 253PixelFormat::blend_color_vspan(int x, int y, unsigned len, 254 const color_type* colors, 255 const uint8* covers, 256 uint8 cover) 257{ 258 fBlendColorVSpan(x, y, len, colors, covers, cover, 259 fBuffer, fPatternHandler); 260} 261 262#endif // PIXEL_FORMAT_H 263 264