* libs-dev: style of exported names changed, ini.get_int -> ini_get_int

* programs which use libs-dev updated accordingly
* libimg: support for .ico and .cur files (icons and cursors)
* kiv: show many different images in one file in one row

git-svn-id: svn://kolibrios.org@1102 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond)
2009-06-03 21:12:49 +00:00
parent 51a64dc292
commit f705611d81
19 changed files with 740 additions and 261 deletions

View File

@@ -57,7 +57,7 @@ img.is.bmp:
;endp
;;================================================================================================;;
proc img.decode.bmp _data, _length ;//////////////////////////////////////////////////////////////;;
proc img.decode.bmp _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in BMP format ;;
;;------------------------------------------------------------------------------------------------;;
@@ -67,71 +67,77 @@ proc img.decode.bmp _data, _length ;////////////////////////////////////////////
;< eax = 0 (error) or pointer to image ;;
;;================================================================================================;;
locals
length_rest dd ?
img dd ?
bTopDown db ?
bIsIco db ?
endl
img.decode.bmp.length_rest equ length_rest
mov [bIsIco], 0
.common: ; common place for BMP and ICO
push ebx esi edi
; img.is.bmp has been already called by img.decode
; stdcall img.is.bmp, [_data], [_length]
; or eax, eax
; jz .error
mov ebx, [_data]
; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB
; je @f
; mov eax, [ebx + bmp.Header.file.Size]
; cmp eax, [_length]
; jne .error
; @@:
cmp [bIsIco], 0
jnz @f
add ebx, sizeof.bmp.FileHeader
sub [_length], sizeof.bmp.FileHeader
@@:
mov eax, [ebx + bmp.Header.info.Size]
mov eax, [ebx + bmp.InfoHeader.Size]
; sanity check: file length must be greater than size of headers
add eax, sizeof.bmp.FileHeader
cmp [_length], eax
jbe .error
mov [bTopDown], 0
cmp eax, sizeof.bmp.FileHeader + 12
cmp eax, 12
jz .old1
cmp eax, sizeof.bmp.FileHeader + 40
cmp eax, 40
jz .normal
cmp eax, sizeof.bmp.FileHeader + 56
cmp eax, 56
jnz .error
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
.normal:
m2m eax, Image.bpp8
cmp [ebx + bmp.Header.info.BitCount], 8
cmp byte [ebx + 14], 8 ; bit count
jbe @f
mov al, Image.bpp32
@@:
push eax
mov eax, [ebx + bmp.Header.info.Height]
mov eax, [ebx + 8] ;[ebx + bmp.InfoHeader.Height]
test eax, eax
jns @f
inc [bTopDown]
neg eax
@@:
cmp [bIsIco], 0 ; for icons Height is two times larger than image height
jz @f
shr eax, 1
@@:
pushd eax
pushd [ebx + bmp.Header.info.Width]
pushd [ebx + 4] ;[ebx + bmp.InfoHeader.Width]
jmp .create
.old1:
m2m eax, Image.bpp8
cmp [ebx + bmp.Header.info.OldBitCount], 8
cmp byte [ebx + 10], 8 ; bit count
jbe @f
mov al, Image.bpp32
@@:
push eax
movsx eax, [ebx + bmp.Header.info.OldHeight]
movsx eax, word [ebx + 6] ;[ebx + bmp.InfoHeader.OldHeight]
test eax, eax
jns @f
inc [bTopDown]
neg eax
@@:
cmp [bIsIco], 0 ; for icons Height is two times larger than image height
jz @f
shr eax, 1
@@:
push eax
movzx eax, [ebx + bmp.Header.info.OldWidth]
movzx eax, word [ebx + 4] ;[ebx + bmp.InfoHeader.OldWidth]
push eax
.create:
call img.create
@@ -151,9 +157,9 @@ endl
xor eax, eax
rep stosd
pop edi
lea esi, [ebx + sizeof.bmp.FileHeader]
pushd [ebx + bmp.FileHeader.OffBits]
mov ecx, [esi + bmp.InfoHeader.Size]
push edi
mov esi, ebx
mov ecx, [ebx] ;[ebx + bmp.InfoHeader.Size]
cmp ecx, 12
jz .old2
rep movsb
@@ -168,10 +174,28 @@ endl
movsd ; Planes+BitCount
.decode:
pop eax
mov esi, [_length]
sub esi, eax
pop edi
cmp [bIsIco], 0
jnz @f
mov edi, [_length]
add edi, sizeof.bmp.FileHeader
mov esi, [ebx - sizeof.bmp.FileHeader + bmp.FileHeader.OffBits]
jmp .offset_calculated
@@:
xor esi, esi
mov cl, byte [edi + bmp.Image.info.BitCount]
cmp cl, 8
ja @f
inc esi
add cl, 2
shl esi, cl
@@:
add esi, [edi + bmp.Image.info.Size]
mov edi, [_length]
.offset_calculated:
sub edi, esi
jbe .error.free
add esi, [_data]
mov eax, [edx + Image.Extended]
mov eax, [eax + bmp.Image.info.Compression]
@@ -181,13 +205,13 @@ endl
jmp .decoded
@@: cmp eax, bmp.BI_RLE8
jne @f
cmp [ebx + bmp.Header.info.BitCount], 8
cmp word [ebx + 14], 8 ;bmp.InfoHeader.BitCount
jnz .error.free
stdcall ._.rle
jmp .decoded
@@: cmp eax, bmp.BI_RLE4
jne @f
cmp [ebx + bmp.Header.info.BitCount], 4
cmp word [ebx + 14], 4
jnz .error.free
stdcall ._.rle
jmp .decoded
@@ -218,6 +242,11 @@ endl
stdcall img.flip, [img], FLIP_VERTICAL
@@:
mov eax, [img]
mov ecx, [length_rest] ; return length for ICO code
cmp [bIsIco], 0
jz @f
mov [esp + 4], esi ; return pointer to end-of-data for ICO code
@@:
pop edi esi ebx
ret
@@ -228,7 +257,7 @@ endl
endp
;;================================================================================================;;
proc img.encode.bmp _img, _p_length ;/////////////////////////////////////////////////////////////;;
proc img.encode.bmp _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in BMP format ;;
;;------------------------------------------------------------------------------------------------;;
@@ -263,7 +292,6 @@ proc img.decode.bmp._.rgb ;/////////////////////////////////////////////////////
;;================================================================================================;;
mov ecx, [edx + Image.Extended]
mov [ecx + bmp.Image.info.AlphaMask], 0
mov edi, [edx + Image.Data]
movzx eax, [ecx + bmp.Image.info.BitCount]
cmp eax, 32
@@ -297,10 +325,10 @@ img.decode.bmp._.rgb.24bpp:
and eax, not 3
mov ecx, [edx + Image.Height]
imul eax, ecx
cmp esi, eax
sub edi, eax
jb img.decode.bmp._.rgb.error
mov esi, ebx
add esi, [ebx + bmp.Header.file.OffBits]
mov [img.decode.bmp.length_rest], edi
mov edi, [edx + Image.Data]
.next_line:
push ecx edx
@@ -447,19 +475,20 @@ img.decode.bmp._.rgb.prepare_palette:
and eax, not 3
mov ecx, [edx + Image.Height]
imul eax, ecx
cmp esi, eax
sub edi, eax
jb .ret
mov esi, [ebx + bmp.Header.info.Size]
add esi, sizeof.bmp.FileHeader
jc .ret
mov eax, [ebx + bmp.Header.file.OffBits]
sub eax, esi
jc .ret
push edi
mov [img.decode.bmp.length_rest], edi
push esi
sub esi, ebx
jc .ret.pop
sub esi, [ebx + bmp.InfoHeader.Size]
jc .ret.pop
mov eax, esi
mov edi, [edx + Image.Palette]
push ecx
mov ecx, 256
cmp esi, sizeof.bmp.FileHeader + 12
mov esi, [ebx + bmp.InfoHeader.Size]
cmp esi, 12
jz .old
shr eax, 2
add esi, ebx
@@ -470,18 +499,21 @@ img.decode.bmp._.rgb.prepare_palette:
rep movsd
jmp .common
.old:
add esi, ebx
@@:
movsd
dec esi
sub eax, 3
jbe @f
sub ecx, 1
jnz .old
jnz @b
@@:
.common:
pop ecx
pop edi
mov esi, ebx
add esi, [ebx + bmp.Header.file.OffBits]
mov edi, [edx + Image.Data]
clc
.ret.pop:
pop esi
.ret:
ret
endp
@@ -507,15 +539,18 @@ endl
mov [abs_mode_addr], .absolute_mode.rle8
mov [enc_mode_addr], .encoded_mode.rle8
cmp [ebx + bmp.Header.info.Compression], bmp.BI_RLE4
cmp [ebx + bmp.InfoHeader.Compression], bmp.BI_RLE4
jne @f
mov [abs_mode_addr], .absolute_mode.rle4
mov [enc_mode_addr], .encoded_mode.rle4
@@:
push esi
push edi
xor eax, eax ; do not check file size in .prepare_palette
push ebp
mov ebp, [ebp] ; set parent stack frame
call img.decode.bmp._.rgb.prepare_palette
pop ebp
pop ecx ; ecx = rest bytes in file
jc .error
@@ -712,8 +747,6 @@ locals
delta dd ?
endl
push edi
mov [delta], 4
mov eax, [edx + Image.Extended]
cmp [eax + bmp.Image.info.BitCount], 32
@@ -725,9 +758,12 @@ endl
mov ecx, [edx + Image.Width]
imul ecx, [edx + Image.Height]
imul ecx, [delta]
cmp esi, ecx
sub edi, ecx
jb .error
mov ecx, [ebp] ; use parent stack frame
mov [ecx + img.decode.bmp.length_rest - ebp], edi ; !
push esi
mov esi, eax
mov ecx, [esi + bmp.Image.info.RedMask]
@@ -759,8 +795,7 @@ endl
mov [unshift.Alpha], al
mov edi, [edx + Image.Data]
mov esi, ebx
add esi, [ebx + bmp.Header.file.OffBits]
pop esi
;;------------------------------------------------------------------------------------------------;;

