Show
Ignore:
Timestamp:
12/18/09 20:41:38 (2 years ago)
Author:
Thibaut GIRKA <thib@…>
Branch:
default
Message:
Replaced SATURATE -> ADD, implemented objComposite, corrected minor things
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • window/render.cc

    r56 r60  
    252252#define CMASK2 0x00ff00 
    253253 
    254 inline void blit_pixel(Uint32* dmem, Uint32* smem, const unsigned char* amem, bool use_srcalpha) { 
    255         Uint32 d = *dmem; 
    256         Uint32 s = *smem; 
    257         Uint32 as = s>>ASHIFT; 
     254inline void blit_pixel(Uint32* dest, Uint32* src, const unsigned char* alpha, bool use_srcalpha) { 
     255        Uint32 dest_value = *dest; 
     256        Uint32 src_value = *src; 
     257        Uint32 as = src_value >> ASHIFT; 
    258258        if (as == 255 || (!use_srcalpha) ) { 
    259                 as = *amem; 
     259                as = *alpha; 
    260260        } else { 
    261                 as += as>>7; /* 0-0xff -> 0-0x100 */ 
    262                 as *= *amem; 
     261                as += (as >> 7); /* 0-0xff -> 0-0x100 */ 
     262                as *= *alpha; 
    263263                as >>= 8; 
    264264        } 
    265         as += as>>7; 
    266         Uint32 s1 = s & CMASK1; 
    267         Uint32 d1 = d & CMASK1; 
    268         d1 = (d1 + (((s1-d1) * as) >> 8)) & CMASK1; 
    269         s &= CMASK2; 
    270         d &= CMASK2; 
    271         d = (d + (((s-d) * as) >> 8)) & CMASK2; 
    272         *dmem = d1 | d | 0xff000000; 
    273 } 
    274  
    275 static void blit_line(Uint32* dmem, Uint32* smem, const unsigned char* amem,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { 
     265        as += as >> 7; 
     266        // Isolate Red and Blue components 
     267        Uint32 src_c1 = src_value & CMASK1; 
     268        Uint32 dest_c1 = dest_value & CMASK1; 
     269        // Blend Red and Blue components 
     270        dest_c1 = (dest_c1 + (((src_c1-dest_c1) * as) >> 8)) & CMASK1; 
     271        // Isolate Green component 
     272        src_value &= CMASK2; 
     273        dest_value &= CMASK2; 
     274        // Blend Green component 
     275        dest_value = (dest_value + (((src_value-dest_value) * as) >> 8)) & CMASK2; 
     276        // Put it alltogether 
     277        *dest = dest_c1 | dest_value | 0xff000000; 
     278} 
     279 
     280static void blit_line(Uint32* dest, Uint32* src, const unsigned char* alpha,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { 
    276281        int j; 
    277282        int ax = ax0; 
    278         const unsigned char* a = amem + ax0; 
    279         Uint32* d = dmem; 
    280         Uint32* s = smem; 
     283        const unsigned char* a = alpha + ax0; 
    281284        if (awidth == 1) { //  €ï€ê€È€è€¯€¢€ë€Î€ÇºÇŬ²œ 
    282285                for (j=aj0; j < aj1; j++) { 
    283                         blit_pixel(d++, s++, amem, use_srcalpha); 
    284                 } 
    285         } else { 
     286                        blit_pixel(dest++, src++, alpha, use_srcalpha); 
     287                } 
     288        } 
     289        else 
     290        { 
    286291                for (j=aj0; j < aj1; j++) { 
    287292                        for (; ax<awidth; ax++) 
    288                                 blit_pixel(d++, s++, a++, use_srcalpha); 
     293                                blit_pixel(dest++, src++, a++, use_srcalpha); 
    289294                        ax = 0; 
    290                         a = amem; 
    291                 } 
    292                 for (; ax < ax1; ax++) blit_pixel(d++, s++, a++, use_srcalpha); 
    293         } 
    294 } 
    295  
    296 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect) { 
     295                        a = alpha; 
     296                } 
     297                for (; ax < ax1; ax++) 
     298                        blit_pixel(dest++, src++, a++, use_srcalpha); 
     299        } 
     300} 
     301 
     302void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect) 
     303{ 
    297304        SDL_Surface* dst = (SDL_Surface*)dst_o; 
    298305        SDL_Surface* src = (SDL_Surface*)src_o; 
     
    347354} 
    348355 
    349 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { 
     356void DSurfaceBlitAdd(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { 
    350357        SDL_Surface* dst = (SDL_Surface*)dst_o; 
    351358        SDL_Surface* src = (SDL_Surface*)src_o; 
     
    371378        int gshift = fmt.Gshift - fmt.Gloss; int gmask = fmt.Gmask; 
    372379        int bshift = fmt.Bshift - fmt.Bloss; int bmask = fmt.Bmask; 
     380        int ashift = src->format->Ashift - src->format->Aloss; int amask = src->format->Amask; 
    373381        int allmask = rmask | gmask | bmask; 
    374         int i; 
    375         for (i=0; i<height; i++) { 
     382        int i, j; 
     383        for (i=0; i < height; i++) { 
    376384                char* d = dmem; char* s = smem; 
    377                 int j; for (j=0; j<width; j++) { 
     385                for (j=0; j < width; j++) { 
    378386                        Uint32 sd = *(Uint32*)s; 
    379387                        Uint32 dd = *(Uint32*)d; 
     
    382390                                Uint32 sg = (sd&gmask)>>gshift; 
    383391                                Uint32 sb = (sd&bmask)>>bshift; 
    384                                 if (alpha != ALPHA_MAX) { 
    385                                         sr = (sr*alpha)>>8; 
    386                                         sg = (sg*alpha)>>8; 
    387                                         sb = (sb*alpha)>>8; 
     392                                Uint32 alpha2 = alpha; 
     393                                if (amask) 
     394                                { 
     395                                        alpha2 = ((sd&amask)>>ashift); 
     396                                        alpha2 += alpha2 >> 7; 
     397                                        alpha2 *= alpha; 
     398                                        alpha2 >>= 8; 
     399                                } 
     400                                 
     401                                if (alpha2 != ALPHA_MAX) { 
     402                                        sr = (sr*alpha2)>>8; 
     403                                        sg = (sg*alpha2)>>8; 
     404                                        sb = (sb*alpha2)>>8; 
    388405                                } 
    389406                                Uint32 dr = sr + ((dd&rmask)>>rshift);