Changeset 60:e16e13d8cd68 for window/render.cc
- Timestamp:
- 12/18/09 20:41:38 (2 years ago)
- Branch:
- default
- Files:
-
- 1 modified
-
window/render.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
window/render.cc
r56 r60 252 252 #define CMASK2 0x00ff00 253 253 254 inline void blit_pixel(Uint32* d mem, Uint32* smem, const unsigned char* amem, bool use_srcalpha) {255 Uint32 d = *dmem;256 Uint32 s = *smem;257 Uint32 as = s >>ASHIFT;254 inline 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; 258 258 if (as == 255 || (!use_srcalpha) ) { 259 as = *a mem;259 as = *alpha; 260 260 } else { 261 as += as>>7; /* 0-0xff -> 0-0x100 */262 as *= *a mem;261 as += (as >> 7); /* 0-0xff -> 0-0x100 */ 262 as *= *alpha; 263 263 as >>= 8; 264 264 } 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 280 static void blit_line(Uint32* dest, Uint32* src, const unsigned char* alpha,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { 276 281 int j; 277 282 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; 281 284 if (awidth == 1) { // €ï€ê€È€è€¯€¢€ë€Î€ÇºÇŬ²œ 282 285 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 { 286 291 for (j=aj0; j < aj1; j++) { 287 292 for (; ax<awidth; ax++) 288 blit_pixel(d ++, s++, a++, use_srcalpha);293 blit_pixel(dest++, src++, a++, use_srcalpha); 289 294 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 302 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect) 303 { 297 304 SDL_Surface* dst = (SDL_Surface*)dst_o; 298 305 SDL_Surface* src = (SDL_Surface*)src_o; … … 347 354 } 348 355 349 void DSurfaceBlit Saturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) {356 void DSurfaceBlitAdd(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { 350 357 SDL_Surface* dst = (SDL_Surface*)dst_o; 351 358 SDL_Surface* src = (SDL_Surface*)src_o; … … 371 378 int gshift = fmt.Gshift - fmt.Gloss; int gmask = fmt.Gmask; 372 379 int bshift = fmt.Bshift - fmt.Bloss; int bmask = fmt.Bmask; 380 int ashift = src->format->Ashift - src->format->Aloss; int amask = src->format->Amask; 373 381 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++) { 376 384 char* d = dmem; char* s = smem; 377 int j; for (j=0; j<width; j++) {385 for (j=0; j < width; j++) { 378 386 Uint32 sd = *(Uint32*)s; 379 387 Uint32 dd = *(Uint32*)d; … … 382 390 Uint32 sg = (sd&gmask)>>gshift; 383 391 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; 388 405 } 389 406 Uint32 dr = sr + ((dd&rmask)>>rshift);
![(please configure the [header_logo] section in trac.ini)](/otakunoraifu/chrome/site/your_project_logo.png)