View File

@@ -72,7 +72,7 @@ proc img.is.gif _data, _length ;////////////////////////////////////////////////
endp
;;================================================================================================;;
proc img.decode.gif _data, _length ;//////////////////////////////////////////////////////////////;;
proc img.decode.gif _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in GIF format ;;
;;------------------------------------------------------------------------------------------------;;
@@ -86,6 +86,7 @@ locals
cur_color_table_size dd ?
transparent_color dd ?
background_color dd ?
options_bgr dd ?
prev_palette dd ?
aux_palette dd ?
img dd ?
@@ -110,6 +111,7 @@ img.decode.gif._data equ _data
img.decode.gif.aux_img_data equ aux_img_data
img.decode.gif.aux_img_type equ aux_img_type
img.decode.gif.aux_palette equ aux_palette
img.decode.gif.options_bgr equ options_bgr
; offset of _length parameter for child functions with ebp-based frame
; child saved ebp, return address, 3 saved registers, 14 local variables
img.decode.gif._length_child equ _length + 4 + 4 + 4*3 + 4*14
@@ -130,8 +132,16 @@ img.decode.gif.cur_color_table_size_child equ ebp + 4 + 4 + 4*3 + 4
mov [prev_num_colors], eax
lea eax, [background_color]
mov [prev_palette], eax
; guard against incorrect gif files, which use Restore-To-Background disposal method, but do not define bgr color
mov dword [eax], 0xFFFFFF
; value for bgr color in transparent images
mov edx, 0xFFFFFF ; white bgr if no value given
mov ecx, [_options]
jecxz @f
cmp [ecx + ImageDecodeOptions.UsedSize], ImageDecodeOptions.BackgroundColor + 4
jb @f
mov edx, [ecx + ImageDecodeOptions.BackgroundColor]
@@:
mov [options_bgr], edx
mov dword [eax], edx
; guard against incorrect gif files without any color tables
; "If no color table is available at
; all, the decoder is free to use a system color table or a table of its own. In
@@ -790,22 +800,11 @@ proc img.decode.gif._.superimpose ;/////////////////////////////////////////////
jnz .has_transparency
shl ecx, 2
add ecx, [edx + Image.Palette]
mov dword [background_color], 0xFFFFFF ; white background
mov dword [ecx], 0xFFFFFF
; mov esi, [_data]
; test [esi+gif.Header.lsd.Packed], gif.LSD.Packed.GlobalColorTableFlag
; jz @f
; movzx ecx, [esi+gif.Header.lsd.BackgroundColor]
; push ecx
; shl ecx, 2
; add ecx, [edx + Image.Palette]
; mov dword [ecx], 0xFFFFFF
; pop ecx
; lea ecx, [ecx*3]
; add esi, ecx
; mov byte [esi+sizeof.gif.Header+0], 0xFF
; mov byte [esi+sizeof.gif.Header+1], 0xFF
; mov byte [esi+sizeof.gif.Header+2], 0xFF
push eax
mov eax, [img.decode.gif.options_bgr]
mov dword [background_color], eax
mov dword [ecx], eax
pop eax
@@:
call img.decode.gif._.is_logical_screen
jnz .has_transparency

View File

@@ -0,0 +1,371 @@
;;================================================================================================;;
;;//// ico.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ///////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
;; ;;
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
;; of the License, or (at your option) any later version. ;;
;; ;;
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;;
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
;; Lesser General Public License for more details. ;;
;; ;;
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev. ;;
;; If not, see <http://www.gnu.org/licenses/>. ;;
;; ;;
;;================================================================================================;;
;; ;;
;; References: ;;
;; 1. "Icons in Win32" ;;
;; by John Hornick, Microsoft Corporation ;;
;; http://msdn2.microsoft.com/en-us/library/ms997538.aspx ;;
;; ;;
;;================================================================================================;;
include 'ico_cur.inc'
;;================================================================================================;;
;;proc img.is.ico _data, _length ;////////////////////////////////////////////////////////////////;;
img.is.ico:
mov edx, 0x00010000 ; icon type = 1
jmp @f
img.is.cur:
mov edx, 0x00020000 ; cursor type = 2
@@:
;;------------------------------------------------------------------------------------------------;;
;? Determine if raw data could be decoded (is in ICO format) ;;
;;------------------------------------------------------------------------------------------------;;
;> _data = raw data as read from file/stream ;;
;> _length = data length ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;================================================================================================;;
; test 1 (length of data): data must contain FileHeader
mov ecx, [esp+8]
sub ecx, sizeof.ico.FileHeader
jb .nope
; test 2: signature
mov eax, [esp+4]
cmp dword [eax], edx ; Reserved & Type
jne .nope
; test 3: count must be non-zero
movzx eax, [eax + ico.FileHeader.Count]
test eax, eax
jz .nope
; test 4 (length of data): data must containt Count dir entries
shl eax, 4
sub ecx, eax
jae .yep
.nope:
xor eax, eax
ret 8
.yep:
xor eax, eax
inc eax
ret 8
;endp
;;================================================================================================;;
proc img.decode.ico_cur _data, _length, _options ;////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in ICO/CUR format ;;
;;------------------------------------------------------------------------------------------------;;
;> _data = raw data as read from file/stream ;;
;> _length = data length ;;
;> _options = options for decoding (e.g. background color) ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (error) or pointer to image ;;
;;================================================================================================;;
locals
count dd ?
img dd ?
main_img dd ?
endl
push ebx esi edi
; img.is.ico has been already called by img.decode
; stdcall img.is.ico, [_data], [_length]
; or eax, eax
; jz .error
mov ebx, [_data]
movzx eax, [ebx + ico.FileHeader.Count]
mov [count], eax
and [img], 0
and [main_img], 0
.loop:
mov ecx, [ebx + sizeof.ico.FileHeader + ico.DirEntry.ByteSize]
mov edx, [ebx + sizeof.ico.FileHeader + ico.DirEntry.ImageOffset]
mov eax, [_length]
sub eax, edx
jb .skip
cmp eax, ecx
jb .skip
cmp ecx, 12 ; length test, see img.is.bmp
jb .skip
add edx, [_data]
push [_options]
push ecx
push edx
call img.decode.ico._.decode_icon_data
test eax, eax
jz .skip
push 0xFFFFFF ; set bgr to white if no given
mov edx, [_options]
test edx, edx
jz @f
cmp [edx + ImageDecodeOptions.UsedSize], ImageDecodeOptions.BackgroundColor + 4
jb @f
add esp, 4
push [edx + ImageDecodeOptions.BackgroundColor]
@@:
call img.decode.ico._.decode_icon_mask
test eax, eax
jz .skip
mov edx, [img]
test edx, edx
jz .first
mov [edx + Image.Next], eax
mov [eax + Image.Previous], edx
jmp @f
.first:
mov [main_img], eax
@@:
mov [img], eax
.skip:
add ebx, sizeof.ico.DirEntry
dec [count]
jnz .loop
mov eax, [main_img]
pop edi esi ebx
ret
endp
;;================================================================================================;;
img.encode.cur:
proc img.encode.ico _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in ICO format ;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (error) or pointer to encoded data ;;
;< _p_length = encoded data length ;;
;;================================================================================================;;
xor eax, eax
ret
endp
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;! Below are private procs you should never call directly from your code ;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
img.decode.ico._.decode_icon_data:
; create stack frame and jump to common BMP+ICO code
push ebp
mov ebp, esp
sub esp, 12
mov byte [ebp - 3], 1 ; bIsIco
jmp img.decode.bmp.common
img.decode.ico._.decode_icon_mask:
mov edx, [eax + Image.Width]
add edx, 31
shr edx, 3
and edx, not 3
push edx
imul edx, [eax + Image.Height]
cmp ecx, edx
pop edx
jb .error.free
mov edi, [eax + Image.Data]
push ebp ebx eax
xor ebp, ebp
mov ebx, [eax + Image.Extended]
cmp [ebx + bmp.Image.info.Height], 0
js @f
push edx
imul edx, [eax + Image.Height]
add esi, edx
pop edx
lea ebp, [edx+edx]
sub esi, edx
@@:
mov ebx, [eax + Image.Height]
mov ecx, [eax + Image.Width]
; for now, BMP code produces only 8 and 32 bpp images
cmp [eax + Image.Type], Image.bpp8
jz .bpp8
.bpp32:
mov edx, [esp+16] ; get background color
.bpp32.extloop:
push ecx
.bpp32.innloop:
lodsd
bswap eax
push 32
.bpp32.dwordloop:
add eax, eax
jnc @f
mov [edi], edx
@@:
add edi, 4
dec ecx
jz @f
dec dword [esp]
jnz .bpp32.dwordloop
@@:
pop eax
test ecx, ecx
jnz .bpp32.innloop
sub esi, ebp
pop ecx
dec ebx
jnz .bpp32.extloop
pop eax ebx ebp
ret 4
.bpp8:
push edi
mov edi, [eax + Image.Palette]
mov eax, [esp+20] ; get background color
; if palette already has index for bgr color, use it
push ecx
mov ecx, 256
repnz scasd
jnz .bpp8.notfound
not cl ; cl = index
pop edx
pop edi
.bpp8.extloop:
push edx
.bpp8.innloop:
lodsd
bswap eax
push 32
.bpp8.dwordloop:
add eax, eax
jnc @f
mov [edi], cl
@@:
inc edi
dec edx
jz @f
dec dword [esp]
jnz .bpp8.dwordloop
@@:
pop eax
test edx, edx
jnz .bpp8.innloop
sub esi, ebp
pop edx
dec ebx
jnz .bpp8.extloop
pop eax ebx ebp
ret 4
.bpp8.notfound:
; get maximum used color; if index < 255, then we can add one color to palette
pop ecx
pop edi
pop eax
mov edx, [eax + Image.Width]
imul edx, ebx
mov edi, [eax + Image.Data]
xor ecx, ecx
.bpp8.scanloop:
cmp [edi], cl
jb @f
mov cl, [edi]
@@:
inc edi
dec edx
jnz .bpp8.scanloop
inc cl
jz .bpp8.nospace
mov edx, [esp+8]
mov edi, [eax + Image.Palette]
mov [edi+ecx*4], edx ; set palette color
mov edi, [eax + Image.Data]
mov edx, [eax + Image.Width]
push eax
jmp .bpp8.extloop
.bpp8.nospace:
; convert to 24 bpp
mov edx, [eax + Image.Width]
imul edx, ebx
lea edx, [edx*3]
push eax
invoke mem.alloc, edx
mov edi, eax
pop eax
test edi, edi
jz .error.free2
push eax esi edi
mov esi, eax
call img._.do_rgb
pop edi esi eax
xchg edi, [eax + Image.Data]
mov byte [eax + Image.Type], Image.bpp24
push eax
invoke mem.free, edi
pop eax
push eax
mov ecx, [eax + Image.Width]
.bpp24:
mov edx, [esp+16] ; get background color
.bpp24.extloop:
push ecx
.bpp24.innloop:
lodsd
bswap eax
push 32
.bpp24.dwordloop:
add eax, eax
jnc @f
mov [edi], dx
ror edx, 16
mov [edi+2], dl
ror edx, 16
@@:
add edi, 4
dec ecx
jz @f
dec dword [esp]
jnz .bpp24.dwordloop
@@:
pop eax
test ecx, ecx
jnz .bpp24.innloop
sub esi, ebp
pop ecx
dec ebx
jnz .bpp24.extloop
pop eax ebx ebp
ret 4
.error.free2:
pop ebx ebp
.error.free:
stdcall img._.delete, eax
xor eax, eax
ret 4
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;! Below is private data you should never use directly from your code ;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;

View File

@@ -1,5 +1,5 @@
;;================================================================================================;;
;;//// ico.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
;;//// ico.inc //// (c) diamond, 2009 ////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
@@ -16,10 +16,31 @@
;; If not, see <http://www.gnu.org/licenses/>. ;;
;; ;;
;;================================================================================================;;
;; ;;
;; References: ;;
;; 1. "Icons in Win32" ;;
;; by John Hornick, Microsoft Corporation ;;
;; http://msdn2.microsoft.com/en-us/library/ms997538.aspx ;;
;; ;;
;;================================================================================================;;
struct ico.FileHeader
Reserved dw ? ; must be 0
Type dw ? ; must be 1
Count dw ?
ends
struct ico.DirEntry
Width db ?
Height db ?
ColorCount db ?
db ? ; reseved
dw ? ; reserved
dw ? ; reserved
ByteSize dd ?
ImageOffset dd ?
ends
struct cur.DirEntry
Width db ?
Height db ?
ColorCount db ?
db ? ; reserved
XHotSpot dw ?
YHotSpot dw ?
ByteSize dd ?
ImageOffset dd ?
ends

View File

@@ -69,7 +69,7 @@ img.decode.jpg:
.ret:
mov [esp+28], eax
popad
ret 8
ret 12
.soi_ok:
mov [ebx + jpeg.work.restart_interval], ecx
mov [ebx + jpeg.work.adobe_ycck], cl

View File

@@ -37,6 +37,7 @@ include 'jpeg/jpeg.asm'
include 'png/png.asm'
include 'tga/tga.asm'
include 'z80/z80.asm'
include 'ico_cur/ico_cur.asm'
;;================================================================================================;;
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
@@ -496,7 +497,7 @@ align 16
endp
;;================================================================================================;;
proc img.decode _data, _length ;//////////////////////////////////////////////////////////////////;;
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
@@ -510,17 +511,18 @@ proc img.decode _data, _length ;////////////////////////////////////////////////
or eax, eax
jnz @f
add ebx, sizeof.FormatsTableEntry
cmp dword[ebx], 0
cmp dword[ebx], eax ;0
jnz @b
jmp .error
@@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length]
.error:
pop ebx
ret
@@: mov eax, [ebx + FormatsTableEntry.Decode]
pop ebx
leave
jmp eax
endp
;;================================================================================================;;
proc img.encode _img, _p_length ;/////////////////////////////////////////////////////////////////;;
proc img.encode _img, _p_length, _options ;///////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;------------------------------------------------------------------------------------------------;;
@@ -1667,8 +1669,8 @@ img._.get_scanline_len: ;///////////////////////////////////////////////////////
align 4
img._.formats_table:
.bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
; .cur dd img.is.cur, img.decode.cur, img.encode.cur
.ico dd img.is.ico, img.decode.ico_cur, img.encode.ico
.cur dd img.is.cur, img.decode.ico_cur, img.encode.cur
.gif dd img.is.gif, img.decode.gif, img.encode.gif
.png dd img.is.png, img.decode.png, img.encode.png
.jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
@@ -1707,35 +1709,35 @@ align 4
export \
lib_init , 'lib_init' , \
0x00010004 , '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'
0x00050005 , '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'
; import from deflate unpacker
; is initialized only when PNG loading is requested
align 4
@IMPORT:
library kfar_arc, '../File Managers/kfar_arc.obj'
import kfar_arc, \
library archiver, 'archiver.obj'
import archiver, \
deflate_unpack2, 'deflate_unpack2'
align 4

View File

@@ -49,6 +49,11 @@ Image.bpp16 = 5
; bits in Image.Flags
Image.IsAnimated = 1
struct ImageDecodeOptions
UsedSize dd ? ; if >=8, the field BackgroundColor is valid, and so on
BackgroundColor dd ? ; used for transparent images as background
ends
FLIP_VERTICAL = 0x01
FLIP_HORIZONTAL = 0x02
FLIP_BOTH = FLIP_VERTICAL or FLIP_HORIZONTAL

View File

@@ -49,7 +49,7 @@ img.is.png:
;endp
;;================================================================================================;;
;;proc img.decode.png _data, _length ;////////////////////////////////////////////////////////////;;
;;proc img.decode.png _data, _length, _options ;//////////////////////////////////////////////////;;
img.decode.png:
xor eax, eax ; .image = 0
pushad
@@ -76,6 +76,7 @@ virtual at ebp - .localsize
rd 1
.data dd ?
.length dd ?
.options dd ?
end virtual
push 0 ; .idat_read = 0
sub esp, .localsize-4
@@ -99,7 +100,7 @@ end virtual
add esp, .localsize
popad
mov [deflate_loader_mutex], eax
ret
ret 12
.deflate_loaded:
; release mutex
mov [deflate_loader_mutex], 0
@@ -229,7 +230,7 @@ end virtual
.eof:
add esp, .localsize
popad
ret
ret 12
; PLTE chunk
.palette:
mov eax, [.image]
@@ -876,4 +877,4 @@ end repeat
img.encode.png:
xor eax, eax
ret 8
ret 12

