libimg: add img.from_file, refactor img.convert.

Add new function, img.from_file: gets file name and returns decoded Image.
Make img.convert code less spaghetti: use jump table, not a chain of jmp's.


git-svn-id: svn://kolibrios.org@7105 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2017-10-31 21:33:52 +00:00
parent 437e995f11
commit 6cf659fe71
3 changed files with 593 additions and 540 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,10 @@ include '../../../../struct.inc'
include '../../../../proc32.inc' include '../../../../proc32.inc'
include '../../../../macros.inc' include '../../../../macros.inc'
include '../../../../config.inc' include '../../../../config.inc'
;include '../../../../debug.inc' include '../../../../debug-fdo.inc'
__DEBUG__ = 0
__DEBUG_LEVEL__ = 1
include '../../../../develop/libraries/libs-dev/libio/libio.inc'
purge section,mov,add,sub purge section,mov,add,sub
include 'libimg.inc' include 'libimg.inc'
@ -124,14 +127,50 @@ endp
;;================================================================================================;; ;;================================================================================================;;
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;; proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;; ;? load file from disk and decode it ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;; ;> [_filename] = file name as passed to libio ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;; ;< eax = 0 / pointer to image ;;
;;================================================================================================;; ;;================================================================================================;;
xor eax, eax locals
ret 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
ret
endp endp
;;================================================================================================;; ;;================================================================================================;;
@ -2439,18 +2478,6 @@ img.formats_table:
.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 .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 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)
;;================================================================================================;; ;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;; ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;; ;;================================================================================================;;
@ -2717,6 +2744,8 @@ img._.get_scanline_len: ;///////////////////////////////////////////////////////
;;////////////////////////////////////////////////////////////////////////////////////////////////;; ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;; ;;================================================================================================;;
include_debug_strings
align 4 align 4
type2bpp dd 8, 24, 32, 15, 16, 1, 9, 2, 4 type2bpp dd 8, 24, 32, 15, 16, 1, 9, 2, 4
img._.do_rgb.handlers: img._.do_rgb.handlers:
@ -2786,14 +2815,23 @@ export \
align 16 align 16
@IMPORT: @IMPORT:
library archiver, 'archiver.obj' library \
archiver, 'archiver.obj', \
libio , 'libio.obj'
import archiver, \ import archiver, \
deflate_unpack2, 'deflate_unpack2',\ deflate_unpack2, 'deflate_unpack2',\
deflateInit2, 'deflateInit2',\ deflateInit2, 'deflateInit2',\
deflateReset, 'deflateReset',\ deflateReset, 'deflateReset',\
deflate, 'deflate',\ deflate, 'deflate',\
deflateEnd, 'deflateEnd',\ deflateEnd, 'deflateEnd',\
calc_crc32, 'calc_crc32' calc_crc32, 'calc_crc32'
import libio , \
file.size , 'file_size' , \
file.open , 'file_open' , \
file.read , 'file_read' , \
file.close, 'file_close'
align 4 align 4
; mutex for unpacker loading ; mutex for unpacker loading

View File

@ -30,7 +30,7 @@ LIBIMG_FORMAT_XCF = 9
LIBIMG_FORMAT_TIFF = 10 LIBIMG_FORMAT_TIFF = 10
LIBIMG_FORMAT_PNM = 11 LIBIMG_FORMAT_PNM = 11
LIBIMG_FORMAT_WBMP = 12 LIBIMG_FORMAT_WBMP = 12
LIBIMG_FORMAT_XBM = 13 LIBIMG_FORMAT_XBM = 13
LIBIMG_FORMAT_Z80 = 14 LIBIMG_FORMAT_Z80 = 14
; scale type ; corresponding img.scale params ; scale type ; corresponding img.scale params
@ -65,10 +65,10 @@ LIBIMG_ERROR_NOT_INPLEMENTED = 9
LIBIMG_ERROR_INVALID_INPUT = 10 LIBIMG_ERROR_INVALID_INPUT = 10
; encode flags (byte 0x02 of _common option) ; encode flags (byte 0x02 of _common option)
;LIBIMG_ENCODE_STRICT_SPECIFIC = 0x01 ;LIBIMG_ENCODE_STRICT_SPECIFIC = 0x01
LIBIMG_ENCODE_STRICT_BIT_DEPTH = 0x02 LIBIMG_ENCODE_STRICT_BIT_DEPTH = 0x02
;LIBIMG_ENCODE_DELETE_ALPHA = 0x08 ;LIBIMG_ENCODE_DELETE_ALPHA = 0x08
;LIBIMG_ENCODE_FLUSH_ALPHA = 0x10 ;LIBIMG_ENCODE_FLUSH_ALPHA = 0x10
; convert flags ; convert flags
; none so far ; none so far