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 * DrawingMode implementing B_OP_ADD on B_RGBA32. 7 * 8 */ 9 10 #ifndef DRAWING_MODE_ADD_SUBPIX_H 11 #define DRAWING_MODE_ADD_SUBPIX_H 12 13 #include "DrawingMode.h" 14 15 16 // BLEND_ADD_SUBPIX 17 #define BLEND_ADD_SUBPIX(d, r, g, b, a1, a2, a3) \ 18 { \ 19 pixel32 _p; \ 20 _p.data32 = *(uint32*)d; \ 21 uint8 rt = min_c(255, _p.data8[2] + (r)); \ 22 uint8 gt = min_c(255, _p.data8[1] + (g)); \ 23 uint8 bt = min_c(255, _p.data8[0] + (b)); \ 24 BLEND_SUBPIX(d, rt, gt, bt, a1, a2, a3); \ 25 } 26 27 28 // BLEND_ADD 29 #define BLEND_ADD(d, r, g, b, a) \ 30 { \ 31 pixel32 _p; \ 32 _p.data32 = *(uint32*)d; \ 33 uint8 rt = min_c(255, _p.data8[2] + (r)); \ 34 uint8 gt = min_c(255, _p.data8[1] + (g)); \ 35 uint8 bt = min_c(255, _p.data8[0] + (b)); \ 36 BLEND(d, rt, gt, bt, a); \ 37 } 38 39 40 //ASSIGN_ADD 41 #define ASSIGN_ADD(d, r, g, b) \ 42 { \ 43 pixel32 _p; \ 44 _p.data32 = *(uint32*)d; \ 45 d[0] = min_c(255, _p.data8[0] + (b)); \ 46 d[1] = min_c(255, _p.data8[1] + (g)); \ 47 d[2] = min_c(255, _p.data8[2] + (r)); \ 48 d[3] = 255; \ 49 } 50 51 52 // blend_hline_add_subpix 53 void 54 blend_hline_add_subpix(int x, int y, unsigned len, const color_type& c, 55 uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) 56 { 57 uint8* p = buffer->row_ptr(y) + (x << 2); 58 if (cover == 255) { 59 do { 60 rgb_color color = pattern->ColorAt(x, y); 61 62 ASSIGN_ADD(p, color.red, color.green, color.blue); 63 64 p += 4; 65 x++; 66 len -= 3; 67 } while (len); 68 } else { 69 do { 70 rgb_color color = pattern->ColorAt(x, y); 71 72 BLEND_ADD(p, color.red, color.green, color.blue, cover); 73 74 x++; 75 p += 4; 76 len -= 3; 77 } while (len); 78 } 79 } 80 81 82 // blend_solid_hspan_add_subpix 83 void 84 blend_solid_hspan_add_subpix(int x, int y, unsigned len, const color_type& c, 85 const uint8* covers, agg_buffer* buffer, const PatternHandler* pattern) 86 { 87 uint8* p = buffer->row_ptr(y) + (x << 2); 88 do { 89 rgb_color color = pattern->ColorAt(x, y); 90 BLEND_ADD_SUBPIX(p, color.red, color.green, color.blue, 91 covers[2], covers[1], covers[0]); 92 covers += 3; 93 p += 4; 94 x++; 95 len -= 3; 96 } while (len); 97 } 98 99 100 #endif // DRAWING_MODE_ADD_SUBPIX_H 101 102