SHOW:
|
|
- or go back to the newest paste.
| 1 | template<int bpp, int incrementPtr> | |
| 2 | STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlphaSwitch(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A) | |
| 3 | {
| |
| 4 | Uint *ptr2 = ptr; | |
| 5 | if (bpp == 4) | |
| 6 | ptr2++; | |
| 7 | switch (A) | |
| 8 | {
| |
| 9 | case 255: | |
| 10 | ptr += bpp * incrementPtr; | |
| 11 | return; | |
| 12 | case 0: | |
| 13 | - | PutColor(ptr, ((Uint16)R + (Uint16)ptr[1]) >> 1, |
| 13 | + | |
| 14 | - | ((Uint16)G + (Uint16)ptr[2]) >> 1, |
| 14 | + | |
| 15 | - | ((Uint16)B + (Uint16)ptr[3]) >> 1); |
| 15 | + | |
| 16 | PutColor(ptr, ((Uint16)R + (Uint16)ptr2[1]) >> 1, | |
| 17 | ((Uint16)G + (Uint16)ptr2[2]) >> 1, | |
| 18 | ((Uint16)B + (Uint16)ptr2[3]) >> 1); | |
| 19 | return; | |
| 20 | default: | |
| 21 | PutColor(ptr, R, G, B, A); | |
| 22 | return; | |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | - | PutColor(ptr, ((((Uint32)ptr[1]-(Uint32)R)*(Uint32)A) >> 8 ) + (Uint32)R, |
| 26 | + | |
| 27 | - | ((((Uint32)ptr[2]-(Uint32)G)*(Uint32)A) >> 8 ) + (Uint32)G, |
| 27 | + | |
| 28 | - | ((((Uint32)ptr[3]-(Uint32)B)*(Uint32)A) >> 8 ) + (Uint32)B); |
| 28 | + | |
| 29 | Uint *ptr2 = ptr; | |
| 30 | if (bpp == 4) | |
| 31 | ptr2++; | |
| 32 | PutColor(ptr, ((((Uint32)ptr2[1]-(Uint32)R)*(Uint32)A) >> 8 ) + (Uint32)R, | |
| 33 | ((((Uint32)ptr2[2]-(Uint32)G)*(Uint32)A) >> 8 ) + (Uint32)G, | |
| 34 | ((((Uint32)ptr2[3]-(Uint32)B)*(Uint32)A) >> 8 ) + (Uint32)B); | |
| 35 | } | |
| 36 | ||
| 37 | template<int bpp, int incrementPtr> | |
| 38 | STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B) | |
| 39 | {
| |
| 40 | if(incrementPtr == 0) | |
| 41 | {
| |
| 42 | Uint8 *ptr2 = ptr; | |
| 43 | if(bpp == 4) | |
| 44 | *ptr2++ = 0; | |
| 45 | ||
| 46 | ptr2[0] = R; | |
| 47 | ptr2[1] = G; | |
| 48 | ptr2[2] = B; | |
| 49 | } | |
| 50 | else if(incrementPtr == 1) | |
| 51 | {
| |
| 52 | if(bpp == 4) | |
| 53 | *ptr++ = 0; | |
| 54 | ||
| 55 | *ptr++ = R; | |
| 56 | *ptr++ = G; | |
| 57 | *ptr++ = B; | |
| 58 | } | |
| 59 | else if(incrementPtr == -1) | |
| 60 | {
| |
| 61 | *(--ptr) = B; | |
| 62 | *(--ptr) = G; | |
| 63 | *(--ptr) = R; | |
| 64 | ||
| 65 | if(bpp == 4) | |
| 66 | *(--ptr) = 0; | |
| 67 | } | |
| 68 | else | |
| 69 | {
| |
| 70 | assert(0); | |
| 71 | } | |
| 72 | } | |
| 73 | ||
| 74 | template<int bpp, int incrementPtr> | |
| 75 | STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorRow(Uint8 *&ptr, const SDL_Color & Color, size_t count) | |
| 76 | {
| |
| 77 | Uint32 pixel = ((Uint32)Color.b << 16 ) + ((Uint32)Color.g << 8) + ((Uint32)Color.r << 0); | |
| 78 | ||
| 79 | for (size_t i=0; i<count; i++) | |
| 80 | {
| |
| 81 | memcpy(ptr, &pixel, bpp); | |
| 82 | if(incrementPtr == -1) | |
| 83 | ptr -= bpp; | |
| 84 | if(incrementPtr == 1) | |
| 85 | ptr += bpp; | |
| 86 | } | |
| 87 | } |