Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8497 → Rev 8486

/programs/develop/libraries/libs-dev/libimg/libimg.asm
1,25 → 1,21
;;============================================================================;;
;;//// libimg.asm //// (c) mike.dld, 2007-2008 ;;
;; //// (c) diamond, 2009, ;;
;; //// (c) dunkaist, 2011-2020 ;;
;;============================================================================;;
;;================================================================================================;;
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009, (c) dunkaist, 2011-2013 ///////;;
;;================================================================================================;;
;; ;;
;; 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 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. ;;
;; 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/>. ;;
;; 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/>. ;;
;; ;;
;;============================================================================;;
;;================================================================================================;;
 
 
format MS COFF
62,18 → 58,18
; SSE | a bit faster, but may be unsupported by some CPUs
include 'blend.asm'
 
;;============================================================================;;
proc lib_init ;///////////////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
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
94,24 → 90,22
mov dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
@@:
 
.ok:
xor eax, eax
.ok: xor eax,eax
ret
endp
 
;;============================================================================;;
proc img.is_img _data, _length ;//////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;;
;;============================================================================;;
;;================================================================================================;;
push ebx
mov ebx, img.formats_table
@@:
stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
@@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
or eax, eax
jnz @f
add ebx, sizeof.FormatsTableEntry
118,33 → 112,32
cmp dword[ebx], 0
jnz @b
xor eax, eax
@@:
pop ebx
@@: pop ebx
ret
endp
 
;;============================================================================;;
proc img.info _data, _length ;////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;;
;;============================================================================;;
;;================================================================================================;;
xor eax, eax
ret
endp
 
;;============================================================================;;
proc img.from_file _filename ;////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? load file from disk and decode it ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> [_filename] = file name as passed to libio ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;============================================================================;;
;;================================================================================================;;
locals
fd dd ?
img_data_len dd ?
184,42 → 177,42
ret
endp
 
;;============================================================================;;
proc img.to_file _img, _filename ;////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
xor eax, eax
ret
endp
 
;;============================================================================;;
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;============================================================================;;
;;================================================================================================;;
xor eax, eax
ret
endp
 
;;============================================================================;;
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? decodes image data into RGB triplets and stores them where [_out] points to;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to source image ;;
;> [_out] = where to store RGB triplets ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;============================================================================;;
;;================================================================================================;;
push esi edi
mov esi, [_img]
stdcall img._.validate, esi
232,19 → 225,18
ret
endp
 
;;============================================================================;;
proc img.to_rgb _img ;////////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;? decodes image data into RGB triplets and returns pointer to memory area of ;;
;? following structure: ;;
;;================================================================================================;;
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? 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 ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets) ;;
;;============================================================================;;
;;================================================================================================;;
push esi edi
mov esi, [_img]
stdcall img._.validate, esi
276,16 → 268,16
ret
endp
 
;;============================================================================;;
proc img._.do_rgb ;///////////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi] ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> esi = pointer to source image ;;
;> edi = pointer to memory to store RGB triplets ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< none ;;
;;============================================================================;;
;;================================================================================================;;
mov ecx, [esi + Image.Width]
imul ecx, [esi + Image.Height]
mov eax, [esi + Image.Type]
716,24 → 708,23
 
endp
 
;;============================================================================;;
proc img.decode _data, _length, _options ;////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? decodes loaded into memory graphic file ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> [_data] = pointer to file in memory ;;
;> [_length] = size in bytes of memory area pointed to by [_data] ;;
;> [_options] = 0 / pointer to the structure of additional options ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;============================================================================;;
;;================================================================================================;;
push ebx
mov ebx, [_length]
or ebx, ebx
jz .fail
mov ebx, img.formats_table
@@:
stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
@@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
or eax, eax
jnz @f
add ebx, sizeof.FormatsTableEntry
743,40 → 734,34
xor eax, eax
pop ebx
ret
@@:
mov eax, [ebx + FormatsTableEntry.Decode]
@@: mov eax, [ebx + FormatsTableEntry.Decode]
pop ebx
leave
jmp eax
endp
 
