2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
2009-01-25 21:12:30 +03:00
|
|
|
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ////////////////////////////////;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
;; ;;
|
|
|
|
;; 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 ;;
|
2009-01-25 21:12:30 +03:00
|
|
|
;; 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. ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;; ;;
|
|
|
|
;; 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 ;;
|
2009-01-25 21:12:30 +03:00
|
|
|
;; Lesser General Public License for more details. ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;; ;;
|
2009-01-25 21:12:30 +03:00
|
|
|
;; 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/>. ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;; ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
|
|
|
public @EXPORT as 'EXPORTS'
|
|
|
|
|
|
|
|
include '../../../../struct.inc'
|
|
|
|
include '../../../../proc32.inc'
|
|
|
|
include '../../../../macros.inc'
|
2009-01-25 21:12:30 +03:00
|
|
|
purge section,mov,add,sub
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
include 'libimg.inc'
|
|
|
|
|
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
include 'bmp/bmp.asm'
|
|
|
|
include 'gif/gif.asm'
|
2009-01-25 21:12:30 +03:00
|
|
|
include 'jpeg/jpeg.asm'
|
2009-01-31 04:58:27 +03:00
|
|
|
include 'png/png.asm'
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
mem.alloc dd ?
|
|
|
|
mem.free dd ?
|
|
|
|
mem.realloc dd ?
|
|
|
|
dll.load dd ?
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Library entry point (called after library load) ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> eax = pointer to memory allocation routine ;;
|
|
|
|
;> ebx = pointer to memory freeing routine ;;
|
|
|
|
;> ecx = pointer to memory reallocation routine ;;
|
|
|
|
;> edx = pointer to library loading routine ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 1 (fail) / 0 (ok) (library initialization result) ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
mov [mem.alloc], eax
|
|
|
|
mov [mem.free], ebx
|
|
|
|
mov [mem.realloc], ecx
|
|
|
|
mov [dll.load], edx
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
call img.initialize.jpeg
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
.ok: xor eax,eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push ebx
|
|
|
|
mov ebx, img._.formats_table
|
|
|
|
@@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
|
|
|
|
or eax, eax
|
|
|
|
jnz @f
|
|
|
|
add ebx, sizeof.FormatsTableEntry
|
|
|
|
cmp dword[ebx], 0
|
|
|
|
jnz @b
|
|
|
|
xor eax, eax
|
|
|
|
@@: pop ebx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2009-01-27 02:43:01 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push esi edi
|
|
|
|
mov esi, [_img]
|
|
|
|
stdcall img._.validate, esi
|
|
|
|
or eax, eax
|
|
|
|
jnz .ret
|
|
|
|
mov edi, [_out]
|
|
|
|
call img._.do_rgb
|
|
|
|
.ret:
|
|
|
|
pop edi esi
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets) ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push esi edi
|
2009-01-27 02:43:01 +03:00
|
|
|
mov esi, [_img]
|
|
|
|
stdcall img._.validate, esi
|
2008-02-08 01:45:15 +03:00
|
|
|
or eax, eax
|
|
|
|
jnz .error
|
|
|
|
|
|
|
|
mov esi, [_img]
|
|
|
|
mov ecx, [esi + Image.Width]
|
|
|
|
imul ecx, [esi + Image.Height]
|
|
|
|
lea eax, [ecx * 3 + 4 * 3]
|
|
|
|
invoke mem.alloc, eax
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
|
|
|
|
mov edi, eax
|
|
|
|
push eax
|
|
|
|
mov eax, [esi + Image.Width]
|
|
|
|
stosd
|
|
|
|
mov eax, [esi + Image.Height]
|
|
|
|
stosd
|
2009-01-27 02:43:01 +03:00
|
|
|
call img._.do_rgb
|
|
|
|
pop eax
|
|
|
|
pop edi esi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
xor eax, eax
|
|
|
|
pop edi esi
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
mov ecx, [esi + Image.Width]
|
|
|
|
imul ecx, [esi + Image.Height]
|
2009-01-25 21:12:30 +03:00
|
|
|
mov eax, [esi + Image.Type]
|
|
|
|
dec eax
|
|
|
|
jz .bpp8
|
|
|
|
dec eax
|
|
|
|
jz .bpp24
|
|
|
|
; 32 BPP -> 24 BPP
|
2008-02-08 01:45:15 +03:00
|
|
|
mov esi, [esi + Image.Data]
|
|
|
|
|
2009-01-31 06:30:53 +03:00
|
|
|
@@:
|
|
|
|
mov eax, [esi]
|
|
|
|
mov [edi], ax
|
|
|
|
shr eax, 16
|
|
|
|
mov [edi+2], al
|
|
|
|
add esi, 4
|
|
|
|
add edi, 3
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
2008-02-08 01:45:15 +03:00
|
|
|
|
2009-01-27 02:43:01 +03:00
|
|
|
@@:
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
.bpp24:
|
|
|
|
; 24 BPP -> 24 BPP
|
|
|
|
lea ecx, [ecx*3 + 3]
|
|
|
|
mov esi, [esi + Image.Data]
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
ret
|
|
|
|
|
|
|
|
.bpp8:
|
|
|
|
; 8 BPP -> 24 BPP
|
|
|
|
push ebx
|
|
|
|
mov ebx, [esi + Image.Palette]
|
|
|
|
mov esi, [esi + Image.Data]
|
|
|
|
@@:
|
|
|
|
movzx eax, byte [esi]
|
|
|
|
add esi, 1
|
|
|
|
mov eax, [ebx + eax*4]
|
2009-01-31 06:30:53 +03:00
|
|
|
mov [edi], ax
|
|
|
|
shr eax, 16
|
|
|
|
mov [edi+2], al
|
2009-01-25 21:12:30 +03:00
|
|
|
add edi, 3
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
pop ebx
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.decode _data, _length ;//////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push ebx
|
|
|
|
mov ebx, img._.formats_table
|
|
|
|
@@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
|
|
|
|
or eax, eax
|
|
|
|
jnz @f
|
|
|
|
add ebx, sizeof.FormatsTableEntry
|
|
|
|
cmp dword[ebx], 0
|
2009-01-25 21:12:30 +03:00
|
|
|
jnz @b
|
2008-02-08 01:45:15 +03:00
|
|
|
jmp .error
|
|
|
|
@@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length]
|
|
|
|
|
|
|
|
.error:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.encode _img, _p_length ;/////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to encoded data ;;
|
|
|
|
;< [_p_length] = data length ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
2009-01-25 21:12:30 +03:00
|
|
|
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
stdcall img._.new
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
mov ecx, [_type]
|
|
|
|
mov [eax + Image.Type], ecx
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
push eax
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
stdcall img._.resize_data, eax, [_width], [_height]
|
2008-02-08 01:45:15 +03:00
|
|
|
or eax, eax
|
|
|
|
jz .error.2
|
|
|
|
|
|
|
|
pop eax
|
2009-01-25 21:12:30 +03:00
|
|
|
jmp .ret
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
.error.2:
|
|
|
|
; pop eax
|
|
|
|
stdcall img._.delete; eax
|
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
.error:
|
2009-01-25 21:12:30 +03:00
|
|
|
.ret:
|
2008-02-08 01:45:15 +03:00
|
|
|
pop ecx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;TODO: link Next and Previous
|
|
|
|
stdcall img._.delete, [_img]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
2008-03-31 02:31:00 +04:00
|
|
|
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;? Get number of images in the list (e.g. in animated GIF file) ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;> _img = pointer to image ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;< eax = -1 (fail) / >0 (ok) ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
2008-03-31 02:31:00 +04:00
|
|
|
push ecx edx
|
|
|
|
mov edx, [_img]
|
|
|
|
stdcall img._.validate, edx
|
2008-02-08 01:45:15 +03:00
|
|
|
or eax, eax
|
2008-03-31 02:31:00 +04:00
|
|
|
jnz .error
|
2008-02-08 01:45:15 +03:00
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
@@: mov eax, [edx + Image.Previous]
|
|
|
|
or eax, eax
|
|
|
|
jz @f
|
|
|
|
mov edx, eax
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
@@: xor ecx, ecx
|
|
|
|
@@: inc ecx
|
|
|
|
mov eax, [edx + Image.Next]
|
|
|
|
or eax, eax
|
|
|
|
jz .exit
|
|
|
|
mov edx, eax
|
|
|
|
jmp @b
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
mov eax, ecx
|
|
|
|
pop edx ecx
|
|
|
|
ret
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
.error:
|
2008-03-31 02:31:00 +04:00
|
|
|
or eax, -1
|
|
|
|
pop edx ecx
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to bits ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;? Flip image ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;> _img = pointer to image ;;
|
|
|
|
;> _flip_kind = one of FLIP_* constants ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2008-03-31 02:31:00 +04:00
|
|
|
;< eax = false / true ;;
|
2008-02-08 01:45:15 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
scanline_len dd ?
|
|
|
|
endl
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
push ebx esi edi
|
|
|
|
mov ebx, [_img]
|
|
|
|
stdcall img._.validate, ebx
|
2008-02-08 01:45:15 +03:00
|
|
|
or eax, eax
|
|
|
|
jnz .error
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
mov ecx, [ebx + Image.Height]
|
|
|
|
mov eax, [ebx + Image.Width]
|
|
|
|
call img._.get_scanline_len
|
2008-02-08 01:45:15 +03:00
|
|
|
mov [scanline_len], eax
|
|
|
|
|
|
|
|
test [_flip_kind], FLIP_VERTICAL
|
|
|
|
jz .dont_flip_vert
|
|
|
|
|
|
|
|
imul eax, ecx
|
|
|
|
sub eax, [scanline_len]
|
|
|
|
shr ecx, 1
|
2009-01-25 21:12:30 +03:00
|
|
|
mov esi, [ebx + Image.Data]
|
2008-02-08 01:45:15 +03:00
|
|
|
lea edi, [esi + eax]
|
|
|
|
|
|
|
|
.next_line_vert:
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov ecx, [scanline_len]
|
2009-01-25 21:12:30 +03:00
|
|
|
push ecx
|
2008-03-31 02:31:00 +04:00
|
|
|
shr ecx, 2
|
2009-01-25 21:12:30 +03:00
|
|
|
@@: mov eax, [esi]
|
2008-02-08 01:45:15 +03:00
|
|
|
xchg eax, [edi]
|
2009-01-25 21:12:30 +03:00
|
|
|
mov [esi], eax
|
|
|
|
add esi, 4
|
2008-02-08 01:45:15 +03:00
|
|
|
add edi, 4
|
2009-01-25 21:12:30 +03:00
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
pop ecx
|
|
|
|
and ecx, 3
|
|
|
|
jz .cont_line_vert
|
|
|
|
@@:
|
|
|
|
mov al, [esi]
|
|
|
|
xchg al, [edi]
|
|
|
|
mov [esi], al
|
|
|
|
add esi, 1
|
|
|
|
add edi, 1
|
2008-03-31 02:31:00 +04:00
|
|
|
dec ecx
|
2008-02-08 01:45:15 +03:00
|
|
|
jnz @b
|
2009-01-25 21:12:30 +03:00
|
|
|
.cont_line_vert:
|
2008-02-08 01:45:15 +03:00
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
pop ecx
|
2008-02-08 01:45:15 +03:00
|
|
|
mov eax, [scanline_len]
|
|
|
|
shl eax, 1
|
|
|
|
sub edi, eax
|
|
|
|
dec ecx
|
|
|
|
jnz .next_line_vert
|
|
|
|
|
|
|
|
.dont_flip_vert:
|
|
|
|
|
|
|
|
test [_flip_kind], FLIP_HORIZONTAL
|
|
|
|
jz .exit
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
mov ecx, [ebx + Image.Height]
|
|
|
|
mov eax, [ebx + Image.Type]
|
|
|
|
mov esi, [ebx + Image.Data]
|
|
|
|
mov edi, [scanline_len]
|
|
|
|
add edi, esi
|
|
|
|
|
|
|
|
dec eax
|
|
|
|
jz .bpp8.2
|
|
|
|
dec eax
|
|
|
|
jz .bpp24.2
|
|
|
|
|
|
|
|
sub edi, 4
|
2008-03-31 02:31:00 +04:00
|
|
|
|
|
|
|
.next_line_horz:
|
|
|
|
push ecx esi edi
|
|
|
|
|
|
|
|
mov ecx, [scanline_len]
|
|
|
|
shr ecx, 3
|
|
|
|
@@: mov eax, [esi]
|
|
|
|
xchg eax, [edi]
|
|
|
|
mov [esi], eax
|
|
|
|
add esi, 4
|
|
|
|
add edi, -4
|
2009-01-25 21:12:30 +03:00
|
|
|
sub ecx, 1
|
2008-03-31 02:31:00 +04:00
|
|
|
jnz @b
|
|
|
|
|
|
|
|
pop edi esi ecx
|
|
|
|
add esi, [scanline_len]
|
|
|
|
add edi, [scanline_len]
|
|
|
|
dec ecx
|
|
|
|
jnz .next_line_horz
|
2009-01-25 21:12:30 +03:00
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.bpp8.2:
|
|
|
|
dec edi
|
|
|
|
.next_line_horz8:
|
|
|
|
push ecx esi edi
|
|
|
|
|
|
|
|
mov ecx, [scanline_len]
|
|
|
|
shr ecx, 1
|
|
|
|
@@: mov al, [esi]
|
|
|
|
mov dl, [edi]
|
|
|
|
mov [edi], al
|
|
|
|
mov [esi], dl
|
|
|
|
add esi, 1
|
|
|
|
sub edi, 1
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
pop edi esi ecx
|
|
|
|
add esi, [scanline_len]
|
|
|
|
add edi, [scanline_len]
|
|
|
|
dec ecx
|
|
|
|
jnz .next_line_horz8
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.bpp24.2:
|
|
|
|
sub edi, 3
|
|
|
|
.next_line_horz32:
|
|
|
|
push ecx esi edi
|
|
|
|
|
|
|
|
mov ecx, [ebx + Image.Width]
|
|
|
|
shr ecx, 1
|
|
|
|
@@:
|
|
|
|
mov al, [esi]
|
|
|
|
mov dl, [edi]
|
|
|
|
mov [edi], al
|
|
|
|
mov [esi], dl
|
|
|
|
mov al, [esi+1]
|
|
|
|
mov dl, [edi+1]
|
|
|
|
mov [edi+1], al
|
|
|
|
mov [esi+1], dl
|
|
|
|
mov al, [esi+2]
|
|
|
|
mov dl, [edi+2]
|
|
|
|
mov [edi+2], al
|
|
|
|
mov [esi+2], dl
|
|
|
|
add esi, 3
|
|
|
|
sub edi, 3
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
pop edi esi ecx
|
|
|
|
add esi, [scanline_len]
|
|
|
|
add edi, [scanline_len]
|
|
|
|
dec ecx
|
|
|
|
jnz .next_line_horz32
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
.exit:
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
2009-01-25 21:12:30 +03:00
|
|
|
pop edi esi ebx
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
xor eax, eax
|
2009-01-25 21:12:30 +03:00
|
|
|
pop edi esi ebx
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? Rotate image ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _img = pointer to image ;;
|
|
|
|
;> _rotate_kind = one of ROTATE_* constants ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
|
|
|
scanline_len_old dd ?
|
|
|
|
scanline_len_new dd ?
|
|
|
|
scanline_pixels_new dd ?
|
|
|
|
line_buffer dd ?
|
|
|
|
pixels_ptr dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
mov [line_buffer], 0
|
|
|
|
|
|
|
|
push ebx esi edi
|
2009-01-25 21:12:30 +03:00
|
|
|
mov ebx, [_img]
|
|
|
|
stdcall img._.validate, ebx
|
2008-03-31 02:31:00 +04:00
|
|
|
or eax, eax
|
|
|
|
jnz .error
|
|
|
|
|
|
|
|
cmp [_rotate_kind], ROTATE_90_CCW
|
|
|
|
je .rotate_ccw_low
|
|
|
|
cmp [_rotate_kind], ROTATE_90_CW
|
|
|
|
je .rotate_cw_low
|
|
|
|
cmp [_rotate_kind], ROTATE_180
|
|
|
|
je .flip
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.rotate_ccw_low:
|
|
|
|
mov eax, [ebx + Image.Height]
|
|
|
|
mov [scanline_pixels_new], eax
|
2009-01-25 21:12:30 +03:00
|
|
|
call img._.get_scanline_len
|
2008-03-31 02:31:00 +04:00
|
|
|
mov [scanline_len_new], eax
|
|
|
|
|
|
|
|
invoke mem.alloc, eax
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
mov [line_buffer], eax
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
mov eax, [ebx + Image.Width]
|
|
|
|
mov ecx, eax
|
|
|
|
call img._.get_scanline_len
|
2008-03-31 02:31:00 +04:00
|
|
|
mov [scanline_len_old], eax
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
imul eax, ecx
|
|
|
|
add eax, [ebx + Image.Data]
|
|
|
|
mov [pixels_ptr], eax
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
cmp [ebx + Image.Type], Image.bpp8
|
|
|
|
jz .rotate_ccw8
|
|
|
|
cmp [ebx + Image.Type], Image.bpp24
|
|
|
|
jz .rotate_ccw24
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
.next_column_ccw_low:
|
|
|
|
dec ecx
|
2009-01-25 21:12:30 +03:00
|
|
|
js .exchange_dims
|
2008-03-31 02:31:00 +04:00
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -4
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [ebx + Image.Data]
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov eax, [esi]
|
|
|
|
stosd
|
|
|
|
add esi, edx
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
lea esi, [edi + 4]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
shr edx, 2
|
|
|
|
@@: mov ecx, edx
|
|
|
|
rep movsd
|
|
|
|
add esi, 4
|
|
|
|
dec eax
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
rep movsd
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_ccw_low
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
.rotate_ccw8:
|
|
|
|
.next_column_ccw_low8:
|
|
|
|
dec ecx
|
|
|
|
js .exchange_dims
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -1
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [ebx + Image.Data]
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov al, [esi]
|
|
|
|
mov [edi], al
|
|
|
|
add esi, edx
|
|
|
|
add edi, 1
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
lea esi, [edi + 1]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
@@: mov ecx, edx
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, edx
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
add esi, 1
|
|
|
|
sub eax, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
mov edx, ecx
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, edx
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_ccw_low8
|
|
|
|
|
|
|
|
.rotate_ccw24:
|
|
|
|
.next_column_ccw_low24:
|
|
|
|
dec ecx
|
|
|
|
js .exchange_dims
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -3
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [ebx + Image.Data]
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov al, [esi]
|
|
|
|
mov [edi], al
|
|
|
|
mov al, [esi+1]
|
|
|
|
mov [edi+1], al
|
|
|
|
mov al, [esi+2]
|
|
|
|
mov [edi+2], al
|
|
|
|
add esi, edx
|
|
|
|
add edi, 3
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
lea esi, [edi + 3]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
@@: mov ecx, edx
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, edx
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
add esi, 3
|
|
|
|
sub eax, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, eax
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, eax
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_ccw_low24
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
.rotate_cw_low:
|
|
|
|
mov eax, [ebx + Image.Height]
|
|
|
|
mov [scanline_pixels_new], eax
|
2009-01-25 21:12:30 +03:00
|
|
|
call img._.get_scanline_len
|
2008-03-31 02:31:00 +04:00
|
|
|
mov [scanline_len_new], eax
|
|
|
|
|
|
|
|
invoke mem.alloc, eax
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
mov [line_buffer], eax
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
mov eax, [ebx + Image.Width]
|
|
|
|
mov ecx, eax
|
|
|
|
call img._.get_scanline_len
|
2008-03-31 02:31:00 +04:00
|
|
|
mov [scanline_len_old], eax
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
imul eax, ecx
|
|
|
|
add eax, [ebx + Image.Data]
|
|
|
|
mov [pixels_ptr], eax
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
cmp [ebx + Image.Type], Image.bpp8
|
|
|
|
jz .rotate_cw8
|
|
|
|
cmp [ebx + Image.Type], Image.bpp24
|
|
|
|
jz .rotate_cw24
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
.next_column_cw_low:
|
|
|
|
dec ecx
|
|
|
|
js .exchange_dims
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -4
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [pixels_ptr]
|
|
|
|
add esi, -4
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov eax, [esi]
|
|
|
|
stosd
|
|
|
|
sub esi, edx
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
dec eax
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
add edi, [scanline_len_old]
|
|
|
|
lea esi, [edi + 4]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
shr edx, 2
|
|
|
|
@@: mov ecx, edx
|
|
|
|
rep movsd
|
|
|
|
add esi, 4
|
|
|
|
dec eax
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
rep movsd
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_cw_low
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
.rotate_cw8:
|
|
|
|
.next_column_cw_low8:
|
|
|
|
dec ecx
|
|
|
|
js .exchange_dims
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -1
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [pixels_ptr]
|
|
|
|
add esi, -1
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov al, [esi]
|
|
|
|
mov [edi], al
|
|
|
|
sub esi, edx
|
|
|
|
add edi, 1
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
dec eax
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
add edi, [scanline_len_old]
|
|
|
|
lea esi, [edi + 1]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
@@: mov ecx, edx
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, edx
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
add esi, 1
|
|
|
|
sub eax, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, eax
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, eax
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_cw_low8
|
|
|
|
|
|
|
|
.rotate_cw24:
|
|
|
|
.next_column_cw_low24:
|
|
|
|
dec ecx
|
|
|
|
js .exchange_dims
|
|
|
|
push ecx
|
|
|
|
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
add [scanline_len_old], -3
|
|
|
|
|
|
|
|
mov ecx, [scanline_pixels_new]
|
|
|
|
mov esi, [pixels_ptr]
|
|
|
|
add esi, -3
|
|
|
|
mov edi, [line_buffer]
|
|
|
|
@@: mov al, [esi]
|
|
|
|
mov [edi], al
|
|
|
|
mov al, [esi+1]
|
|
|
|
mov [edi+1], al
|
|
|
|
mov al, [esi+2]
|
|
|
|
mov [edi+2], al
|
|
|
|
sub esi, edx
|
|
|
|
add edi, 3
|
|
|
|
sub ecx, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_pixels_new]
|
|
|
|
dec eax
|
|
|
|
mov edi, [ebx + Image.Data]
|
|
|
|
add edi, [scanline_len_old]
|
|
|
|
lea esi, [edi + 3]
|
|
|
|
mov edx, [scanline_len_old]
|
|
|
|
@@: mov ecx, edx
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, edx
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
add esi, 3
|
|
|
|
sub eax, 1
|
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov eax, [scanline_len_new]
|
|
|
|
sub [pixels_ptr], eax
|
|
|
|
mov ecx, eax
|
|
|
|
mov esi, [line_buffer]
|
|
|
|
mov edi, [pixels_ptr]
|
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
|
|
|
mov ecx, eax
|
|
|
|
and ecx, 3
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
pop ecx
|
|
|
|
jmp .next_column_cw_low24
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
.flip:
|
|
|
|
jmp .exit
|
|
|
|
|
|
|
|
.exchange_dims:
|
|
|
|
push [ebx + Image.Width] [ebx + Image.Height]
|
|
|
|
pop [ebx + Image.Width] [ebx + Image.Height]
|
|
|
|
|
|
|
|
.exit:
|
|
|
|
invoke mem.free, [line_buffer]
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
|
|
|
|
|
|
|
.error:
|
|
|
|
invoke mem.free, [line_buffer]
|
|
|
|
xor eax, eax
|
|
|
|
pop edi esi ebx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Below are private procs you should never call directly from your code ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 / pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
invoke mem.alloc, sizeof.Image
|
2009-01-25 21:12:30 +03:00
|
|
|
test eax, eax
|
|
|
|
jz @f
|
|
|
|
push ecx
|
|
|
|
xor ecx, ecx
|
|
|
|
mov [eax + Image.Data], ecx
|
|
|
|
mov [eax + Image.Type], ecx
|
|
|
|
mov [eax + Image.Extended], ecx
|
|
|
|
mov [eax + Image.Previous], ecx
|
|
|
|
mov [eax + Image.Next], ecx
|
|
|
|
pop ecx
|
|
|
|
@@:
|
2008-02-08 01:45:15 +03:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
push edx
|
|
|
|
mov edx, [_img]
|
|
|
|
cmp [edx + Image.Data], 0
|
|
|
|
je @f
|
|
|
|
invoke mem.free, [edx + Image.Data]
|
|
|
|
@@: cmp [edx + Image.Extended], 0
|
|
|
|
je @f
|
|
|
|
invoke mem.free, [edx + Image.Extended]
|
|
|
|
@@: invoke mem.free, edx
|
|
|
|
pop edx
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2008-03-31 02:31:00 +04:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img._.resize_data _img, _width, _height ;////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
2009-01-25 21:12:30 +03:00
|
|
|
push ebx esi
|
2008-03-31 02:31:00 +04:00
|
|
|
mov ebx, [_img]
|
|
|
|
mov eax, [_height]
|
2009-01-25 21:12:30 +03:00
|
|
|
; our memory is limited, [_width]*[_height] must not overflow
|
|
|
|
; image with width or height greater than 65535 is most likely bogus
|
|
|
|
cmp word [_width+2], 0
|
|
|
|
jnz .error
|
|
|
|
cmp word [_height+2], 0
|
|
|
|
jnz .error
|
2008-03-31 02:31:00 +04:00
|
|
|
imul eax, [_width]
|
2009-01-25 21:12:30 +03:00
|
|
|
test eax, eax
|
|
|
|
jz .error
|
|
|
|
; do not allow images which require too many memory
|
|
|
|
cmp eax, 4000000h
|
|
|
|
jae .error
|
|
|
|
cmp [ebx + Image.Type], Image.bpp8
|
|
|
|
jz .bpp8
|
|
|
|
cmp [ebx + Image.Type], Image.bpp24
|
|
|
|
jz .bpp24
|
|
|
|
.bpp32:
|
2008-03-31 02:31:00 +04:00
|
|
|
shl eax, 2
|
2009-01-25 21:12:30 +03:00
|
|
|
jmp @f
|
|
|
|
.bpp24:
|
|
|
|
lea eax, [eax*3]
|
|
|
|
jmp @f
|
|
|
|
.bpp8:
|
|
|
|
add eax, 256*4 ; for palette
|
|
|
|
@@:
|
|
|
|
mov esi, eax
|
2008-03-31 02:31:00 +04:00
|
|
|
invoke mem.realloc, [ebx + Image.Data], eax
|
|
|
|
or eax, eax
|
|
|
|
jz .error
|
|
|
|
|
|
|
|
mov [ebx + Image.Data], eax
|
|
|
|
push [_width]
|
|
|
|
pop [ebx + Image.Width]
|
|
|
|
push [_height]
|
|
|
|
pop [ebx + Image.Height]
|
2009-01-25 21:12:30 +03:00
|
|
|
cmp [ebx + Image.Type], Image.bpp8
|
|
|
|
jnz .ret
|
|
|
|
lea esi, [eax + esi - 256*4]
|
|
|
|
mov [ebx + Image.Palette], esi
|
|
|
|
jmp .ret
|
2008-03-31 02:31:00 +04:00
|
|
|
|
|
|
|
.error:
|
2009-01-25 21:12:30 +03:00
|
|
|
xor eax, eax
|
|
|
|
.ret:
|
|
|
|
pop esi ebx
|
2008-03-31 02:31:00 +04:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
;;================================================================================================;;
|
|
|
|
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;? --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> --- TBD --- ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< --- TBD --- ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
cmp [ebx + Image.Type], Image.bpp8
|
|
|
|
jz .bpp8.1
|
|
|
|
cmp [ebx + Image.Type], Image.bpp24
|
|
|
|
jz .bpp24.1
|
|
|
|
shl eax, 2
|
|
|
|
jmp @f
|
|
|
|
.bpp24.1:
|
|
|
|
lea eax, [eax*3]
|
|
|
|
.bpp8.1:
|
|
|
|
@@:
|
|
|
|
ret
|
|
|
|
|
2008-02-08 01:45:15 +03:00
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Below is private data you should never use directly from your code ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
.gif dd img.is.gif, img.decode.gif, img.encode.gif
|
2009-01-31 04:58:27 +03:00
|
|
|
.png dd img.is.png, img.decode.png, img.encode.png
|
2009-01-25 21:12:30 +03:00
|
|
|
.jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
|
2008-02-08 01:45:15 +03:00
|
|
|
dd 0
|
|
|
|
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Exported functions section ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
align 4
|
2008-02-08 01:45:15 +03:00
|
|
|
@EXPORT:
|
|
|
|
|
|
|
|
export \
|
|
|
|
lib_init , 'lib_init' , \
|
2009-01-31 06:30:53 +03:00
|
|
|
0x00010003 , 'version' , \
|
2008-02-08 01:45:15 +03:00
|
|
|
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' , \
|
2009-01-27 02:43:01 +03:00
|
|
|
img.to_rgb2 , 'img.to_rgb2' , \
|
2008-02-08 01:45:15 +03:00
|
|
|
img.decode , 'img.decode' , \
|
|
|
|
img.encode , 'img.encode' , \
|
|
|
|
img.create , 'img.create' , \
|
|
|
|
img.destroy , 'img.destroy' , \
|
2008-03-31 02:31:00 +04:00
|
|
|
img.count , 'img.count' , \
|
2008-02-08 01:45:15 +03:00
|
|
|
img.lock_bits , 'img.lock_bits' , \
|
2008-03-31 02:31:00 +04:00
|
|
|
img.unlock_bits , 'img.unlock_bits' , \
|
|
|
|
img.flip , 'img.flip' , \
|
|
|
|
img.rotate , 'img.rotate'
|
2009-01-25 21:12:30 +03:00
|
|
|
|
2009-01-31 04:58:27 +03:00
|
|
|
; 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, \
|
|
|
|
deflate_unpack2, 'deflate_unpack2'
|
|
|
|
|
|
|
|
; mutex for unpacker loading
|
|
|
|
deflate_loader_mutex dd 0
|
|
|
|
|
2009-01-25 21:12:30 +03:00
|
|
|
section '.data' data readable writable align 16
|
|
|
|
; uninitialized data - global constant tables
|
|
|
|
|
|
|
|
; data for YCbCr -> RGB translation
|
|
|
|
color_table_1 rd 256
|
|
|
|
color_table_2 rd 256
|
|
|
|
color_table_3 rd 256
|
|
|
|
color_table_4 rd 256
|