| 
 
| 赞 | 0 |  
| VIP | 0 |  
| 好人卡 | 0 |  
| 积分 | 2 |  
| 经验 | 11219 |  
| 最后登录 | 2012-8-9 |  
| 在线时间 | 698 小时 |  
 Lv1.梦旅人 
	梦石0 星屑165 在线时间698 小时注册时间2009-11-15帖子538 | 
| 
本帖最后由 2719358 于 2012-2-9 17:28 编辑
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  
 由于我目前正在开发引擎的缘故,请问RM里的色调(更改画面色调)的原理是什么.
 我自己用C+嵌入汇编写了一个但不完美,
 1.在任意值为0xff时并不会变成这种颜色,这是预想内的,因为我现在的算法是:最终颜色=颜色一/2+颜色2/2
 需要手动判断每个分量是否为0xff吗
 2.我这个只能使一张图片变色,而不能对整个画面变色,RM是每帧都执行一遍函数为画面变色吗?那样的话效率会不会很低?
 
 3.无法变回原色
 翻译成Ruby:
 
 
 def tcolor(c1,c2)        r1=(c1>>16)&0xff        g1=(c1>>8 )&0xff        b1=(c1)&0xff        r2=(c2>>16)&0xff        g2=(c2>>8 )&0xff        b2=(c2)&0xff        return ((r1/2+r2/2)<<16)+((g1/2+g2/2)<<8)+(b1/2+b2/2)enddef set_color(r,g,b)        c=(r<<16)+(g<<8)+b        LockSurface(pScreen);        Width.times{|i|                Height.times{|j|                                                putpixel(i,j,Tcolor(c,getpixel(i,j)))                }        }        UnlockSurface(pScreen);end
def tcolor(c1,c2) 
        r1=(c1>>16)&0xff 
        g1=(c1>>8 )&0xff 
        b1=(c1)&0xff 
        r2=(c2>>16)&0xff 
        g2=(c2>>8 )&0xff 
        b2=(c2)&0xff 
        return ((r1/2+r2/2)<<16)+((g1/2+g2/2)<<8)+(b1/2+b2/2) 
end 
def set_color(r,g,b) 
        c=(r<<16)+(g<<8)+b 
        LockSurface(pScreen); 
        Width.times{|i| 
                Height.times{|j|                         
                        putpixel(i,j,Tcolor(c,getpixel(i,j))) 
                } 
        } 
        UnlockSurface(pScreen); 
end 
C+内嵌汇编:
 
 Uint32 Tcolor(Uint32 c1,Uint32 c2)                {                        Uint8 r1;                        Uint8 g1;                        Uint8 b1;                        Uint8 r2;                        Uint8 g2;                        Uint8 b2;                        Uint32 rgb;                                        _asm                        {                                                        ;取得各个RGB分量                                        ;********                                        mov eax,c1                                        mov cl,16                                        shr eax,cl                                        mov r1,al                                        ;********                                        mov eax,c1                                        mov cl,8                                        shr eax,cl                                        mov g1,al                                        ;********                                        mov eax,c1                                        mov b1,al                                        ;********                                        mov eax,c2                                        mov cl,16                                        shr eax,cl                                        mov r2,al                                        ;*********                                        mov eax,c2                                        mov cl,8                                        shr eax,cl                                        mov g2,al                                        ;*********                                        mov eax,c2                                        mov b2,al                                         ;*****************************************                                        ;开始处理 R                                         mov ax,0                                          mov al,r1                                          mov cl,2                                        div cl                                          mov bl,al                                           mov al,r2                                          mov cl,8                                        div cl                                              add al,bl                                          mov ah,0                                        mov cl,16                                          shl al,cl                                          mov ebx,eax                                          ;*****************************************                                        ;开始处理 G                                        mov eax,0                                         mov al,g1                                         mov cl,2                                        div cl                                            mov ah,0                                         mov bh,al                                         mov al,g2                                        mov cl,2                                        div cl                                             mov ah,0                                         add bh,al                                         ;*****************************************                                        ;开始处理 B                                         mov al,b1                                        mov cl,2                                        div cl                                           mov ah,0                                         mov bl,al                                         mov al,b2                                        mov cl,2                                        div cl                                          add bl,al                                         ;处理完毕                                        mov rgb,ebx                         }                        return rgb;                }
Uint32 Tcolor(Uint32 c1,Uint32 c2) 
                { 
                        Uint8 r1; 
                        Uint8 g1; 
                        Uint8 b1; 
                        Uint8 r2; 
                        Uint8 g2; 
                        Uint8 b2; 
                        Uint32 rgb;                 
                        _asm 
                        {                 
                                        ;取得各个RGB分量 
                                        ;******** 
                                        mov eax,c1 
                                        mov cl,16 
                                        shr eax,cl 
                                        mov r1,al 
                                        ;******** 
                                        mov eax,c1 
                                        mov cl,8 
                                        shr eax,cl 
                                        mov g1,al 
                                        ;******** 
                                        mov eax,c1 
                                        mov b1,al 
                                        ;******** 
                                        mov eax,c2 
                                        mov cl,16 
                                        shr eax,cl 
                                        mov r2,al 
                                        ;********* 
                                        mov eax,c2 
                                        mov cl,8 
                                        shr eax,cl 
                                        mov g2,al 
                                        ;********* 
                                        mov eax,c2 
                                        mov b2,al 
  
                                        ;***************************************** 
                                        ;开始处理 R 
  
                                        mov ax,0 
  
  
                                        mov al,r1   
                                        mov cl,2 
                                        div cl 
  
  
                                        mov bl,al   
  
                                        mov al,r2   
                                        mov cl,8 
                                        div cl      
  
                                        add al,bl   
                                        mov ah,0 
                                        mov cl,16   
                                        shl al,cl  
  
                                        mov ebx,eax 
  
  
                                        ;***************************************** 
                                        ;开始处理 G 
                                        mov eax,0 
  
                                        mov al,g1 
  
                                        mov cl,2 
                                        div cl    
  
                                        mov ah,0 
  
                                        mov bh,al 
  
                                        mov al,g2 
                                        mov cl,2 
                                        div cl     
  
                                        mov ah,0 
  
                                        add bh,al 
  
                                        ;***************************************** 
                                        ;开始处理 B 
  
                                        mov al,b1 
                                        mov cl,2 
                                        div cl   
  
                                        mov ah,0 
  
                                        mov bl,al 
  
                                        mov al,b2 
                                        mov cl,2 
                                        div cl 
  
  
                                        add bl,al 
  
                                        ;处理完毕 
                                        mov rgb,ebx 
  
                        } 
                        return rgb; 
                } 
 
 void SetColor(Uint8 r,Uint8 g,Uint8 b)                {                        Uint32 c = (r<<16)+(g<<8)+b;                        LockSurface(pScreen);                         for (int i=0;i<Width();i++)                        {                                for (int j=0;j<Height();j++)                                {                                        putpixel(i,j,Tcolor(c,getpixel(i,j)));                                }                        }                         UnlockSurface(pScreen);                }
void SetColor(Uint8 r,Uint8 g,Uint8 b) 
                { 
                        Uint32 c = (r<<16)+(g<<8)+b; 
                        LockSurface(pScreen); 
  
                        for (int i=0;i<Width();i++) 
                        { 
                                for (int j=0;j<Height();j++) 
                                { 
                                        putpixel(i,j,Tcolor(c,getpixel(i,j))); 
                                } 
                        } 
  
                        UnlockSurface(pScreen); 
                } 
 | 
 |