Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7105 → Rev 7104

/programs/develop/libraries/libs-dev/libimg/convert.asm
33,13 → 33,7
;< eax = 0 / pointer to converted image ;;
;< ecx = error code / undefined ;;
;;================================================================================================;;
locals
img dd ?
prev dd ?
endl
push ebx esi edi
mov [img], 0
mov [prev], 0
push ebx esi edi 0 0
mov ebx, [_src]
@@:
mov eax, [ebx + Image.Previous]
51,26 → 45,28
stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
test eax, eax
jz .error
cmp [img], 0
cmp dword[esp + 4], 0
jnz @f
mov [img], eax
mov [esp + 4], eax
@@:
mov ecx, [prev]
mov ecx, [esp]
jecxz @f
mov [ecx + Image.Next], eax
mov [eax + Image.Previous], ecx
@@:
mov [prev], eax
push [ebx + Image.Flags]
pop [eax + Image.Flags]
push [ebx + Image.Delay]
pop [eax + Image.Delay]
mov [eax + Image.Previous], ecx
mov [esp], eax
mov ebx, [ebx + Image.Next]
test ebx, ebx
jnz .loop
mov eax, [img]
.quit:
pop eax eax edi esi ebx
ret
.error:
pop edi esi ebx
pop eax eax edi esi ebx
ret
endp
 
90,44 → 86,65
;< ecx = error code / undefined ;;
;;================================================================================================;;
locals
fun rd 1
width rd 1
height rd 1
endl
push ebx esi edi
 
mov ebx, [_src]
mov eax, [ebx + Image.Type]
mov esi, [img.convert.table + 4*eax]
.next:
lodsd
test eax, eax
mov eax, 1
mov ecx, [_dst_type]
shl eax, cl
mov ecx, [ebx + Image.Type]
test eax, [img.types_table + 4*ecx]
jnz @f
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .exit
jmp .error
@@:
cmp eax, [_dst_type]
lodsd
jnz .next
mov [fun], eax
 
mov eax, [_dst]
test eax, eax
jnz @f
stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], [_dst_type]
test eax, eax
jz .exit
jz .error
mov [_dst], eax
@@:
mov edi, [eax + Image.Data]
mov esi, [ebx + Image.Data]
mov eax, [ebx + Image.Type]
stdcall [fun], [_src], [_dst]
mov eax, [_dst]
.exit:
pop edi esi ebx
ret
endp
cmp eax, Image.bpp8i
je .bpp8i
cmp eax, Image.bpp8g
je .bpp8g
cmp eax, Image.bpp24
je .bpp24
cmp eax, Image.bpp32
je .bpp32
cmp eax, Image.bpp15
je .bpp15
cmp eax, Image.bpp16
je .bpp16
cmp eax, Image.bpp1
je .bpp1
cmp eax, Image.bpp8a
je .bpp8a
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .error
 
proc img._.convert.bpp8i_to_bpp24 _src, _dst
.find_in_table_and_jump:
mov ecx, [_dst_type]
@@:
mov eax, [edx]
add edx, 8
cmp eax, ecx
jne @b
jmp dword[edx - 4]
 
 
.bpp8i:
mov edx, img.convert.bpp8i.table
jmp .find_in_table_and_jump
.bpp8i_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
 
148,28 → 165,15
mov [edi], ax
shr eax, 16
mov [edi + 2], al
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp8i_to_bpp32 _src, _dst
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
 
mov ebx, [ebx + Image.Palette]
@@:
movzx eax, byte[esi]
add esi, 1
mov eax, [ebx + eax*4]
mov [edi], eax
add edi, 4
dec ecx
jnz @b
ret
endp
 
 
proc img._.convert.bpp8g_to_bpp1 _src, _dst
.bpp8g:
mov edx, img.convert.bpp8g.table
jmp .find_in_table_and_jump
.bpp8g_to_bpp1:
mov eax, [_dst]
mov eax, [eax + Image.Palette]
mov dword[eax], 0x00000000
201,12 → 205,19
@@:
dec edx
jnz .bpp8g_to_bpp1.line
ret
endp
mov eax, [_dst]
jmp .quit
 
proc img._.convert.bpp8g_to_bpp24 _src, _dst
.bpp8g_to_bpp8g:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
rep movsb
mov eax, [_dst]
jmp .quit
 
.bpp8g_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
mov al, byte[esi]
mov byte[edi + 0], al
216,11 → 227,13
add edi, 3
sub ecx, 1
jnz @b
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp24_to_bpp24 _src, _dst
.bpp24:
mov edx, img.convert.bpp24.table
jmp .find_in_table_and_jump
.bpp24_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
lea ecx, [ecx*3]
230,11 → 243,9
mov ecx, edx
and ecx, 3
rep movsb
ret
endp
 
 
proc img._.convert.bpp24_to_bpp8g _src, _dst
mov eax, [_dst]
jmp .quit
.bpp24_to_bpp8g:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
250,11 → 261,9
add edi, 1
sub ecx, 1
jnz @b
ret
endp
 
 
proc img._.convert.bpp24_to_bpp32 _src, _dst
mov eax, [_dst]
jmp .quit
.bpp24_to_bpp32:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
265,11 → 274,14
stosd
dec ecx
jnz @b
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp32_to_bpp24 _src, _dst
.bpp32:
mov edx, img.convert.bpp32.table
jmp .find_in_table_and_jump
.bpp32_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
281,22 → 293,17
add edi, 3
sub ecx, 1
jnz @b
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp32_to_bpp32 _src, _dst
.bpp15:
mov edx, img.convert.bpp15.table
jmp .find_in_table_and_jump
.bpp15_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
rep movsd
ret
endp
 
 
proc img._.convert.bpp15_to_bpp24 _src, _dst
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
 
.bpp15.intel: ; copypasted from do_rgb
push ebx ebp
sub ecx, 4
413,12 → 420,11
jnb .bpp15.amd.loop
jmp .bpp15.tail
 
.quit:
ret
endp
 
 
proc img._.convert.bpp16_to_bpp24 _src, _dst
.bpp16:
mov edx, img.convert.bpp16.table
jmp .find_in_table_and_jump
.bpp16_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
.bpp16.intel:
536,16 → 542,11
jnb .bpp16.amd.loop
jmp .bpp16.tail
 
.quit:
ret
endp
 
 
proc img._.convert.bpp1_to_bpp24 _src, _dst
locals
width rd 1
height rd 1
endl
.bpp1:
mov edx, img.convert.bpp1.table
jmp .find_in_table_and_jump
.bpp1_to_bpp24:
push [ebx + Image.Width]
pop [width]
push [ebx + Image.Height]
576,11 → 577,14
jnz .bpp1_to_bpp24.bit
jmp .bpp1_to_bpp24.byte
.bpp1.done:
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp8a_to_bpp1 _src, _dst
.bpp8a:
mov edx, img.convert.bpp8a.table
jmp .find_in_table_and_jump
.bpp8a_to_bpp1:
mov eax, [_dst]
mov eax, [eax + Image.Palette]
mov dword[eax], 0x00000000
612,11 → 616,10
@@:
dec edx
jnz .bpp8a_to_bpp1.line
ret
endp
mov eax, [_dst]
jmp .quit
 
 
proc img._.convert.bpp8a_to_bpp24 _src, _dst
.bpp8a_to_bpp24:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
628,53 → 631,35
add edi, 3
sub ecx, 1
jnz @b
mov eax, [_dst]
jmp .quit
 
 
.error:
xor eax, eax
.quit:
pop edi esi ebx
ret
endp
 
 
img.convert.bpp8i.table:
dd Image.bpp24, img._.convert.bpp8i_to_bpp24
dd Image.bpp32, img._.convert.bpp8i_to_bpp32
dd 0
dd Image.bpp24, img.convert.layer.bpp8i_to_bpp24
img.convert.bpp8g.table:
dd Image.bpp24, img.convert.layer.bpp8g_to_bpp24
dd Image.bpp8g, img.convert.layer.bpp8g_to_bpp8g
dd Image.bpp1, img.convert.layer.bpp8g_to_bpp1
img.convert.bpp24.table:
dd Image.bpp24, img._.convert.bpp24_to_bpp24
dd Image.bpp8g, img._.convert.bpp24_to_bpp8g
dd Image.bpp32, img._.convert.bpp24_to_bpp32
dd 0
dd Image.bpp24, img.convert.layer.bpp24_to_bpp24
dd Image.bpp8g, img.convert.layer.bpp24_to_bpp8g
dd Image.bpp32, img.convert.layer.bpp24_to_bpp32
img.convert.bpp32.table:
dd Image.bpp24, img._.convert.bpp32_to_bpp24
dd Image.bpp32, img._.convert.bpp32_to_bpp32
dd 0
dd Image.bpp24, img.convert.layer.bpp32_to_bpp24
img.convert.bpp15.table:
dd Image.bpp24, img._.convert.bpp15_to_bpp24
dd 0
dd Image.bpp24, img.convert.layer.bpp15_to_bpp24
img.convert.bpp16.table:
dd Image.bpp24, img._.convert.bpp16_to_bpp24
dd 0
dd Image.bpp24, img.convert.layer.bpp16_to_bpp24
img.convert.bpp1.table:
dd Image.bpp24, img._.convert.bpp1_to_bpp24
dd 0
img.convert.bpp8g.table:
dd Image.bpp24, img._.convert.bpp8g_to_bpp24
dd Image.bpp1, img._.convert.bpp8g_to_bpp1
dd 0
img.convert.bpp2i.table:
dd 0
img.convert.bpp4i.table:
dd 0
dd Image.bpp24, img.convert.layer.bpp1_to_bpp24
img.convert.bpp8a.table:
dd Image.bpp24, img._.convert.bpp8a_to_bpp24
dd 0
 
img.convert.table:
dd 0 ; no image type zero
dd img.convert.bpp8i.table
dd img.convert.bpp24.table
dd img.convert.bpp32.table
dd img.convert.bpp15.table
dd img.convert.bpp16.table
dd img.convert.bpp1.table
dd img.convert.bpp8g.table
dd img.convert.bpp2i.table
dd img.convert.bpp4i.table
dd img.convert.bpp8a.table
dd Image.bpp24, img.convert.layer.bpp8a_to_bpp24
/programs/develop/libraries/libs-dev/libimg/libimg.asm
26,10 → 26,7
include '../../../../proc32.inc'
include '../../../../macros.inc'
include '../../../../config.inc'
include '../../../../debug-fdo.inc'
__DEBUG__ = 0
__DEBUG_LEVEL__ = 1
include '../../../../develop/libraries/libs-dev/libio/libio.inc'
;include '../../../../debug.inc'
purge section,mov,add,sub
 
include 'libimg.inc'
127,49 → 124,13
;;================================================================================================;;
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? load file from disk and decode it ;;
;? --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
;> [_filename] = file name as passed to libio ;;
;> --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;================================================================================================;;
locals
fd dd ?
img_data_len dd ?
img_data dd ? ; raw bytes
img dd ? ; Image pointer
endl
DEBUGF 2, 'img.from_file: %s\n', [_filename]
push ebx
mov [img], 0
invoke file.open, [_filename], O_READ
mov [fd], eax
test eax, eax
jz .exit
invoke file.size, [_filename]
test eax, eax
jnz .exit_close
mov [img_data_len], ebx
invoke mem.alloc, ebx
test eax, eax
jz .exit_close
mov [img_data], eax
invoke file.read, [fd], eax, [img_data_len]
cmp eax, -1
jz .exit_free_close
cmp eax, [img_data_len]
jnz .exit_free_close
stdcall img.decode, [img_data], [img_data_len], 0
test eax, eax
jz .exit_free_close
mov [img], eax
.exit_free_close:
invoke mem.free, [img_data]
.exit_close:
invoke file.close, [fd]
mov eax, [img]
.exit:
pop ebx
xor eax, eax
ret
endp
 
2478,6 → 2439,18
.z80 dd LIBIMG_FORMAT_Z80, img.is.z80, img.decode.z80, img.encode.z80, 0 ;this must be the last entry as there are no signatures in z80 screens at all
dd 0
 
align 4
img.types_table: ; entries order must correspond to type defnitions in libimg.inc
dd 0 ; there is no Image.bpp* = 0
.bpp8i dd (1 SHL Image.bpp24)
.bpp24 dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp8g)
.bpp32 dd (1 SHL Image.bpp24)
.bpp15 dd (1 SHL Image.bpp24)
.bpp16 dd (1 SHL Image.bpp24)
.bpp1 dd (1 SHL Image.bpp24)
.bpp8g dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp1 ) OR (1 SHL Image.bpp8g)
.bpp8a dd (1 SHL Image.bpp24)
 
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
2744,8 → 2717,6
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
 
include_debug_strings
 
align 4
type2bpp dd 8, 24, 32, 15, 16, 1, 9, 2, 4
img._.do_rgb.handlers:
2815,10 → 2786,7
align 16
@IMPORT:
 
library \
archiver, 'archiver.obj', \
libio , 'libio.obj'
 
library archiver, 'archiver.obj'
import archiver, \
deflate_unpack2, 'deflate_unpack2',\
deflateInit2, 'deflateInit2',\
2827,12 → 2795,6
deflateEnd, 'deflateEnd',\
calc_crc32, 'calc_crc32'
 
import libio , \
file.size , 'file_size' , \
file.open , 'file_open' , \
file.read , 'file_read' , \
file.close, 'file_close'
 
align 4
; mutex for unpacker loading
deflate_loader_mutex dd 0