📄 render_rend.c.svn-base
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "config.h"#include "render_rend.h"#include "cxform.h"#include "matrix.h"#include "rect.h"#include "instance.h"#include "base_types.h"#include "bitmap_def.h"#include "render_mask.h"#include <assert.h>#if WITH_DMALLOC#include <dmalloc.h>#endifextern player_t *player_p;extern first_frame;extern struct RECT Bbox;extern unsigned char SQRT[];extern unsigned int canvassize;extern unsigned int gmaskflag;extern unsigned int gmaskedflag;extern int save;extern struct savearea *currentpic;extern struct RECT idrect;struct RGB BackgroundColorCopy;struct GraphicDevice gd;#define FULL_AA#define PRINT 0typedef unsigned long TYPE;void maskfunc(GraphicDevice *gd1,long y,long start,long end) { struct MaskEntry *currentmaskentry; unsigned char *currentmaskpointer; currentmaskentry=player_p->_level0_p->mask_stack_p; currentmaskpointer=currentmaskentry->maskpointer;}int maskedfunc(GraphicDevice *gd1,TYPE *point) { struct MaskEntry *currentmaskentry; unsigned char *currentmaskpointer; currentmaskentry=player_p->_level0_p->mask_stack_p; currentmaskpointer=currentmaskentry->maskpointer; switch((((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer))<<29)>>29) { case 0: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x01) return 1; else return 0; break; case 1: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x02) return 1; else return 0; break; case 2: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x04) return 1; else return 0; break; case 3: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x08) return 1; else return 0; break; case 4: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x10) return 1; else return 0; break; case 5: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x20) return 1; else return 0; break; case 6: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x40) return 1; else return 0; break; case 7: if(*(currentmaskpointer+(unsigned int)((((unsigned int)((unsigned int)(point)-(unsigned int)(gd1->canvasBuffer)))>>3)))&0x80) return 1; else return 0; break; }}long allocColor16(GraphicDevice *gd1,Color color) { // return (color.Red >> 3)<<11 | (color.Green>>2)<<5 | (color.Blue>>3); return ((color.Alpha)<<24|(color.Red)<<16 | (color.Green)<<8 |(color.Blue));}voidclearCanvas16(GraphicDevice *gd1,int first_frame) { TYPE pixel; TYPE *point,*p; long h, w,n; if (!gd1->bgInitialized) { return; } gd1->backgroundColor.Red=player_p->_level0_p->BackgroundColor.Red; gd1->backgroundColor.Green=player_p->_level0_p->BackgroundColor.Green; gd1->backgroundColor.Blue=player_p->_level0_p->BackgroundColor.Blue; if((BackgroundColorCopy.Red!=player_p->_level0_p->BackgroundColor.Red)||(BackgroundColorCopy.Green!=player_p->_level0_p->BackgroundColor.Green)||(BackgroundColorCopy.Blue!=player_p->_level0_p->BackgroundColor.Blue)) { BackgroundColorCopy=player_p->_level0_p->BackgroundColor; gd1->backgroundColor.Red=player_p->_level0_p->BackgroundColor.Red; gd1->backgroundColor.Green=player_p->_level0_p->BackgroundColor.Green; gd1->backgroundColor.Blue=player_p->_level0_p->BackgroundColor.Blue; gd1->backgroundColor.Alpha=255; } // printf("gd->badckgouclor.alpha is %d\n",gd.backgroundColor.Alpha); pixel = allocColor16(gd1,gd1->backgroundColor); // printf("pixel is %ld\n",pixel); //printf("clip_rect.xmin=%ld clip_rect.ymin=%ld clip_rect.xmax=%ld clip_rect.ymax=%ld\n",gd->clip_rect.Xmin,gd->clip_rect.Ymin,gd->clip_rect.Xmax,gd->clip_rect.Ymax); if(first_frame==0) { point = (TYPE *) (gd1->canvasBuffer + gd1->clip_rect.Ymin * (gd1->bpl/2)) + gd1->clip_rect.Xmin; point = (TYPE *) ((unsigned char*)(gd1->canvasBuffer) + gd1->clip_rect.Ymin * (gd1->bpl)*2)+gd1->clip_rect.Xmin; w = gd1->clip_rect.Xmax - gd1->clip_rect.Xmin; h = gd1->clip_rect.Ymax - gd1->clip_rect.Ymin;#if 0 asm( "up: pushl %%ecx;" // 压入 h "movl %%ebx,%%ecx;" // 将 w 赋给 ecx "cld;" "rep;" "stosw;" // 将 ax 内容写入 edi 起 ecx 个 word 中 "popl %%ecx;" // 恢复 h "addl %%edx,%%edi;" // 计算下行填充的起始地址 "loop up;" // h - 1 并循环到 up. : : "c"(h),"b"(w),"D"(point),"a"(pixel),"d"(gd1->bpl-w*2));#else while (h--) { p = point; n = w; while (n--) { *p++ = pixel; //printf("to update clip rect\n"); } point = (TYPE *)((char *)point + gd1->bpl*2); }#endif } else { first_frame=0; point = (TYPE *) ((unsigned char*)(gd1->canvasBuffer) + gd1->viewPort.Ymin * (gd1->bpl)*2); w = gd1->viewPort.Xmax - gd1->viewPort.Xmin; h = (gd1->viewPort.Ymax - gd1->viewPort.Ymin); //printf("w is %ld h is %ld\n",w,h); while (h--) { p = point; n = w; while (n--) { *p++ = pixel; //assert(pixel==-1); //*p++ = 0xffffffff; } point = (TYPE *)((char *)point + gd1->bpl*2); } } gd1->flashDisplay->flash_refresh = 1; gd1->flashDisplay->clip_x = gd1->clip_rect.Xmin; gd1->flashDisplay->clip_y = gd1->clip_rect.Ymin; gd1->flashDisplay->clip_width = gd1->clip_rect.Xmax-gd1->clip_rect.Xmin; gd1->flashDisplay->clip_height = gd1->clip_rect.Ymax-gd1->clip_rect.Ymin;}/*#define RED_MASK 0xF800#define GREEN_MASK 0x07E0#define BLUE_MASK 0x001F*//*#define RED_MASK 0xFF000000#define GREEN_MASK 0x00FF0000#define BLUE_MASK 0x0000FF00#define ALPHA_MASK 0x000000FF*/#define RED_MASK 0x00FF0000#define GREEN_MASK 0x0000FF00#define BLUE_MASK 0x000000FF#define ALPHA_MASK 0xFF000000/*voidmix_alpha(unsigned long c1,unsigned long c2,unsigned long p1,unsigned long p2,struct tb *s) { long r1,r2,r3,r4,r,rr; long g1,g2,g3,g4,g,gg; long b1,b2,b3,b4,b,bb; long a1,a2; a1=(p1 & ALPHA_MASK)>>24; a2=(p2 & ALPHA_MASK)>>24; // printf("a1 is %ld a2 is %ld\n",a1,a1); r1 = (c1 & RED_MASK); r2 = (c2 & RED_MASK); r3 = (p1 & RED_MASK); r4 = (p2 & RED_MASK); r = (((r3-r1)*a1 + r1 * 256)>>8 ) & RED_MASK; rr = (((r4-r2)*a2 + r2 * 256)>>8 ) & RED_MASK; g1 = (c1 & GREEN_MASK); g2 = (c2 & GREEN_MASK); g3 = (p1 & GREEN_MASK); g4 = (p2 & GREEN_MASK); g = (((g3-g1)*a1 + g1 * 256)>>8) & GREEN_MASK; gg = (((g4-g2)*a2 + g2 * 256)>>8) & GREEN_MASK; b1 = (c1 & BLUE_MASK); b2 = (c2 & BLUE_MASK); b3 = (p1 & BLUE_MASK); b4 = (p2 & BLUE_MASK); b = (((b3-b1)*a1 + b1 * 256) >> 8) & BLUE_MASK; bb = (((b4-b2)*a2 + b2 * 256) >> 8) & BLUE_MASK; s->p1=(r|g|b); s->p2=(rr|gg|bb); return ;}*/void inline mix_line(uint32_t *top, uint32_t *bottom, int length) { asm( "cld;" "xor %%eax,%%eax;" "movd %%eax, %%mm7;" // mixed = (alpha*(src-dst))/256 + dst // 为防止 alpha*(src-dst) 处乘法溢出,将等式改为. // mixed = (src-dst)/2*alpha/128 + dst // mm0 alpha // mm1 dst // mm2 src // mm7 0 "up:xor %%eax,%%eax;" "movl (%%esi),%%eax;"// src -> eax; "cmp $0xff000000,%%eax;" "jae fu_gai;" "cmp $0x01000000,%%eax;" "jb tou_ming;" "movd (%%edi),%%mm1;"// 将底图的点 dst 装入 mm1 "movd %%eax,%%mm2;"// 将顶图的点 src 装入 mm2 "shr $24, %%eax;" "movd %%eax,%%mm0;" "punpcklwd %%mm0,%%mm0;"// 00 aa 变成 00 aa 00 aa "punpckldq %%mm0,%%mm0;"// 00 aa 00 aa 变成 00 aa 00 aa 00 aa 00 aa "punpcklbw %%mm7,%%mm1;"// 将 dst 8:8:8:8 的点展开为 16:16:16:16 的格式. "punpcklbw %%mm7,%%mm2;"// 将 src 8:8:8:8 的点展开为 16:16:16:16 的格式. "psubsw %%mm1,%%mm2;" // 将顶图的颜色减去底图的颜色 (src - dst)->mm2 ; "psraw $1,%%mm2;" // / 2 -> mm2; "pmullw %%mm0,%%mm2;" // * alpha -> mm2; "psraw $7,%%mm2;" // / 128 -> mm2; "paddsw %%mm2,%%mm1;" // + dst; "packuswb %%mm7,%%mm1;" // 将加的结果 由 16:16:16:16 的格式 pack 为 8:8:8:8 的格式; "movd %%mm1,(%%edi);" "add $4,%%esi;" "add $4,%%edi;" "loop up;" "jmp get_out;" "fu_gai:;" "stosl;" "add $4,%%esi;" "loop up;" "jmp get_out;" "tou_ming:;" "add $4,%%esi;" "add $4,%%edi;" "loop up;" "get_out:;" "emms;" : : "c"(length),"S"(top),"D"(bottom));}voidfillLineAA16(GraphicDevice *gd1,FillStyleDef *f, long y, long start, long end) { register long n; long start1,end1,start2,end2; TYPE *line,*line1; unsigned char *point2,*line2; TYPE *point,pixel,*point1,*ppmax,*ppmin; unsigned long alpha, start_alpha,end_alpha; start1=start; end1=end; start2=start; end2=end; start2 >>= FRAC_BITS; end2 >>= FRAC_BITS; alpha = f->Color.Alpha; pixel = f->Color.pixel; //printf("idrect aa xmin is %ld ymin is %ld xmax is %ld ymax is %ld\n",idrect.Xmin,idrect.Ymin,idrect.Xmax,idrect.Ymax); //printf("y is %ld start is %ld end is %ld\n",y,start2,end2); if(start>end) start=end; if(save==1&¤tpic&&gmaskflag==0) { if(currentpic) { ppmax=(unsigned long*)(currentpic->pp)+(idrect.Xmax-idrect.Xmin+1)*(idrect.Ymax-idrect.Ymin+1); ppmin=(unsigned long*)(currentpic->pp); } /*start_alpha = 255 - ((start & (FRAC-1)) << (8-FRAC_BITS)); end_alpha = (end & (FRAC-1)) << (8-FRAC_BITS); start >>= FRAC_BITS; end >>= FRAC_BITS;*/ if(((unsigned long*)(currentpic->pp)+(idrect.Xmax-idrect.Xmin)*(y-idrect.Ymin))>ppmax) return; if(((unsigned long*)(currentpic->pp)+(idrect.Xmax-idrect.Xmin)*(y-idrect.Ymin))<ppmin) return; line1=(TYPE *) ((unsigned long*)(currentpic->pp)+(idrect.Xmax-idrect.Xmin)*(y-idrect.Ymin)); // printf("x1 is %ld x2 is %ld\n",currentpic->sp[y-idrect.Ymin].x1,currentpic->sp[y-idrect.Ymin].x2); /* if(currentpic->fillflag==0) { //if(start-idrect.Xmin<=currentpic->sp[y-idrect.Ymin].x1) currentpic->sp[y-idrect.Ymin].x1=start-idrect.Xmin-1; //if(end-idrect.Xmin>=currentpic->sp[y-idrect.Ymin].x2) currentpic->sp[y-idrect.Ymin].x2=end-idrect.Xmin+1; // printf("x1 is %ld x2 is %ld\n",currentpic->sp[y-idrect.Ymin].x1,currentpic->sp[y-idrect.Ymin].x2); }*/ if (alpha == ALPHA_OPAQUE) { start_alpha = 255 - ((start & (FRAC-1)) << (8-FRAC_BITS));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -