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

📄 asm_palette.asm

📁 图像处理
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	mov aL,Increment	;00 In In In
	                    ;A  R  G  B
	
	mov lo32,eax
	mov hi32,eax
	movq mm0,hi32
	
	mov ecx,PalSize
	shr ecx,1			; Num 8 byte chunks
	mov ebx,8
L9:
	movq mm1,[esi]
	psubb mm1,mm0
	movq [esi],mm1
	add esi,ebx
	dec ecx
	jnz L9
	emms
RET
;============================================================

%define zFac2      [ebp-52]	; = (zFac * 2 + 1)
%define a255	   [ebp-56]	
%define culB	   [ebp-60]	
%define culG	   [ebp-64]	
%define culR	   [ebp-68]	
%define aran       [ebp-72] ; aran 0-255
%define zFac	   [ebp-76]	; = 20 * Increment

AddNoise:	; 10

	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

	mov eax,Increment
	mov ebx,20
	mul ebx
	mov zFac,eax		; zFac=20*Increment
	shl eax,1			; zFac*2
	add eax,1			; zFac*2+1
	mov zFac2,eax
	
	mov eax,255
	mov a255,eax
	
	mov ecx,PalSize
iy10:
	;---------------------
	Call RANDNOISE		; Out: aL & Seed & aran = rand(0-255)
	fild dword aran		
	fild dword a255		; 255,aran
	fdivp st1			; aran/255   0-1
	fild dword zFac2
	fmulp st1			; (zFac*2+1)*Rnd
	fild dword zFac		; zFac,(zFac*2+1)*Rnd
	fsubp st1			; (zFac*2+1)*Rnd - zFac
	
	movzx eax,byte [esi]   ; B
	mov culB,eax
	
	fild dword culB
	faddp st1
	fistp dword culB
	;---------------------
	inc esi				; G	
	;---------------------
	Call RANDNOISE		; Out: aL & Seed = rand(0-255)
	fild dword aran		
	fild dword a255		; 255,aran
	fdivp st1			; aran/255   0-1
	fild dword zFac2
	fmulp st1			; (zFac*2+1)*Rnd
	fild dword zFac		; zFac,(zFac*2+1)*Rnd
	fsubp st1			; (zFac*2+1)*Rnd - zFac
	
	movzx eax,byte [esi]   ; G
	mov culG,eax
	
	fild dword culG
	faddp st1
	fistp dword culG
	;---------------------
	inc esi				; R
	;---------------------
	Call RANDNOISE		; Out: aL & Seed = rand(0-255)
	fild dword aran		
	fild dword a255		; 255,aran
	fdivp st1			; aran/255   0-1
	fild dword zFac2
	fmulp st1			; (zFac*2+1)*Rnd
	fild dword zFac		; zFac,(zFac*2+1)*Rnd
	fsubp st1			; (zFac*2+1)*Rnd - zFac
	
	movzx eax,byte [esi]   ; R
	mov culR,eax
	
	fild dword culR
	faddp st1
	fistp dword culR
	;---------------------

	;---------------------
	mov eax,culB
	cmp eax,255
	jl t10
	mov eax,255
	jmp s10
t10:
	cmp eax,0
	jg s10
	mov eax,0
s10:
	mov culB,eax
	;---------------------
	mov eax,culG
	cmp eax,255
	jl t100
	mov eax,255
	jmp s100
t100:
	cmp eax,0
	jg s100
	mov eax,0
s100:
	mov culG,eax
	;---------------------
	mov eax,culR
	cmp eax,255
	jl t1000
	mov eax,255
	jmp s1000
t1000:
	cmp eax,0
	jg s1000
	mov eax,0
s1000:
	mov culR,eax
	;---------------------
	; esi->R
	mov eax,culR
	mov byte[esi],aL
	dec esi			; ->G
	mov eax,culG
	mov byte[esi],aL
	dec esi			; ->B
	mov eax,culB
	mov byte[esi],aL
	
	mov edx,4
	add esi,edx		; -> next B
	
	dec ecx
	jnz near iy10

RET

;============================================================
RANDNOISE:		; Out: aL & Seed = rand(0-255)
	mov eax,011813h	 	; 71699 prime 
	imul DWORD Seed
	add eax, 0AB209h 	; 700937 prime
	rcr eax,1			; leaving out gives vertical lines plus
						; faint horizontal ones, tartan

	;----------------------------------------
	;jc ok				; these 2 have little effect
	;rol eax,1			;
ok:						;
	;----------------------------------------
	
	;----------------------------------------
	;dec eax			; these produce vert lines
	;inc eax			; & with fsin marble arches
	;----------------------------------------

	mov Seed,eax	; save seed
	and eax,255
	mov aran,eax	; aran = rnd(0-255)
RET

;============================================================
Invert:	; 11

	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

	xor eax,eax
	mov eax,0FFFFFFFFh
	
	mov lo32,eax
	mov hi32,eax
	
	mov ecx,PalSize
	shr ecx,1			; Num 8 byte chunks
	mov ebx,8
L11:
	movq mm0,hi32
	movq mm1,[esi]
	psubb mm0,mm1
	movq [esi],mm0
	add esi,ebx
	dec ecx
	jnz L11
	emms
RET
;============================================================
Grey:	; 12
	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

	mov ecx,PalSize
iy12:
	movzx ax,byte[esi]
	mov bx,ax
	movzx ax,byte[esi+1]
	mov dx,ax
	movzx ax,byte[esi+2]
	add ax,dx
	add ax,bx
	mov bx,3
	div bL				; to get result in aL !
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	
	dec ecx
	jnz iy12

RET
;============================================================
Blacken:	; 13	Blacken if R,G & B <24
	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

	mov ecx,PalSize
iy13:
	mov aL,byte[esi]
	cmp aL,24
	ja ny13				; ja not jg 
	mov aL,byte[esi+1]
	cmp aL,24
	ja ny13
	mov aL,byte[esi+2]
	cmp aL,24
	ja ny13
	mov aL,0
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny130
ny13:
	mov edx,4
	add esi,edx
ny130:
	dec ecx
	jnz iy13

RET

;============================================================
Whiten:	; 14 Whiten if R,G & B >248
	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

	mov ecx,PalSize
iy14:
	mov aL,byte[esi]
	cmp aL,248			; aL-248
	jbe ny14	 
	mov aL,byte[esi+1]
	cmp aL,248
	jbe ny14
	mov aL,byte[esi+2]
	cmp aL,248
	jbe ny14
	
	mov aL,255
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny140
ny14:
	mov edx,4
	add esi,edx
ny140:
	dec ecx
	jnz iy14

RET

;============================================================
Black2White:	; 15 B to W if R,G & B = 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

	mov ecx,PalSize
iy15:
	mov aL,byte[esi]
	cmp aL,0			; aL-0
	jne ny15	 
	mov aL,byte[esi+1]
	cmp aL,0
	jne ny15
	mov aL,byte[esi+2]
	cmp aL,0
	jne ny15
	
	mov aL,255
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny150
ny15:
	mov edx,4
	add esi,edx
ny150:
	dec ecx
	jnz iy15

RET

;============================================================
White2Black:	; 16 W to B if R,G & B = 255
	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

	mov ecx,PalSize
iy16:
	mov aL,byte[esi]
	cmp aL,255		
	jne ny16	 
	mov aL,byte[esi+1]
	cmp aL,255
	jne ny16
	mov aL,byte[esi+2]
	cmp aL,255
	jne ny16
	
	mov aL,0
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny160
ny16:
	mov edx,4
	add esi,edx
ny160:
	dec ecx
	jnz iy16

RET

;============================================================
NonWhite2Black:	; 17 NW to B if R,G & B <> 255
	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

	mov ecx,PalSize
iy17:
	mov aL,byte[esi]
	cmp aL,255		
	jne ny17	 
	mov aL,byte[esi+1]
	cmp aL,255
	jne ny17
	mov aL,byte[esi+2]
	cmp aL,255
	je ny170
ny17:
	mov aL,0
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny1700
ny170:
	mov edx,4
	add esi,edx
ny1700:
	dec ecx
	jnz iy17

RET
;============================================================
NonBlack2White:	; 18 NB to W if R,G & B <> 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

	mov ecx,PalSize
iy18:
	mov aL,byte[esi]
	cmp aL,0		
	jnz ny18	 
	mov aL,byte[esi+1]
	cmp aL,0
	jnz ny18
	mov aL,byte[esi+2]
	cmp aL,0
	jz ny180
ny18:	
	mov aL,255
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny1800
ny180:
	mov edx,4
	add esi,edx
ny1800:
	dec ecx
	jnz iy18

RET

;============================================================
BlackAndWhite:	; 19 Whiten if R,G & B >=180 else Black
	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

	mov ecx,PalSize
iy19:
	mov aL,byte[esi]	; B
	cmp aL,180			; aL-180
	jb ny19	 
	mov aL,byte[esi+1]	; G
	cmp aL,180
	jb ny191
	mov aL,byte[esi+2]	; R
	cmp aL,180
	jb ny192
GE180:
	mov aL,255
BW19:
	mov byte[esi],aL	; B
	inc esi
	mov byte[esi],aL	; G
	inc esi	
	mov byte[esi],aL	; R
	inc esi			; -> A
	inc esi			; -> next B
	jmp ny1900
ny19:
	mov aL,byte[esi+1]	; G
	cmp aL,180
	jae GE180 
ny191:
	mov aL,byte[esi+2]	; R
	cmp aL,180
	jae GE180 
ny192:
	mov aL,0
	jmp BW19			; All < 180

ny1900:
	dec ecx
	jnz iy19

RET

⌨️ 快捷键说明

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