;;============================================================================;;
proc img.encode uses ebx, _img, _common, _specific ;//////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.encode uses ebx, _img, _common, _specific ;////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? encode image to some format ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to input image ;;
;> [_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) ;;
; 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. 0 here will be ignored if ;;
; particular compression algorithm is specified ;;
; this option may be ignored if any format specific options are defined ;;
; 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 ;;
; 0x01 : return an error if format specific conditions cannot be met ;;
; 0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on ;;
; 0x04 : delete alpha channel, if any ;;
; 0x08 : flush alpha channel with 0xff, if any; add it if ;;
; none ;;
; 0x08 : flush alpha channel with 0xff, if any; add it if none ;;
; 0x03 : byte : reserved, must be 0 ;;
;> [_specific] = 0 / pointer to the structure of format specific options ;;
; see <format_name>.inc for description ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to encoded data ;;
;< ecx = error code / the size of encoded data ;;
; 1 : out of memory ;;
783,7 → 768,7
; 2 : format is not supported ;;
; 3 : specific conditions cannot be satisfied ;;
; 4 : bit depth cannot be preserved ;;
;;============================================================================;;
;;================================================================================================;;
mov ebx, [_img]
 
movzx eax, byte[_common]
845,17 → 830,17
ret
endp
 
;;============================================================================;;
proc img.create _width, _height, _type ;//////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? creates an Image structure and initializes some its fields ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> [_width] = width of an image in pixels ;;
;> [_height] = height of an image in pixels ;;
;> [_type] = one of the Image.bppN constants from libimg.inc ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;============================================================================;;
;;================================================================================================;;
push ecx
 
stdcall img._.new
885,17 → 870,16
ret
endp
 
;;============================================================================;;
proc img.destroy.layer _img ;/////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;? Frees memory occupied by an image and all the memory regions its fields ;;
;? point to. For image sequences deletes only one frame and fixes Previous/ ;;
;? Next pointers. ;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? frees memory occupied by an image and all the memory regions its fields point to ;;
;? for image sequences deletes only one frame and fixes Previous/Next pointers ;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (fail) / 1 (success) ;;
;;============================================================================;;
;;================================================================================================;;
mov eax, [_img]
mov edx, [eax + Image.Previous]
test edx, edx
913,17 → 897,16
ret
endp
 
;;============================================================================;;
proc img.destroy _img ;///////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;? Frees memory occupied by an image and all the memory regions its fields ;;
;? point to. Follows Previous/Next pointers and deletes all the images in ;;
;? sequence. ;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? frees memory occupied by an image and all the memory regions its fields point to ;;
;? follows Previous/Next pointers and deletes all the images in sequence ;;
;;------------------------------------------------------------------------------------------------;;
;> [_img] = pointer to image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (fail) / 1 (success) ;;
;;============================================================================;;
;;================================================================================================;;
push 1
mov eax, [_img]
mov eax, [eax + Image.Previous]
954,15 → 937,15
ret
endp
 
;;============================================================================;;
proc img.count _img ;/////////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.count _img ;/////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Get number of images in the list (e.g. in animated GIF file) ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = -1 (fail) / >0 (ok) ;;
;;============================================================================;;
;;================================================================================================;;
push ecx edx
mov edx, [_img]
stdcall img._.validate, edx
969,17 → 952,14
or eax, eax
jnz .error
 
@@:
mov eax, [edx + Image.Previous]
@@: mov eax, [edx + Image.Previous]
or eax, eax
jz @f
mov edx, eax
jmp @b
 
@@:
xor ecx, ecx
@@:
inc ecx
@@: xor ecx, ecx
@@: inc ecx
mov eax, [edx + Image.Next]
or eax, eax
jz .exit
997,44 → 977,44
ret
endp
 
;;//// image processing //////////////////////////////////////////////////////;;
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
 
;;============================================================================;;
proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
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 ;////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
xor eax, eax
ret
endp
 
;;============================================================================;;
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Flip image layer ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;> _flip_kind = one of FLIP_* constants ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
locals
scanline_len dd ?
endl
1116,8 → 1096,7
 
