forked from KolibriOS/kolibrios
libimg: bmp support improved, jpeg support added
git-svn-id: svn://kolibrios.org@999 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
0be9a1a504
commit
e2b2bba7ba
@ -1,19 +1,19 @@
|
||||
;;================================================================================================;;
|
||||
;;//// bmp.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;//// bmp.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ///////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 of the ;;
|
||||
;; License, or (at your option) any later version. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
@ -28,7 +28,8 @@
|
||||
include 'bmp.inc'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.is.bmp _data, _length ;//////////////////////////////////////////////////////////////////;;
|
||||
;;proc img.is.bmp _data, _length ;////////////////////////////////////////////////////////////////;;
|
||||
img.is.bmp:
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Determine if raw data could be decoded (is in BMP format) ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -37,21 +38,23 @@ proc img.is.bmp _data, _length ;////////////////////////////////////////////////
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
cmp [_length], 2
|
||||
; test 1 (length of data): data must contain FileHeader and required fields from InfoHeader
|
||||
cmp dword [esp+8], sizeof.bmp.FileHeader + 12
|
||||
jb .nope
|
||||
mov eax, [_data]
|
||||
; test 2: signature
|
||||
mov eax, [esp+4]
|
||||
cmp word [eax], 'BM'
|
||||
je .yep
|
||||
|
||||
.nope:
|
||||
xor eax, eax
|
||||
ret
|
||||
ret 8
|
||||
|
||||
.yep:
|
||||
xor eax, eax
|
||||
inc eax
|
||||
ret
|
||||
endp
|
||||
ret 8
|
||||
;endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp _data, _length ;//////////////////////////////////////////////////////////////;;
|
||||
@ -65,13 +68,15 @@ proc img.decode.bmp _data, _length ;////////////////////////////////////////////
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
img dd ?
|
||||
bTopDown db ?
|
||||
endl
|
||||
|
||||
push ebx
|
||||
push ebx esi edi
|
||||
|
||||
stdcall img.is.bmp, [_data], [_length]
|
||||
or eax, eax
|
||||
jz .error
|
||||
; img.is.bmp has been already called by img.decode
|
||||
; stdcall img.is.bmp, [_data], [_length]
|
||||
; or eax, eax
|
||||
; jz .error
|
||||
|
||||
mov ebx, [_data]
|
||||
; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB
|
||||
@ -79,8 +84,60 @@ endl
|
||||
; mov eax, [ebx + bmp.Header.file.Size]
|
||||
; cmp eax, [_length]
|
||||
; jne .error
|
||||
; @@:
|
||||
|
||||
mov eax, [ebx + bmp.Header.info.Size]
|
||||
; sanity check: file length must be greater than size of headers
|
||||
add eax, sizeof.bmp.FileHeader
|
||||
cmp [_length], eax
|
||||
jbe .error
|
||||
|
||||
mov [bTopDown], 0
|
||||
|
||||
cmp eax, sizeof.bmp.FileHeader + 12
|
||||
jz .old1
|
||||
cmp eax, sizeof.bmp.FileHeader + 40
|
||||
jz .normal
|
||||
cmp eax, sizeof.bmp.FileHeader + 56
|
||||
jnz .error
|
||||
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
|
||||
.normal:
|
||||
xor eax, eax
|
||||
inc eax ; Image.bpp8
|
||||
cmp [ebx + bmp.Header.info.BitCount], 8
|
||||
jbe @f
|
||||
mov al, Image.bpp32
|
||||
@@:
|
||||
push eax
|
||||
mov eax, [ebx + bmp.Header.info.Height]
|
||||
test eax, eax
|
||||
jns @f
|
||||
inc [bTopDown]
|
||||
neg eax
|
||||
@@:
|
||||
pushd eax
|
||||
pushd [ebx + bmp.Header.info.Width]
|
||||
jmp .create
|
||||
.old1:
|
||||
xor eax, eax
|
||||
inc eax ; Image.bpp8
|
||||
cmp [ebx + bmp.Header.info.OldBitCount], 8
|
||||
jbe @f
|
||||
mov al, Image.bpp32
|
||||
@@:
|
||||
push eax
|
||||
movsx eax, [ebx + bmp.Header.info.OldHeight]
|
||||
test eax, eax
|
||||
jns @f
|
||||
inc [bTopDown]
|
||||
neg eax
|
||||
@@:
|
||||
push eax
|
||||
movzx eax, [ebx + bmp.Header.info.OldWidth]
|
||||
push eax
|
||||
.create:
|
||||
call img.create
|
||||
|
||||
@@: stdcall img.create, [ebx + bmp.Header.info.Width], [ebx + bmp.Header.info.Height]
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [img], eax
|
||||
@ -88,52 +145,87 @@ endl
|
||||
|
||||
invoke mem.alloc, sizeof.bmp.Image
|
||||
or eax, eax
|
||||
jz .error
|
||||
jz .error.free
|
||||
mov [edx + Image.Extended], eax
|
||||
mov esi, ebx
|
||||
add esi, sizeof.bmp.FileHeader
|
||||
push eax
|
||||
mov edi, eax
|
||||
mov ecx, sizeof.bmp.InfoHeader
|
||||
mov ecx, sizeof.bmp.Image/4
|
||||
xor eax, eax
|
||||
rep stosd
|
||||
pop edi
|
||||
lea esi, [ebx + sizeof.bmp.FileHeader]
|
||||
pushd [ebx + bmp.FileHeader.OffBits]
|
||||
mov ecx, [esi + bmp.InfoHeader.Size]
|
||||
cmp ecx, 12
|
||||
jz .old2
|
||||
rep movsb
|
||||
jmp .decode
|
||||
.old2:
|
||||
movsd ; Size
|
||||
movzx eax, word [esi] ; OldWidth -> Width
|
||||
stosd
|
||||
movsx eax, word [esi+2] ; OldHeight -> Height
|
||||
stosd
|
||||
lodsd ; skip OldWidth+OldHeight
|
||||
movsd ; Planes+BitCount
|
||||
.decode:
|
||||
|
||||
mov eax, [ebx + bmp.Header.info.Compression]
|
||||
pop eax
|
||||
mov esi, [_length]
|
||||
sub esi, eax
|
||||
jbe .error.free
|
||||
|
||||
mov eax, [edx + Image.Extended]
|
||||
mov eax, [eax + bmp.Image.info.Compression]
|
||||
cmp eax, bmp.BI_RGB
|
||||
jne @f
|
||||
stdcall ._.rgb
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_RLE8
|
||||
jne @f
|
||||
cmp [ebx + bmp.Header.info.BitCount], 8
|
||||
jnz .error.free
|
||||
stdcall ._.rle
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_RLE4
|
||||
jne @f
|
||||
cmp [ebx + bmp.Header.info.BitCount], 4
|
||||
jnz .error.free
|
||||
stdcall ._.rle
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_BITFIELDS
|
||||
jne @f
|
||||
jne .error.free
|
||||
stdcall ._.bitfields
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_JPEG
|
||||
jne @f
|
||||
stdcall ._.jpeg
|
||||
jmp .decoded
|
||||
@@: cmp eax, bmp.BI_PNG
|
||||
jne .error
|
||||
stdcall ._.png
|
||||
; BI_JPEG and BI_PNG constants are not valid values for BMP file,
|
||||
; they are intended for WinAPI
|
||||
; @@: 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
|
||||
.error.free:
|
||||
stdcall img.destroy, [img]
|
||||
jmp .error
|
||||
|
||||
@@: stdcall img.flip, [img], FLIP_VERTICAL
|
||||
@@:
|
||||
cmp [bTopDown], 0
|
||||
jnz @f
|
||||
stdcall img.flip, [img], FLIP_VERTICAL
|
||||
@@:
|
||||
mov eax, [img]
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop ebx
|
||||
pop edi esi ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
@ -175,7 +267,7 @@ proc img.decode.bmp._.rgb ;/////////////////////////////////////////////////////
|
||||
mov [ecx + bmp.Image.info.AlphaMask], 0
|
||||
mov edi, [edx + Image.Data]
|
||||
|
||||
movzx eax, [ebx + bmp.Header.info.BitCount]
|
||||
movzx eax, [ecx + bmp.Image.info.BitCount]
|
||||
cmp eax, 32
|
||||
je .32bpp
|
||||
cmp eax, 24
|
||||
@ -202,13 +294,19 @@ img.decode.bmp._.rgb.32bpp:
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.24bpp:
|
||||
mov eax, [edx + Image.Width]
|
||||
lea eax, [eax*3 + 3]
|
||||
and eax, not 3
|
||||
mov ecx, [edx + Image.Height]
|
||||
imul eax, ecx
|
||||
cmp esi, eax
|
||||
jb img.decode.bmp._.rgb.error
|
||||
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]
|
||||
push ecx edx
|
||||
mov ecx, [edx + Image.Width]
|
||||
xor edx, edx
|
||||
|
||||
.next_line_pixel:
|
||||
@ -220,7 +318,7 @@ img.decode.bmp._.rgb.24bpp:
|
||||
|
||||
and edx, 0x03
|
||||
add esi, edx
|
||||
pop ecx
|
||||
pop edx ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
@ -238,22 +336,19 @@ img.decode.bmp._.rgb.16bpp:
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.8bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
mov eax, [edx + Image.Width]
|
||||
add eax, 3
|
||||
call img.decode.bmp._.rgb.prepare_palette
|
||||
jc img.decode.bmp._.rgb.error
|
||||
|
||||
.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
|
||||
|
||||
mov ecx, [edx + Image.Width]
|
||||
mov eax, ecx
|
||||
neg eax
|
||||
and eax, 3
|
||||
rep movsb
|
||||
add esi, eax
|
||||
pop ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
@ -263,13 +358,15 @@ img.decode.bmp._.rgb.8bpp:
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.4bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
mov eax, [edx + Image.Width]
|
||||
add eax, 7
|
||||
shr eax, 1
|
||||
call img.decode.bmp._.rgb.prepare_palette
|
||||
jc img.decode.bmp._.rgb.error
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
push ecx edx
|
||||
mov ecx, [edx + Image.Width]
|
||||
|
||||
.next_line_dword:
|
||||
push ecx
|
||||
@ -281,9 +378,8 @@ img.decode.bmp._.rgb.4bpp:
|
||||
.next_pixel:
|
||||
rol edx, 4
|
||||
mov al, dl
|
||||
and eax, 0x0000000F
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
and al, 0x0000000F
|
||||
stosb
|
||||
dec dword[esp]
|
||||
jz @f
|
||||
dec ecx
|
||||
@ -293,7 +389,7 @@ img.decode.bmp._.rgb.4bpp:
|
||||
or ecx, ecx
|
||||
jnz .next_line_dword
|
||||
|
||||
pop ecx
|
||||
pop edx ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
@ -302,13 +398,15 @@ img.decode.bmp._.rgb.4bpp:
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
img.decode.bmp._.rgb.1bpp:
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov ecx, [ebx + bmp.Header.info.Height]
|
||||
mov eax, [edx + Image.Width]
|
||||
add eax, 31
|
||||
shr eax, 3
|
||||
call img.decode.bmp._.rgb.prepare_palette
|
||||
jc img.decode.bmp._.rgb.error
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
mov ecx, [ebx + bmp.Header.info.Width]
|
||||
push ecx edx
|
||||
mov ecx, [edx + Image.Width]
|
||||
|
||||
.next_line_dword:
|
||||
push ecx
|
||||
@ -320,9 +418,8 @@ img.decode.bmp._.rgb.1bpp:
|
||||
.next_pixel:
|
||||
rol edx, 1
|
||||
mov al, dl
|
||||
and eax, 0x00000001
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
stosd
|
||||
and al, 0x00000001
|
||||
stosb
|
||||
dec dword[esp]
|
||||
jz @f
|
||||
dec ecx
|
||||
@ -332,7 +429,7 @@ img.decode.bmp._.rgb.1bpp:
|
||||
or ecx, ecx
|
||||
jnz .next_line_dword
|
||||
|
||||
pop ecx
|
||||
pop edx ecx
|
||||
dec ecx
|
||||
jnz .next_line
|
||||
|
||||
@ -347,6 +444,48 @@ img.decode.bmp._.rgb.1bpp:
|
||||
img.decode.bmp._.rgb.error:
|
||||
or eax, -1
|
||||
ret
|
||||
|
||||
img.decode.bmp._.rgb.prepare_palette:
|
||||
and eax, not 3
|
||||
mov ecx, [edx + Image.Height]
|
||||
imul eax, ecx
|
||||
cmp esi, eax
|
||||
jb .ret
|
||||
mov esi, [ebx + bmp.Header.info.Size]
|
||||
add esi, sizeof.bmp.FileHeader
|
||||
jc .ret
|
||||
mov eax, [ebx + bmp.Header.file.OffBits]
|
||||
sub eax, esi
|
||||
jc .ret
|
||||
push edi
|
||||
mov edi, [edx + Image.Palette]
|
||||
push ecx
|
||||
mov ecx, 256
|
||||
cmp esi, sizeof.bmp.FileHeader + 12
|
||||
jz .old
|
||||
shr eax, 2
|
||||
add esi, ebx
|
||||
cmp ecx, eax
|
||||
jb @f
|
||||
mov ecx, eax
|
||||
@@:
|
||||
rep movsd
|
||||
jmp .common
|
||||
.old:
|
||||
movsd
|
||||
dec esi
|
||||
sub eax, 3
|
||||
jbe @f
|
||||
sub ecx, 1
|
||||
jnz .old
|
||||
@@:
|
||||
.common:
|
||||
pop ecx
|
||||
pop edi
|
||||
mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
.ret:
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
@ -365,27 +504,35 @@ locals
|
||||
marker_y dd ?
|
||||
abs_mode_addr dd ?
|
||||
enc_mode_addr dd ?
|
||||
height 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
|
||||
@@:
|
||||
|
||||
push esi
|
||||
xor eax, eax ; do not check file size in .prepare_palette
|
||||
call img.decode.bmp._.rgb.prepare_palette
|
||||
pop ecx ; ecx = rest bytes in file
|
||||
jc .error
|
||||
|
||||
@@: mov esi, ebx
|
||||
add esi, [ebx + bmp.Header.file.OffBits]
|
||||
mov eax, [edx + Image.Width]
|
||||
shl eax, 2
|
||||
mov [scanline_len], eax
|
||||
mov eax, [edx + Image.Height]
|
||||
mov [height], eax
|
||||
xor eax, eax
|
||||
mov [marker_x], eax
|
||||
mov [marker_y], eax
|
||||
mov edi, [edx + Image.Data]
|
||||
|
||||
.next_run:
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
xor eax, eax
|
||||
lodsb
|
||||
or al, al
|
||||
@ -393,6 +540,8 @@ endl
|
||||
jmp [enc_mode_addr]
|
||||
|
||||
.escape_mode:
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
lodsb
|
||||
cmp al, 0
|
||||
je .end_of_scanline
|
||||
@ -403,29 +552,30 @@ endl
|
||||
jmp [abs_mode_addr]
|
||||
|
||||
.end_of_scanline: ; 0
|
||||
mov eax, [marker_x]
|
||||
shl eax, 2
|
||||
neg eax
|
||||
add eax, [scanline_len]
|
||||
add edi, eax
|
||||
sub edi, [marker_x]
|
||||
add edi, [scanline_len]
|
||||
mov [marker_x], 0
|
||||
inc [marker_y]
|
||||
jmp .next_run
|
||||
mov eax, [marker_y]
|
||||
inc eax
|
||||
mov [marker_y], eax
|
||||
cmp eax, [height]
|
||||
jb .next_run
|
||||
jmp .exit
|
||||
|
||||
.offset_marker: ; 2: dx, dy
|
||||
sub ecx, 2
|
||||
jc .eof
|
||||
lodsb
|
||||
mov edx, [marker_x]
|
||||
add edx, eax
|
||||
cmp edx, [ebx + bmp.Header.info.Width]
|
||||
cmp edx, [scanline_len]
|
||||
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]
|
||||
cmp edx, [height]
|
||||
jae .exit
|
||||
mov [marker_y], edx
|
||||
imul eax, [scanline_len]
|
||||
@ -433,90 +583,112 @@ endl
|
||||
jmp .next_run
|
||||
|
||||
.encoded_mode.rle8: ; N: b1 * N
|
||||
mov edx, eax
|
||||
call .fix_marker
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
lodsb
|
||||
mov eax, [ebx + eax * 4 + bmp.Header.info.Palette]
|
||||
@@: dec edx
|
||||
js .fix_marker
|
||||
stosd
|
||||
inc [marker_x]
|
||||
jmp @b
|
||||
push ecx
|
||||
mov ecx, edx
|
||||
rep stosb
|
||||
pop ecx
|
||||
jmp .check_eoi
|
||||
|
||||
.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
|
||||
call .fix_marker
|
||||
cmp ecx, edx
|
||||
jae @f
|
||||
mov edx, ecx
|
||||
@@:
|
||||
push ecx
|
||||
mov ecx, edx
|
||||
rep movsb
|
||||
pop ecx
|
||||
sub ecx, edx
|
||||
jz .eof
|
||||
test edx, 1
|
||||
jz .check_eoi
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
inc esi
|
||||
jmp .fix_marker
|
||||
.check_eoi:
|
||||
mov eax, [marker_y]
|
||||
cmp eax, [height]
|
||||
jb .next_run
|
||||
jmp .exit
|
||||
|
||||
.encoded_mode.rle4: ; N: b1 * N
|
||||
mov edx, eax
|
||||
lodsb
|
||||
call .fix_marker
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
movzx eax, byte [esi]
|
||||
inc esi
|
||||
push ecx
|
||||
mov ecx, eax
|
||||
and eax, 0xF
|
||||
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]
|
||||
mov [edi], cl
|
||||
dec edx
|
||||
js @f
|
||||
mov [edi+1], al
|
||||
add edi, 2
|
||||
jmp @b
|
||||
@@: pop eax
|
||||
@@:
|
||||
pop ecx
|
||||
jmp .check_eoi
|
||||
|
||||
.absolute_mode.rle4: ; N: b1 .. bN
|
||||
call .fix_marker
|
||||
lea eax, [edx+1]
|
||||
shr eax, 1
|
||||
cmp ecx, eax
|
||||
jbe @f
|
||||
lea edx, [ecx*2]
|
||||
@@:
|
||||
push ecx edx
|
||||
@@: dec edx
|
||||
js @f
|
||||
lodsb
|
||||
mov cl, al
|
||||
shr al, 4
|
||||
and cl, 0xF
|
||||
stosb
|
||||
dec edx
|
||||
js @f
|
||||
mov [edi], cl
|
||||
inc edi
|
||||
jmp @b
|
||||
@@: pop eax ecx
|
||||
and eax, 0x03
|
||||
jz .fix_marker
|
||||
cmp eax, 3
|
||||
je .fix_marker
|
||||
jp .check_eoi
|
||||
sub ecx, 1
|
||||
jc .eof
|
||||
inc esi
|
||||
jmp .fix_marker
|
||||
jmp .check_eoi
|
||||
|
||||
.fix_marker:
|
||||
mov eax, [marker_x]
|
||||
@@: sub eax, [ebx + bmp.Header.info.Width]
|
||||
jle .next_run
|
||||
mov edx, eax
|
||||
add eax, [marker_x]
|
||||
mov [marker_x], eax
|
||||
inc [marker_y]
|
||||
jmp @b
|
||||
@@:
|
||||
sub eax, [scanline_len]
|
||||
jle @f
|
||||
mov [marker_x], eax
|
||||
push eax
|
||||
mov eax, [marker_y]
|
||||
inc eax
|
||||
mov [marker_y], eax
|
||||
cmp eax, [height]
|
||||
pop eax
|
||||
jb @b
|
||||
sub edx, eax
|
||||
@@:
|
||||
retn
|
||||
|
||||
.exit:
|
||||
.eof:
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
@ -542,8 +714,23 @@ locals
|
||||
delta dd ?
|
||||
endl
|
||||
|
||||
push esi edi
|
||||
mov esi, [edx + Image.Extended]
|
||||
push edi
|
||||
|
||||
mov [delta], 4
|
||||
mov eax, [edx + Image.Extended]
|
||||
cmp [eax + bmp.Image.info.BitCount], 32
|
||||
je @f
|
||||
cmp [eax + bmp.Image.info.BitCount], 16
|
||||
jne .error
|
||||
mov [delta], 2
|
||||
@@:
|
||||
mov ecx, [edx + Image.Width]
|
||||
imul ecx, [edx + Image.Height]
|
||||
imul ecx, [delta]
|
||||
cmp esi, ecx
|
||||
jb .error
|
||||
|
||||
mov esi, eax
|
||||
|
||||
mov ecx, [esi + bmp.Image.info.RedMask]
|
||||
call .calc_shift
|
||||
@ -577,17 +764,9 @@ endl
|
||||
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]
|
||||
mov ecx, [edx + Image.Height]
|
||||
|
||||
.next_line:
|
||||
push ecx
|
||||
@ -642,12 +821,12 @@ endl
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
pop edi
|
||||
ret
|
||||
|
||||
.error:
|
||||
or eax, -1
|
||||
pop edi esi
|
||||
pop edi
|
||||
ret
|
||||
|
||||
.calc_shift:
|
||||
@ -678,6 +857,7 @@ endl
|
||||
retn
|
||||
endp
|
||||
|
||||
if 0
|
||||
;;================================================================================================;;
|
||||
proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -705,7 +885,7 @@ proc img.decode.bmp._.png ;/////////////////////////////////////////////////////
|
||||
xor eax, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
end if
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
|
@ -1,19 +1,19 @@
|
||||
;;================================================================================================;;
|
||||
;;//// bmp.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
|
||||
;;//// bmp.inc //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ///////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 of the ;;
|
||||
;; License, or (at your option) any later version. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
@ -28,10 +28,20 @@ ends
|
||||
struct bmp.InfoHeader
|
||||
; v2 (Windows 2.x)
|
||||
Size dd ? ; Size of this header in bytes
|
||||
union
|
||||
struct ; new format
|
||||
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
|
||||
ends
|
||||
struct ; old format
|
||||
OldWidth dw ? ; Image width in pixels as word
|
||||
OldHeight dw ? ; Image height in pixels as word
|
||||
OldPlanes dw ? ; Number of color planes
|
||||
OldBitCount dw ? ; Number of bits per pixel
|
||||
ends
|
||||
ends
|
||||
; v3 (Windows 3.x)
|
||||
Compression dd ? ; Compression method used
|
||||
SizeImage dd ? ; Size of bitmap in bytes
|
||||
|
@ -5,15 +5,15 @@
|
||||
;; 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. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
|
@ -7,15 +7,15 @@
|
||||
;; 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. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
@ -84,20 +84,18 @@ proc img.decode.gif _data, _length ;////////////////////////////////////////////
|
||||
locals
|
||||
img dd ?
|
||||
global_color_table dd ?
|
||||
global_color_table_size dd ?
|
||||
endl
|
||||
|
||||
push ebx
|
||||
|
||||
stdcall img.is.gif, [_data], [_length]
|
||||
or eax, eax
|
||||
jz .error
|
||||
; img.is.gif is called by caller (img.decode)
|
||||
; stdcall img.is.gif, [_data], [_length]
|
||||
; or eax, eax
|
||||
; jz .error
|
||||
|
||||
mov [global_color_table_size], 0
|
||||
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
|
||||
@ -106,9 +104,9 @@ endl
|
||||
mov cl, [ebx + gif.Header.lsd.Packed]
|
||||
and cl, gif.LSD.Packed.SizeOfGlobalColorTableMask
|
||||
shr cl, gif.LSD.Packed.SizeOfGlobalColorTableShift
|
||||
inc cl
|
||||
mov eax, 1
|
||||
mov eax, 2
|
||||
shl eax, cl
|
||||
mov [global_color_table_size], eax
|
||||
lea eax, [eax * 3]
|
||||
add ebx, eax
|
||||
@@: add ebx, sizeof.gif.Header
|
||||
@ -130,11 +128,15 @@ endl
|
||||
jz .error
|
||||
mov edx, [img]
|
||||
mov [eax + Image.Previous], edx
|
||||
test edx, edx
|
||||
jz @f
|
||||
mov [edx + Image.Next], eax
|
||||
@@:
|
||||
mov [img], eax
|
||||
mov edx, eax
|
||||
mov [eax + Image.Type], Image.bpp8
|
||||
|
||||
mov ecx, sizeof.gif.Image
|
||||
invoke mem.alloc, ecx
|
||||
invoke mem.alloc, sizeof.gif.Image
|
||||
or eax, eax
|
||||
jz .error
|
||||
mov [edx + Image.Extended], eax
|
||||
@ -149,33 +151,34 @@ endl
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
xor ecx, ecx
|
||||
mov eax, [edx + Image.Extended]
|
||||
mov esi, ebx
|
||||
mov edi, [edx + Image.Extended]
|
||||
mov ecx, sizeof.gif.ImageDescriptor
|
||||
rep movsb
|
||||
|
||||
mov edi, [edx + Image.Palette]
|
||||
mov esi, [global_color_table]
|
||||
mov ecx, [global_color_table_size]
|
||||
test [ebx + gif.ImageDescriptor.Packed], gif.ID.Packed.LocalColorTableFlag
|
||||
jz @f
|
||||
lea esi, [ebx + sizeof.gif.ImageDescriptor]
|
||||
mov cl, [ebx + gif.ImageDescriptor.Packed]
|
||||
and cl, gif.ID.Packed.SizeOfLocalColorTableMask
|
||||
shr cl, gif.ID.Packed.SizeOfLocalColorTableShift
|
||||
inc cl
|
||||
mov eax, 1
|
||||
mov eax, 2
|
||||
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
|
||||
@@: mov esi, ebx
|
||||
lea edi, [eax + sizeof.gif.GraphicsControlExtension]
|
||||
add ecx, sizeof.gif.ImageDescriptor
|
||||
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
|
||||
mov ecx, eax
|
||||
lea eax, [eax*3]
|
||||
add ebx, eax
|
||||
@@:
|
||||
lodsd
|
||||
dec esi
|
||||
bswap eax
|
||||
shr eax, 8
|
||||
stosd
|
||||
loop @b
|
||||
add ebx, sizeof.gif.ImageDescriptor
|
||||
stdcall ._.process_image
|
||||
|
||||
.decoded:
|
||||
or eax, eax
|
||||
@ -187,6 +190,11 @@ endl
|
||||
ret
|
||||
|
||||
.error:
|
||||
mov eax, [img]
|
||||
test eax, eax
|
||||
jz @f
|
||||
stdcall img.destroy, eax
|
||||
@@:
|
||||
xor eax, eax
|
||||
pop ebx
|
||||
ret
|
||||
@ -309,7 +317,7 @@ proc img.decode.gif._.process_extensions ;//////////////////////////////////////
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.gif._.process_image _color_table ;////////////////////////////////////////////////;;
|
||||
proc img.decode.gif._.process_image ;/////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -342,8 +350,6 @@ endl
|
||||
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
|
||||
@ -351,8 +357,6 @@ endl
|
||||
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
|
||||
@ -502,21 +506,11 @@ img.decode.gif._.process_image.output:
|
||||
|
||||
.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
|
||||
stosb
|
||||
|
||||
cmp edi, [row_end]
|
||||
jb .norowend
|
||||
mov eax, [width]
|
||||
; lea eax, [eax * 3]
|
||||
shl eax, 2
|
||||
push eax
|
||||
sub edi, eax
|
||||
add eax, eax
|
||||
|
@ -5,15 +5,15 @@
|
||||
;; 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. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
2231
programs/develop/libraries/libs-dev/libimg/jpeg/jpeg.asm
Normal file
2231
programs/develop/libraries/libs-dev/libimg/jpeg/jpeg.asm
Normal file
File diff suppressed because it is too large
Load Diff
96
programs/develop/libraries/libs-dev/libimg/jpeg/jpeg.inc
Normal file
96
programs/develop/libraries/libs-dev/libimg/jpeg/jpeg.inc
Normal file
@ -0,0 +1,96 @@
|
||||
;;================================================================================================;;
|
||||
;;//// jpeg.inc //// (c) diamond, 2008-2009 //////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
||||
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
|
||||
;; of the License, or (at your option) any later version. ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;;
|
||||
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
|
||||
;; Lesser General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev. ;;
|
||||
;; If not, see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
struct jpeg.work ; working area for JPEG handling
|
||||
image dd ?
|
||||
; progressive JPEG?
|
||||
progressive db ?
|
||||
; one component in the scan?
|
||||
not_interleaved db ?
|
||||
; Adobe YCCK file?
|
||||
adobe_ycck db ?
|
||||
rb 1
|
||||
; parameters for progressive scan
|
||||
ScanStart db ?
|
||||
ScanEnd db ?
|
||||
ApproxPosLow db ?
|
||||
ApproxPosHigh db ?
|
||||
; restart interval
|
||||
restart_interval dd ?
|
||||
decoded_MCUs dd ?
|
||||
|
||||
_esp dd ?
|
||||
|
||||
; components information, up to 4 components
|
||||
; db ComponentIdentifier, db V, db H, db VFactor, db HFactor, db QuantizationTable
|
||||
components rb 4*6
|
||||
max_v db ?
|
||||
max_h db ?
|
||||
cur_rst_marker db ?
|
||||
db ?
|
||||
huffman_bits dd ?
|
||||
block_width dd ?
|
||||
block_height dd ?
|
||||
block_delta_x dd ?
|
||||
block_delta_y dd ?
|
||||
cur_block_dx dd ?
|
||||
cur_block_dy dd ?
|
||||
x_num_blocks dd ?
|
||||
y_num_blocks dd ?
|
||||
delta_x dd ?
|
||||
delta_y dd ?
|
||||
pixel_size dd ?
|
||||
line_size dd ?
|
||||
cur_x dd ?
|
||||
cur_y dd ?
|
||||
max_x dd ?
|
||||
max_y dd ?
|
||||
cur_out_ptr dd ?
|
||||
dct_buffer dd ?
|
||||
dct_buffer_size dd ?
|
||||
;ns dd ?
|
||||
; +0: db V, db H, db VFactor, db HFactor, dd HIncrement, dd VIncrement,
|
||||
; +12: dd QuantizationTable, dd DCTable, dd ACTable,
|
||||
; +24: dd width/HFactor, dd width/HFactor-8k, dd HFactor+1-(width%HFactor),
|
||||
; +36: dd height/VFactor, dd height/VFactor-8m, dd VFactor+1-(height%VFactor),
|
||||
; +48: dw DCPrediction, db ?, db (0 for Y, 80h for Cb,Cr), dd ComponentOffset
|
||||
cur_components rb 4*56
|
||||
cur_components_end dd ?
|
||||
; Fourier coefficients
|
||||
dct_coeff rw 64
|
||||
; Temporary space for IDCT
|
||||
idct_tmp_area rd 64
|
||||
; decoded block 8*8
|
||||
decoded_data rb 8*8
|
||||
; up to 4 quantization tables
|
||||
quant_tables rd 4*64
|
||||
quant_tables_defined rb 4
|
||||
|
||||
; Huffman tables
|
||||
dc_huffman_defined rb 4
|
||||
ac_huffman_defined rb 4
|
||||
; up to 4 DC Huffman tables
|
||||
;dc_huffman rd 4*256*2
|
||||
; up to 4 AC Huffman tables
|
||||
;ac_huffman rd 4*256*2
|
||||
max_hufftable_size = (256 + (9+128)*16)*2
|
||||
dc_huffman rb 4*max_hufftable_size
|
||||
ac_huffman rb 4*max_hufftable_size
|
||||
|
||||
ends
|
@ -1,19 +1,19 @@
|
||||
;;================================================================================================;;
|
||||
;;//// libimg.asm //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;;
|
||||
;;//// libimg.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 of the ;;
|
||||
;; License, or (at your option) any later version. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
@ -25,7 +25,7 @@ public @EXPORT as 'EXPORTS'
|
||||
include '../../../../struct.inc'
|
||||
include '../../../../proc32.inc'
|
||||
include '../../../../macros.inc'
|
||||
purge section,mov;add,sub
|
||||
purge section,mov,add,sub
|
||||
|
||||
include 'libimg.inc'
|
||||
|
||||
@ -33,6 +33,7 @@ section '.flat' code readable align 16
|
||||
|
||||
include 'bmp/bmp.asm'
|
||||
include 'gif/gif.asm'
|
||||
include 'jpeg/jpeg.asm'
|
||||
|
||||
mem.alloc dd ?
|
||||
mem.free dd ?
|
||||
@ -56,6 +57,8 @@ proc lib_init ;/////////////////////////////////////////////////////////////////
|
||||
mov [mem.realloc], ecx
|
||||
mov [dll.load], edx
|
||||
|
||||
call img.initialize.jpeg
|
||||
|
||||
.ok: xor eax,eax
|
||||
ret
|
||||
endp
|
||||
@ -162,6 +165,14 @@ proc img.to_rgb _img ;//////////////////////////////////////////////////////////
|
||||
stosd
|
||||
mov eax, [esi + Image.Height]
|
||||
stosd
|
||||
mov eax, [esi + Image.Type]
|
||||
dec eax
|
||||
jz .bpp8
|
||||
dec eax
|
||||
jz .bpp24
|
||||
dec eax
|
||||
jnz .error_pop
|
||||
; 32 BPP -> 24 BPP
|
||||
mov esi, [esi + Image.Data]
|
||||
|
||||
@@: dec ecx
|
||||
@ -174,6 +185,37 @@ proc img.to_rgb _img ;//////////////////////////////////////////////////////////
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.bpp24:
|
||||
; 24 BPP -> 24 BPP
|
||||
lea ecx, [ecx*3 + 3]
|
||||
mov esi, [esi + Image.Data]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
pop eax
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.bpp8:
|
||||
; 8 BPP -> 24 BPP
|
||||
push ebx
|
||||
mov ebx, [esi + Image.Palette]
|
||||
mov esi, [esi + Image.Data]
|
||||
@@:
|
||||
movzx eax, byte [esi]
|
||||
add esi, 1
|
||||
mov eax, [ebx + eax*4]
|
||||
mov [edi], eax
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
pop ebx
|
||||
pop eax
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
.error_pop:
|
||||
pop eax
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
@ -196,7 +238,7 @@ proc img.decode _data, _length ;////////////////////////////////////////////////
|
||||
jnz @f
|
||||
add ebx, sizeof.FormatsTableEntry
|
||||
cmp dword[ebx], 0
|
||||
jnz @f
|
||||
jnz @b
|
||||
jmp .error
|
||||
@@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length]
|
||||
|
||||
@ -219,7 +261,7 @@ proc img.encode _img, _p_length ;///////////////////////////////////////////////
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.create _width, _height ;/////////////////////////////////////////////////////////////////;;
|
||||
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -233,6 +275,9 @@ proc img.create _width, _height ;///////////////////////////////////////////////
|
||||
or eax, eax
|
||||
jz .error
|
||||
|
||||
mov ecx, [_type]
|
||||
mov [eax + Image.Type], ecx
|
||||
|
||||
push eax
|
||||
|
||||
stdcall img._.resize_data, eax, [_width], [_height]
|
||||
@ -240,7 +285,7 @@ proc img.create _width, _height ;///////////////////////////////////////////////
|
||||
jz .error.2
|
||||
|
||||
pop eax
|
||||
ret
|
||||
jmp .ret
|
||||
|
||||
.error.2:
|
||||
; pop eax
|
||||
@ -248,6 +293,7 @@ proc img.create _width, _height ;///////////////////////////////////////////////
|
||||
xor eax, eax
|
||||
|
||||
.error:
|
||||
.ret:
|
||||
pop ecx
|
||||
ret
|
||||
endp
|
||||
@ -348,39 +394,51 @@ locals
|
||||
scanline_len dd ?
|
||||
endl
|
||||
|
||||
push esi edi
|
||||
stdcall img._.validate, [_img]
|
||||
push ebx esi edi
|
||||
mov ebx, [_img]
|
||||
stdcall img._.validate, ebx
|
||||
or eax, eax
|
||||
jnz .error
|
||||
|
||||
mov esi, [_img]
|
||||
mov ecx, [esi + Image.Height]
|
||||
mov eax, [esi + Image.Width]
|
||||
shl eax, 2
|
||||
mov ecx, [ebx + Image.Height]
|
||||
mov eax, [ebx + Image.Width]
|
||||
call img._.get_scanline_len
|
||||
mov [scanline_len], eax
|
||||
|
||||
push esi
|
||||
|
||||
test [_flip_kind], FLIP_VERTICAL
|
||||
jz .dont_flip_vert
|
||||
|
||||
imul eax, ecx
|
||||
sub eax, [scanline_len]
|
||||
shr ecx, 1
|
||||
mov esi, [esi + Image.Data]
|
||||
mov esi, [ebx + Image.Data]
|
||||
lea edi, [esi + eax]
|
||||
|
||||
.next_line_vert:
|
||||
push ecx
|
||||
|
||||
mov ecx, [scanline_len]
|
||||
push ecx
|
||||
shr ecx, 2
|
||||
@@: lodsd
|
||||
@@: mov eax, [esi]
|
||||
xchg eax, [edi]
|
||||
mov [esi - 4], eax
|
||||
mov [esi], eax
|
||||
add esi, 4
|
||||
add edi, 4
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
pop ecx
|
||||
and ecx, 3
|
||||
jz .cont_line_vert
|
||||
@@:
|
||||
mov al, [esi]
|
||||
xchg al, [edi]
|
||||
mov [esi], al
|
||||
add esi, 1
|
||||
add edi, 1
|
||||
dec ecx
|
||||
jnz @b
|
||||
.cont_line_vert:
|
||||
|
||||
pop ecx
|
||||
mov eax, [scanline_len]
|
||||
@ -391,15 +449,21 @@ endl
|
||||
|
||||
.dont_flip_vert:
|
||||
|
||||
pop esi
|
||||
|
||||
test [_flip_kind], FLIP_HORIZONTAL
|
||||
jz .exit
|
||||
|
||||
mov ecx, [esi + Image.Height]
|
||||
mov esi, [esi + Image.Data]
|
||||
lea edi, [esi - 4]
|
||||
add edi, [scanline_len]
|
||||
mov ecx, [ebx + Image.Height]
|
||||
mov eax, [ebx + Image.Type]
|
||||
mov esi, [ebx + Image.Data]
|
||||
mov edi, [scanline_len]
|
||||
add edi, esi
|
||||
|
||||
dec eax
|
||||
jz .bpp8.2
|
||||
dec eax
|
||||
jz .bpp24.2
|
||||
|
||||
sub edi, 4
|
||||
|
||||
.next_line_horz:
|
||||
push ecx esi edi
|
||||
@ -411,7 +475,7 @@ endl
|
||||
mov [esi], eax
|
||||
add esi, 4
|
||||
add edi, -4
|
||||
dec ecx
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
pop edi esi ecx
|
||||
@ -419,16 +483,71 @@ endl
|
||||
add edi, [scanline_len]
|
||||
dec ecx
|
||||
jnz .next_line_horz
|
||||
jmp .exit
|
||||
|
||||
.bpp8.2:
|
||||
dec edi
|
||||
.next_line_horz8:
|
||||
push ecx esi edi
|
||||
|
||||
mov ecx, [scanline_len]
|
||||
shr ecx, 1
|
||||
@@: mov al, [esi]
|
||||
mov dl, [edi]
|
||||
mov [edi], al
|
||||
mov [esi], dl
|
||||
add esi, 1
|
||||
sub edi, 1
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
pop edi esi ecx
|
||||
add esi, [scanline_len]
|
||||
add edi, [scanline_len]
|
||||
dec ecx
|
||||
jnz .next_line_horz8
|
||||
jmp .exit
|
||||
|
||||
.bpp24.2:
|
||||
sub edi, 3
|
||||
.next_line_horz32:
|
||||
push ecx esi edi
|
||||
|
||||
mov ecx, [ebx + Image.Width]
|
||||
shr ecx, 1
|
||||
@@:
|
||||
mov al, [esi]
|
||||
mov dl, [edi]
|
||||
mov [edi], al
|
||||
mov [esi], dl
|
||||
mov al, [esi+1]
|
||||
mov dl, [edi+1]
|
||||
mov [edi+1], al
|
||||
mov [esi+1], dl
|
||||
mov al, [esi+2]
|
||||
mov dl, [edi+2]
|
||||
mov [edi+2], al
|
||||
mov [esi+2], dl
|
||||
add esi, 3
|
||||
sub edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
pop edi esi ecx
|
||||
add esi, [scanline_len]
|
||||
add edi, [scanline_len]
|
||||
dec ecx
|
||||
jnz .next_line_horz32
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
inc eax
|
||||
pop edi esi
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
.error:
|
||||
xor eax, eax
|
||||
pop edi esi
|
||||
pop edi esi ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
@ -453,7 +572,8 @@ endl
|
||||
mov [line_buffer], 0
|
||||
|
||||
push ebx esi edi
|
||||
stdcall img._.validate, [_img]
|
||||
mov ebx, [_img]
|
||||
stdcall img._.validate, ebx
|
||||
or eax, eax
|
||||
jnz .error
|
||||
|
||||
@ -466,10 +586,9 @@ endl
|
||||
jmp .exit
|
||||
|
||||
.rotate_ccw_low:
|
||||
mov ebx, [_img]
|
||||
mov eax, [ebx + Image.Height]
|
||||
mov [scanline_pixels_new], eax
|
||||
shl eax, 2
|
||||
call img._.get_scanline_len
|
||||
mov [scanline_len_new], eax
|
||||
|
||||
invoke mem.alloc, eax
|
||||
@ -477,8 +596,9 @@ endl
|
||||
jz .error
|
||||
mov [line_buffer], eax
|
||||
|
||||
mov ecx, [ebx + Image.Width]
|
||||
lea eax, [ecx * 4]
|
||||
mov eax, [ebx + Image.Width]
|
||||
mov ecx, eax
|
||||
call img._.get_scanline_len
|
||||
mov [scanline_len_old], eax
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
@ -486,9 +606,14 @@ endl
|
||||
add eax, [ebx + Image.Data]
|
||||
mov [pixels_ptr], eax
|
||||
|
||||
cmp [ebx + Image.Type], Image.bpp8
|
||||
jz .rotate_ccw8
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .rotate_ccw24
|
||||
|
||||
.next_column_ccw_low:
|
||||
dec ecx
|
||||
jz .exchange_dims
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
@ -524,11 +649,109 @@ endl
|
||||
pop ecx
|
||||
jmp .next_column_ccw_low
|
||||
|
||||
.rotate_ccw8:
|
||||
.next_column_ccw_low8:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -1
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [ebx + Image.Data]
|
||||
mov edi, [line_buffer]
|
||||
@@: mov al, [esi]
|
||||
mov [edi], al
|
||||
add esi, edx
|
||||
add edi, 1
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_pixels_new]
|
||||
mov edi, [ebx + Image.Data]
|
||||
lea esi, [edi + 1]
|
||||
mov edx, [scanline_len_old]
|
||||
@@: mov ecx, edx
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, edx
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
add esi, 1
|
||||
sub eax, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
sub [pixels_ptr], eax
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [line_buffer]
|
||||
mov edi, [pixels_ptr]
|
||||
mov edx, ecx
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, edx
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
jmp .next_column_ccw_low8
|
||||
|
||||
.rotate_ccw24:
|
||||
.next_column_ccw_low24:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -3
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [ebx + Image.Data]
|
||||
mov edi, [line_buffer]
|
||||
@@: mov al, [esi]
|
||||
mov [edi], al
|
||||
mov al, [esi+1]
|
||||
mov [edi+1], al
|
||||
mov al, [esi+2]
|
||||
mov [edi+2], al
|
||||
add esi, edx
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_pixels_new]
|
||||
mov edi, [ebx + Image.Data]
|
||||
lea esi, [edi + 3]
|
||||
mov edx, [scanline_len_old]
|
||||
@@: mov ecx, edx
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, edx
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
add esi, 3
|
||||
sub eax, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
sub [pixels_ptr], eax
|
||||
mov ecx, eax
|
||||
mov esi, [line_buffer]
|
||||
mov edi, [pixels_ptr]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, eax
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
jmp .next_column_ccw_low24
|
||||
|
||||
.rotate_cw_low:
|
||||
mov ebx, [_img]
|
||||
mov eax, [ebx + Image.Height]
|
||||
mov [scanline_pixels_new], eax
|
||||
shl eax, 2
|
||||
call img._.get_scanline_len
|
||||
mov [scanline_len_new], eax
|
||||
|
||||
invoke mem.alloc, eax
|
||||
@ -536,8 +759,9 @@ endl
|
||||
jz .error
|
||||
mov [line_buffer], eax
|
||||
|
||||
mov ecx, [ebx + Image.Width]
|
||||
lea eax, [ecx * 4]
|
||||
mov eax, [ebx + Image.Width]
|
||||
mov ecx, eax
|
||||
call img._.get_scanline_len
|
||||
mov [scanline_len_old], eax
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
@ -545,6 +769,11 @@ endl
|
||||
add eax, [ebx + Image.Data]
|
||||
mov [pixels_ptr], eax
|
||||
|
||||
cmp [ebx + Image.Type], Image.bpp8
|
||||
jz .rotate_cw8
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .rotate_cw24
|
||||
|
||||
.next_column_cw_low:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
@ -586,6 +815,110 @@ endl
|
||||
pop ecx
|
||||
jmp .next_column_cw_low
|
||||
|
||||
.rotate_cw8:
|
||||
.next_column_cw_low8:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -1
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [pixels_ptr]
|
||||
add esi, -1
|
||||
mov edi, [line_buffer]
|
||||
@@: mov al, [esi]
|
||||
mov [edi], al
|
||||
sub esi, edx
|
||||
add edi, 1
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_pixels_new]
|
||||
dec eax
|
||||
mov edi, [ebx + Image.Data]
|
||||
add edi, [scanline_len_old]
|
||||
lea esi, [edi + 1]
|
||||
mov edx, [scanline_len_old]
|
||||
@@: mov ecx, edx
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, edx
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
add esi, 1
|
||||
sub eax, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
sub [pixels_ptr], eax
|
||||
mov ecx, eax
|
||||
mov esi, [line_buffer]
|
||||
mov edi, [pixels_ptr]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, eax
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
jmp .next_column_cw_low8
|
||||
|
||||
.rotate_cw24:
|
||||
.next_column_cw_low24:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -3
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [pixels_ptr]
|
||||
add esi, -3
|
||||
mov edi, [line_buffer]
|
||||
@@: mov al, [esi]
|
||||
mov [edi], al
|
||||
mov al, [esi+1]
|
||||
mov [edi+1], al
|
||||
mov al, [esi+2]
|
||||
mov [edi+2], al
|
||||
sub esi, edx
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_pixels_new]
|
||||
dec eax
|
||||
mov edi, [ebx + Image.Data]
|
||||
add edi, [scanline_len_old]
|
||||
lea esi, [edi + 3]
|
||||
mov edx, [scanline_len_old]
|
||||
@@: mov ecx, edx
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, edx
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
add esi, 3
|
||||
sub eax, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_len_new]
|
||||
sub [pixels_ptr], eax
|
||||
mov ecx, eax
|
||||
mov esi, [line_buffer]
|
||||
mov edi, [pixels_ptr]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
mov ecx, eax
|
||||
and ecx, 3
|
||||
rep movsb
|
||||
|
||||
pop ecx
|
||||
jmp .next_column_cw_low24
|
||||
|
||||
.flip:
|
||||
jmp .exit
|
||||
|
||||
@ -640,6 +973,17 @@ proc img._.new ;////////////////////////////////////////////////////////////////
|
||||
;< eax = 0 / pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
invoke mem.alloc, sizeof.Image
|
||||
test eax, eax
|
||||
jz @f
|
||||
push ecx
|
||||
xor ecx, ecx
|
||||
mov [eax + Image.Data], ecx
|
||||
mov [eax + Image.Type], ecx
|
||||
mov [eax + Image.Extended], ecx
|
||||
mov [eax + Image.Previous], ecx
|
||||
mov [eax + Image.Next], ecx
|
||||
pop ecx
|
||||
@@:
|
||||
ret
|
||||
endp
|
||||
|
||||
@ -674,11 +1018,35 @@ proc img._.resize_data _img, _width, _height ;//////////////////////////////////
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
push ebx
|
||||
push ebx esi
|
||||
mov ebx, [_img]
|
||||
mov eax, [_height]
|
||||
; our memory is limited, [_width]*[_height] must not overflow
|
||||
; image with width or height greater than 65535 is most likely bogus
|
||||
cmp word [_width+2], 0
|
||||
jnz .error
|
||||
cmp word [_height+2], 0
|
||||
jnz .error
|
||||
imul eax, [_width]
|
||||
test eax, eax
|
||||
jz .error
|
||||
; do not allow images which require too many memory
|
||||
cmp eax, 4000000h
|
||||
jae .error
|
||||
cmp [ebx + Image.Type], Image.bpp8
|
||||
jz .bpp8
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .bpp24
|
||||
.bpp32:
|
||||
shl eax, 2
|
||||
jmp @f
|
||||
.bpp24:
|
||||
lea eax, [eax*3]
|
||||
jmp @f
|
||||
.bpp8:
|
||||
add eax, 256*4 ; for palette
|
||||
@@:
|
||||
mov esi, eax
|
||||
invoke mem.realloc, [ebx + Image.Data], eax
|
||||
or eax, eax
|
||||
jz .error
|
||||
@ -688,12 +1056,40 @@ proc img._.resize_data _img, _width, _height ;//////////////////////////////////
|
||||
pop [ebx + Image.Width]
|
||||
push [_height]
|
||||
pop [ebx + Image.Height]
|
||||
cmp [ebx + Image.Type], Image.bpp8
|
||||
jnz .ret
|
||||
lea esi, [eax + esi - 256*4]
|
||||
mov [ebx + Image.Palette], esi
|
||||
jmp .ret
|
||||
|
||||
.error:
|
||||
pop ebx
|
||||
xor eax, eax
|
||||
.ret:
|
||||
pop esi ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< --- TBD --- ;;
|
||||
;;================================================================================================;;
|
||||
cmp [ebx + Image.Type], Image.bpp8
|
||||
jz .bpp8.1
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .bpp24.1
|
||||
shl eax, 2
|
||||
jmp @f
|
||||
.bpp24.1:
|
||||
lea eax, [eax*3]
|
||||
.bpp8.1:
|
||||
@@:
|
||||
ret
|
||||
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
@ -710,7 +1106,7 @@ img._.formats_table:
|
||||
; .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
|
||||
.jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
|
||||
dd 0
|
||||
|
||||
|
||||
@ -723,7 +1119,7 @@ img._.formats_table:
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
align 16
|
||||
align 4
|
||||
@EXPORT:
|
||||
|
||||
export \
|
||||
@ -744,3 +1140,12 @@ export \
|
||||
img.unlock_bits , 'img.unlock_bits' , \
|
||||
img.flip , 'img.flip' , \
|
||||
img.rotate , 'img.rotate'
|
||||
|
||||
section '.data' data readable writable align 16
|
||||
; uninitialized data - global constant tables
|
||||
|
||||
; data for YCbCr -> RGB translation
|
||||
color_table_1 rd 256
|
||||
color_table_2 rd 256
|
||||
color_table_3 rd 256
|
||||
color_table_4 rd 256
|
||||
|
@ -1,19 +1,19 @@
|
||||
;;================================================================================================;;
|
||||
;;//// libimg.inc //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;;
|
||||
;;//// libimg.inc //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; This file is part of Common development libraries (Libs-Dev). ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
|
||||
;; General Public License as published by the Free Software Foundation, either version 3 of the ;;
|
||||
;; License, or (at your option) any later version. ;;
|
||||
;; 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 ;;
|
||||
;; General Public License for more details. ;;
|
||||
;; Lesser 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/>. ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
@ -30,10 +30,16 @@ struct Image
|
||||
Height dd ?
|
||||
Next dd ?
|
||||
Previous dd ?
|
||||
Type dd ? ; one of Image.bppN
|
||||
Data dd ?
|
||||
Palette dd ? ; used iff Type eq Image.bpp8
|
||||
Extended dd ?
|
||||
ends
|
||||
|
||||
Image.bpp8 = 1
|
||||
Image.bpp24 = 2
|
||||
Image.bpp32 = 3
|
||||
|
||||
FLIP_VERTICAL = 0x01
|
||||
FLIP_HORIZONTAL = 0x02
|
||||
FLIP_BOTH = FLIP_VERTICAL or FLIP_HORIZONTAL
|
||||
|
Loading…
Reference in New Issue
Block a user