Libs-dev: libio, libini, libgfx, libimg
git-svn-id: svn://kolibrios.org@717 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
719
programs/develop/libraries/libs-dev/libimg/bmp/bmp.asm
Normal file
719
programs/develop/libraries/libs-dev/libimg/bmp/bmp.asm
Normal file
@@ -0,0 +1,719 @@
|
||||
;;================================================================================================;;
|
||||
;;//// bmp.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; References: ;;
|
||||
;; 1. "Microsoft Windows Bitmap File Format Summary" ;;
|
||||
;; from "Encyclopedia of Graphics File Formats" by O'Reilly ;;
|
||||
;; http://www.fileformat.info/format/bmp/ ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
include 'bmp.inc'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.is.bmp _data, _length ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Determine if raw data could be decoded (is in BMP format) ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
cmp [_length], 2
|
||||
jb .nope
|
||||
mov eax, [_data]
|
||||
cmp word[eax], 'BM'
|
||||
je .yep
|
||||
|
||||
.nope:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
.yep:
|
||||
xor eax,eax
|
||||
inc eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp _data, _length ;//////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Decode data into image if it contains correctly formed raw data in BMP format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
img dd ?
|
||||
endl
|
||||
|
||||
push ebx
|
||||
|
||||
stdcall img.is.bmp, [_data], [_length]
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
mov ebx, [_data]
|
||||
; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB
|
||||
; je @f
|
||||
; mov eax, [ebx + bmp.Header.file.Size]
|
||||
; cmp eax, [_length]
|
||||
; jne .error
|
||||
|
||||
@@: stdcall img.create, [ebx + bmp.Header.info.Width], [ebx + bmp.Header.info.Height]
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [img], eax
|
||||
mov edx, eax
|
||||
|
||||
invoke mem.alloc, sizeof.bmp.Image
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [edx + Image.Extended], eax
|
||||
mov esi, ebx
|
||||
add esi, sizeof.bmp.FileHeader
|
||||
mov edi, eax
|
||||
mov ecx, sizeof.bmp.InfoHeader
|
||||
rep movsb
|
||||
|
||||
mov eax, [ebx + bmp.Header.info.Compression]
|
||||
cmp eax, bmp.BI_RGB
|
||||
jne @f
|
||||
stdcall ._.rgb
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_RLE8
|
||||
jne @f
|
||||
stdcall ._.rle
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_RLE4
|
||||
jne @f
|
||||
stdcall ._.rle
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_BITFIELDS
|
||||
jne @f
|
||||
stdcall ._.bitfields
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_JPEG
|
||||
jne @f
|
||||
stdcall ._.jpeg
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_PNG
|
||||
jne .error
|
||||
stdcall ._.png
|
||||
|
||||
.decoded:
|
||||
or eax, eax
|
||||
jz @f
|
||||
stdcall img.destroy, [img]
|
||||
jmp .error
|
||||
|
||||
@@: stdcall img.flip, [img], FLIP_VERTICAL
|
||||
mov eax, [img]
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.encode.bmp _img, _p_length ;/////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Encode image into raw data in BMP format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to encoded data ;;
|
||||
;< _p_length = encoded data length ;;
|
||||
;;================================================================================================;;
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below are private procs you should never call directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.rgb ;///////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
mov ecx, [edx + Image.Extended]
|
||||
mov [ecx + bmp.Image.info.AlphaMask], 0
|
||||
mov edi, [edx + Image.Data]
|
||||
|
||||
movzx eax, [ebx + bmp.Header.info.BitCount]
|
||||
cmp eax, 32
|
||||
je .32bpp
|
||||
cmp eax, 24
|
||||
je .24bpp
|
||||
cmp eax, 16
|
||||
je .16bpp
|
||||
cmp eax, 8
|
||||
je .8bpp
|
||||
cmp eax, 4
|
||||
je .4bpp
|
||||
cmp eax, 1
|
||||
je .1bpp
|
||||
jmp .error
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.32bpp:
|
||||
mov [ecx + bmp.Image.info.RedMask], 00000000111111110000000000000000b ; 8-0-0
|
||||
mov [ecx + bmp.Image.info.GreenMask], 00000000000000001111111100000000b ; 0-8-0
|
||||
mov [ecx + bmp.Image.info.BlueMask], 00000000000000000000000011111111b ; 0-0-8
|
||||
stdcall img.decode.bmp._.bitfields
|
||||
ret
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.24bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
xor edx, edx
|
||||
|
||||
.next_line_pixel:
|
||||
movsd
|
||||
dec esi
|
||||
inc edx
|
||||
dec ecx
|
||||
jnz .next_line_pixel
|
||||
|
||||
and edx, 0x03
|
||||
add esi, edx
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
jmp img.decode.bmp._.rgb.exit
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.16bpp:
|
||||
mov [ecx + bmp.Image.info.RedMask], 00000000000000000111110000000000b ; 5-0-0
|
||||
mov [ecx + bmp.Image.info.GreenMask], 00000000000000000000001111100000b ; 0-5-0
|
||||
mov [ecx + bmp.Image.info.BlueMask], 00000000000000000000000000011111b ; 0-0-5
|
||||
stdcall img.decode.bmp._.bitfields
|
||||
ret
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.8bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
|
||||
.next_line_dword:
|
||||
lodsb
|
||||
and eax, 0x000000FF
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
dec ecx
|
||||
jnz .next_line_dword
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
jmp img.decode.bmp._.rgb.exit
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.4bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
|
||||
.next_line_dword:
|
||||
push ecx
|
||||
lodsd
|
||||
bswap eax
|
||||
xchg edx, eax
|
||||
mov ecx, 32 / 4
|
||||
|
||||
.next_pixel:
|
||||
rol edx, 4
|
||||
mov al, dl
|
||||
and eax, 0x0000000F
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
dec dword[esp]
|
||||
jz @f
|
||||
dec ecx
|
||||
jnz .next_pixel
|
||||
|
||||
@@: pop ecx
|
||||
or ecx, ecx
|
||||
jnz .next_line_dword
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
jmp img.decode.bmp._.rgb.exit
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.1bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
|
||||
.next_line_dword:
|
||||
push ecx
|
||||
lodsd
|
||||
bswap eax
|
||||
xchg edx, eax
|
||||
mov ecx, 32 / 1
|
||||
|
||||
.next_pixel:
|
||||
rol edx, 1
|
||||
mov al, dl
|
||||
and eax, 0x00000001
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
dec dword[esp]
|
||||
jz @f
|
||||
dec ecx
|
||||
jnz .next_pixel
|
||||
|
||||
@@: pop ecx
|
||||
or ecx, ecx
|
||||
jnz .next_line_dword
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
jmp img.decode.bmp._.rgb.exit
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.exit:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
img.decode.bmp._.rgb.error:
|
||||
or eax, -1
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.rle ;///////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
scanline_len dd ?
|
||||
marker_x dd ?
|
||||
marker_y dd ?
|
||||
abs_mode_addr dd ?
|
||||
enc_mode_addr dd ?
|
||||
endl
|
||||
|
||||
mov edi, [edx + Image.Data]
|
||||
|
||||
mov [abs_mode_addr], .absolute_mode.rle8
|
||||
mov [enc_mode_addr], .encoded_mode.rle8
|
||||
cmp [ebx + bmp.Header.info.Compression], bmp.BI_RLE4
|
||||
jne @f
|
||||
mov [abs_mode_addr], .absolute_mode.rle4
|
||||
mov [enc_mode_addr], .encoded_mode.rle4
|
||||
|
||||
@@: mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov eax, [edx + Image.Width]
|
||||
shl eax, 2
|
||||
mov [scanline_len], eax
|
||||
xor eax, eax
|
||||
mov [marker_x], eax
|
||||
mov [marker_y], eax
|
||||
|
||||
.next_run:
|
||||
xor eax, eax
|
||||
lodsb
|
||||
or al, al
|
||||
jz .escape_mode
|
||||
jmp [enc_mode_addr]
|
||||
|
||||
.escape_mode:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
je .end_of_scanline
|
||||
cmp al, 1
|
||||
je .exit
|
||||
cmp al, 2
|
||||
je .offset_marker
|
||||
jmp [abs_mode_addr]
|
||||
|
||||
.end_of_scanline: ; 0
|
||||
mov eax, [marker_x]
|
||||
shl eax, 2
|
||||
neg eax
|
||||
add eax, [scanline_len]
|
||||
add edi, eax
|
||||
mov [marker_x], 0
|
||||
inc [marker_y]
|
||||
jmp .next_run
|
||||
|
||||
.offset_marker: ; 2: dx, dy
|
||||
lodsb
|
||||
mov edx, [marker_x]
|
||||
add edx, eax
|
||||
cmp edx, [ebx + bmp.Header.info.Width]
|
||||
jae .exit
|
||||
mov [marker_x], edx
|
||||
shl eax, 2
|
||||
add edi, eax
|
||||
lodsb
|
||||
and eax, 0x0FF
|
||||
mov edx, [marker_y]
|
||||
add edx, eax
|
||||
cmp edx, [ebx + bmp.Header.info.Height]
|
||||
jae .exit
|
||||
mov [marker_y], edx
|
||||
imul eax, [scanline_len]
|
||||
add edi, eax
|
||||
jmp .next_run
|
||||
|
||||
.encoded_mode.rle8: ; N: b1 * N
|
||||
mov edx, eax
|
||||
lodsb
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
@@: dec edx
|
||||
js .fix_marker
|
||||
stosd
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
|
||||
.absolute_mode.rle8: ; N: b1 .. bN
|
||||
mov edx, eax
|
||||
push eax
|
||||
@@: dec edx
|
||||
js @f
|
||||
lodsb
|
||||
and eax, 0x0FF
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
@@: pop eax
|
||||
test eax, 1
|
||||
jz .fix_marker
|
||||
inc esi
|
||||
jmp .fix_marker
|
||||
|
||||
.encoded_mode.rle4: ; N: b1 * N
|
||||
mov edx, eax
|
||||
lodsb
|
||||
mov ecx, eax
|
||||
shr ecx, 4
|
||||
mov ecx, [ebx + ecx * 4 + bmp.Header.info.Palette]
|
||||
and eax, 0x00F
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
@@: dec edx
|
||||
js .fix_marker
|
||||
test edx, 1
|
||||
jz .odd
|
||||
mov [edi], ecx
|
||||
add edi, 4
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
.odd:
|
||||
stosd
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
|
||||
.absolute_mode.rle4: ; N: b1 .. bN
|
||||
mov edx, eax
|
||||
push eax
|
||||
@@: dec edx
|
||||
js @f
|
||||
lodsb
|
||||
and eax, 0x0FF
|
||||
mov ecx, eax
|
||||
shr eax, 4
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
inc [marker_x]
|
||||
dec edx
|
||||
js @f
|
||||
mov eax, ecx
|
||||
and eax, 0x00F
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
@@: pop eax
|
||||
and eax, 0x03
|
||||
jz .fix_marker
|
||||
cmp eax, 3
|
||||
je .fix_marker
|
||||
inc esi
|
||||
jmp .fix_marker
|
||||
|
||||
.fix_marker:
|
||||
mov eax, [marker_x]
|
||||
@@: sub eax, [ebx + bmp.Header.info.Width]
|
||||
jle .next_run
|
||||
mov [marker_x], eax
|
||||
inc [marker_y]
|
||||
jmp @b
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
.error:
|
||||
or eax, -1
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.bitfields ;/////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
shift bmp.RgbByteQuad
|
||||
unshift bmp.RgbByteQuad
|
||||
mask bmp.RgbQuad
|
||||
delta dd ?
|
||||
endl
|
||||
|
||||
push esi edi
|
||||
mov esi, [edx + Image.Extended]
|
||||
|
||||
mov ecx, [esi + bmp.Image.info.RedMask]
|
||||
call .calc_shift
|
||||
mov [shift.Red], al
|
||||
mov [mask.Red], ecx
|
||||
call .calc_unshift
|
||||
mov [unshift.Red], al
|
||||
mov ecx, [esi + bmp.Image.info.GreenMask]
|
||||
call .calc_shift
|
||||
mov [shift.Green], al
|
||||
mov [unshift.Green], al
|
||||
mov [mask.Green], ecx
|
||||
call .calc_unshift
|
||||
mov [unshift.Green], al
|
||||
mov ecx, [esi + bmp.Image.info.BlueMask]
|
||||
call .calc_shift
|
||||
mov [shift.Blue], al
|
||||
mov [unshift.Blue], al
|
||||
mov [mask.Blue], ecx
|
||||
call .calc_unshift
|
||||
mov [unshift.Blue], al
|
||||
mov ecx, [esi + bmp.Image.info.AlphaMask]
|
||||
call .calc_shift
|
||||
mov [shift.Alpha], al
|
||||
mov [unshift.Alpha], al
|
||||
mov [mask.Alpha], ecx
|
||||
call .calc_unshift
|
||||
mov [unshift.Alpha], al
|
||||
|
||||
mov edi, [edx + Image.Data]
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
|
||||
mov [delta], 4
|
||||
movzx eax, [ebx + bmp.Header.info.BitCount]
|
||||
cmp eax, 32
|
||||
je @f
|
||||
cmp eax, 16
|
||||
jne .error
|
||||
mov [delta], 2
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
@@: mov ecx, [edx + Image.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [edx + Image.Width]
|
||||
|
||||
.next_pixel:
|
||||
push ecx
|
||||
|
||||
mov eax, [esi]
|
||||
mov cl, [shift.Blue]
|
||||
shr eax, cl
|
||||
and eax, [mask.Blue]
|
||||
mov cl, [unshift.Blue]
|
||||
shl eax, cl
|
||||
stosb
|
||||
|
||||
mov eax, [esi]
|
||||
mov cl, [shift.Green]
|
||||
shr eax, cl
|
||||
and eax, [mask.Green]
|
||||
mov cl, [unshift.Green]
|
||||
shl eax, cl
|
||||
stosb
|
||||
|
||||
mov eax, [esi]
|
||||
mov cl, [shift.Red]
|
||||
shr eax, cl
|
||||
and eax, [mask.Red]
|
||||
mov cl, [unshift.Red]
|
||||
shl eax, cl
|
||||
stosb
|
||||
|
||||
mov eax, [esi]
|
||||
mov cl, [shift.Alpha]
|
||||
shr eax, cl
|
||||
and eax, [mask.Alpha]
|
||||
mov cl, [unshift.Alpha]
|
||||
shl eax, cl
|
||||
stosb
|
||||
|
||||
add esi, [delta]
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_pixel
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.error:
|
||||
or eax, -1
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.calc_shift:
|
||||
xor eax, eax
|
||||
or ecx, ecx
|
||||
jnz @f
|
||||
retn
|
||||
@@: test ecx, 1
|
||||
jnz @f
|
||||
.zz: shr ecx, 1
|
||||
inc eax
|
||||
jmp @b
|
||||
@@: test ecx, 0100000000b
|
||||
jnz .zz
|
||||
retn
|
||||
.calc_unshift:
|
||||
xor eax, eax
|
||||
or ecx, ecx
|
||||
jnz @f
|
||||
retn
|
||||
@@: test ecx, 1
|
||||
jz @f
|
||||
shr ecx, 1
|
||||
inc eax
|
||||
jmp @b
|
||||
@@: sub eax, 8
|
||||
neg eax
|
||||
retn
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.png ;///////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below is private data you should never use directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
;
|
97
programs/develop/libraries/libs-dev/libimg/bmp/bmp.inc
Normal file
97
programs/develop/libraries/libs-dev/libimg/bmp/bmp.inc
Normal file
@@ -0,0 +1,97 @@
|
||||
;;================================================================================================;;
|
||||
;;//// bmp.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
struct bmp.FileHeader
|
||||
Type dw ? ; File type, always 4D42h ("BM")
|
||||
Size dd ? ; Size of the file in bytes
|
||||
dw 2 dup(?) ; Reserved; must be set to zero.
|
||||
OffBits dd ? ; Starting position of image data in bytes
|
||||
ends
|
||||
|
||||
struct bmp.InfoHeader
|
||||
; v2 (Windows 2.x)
|
||||
Size dd ? ; Size of this header in bytes
|
||||
Width dd ? ; Image width in pixels
|
||||
Height dd ? ; Image height in pixels
|
||||
Planes dw ? ; Number of color planes
|
||||
BitCount dw ? ; Number of bits per pixel
|
||||
; v3 (Windows 3.x)
|
||||
Compression dd ? ; Compression method used
|
||||
SizeImage dd ? ; Size of bitmap in bytes
|
||||
XPelsPerMeter dd ? ; Horizontal resolution in pixels per meter
|
||||
YPelsPerMeter dd ? ; Vertical resolution in pixels per meter
|
||||
ClrUsed dd ? ; Number of colors in the image
|
||||
ClrImportant dd ? ; Minimum number of important colors
|
||||
union
|
||||
Palette dd ? ; Image palette if BitCount in [1,4,8]
|
||||
; v4 (Windows 95)
|
||||
struct
|
||||
RedMask dd ? ; Mask identifying bits of red component
|
||||
GreenMask dd ? ; Mask identifying bits of green component
|
||||
BlueMask dd ? ; Mask identifying bits of blue component
|
||||
AlphaMask dd ? ; Mask identifying bits of alpha component
|
||||
CSType dd ? ; Color space type
|
||||
RedX dd ? ; X coordinate of red endpoint
|
||||
RedY dd ? ; Y coordinate of red endpoint
|
||||
RedZ dd ? ; Z coordinate of red endpoint
|
||||
GreenX dd ? ; X coordinate of green endpoint
|
||||
GreenY dd ? ; Y coordinate of green endpoint
|
||||
GreenZ dd ? ; Z coordinate of green endpoint
|
||||
BlueX dd ? ; X coordinate of blue endpoint
|
||||
BlueY dd ? ; Y coordinate of blue endpoint
|
||||
BlueZ dd ? ; Z coordinate of blue endpoint
|
||||
GammaRed dd ? ; Gamma red coordinate scale value
|
||||
GammaGreen dd ? ; Gamma green coordinate scale value
|
||||
GammaBlue dd ? ; Gamma blue coordinate scale value
|
||||
ends
|
||||
ends
|
||||
ends
|
||||
|
||||
define bmp.BI_RGB 0
|
||||
define bmp.BI_RLE8 1
|
||||
define bmp.BI_RLE4 2
|
||||
define bmp.BI_BITFIELDS 3
|
||||
define bmp.BI_JPEG 4
|
||||
define bmp.BI_PNG 5
|
||||
|
||||
struct bmp.Header
|
||||
file bmp.FileHeader
|
||||
info bmp.InfoHeader
|
||||
ends
|
||||
|
||||
struct bmp.RgbByteQuad
|
||||
Red db ?
|
||||
Green db ?
|
||||
Blue db ?
|
||||
Alpha db ?
|
||||
ends
|
||||
|
||||
struct bmp.RgbQuad
|
||||
Red dd ?
|
||||
Green dd ?
|
||||
Blue dd ?
|
||||
Alpha dd ?
|
||||
ends
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
struct bmp.Image
|
||||
info bmp.InfoHeader
|
||||
ends
|
25
programs/develop/libraries/libs-dev/libimg/bmp/ico.asm
Normal file
25
programs/develop/libraries/libs-dev/libimg/bmp/ico.asm
Normal file
@@ -0,0 +1,25 @@
|
||||
;;================================================================================================;;
|
||||
;;//// ico.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; References: ;;
|
||||
;; 1. "Icons in Win32" ;;
|
||||
;; by John Hornick, Microsoft Corporation ;;
|
||||
;; http://msdn2.microsoft.com/en-us/library/ms997538.aspx ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
564
programs/develop/libraries/libs-dev/libimg/gif/gif.asm
Normal file
564
programs/develop/libraries/libs-dev/libimg/gif/gif.asm
Normal file
@@ -0,0 +1,564 @@
|
||||
;;================================================================================================;;
|
||||
;;//// gif.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;;//// Partial (c) by Willow, Diamond and HidnPlayr //////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; References: ;;
|
||||
;; 1. GIF LITE v3.0 (2004-2007) ;;
|
||||
;; by Willow and Diamond ;;
|
||||
;; svn://kolibrios.org/programs/media/gifview/trunk/gif_lite.inc ;;
|
||||
;; 2. "GIF File Format Summary" ;;
|
||||
;; from "Encyclopedia of Graphics File Formats" by O'Reilly ;;
|
||||
;; http://www.fileformat.info/format/gif/ ;;
|
||||
;; 3. "LZW and GIF explained" (1987) ;;
|
||||
;; by Steve Blackstock, IEEE ;;
|
||||
;; http://www.cis.udel.edu/~amer/CISC651/lzw.and.gif.explained.html ;;
|
||||
;; 4. "Graphics Interchange Format (tm)" (June 15, 1987) ;;
|
||||
;; by CompuServe Incorporated ;;
|
||||
;; http://examples.oreilly.de/english_examples/gff/CDROM/GFF/VENDSPEC/GIF/GIF87A.TXT ;;
|
||||
;; 5. "Graphics Interchange Format (sm)" (July 31, 1990) ;;
|
||||
;; by CompuServe Incorporated ;;
|
||||
;; http://examples.oreilly.de/english_examples/gff/CDROM/GFF/VENDSPEC/GIF/GIF89A.TXT ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
include 'gif.inc'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.is.gif _data, _length ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Determine if raw data could be decoded (is in GIF format) ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
cmp [_length], 6
|
||||
jb .nope
|
||||
mov eax, [_data]
|
||||
cmp dword[eax], 'GIF8'
|
||||
jne .nope
|
||||
cmp word[eax + 4], '7a'
|
||||
je .yep
|
||||
cmp word[eax + 4], '9a'
|
||||
je .yep
|
||||
|
||||
.nope:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
.yep:
|
||||
xor eax, eax
|
||||
inc eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.gif _data, _length ;//////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Decode data into image if it contains correctly formed raw data in GIF format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
img dd ?
|
||||
global_color_table dd ?
|
||||
endl
|
||||
|
||||
push ebx
|
||||
|
||||
stdcall img.is.gif, [_data], [_length]
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
mov ebx, [_data]
|
||||
; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB
|
||||
; je @f
|
||||
; mov eax, [ebx + bmp.Header.file.Size]
|
||||
; cmp eax, [_length]
|
||||
; jne .error
|
||||
|
||||
test [ebx + gif.Header.lsd.Packed], gif.LSD.Packed.GlobalColorTableFlag
|
||||
jz @f
|
||||
lea eax, [ebx + sizeof.gif.Header]
|
||||
mov [global_color_table], eax
|
||||
mov cl, [ebx + gif.Header.lsd.Packed]
|
||||
and cl, gif.LSD.Packed.SizeOfGlobalColorTableMask
|
||||
shr cl, gif.LSD.Packed.SizeOfGlobalColorTableShift
|
||||
inc cl
|
||||
mov eax, 1
|
||||
shl eax, cl
|
||||
lea eax, [eax * 3]
|
||||
add ebx, eax
|
||||
@@: add ebx, sizeof.gif.Header
|
||||
|
||||
mov [img], 0
|
||||
|
||||
; @@: cmp byte[ebx + gif.Block.Introducer], gif.Block.Introducer.Extension
|
||||
; jne .next_image
|
||||
; cmp byte[ebx + gif.Extension.Label], gif.Extension.Label.Comment
|
||||
; jne .error
|
||||
; add ebx, sizeof.gif.Extension
|
||||
; stdcall ._.skip_data
|
||||
; mov ebx, eax
|
||||
; jmp @b
|
||||
|
||||
.next_image:
|
||||
stdcall img._.new
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov edx, [img]
|
||||
mov [eax + Image.Previous], edx
|
||||
mov [img], eax
|
||||
mov edx, eax
|
||||
|
||||
mov ecx, sizeof.gif.Image
|
||||
invoke mem.alloc, ecx
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [edx + Image.Extended], eax
|
||||
|
||||
stdcall ._.process_extensions
|
||||
|
||||
cmp byte[ebx + gif.Block.Introducer], gif.Block.Introducer.ImageDescriptor
|
||||
jne .error
|
||||
movzx eax, [ebx + gif.ImageDescriptor.Width]
|
||||
movzx ecx, [ebx + gif.ImageDescriptor.Height]
|
||||
stdcall img._resize_data, [img], eax, ecx
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
test [ebx + gif.ImageDescriptor.Packed], gif.ID.Packed.LocalColorTableFlag
|
||||
jz @f
|
||||
mov cl, [ebx + gif.ImageDescriptor.Packed]
|
||||
and cl, gif.ID.Packed.SizeOfLocalColorTableMask
|
||||
shr cl, gif.ID.Packed.SizeOfLocalColorTableShift
|
||||
inc cl
|
||||
mov eax, 1
|
||||
shl eax, cl
|
||||
lea ecx, [eax * sizeof.gif.RgbTriplet]
|
||||
lea eax, [ecx + sizeof.gif.Image]
|
||||
invoke mem.realloc, [edx + Image.Extended], eax
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [edx + Image.Extended], eax
|
||||
lea esi, [ebx + sizeof.gif.ImageDescriptor]
|
||||
lea edi, [eax + sizeof.gif.Image]
|
||||
rep movsb
|
||||
|
||||
@@: mov eax, [global_color_table]
|
||||
test [ebx + gif.ImageDescriptor.Packed], gif.ID.Packed.LocalColorTableFlag
|
||||
jz @f
|
||||
lea eax, [ebx + sizeof.gif.ImageDescriptor]
|
||||
@@: mov ebx, esi
|
||||
stdcall ._.process_image, eax
|
||||
|
||||
.decoded:
|
||||
or eax, eax
|
||||
jz @f
|
||||
stdcall img.destroy, [img]
|
||||
jmp .error
|
||||
|
||||
@@: mov eax, [img]
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.encode.gif _img, _p_length ;/////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Encode image into raw data in GIF format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to encoded data ;;
|
||||
;< _p_length = encoded data length ;;
|
||||
;;================================================================================================;;
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below are private procs you should never call directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.gif._.skip_data ;/////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = pointer to data blocks array ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = pointer to data right after data blocks array ;;
|
||||
;;================================================================================================;;
|
||||
push ecx
|
||||
xor ecx, ecx
|
||||
@@: mov cl, [esi]
|
||||
or cl, cl
|
||||
jz @f
|
||||
lea esi, [esi + ecx + 1]
|
||||
jmp @b
|
||||
@@: pop ecx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.gif._.process_extensions ;////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
push edx
|
||||
mov esi, ebx
|
||||
|
||||
.next_block:
|
||||
mov al, [esi + gif.Block.Introducer]
|
||||
cmp al, gif.Block.Introducer.Extension
|
||||
je .ext_block
|
||||
; cmp al, gif.Block.Introducer.ImageDescriptor
|
||||
; je .exit
|
||||
; cmp al, gif.Block.Introducer.EndOfFile
|
||||
; je .exit
|
||||
jmp .exit
|
||||
|
||||
.ext_block:
|
||||
mov al, [esi + gif.Extension.Label]
|
||||
cmp al, gif.Extension.Label.PlainText
|
||||
je .plain_text_ext
|
||||
cmp al, gif.Extension.Label.GraphicsControl
|
||||
je .graphics_control_ext
|
||||
cmp al, gif.Extension.Label.Comment
|
||||
je .comment_ext
|
||||
cmp al, gif.Extension.Label.Application
|
||||
je .application_ext
|
||||
jmp .exit
|
||||
|
||||
.plain_text_ext:
|
||||
add esi, gif.PlainTextExtension.PlainTextData
|
||||
stdcall img.decode.gif._.skip_data
|
||||
jmp .next_ext_block
|
||||
|
||||
.graphics_control_ext:
|
||||
push edi
|
||||
mov edi, [edx + Image.Extended]
|
||||
add edi, gif.Image.gce
|
||||
mov ecx, sizeof.gif.GraphicsControlExtension
|
||||
rep movsb
|
||||
pop edi
|
||||
jmp .next_ext_block
|
||||
|
||||
.comment_ext:
|
||||
add esi, gif.CommentExtension.CommentData
|
||||
stdcall img.decode.gif._.skip_data
|
||||
jmp .next_ext_block
|
||||
|
||||
.application_ext:
|
||||
add esi, gif.ApplicationExtension.ApplicationData
|
||||
stdcall img.decode.gif._.skip_data
|
||||
jmp .next_ext_block
|
||||
|
||||
.next_ext_block:
|
||||
mov al, [ebx + gif.Block.Introducer]
|
||||
cmp al, gif.Block.Introducer.EndOfData
|
||||
jne .exit
|
||||
inc ebx
|
||||
jmp .next_block
|
||||
|
||||
.exit:
|
||||
mov ebx, esi
|
||||
pop edx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.gif._.process_image _color_table ;////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> ebx = raw image data ;;
|
||||
;> edx = image data ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
width dd ?
|
||||
img_start dd ?
|
||||
img_end dd ?
|
||||
row_end dd ?
|
||||
pass dd ?
|
||||
codesize dd ?
|
||||
compsize dd ?
|
||||
workarea dd ?
|
||||
block_ofs dd ?
|
||||
bit_count dd ?
|
||||
CC dd ?
|
||||
EOI dd ?
|
||||
endl
|
||||
|
||||
invoke mem.alloc, 16 * 1024
|
||||
mov [workarea], eax
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
mov ecx, [edx + Image.Width]
|
||||
mov [width], ecx
|
||||
mov eax, [edx + Image.Height]
|
||||
imul eax, ecx
|
||||
; lea eax, [eax * 3]
|
||||
shl eax, 2
|
||||
mov [img_end], eax
|
||||
inc eax
|
||||
mov [row_end], eax
|
||||
and [pass], 0
|
||||
mov eax, [edx + Image.Extended]
|
||||
test [eax + gif.Image.info.Packed], gif.ID.Packed.InterleaceFlag
|
||||
jz @f
|
||||
; lea ecx, [ecx * 3]
|
||||
shl ecx, 2
|
||||
mov [row_end], ecx
|
||||
|
||||
@@: mov esi, ebx
|
||||
mov edi, [edx + Image.Data]
|
||||
|
||||
push edi
|
||||
movzx ecx, byte[esi]
|
||||
inc esi
|
||||
mov [codesize], ecx
|
||||
inc [codesize]
|
||||
mov edi, [workarea]
|
||||
xor eax, eax
|
||||
lodsb ; eax - block_count
|
||||
add eax, esi
|
||||
mov [block_ofs], eax
|
||||
mov [bit_count], 8
|
||||
mov eax, 1
|
||||
shl eax, cl
|
||||
mov [CC], eax
|
||||
mov ecx, eax
|
||||
inc eax
|
||||
mov [EOI], eax
|
||||
mov eax, gif.Null shl 16
|
||||
.filltable:
|
||||
stosd
|
||||
inc eax
|
||||
loop .filltable
|
||||
pop edi
|
||||
mov [img_start], edi
|
||||
add [img_end], edi
|
||||
add [row_end], edi
|
||||
.reinit:
|
||||
mov edx, [EOI]
|
||||
inc edx
|
||||
push [codesize]
|
||||
pop [compsize]
|
||||
call .get_symbol
|
||||
cmp eax, [CC]
|
||||
je .reinit
|
||||
call .output
|
||||
.cycle:
|
||||
movzx ebx, ax
|
||||
call .get_symbol
|
||||
cmp eax, edx
|
||||
jae .notintable
|
||||
cmp eax, [CC]
|
||||
je .reinit
|
||||
cmp eax, [EOI]
|
||||
je .end
|
||||
call .output
|
||||
.add:
|
||||
mov ecx, [workarea]
|
||||
mov [ecx + edx * 4], ebx
|
||||
cmp edx, 0x00000FFF
|
||||
jae .cycle
|
||||
inc edx
|
||||
bsr ebx, edx
|
||||
cmp ebx, [compsize]
|
||||
jne .noinc
|
||||
inc [compsize]
|
||||
.noinc:
|
||||
jmp .cycle
|
||||
.notintable:
|
||||
push eax
|
||||
mov eax, ebx
|
||||
call .output
|
||||
push ebx
|
||||
movzx eax, bx
|
||||
call .output
|
||||
pop ebx eax
|
||||
jmp .add
|
||||
.end:
|
||||
mov edi, [img_end]
|
||||
xor eax, eax
|
||||
|
||||
.exit:
|
||||
cmp [workarea], 0
|
||||
je @f
|
||||
invoke mem.free, [workarea]
|
||||
@@: xor eax, eax
|
||||
ret
|
||||
|
||||
.error:
|
||||
cmp [workarea], 0
|
||||
je @f
|
||||
invoke mem.free, [workarea]
|
||||
@@: xor eax, eax
|
||||
inc eax
|
||||
ret
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.gif._.process_image.get_symbol:
|
||||
mov ecx, [compsize]
|
||||
push ecx
|
||||
xor eax, eax
|
||||
|
||||
.shift:
|
||||
ror byte[esi], 1
|
||||
rcr eax,1
|
||||
dec [bit_count]
|
||||
jnz .loop1
|
||||
inc esi
|
||||
cmp esi, [block_ofs]
|
||||
jb .noblock
|
||||
push eax
|
||||
xor eax, eax
|
||||
lodsb
|
||||
test eax, eax
|
||||
jnz .nextbl
|
||||
mov eax, [EOI]
|
||||
sub esi, 2
|
||||
add esp, 8
|
||||
jmp .exit
|
||||
|
||||
.nextbl:
|
||||
add eax, esi
|
||||
mov [block_ofs], eax
|
||||
pop eax
|
||||
|
||||
.noblock:
|
||||
mov [bit_count], 8
|
||||
|
||||
.loop1:
|
||||
loop .shift
|
||||
pop ecx
|
||||
rol eax, cl
|
||||
|
||||
.exit:
|
||||
xor ecx, ecx
|
||||
retn
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.gif._.process_image.output:
|
||||
push esi eax edx
|
||||
mov edx, [workarea]
|
||||
|
||||
.next:
|
||||
pushw [edx + eax * 4]
|
||||
mov ax, [edx + eax * 4 + 2]
|
||||
inc ecx
|
||||
cmp ax, gif.Null
|
||||
jnz .next
|
||||
shl ebx, 16
|
||||
mov bx, [esp]
|
||||
|
||||
.loop2:
|
||||
pop ax
|
||||
|
||||
lea esi, [eax * 3]
|
||||
add esi, [_color_table]
|
||||
|
||||
mov esi, [esi]
|
||||
bswap esi
|
||||
shr esi, 8
|
||||
mov [edi], esi
|
||||
add edi, 4
|
||||
|
||||
cmp edi, [row_end]
|
||||
jb .norowend
|
||||
mov eax, [width]
|
||||
; lea eax, [eax * 3]
|
||||
shl eax, 2
|
||||
push eax
|
||||
sub edi, eax
|
||||
add eax, eax
|
||||
cmp [pass], 3
|
||||
je @f
|
||||
add eax, eax
|
||||
cmp [pass], 2
|
||||
je @f
|
||||
add eax, eax
|
||||
@@: add edi, eax
|
||||
pop eax
|
||||
cmp edi, [img_end]
|
||||
jb .nextrow
|
||||
mov edi, [img_start]
|
||||
inc [pass]
|
||||
add edi, eax
|
||||
cmp [pass], 3
|
||||
je @f
|
||||
add edi, eax
|
||||
cmp [pass], 2
|
||||
je @f
|
||||
add edi, eax
|
||||
add edi, eax
|
||||
@@:
|
||||
|
||||
.nextrow:
|
||||
add eax, edi
|
||||
mov [row_end], eax
|
||||
xor eax, eax
|
||||
|
||||
.norowend:
|
||||
loop .loop2
|
||||
pop edx eax esi
|
||||
retn
|
||||
|
||||
endp
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below is private data you should never use directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
;
|
137
programs/develop/libraries/libs-dev/libimg/gif/gif.inc
Normal file
137
programs/develop/libraries/libs-dev/libimg/gif/gif.inc
Normal file
@@ -0,0 +1,137 @@
|
||||
;;================================================================================================;;
|
||||
;;//// gif.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
struct gif.FileHeader ; GIF87a
|
||||
Signature db 3 dup(?) ; Header Signature (always "GIF")
|
||||
Version db 3 dup(?) ; GIF format version("87a" or "89a")
|
||||
ends
|
||||
|
||||
struct gif.LogicalScreenDescriptor ; GIF87a
|
||||
ScreenWidth dw ? ; Width of Display Screen in Pixels
|
||||
ScreenHeight dw ? ; Height of Display Screen in Pixels
|
||||
Packed db ? ; Screen and Color Map Information
|
||||
BackgroundColor db ? ; Background Color Index
|
||||
AspectRatio db ? ; Pixel Aspect Ratio
|
||||
ends
|
||||
|
||||
gif.LSD.Packed.SizeOfGlobalColorTableMask = 000000111b
|
||||
gif.LSD.Packed.SizeOfGlobalColorTableShift = 0
|
||||
gif.LSD.Packed.ColorTableSortFlag = 000001000b
|
||||
gif.LSD.Packed.ColorTableSortShift = 3
|
||||
gif.LSD.Packed.ColorResolutionMask = 001110000b
|
||||
gif.LSD.Packed.ColorResolutionShift = 4
|
||||
gif.LSD.Packed.GlobalColorTableFlag = 010000000b
|
||||
gif.LSD.Packed.GlobalColorTableShift = 7
|
||||
|
||||
struct gif.Header
|
||||
file gif.FileHeader
|
||||
lsd gif.LogicalScreenDescriptor
|
||||
ends
|
||||
|
||||
struct gif.RgbTriplet ; GIF87a
|
||||
Red db ? ; Red Color Element
|
||||
Green db ? ; Green Color Element
|
||||
Blue db ? ; Blue Color Element
|
||||
ends
|
||||
|
||||
struct gif.Block
|
||||
Introducer db ?
|
||||
ends
|
||||
|
||||
gif.Block.Introducer.EndOfData = 0x00
|
||||
gif.Block.Introducer.Extension = 0x21
|
||||
gif.Block.Introducer.ImageDescriptor = 0x2C
|
||||
gif.Block.Introducer.EndOfFile = 0x3B
|
||||
|
||||
struct gif.ImageDescriptor ; GIF87a
|
||||
b gif.Block ; Introducer = 2Ch (',')
|
||||
Left dw ? ; X position of image on the display
|
||||
Top dw ? ; Y position of image on the display
|
||||
Width dw ? ; Width of the image in pixels
|
||||
Height dw ? ; Height of the image in pixels
|
||||
Packed db ? ; Image and Color Table Data Information
|
||||
ends
|
||||
|
||||
gif.ID.Packed.SizeOfLocalColorTableMask = 000000111b
|
||||
gif.ID.Packed.SizeOfLocalColorTableShift = 0
|
||||
gif.ID.Packed.SortFlag = 000100000b
|
||||
gif.ID.Packed.SortShift = 5
|
||||
gif.ID.Packed.InterleaceFlag = 001000000b
|
||||
gif.ID.Packed.InterleaceShift = 6
|
||||
gif.ID.Packed.LocalColorTableFlag = 010000000b
|
||||
gif.ID.Packed.LocalColorTableShift = 7
|
||||
|
||||
struct gif.Extension
|
||||
b gif.Block ; Introducer = 21h ('|')
|
||||
Label db ? ; Extension label
|
||||
ends
|
||||
|
||||
gif.Extension.Label.PlainText = 0x01
|
||||
gif.Extension.Label.GraphicsControl = 0xF9
|
||||
gif.Extension.Label.Comment = 0xFE
|
||||
gif.Extension.Label.Application = 0xFF
|
||||
|
||||
struct gif.PlainTextExtension ; GIF89a
|
||||
e gif.Extension ; Label = 01h
|
||||
BlockSize db ? ; Size of Extension Block (always 0Ch)
|
||||
TextGridLeft dw ? ; X position of text grid in pixels
|
||||
TextGridTop dw ? ; Y position of text grid in pixels
|
||||
TextGridWidth dw ? ; Width of the text grid in pixels
|
||||
TextGridHeight dw ? ; Height of the text grid in pixels
|
||||
CellWidth db ? ; Width of a grid cell in pixels
|
||||
CellHeight db ? ; Height of a grid cell in pixels
|
||||
TextFgColorIndex db ? ; Text foreground color index value
|
||||
TextBgColorIndex db ? ; Text background color index value
|
||||
PlainTextData db ? ; The Plain Text data (*)
|
||||
; Terminator db ? ; Block Terminator (always 0)
|
||||
ends
|
||||
|
||||
struct gif.GraphicsControlExtension ; GIF89a
|
||||
e gif.Extension ; Label = F9h
|
||||
BlockSize db ? ; Size of remaining fields (always 04h)
|
||||
Packed db ? ; Method of graphics disposal to use
|
||||
DelayTime dw ? ; Hundredths of seconds to wait
|
||||
ColorIndex db ? ; Transparent Color Index
|
||||
; Terminator db ? ; Block Terminator (always 0)
|
||||
ends
|
||||
|
||||
struct gif.CommentExtension ; GIF89a
|
||||
e gif.Extension ; Label = FEh
|
||||
CommentData db ? ; Pointer to Comment Data sub-blocks (*)
|
||||
; Terminator db ? ; Block Terminator (always 0)
|
||||
ends
|
||||
|
||||
struct gif.ApplicationExtension ; GIF89a
|
||||
e gif.Extension ; Label = FFh
|
||||
BlockSize db ? ; Size of Extension Block (always 0Bh)
|
||||
Identifier db 8 dup(?) ; Application Identifier
|
||||
AuthentCode db 3 dup(?) ; Application Authentication Code
|
||||
ApplicationData db ? ; Point to Application Data sub-blocks (*)
|
||||
; Terminator db ? ; Block Terminator (always 0)
|
||||
ends
|
||||
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
struct gif.Image
|
||||
gce gif.GraphicsControlExtension
|
||||
info gif.ImageDescriptor
|
||||
ends
|
||||
|
||||
gif.Null equ 0x1000
|
501
programs/develop/libraries/libs-dev/libimg/libimg.asm
Normal file
501
programs/develop/libraries/libs-dev/libimg/libimg.asm
Normal file
@@ -0,0 +1,501 @@
|
||||
;;================================================================================================;;
|
||||
;;//// libimg.asm //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
format MS COFF
|
||||
|
||||
public @EXPORT as 'EXPORTS'
|
||||
|
||||
include '../../../../struct.inc'
|
||||
include '../../../../proc32.inc'
|
||||
include '../../../../macros.inc'
|
||||
purge section,mov;add,sub
|
||||
|
||||
include 'libimg.inc'
|
||||
|
||||
section '.flat' code readable align 16
|
||||
|
||||
include 'bmp/bmp.asm'
|
||||
include 'gif/gif.asm'
|
||||
|
||||
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
|
||||
|
||||
.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
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets) ;;
|
||||
;;================================================================================================;;
|
||||
push esi edi
|
||||
stdcall img._.validate, [_img]
|
||||
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
|
||||
mov esi, [esi + Image.Data]
|
||||
|
||||
@@: dec ecx
|
||||
js @f
|
||||
movsd
|
||||
dec edi
|
||||
jmp @b
|
||||
|
||||
@@: pop eax
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
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
|
||||
jnz @f
|
||||
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
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.create _width, _height ;/////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 / pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
push ecx
|
||||
|
||||
stdcall img._.new
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
push eax
|
||||
|
||||
stdcall img._resize_data, eax, [_width], [_height]
|
||||
or eax, eax
|
||||
jz .error.2
|
||||
|
||||
pop eax
|
||||
ret
|
||||
|
||||
.error.2:
|
||||
; pop eax
|
||||
stdcall img._.delete; eax
|
||||
xor eax, eax
|
||||
|
||||
.error:
|
||||
pop ecx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
;TODO: link Next and Previous
|
||||
stdcall img._.delete, [_img]
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img._resize_data _img, _width, _height ;/////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
push ebx
|
||||
mov ebx, [_img]
|
||||
mov eax, [_height]
|
||||
imul eax, [_width]
|
||||
shl eax, 2
|
||||
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]
|
||||
|
||||
.error:
|
||||
pop ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
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
|
||||
|
||||
;;//// image processing //////////////////////////////////////////////////////////////////////////;;
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
scanline_len dd ?
|
||||
endl
|
||||
|
||||
push esi edi
|
||||
stdcall img._.validate, [_img]
|
||||
or eax, eax
|
||||
jnz .error
|
||||
|
||||
mov esi, [_img]
|
||||
mov ecx, [esi + Image.Height]
|
||||
mov eax, [esi + Image.Width]
|
||||
shl eax, 2
|
||||
mov [scanline_len], eax
|
||||
|
||||
test [_flip_kind], FLIP_VERTICAL
|
||||
jz .dont_flip_vert
|
||||
|
||||
imul eax, ecx
|
||||
sub eax, [scanline_len]
|
||||
shr ecx, 1
|
||||
mov esi, [esi + Image.Data]
|
||||
lea edi, [esi + eax]
|
||||
|
||||
.next_line_vert:
|
||||
push ecx
|
||||
|
||||
mov ecx, [scanline_len]
|
||||
@@: lodsd
|
||||
xchg eax, [edi]
|
||||
mov [esi - 4], eax
|
||||
add edi, 4
|
||||
add ecx, -4
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_len]
|
||||
shl eax, 1
|
||||
sub edi, eax
|
||||
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line_vert
|
||||
|
||||
.dont_flip_vert:
|
||||
|
||||
test [_flip_kind], FLIP_HORIZONTAL
|
||||
jz .exit
|
||||
|
||||
;TODO: horz flip code
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
inc eax
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
ret
|
||||
endp
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! 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
|
||||
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
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! 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
|
||||
; .png dd img.is.png, img.decode.png, img.encode.png
|
||||
; .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
|
||||
dd 0
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Exported functions section ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
align 16
|
||||
@EXPORT:
|
||||
|
||||
export \
|
||||
lib_init , 'lib_init' , \
|
||||
0x00010001 , 'version' , \
|
||||
img.is_img , 'img.is_img' , \
|
||||
img.info , 'img.info' , \
|
||||
img.from_file , 'img.from_file' , \
|
||||
img.to_file , 'img.to_file' , \
|
||||
img.from_rgb , 'img.from_rgb' , \
|
||||
img.to_rgb , 'img.to_rgb' , \
|
||||
img.decode , 'img.decode' , \
|
||||
img.encode , 'img.encode' , \
|
||||
img.create , 'img.create' , \
|
||||
img.destroy , 'img.destroy' , \
|
||||
img.lock_bits , 'img.lock_bits' , \
|
||||
img.unlock_bits , 'img.unlock_bits'
|
39
programs/develop/libraries/libs-dev/libimg/libimg.inc
Normal file
39
programs/develop/libraries/libs-dev/libimg/libimg.inc
Normal file
@@ -0,0 +1,39 @@
|
||||
;;================================================================================================;;
|
||||
;;//// libimg.inc //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; 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 ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
|
||||
;; see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
struct FormatsTableEntry
|
||||
Is dd ?
|
||||
Decode dd ?
|
||||
Encode dd ?
|
||||
ends
|
||||
|
||||
struct Image
|
||||
Checksum dd ? ; ((Width ROL 16) OR Height) XOR Data[0]
|
||||
Width dd ?
|
||||
Height dd ?
|
||||
Next dd ?
|
||||
Previous dd ?
|
||||
Data dd ?
|
||||
Extended dd ?
|
||||
ends
|
||||
|
||||
FLIP_VERTICAL = 0x01
|
||||
FLIP_HORIZONTAL = 0x02
|
||||
FLIP_BOTH = FLIP_VERTICAL or FLIP_HORIZONTAL
|
Reference in New Issue
Block a user