libimg: basic xcf support (reading)

git-svn-id: svn://kolibrios.org@1921 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2011-05-02 17:26:50 +00:00
parent b543704e50
commit 6537174613
6 changed files with 2449 additions and 4 deletions

View File

@ -39,6 +39,7 @@ include 'tga/tga.asm'
include 'z80/z80.asm' include 'z80/z80.asm'
include 'ico_cur/ico_cur.asm' include 'ico_cur/ico_cur.asm'
include 'pcx/pcx.asm' include 'pcx/pcx.asm'
include 'xcf/xcf.asm'
;;================================================================================================;; ;;================================================================================================;;
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;; proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
@ -1997,6 +1998,7 @@ img._.formats_table:
.jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
.tga dd img.is.tga, img.decode.tga, img.encode.tga .tga dd img.is.tga, img.decode.tga, img.encode.tga
.pcx dd img.is.pcx, img.decode.pcx, img.encode.pcx .pcx dd img.is.pcx, img.decode.pcx, img.encode.pcx
.xcf dd img.is.xcf, img.decode.xcf, img.encode.xcf
.z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no .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 ;signatures in z80 screens at all
dd 0 dd 0

View File

@ -32,7 +32,7 @@ struct Image
Previous dd ? Previous dd ?
Type dd ? ; one of Image.bppN Type dd ? ; one of Image.bppN
Data dd ? Data dd ?
Palette dd ? ; used iff Type eq Image.bpp8 Palette dd ? ; used iff Type eq Image.bpp8 or Image.bpp1
Extended dd ? Extended dd ?
Flags dd ? ; bitfield Flags dd ? ; bitfield
Delay dd ? ; used iff Image.IsAnimated is set in Flags Delay dd ? ; used iff Image.IsAnimated is set in Flags

View File

@ -23,7 +23,7 @@ include 'pcx.inc'
;;================================================================================================;; ;;================================================================================================;;
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;; proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;? Determine if raw data could be decoded (is in Targa format) ;; ;? Determine if raw data could be decoded (is in pcx format) ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;> _data = raw data as read from file/stream ;; ;> _data = raw data as read from file/stream ;;
;> _length = data length ;; ;> _length = data length ;;
@ -65,7 +65,7 @@ endp
;;================================================================================================;; ;;================================================================================================;;
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;; proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;? Decode data into image if it contains correctly formed raw data in Targa format ;; ;? Decode data into image if it contains correctly formed raw data in pcx format ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;> _data = raw data as read from file/stream ;; ;> _data = raw data as read from file/stream ;;
;> _length = data length ;; ;> _length = data length ;;
@ -290,7 +290,7 @@ endp
;;================================================================================================;; ;;================================================================================================;;
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;; proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;? Encode image into raw data in Targa format ;; ;? Encode image into raw data in pcx format ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;
;> _img = pointer to image ;; ;> _img = pointer to image ;;
;;------------------------------------------------------------------------------------------------;; ;;------------------------------------------------------------------------------------------------;;

View File

@ -0,0 +1,828 @@
proc blend_rgb
xchg al, bh
mov ah, bh
neg ax
add ax, 0xffff
mul ah
neg ah
add ah, 0xff
xchg ah, bh
mov al, 0xff
cmp ah, bh
je @f
not al
div bh
@@:
mov ah, al
movd mm1, eax
; pxor mm0, mm0 ; already xor'ed in composite function
punpcklbw mm1, mm1
punpcklbw mm1, mm0
; punpcklbw mm3, mm0
movq mm7, mm1
psrlw mm7, 7
paddw mm1, mm7
psubw mm3, mm2
pmullw mm3, mm1
psllw mm2, 8
paddw mm3, mm2
pinsrw mm3, ebx, 3
psrlw mm3, 8
packuswb mm3, mm0
movd eax, mm3
ret
endp
proc blend_gray
xchg al, bh
mov ah, bh
neg ax
add ax, 0xffff
mul ah
neg ah
add ah, 0xff
xchg ah, bh
mov al, 0xff
cmp ah, bh
je @f
not al
div bh
@@:
mov ah, al
movd mm1, eax
; pxor mm0, mm0 ; already xor'ed in composite function
punpcklbw mm1, mm1
punpcklbw mm1, mm0
; punpcklbw mm3, mm0
movq mm7, mm1
psrlw mm7, 7
paddw mm1, mm7
psubw mm3, mm2
pmullw mm3, mm1
psllw mm2, 8
paddw mm3, mm2
pinsrw mm3, ebx, 1
psrlw mm3, 8
packuswb mm3, mm0
movd eax, mm3
ret
endp
proc merge_32 _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
.rgb_line:
mov ecx, [_copy_width]
.rgb_pixel:
mov ebx, [edi]
lodsd
movd mm2, ebx
movd mm3, eax
shr eax, 24
shr ebx, 16
cmp al, bh
jna @f
mov al, bh
@@: pxor mm0, mm0
call edx
call blend_rgb
stosd
dec ecx
jnz .rgb_pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .rgb_line
emms
ret
endp
proc merge_8a _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
.gray_line:
mov ecx, [_copy_width]
.gray_pixel:
mov bx, word[edi]
lodsw
movd mm2, ebx
movd mm3, eax
shr eax, 8
cmp al, bh
jna @f
mov al, bh
@@: pxor mm0, mm0
call edx
call blend_gray
stosw
dec ecx
jnz .gray_pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .gray_line
emms
ret
endp
proc composite_rgb_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
.line: mov ecx, [_copy_width]
.pixel: mov ebx, [edi]
lodsd
movd mm2, ebx
movd mm3, eax
shr eax, 24
shr ebx, 16
xchg al, bh
mov ah, bh
neg ax
add ax, 0xffff
mul ah
neg ah
add ah, 0xff
xchg ah, bh
mov al, 0xff
cmp ah, bh
je @f
not al
div bh
@@:
mov ah, al
movd mm1, eax
pxor mm0, mm0
punpcklbw mm1, mm1
punpcklbw mm1, mm0
punpcklbw mm2, mm0
punpcklbw mm3, mm0
psubsw mm3, mm2
pmullw mm3, mm1
psllw mm2, 8
paddw mm3, mm2
pinsrw mm3, ebx, 3
psrlw mm3, 8
packuswb mm3, mm0
movd eax, mm3
stosd
dec ecx
jnz .pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .line
ret
endp
proc composite_gray_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
.line: mov ecx, [_copy_width]
.pixel: mov bx, [edi]
lodsw
movd mm2, ebx
movd mm3, eax
shr eax, 8
xchg al, bh
mov ah, bh
neg ax
add ax, 0xffff
mul ah
neg ah
add ah, 0xff
xchg ah, bh
mov al, 0xff
cmp ah, bh
je @f
not al
div bh
@@:
mov ah, al
movd mm1, eax
pxor mm0, mm0
punpcklbw mm1, mm1
punpcklbw mm1, mm0
punpcklbw mm2, mm0
punpcklbw mm3, mm0
psubw mm3, mm2
pmullw mm3, mm1
psllw mm2, 8
paddw mm3, mm2
pinsrw mm3, ebx, 1
psrlw mm3, 8
packuswb mm3, mm0
movd eax, mm3
stosw
dec ecx
jnz .pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .line
ret
endp
proc composite_indexed_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
.line: mov ecx, [_copy_width]
.pixel: mov bx, [edi]
lodsw
or ah, 0x7f
test ah, 0x80
jnz @f
mov ax, bx
@@: stosw
dec ecx
jnz .pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .line
ret
endp
proc composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
pushad
pxor mm4, mm4
movd mm4, [random_b]
movd mm1, [random_a]
movd mm2, [random_c]
.line: mov ecx, [_copy_width]
.pixel: mov ebx, [edi]
lodsd
movq mm0, mm4
pmuludq mm0, mm1
paddq mm0, mm2
movd edx, mm0
movd mm4, edx
pxor mm0, mm0
rol eax, 8
test al, al
jz @f
shr edx, 17
cmp dl, al
ja @f
ror eax, 8
or eax, 0xff000000
jmp .done
@@: mov eax, ebx
.done: stosd
dec ecx
jnz .pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .line
.quit: popad
ret
endp
proc composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
pushad
pxor mm4, mm4
movd mm4, [random_b]
movd mm1, [random_a]
movd mm2, [random_c]
.line: mov ecx, [_copy_width]
.pixel: mov ebx, [edi]
lodsw
movq mm0, mm4
pmuludq mm0, mm1
paddq mm0, mm2
movd edx, mm0
movd mm4, edx
pxor mm0, mm0
test ah, ah
jz @f
shr edx, 17
cmp dl, ah
ja @f
or ax, 0xff00
jmp .done
@@: mov eax, ebx
.done: stosw
dec ecx
jnz .pixel
add esi, [_img_total_bpl]
add edi, [_bottom_total_bpl]
dec [_copy_height]
jnz .line
.quit: popad
ret
endp
;proc composite_indexed_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
; pushad
;
; pxor mm4, mm4
; movd mm4, [random_b]
; movd mm1, [random_a]
; movd mm2, [random_c]
;
;.line: mov ecx, [_copy_width]
;.pixel: mov ebx, [edi]
; lodsw
;
; movq mm0, mm4
; pmuludq mm0, mm1
; paddq mm0, mm2
; movd edx, mm0
; movd mm4, edx
; pxor mm0, mm0
;
; test ah, ah
; jz @f
; shr edx, 17
; cmp dl, ah
; ja @f
; or ax, 0xff00
; jmp .done
;@@: mov eax, ebx
;.done: stosw
; dec ecx
; jnz .pixel
; add esi, [_img_total_bpl]
; add edi, [_bottom_total_bpl]
; dec [_copy_height]
; jnz .line
;
;.quit: popad
; ret
;endp
proc composite_rgb_03 ; Multiply
punpcklbw mm2, mm0
punpcklbw mm3, mm0
pmullw mm3, mm2
psrlw mm3, 8
ret
endp
proc composite_rgb_04 ; Screen
punpcklbw mm2, mm0
punpcklbw mm3, mm0
movq mm4, [mmx_00ff]
movq mm5, mm4
psubw mm4, mm2
psubw mm5, mm3
pmullw mm4, mm5
psrlw mm4, 8
movq mm3, [mmx_00ff]
psubw mm3, mm4
ret
endp
proc composite_rgb_05 ; Overlay
punpcklbw mm2, mm0
punpcklbw mm3, mm0
movq mm4, [mmx_00ff]
psubw mm4, mm2
pmullw mm3, mm4
psrlw mm3, 7
paddw mm3, mm2
pmullw mm3, mm2
psrlw mm3, 8
ret
endp
proc composite_rgb_06 ; Difference
movq mm4, mm3
pminub mm4, mm2
pmaxub mm3, mm2
psubusb mm3, mm4
punpcklbw mm2, mm0
punpcklbw mm3, mm0
ret
endp
proc composite_rgb_07 ; Addition
paddusb mm3, mm2
punpcklbw mm2, mm0
punpcklbw mm3, mm0
ret
endp
proc composite_rgb_08 ; Subtract
movq mm4, mm2
psubusb mm4, mm3
movq mm3, mm4
punpcklbw mm2, mm0
punpcklbw mm3, mm0
ret
endp
proc composite_rgb_09 ; Darken Only
pminub mm3, mm2
punpcklbw mm2, mm0
punpcklbw mm3, mm0
ret
endp
proc composite_rgb_10 ; Lighten Only
pmaxub mm3, mm2
punpcklbw mm2, mm0
punpcklbw mm3, mm0
ret
endp
proc composite_rgb_11 ; Hue (H of HSV)
push eax ebx ecx edx
movd eax, mm3
movd ebx, mm2
call pixel_rgb2hsv
xchg eax, ebx
call pixel_rgb2hsv
xchg eax, ebx
test ah, ah
jnz @f
ror eax, 8
ror ebx, 8
mov ah, bh
rol eax, 8
rol ebx, 8
@@:
mov ax, bx
call pixel_hsv2rgb
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
.quit:
pop edx ecx ebx eax
ret
endp
proc composite_rgb_12 ; Saturation (S of HSV)
push eax ebx ecx edx
movd eax, mm3
movd ebx, mm2
call pixel_rgb2hsv
xchg eax, ebx
call pixel_rgb2hsv
xchg eax, ebx
ror eax, 8
ror ebx, 8
mov ah, bh
rol eax, 8
rol ebx, 8
mov al, bl
call pixel_hsv2rgb
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
.quit:
pop edx ecx ebx eax
ret
endp
proc composite_rgb_13 ; Color (H and S of HSL)
push eax ebx ecx edx
movd eax, mm3
movd ebx, mm2
call pixel_rgb2hsl
xchg eax, ebx
call pixel_rgb2hsl
xchg eax, ebx
mov al, bl
call pixel_hsl2rgb
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
.quit:
pop edx ecx ebx eax
ret
endp
proc composite_rgb_14 ; Value (V of HSV)
push eax ebx ecx edx
movd eax, mm3
movd ebx, mm2
call pixel_rgb2hsv
xchg eax, ebx
call pixel_rgb2hsv
xchg eax, ebx
ror eax, 8
ror ebx, 8
mov ax, bx
rol eax, 8
rol ebx, 8
call pixel_hsv2rgb
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
.quit:
pop edx ecx ebx eax
ret
endp
proc composite_rgb_15 ; Divide
push eax ebx ecx
movd eax, mm3
movd ebx, mm2
rol eax, 8
rol ebx, 8
xchg eax, ebx
mov ecx, 3
.color: rol eax, 8
rol ebx, 8
shl ax, 8
test bl, bl
jz .clamp1
cmp ah, bl
jae .clamp2
div bl
jmp .done
.clamp1:mov al, 0xff
test ah, ah
jnz @f
not al
@@: jmp .done
.clamp2:mov al, 0xff
jmp .done
.done: mov ah, al
loop .color
ror eax, 8
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
pop ecx ebx eax
ret
endp
proc composite_rgb_16 ; Dodge
push eax ebx ecx
movd eax, mm3
movd ebx, mm2
rol eax, 8
rol ebx, 8
xchg eax, ebx
mov ecx, 3
.color: rol eax, 8
rol ebx, 8
shl ax, 8
neg bl
add bl, 0xff
test bl, bl
jz .clamp1
cmp ah, bl
jae .clamp2
div bl
jmp .done
.clamp1:mov al, 0xff
test ah, ah
jnz @f
not al
@@: jmp .done
.clamp2:mov al, 0xff
jmp .done
.done: mov ah, al
loop .color
ror eax, 8
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
pop ecx ebx eax
ret
endp
proc composite_rgb_17 ; Burn
push eax ebx ecx
movd eax, mm3
movd ebx, mm2
rol eax, 8
rol ebx, 8
xchg eax, ebx
mov ecx, 3
.color: rol eax, 8
rol ebx, 8
shl ax, 8
neg ah
add ah, 0xff
test bl, bl
jz .clamp1
cmp ah, bl
jae .clamp2
div bl
jmp .done
.clamp1:mov al, 0xff
test ah, ah
jnz @f
not al
@@: jmp .done
.clamp2:mov al, 0xff
jmp .done
.done: mov ah, al
neg ah
add ah, 0xff
loop .color
ror eax, 8
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
pop ecx ebx eax
ret
endp
proc composite_rgb_18 ; Hard Light
push eax ebx ecx
movd eax, mm3
movd ebx, mm2
rol eax, 8
rol ebx, 8
mov ecx, 3
.color: rol eax, 8
rol ebx, 8
cmp al, 127
jna .part1
mov ah, 0xff
sub ah, bl
neg al
add al, 0xff
mul ah
shl ax, 1
neg ah
add ah, 0xff
jmp .done
.part1:
mul bl
shl ax, 1
.done: loop .color
ror eax, 8
movd mm3, eax
punpcklbw mm2, mm0
punpcklbw mm3, mm0
pop ecx ebx eax
ret
endp
proc composite_rgb_20 ; Grain Extract
movq mm4, [mmx_0080]
punpcklbw mm2, mm0
punpcklbw mm3, mm0
movq mm5, mm2
psubw mm3, mm4
psubsw mm5, mm3
packuswb mm5, mm0
punpcklbw mm5, mm0
movq mm3, mm5
ret
endp
proc composite_rgb_21 ; Grain Merge
movq mm4, [mmx_0080]
punpcklbw mm2, mm0
punpcklbw mm3, mm0
movq mm5, mm2
psubw mm5, mm4
paddsw mm3, mm5
packuswb mm3, mm0
punpcklbw mm3, mm0
ret
endp
mmx_0080 dq 0x0080008000800080
mmx_00ff dq 0x00ff00ff00ff00ff
mmx_0100 dq 0x0100010001000100

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
;;================================================================================================;;
;;//// xcf.inc //// (c) dunkaist, 2011 ///////////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; 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 xcf_header
magic_string rb 9
version rd 1
reserved rb 1
width rd 1
height rd 1
base_type rd 1
ends
XCF_BASETYPE_RGB equ 0
XCF_BASETYPE_GRAY equ 1
XCF_BASETYPE_INDEXED equ 2
struct xcf_ext
visible rd 1
layer_mode rd 1
offset_x rd 1
offset_y rd 1
opacity rd 1
apply_mask rd 1
type rd 1
planes rd 1
ends