img.scale and img.convert fix for multiframe images

new function: img.get_scaled_size


git-svn-id: svn://kolibrios.org@6807 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
2016-12-22 23:29:25 +00:00
parent c299820b03
commit 741b6ad89c
4 changed files with 3721 additions and 3519 deletions

View File

@@ -17,15 +17,70 @@
;; ;;
;;================================================================================================;;
;;================================================================================================;;
proc img.convert _src, _dst, _dst_type, _flags, _param ;;
;;------------------------------------------------------------------------------------------------;;
;? scale _image ;;
;? convert _image ;;
;;------------------------------------------------------------------------------------------------;;
;> [_src] = pointer to source image ;;
;> [_dst] = pointer to destination image, or 0 to create a new one ;;
;> [_dst_type] = Image.Type of resulting image ;;
;> [_flags] = see libimg.inc ;;
;> [_dst_type] = the Image.Type of converted image ;;
;> [_dst] = pointer to destination image, if any ;;
;> [_param] = depends on _flags fields, see libimg.inc ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to converted image ;;
;< ecx = error code / undefined ;;
;;================================================================================================;;
push ebx esi edi 0 0
mov ebx, [_src]
@@:
mov eax, [ebx + Image.Previous]
test eax, eax
jz .loop
mov ebx, eax
jmp @b
.loop:
stdcall img.convert.layer, ebx, [_dst], [_dst_type], [_flags], [_param]
test eax, eax
jz .error
cmp dword[esp + 4], 0
jnz @f
mov [esp + 4], eax
@@:
mov ecx, [esp]
jecxz @f
mov [ecx + Image.Next], 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
.quit:
pop eax eax edi esi ebx
ret
.error:
pop eax eax edi esi ebx
ret
endp
;;================================================================================================;;
proc img.convert.layer _src, _dst, _dst_type, _flags, _param ;;
;;------------------------------------------------------------------------------------------------;;
;? convert _image layer ;;
;;------------------------------------------------------------------------------------------------;;
;> [_src] = pointer to source image ;;
;> [_dst] = pointer to destination image, or 0 to create a new one ;;
;> [_dst_type] = Image.Type of resulting image ;;
;> [_flags] = see libimg.inc ;;
;> [_param] = depends on _flags fields, see libimg.inc ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to converted image ;;
;< ecx = error code / undefined ;;
@@ -34,6 +89,8 @@ locals
width rd 1
height rd 1
endl
push ebx esi edi
mov ebx, [_src]
mov eax, 1
mov ecx, [_dst_type]
@@ -151,6 +208,13 @@ endl
mov eax, [_dst]
jmp .quit
.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]
@@ -199,6 +263,19 @@ endl
jnz @b
mov eax, [_dst]
jmp .quit
.bpp24_to_bpp32:
mov ecx, [ebx + Image.Width]
imul ecx, [ebx + Image.Height]
@@:
lodsw
ror eax, 16
lodsb
rol eax, 16
stosd
dec ecx
jnz @b
mov eax, [_dst]
jmp .quit
.bpp32:
@@ -561,25 +638,28 @@ end repeat
.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.bpp24, img.convert.layer.bpp8i_to_bpp24
img.convert.bpp8g.table:
dd Image.bpp24, img.convert.bpp8g_to_bpp24
dd Image.bpp1, img.convert.bpp8g_to_bpp1
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.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.bpp24, img.convert.layer.bpp32_to_bpp24
img.convert.bpp15.table:
dd Image.bpp24, img.convert.bpp15_to_bpp24
dd Image.bpp24, img.convert.layer.bpp15_to_bpp24
img.convert.bpp16.table:
dd Image.bpp24, img.convert.bpp16_to_bpp24
dd Image.bpp24, img.convert.layer.bpp16_to_bpp24
img.convert.bpp1.table:
dd Image.bpp24, img.convert.bpp1_to_bpp24
dd Image.bpp24, img.convert.layer.bpp1_to_bpp24
img.convert.bpp8a.table:
dd Image.bpp24, img.convert.bpp8a_to_bpp24
dd Image.bpp24, img.convert.layer.bpp8a_to_bpp24

View File

