![](/icons/4265de.gif)
![](/icons/4265yi.gif)
![](/icons/4265yi.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265yinwei.gif)
![](/icons/4265yi.gif)
![](/icons/4265de.gif)
先设 color 是 RGB 565 
![](/icons/4265de.gif)
![](/icons/4265de.gif)
RRRRR GGGGGG BBBBB 
5位 6位 5位 
而 386 以上 CPU 都有 32 位
![](/icons/4265de.gif)
00000 GGGGGG 00000 RRRRR 000000 BBBBB 
5位 6位 5位 5位 6位 5位 
储存在 32 位寄存器中,(就是把绿色提到 前 16 位里) 由于64k 色下颜色深度是 32 级
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
最近温习了
![](/icons/4265yi.gif)
![](/icons/4265diaoyong.gif)
![](/icons/4265de.gif)
![](/icons/4265hanshu.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265yi.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265chengxu.gif)
![](/icons/4265cuowu.gif)
![](/icons/4265de.gif)
; 对 16bit 
![](/icons/4265de.gif)
; R=(r1*alpha+r2*(32-alpha))/32 
; G=(g1*alpha+g2*(32-alpha))/32 
; B=(b1*alpha+b2*(32-alpha))/32 
; C 语言
![](/icons/4265diaoyong.gif)
![](/icons/4265hanshu.gif)
; By Cloud Wu ([email protected]) 
; (
; ------------------------------------------------------------------------- 
; unsigned long alpha (unsigned long c1,unsigned long c2,unsigned long alpha); 
; ------------------------------------------------------------------------- 
; c1: 颜色1 RGB (565), c2: 颜色2 RGB (565), alpha: Alpha值 (0~31) 
; NASM 编译通过 
[BITS 32] 
[GLOBAL _alpha] 
[SECTION .text] 
_alpha: 
; 
![](/icons/4265chushi.gif)
push ebp ebp 压栈 
mov ebp,esp 保存 esp 到 ebp 
mov edi,0x7e0f81f dx=00000111111000001111100000011111 
add esp,8 esp 指向参数 c1 
pop eax 弹出 c1 到 ax 
pop ebx 弹出 c2 到 bx 
; 处理颜色 
mov cx,ax cx=r1..b1 
mov dx,ax dx=r2..b2 
sal eax,16 eax=r1g1b1...... 
sal ebx,16 ebx=r2g2b2...... 
mov ax,cx eax=r1g1b1r1g1b1 
mov bx,dx ebx=r2g2b2r2g2b2 
and eax,edi eax=..g1..r1..b1 
pop esi 弹出 alpha 
mul esi eax*=alpha 
neg esi -alpha 
and ebx,edi ebx=..g2..r2..b2 
add esi,0x20 32-alpha 
xchg eax,ebx 交换 eax,ebx 
mul esi c2*=(32-alpha) 
add eax,ebx c1*alpha+c2*(32-alpha) 
mov esp,ebp 
sar eax,5 ;color=(c1*alpha+c2*(32-alpha))/32 
;还原成 RGB 形式 
pop ebp 
and eax,edi color=..g..r..b 
mov cx,ax 
sar eax,16 
or ax,cx color=rgb (eax) 
ret 
如果建
![](/icons/4265yi.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265hanshu.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
![](/icons/4265de.gif)
最新评论