1/* 2 * Copyright 2005-2007, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan A��mus <superstippi@gmx.de> 7 */ 8#ifndef DRAWING_SUPPORT_H 9#define DRAWING_SUPPORT_H 10 11 12#include <SupportDefs.h> 13#include <string.h> 14 15class BRect; 16 17 18// gfxset32 19// * numBytes is expected to be a multiple of 4 20static inline void 21gfxset32(uint8* dst, uint32 color, int32 numBytes) 22{ 23 uint64 s64 = ((uint64)color << 32) | color; 24 while (numBytes >= 8) { 25 *(uint64*)dst = s64; 26 numBytes -= 8; 27 dst += 8; 28 } 29 if (numBytes == 4) { 30 *(uint32*)dst = color; 31 } 32} 33 34union pixel32 { 35 uint32 data32; 36 uint8 data8[4]; 37}; 38 39// blend_line32 40static inline void 41blend_line32(uint8* buffer, int32 pixels, uint8 r, uint8 g, uint8 b, uint8 a) 42{ 43 pixel32 p; 44 45 r = (r * a) >> 8; 46 g = (g * a) >> 8; 47 b = (b * a) >> 8; 48 a = 255 - a; 49 50 uint8 tempBuffer[pixels * 4]; 51 52 uint8* t = tempBuffer; 53 uint8* s = buffer; 54 55 for (int32 i = 0; i < pixels; i++) { 56 p.data32 = *(uint32*)s; 57 58 t[0] = ((p.data8[0] * a) >> 8) + b; 59 t[1] = ((p.data8[1] * a) >> 8) + g; 60 t[2] = ((p.data8[2] * a) >> 8) + r; 61 62 t += 4; 63 s += 4; 64 } 65 66 memcpy(buffer, tempBuffer, pixels * 4); 67} 68 69void align_rect_to_pixels(BRect* rect); 70 71#endif // DRAWING_SUPPORT_H 72