mov ecx, [scanline_len]
shr ecx, 3
@@:
mov eax, [esi]
@@: mov eax, [esi]
xchg eax, [edi]
mov [esi], eax
add esi, 4
1138,8 → 1117,7
push ecx esi edi
 
mov ecx, [ebx + Image.Width]
@@:
mov ax, [esi]
@@: mov ax, [esi]
mov dx, [edi]
mov [edi], ax
mov [esi], dx
1162,8 → 1140,7
 
mov ecx, [scanline_len]
shr ecx, 1
@@:
mov al, [esi]
@@: mov al, [esi]
mov dl, [edi]
mov [edi], al
mov [esi], dl
1403,16 → 1380,16
ret
endp
 
;;============================================================================;;
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Flip all layers of image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;> _flip_kind = one of FLIP_* constants ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
push 1
mov ebx, [_img]
@@:
1434,16 → 1411,16
ret
endp
 
;;============================================================================;;
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Rotate image layer ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;> _rotate_kind = one of ROTATE_* constants ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
locals
scanline_len_old dd ?
scanline_len_new dd ?
1515,8 → 1492,7
mov ecx, [scanline_pixels_new]
mov esi, [ebx + Image.Data]
mov edi, [line_buffer]
@@:
mov ax, [esi]
@@: mov ax, [esi]
mov [edi], ax
add esi, edx
add edi, 2
1527,8 → 1503,7
mov edi, [ebx + Image.Data]
lea esi, [edi + 2]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
1565,8 → 1540,7
mov ecx, [scanline_pixels_new]
mov esi, [ebx + Image.Data]
mov edi, [line_buffer]
@@:
mov eax, [esi]
@@: mov eax, [esi]
stosd
add esi, edx
dec ecx
1577,8 → 1551,7
lea esi, [edi + 4]
mov edx, [scanline_len_old]
shr edx, 2
@@:
mov ecx, edx
@@: mov ecx, edx
rep movsd
add esi, 4
dec eax
1606,8 → 1579,7
mov ecx, [scanline_pixels_new]
mov esi, [ebx + Image.Data]
mov edi, [line_buffer]
@@:
mov al, [esi]
@@: mov al, [esi]
mov [edi], al
add esi, edx
add edi, 1
1618,8 → 1590,7
mov edi, [ebx + Image.Data]
lea esi, [edi + 1]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
1656,8 → 1627,7
mov ecx, [scanline_pixels_new]
mov esi, [ebx + Image.Data]
mov edi, [line_buffer]
@@:
mov al, [esi]
@@: mov al, [esi]
mov [edi], al
mov al, [esi+1]
mov [edi+1], al
1672,8 → 1642,7
mov edi, [ebx + Image.Data]
lea esi, [edi + 3]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
1973,8 → 1942,7
mov esi, [pixels_ptr]
add esi, -2
mov edi, [line_buffer]
@@:
mov ax, [esi]
@@: mov ax, [esi]
mov [edi], ax
sub esi, edx
add edi, 2
1987,8 → 1955,7
add edi, [scanline_len_old]
lea esi, [edi + 2]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
2025,8 → 1992,7
mov esi, [pixels_ptr]
add esi, -4
mov edi, [line_buffer]
@@:
mov eax, [esi]
@@: mov eax, [esi]
stosd
sub esi, edx
dec ecx
2039,8 → 2005,7
lea esi, [edi + 4]
mov edx, [scanline_len_old]
shr edx, 2
@@:
mov ecx, edx
@@: mov ecx, edx
rep movsd
add esi, 4
dec eax
2069,8 → 2034,7
mov esi, [pixels_ptr]
add esi, -1
mov edi, [line_buffer]
@@:
mov al, [esi]
@@: mov al, [esi]
mov [edi], al
sub esi, edx
add edi, 1
2083,8 → 2047,7
add edi, [scanline_len_old]
lea esi, [edi + 1]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
2121,8 → 2084,7
mov esi, [pixels_ptr]
add esi, -3
mov edi, [line_buffer]
@@:
mov al, [esi]
@@: mov al, [esi]
mov [edi], al
mov al, [esi+1]
mov [edi+1], al
2139,8 → 2101,7
add edi, [scanline_len_old]
lea esi, [edi + 3]
mov edx, [scanline_len_old]
@@:
mov ecx, edx
@@: mov ecx, edx
shr ecx, 2
rep movsd
mov ecx, edx
2413,16 → 2374,16
ret
endp
 
;;============================================================================;;
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Rotate all layers of image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;> _rotate_kind = one of ROTATE_* constants ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = false / true ;;
;;============================================================================;;
;;================================================================================================;;
push 1
mov ebx, [_img]
@@:
2444,11 → 2405,11
ret
endp
 
;;============================================================================;;
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Draw image in the window ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;>_x = x-coordinate in the window ;;
;>_y = y-coordinate in the window ;;
2456,9 → 2417,9
;>_height = maximum height to draw ;;
;>_xpos = offset in image by x-axis ;;
;>_ypos = offset in image by y-axis ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< no return value ;;
;;============================================================================;;
;;================================================================================================;;
push ebx esi edi
mov ebx, [_img]
stdcall img._.validate, ebx
2526,37 → 2487,37
.z80 dd LIBIMG_FORMAT_Z80, img.is.z80, img.decode.z80, img.encode.z80, 0 ;this must be the last entry as there are no signatures in z80 screens at all
dd 0
 
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;! Below are private procs you should never call directly from your code ;;
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
 
 
;;============================================================================;;
proc img._.validate, _img ;///////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< --- TBD --- ;;
;;============================================================================;;
;;================================================================================================;;
xor eax, eax
ret
endp
 
;;============================================================================;;
proc img._.new ;//////////////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> --- TBD --- ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 / pointer to image ;;
;;============================================================================;;
;;================================================================================================;;
invoke mem.alloc, sizeof.Image
test eax, eax
jz @f
2573,44 → 2534,41
ret
endp
 
;;============================================================================;;
proc img._.delete _img ;//////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
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
@@: cmp [edx + Image.Extended], 0
je @f
invoke mem.free, [edx + Image.Extended]
@@:
invoke mem.free, edx
@@: invoke mem.free, edx
pop edx
ret
endp
 
;;============================================================================;;
proc img.resize_data _img, _width, _height ;//////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;? Resize data block of image. New size is calculated from _width and _height ;;
;? params and internal Image.Type value. All the internal fields are updated ;;
;? iff succeeded. This function does not scale images, use img.scale if you ;;
;? need to. ;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
proc img.resize_data _img, _width, _height ;//////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Resize data block of image. New size is calculated from _width and _height params and internal ;;
;? Image.Type value. All the internal fields are updated iff succeeded. ;;
;? This function does not scale images, use img.scale if you need to. ;;
;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;;
;> _width = new width ;;
;> _height = new height ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = 0 (fail) / pointer to the new pixels data ;;
;;============================================================================;;
;;================================================================================================;;
push ebx esi
mov ebx, [_img]
mov eax, [_height]
2740,16 → 2698,16
ret
endp
 
;;============================================================================;;
img._.get_scanline_len: ;/////////////////////////////////////////////////////;;
;;----------------------------------------------------------------------------;;
;;================================================================================================;;
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
;? Get scanline length of image in bytes ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;> eax = width of image in pixels ;;
;> ebx = image ;;
;;----------------------------------------------------------------------------;;
;;------------------------------------------------------------------------------------------------;;
;< eax = scanline length in bytes ;;
;;============================================================================;;
;;================================================================================================;;
cmp [ebx + Image.Type], Image.bpp1
jz .bpp1.1
cmp [ebx + Image.Type], Image.bpp2i
2791,13 → 2749,13
ret
 
 
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;! Below is private data you should never use directly from your code ;;
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
 
section '.data' data readable writable align 16
;include_debug_strings
2826,13 → 2784,13
dd img.flip.layer.bpp2i_horz
dd img.flip.layer.bpp4i_horz
 
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
;! Exported functions section ;;
;;============================================================================;;
;;////////////////////////////////////////////////////////////////////////////;;
;;============================================================================;;
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
 
 
align 4