⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asm_pixel.asm

📁 图像处理
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;ASM_Pixel.asm  by Robert Rayment  7/11/01

;VB

; Assumes MCode Structure set
; MCode Structure
; Public Type MCodeStruc
;   PICW As Long
;   PICH As Long
;   PtrPalBGR As Long
;   PtrPalLineCopy As Long
;   Increment As Long
;   QBLongColor As Long
;   OpCode As Long
; End Type
; Public MCODE As MCodeStruc
;
; ptrStruc = VarPtr(MCODE.PICW)
; ptMC = VarPtr mcode byte array

; Pixel Effects
; OpCode& = 0    'Smooth (Increment)
; OpCode& = 1    'Contour
; OpCode& = 2    'Emboss
; OpCode& = 3    'Ripple
; OpCode& = 4    'Relief
; OpCode& = 5    'Twirl
;
; res = CallWindowProc(ptMC, ptrStruc, param1, param2, INT)
;                      [ebp +  8        12     16      20 ]
; End Sub


%macro movab 2		; name & num of parameters
  push dword %2		; 2nd param
  pop dword %1		; 1st param
%endmacro			; use  movab %1,%2
; Allows eg	movab bmW,[ebx+4]

%define PICW            [ebp-4]		; PICW Mod 4
%define PICH            [ebp-8]		; PICH
%define PtrPalBGR       [ebp-12]	; PTR to PalBGR(1,1,1,N)
%define PtrPalLineCopy  [ebp-16]	; PTR to PalLineCopy(4,1)
%define Increment       [ebp-20] 	; 1,2,4,8
%define QBLongColor     [ebp-24]    ; RGB(QBRed, QBGreen, QBBlue)	
%define OpCode          [ebp-28]    ; 0,1,2,, etc

%define PalSize    [ebp-32]
%define LineBytes  [ebp-36]
%define Mask2	   [ebp-40] 
%define Mask4	   [ebp-44] 
%define Mask8	   [ebp-48] 

%define ix    [ebp-52]
%define iy    [ebp-56]

%define QBBlue	   [ebp-60]	
%define QBGreen	   [ebp-64]	
%define QBRed	   [ebp-68]	
%define culBT 	   [ebp-72]	; Temps
%define culGT 	   [ebp-76]	
%define culRT 	   [ebp-80]	

%define YWave      [ebp-84]

%define radmax     [ebp-88]
%define ixc        [ebp-92]
%define iyc        [ebp-96]
%define zpimul     [ebp-100]
%define zSin       [ebp-104]
%define zCos       [ebp-108]
%define ixs        [ebp-112]
%define iys        [ebp-116]

[bits 32]

	push ebp
	mov ebp,esp
	sub esp,116
	push edi
	push esi
	push ebx
	push edx

	; Copy structure
	mov ebx,[ebp+8]
	
	movab PICW,          [ebx]
	movab PICH,          [ebx+4]
	movab PtrPalBGR,     [ebx+8]
	movab PtrPalLineCopy,[ebx+12]
	movab Increment,     [ebx+16]
	movab QBLongColor,   [ebx+20]
	movab OpCode,        [ebx+24]
	
	mov eax,PICH
	mov ebx,PICW
	mul ebx
	mov PalSize,eax		; In 4 byte chunks
	
	mov eax,PICW
	shl eax,2			; x4
	mov LineBytes,eax
	
	; Get RGB	
	mov eax,QBLongColor
	and eax,0FFh
	mov QBRed,eax
	mov eax,QBLongColor
	and eax,0FF00h
	shr eax,8
	mov QBGreen,eax
	mov eax,QBLongColor
	and eax,0FF0000h
	shr eax,16
	mov QBBlue,eax

	mov eax,0FEFEFEFEh
	mov Mask2,eax
	
	mov eax,0FCFCFCFCh
	mov Mask4,eax

	mov eax,0F8F8F8F8h
	mov Mask8,eax

	mov eax,OpCode
	cmp eax,0
	jne Test1
	Call near Smooth
	jmp near GETOUT
Test1:
	cmp eax,1
	jne Test2
	Call near Contour
	jmp near GETOUT
Test2:
	cmp eax,2
	jne Test3
	Call near Emboss
	jmp near GETOUT
Test3:
	cmp eax,3
	jne Test4
	Call near Ripple
	jmp near GETOUT
Test4:
	cmp eax,4
	jne Test5
	Call near Relief
	jmp near GETOUT
Test5:
	cmp eax,5
	jne Test6
	Call near Twirl
	jmp near GETOUT
Test6:

GETOUT:
	pop edx
	pop ebx
	pop esi
	pop edi
	mov esp,ebp
	pop ebp
	ret 16

;############################################################
;============================================================

Smooth:		; 0
	mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
	mov eax,PalSize
	shl eax,2			; x4
	add esi,eax			; pts to PalBGR(1,1,1,2) Blue
	push esi
	pop edi				; edi DEST to PalBGR(1,1,1,2) Blue
	add esi,eax			; esi SORCE to PalBGR(1,1,1,3) Blue

	mov eax,Increment
	cmp eax,1
	jne TI2
	Call near Smooth1
	RET
TI2:
	cmp eax,2
	jne TI4
	Call near Smooth2
	RET
TI4:
	cmp eax,4
	jne TI8
	Call near Smooth4
	RET
TI8:
	cmp eax,8
	jne TI16
	Call Near Smooth8
	RET 
TI16:

RET
;============================================================
Smooth1:		; esi->B3   o x o

	mov ecx,PICH	; iy PICH->1
SY1:
	push ecx
	mov iy,ecx

	mov ecx,PICW
	dec ecx			; ix PICW-2 -> 1
	dec ecx
SX1:
	mov ix,ecx
	
	push esi
	push edi
	
	Call near GetAddrESIixiy
	Call near GetAddrEDIixiy
	
	mov eax,[esi]
	and eax,Mask2
	shr eax,1
	
	mov edx,[esi+8]
	and edx,Mask2
	shr edx,1
	add eax,edx
	
	mov [edi+4],eax
	
	pop edi
	pop esi
	
	dec ecx
	jnz SX1
	
	pop ecx
	dec ecx
	jnz SY1
	
RET
;============================================================
Smooth2:		; esi->B3    o 
                ;            x
                ;            o 

	
	mov ecx,PICH	; iy PICH-2->1
	dec ecx
	dec ecx
SY2:
	push ecx
	mov iy,ecx

	mov ecx,PICW	; ix PICW ->1 
SX2:
	mov ix,ecx
	
	push esi
	push edi
	
	Call near GetAddrESIixiy
	Call near GetAddrEDIixiy
	
	mov ebx,PICW
	shl ebx,2

	mov eax,[esi]
	and eax,Mask2
	shr eax,1
	
	mov edx,[esi+ebx+ebx]
	and edx,Mask2
	shr edx,1
	add eax,edx
	
	mov [edi+ebx],eax
	
	pop edi
	pop esi
	
	dec ecx
	jnz SX2
	
	pop ecx
	dec ecx
	jnz SY2

RET
;============================================================
Smooth4:		; esi->B3    o   o
                ;              x
                ;            o   o

	mov ecx,PICH	; iy PICH-2->1
	dec ecx
	dec ecx
SY4:
	push ecx
	mov iy,ecx

	mov ecx,PICW	; ix PICW-2 ->1 
	dec ecx
	dec ecx
SX4:
	mov ix,ecx
	
	push esi
	push edi
	
	Call near GetAddrESIixiy
	Call near GetAddrEDIixiy
	
	mov ebx,PICW
	shl ebx,2
	
	mov eax,[esi]
	and eax,Mask4
	shr eax,2
	
	mov edx,[esi+ebx+ebx]
	and edx,Mask4
	shr edx,2
	add eax,edx
	
	mov edx,[esi+8]
	and edx,Mask4
	shr edx,2
	add eax,edx
	
	mov edx,[esi+ebx+ebx+8]
	and edx,Mask4
	shr edx,2
	add eax,edx
	
	
	mov [edi+ebx+4],eax
	
	pop edi
	pop esi
	
	dec ecx
	jnz SX4
	
	pop ecx
	dec ecx
	jnz SY4

RET
;============================================================
Smooth8:        ; esi->B3    o o o
                ;            o x o
                ;            o o o
                
                
	mov ecx,PICH	; iy PICH-2->1
	dec ecx
	dec ecx
SY8:
	push ecx
	mov iy,ecx

	mov ecx,PICW	; ix PICW-2 ->1 
	dec ecx
	dec ecx
SX8:
	mov ix,ecx
	
	push esi
	push edi
	
	Call near GetAddrESIixiy
	Call near GetAddrEDIixiy
	
	mov ebx,PICW
	shl ebx,2
	
	mov eax,[esi]
	and eax,Mask8
	shr eax,3
	mov edx,[esi+ebx]
	and edx,Mask8
	shr edx,3
	add eax,edx
	mov edx,[esi+ebx+ebx]
	and edx,Mask8
	shr edx,3
	add eax,edx

	mov edx,[esi+4]
	and edx,Mask8
	shr edx,3
	add eax,edx
	mov edx,[esi+ebx+ebx+4]
	and edx,Mask8
	shr edx,3
	add eax,edx
	
	mov edx,[esi+8]
	and edx,Mask8
	shr edx,3
	add eax,edx
	mov edx,[esi+ebx+8]
	and edx,Mask8
	shr edx,3
	add eax,edx
	mov edx,[esi+ebx+ebx+8]
	and edx,Mask8
	shr edx,3
	add eax,edx

	mov [edi+ebx+4],eax
	
	pop edi
	pop esi
	
	dec ecx
	jnz near SX8
	
	pop ecx
	dec ecx
	jnz near SY8

RET
;============================================================

				;                    6 7 8
Contour:     ;1 ; esi->B3  culBGR =  o o o   culBGR =  8 * x - SUM8(culBGR) + QBBGR
                ;                  4 o x o 5
                ;                    o o o
				;                    1 2 3

	mov ebx,PICW
	shl ebx,2

	mov esi,PtrPalBGR   ; pts to PalBGR(1,1,1,1)
	mov eax,PalSize
	shl eax,2			; x4
	add esi,eax			; pts to PalBGR(1,1,1,2) Blue
	add esi,ebx			; pts to PalBGR(1,1,2,2) Blue
	inc esi
	inc esi
	inc esi
	inc esi				; pts to PalBGR(1,2,2,2) Blue
	
	push esi
	pop edi				; edi DEST to PalBGR(1,2,2,2) Blue
	add esi,eax			; esi SOURCE to PalBGR(1,2,2,3) Blue

	
	mov ecx,PICH	; iy PICH-2->2
	dec ecx
	dec ecx
CY1:
	push ecx
	mov iy,ecx

	mov ecx,PICW	; ix PICW-2 ->2 
	dec ecx
	dec ecx
CX1:
	mov ix,ecx
	
	push esi
	push edi
	
	Call near GetAddrESIixiy
	Call near GetAddrEDIixiy
	
	mov ebx,PICW
	shl ebx,2
	;----------------------------
	; BLUE
	neg ebx
	movzx edx,byte[esi+ebx-4] ;1  == movzx edx,byte[esi-ebx-4]
	movzx eax,byte[esi+ebx]   ;2
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;3
	add edx,eax
	
	movzx eax,byte[esi-4]     ;4
	add edx,eax
	movzx eax,byte[esi+4]     ;5
	add edx,eax
	
	neg ebx
	movzx eax,byte[esi+ebx-4] ;6
	add edx,eax
	movzx eax,byte[esi+ebx]   ;7
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;8
	add edx,eax
	mov culBT,edx
	
	inc esi		; GREEN
	
	neg ebx
	movzx edx,byte[esi+ebx-4] ;1
	movzx eax,byte[esi+ebx]   ;2
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;3
	add edx,eax
	
	movzx eax,byte[esi-4]     ;4
	add edx,eax
	movzx eax,byte[esi+4]     ;5
	add edx,eax
	
	neg ebx
	movzx eax,byte[esi+ebx-4] ;6
	add edx,eax
	movzx eax,byte[esi+ebx]   ;7
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;8
	add edx,eax
	mov culGT,edx
	
	inc esi		; RED
	
	neg ebx
	movzx edx,byte[esi+ebx-4] ;1
	movzx eax,byte[esi+ebx]   ;2
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;3
	add edx,eax
	
	movzx eax,byte[esi-4]     ;4
	add edx,eax
	movzx eax,byte[esi+4]     ;5
	add edx,eax
	
	neg ebx
	movzx eax,byte[esi+ebx-4] ;6
	add edx,eax
	movzx eax,byte[esi+ebx]   ;7
	add edx,eax
	movzx eax,byte[esi+ebx+4] ;8
	add edx,eax
	mov culRT,edx
	
	dec esi
	dec esi
	
	movzx eax,byte[esi]		; B
	shl eax,3				; 8 * PalBGR(1,ix,iy,3)
	sub eax,culBT
	add eax,QBBlue			; 8 * PalBGR(1,ix,iy,3) - CulBT + QBBlue
	mov culBT,eax
	
	movzx eax,byte[esi+1]	; G
	shl eax,3
	sub eax,culGT
	add eax,QBGreen
	mov culGT,eax

	movzx eax,byte[esi+2]	; R
	shl eax,3
	sub eax,culRT
	add eax,QBRed
	mov culRT,eax
	
	;Check culBGRT size 0-255
	Call near CheckculBGRT
	;----------------------------
	mov eax,culBT
	mov byte[edi],aL
	mov eax,culGT
	mov [edi+1],aL
	mov eax,culRT
	mov [edi+2],aL
	
	pop edi
	pop esi
	
	dec ecx
	cmp ecx,2
	jae near CX1
	
	pop ecx
	dec ecx
	cmp ecx,2
	jae near CY1

RET
;============================================================

CheckculBGRT:
	
	; Ensure colors in range
	mov eax,255
	cmp culBT,eax	; culBT-255
	jle THG
	mov culBT,eax
THG:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -