add filter 'paeth', fix in 'build_bl_tree'

git-svn-id: svn://kolibrios.org@6888 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2017-04-18 09:45:38 +00:00
parent 61e1662b4e
commit c162817dfc
4 changed files with 290 additions and 104 deletions

View File

@ -2760,7 +2760,7 @@ if 1 ;;; IDAT compress all
cmp ecx,1 cmp ecx,1
jl .end8 jl .end8
stdcall create_compress_IDAT, edi, [edx+png_image_write_control.first_row], ecx, [ebx+png_image.width], [ebx+png_image.height] stdcall create_compress_IDAT, edi, [edx+png_image_write_control.first_row], ecx, [ebx+png_image.width], [ebx+png_image.height]
else ;;; not work, IDAT compress by lines else ;;; IDAT compress by lines
mov ecx,[ebx+png_image.height] mov ecx,[ebx+png_image.height]
cmp ecx,1 cmp ecx,1
jl .end8 jl .end8
@ -2914,6 +2914,14 @@ align 4
stdcall copy_row_mins, [edx+png_struct.tst_row], [edx+png_struct.try_row] stdcall copy_row_mins, [edx+png_struct.tst_row], [edx+png_struct.try_row]
@@: @@:
; Paeth filter
stdcall png_setup_paeth_row, edx, ebx, esi, [mins]
cmp eax,[mins]
jge @f ;if (..<..)
mov [mins],eax
stdcall copy_row_mins, [edx+png_struct.tst_row], [edx+png_struct.try_row]
@@:
; Copy best row ; Copy best row
mov eax,[edx+png_struct.tst_row] mov eax,[edx+png_struct.tst_row]
cmp byte[eax],0 cmp byte[eax],0

View File