@@ -49,7 +49,6 @@ include 'xbm/xbm.asm'
include 'scale.asm'
include 'convert.asm'
;include 'transform.asm'
;;================================================================================================;;
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
@@ -186,7 +185,10 @@ endp
;;================================================================================================;;
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? decodes image data into RGB triplets and returns pointer to memory area containing them ;;
;? decodes image data into RGB triplets and returns pointer to memory area of following structure:;;
;? width dd ? ;;
;? height dd ? ;;
;? rgb triplets ;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to source image ;;
;;------------------------------------------------------------------------------------------------;;
@@ -696,13 +698,13 @@ proc img.encode _img, _common, _specific ;//////////////////////////////////////
;? encode image to some format ;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to input image ;;
;> [_common] = some most important options ;;
;> [_common] = some most important/common options ;;
; 0x00 : byte : format id (defined in libimg.inc) ;;
; 0x01 : byte : fast encoding (0) / best compression ratio (255) ;;
; 0 : store uncompressed data (if supported both by the format and libimg) ;;
; 1 - 255 : use compression, if supported ;;
; this option may be ignored if any format specific options are defined ;;
; i.e. the 0 here will be ignored if some compression algorithm is specified ;;
; i.e. 0 here will be ignored if particular compression algorithm is specified ;;
; 0x02 : byte : flags (bitfield) ;;
; 0x01 : return an error if format specific conditions cannot be met ;;
; 0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on ;;
@@ -719,65 +721,65 @@ proc img.encode _img, _common, _specific ;//////////////////////////////////////
; 3 : specific conditions cannot be satisfied ;;
; 4 : bit depth cannot be preserved ;;
;;================================================================================================;;
mov ebx, [_img]
mov ebx, [_img]
movzx eax, byte[_common]
dec eax
imul eax, sizeof.FormatsTableEntry
add eax, FormatsTableEntry.Capabilities
add eax, img.formats_table
mov eax, [eax]
test eax, 1 ; is encoding to this format supported at all?
jnz @f
mov ecx, LIBIMG_ERROR_FORMAT
jmp .error
movzx eax, byte[_common]
dec eax
imul eax, sizeof.FormatsTableEntry
add eax, FormatsTableEntry.Capabilities
add eax, img.formats_table
mov eax, [eax]
test eax, 1 ; is encoding to this format supported at all?
jnz @f
mov ecx, LIBIMG_ERROR_FORMAT
jmp .error
@@:
mov ecx, [ebx + Image.Type]
mov edx, 1
shl edx, cl
test eax, edx
jnz .bit_depth_ok
test byte[_common+2], LIBIMG_ENCODE_STRICT_BIT_DEPTH
jz @f
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .error
mov ecx, [ebx + Image.Type]
mov edx, 1
shl edx, cl
test eax, edx
jnz .bit_depth_ok
test byte[_common+2], LIBIMG_ENCODE_STRICT_BIT_DEPTH
jz @f
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .error
@@:
mov edx, 1 SHL Image.bpp24
test eax, edx
jnz @f
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .error
mov edx, 1 SHL Image.bpp24
test eax, edx
jnz @f
mov ecx, LIBIMG_ERROR_BIT_DEPTH
jmp .error
@@:
stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], Image.bpp24
test eax, eax
jnz @f
mov ecx, LIBIMG_ERROR_OUT_OF_MEMORY
jmp .error
stdcall img.create, [ebx + Image.Width], [ebx + Image.Height], Image.bpp24
test eax, eax
jnz @f
mov ecx, LIBIMG_ERROR_OUT_OF_MEMORY
jmp .error
@@:
push eax
stdcall img.to_rgb2, ebx, [eax + Image.Data]
pop ebx
push eax
stdcall img.to_rgb2, ebx, [eax + Image.Data]
pop ebx
.bit_depth_ok:
movzx eax, byte[_common]
dec eax
imul eax, sizeof.FormatsTableEntry
add eax, FormatsTableEntry.Encode
add eax, img.formats_table
mov eax, [eax]
stdcall eax, [_img], [_common], [_specific]
push eax ecx
cmp ebx, [_img]
je @f
stdcall img.destroy, ebx
movzx eax, byte[_common]
dec eax
imul eax, sizeof.FormatsTableEntry
add eax, FormatsTableEntry.Encode
add eax, img.formats_table
mov eax, [eax]
stdcall eax, [_img], [_common], [_specific]
push eax ecx
cmp ebx, [_img]
je @f
stdcall img.destroy, ebx
@@:
pop ecx eax
jmp .quit
pop ecx eax
jmp .quit
.error:
xor eax, eax
xor eax, eax
.quit:
ret
ret
endp
;;================================================================================================;;
@@ -2301,6 +2303,9 @@ endl
.flip:
stdcall img.flip.layer, [_img], FLIP_VERTICAL
test eax, eax
jz .error
jmp .exit
.exchange_dims:
@@ -2435,15 +2440,15 @@ img.formats_table:
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
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 )
.bpp8g dd (1 SHL Image.bpp24) OR (1 SHL Image.bpp1 ) OR (1 SHL Image.bpp8g)
.bpp8a dd (1 SHL Image.bpp24)
;;================================================================================================;;
@@ -2656,11 +2661,12 @@ endp
;;================================================================================================;;
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;? Get scanline length of image in bytes ;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;> eax = width of image in pixels ;;
;> ebx = image ;;
;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;;
;< eax = scanline length in bytes ;;
;;================================================================================================;;
cmp [ebx + Image.Type], Image.bpp1
jz .bpp1.1
@@ -2748,31 +2754,32 @@ align 4
@EXPORT:
export \
lib_init , 'lib_init' , \
0x00050007 , 'version' , \
img.is_img , 'img_is_img' , \
img.info , 'img_info' , \
img.from_file , 'img_from_file' , \
img.to_file , 'img_to_file' , \
img.from_rgb , 'img_from_rgb' , \
img.to_rgb , 'img_to_rgb' , \
img.to_rgb2 , 'img_to_rgb2' , \
img.decode , 'img_decode' , \
img.encode , 'img_encode' , \
img.create , 'img_create' , \
img.destroy , 'img_destroy' , \
img.destroy.layer, 'img_destroy_layer', \
img.count , 'img_count' , \
img.lock_bits , 'img_lock_bits' , \
img.unlock_bits , 'img_unlock_bits' , \
img.flip , 'img_flip' , \
img.flip.layer , 'img_flip_layer' , \
img.rotate , 'img_rotate' , \
img.rotate.layer , 'img_rotate_layer' , \
img.draw , 'img_draw' , \
img.scale , 'img_scale' , \
img.convert , 'img_convert' , \
img.formats_table, 'img_formats_table'
lib_init , 'lib_init' , \
0x00050007 , 'version' , \
img.is_img , 'img_is_img' , \
img.info , 'img_info' , \
img.from_file , 'img_from_file' , \
img.to_file , 'img_to_file' , \
img.from_rgb , 'img_from_rgb' , \
img.to_rgb , 'img_to_rgb' , \
img.to_rgb2 , 'img_to_rgb2' , \
img.decode , 'img_decode' , \
img.encode , 'img_encode' , \
img.create , 'img_create' , \
img.destroy , 'img_destroy' , \
img.destroy.layer , 'img_destroy_layer' , \
img.count , 'img_count' , \
img.lock_bits , 'img_lock_bits' , \
img.unlock_bits , 'img_unlock_bits' , \
img.flip , 'img_flip' , \
img.flip.layer , 'img_flip_layer' , \
img.rotate , 'img_rotate' , \
img.rotate.layer , 'img_rotate_layer' , \
img.draw , 'img_draw' , \
img.scale , 'img_scale' , \
img.get_scaled_size, 'img_get_scaled_size', \
img.convert , 'img_convert' , \
img.formats_table , 'img_formats_table'
; import from deflate unpacker
; is initialized only when PNG loading is requested

