forked from KolibriOS/kolibrios
libimg, version 4:
* decoder for animated GIFs * some fixes in PNG and JPEG decoders * internal image representation now allows 15 and 16 bpp (without conversions in decoders) * decoder for TGA, Z80 from Nable git-svn-id: svn://kolibrios.org@1079 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
3c09ef7d96
commit
1b6868a022
@ -102,8 +102,7 @@ endl
|
||||
jnz .error
|
||||
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
|
||||
.normal:
|
||||
xor eax, eax
|
||||
inc eax ; Image.bpp8
|
||||
m2m eax, Image.bpp8
|
||||
cmp [ebx + bmp.Header.info.BitCount], 8
|
||||
jbe @f
|
||||
mov al, Image.bpp32
|
||||
@ -119,8 +118,7 @@ endl
|
||||
pushd [ebx + bmp.Header.info.Width]
|
||||
jmp .create
|
||||
.old1:
|
||||
xor eax, eax
|
||||
inc eax ; Image.bpp8
|
||||
m2m eax, Image.bpp8
|
||||
cmp [ebx + bmp.Header.info.OldBitCount], 8
|
||||
jbe @f
|
||||
mov al, Image.bpp32
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -61,7 +61,9 @@ gif.Block.Introducer.ImageDescriptor = 0x2C
|
||||
gif.Block.Introducer.EndOfFile = 0x3B
|
||||
|
||||
struct gif.ImageDescriptor ; GIF87a
|
||||
b gif.Block ; Introducer = 2Ch (',')
|
||||
; we read Introducer before parsing gif.ImageDescriptor,
|
||||
; so it is convenient to not include it in struct
|
||||
; 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
|
||||
@ -89,8 +91,8 @@ 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)
|
||||
; 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
|
||||
@ -104,8 +106,10 @@ struct gif.PlainTextExtension ; GIF89a
|
||||
ends
|
||||
|
||||
struct gif.GraphicsControlExtension ; GIF89a
|
||||
e gif.Extension ; Label = F9h
|
||||
BlockSize db ? ; Size of remaining fields (always 04h)
|
||||
; e gif.Extension ; Label = F9h
|
||||
; BlockSize db ? ; Size of remaining fields (always 04h)
|
||||
; previous fields are not included in this structure for convenience
|
||||
; (they are parsed before this)
|
||||
Packed db ? ; Method of graphics disposal to use
|
||||
DelayTime dw ? ; Hundredths of seconds to wait
|
||||
ColorIndex db ? ; Transparent Color Index
|
||||
@ -130,8 +134,9 @@ ends
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
|
||||
struct gif.Image
|
||||
gce gif.GraphicsControlExtension
|
||||
info gif.ImageDescriptor
|
||||
gce gif.GraphicsControlExtension
|
||||
; lsd gif.LogicalScreenDescriptor ; saved only in first image
|
||||
ends
|
||||
|
||||
gif.Null equ 0x1000
|
||||
|
@ -474,8 +474,8 @@ img.decode.jpg:
|
||||
; image type: 8 bpp for grayscale JPEGs, 24 bpp for normal,
|
||||
; 32 bpp for Adobe YCCK
|
||||
push Image.bpp8
|
||||
pop eax
|
||||
cmp edi, 1
|
||||
pop eax ; Image.bpp8 = 1
|
||||
cmp edi, eax
|
||||
jz @f
|
||||
inc eax ; Image.bpp24 = 2
|
||||
cmp edi, 3
|
||||
@ -1621,9 +1621,9 @@ handle_progressive:
|
||||
stosd ; dd VFactor_i+1 - (height % VFactor_i)
|
||||
pop ecx
|
||||
xor eax, eax
|
||||
cmp ebp, 1
|
||||
cmc
|
||||
rcr eax, 1
|
||||
test ebp, ebp
|
||||
setnp al
|
||||
ror eax, 1
|
||||
stosd ; dd DCPrediction
|
||||
mov eax, ebp
|
||||
stosd ; dd ComponentOffset
|
||||
|
@ -35,11 +35,8 @@ include 'bmp/bmp.asm'
|
||||
include 'gif/gif.asm'
|
||||
include 'jpeg/jpeg.asm'
|
||||
include 'png/png.asm'
|
||||
|
||||
mem.alloc dd ?
|
||||
mem.free dd ?
|
||||
mem.realloc dd ?
|
||||
dll.load dd ?
|
||||
include 'tga/tga.asm'
|
||||
include 'z80/z80.asm'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
|
||||
@ -60,6 +57,14 @@ proc lib_init ;/////////////////////////////////////////////////////////////////
|
||||
|
||||
call img.initialize.jpeg
|
||||
|
||||
xor eax, eax
|
||||
cpuid
|
||||
cmp ecx, 'ntel'
|
||||
jnz @f
|
||||
mov dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
|
||||
mov dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
|
||||
@@:
|
||||
|
||||
.ok: xor eax,eax
|
||||
ret
|
||||
endp
|
||||
@ -211,10 +216,267 @@ proc img._.do_rgb ;/////////////////////////////////////////////////////////////
|
||||
mov ecx, [esi + Image.Width]
|
||||
imul ecx, [esi + Image.Height]
|
||||
mov eax, [esi + Image.Type]
|
||||
dec eax
|
||||
jz .bpp8
|
||||
dec eax
|
||||
jz .bpp24
|
||||
jmp dword [.handlers + (eax-1)*4]
|
||||
|
||||
align 16
|
||||
.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
|
||||
ret
|
||||
|
||||
; 15 BPP -> 24 BPP
|
||||
.bpp15.intel:
|
||||
push ebx ebp
|
||||
sub ecx, 4
|
||||
jb .bpp15.tail
|
||||
align 16
|
||||
.bpp15.intel.loop:
|
||||
repeat 2
|
||||
mov ebx, [esi]
|
||||
mov al, [esi]
|
||||
mov ah, [esi+1]
|
||||
add esi, 4
|
||||
and al, 0x1F
|
||||
and ah, 0x1F shl 2
|
||||
mov ebp, ebx
|
||||
mov dl, al
|
||||
mov dh, ah
|
||||
shr al, 2
|
||||
shr ah, 4
|
||||
shl dl, 3
|
||||
shl dh, 1
|
||||
and ebp, 0x1F shl 5
|
||||
add al, dl
|
||||
add ah, dh
|
||||
shr ebp, 2
|
||||
mov [edi], al
|
||||
mov [edi+2], ah
|
||||
mov eax, ebx
|
||||
mov ebx, ebp
|
||||
shr eax, 16
|
||||
shr ebx, 5
|
||||
add ebx, ebp
|
||||
mov ebp, eax
|
||||
mov [edi+1], bl
|
||||
and eax, (0x1F) or (0x1F shl 10)
|
||||
and ebp, 0x1F shl 5
|
||||
lea edx, [eax+eax]
|
||||
shr al, 2
|
||||
mov ebx, ebp
|
||||
shr ah, 4
|
||||
shl dl, 2
|
||||
shr ebx, 2
|
||||
shr ebp, 7
|
||||
add al, dl
|
||||
add ah, dh
|
||||
mov [edi+3], al
|
||||
add ebx, ebp
|
||||
mov [edi+5], ah
|
||||
mov [edi+4], bl
|
||||
add edi, 6
|
||||
end repeat
|
||||
sub ecx, 4
|
||||
jnb .bpp15.intel.loop
|
||||
.bpp15.tail:
|
||||
add ecx, 4
|
||||
jz .bpp15.done
|
||||
@@:
|
||||
movzx eax, word [esi]
|
||||
mov ebx, eax
|
||||
add esi, 2
|
||||
and eax, (0x1F) or (0x1F shl 10)
|
||||
and ebx, 0x1F shl 5
|
||||
lea edx, [eax+eax]
|
||||
shr al, 2
|
||||
mov ebp, ebx
|
||||
shr ebx, 2
|
||||
shr ah, 4
|
||||
shl dl, 2
|
||||
shr ebp, 7
|
||||
add eax, edx
|
||||
add ebx, ebp
|
||||
mov [edi], al
|
||||
mov [edi+1], bl
|
||||
mov [edi+2], ah
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
.bpp15.done:
|
||||
pop ebp ebx
|
||||
ret
|
||||
|
||||
.bpp15.amd:
|
||||
push ebx ebp
|
||||
sub ecx, 4
|
||||
jb .bpp15.tail
|
||||
align 16
|
||||
.bpp15.amd.loop:
|
||||
repeat 4
|
||||
if (% mod 2) = 1
|
||||
mov eax, dword [esi]
|
||||
mov ebx, dword [esi]
|
||||
else
|
||||
movzx eax, word [esi]
|
||||
mov ebx, eax
|
||||
end if
|
||||
add esi, 2
|
||||
and eax, (0x1F) or (0x1F shl 10)
|
||||
and ebx, 0x1F shl 5
|
||||
lea edx, [eax+eax]
|
||||
shr al, 2
|
||||
mov ebp, ebx
|
||||
shr ebx, 2
|
||||
shr ah, 4
|
||||
shl dl, 2
|
||||
shr ebp, 7
|
||||
add eax, edx
|
||||
add ebx, ebp
|
||||
mov [edi], al
|
||||
mov [edi+1], bl
|
||||
mov [edi+2], ah
|
||||
add edi, 3
|
||||
end repeat
|
||||
sub ecx, 4
|
||||
jnb .bpp15.amd.loop
|
||||
jmp .bpp15.tail
|
||||
|
||||
; 16 BPP -> 24 BPP
|
||||
.bpp16.intel:
|
||||
push ebx ebp
|
||||
sub ecx, 4
|
||||
jb .bpp16.tail
|
||||
align 16
|
||||
.bpp16.intel.loop:
|
||||
repeat 2
|
||||
mov ebx, [esi]
|
||||
mov al, [esi]
|
||||
mov ah, [esi+1]
|
||||
add esi, 4
|
||||
and al, 0x1F
|
||||
and ah, 0x1F shl 3
|
||||
mov ebp, ebx
|
||||
mov dl, al
|
||||
mov dh, ah
|
||||
shr al, 2
|
||||
shr ah, 5
|
||||
shl dl, 3
|
||||
and ebp, 0x3F shl 5
|
||||
add al, dl
|
||||
add ah, dh
|
||||
shr ebp, 3
|
||||
mov [edi], al
|
||||
mov [edi+2], ah
|
||||
mov eax, ebx
|
||||
mov ebx, ebp
|
||||
shr eax, 16
|
||||
shr ebx, 6
|
||||
add ebx, ebp
|
||||
mov ebp, eax
|
||||
mov [edi+1], bl
|
||||
and eax, (0x1F) or (0x1F shl 11)
|
||||
and ebp, 0x3F shl 5
|
||||
mov edx, eax
|
||||
shr al, 2
|
||||
mov ebx, ebp
|
||||
shr ah, 5
|
||||
shl dl, 3
|
||||
shr ebx, 3
|
||||
shr ebp, 9
|
||||
add al, dl
|
||||
add ah, dh
|
||||
mov [edi+3], al
|
||||
add ebx, ebp
|
||||
mov [edi+5], ah
|
||||
mov [edi+4], bl
|
||||
add edi, 6
|
||||
end repeat
|
||||
sub ecx, 4
|
||||
jnb .bpp16.intel.loop
|
||||
.bpp16.tail:
|
||||
add ecx, 4
|
||||
jz .bpp16.done
|
||||
@@:
|
||||
movzx eax, word [esi]
|
||||
mov ebx, eax
|
||||
add esi, 2
|
||||
and eax, (0x1F) or (0x1F shl 11)
|
||||
and ebx, 0x3F shl 5
|
||||
mov edx, eax
|
||||
shr al, 2
|
||||
mov ebp, ebx
|
||||
shr ebx, 3
|
||||
shr ah, 5
|
||||
shl dl, 3
|
||||
shr ebp, 9
|
||||
add eax, edx
|
||||
add ebx, ebp
|
||||
mov [edi], al
|
||||
mov [edi+1], bl
|
||||
mov [edi+2], ah
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
.bpp16.done:
|
||||
pop ebp ebx
|
||||
ret
|
||||
|
||||
.bpp16.amd:
|
||||
push ebx ebp
|
||||
sub ecx, 4
|
||||
jb .bpp16.tail
|
||||
align 16
|
||||
.bpp16.amd.loop:
|
||||
repeat 4
|
||||
if (% mod 2) = 1
|
||||
mov eax, dword [esi]
|
||||
mov ebx, dword [esi]
|
||||
else
|
||||
movzx eax, word [esi]
|
||||
mov ebx, eax
|
||||
end if
|
||||
add esi, 2
|
||||
and eax, (0x1F) or (0x1F shl 11)
|
||||
and ebx, 0x3F shl 5
|
||||
mov edx, eax
|
||||
shr al, 2
|
||||
mov ebp, ebx
|
||||
shr ebx, 3
|
||||
shr ah, 5
|
||||
shl dl, 3
|
||||
shr ebp, 9
|
||||
add eax, edx
|
||||
add ebx, ebp
|
||||
mov [edi], al
|
||||
mov [edi+1], bl
|
||||
mov [edi+2], ah
|
||||
add edi, 3
|
||||
end repeat
|
||||
sub ecx, 4
|
||||
jnb .bpp16.amd.loop
|
||||
jmp .bpp16.tail
|
||||
|
||||
align 16
|
||||
.bpp24:
|
||||
; 24 BPP -> 24 BPP
|
||||
lea ecx, [ecx*3 + 3]
|
||||
mov esi, [esi + Image.Data]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
ret
|
||||
|
||||
align 16
|
||||
.bpp32:
|
||||
; 32 BPP -> 24 BPP
|
||||
mov esi, [esi + Image.Data]
|
||||
|
||||
@ -231,31 +493,6 @@ proc img._.do_rgb ;/////////////////////////////////////////////////////////////
|
||||
@@:
|
||||
ret
|
||||
|
||||
.bpp24:
|
||||
; 24 BPP -> 24 BPP
|
||||
lea ecx, [ecx*3 + 3]
|
||||
mov esi, [esi + Image.Data]
|
||||
shr ecx, 2
|
||||
rep movsd
|
||||
ret
|
||||
|
||||
.bpp8:
|
||||
; 8 BPP -> 24 BPP
|
||||
push ebx
|
||||
mov ebx, [esi + Image.Palette]
|
||||
mov esi, [esi + Image.Data]
|
||||
@@:
|
||||
movzx eax, byte [esi]
|
||||
add esi, 1
|
||||
mov eax, [ebx + eax*4]
|
||||
mov [edi], ax
|
||||
shr eax, 16
|
||||
mov [edi+2], al
|
||||
add edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
pop ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
@ -334,6 +571,32 @@ proc img.create _width, _height, _type ;////////////////////////////////////////
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> --- TBD --- ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
mov eax, [_img]
|
||||
mov edx, [eax + Image.Previous]
|
||||
test edx, edx
|
||||
jz @f
|
||||
push [eax + Image.Next]
|
||||
pop [edx + Image.Next]
|
||||
@@:
|
||||
mov edx, [eax + Image.Next]
|
||||
test edx, edx
|
||||
jz @f
|
||||
push [eax + Image.Previous]
|
||||
pop [edx + Image.Previous]
|
||||
@@:
|
||||
stdcall img._.delete, eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
@ -343,8 +606,33 @@ proc img.destroy _img ;/////////////////////////////////////////////////////////
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
;TODO: link Next and Previous
|
||||
stdcall img._.delete, [_img]
|
||||
push 1
|
||||
mov eax, [_img]
|
||||
mov eax, [eax + Image.Previous]
|
||||
.destroy_prev_loop:
|
||||
test eax, eax
|
||||
jz .destroy_prev_done
|
||||
pushd [eax + Image.Previous]
|
||||
stdcall img._.delete, eax
|
||||
test eax, eax
|
||||
jnz @f
|
||||
mov byte [esp+4], 0
|
||||
@@:
|
||||
pop eax
|
||||
jmp .destroy_prev_loop
|
||||
.destroy_prev_done:
|
||||
mov eax, [_img]
|
||||
.destroy_next_loop:
|
||||
pushd [eax + Image.Next]
|
||||
stdcall img._.delete, eax
|
||||
test eax, eax
|
||||
jnz @f
|
||||
mov byte [esp+4], 0
|
||||
@@:
|
||||
pop eax
|
||||
test eax, eax
|
||||
jnz .destroy_next_loop
|
||||
pop eax
|
||||
ret
|
||||
endp
|
||||
|
||||
@ -417,9 +705,9 @@ proc img.unlock_bits _img, _lock ;//////////////////////////////////////////////
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
|
||||
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Flip image ;;
|
||||
;? Flip image layer ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;> _flip_kind = one of FLIP_* constants ;;
|
||||
@ -493,12 +781,9 @@ endl
|
||||
mov esi, [ebx + Image.Data]
|
||||
mov edi, [scanline_len]
|
||||
add edi, esi
|
||||
jmp dword [.handlers_horz + (eax-1)*4]
|
||||
|
||||
dec eax
|
||||
jz .bpp8.2
|
||||
dec eax
|
||||
jz .bpp24.2
|
||||
|
||||
.bpp32_horz:
|
||||
sub edi, 4
|
||||
|
||||
.next_line_horz:
|
||||
@ -521,7 +806,29 @@ endl
|
||||
jnz .next_line_horz
|
||||
jmp .exit
|
||||
|
||||
.bpp8.2:
|
||||
.bpp1x_horz:
|
||||
sub edi, 2
|
||||
.next_line_horz1x:
|
||||
push ecx esi edi
|
||||
|
||||
mov ecx, [ebx + Image.Width]
|
||||
@@: mov ax, [esi]
|
||||
mov dx, [edi]
|
||||
mov [edi], ax
|
||||
mov [esi], dx
|
||||
add esi, 2
|
||||
sub edi, 2
|
||||
sub ecx, 2
|
||||
ja @b
|
||||
|
||||
pop edi esi ecx
|
||||
add esi, [scanline_len]
|
||||
add edi, [scanline_len]
|
||||
dec ecx
|
||||
jnz .next_line_horz1x
|
||||
jmp .exit
|
||||
|
||||
.bpp8_horz:
|
||||
dec edi
|
||||
.next_line_horz8:
|
||||
push ecx esi edi
|
||||
@ -544,13 +851,12 @@ endl
|
||||
jnz .next_line_horz8
|
||||
jmp .exit
|
||||
|
||||
.bpp24.2:
|
||||
.bpp24_horz:
|
||||
sub edi, 3
|
||||
.next_line_horz32:
|
||||
.next_line_horz24:
|
||||
push ecx esi edi
|
||||
|
||||
mov ecx, [ebx + Image.Width]
|
||||
shr ecx, 1
|
||||
@@:
|
||||
mov al, [esi]
|
||||
mov dl, [edi]
|
||||
@ -566,14 +872,14 @@ endl
|
||||
mov [esi+2], dl
|
||||
add esi, 3
|
||||
sub edi, 3
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
sub ecx, 2
|
||||
ja @b
|
||||
|
||||
pop edi esi ecx
|
||||
add esi, [scanline_len]
|
||||
add edi, [scanline_len]
|
||||
dec ecx
|
||||
jnz .next_line_horz32
|
||||
jnz .next_line_horz24
|
||||
|
||||
.exit:
|
||||
xor eax, eax
|
||||
@ -588,9 +894,40 @@ endl
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
|
||||
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Rotate image ;;
|
||||
;? Flip all layers of image ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;> _flip_kind = one of FLIP_* constants ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
push 1
|
||||
mov ebx, [_img]
|
||||
@@:
|
||||
mov eax, [ebx + Image.Previous]
|
||||
test eax, eax
|
||||
jz .loop
|
||||
mov ebx, eax
|
||||
jmp @b
|
||||
.loop:
|
||||
stdcall img.flip.layer, ebx, [_flip_kind]
|
||||
test eax, eax
|
||||
jnz @f
|
||||
mov byte [esp], 0
|
||||
@@:
|
||||
mov ebx, [ebx + Image.Next]
|
||||
test ebx, ebx
|
||||
jnz .loop
|
||||
pop eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Rotate image layer ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;> _rotate_kind = one of ROTATE_* constants ;;
|
||||
@ -646,7 +983,57 @@ endl
|
||||
jz .rotate_ccw8
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .rotate_ccw24
|
||||
cmp [ebx + Image.Type], Image.bpp32
|
||||
jz .rotate_ccw32
|
||||
|
||||
.next_column_ccw_low1x:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -2
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [ebx + Image.Data]
|
||||
mov edi, [line_buffer]
|
||||
@@: mov ax, [esi]
|
||||
mov [edi], ax
|
||||
add esi, edx
|
||||
add edi, 2
|
||||
sub ecx, 1
|
||||
jnz @b
|
||||
|
||||
mov eax, [scanline_pixels_new]
|
||||
mov edi, [ebx + Image.Data]
|
||||
lea esi, [edi + 2]
|
||||
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_low1x
|
||||
|
||||
.rotate_ccw32:
|
||||
.next_column_ccw_low:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
@ -809,7 +1196,59 @@ endl
|
||||
jz .rotate_cw8
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .rotate_cw24
|
||||
cmp [ebx + Image.Type], Image.bpp32
|
||||
jz .rotate_cw32
|
||||
|
||||
.next_column_cw_low1x:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
push ecx
|
||||
|
||||
mov edx, [scanline_len_old]
|
||||
add [scanline_len_old], -2
|
||||
|
||||
mov ecx, [scanline_pixels_new]
|
||||
mov esi, [pixels_ptr]
|
||||
add esi, -2
|
||||
mov edi, [line_buffer]
|
||||
@@: mov ax, [esi]
|
||||
mov [edi], ax
|
||||
sub esi, edx
|
||||
add edi, 2
|
||||
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 + 2]
|
||||
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_low1x
|
||||
|
||||
.rotate_cw32:
|
||||
.next_column_cw_low:
|
||||
dec ecx
|
||||
js .exchange_dims
|
||||
@ -976,6 +1415,92 @@ endl
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Rotate all layers of image ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;> _rotate_kind = one of ROTATE_* constants ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
push 1
|
||||
mov ebx, [_img]
|
||||
@@:
|
||||
mov eax, [ebx + Image.Previous]
|
||||
test eax, eax
|
||||
jz .loop
|
||||
mov ebx, eax
|
||||
jmp @b
|
||||
.loop:
|
||||
stdcall img.rotate.layer, ebx, [_rotate_kind]
|
||||
test eax, eax
|
||||
jnz @f
|
||||
mov byte [esp], 0
|
||||
@@:
|
||||
mov ebx, [ebx + Image.Next]
|
||||
test ebx, ebx
|
||||
jnz .loop
|
||||
pop eax
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Draw image in the window ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _img = pointer to image ;;
|
||||
;>_x = x-coordinate in the window ;;
|
||||
;>_y = y-coordinate in the window ;;
|
||||
;>_width = maximum width to draw ;;
|
||||
;>_height = maximum height to draw ;;
|
||||
;>_xpos = offset in image by x-axis ;;
|
||||
;>_ypos = offset in image by y-axis ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< no return value ;;
|
||||
;;================================================================================================;;
|
||||
push ebx esi edi
|
||||
mov ebx, [_img]
|
||||
stdcall img._.validate, ebx
|
||||
test eax, eax
|
||||
jnz .done
|
||||
mov ecx, [ebx + Image.Width]
|
||||
sub ecx, [_xpos]
|
||||
jbe .done
|
||||
cmp ecx, [_width]
|
||||
jb @f
|
||||
mov ecx, [_width]
|
||||
@@:
|
||||
mov edx, [ebx + Image.Height]
|
||||
sub edx, [_ypos]
|
||||
jbe .done
|
||||
cmp edx, [_height]
|
||||
jb @f
|
||||
mov edx, [_height]
|
||||
@@:
|
||||
mov eax, [ebx + Image.Width]
|
||||
sub eax, ecx
|
||||
call img._.get_scanline_len
|
||||
shl ecx, 16
|
||||
add ecx, edx
|
||||
mov edx, [_x - 2]
|
||||
mov dx, word [_y]
|
||||
mov esi, [ebx + Image.Type]
|
||||
mov esi, [type2bpp + (esi-1)*4]
|
||||
mov edi, [ebx + Image.Palette]
|
||||
mov ebx, [ebx + Image.Data]
|
||||
push ebp
|
||||
push 65
|
||||
pop ebp
|
||||
xchg eax, ebp
|
||||
int 40h
|
||||
pop ebp
|
||||
.done:
|
||||
pop edi esi ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
@ -1015,6 +1540,7 @@ proc img._.new ;////////////////////////////////////////////////////////////////
|
||||
xor ecx, ecx
|
||||
mov [eax + Image.Data], ecx
|
||||
mov [eax + Image.Type], ecx
|
||||
mov [eax + Image.Flags], ecx
|
||||
mov [eax + Image.Extended], ecx
|
||||
mov [eax + Image.Previous], ecx
|
||||
mov [eax + Image.Next], ecx
|
||||
@ -1118,7 +1644,10 @@ img._.get_scanline_len: ;///////////////////////////////////////////////////////
|
||||
jz .bpp8.1
|
||||
cmp [ebx + Image.Type], Image.bpp24
|
||||
jz .bpp24.1
|
||||
shl eax, 2
|
||||
add eax, eax
|
||||
cmp [ebx + Image.Type], Image.bpp32
|
||||
jnz @f
|
||||
add eax, eax
|
||||
jmp @f
|
||||
.bpp24.1:
|
||||
lea eax, [eax*3]
|
||||
@ -1135,7 +1664,7 @@ img._.get_scanline_len: ;///////////////////////////////////////////////////////
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
|
||||
align 4
|
||||
img._.formats_table:
|
||||
.bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
|
||||
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
|
||||
@ -1143,8 +1672,26 @@ img._.formats_table:
|
||||
.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
|
||||
.tga dd img.is.tga, img.decode.tga, img.encode.tga
|
||||
.z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no
|
||||
;signatures in z80 screens at all
|
||||
dd 0
|
||||
|
||||
align 4
|
||||
type2bpp dd 8, 24, 32, 15, 16
|
||||
img._.do_rgb.handlers:
|
||||
dd img._.do_rgb.bpp8
|
||||
dd img._.do_rgb.bpp24
|
||||
dd img._.do_rgb.bpp32
|
||||
dd img._.do_rgb.bpp15.amd ; can be overwritten in lib_init
|
||||
dd img._.do_rgb.bpp16.amd ; can be overwritten in lib_init
|
||||
|
||||
img.flip.layer.handlers_horz:
|
||||
dd img.flip.layer.bpp8_horz
|
||||
dd img.flip.layer.bpp24_horz
|
||||
dd img.flip.layer.bpp32_horz
|
||||
dd img.flip.layer.bpp1x_horz
|
||||
dd img.flip.layer.bpp1x_horz
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
@ -1160,7 +1707,7 @@ align 4
|
||||
|
||||
export \
|
||||
lib_init , 'lib_init' , \
|
||||
0x00010003 , 'version' , \
|
||||
0x00010004 , 'version' , \
|
||||
img.is_img , 'img.is_img' , \
|
||||
img.info , 'img.info' , \
|
||||
img.from_file , 'img.from_file' , \
|
||||
@ -1172,11 +1719,15 @@ export \
|
||||
img.encode , 'img.encode' , \
|
||||
img.create , 'img.create' , \
|
||||
img.destroy , 'img.destroy' , \
|
||||
img.destroy.layer, 'img.destroy.layer', \
|
||||
img.count , 'img.count' , \
|
||||
img.lock_bits , 'img.lock_bits' , \
|
||||
img.unlock_bits , 'img.unlock_bits' , \
|
||||
img.flip , 'img.flip' , \
|
||||
img.rotate , 'img.rotate'
|
||||
img.flip.layer , 'img.flip.layer' , \
|
||||
img.rotate , 'img.rotate' , \
|
||||
img.rotate.layer, 'img.rotate.layer', \
|
||||
img.draw , 'img.draw'
|
||||
|
||||
; import from deflate unpacker
|
||||
; is initialized only when PNG loading is requested
|
||||
@ -1187,11 +1738,21 @@ library kfar_arc, '../File Managers/kfar_arc.obj'
|
||||
import kfar_arc, \
|
||||
deflate_unpack2, 'deflate_unpack2'
|
||||
|
||||
align 4
|
||||
; mutex for unpacker loading
|
||||
deflate_loader_mutex dd 0
|
||||
|
||||
; default palette for GIF - b&w
|
||||
gif_default_palette:
|
||||
db 0, 0, 0
|
||||
db 0xFF, 0xFF, 0xFF
|
||||
|
||||
section '.data' data readable writable align 16
|
||||
; uninitialized data - global constant tables
|
||||
mem.alloc dd ?
|
||||
mem.free dd ?
|
||||
mem.realloc dd ?
|
||||
dll.load dd ?
|
||||
|
||||
; data for YCbCr -> RGB translation
|
||||
color_table_1 rd 256
|
||||
|
@ -34,11 +34,20 @@ struct Image
|
||||
Data dd ?
|
||||
Palette dd ? ; used iff Type eq Image.bpp8
|
||||
Extended dd ?
|
||||
Flags dd ? ; bitfield
|
||||
Delay dd ? ; used iff Image.IsAnimated is set in Flags
|
||||
ends
|
||||
|
||||
; values for Image.Type
|
||||
; must be consecutive to allow fast switch on Image.Type in support functions
|
||||
Image.bpp8 = 1
|
||||
Image.bpp24 = 2
|
||||
Image.bpp32 = 3
|
||||
Image.bpp15 = 4
|
||||
Image.bpp16 = 5
|
||||
|
||||
; bits in Image.Flags
|
||||
Image.IsAnimated = 1
|
||||
|
||||
FLIP_VERTICAL = 0x01
|
||||
FLIP_HORIZONTAL = 0x02
|
||||
|
@ -515,6 +515,8 @@ align 4
|
||||
mov [edi+2], al
|
||||
mov al, [esi+3]
|
||||
mov [edi+3], al
|
||||
add esi, 4
|
||||
add edi, 4
|
||||
sub ecx, 4
|
||||
jnz @b
|
||||
sub edx, 1
|
||||
@ -737,8 +739,10 @@ end repeat
|
||||
sub ebx, ecx
|
||||
jc .convert_done
|
||||
@@:
|
||||
convert_16_to_8
|
||||
mov ax, [esi]
|
||||
add esi, 2
|
||||
convert_16_to_8
|
||||
mov [edi], al
|
||||
add edi, 1
|
||||
sub ecx, 2
|
||||
jnz @b
|
||||
@ -821,8 +825,10 @@ end repeat
|
||||
sub ebx, ecx
|
||||
jc .convert_done
|
||||
@@:
|
||||
convert_16_to_8
|
||||
mov ax, [esi]
|
||||
add esi, 4
|
||||
convert_16_to_8
|
||||
mov [edi], al
|
||||
add edi, 1
|
||||
sub ecx, 4
|
||||
jnz @b
|
||||
|
250
programs/develop/libraries/libs-dev/libimg/tga/tga.asm
Normal file
250
programs/develop/libraries/libs-dev/libimg/tga/tga.asm
Normal file
@ -0,0 +1,250 @@
|
||||
;;================================================================================================;;
|
||||
;;//// tga.asm //// (c) Nable, 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 ;;
|
||||
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
|
||||
;; of the License, or (at your option) any later version. ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;;
|
||||
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
|
||||
;; Lesser General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev. ;;
|
||||
;; If not, see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; References: ;;
|
||||
;; 1. Hiview 1.2 by Mohammad A. REZAEI ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
include 'tga.inc'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.is.tga _data, _length ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Determine if raw data could be decoded (is in Targa format) ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
cmp [_length], 18
|
||||
jbe .nope
|
||||
mov eax, [_data]
|
||||
push ebx
|
||||
mov ebx,[eax+1] ;bl=cmatype,bh=subtype
|
||||
cmp bl,1 ;cmatype is in [0..1]
|
||||
ja .nope
|
||||
cmp bh,11 ;subtype is in [1..3] (non-rle) or in [9..11] (rle)
|
||||
ja .nope
|
||||
cmp bh,9
|
||||
jae .cont1
|
||||
cmp bh,3
|
||||
ja .nope
|
||||
.cont1: ;continue testing
|
||||
mov ebx,[eax+16] ;bl=bpp, bh=flags //image descriptor
|
||||
test ebx,111b ;bpp must be 8, 15, 16, 24 or 32
|
||||
jnz .maybe15
|
||||
shr bl,3
|
||||
cmp bl,4
|
||||
ja .nope
|
||||
jmp .cont2
|
||||
.maybe15:
|
||||
cmp bl,15
|
||||
jne .nope
|
||||
.cont2: ;continue testing
|
||||
test bh,tga.flags.interlace_type ;deinterlacing is not supported yet
|
||||
jnz .nope
|
||||
cmp byte[eax+7],24 ;test palette bpp - only 24 and 32 are supported
|
||||
je .yep
|
||||
cmp byte[eax+7],32 ;test palette bpp - only 24 and 32 are supported
|
||||
je .yep
|
||||
.nope:
|
||||
xor eax, eax
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
.yep:
|
||||
xor eax, eax
|
||||
inc eax
|
||||
pop ebx
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.tga _data, _length ;//////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Decode data into image if it contains correctly formed raw data in Targa format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
locals
|
||||
IMGwidth dd ?
|
||||
IMGheight dd ?
|
||||
IMGbpp dd ?
|
||||
DupPixelCount dd ?
|
||||
TgaBlockCount dd ?
|
||||
endl
|
||||
pushad
|
||||
cld ;paranoia
|
||||
and [DupPixelCount],0 ;prepare variables
|
||||
and [TgaBlockCount],0 ;prepare variables
|
||||
mov eax,[_data]
|
||||
movzx esi,byte[eax]
|
||||
lea esi,[esi+eax+18] ;skip comment and header
|
||||
mov ebx,[eax+12]
|
||||
movzx ecx,bx ;ecx=width
|
||||
shr ebx,16 ;ebx=height
|
||||
mov [IMGwidth],ecx
|
||||
mov [IMGheight],ebx
|
||||
movzx edx,byte[eax+16]
|
||||
cmp edx,16
|
||||
jnz @f
|
||||
dec edx ;16bpp tga images are really 15bpp ARGB
|
||||
@@:
|
||||
sub edx, 16 - Image.bpp16 ; 15 -> Image.bpp15, 16 -> Image.bpp16
|
||||
mov [IMGbpp],edx
|
||||
stdcall img.create,ecx,ebx,edx
|
||||
mov [esp+28],eax ;save return value
|
||||
test eax,eax ;failed to allocate?
|
||||
jz .locret ;then exit
|
||||
cmp edx,8
|
||||
jne .palette_parsed
|
||||
mov edi,[eax+Image.Palette]
|
||||
mov ecx,[_data]
|
||||
cmp byte[ecx+2],3 ;we also have grayscale subtype
|
||||
jz .write_grayscale_palette ;that don't hold palette in file
|
||||
cmp byte[ecx+2],11
|
||||
jz .write_grayscale_palette
|
||||
mov dh,[ecx+7] ;size of colormap entries in bits
|
||||
movzx ecx,word[ecx+5] ;number of colormap entries
|
||||
cmp dh,24
|
||||
jz .skip_24bpp_palette ;test if colormap entries are 24bpp
|
||||
rep movsd ;else they are 32 bpp
|
||||
jmp .palette_parsed
|
||||
.write_grayscale_palette:
|
||||
push eax
|
||||
mov ecx,0x100
|
||||
xor eax,eax
|
||||
@@:
|
||||
stosd
|
||||
add eax,0x010101
|
||||
loop @b
|
||||
pop eax
|
||||
jmp .palette_parsed
|
||||
.skip_24bpp_palette:
|
||||
push eax
|
||||
@@:
|
||||
lodsd
|
||||
dec esi
|
||||
and eax,0xFFFFFF
|
||||
; bswap eax
|
||||
; shr eax,8
|
||||
stosd
|
||||
loop @b
|
||||
pop eax
|
||||
.palette_parsed:
|
||||
mov edi,[eax+Image.Data]
|
||||
imul ebx,[IMGwidth] ;ebx=width*height
|
||||
|
||||
mov edx,[IMGbpp]
|
||||
add edx,7
|
||||
shr edx,3 ;edx=bytes per pixel
|
||||
mov dh,dl ;dh=dl=bytes per pixel
|
||||
|
||||
mov eax,[_data]
|
||||
cmp byte[eax+2],9
|
||||
jb .not_an_rle
|
||||
.tga_read_rle_pixel:
|
||||
cmp [DupPixelCount],0 ;Duplicate previously read pixel?
|
||||
jg .duplicate_previously_read_pixel
|
||||
dec [TgaBlockCount] ;Decrement pixels remaining in block
|
||||
jns .read_non_rle_pixel
|
||||
xor eax,eax
|
||||
lodsb
|
||||
test al,al ;Start of duplicate-pixel block?
|
||||
jns .2
|
||||
and al,0x7f
|
||||
mov [DupPixelCount],eax ;Number of duplications after this one
|
||||
and [TgaBlockCount],0 ;Then read new block header
|
||||
jmp .read_non_rle_pixel
|
||||
.2:
|
||||
mov dword[TgaBlockCount],eax
|
||||
.read_non_rle_pixel:
|
||||
xor eax,eax
|
||||
mov dl,dh
|
||||
@@:
|
||||
shl eax,8
|
||||
lodsb
|
||||
dec dl
|
||||
jnz @b
|
||||
cmp dh,3
|
||||
jne .put_pixel
|
||||
bswap eax
|
||||
shr eax,8
|
||||
jmp .put_pixel
|
||||
.duplicate_previously_read_pixel:
|
||||
dec [DupPixelCount]
|
||||
.put_pixel:
|
||||
mov dl,dh
|
||||
push eax
|
||||
@@:
|
||||
stosb
|
||||
shr eax,8
|
||||
dec dl
|
||||
jnz @b
|
||||
pop eax
|
||||
dec ebx
|
||||
jnz .tga_read_rle_pixel
|
||||
jmp .locret
|
||||
.not_an_rle:
|
||||
movzx edx,dl ;dh contains bpp too (for decoding needs)
|
||||
imul edx,ebx
|
||||
mov ecx,edx
|
||||
rep movsb ;just copy the image
|
||||
.locret:
|
||||
popad
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.encode.tga _img, _p_length ;/////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Encode image into raw data in Targa 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 ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below is private data you should never use directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
;
|
35
programs/develop/libraries/libs-dev/libimg/tga/tga.inc
Normal file
35
programs/develop/libraries/libs-dev/libimg/tga/tga.inc
Normal file
@ -0,0 +1,35 @@
|
||||
;;================================================================================================;;
|
||||
;;//// tga.inc //// (c) Nable, 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 ;;
|
||||
;; 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 tga.FileHeader
|
||||
CommentLength db ?
|
||||
ColormapType db ?
|
||||
SubType db ?
|
||||
DontKnow1 dw ?
|
||||
ColormapSize dw ?
|
||||
ColormapBpp db ?
|
||||
DontKnow2 dd ?
|
||||
Width dw ?
|
||||
Height dw ?
|
||||
BitPerPixel db ?
|
||||
DontKnow3 db ?
|
||||
ends
|
||||
|
||||
tga.flags.top_down_row_order equ 32 ;bit5
|
||||
tga.flags.interlace_type equ 192;bits6/7
|
257
programs/develop/libraries/libs-dev/libimg/z80/z80.asm
Normal file
257
programs/develop/libraries/libs-dev/libimg/z80/z80.asm
Normal file
@ -0,0 +1,257 @@
|
||||
;;================================================================================================;;
|
||||
;;//// z80.asm //// (c) Nable, 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 ;;
|
||||
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
|
||||
;; of the License, or (at your option) any later version. ;;
|
||||
;; ;;
|
||||
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;;
|
||||
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
|
||||
;; Lesser General Public License for more details. ;;
|
||||
;; ;;
|
||||
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev. ;;
|
||||
;; If not, see <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
;; ;;
|
||||
;; References: ;;
|
||||
;; 1. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
include 'z80.inc'
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.is.z80 _data, _length ;//////////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Determine if raw data could be decoded (is in z80 screen format) ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = false / true ;;
|
||||
;;================================================================================================;;
|
||||
xor eax,eax
|
||||
cmp [_length],6929
|
||||
setz al
|
||||
je @f
|
||||
cmp [_length],6912
|
||||
setz al
|
||||
@@:
|
||||
ret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.decode.z80 _data, _length ;//////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Decode data into image if it contains correctly formed raw data in z80 screen format ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;> _data = raw data as read from file/stream ;;
|
||||
;> _length = data length ;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;< eax = 0 (error) or pointer to image ;;
|
||||
;;================================================================================================;;
|
||||
;---------------------------------------------------------------------------------------------------
|
||||
;During the decoding:
|
||||
;bl - PixelLeft (this means how much pixels left to put in current string)
|
||||
;bh - CurrentString
|
||||
;High half of ebx - use DualStos (two frames per one pixel_write)
|
||||
;cl - PixelColorIndexInPalette
|
||||
;ch - BackgroundColorIndexInPalette
|
||||
;High half of ecx - blinking flag
|
||||
;edx - address of current attribute byte
|
||||
;---------------------------------------------------------------------------------------------------
|
||||
locals
|
||||
frame1 dd ?
|
||||
OffsetIn2ndFrame dd ?
|
||||
endl
|
||||
xor eax,eax
|
||||
pushad
|
||||
cld ;paranoia
|
||||
stdcall img.create,256,192,Image.bpp8
|
||||
test eax,eax
|
||||
jz img.decode.z80.locret ;test if allocation failed
|
||||
mov [frame1],eax
|
||||
mov esi,z80._._16color_palette
|
||||
mov ecx,16
|
||||
mov edi,[eax+Image.Palette]
|
||||
rep movsd ;write palette for the first frame
|
||||
mov esi,[_data]
|
||||
cmp [_length],6929
|
||||
jne @f
|
||||
add esi,17 ;in case of 6929 byte files we just skip the info in the begininning.
|
||||
@@:
|
||||
;---------------------------------------------------------------------------------------------------
|
||||
;At first we'll determine if there are any blinking pixels
|
||||
;if no - we'll produce statical single image
|
||||
mov ecx,768
|
||||
lea edx,[esi+6912-768];edx points to attribute area
|
||||
xor ebx,ebx ;begin from <0,0> (for further decoding)
|
||||
@@:
|
||||
test byte[edx+ecx-1],z80.BlinkFlag ;such addressing is a good optimisation
|
||||
;(as I hope), edx is unchanged
|
||||
jnz .decode_z80_with_blinking
|
||||
loop @b
|
||||
.decode_z80_without_blinking:
|
||||
jmp .decode_z80_main_stage
|
||||
|
||||
.decode_z80_with_blinking:
|
||||
or ebx,0xFFFF0000 ;use DualStos
|
||||
mov ecx,eax ;eax still points to the first frame
|
||||
stdcall img.create,256,192,Image.bpp8
|
||||
test eax,eax
|
||||
jz img.decode.z80.failed
|
||||
mov [eax+Image.Previous],ecx
|
||||
mov [ecx+Image.Next],eax
|
||||
mov esi,z80._._16color_palette
|
||||
mov ecx,16
|
||||
mov edi,[eax+Image.Palette]
|
||||
rep movsd ;write palette for the second frame
|
||||
mov eax,[eax+Image.Data]
|
||||
mov [OffsetIn2ndFrame],eax
|
||||
;-------------------------------------------------------------------------------
|
||||
.decode_z80_main_stage:
|
||||
;2nd stage - convert z80 screen to 8bpp image with palette
|
||||
.decode_z80_main_stage_main_loop:
|
||||
test bl,7
|
||||
jnz .decode_z80_main_stage_put_now
|
||||
|
||||
._z80_update_attributes:
|
||||
movsx ecx,byte[edx] ;note that BlinkFlag is the highest bit in attribute
|
||||
;byte, so ecx's highest bit is set automatically
|
||||
shl ecx,5
|
||||
shr cl,5
|
||||
and ch,0xF
|
||||
test ch,1000b
|
||||
jz @f
|
||||
or ecx,1000b ;it has the same size with 'or cl,1000b' but could be faster
|
||||
@@:
|
||||
inc edx
|
||||
|
||||
lodsb
|
||||
mov ah,al
|
||||
|
||||
.decode_z80_main_stage_put_now:
|
||||
shl ah,1
|
||||
;-------------------------------------------------------------------------------
|
||||
._z80_put_pixel:
|
||||
;In: CF - put pixel with color CL, !CF - pixel with color CH
|
||||
;High parts of ebx and ecx - as described above
|
||||
mov al,cl ;'mov' doesn't affect flags
|
||||
jc @f
|
||||
mov al,ch
|
||||
@@:
|
||||
stosb ;'stosb' doesn't affect flags
|
||||
|
||||
test ebx,ebx
|
||||
jns @f
|
||||
test ecx,ecx
|
||||
jns .1
|
||||
mov al,ch
|
||||
.1:
|
||||
xchg [OffsetIn2ndFrame],edi
|
||||
stosb
|
||||
xchg [OffsetIn2ndFrame],edi
|
||||
@@:
|
||||
inc bl ;next pixel
|
||||
jz .decode_z80_main_stage_row_finished
|
||||
jmp .decode_z80_main_stage_main_loop
|
||||
;-------------------------------------------------------------------------------
|
||||
.decode_z80_main_stage_row_finished:
|
||||
cmp bh,191 ;is image finished?
|
||||
jb .decode_z80_main_stage_image_not_finished ;no.
|
||||
.decode_z80_finish:
|
||||
jmp .locret ;now really finished
|
||||
;-------------------------------------------------------------------------------
|
||||
;or not finished yet. Branch according to a row number (see documentation)
|
||||
.decode_z80_main_stage_next_third:
|
||||
sub bh,7
|
||||
sub edi,256*(8-1)
|
||||
jmp .decode_z80_main_stage_main_loop
|
||||
|
||||
.decode_z80_main_stage_image_not_finished:
|
||||
;next row
|
||||
add bh,8 ;refer to documentation
|
||||
add edi,256*(8-1)
|
||||
|
||||
;if finished row is 63 or 127 then we process next third of the image
|
||||
cmp bh,63+8
|
||||
je .decode_z80_main_stage_next_third
|
||||
cmp bh,127+8
|
||||
je .decode_z80_main_stage_next_third
|
||||
|
||||
cmp bh,56+8 ;if finished row in [56;63) or [120;127) or [184;191)
|
||||
jb .decode_z80_main_stage_main_loop
|
||||
cmp bh,63+8
|
||||
jb .4
|
||||
cmp bh,120+8
|
||||
jb .decode_z80_main_stage_main_loop
|
||||
cmp bh,127+8
|
||||
jb .4
|
||||
cmp bh,184+8
|
||||
jb .decode_z80_main_stage_main_loop
|
||||
;note that if we are here then bh is < 191 (see label .2) but >= 184+8
|
||||
.4:
|
||||
;and if we here then bh is in [56;63) or [120;127) or [184;191)
|
||||
sub bh,(8+56-1)
|
||||
sub edi,256*(8+56-1)
|
||||
sub edx,z80.AttrString*8
|
||||
jmp .decode_z80_main_stage_main_loop
|
||||
img.decode.z80.locret:
|
||||
popad
|
||||
ret
|
||||
img.decode.z80.failed:
|
||||
stdcall img.destroy,[frame1]
|
||||
jmp img.decode.z80.locret
|
||||
endp
|
||||
|
||||
;;================================================================================================;;
|
||||
proc img.encode.z80 _img, _p_length ;/////////////////////////////////////////////////////////////;;
|
||||
;;------------------------------------------------------------------------------------------------;;
|
||||
;? Encode image into raw data in z80 screen 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 ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
;! Below is private data you should never use directly from your code ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
z80._._16color_palette:
|
||||
dd 0 ; black
|
||||
dd 0x000000b0 ; blue
|
||||
dd 0x00b00000 ; red
|
||||
dd 0x00b000b0 ; magenta
|
||||
dd 0x0000b000 ; green
|
||||
dd 0x0000b0b0 ; cyan
|
||||
dd 0x00b0b000 ; yellow
|
||||
dd 0x00b0b0b0 ; gray
|
||||
dd 0 ; black
|
||||
dd 0x000000ff ; light blue
|
||||
dd 0x00ff0000 ; light red
|
||||
dd 0x00ff00ff ; light magenta
|
||||
dd 0x0000ff00 ; light green
|
||||
dd 0x0000ffff ; light cyan
|
||||
dd 0x00ffff00 ; light yellow
|
||||
dd 0x00ffffff ; white
|
23
programs/develop/libraries/libs-dev/libimg/z80/z80.inc
Normal file
23
programs/develop/libraries/libs-dev/libimg/z80/z80.inc
Normal file
@ -0,0 +1,23 @@
|
||||
;;================================================================================================;;
|
||||
;;//// z80.inc //// (c) Nable, 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 ;;
|
||||
;; 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/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
z80.PixColor equ 000111b
|
||||
z80.BgrColor equ 111000b
|
||||
z80.BrightFlag equ (1 shl 6)
|
||||
z80.BlinkFlag equ (1 shl 7)
|
||||
z80.AttrString equ 32
|
Loading…
Reference in New Issue
Block a user