@ -2942,106 +2942,283 @@ endp
;png_size_t (png_structrp png_ptr, const uint_32 bpp, ;png_size_t (png_structrp png_ptr, const uint_32 bpp,
; const png_size_t row_bytes, const png_size_t lmins) ; const png_size_t row_bytes, const png_size_t lmins)
align 4 align 4
proc png_setup_paeth_row, png_ptr:dword, bpp:dword, row_bytes:dword, lmins:dword proc png_setup_paeth_row uses ebx ecx edx edi esi, png_ptr:dword, bpp:dword, row_bytes:dword, lmins:dword
; bytep rp, dp, pp, cp, lp; locals
; png_size_t i; pp dd ?
; png_size_t sum = 0; sum dd ?
; int v; v dd ?
lp dd ?
cp dd ?
a dd ?
b dd ?
c dd ?
p dd ?
pa dd ?
pb dd ?
pc dd ?
endl
;ecx - i
;edi - dp
;esi - rp
mov dword[sum],0
mov ebx,[png_ptr]
mov eax,[ebx+png_struct.try_row]
mov byte[eax],PNG_FILTER_VALUE_PAETH
xor ecx,ecx
mov esi,[ebx+png_struct.row_buf]
inc esi
mov edi,[ebx+png_struct.try_row]
inc edi
mov eax,[ebx+png_struct.prev_row]
inc eax
mov [pp],eax
jmp @f
; png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; align 4
.cycle0:
inc ecx
@@:
cmp ecx,[bpp]
jae .cycle0end
lodsb
mov edx,[pp]
movzx edx,byte[edx]
sub al,dl
stosb
and eax,0xff
mov [v],eax
inc dword[pp]
cmp eax,0x80
jge @f
add [sum],eax
jmp .cycle0
@@:
mov eax,0x100
sub eax,[v]
add [sum],eax
jmp .cycle0
.cycle0end:
; for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, mov eax,[ebx+png_struct.row_buf]
; pp = png_ptr->prev_row + 1; i < bpp; i++) inc eax
; { mov [lp],eax
; v = *dp++ = (byte)(((int)*rp++ - (int)*pp++) & 0xff); mov eax,[ebx+png_struct.prev_row]
inc eax
mov [cp],eax
jmp @f
if PNG_USE_ABS eq 1 align 4
; sum += 128 - abs(v - 128); .cycle1:
else inc ecx
; sum += (v < 128) ? v : 256 - v; @@:
end if cmp ecx,[row_bytes]
; } jae .cycle1end
mov eax,[pp]
; for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; movzx ebx,byte[eax]
; i++) mov [b],ebx
; { inc dword[pp]
; int a, b, c, pa, pb, pc, p; mov eax,[cp]
movzx ebx,byte[eax]
; b = *pp++; mov [c],ebx
; c = *cp++; inc dword[cp]
; a = *lp++; mov eax,[lp]
movzx ebx,byte[eax]
; p = b - c; mov [a],ebx
; pc = a - c; inc dword[lp]
mov eax,[b]
if PNG_USE_ABS eq 1 sub eax,[c]
; pa = abs(p); mov [p],eax
; pb = abs(pc); mov ebx,[a]
; pc = abs(p + pc); sub ebx,[c]
else mov [pc],ebx
; pa = p < 0 ? -p : p; mov eax,[p]
; pb = pc < 0 ? -pc : pc; cmp eax,0
; pc = (p + pc) < 0 ? -(p + pc) : p + pc; jge @f
end if neg eax
@@:
; p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; mov [pa],eax
mov eax,[pc]
; v = *dp++ = (byte)(((int)*rp++ - p) & 0xff); cmp eax,0
jge @f
if PNG_USE_ABS eq 1 neg eax
; sum += 128 - abs(v - 128); @@:
else mov [pb],eax
; sum += (v < 128) ? v : 256 - v; mov eax,[p]
end if add eax,[pc]
jns @f
; if (sum > lmins) /* We are already worse, don't continue. */ neg eax
; break; @@:
; } mov [pc],eax
mov eax,[pa]
; return (sum); cmp eax,[pb]
jg .end0
cmp eax,[pc]
jg .end0
mov eax,[a]
jmp .end1
.end0:
mov eax,[pb]
cmp eax,[pc]
jg .end2
mov eax,[b]
jmp .end1
.end2:
mov eax,[c]
.end1:
mov [p],eax
movzx eax,byte[esi]
sub eax,[p]
and eax,0xff
stosb
mov [v],eax
inc esi
cmp dword[v],0x80
jge .end3
mov eax,[v]
add [sum],eax
jmp .end4
.end3:
mov eax,0x100
sub eax,[v]
add [sum],eax
.end4:
mov eax,[sum]
cmp eax,[lmins] ;We are already worse, don't continue.
jbe .cycle1
.cycle1end:
mov eax,[sum]
ret ret
endp endp
;void (png_structrp png_ptr, const uint_32 bpp, const png_size_t row_bytes) ;void (png_structrp png_ptr, const uint_32 bpp, const png_size_t row_bytes)
align 4 align 4
proc png_setup_paeth_row_only, png_ptr:dword, bpp:dword, row_bytes:dword proc png_setup_paeth_row_only, png_ptr:dword, bpp:dword, row_bytes:dword
; bytep rp, dp, pp, cp, lp; locals
; png_size_t i; pp dd ?
lp dd ?
cp dd ?
a dd ?
b dd ?
c dd ?
p dd ?
pa dd ?
pb dd ?
pc dd ?
endl
pushad
;ecx - i
;edi - dp
;esi - rp
mov eax,[png_ptr]
mov ebx,[eax+png_struct.try_row]
mov byte[ebx],4
xor ecx,ecx
mov edx,[png_ptr]
mov eax,[edx+png_struct.row_buf]
inc eax
mov esi,eax
mov ebx,[png_ptr]
mov edx,[ebx+png_struct.try_row]
inc edx
mov edi,edx
mov eax,[png_ptr]
mov ebx,[eax+png_struct.prev_row]
inc ebx
mov [pp],ebx
jmp @f
; png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; align 4
.cycle0:
inc ecx
@@:
cmp ecx,[bpp]
jae .cycle0end
lodsb
mov ebx,[pp]
movzx ebx,byte[ebx]
sub al,bl
stosb
inc dword[pp]
jmp .cycle0
.cycle0end:
; for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, mov eax,[png_ptr]
; pp = png_ptr->prev_row + 1; i < bpp; i++) mov ebx,[eax+png_struct.row_buf]
; { inc ebx
; *dp++ = (byte)(((int)*rp++ - (int)*pp++) & 0xff); mov [lp],ebx
; } mov edx,[png_ptr]
mov eax,[edx+png_struct.prev_row]
inc eax
mov [cp],eax
jmp @f
; for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; align 4
; i++) .cycle1:
; { inc ecx
; int a, b, c, pa, pb, pc, p; @@:
cmp ecx,[row_bytes]
; b = *pp++; jae .cycle1end
; c = *cp++; mov eax,[pp]
; a = *lp++; movzx ebx,byte[eax]
mov [b],ebx
; p = b - c; inc dword[pp]
; pc = a - c; mov eax,[cp]
movzx ebx,byte[eax]
if PNG_USE_ABS eq 1 mov [c],ebx
; pa = abs(p); inc dword[cp]
; pb = abs(pc); mov eax,[lp]
; pc = abs(p + pc); movzx ebx,byte[eax]
else mov [a],ebx
; pa = p < 0 ? -p : p; inc dword[lp]
; pb = pc < 0 ? -pc : pc; mov eax,[b]
; pc = (p + pc) < 0 ? -(p + pc) : p + pc; sub eax,[c]
end if mov [p],eax
mov ebx,[a]
; p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; sub ebx,[c]
mov [pc],ebx
; *dp++ = (byte)(((int)*rp++ - p) & 0xff); mov eax,[p]
; } cmp eax,0
jge @f
neg eax
@@:
mov [pa],eax
mov eax,[pc]
cmp eax,0
jge @f
neg eax
@@:
mov [pb],eax
mov eax,[p]
add eax,[pc]
jns @f
neg eax
@@:
mov [pc],eax
mov eax,[pa]
cmp eax,[pb]
jg .end0
cmp eax,[pc]
jg .end0
mov eax,[a]
jmp .end1
.end0:
mov eax,[pb]
cmp eax,[pc]
jg .end2
mov eax,[b]
jmp .end1
.end2:
mov eax,[c]
.end1:
mov [p],eax
movzx eax,byte[esi]
sub eax,[p]
and eax,0xff
stosb
inc esi
jmp .cycle1
.cycle1end:
popad
ret ret
endp endp
@ -3221,7 +3398,7 @@ else
mov eax,[best_row] mov eax,[best_row]
mov [edi+png_struct.tst_row],eax mov [edi+png_struct.tst_row],eax
.end3: .end3:
if 0 ;;; tmp
; Paeth filter ; Paeth filter
mov eax,[filter_to_do] mov eax,[filter_to_do]
cmp eax,PNG_FILTER_PAETH cmp eax,PNG_FILTER_PAETH
@ -3247,7 +3424,7 @@ if 0 ;;; tmp
mov eax,[best_row] mov eax,[best_row]
mov [edi+png_struct.tst_row],eax mov [edi+png_struct.tst_row],eax
.end4: .end4:
end if
; Do the actual writing of the filtered row data from the chosen filter. ; Do the actual writing of the filtered row data from the chosen filter.
mov eax,[esi+png_row_info.rowbytes] mov eax,[esi+png_row_info.rowbytes]
inc eax inc eax

View File

@ -18,7 +18,8 @@ init_crc_table:
crc_continue: crc_continue:
; in: eax = pervios crc, ecx = size, esi->buffer ; in: eax = pervios crc, ecx = size, esi->buffer
; out: eax = crc ; out: eax = crc
xor eax,-1 xor eax, -1
jecxz crc.end
jmp crc.loop jmp crc.loop
crc: crc:

View File

@ -1288,8 +1288,8 @@ endp
; bl_order of the last bit length code to send. ; bl_order of the last bit length code to send.
;int (deflate_state* s) ;int (deflate_state* s)
align 4 align 16
proc build_bl_tree uses edi, s:dword proc build_bl_tree uses ecx edi, s:dword
locals locals
max_blindex dd ? ;int ;index of last bit length code of non zero freq max_blindex dd ? ;int ;index of last bit length code of non zero freq
endl endl
@ -1312,18 +1312,18 @@ endl
; 3 but the actual value used is 4.) ; 3 but the actual value used is 4.)
mov dword[max_blindex],BL_CODES-1 mov dword[max_blindex],BL_CODES-1
jmp @f
align 4
.cycle0: ;for (..;..>=..;..) .cycle0: ;for (..;..>=..;..)
dec dword[max_blindex]
@@:
cmp dword[max_blindex],3 cmp dword[max_blindex],3
jl .cycle0end jl .cycle0end
dec dword[max_blindex] mov ecx,[max_blindex]
mov eax,[max_blindex] movzx eax,byte[ecx+bl_order]
add eax,bl_order movzx ecx,word[edi+sizeof.ct_data*eax+deflate_state.bl_tree+Len]
movzx eax,byte[eax] jecxz .cycle0
imul eax,sizeof.ct_data jmp .cycle0end
add eax,edi
cmp word[eax+deflate_state.bl_tree+Len],0
jne .cycle0end ;if (..!=0) break
jmp .cycle0
align 4 align 4
.cycle0end: .cycle0end:
; Update opt_len to include the bit length tree and counts ; Update opt_len to include the bit length tree and counts