View File

@@ -78,7 +78,7 @@ proc img.is.tga _data, _length ;////////////////////////////////////////////////
endp
;;================================================================================================;;
proc img.decode.tga _data, _length ;//////////////////////////////////////////////////////////////;;
proc img.decode.tga _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in Targa format ;;
;;------------------------------------------------------------------------------------------------;;
@@ -217,7 +217,7 @@ endl
endp
;;================================================================================================;;
proc img.encode.tga _img, _p_length ;/////////////////////////////////////////////////////////////;;
proc img.encode.tga _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in Targa format ;;
;;------------------------------------------------------------------------------------------------;;

View File

@@ -45,7 +45,7 @@ proc img.is.z80 _data, _length ;////////////////////////////////////////////////
endp
;;================================================================================================;;
proc img.decode.z80 _data, _length ;//////////////////////////////////////////////////////////////;;
proc img.decode.z80 _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in z80 screen format ;;
;;------------------------------------------------------------------------------------------------;;
@@ -209,7 +209,7 @@ img.decode.z80.failed:
endp
;;================================================================================================;;
proc img.encode.z80 _img, _p_length ;/////////////////////////////////////////////////////////////;;
proc img.encode.z80 _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in z80 screen format ;;
;;------------------------------------------------------------------------------------------------;;