libimg: tiff fix (packbits); pcx old code optimizing and fix (even byte)

git-svn-id: svn://kolibrios.org@2397 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2012-02-24 17:47:42 +00:00
parent 271607503a
commit 852732a9b1
2 changed files with 82 additions and 134 deletions

View File

@ -36,13 +36,13 @@ proc img.is.pcx _data, _length ;////////////////////////////////////////////////
mov edi, [_data] mov edi, [_data]
cmp [edi + pcx_header.magic_number], 10 cmp byte[edi + pcx_header.magic_number], 0x0A
jne .is_not_pcx jne .is_not_pcx
cmp [edi + pcx_header.version], 5 cmp byte[edi + pcx_header.version], 5
jne .is_not_pcx jne .is_not_pcx
cmp [edi + pcx_header.encoding], 1 cmp byte[edi + pcx_header.encoding], 1
jne .is_not_pcx jne .is_not_pcx
cmp [edi + pcx_header.reserved], 0 cmp byte[edi + pcx_header.reserved], 0
jne .is_not_pcx jne .is_not_pcx
add edi, pcx_header.filler add edi, pcx_header.filler
@ -74,9 +74,9 @@ proc img.decode.pcx _data, _length, _options ;//////////////////////////////////
;;================================================================================================;; ;;================================================================================================;;
locals locals
nplanes rd 1 nplanes rd 1
xsize rw 1 xsize rd 1
ysize rw 1 ysize rd 1
bpl rw 1 bpl rd 1
total_bpl rd 1 total_bpl rd 1
line_begin rd 1 line_begin rd 1
retvalue rd 1 ; 0 (error) or pointer to image retvalue rd 1 ; 0 (error) or pointer to image
@ -87,24 +87,20 @@ endl
mov esi, [_data] mov esi, [_data]
movzx eax, byte[esi + pcx_header.nplanes] movzx eax, byte[esi + pcx_header.nplanes]
mov [nplanes], eax mov [nplanes], eax
mov bx, word[esi + pcx_header.bpl] movzx ebx, word[esi + pcx_header.bpl]
mov [bpl], bx mov [bpl], ebx
mul bx imul eax, ebx
shl eax, 16
mov ax, dx
ror eax, 16
mov [total_bpl], eax mov [total_bpl], eax
movzx eax, word[esi + pcx_header.xmax] movzx eax, word[esi + pcx_header.xmax]
inc ax
sub ax, word[esi + pcx_header.xmin] sub ax, word[esi + pcx_header.xmin]
mov [xsize], ax inc eax
mov [xsize], eax
movzx ebx, word[esi + pcx_header.ymax] movzx ebx, word[esi + pcx_header.ymax]
inc bx
sub bx, word[esi + pcx_header.ymin] sub bx, word[esi + pcx_header.ymin]
mov [ysize], bx inc ebx
mov [ysize], ebx
cmp [esi + pcx_header.bpp], 1 cmp [esi + pcx_header.bpp], 1
jz .monochrome jz .monochrome
@ -112,60 +108,52 @@ endl
jnz .indexed jnz .indexed
._24bit: .24bit:
stdcall img.create, eax, ebx, Image.bpp24 stdcall img.create, eax, ebx, Image.bpp24
mov [retvalue], eax mov [retvalue], eax
test eax, eax test eax, eax
jz .quit jz .quit
movzx ebx, [xsize]
movzx ecx, [ysize]
mov edx, [eax+Image.Data]
rol ebx, 16
or ebx, ecx
xor ebx, [edx]
mov [eax + Image.Checksum], ebx
mov esi, [_data] mov esi, [_data]
add esi, 128 add esi, 128 ; skip header
; mov edi, [retvalue]
mov edi, [eax + Image.Data] mov edi, [eax + Image.Data]
add edi, 2 add edi, 2
mov [line_begin], edi mov [line_begin], edi
.24bit.scanline:
mov ebx, [total_bpl] mov ebx, [total_bpl]
.24bit.color_line:
._24bit.begin: mov edx, [bpl]
mov ax, word[bpl] .24bit.next_byte:
._24bit.decode:
call pcx._.get_byte call pcx._.get_byte
._24bit.write_sequence: sub edx, ecx
mov [edi], dl @@:
dec ax mov [edi], al
add edi, [nplanes] add edi, [nplanes]
dec dh dec ecx
jnz ._24bit.write_sequence jnz @b
test ax, ax test edx, edx
jz ._24bit.end_color_line jnz .24bit.next_byte
jmp ._24bit.decode
._24bit.end_color_line: .24bit.end_color_line:
test ebx, ebx test ebx, ebx
jz ._24bit.end_full_line jz .24bit.end_full_line
dec [line_begin] dec [line_begin]
mov edi, [line_begin] mov edi, [line_begin]
jmp ._24bit.begin jmp .24bit.color_line
._24bit.end_full_line: .24bit.end_full_line:
dec word[ysize] dec [ysize]
jz .quit jz .quit
mov ebx, [total_bpl]
add edi, 2 add edi, 2
bt [xsize], 0
jnc @f
sub edi, 3
@@:
mov [line_begin], edi mov [line_begin], edi
jmp ._24bit.begin jmp .24bit.scanline
.indexed: .indexed:
@ -175,54 +163,40 @@ endl
test eax, eax test eax, eax
jz .quit jz .quit
movzx ebx, [xsize] mov ebx, eax
movzx ecx, [ysize]
mov edx, [eax + Image.Data]
rol ebx, 16
or ebx, ecx
xor ebx, [edx]
mov [eax + Image.Checksum], ebx
mov esi, [_data] mov esi, [_data]
add esi, [_length] add esi, [_length]
sub esi, 768 sub esi, 768
mov edi, [eax + Image.Palette] mov edi, [eax + Image.Palette]
mov cx, 256 mov ecx, 256
xor eax, eax
@@: @@:
mov ebx, [esi] lodsw
bswap ebx xchg al, ah
shr ebx, 8 shl eax, 8
mov [edi], ebx lodsb
add edi, 4 stosd
add esi, 3 dec ecx
dec cx
jnz @b jnz @b
mov esi, [_data] mov esi, [_data]
add esi, 128 add esi, 128
; mov edi, [retvalue] mov edi, [ebx + Image.Data]
mov edi, [eax + Image.Data]
.indexed.begin: .indexed.line:
mov ax, word[bpl] mov ebx, [total_bpl]
.indexed.decode: .indexed.next_byte:
call pcx._.get_byte call pcx._.get_byte
.indexed.write_sequence: @@:
mov [edi], dl stosb
inc edi dec ecx
dec ax jnz @b
dec dh test ebx, ebx
jnz .indexed.write_sequence jnz .indexed.next_byte
test ax, ax dec [ysize]
jz .indexed.end_line jnz .indexed.line
jmp .indexed.decode jmp .quit
.indexed.end_line:
dec word[ysize]
jz .quit
jmp .indexed.begin
.monochrome: .monochrome:
@ -232,50 +206,28 @@ endl
test eax, eax test eax, eax
jz .quit jz .quit
movzx ebx, [xsize]
movzx ecx, [ysize]
mov edx, [eax + Image.Data]
rol ebx, 16
or ebx, ecx
xor ebx, [edx]
mov [eax + Image.Checksum], ebx
mov edi, [eax + Image.Palette] mov edi, [eax + Image.Palette]
mov [edi], dword 0x00000000 mov [edi], dword 0xff000000
mov [edi + 4], dword 0x00ffffff mov [edi + 4], dword 0xffffffff
mov esi, [_data] mov esi, [_data]
add esi, 128 add esi, 128
; mov edi, [retvalue]
mov edi, [eax + Image.Data] mov edi, [eax + Image.Data]
.monochrome.begin: .monochrome.line:
mov ebx, [total_bpl] mov ebx, [total_bpl]
mov ax, [xsize] .monochrome.next_byte:
.monochrome.decode:
call pcx._.get_byte call pcx._.get_byte
.monochrome.write_sequence:
mov [edi], dl
inc edi
cmp ax, 8
jng .monochrome.is_last_byte_in_line
sub ax, 8
dec dh
jnz .monochrome.write_sequence
jmp .monochrome.decode
.monochrome.is_last_byte_in_line:
test ebx, ebx
jng @f
call pcx._.get_byte
jmp .monochrome.is_last_byte_in_line
@@: @@:
dec word[ysize] stosb
jnz .monochrome.begin dec ecx
jmp .quit jnz @b
test ebx, ebx
jnz .monochrome.next_byte
dec [ysize]
jnz .monochrome.line
; jmp .quit
.quit: .quit:
@ -309,19 +261,15 @@ endp
;;================================================================================================;; ;;================================================================================================;;
proc pcx._.get_byte proc pcx._.get_byte
mov dh, byte[esi] xor ecx, ecx
inc esi lodsb
cmp dh, 0xC0 cmp al, 0xC0
jnb .cycle1 setb cl
mov dl, dh jb .done
mov dh, 1 and al, 0x3F
jmp .exit1 mov cl, al
.cycle1: lodsb
and dh, 0x3F .done:
mov dl, byte[esi]
inc esi
.exit1:
movzx ecx, dh
sub ebx, ecx sub ebx, ecx
ret ret
endp endp

View File

@ -625,7 +625,7 @@ proc tiff._.decompress.packbits _image
.decode: .decode:
lodsb lodsb
dec edx dec edx
cmp al, 0xff cmp al, 0x7f
jbe .different jbe .different
cmp al, 0x80 cmp al, 0x80
jne .identical jne .identical