View File

@@ -18,68 +18,71 @@
;;================================================================================================;;
; list of format id's
LIBIMG_FORMAT_BMP = 1
LIBIMG_FORMAT_ICO = 2
LIBIMG_FORMAT_CUR = 3
LIBIMG_FORMAT_GIF = 4
LIBIMG_FORMAT_PNG = 5
LIBIMG_FORMAT_JPEG = 6
LIBIMG_FORMAT_TGA = 7
LIBIMG_FORMAT_PCX = 8
LIBIMG_FORMAT_XCF = 9
LIBIMG_FORMAT_TIFF = 10
LIBIMG_FORMAT_PNM = 11
LIBIMG_FORMAT_WBMP = 12
LIBIMG_FORMAT_BMP = 1
LIBIMG_FORMAT_ICO = 2
LIBIMG_FORMAT_CUR = 3
LIBIMG_FORMAT_GIF = 4
LIBIMG_FORMAT_PNG = 5
LIBIMG_FORMAT_JPEG = 6
LIBIMG_FORMAT_TGA = 7
LIBIMG_FORMAT_PCX = 8
LIBIMG_FORMAT_XCF = 9
LIBIMG_FORMAT_TIFF = 10
LIBIMG_FORMAT_PNM = 11
LIBIMG_FORMAT_WBMP = 12
LIBIMG_FORMAT_XBM = 13
LIBIMG_FORMAT_Z80 = 14
LIBIMG_FORMAT_Z80 = 14
; scale type ; corresponding img.scale params
LIBIMG_SCALE_INTEGER = 1 ; scale factor ; reserved 0
LIBIMG_SCALE_TILE = 2 ; new width ; new height
LIBIMG_SCALE_STRETCH = 3 ; new width ; new height
LIBIMG_SCALE_FIT_RECT = 4 ; new width ; new height
LIBIMG_SCALE_FIT_WIDTH = 5 ; new width ; new height
LIBIMG_SCALE_FIT_HEIGHT = 6 ; new width ; new height
LIBIMG_SCALE_FIT_MAX = 7 ; new width ; new height
LIBIMG_SCALE_NONE = 0 ; do not scale
LIBIMG_SCALE_INTEGER = 1 ; scale factor ; reserved 0
LIBIMG_SCALE_TILE = 2 ; new width ; new height
LIBIMG_SCALE_STRETCH = 3 ; new width ; new height
LIBIMG_SCALE_FIT_BOTH = LIBIMG_SCALE_STRETCH
LIBIMG_SCALE_FIT_MIN = 4 ; new width ; new height
LIBIMG_SCALE_FIT_RECT = LIBIMG_SCALE_FIT_MIN
LIBIMG_SCALE_FIT_WIDTH = 5 ; new width ; new height
LIBIMG_SCALE_FIT_HEIGHT = 6 ; new width ; new height
LIBIMG_SCALE_FIT_MAX = 7 ; new width ; new height
; interpolation algorithm
LIBIMG_INTER_NONE = 0 ; use it with LIBIMG_SCALE_INTEGER, LIBIMG_SCALE_TILE, etc
LIBIMG_INTER_BILINEAR = 1
;LIBIMG_INTER_BICUBIC = 2
;LIBIMG_INTER_LANCZOS = 3
LIBIMG_INTER_DEFAULT = LIBIMG_INTER_BILINEAR
LIBIMG_INTER_NONE = 0 ; use it with LIBIMG_SCALE_INTEGER, LIBIMG_SCALE_TILE, etc
LIBIMG_INTER_BILINEAR = 1
;LIBIMG_INTER_BICUBIC = 2
;LIBIMG_INTER_LANCZOS = 3
LIBIMG_INTER_DEFAULT = LIBIMG_INTER_BILINEAR
; error codes
LIBIMG_ERROR_OUT_OF_MEMORY = 1
LIBIMG_ERROR_FORMAT = 2
LIBIMG_ERROR_CONDITIONS = 3
LIBIMG_ERROR_BIT_DEPTH = 4
LIBIMG_ERROR_ENCODER = 5
LIBIMG_ERROR_SRC_TYPE = 6
LIBIMG_ERROR_SCALE = 7
LIBIMG_ERROR_INTER = 8
LIBIMG_ERROR_NOT_INPLEMENTED = 9
LIBIMG_ERROR_OUT_OF_MEMORY = 1
LIBIMG_ERROR_FORMAT = 2
LIBIMG_ERROR_CONDITIONS = 3
LIBIMG_ERROR_BIT_DEPTH = 4
LIBIMG_ERROR_ENCODER = 5
LIBIMG_ERROR_SRC_TYPE = 6
LIBIMG_ERROR_SCALE = 7
LIBIMG_ERROR_INTER = 8
LIBIMG_ERROR_NOT_INPLEMENTED = 9
LIBIMG_ERROR_INVALID_INPUT = 10
; 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_DELETE_ALPHA = 0x08
LIBIMG_ENCODE_FLUSH_ALPHA = 0x10
;LIBIMG_ENCODE_DELETE_ALPHA = 0x08
;LIBIMG_ENCODE_FLUSH_ALPHA = 0x10
; convert flags
; TBD
; none so far
struct FormatsTableEntry
Format_id dd ?
Is dd ?
Decode dd ?
Encode dd ?
Capabilities dd ?
Format_id dd ?
Is dd ?
Decode dd ?
Encode dd ?
Capabilities dd ?
ends
struct Image
Checksum dd ? ; ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far
Checksum dd ? ; ((Width ROL 16) OR Height) XOR Data[0] ; ignored so far
Width dd ?
Height dd ?
Next dd ?

File diff suppressed because it is too large Load Diff