Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<int bpp, int incrementPtr>
- STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlphaSwitch(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
- {
- Uint *ptr2 = ptr;
- if (bpp == 4)
- ptr2++;
- switch (A)
- {
- case 255:
- ptr += bpp * incrementPtr;
- return;
- case 0:
- PutColor(ptr, R, G, B);
- return;
- case 128: // optimized
- PutColor(ptr, ((Uint16)R + (Uint16)ptr2[1]) >> 1,
- ((Uint16)G + (Uint16)ptr2[2]) >> 1,
- ((Uint16)B + (Uint16)ptr2[3]) >> 1);
- return;
- default:
- PutColor(ptr, R, G, B, A);
- return;
- }
- }
- template<int bpp, int incrementPtr>
- STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B, const Uint8 & A)
- {
- Uint *ptr2 = ptr;
- if (bpp == 4)
- ptr2++;
- PutColor(ptr, ((((Uint32)ptr2[1]-(Uint32)R)*(Uint32)A) >> 8 ) + (Uint32)R,
- ((((Uint32)ptr2[2]-(Uint32)G)*(Uint32)A) >> 8 ) + (Uint32)G,
- ((((Uint32)ptr2[3]-(Uint32)B)*(Uint32)A) >> 8 ) + (Uint32)B);
- }
- template<int bpp, int incrementPtr>
- STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColor(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B)
- {
- if(incrementPtr == 0)
- {
- Uint8 *ptr2 = ptr;
- if(bpp == 4)
- *ptr2++ = 0;
- ptr2[0] = R;
- ptr2[1] = G;
- ptr2[2] = B;
- }
- else if(incrementPtr == 1)
- {
- if(bpp == 4)
- *ptr++ = 0;
- *ptr++ = R;
- *ptr++ = G;
- *ptr++ = B;
- }
- else if(incrementPtr == -1)
- {
- *(--ptr) = B;
- *(--ptr) = G;
- *(--ptr) = R;
- if(bpp == 4)
- *(--ptr) = 0;
- }
- else
- {
- assert(0);
- }
- }
- template<int bpp, int incrementPtr>
- STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorRow(Uint8 *&ptr, const SDL_Color & Color, size_t count)
- {
- Uint32 pixel = ((Uint32)Color.b << 16 ) + ((Uint32)Color.g << 8) + ((Uint32)Color.r << 0);
- for (size_t i=0; i<count; i++)
- {
- memcpy(ptr, &pixel, bpp);
- if(incrementPtr == -1)
- ptr -= bpp;
- if(incrementPtr == 1)
- ptr += bpp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement