New 2 dithering algorithms added to buf2d

git-svn-id: svn://kolibrios.org@3138 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
heavyiron 2012-12-24 20:16:12 +00:00
parent be097e22f4
commit 805b19b4e9
3 changed files with 175 additions and 9 deletions

View File

@ -265,7 +265,7 @@ stdcall [buf2d_convert_text_matrix], buf_1</pre>
<p>Фильтр, который преобразует изображение из 24 битного буфера в 8-ми цветное. Разрядность буфера не меняется. Пример:</p>
<pre>stdcall [buf2d_filter_dither], buf_0, 0</pre>
<p>где buf_0 - структура 24-х битного буфера.</p>
<p>0 - àëãîðèòì (âîçìîæíûå çíà÷åíèÿ: 0 - Sierra Lite, 1 - Floyd-Steinberg, 2 - Burkers).</p>
<p>0 - алгоритм (возможные значения: 0 - Sierra Lite, 1 - Floyd-Steinberg, 2 - Burkers, 3 - Heavyiron_mod, 4 - Atkinson).</p>
<h4><a name="f_v_brush_c">buf2d_vox_brush_create</a></h4>
<p>Создание воксельной кисти. Пример:</p>
@ -444,5 +444,6 @@ import_buf2d_lib:
<p>01.10.12 - добавлена функция поворота изображений на 90 и 180 градусов buf2d_rotate.</p>
<p>15.11.12 - добавлена функция отражения 24 битных изображений по вертикали buf_flip_v, исправления в функции buf2d_img_hdiv2.</p>
<p>14.12.12 - добавлена функция наложения фильтра buf2d_filter_dither.</p>
<p>24.12.12 - добавлены 2 новых алгоритма в функцию наложения фильтра buf2d_filter_dither.</p>
</body>
</html>

View File

@ -3451,7 +3451,7 @@ proc buf_curve_bezier, buffer:dword, coord_p0:dword,coord_p1:dword,coord_p2:dwor
ret
endp
;䨫ìâ¥à
;䨫ìâà
align 4
proc buf_filter_dither, buffer:dword, algor:dword
pushad
@ -3464,7 +3464,7 @@ proc buf_filter_dither, buffer:dword, algor:dword
;edi - pointer to 24bit bitmap
;edx - x size
;esi - y size
lea edx,[edx*3]
lea edx,[edx+edx*2]
imul esi,edx
;®¯à¥¤¥«ï¥¬ ª ª®©  «£®à¨â¬ ¨á¯®«ì§®¢ âì
@ -3478,7 +3478,17 @@ proc buf_filter_dither, buffer:dword, algor:dword
call dither_1
jmp .dither_end
@@:
call dither_2
cmp dword[algor],2
jne @f
call dither_2
jmp .dither_end
@@:
cmp dword[algor],3
jne @f
call dither_3
jmp .dither_end
@@:
call dither_4
jmp .dither_end
.error:
stdcall print_err,sz_buf2d_filter_dither,txt_err_n24b
@ -3488,7 +3498,7 @@ proc buf_filter_dither, buffer:dword, algor:dword
endp
align 16
dither_0: ; Sierra Filter Lite algoritm
dither_0: ; Sierra Filter Lite algorithm
newp_0: ; Dithering cycle
xor ebx,ebx ; At first threshold
movzx ecx,byte[edi]
@ -3551,7 +3561,7 @@ newp_0: ; Dithering cycle
ret
align 16
dither_1: ; Floyd-Steinberg algoritm
dither_1: ; Floyd-Steinberg algorithm
newp_1: ; Dithering cycle
xor ebx,ebx ; At first threshold
movzx ecx,byte[edi]
@ -3629,7 +3639,7 @@ newp_1: ; Dithering cycle
ret
align 16
dither_2: ; Burkers algoritm
dither_2: ; Burkes algorithm
newp_2: ; Dithering cycle
xor ebx,ebx ; At first threshold
movsx ecx,byte[edi]
@ -3742,6 +3752,161 @@ newp_2: ; Dithering cycle
ret
align 16
dither_3: ; Heavyiron_mod algorithm
newp_3: ; Dithering cycle
xor ebx,ebx ; At first threshold
movzx ecx,byte[edi]
cmp cl,255
je .next
test cl,cl
jz .next
jns @f
dec ebx
sub ecx,255
@@:
mov [edi],bl ; putpixel
sar ecx,2 ; error/4
movzx eax,byte[edi+3] ; pixel (x+1;y)
add eax,ecx ; add error/4 to (x+1;y)
jge @f ; check_overflow
xor eax,eax
jmp .ok
@@:
cmp eax,255
jle .ok
or al,255
.ok:
mov [edi+3],al ; putpixel
movzx eax,byte[edi+edx-3] ; pixel (x-1;y+1)
add eax,ecx ; add error/4 to (x-1;y+1)
jge @f ; check_overflow
xor eax,eax
jmp .ok1
@@:
cmp eax,255
jle .ok1
or al,255
.ok1:
mov [edi+edx-3],al ; putpixel
movzx eax,byte[edi+edx] ; pixel (x;y+1)
add eax,ecx ; add error/4 to (x;y+1)
jge @f ; check_overflow
xor eax,eax
jmp .ok2
@@:
cmp eax,255
jle .ok2
or al,255
.ok2:
mov [edi+edx],al ; putpixel
.next:
inc edi
dec esi
jnz newp_3
ret
align 16
dither_4: ; Atkinson algorithm
newp_4: ; Dithering cycle
xor ebx,ebx ; At first threshold
movsx ecx,byte[edi]
cmp cl,255
je .next
test cl,cl
jz .next
jns @f
dec ebx
@@:
mov [edi],bl ; putpixel
sar ecx,3 ; error/8
movzx eax,byte[edi+3] ; pixel (x+1;y)
add eax,ecx ; add error/8 to (x+1;y)
jge @f ; check_overflow
xor eax,eax
jmp .ok
@@:
cmp eax,255
jle .ok
or al,255
.ok:
mov [edi+3],al ; putpixel
movzx eax,byte[edi+edx] ; pixel (x;y+1)
add eax,ecx ; add error/8 to (x;y+1)
jge @f ; check_overflow
xor eax,eax
jmp .ok1
@@:
cmp eax,255
jle .ok1
or al,255
.ok1:
mov [edi+edx],al ; putpixel
movzx eax,byte[edi+6] ; pixel (x+2;y)
add eax,ecx ; add error/8 to (x+2;y)
jge @f ; check_overflow
xor eax,eax
jmp .ok2
@@:
cmp eax,255
jle .ok2
or al,255
.ok2:
mov [edi+6],al ; putpixel
movzx eax,byte[edi+edx-3] ; pixel (x-1;y+1)
add eax,ecx ; add error/8 to (x-1;y+1)
jge @f ; check_overflow
xor eax,eax
jmp .ok3
@@:
cmp eax,255
jle .ok3
or al,255
.ok3:
mov [edi+edx-3],al ; putpixel
movzx eax,byte[edi+edx+3] ; pixel (x+1;y+1)
add eax,ecx ; add error/8 to (x+1;y+1)
jge @f ; check_overflow
xor eax,eax
jmp .ok4
@@:
cmp eax,255
jle .ok4
or al,255
.ok4:
mov [edi+edx+3],al ; putpixel
movzx eax,byte[edi+edx+edx] ; pixel (x;y+2)
add eax,ecx ; add error/8 to (x;y+2)
jge @f ; check_overflow
xor eax,eax
jmp .ok5
@@:
cmp eax,255
jle .ok5
or al,255
.ok5:
mov [edi+edx+edx],al ; putpixel
.next:
inc edi
dec esi
jnz newp_4
ret
;*** ä㭪樨 ¤«ï à ¡®âë á ¢®ªá¥«ì­®© £à ä¨ª®© ***

View File

@ -101,8 +101,8 @@ start:
stdcall [buf2d_create_f_img], buf_2,[image_data_rgb] ;ᮧ¤ ¥¬ ¡ãä¥à
stdcall mem.Free,[image_data_rgb] ;®á¢®¡®¦¤ ¥¬ ¯ ¬ïâì
stdcall [buf2d_filter_dither], buf_1,0
stdcall [buf2d_filter_dither], buf_2,2
stdcall [buf2d_filter_dither], buf_1,2
stdcall [buf2d_filter_dither], buf_2,3
align 4
red_win: