diff --git a/programs/develop/libraries/libs-dev/libimg/libimg.asm b/programs/develop/libraries/libs-dev/libimg/libimg.asm
index 012d174df6..9cc4fcdd74 100644
--- a/programs/develop/libraries/libs-dev/libimg/libimg.asm
+++ b/programs/develop/libraries/libs-dev/libimg/libimg.asm
@@ -40,6 +40,8 @@ include 'z80/z80.asm'
include 'ico_cur/ico_cur.asm'
include 'pcx/pcx.asm'
include 'xcf/xcf.asm'
+include 'tiff/tiff.asm'
+include 'pnm/pnm.asm'
;;================================================================================================;;
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
@@ -1999,6 +2001,8 @@ img._.formats_table:
.tga dd img.is.tga, img.decode.tga, img.encode.tga
.pcx dd img.is.pcx, img.decode.pcx, img.encode.pcx
.xcf dd img.is.xcf, img.decode.xcf, img.encode.xcf
+ .tiff dd img.is.tiff, img.decode.tiff, img.encode.tiff
+ .pnm dd img.is.pnm, img.decode.pnm, img.encode.pnm
.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
diff --git a/programs/develop/libraries/libs-dev/libimg/libimg.inc b/programs/develop/libraries/libs-dev/libimg/libimg.inc
index 2e8b979ef6..86e499201c 100644
--- a/programs/develop/libraries/libs-dev/libimg/libimg.inc
+++ b/programs/develop/libraries/libs-dev/libimg/libimg.inc
@@ -46,6 +46,7 @@ Image.bpp32 = 3
Image.bpp15 = 4
Image.bpp16 = 5
Image.bpp1 = 6
+Image.bpp4 = 7
; bits in Image.Flags
Image.IsAnimated = 1
diff --git a/programs/develop/libraries/libs-dev/libimg/pcx/pcx.asm b/programs/develop/libraries/libs-dev/libimg/pcx/pcx.asm
index 29e7fff75a..07f87869d2 100644
--- a/programs/develop/libraries/libs-dev/libimg/pcx/pcx.asm
+++ b/programs/develop/libraries/libs-dev/libimg/pcx/pcx.asm
@@ -1,5 +1,5 @@
;;================================================================================================;;
-;;//// pcx.asm //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
+;;//// pcx.asm //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
@@ -17,7 +17,7 @@
;; ;;
;;================================================================================================;;
-include 'pcx.inc'
+include 'pcx.inc'
;include '../../../../system/board/trunk/debug.inc'
;;================================================================================================;;
@@ -31,37 +31,37 @@ proc img.is.pcx _data, _length ;////////////////////////////////////////////////
;< eax = false / true ;;
;;================================================================================================;;
- push ecx edi
- xor eax, eax
+ push ecx edi
+ xor eax, eax
- mov edi, [_data]
+ mov edi, [_data]
- cmp [edi+pcx_header.magic_number], 10
- jne .is_not_pcx
- cmp [edi+pcx_header.version], 5
- jne .is_not_pcx
- cmp [edi+pcx_header.encoding], 1
- jne .is_not_pcx
- cmp [edi+pcx_header.reserved], 0
- jne .is_not_pcx
+ cmp [edi + pcx_header.magic_number], 10
+ jne .is_not_pcx
+ cmp [edi + pcx_header.version], 5
+ jne .is_not_pcx
+ cmp [edi + pcx_header.encoding], 1
+ jne .is_not_pcx
+ cmp [edi + pcx_header.reserved], 0
+ jne .is_not_pcx
- add edi, pcx_header.filler
- xor al, al
- mov ecx, 58
- cld
- repe scasb
- test ecx, ecx
- jnz .is_not_pcx
+ add edi, pcx_header.filler
+ xor al, al
+ mov ecx, 58
+ cld
+ repe scasb
+ test ecx, ecx
+ jnz .is_not_pcx
-.is_pcx:
- inc eax
-
-.is_not_pcx:
- pop edi ecx
- ret
+ .is_pcx:
+ inc eax
+ .is_not_pcx:
+ pop edi ecx
+ ret
endp
+
;;================================================================================================;;
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
@@ -73,220 +73,218 @@ proc img.decode.pcx _data, _length, _options ;//////////////////////////////////
;< eax = 0 (error) or pointer to image ;;
;;================================================================================================;;
locals
-nplanes rd 1
-xsize rw 1
-ysize rw 1
-bpl rw 1
-total_bpl rd 1
-line_begin rd 1
-retvalue rd 1 ; 0 (error) or pointer to image
+ nplanes rd 1
+ xsize rw 1
+ ysize rw 1
+ bpl rw 1
+ total_bpl rd 1
+ line_begin rd 1
+ retvalue rd 1 ; 0 (error) or pointer to image
endl
- pusha
+ pusha
- mov esi, [_data]
- movzx eax, byte[esi+pcx_header.nplanes]
- mov [nplanes], eax
- mov bx, word[esi+pcx_header.bpl]
- mov [bpl], bx
- mul bx
- shl eax, 16
- mov ax, dx
- ror eax, 16
- mov [total_bpl], eax
+ mov esi, [_data]
+ movzx eax, byte[esi + pcx_header.nplanes]
+ mov [nplanes], eax
+ mov bx, word[esi + pcx_header.bpl]
+ mov [bpl], bx
+ mul bx
+ shl eax, 16
+ mov ax, dx
+ ror eax, 16
+ mov [total_bpl], eax
- movzx eax, word[esi+pcx_header.xmax]
- inc ax
- sub ax, word[esi+pcx_header.xmin]
- mov [xsize], ax
+ movzx eax, word[esi + pcx_header.xmax]
+ inc ax
+ sub ax, word[esi + pcx_header.xmin]
+ mov [xsize], ax
- movzx ebx, word[esi+pcx_header.ymax]
- inc bx
- sub bx, word[esi+pcx_header.ymin]
- mov [ysize], bx
+ movzx ebx, word[esi + pcx_header.ymax]
+ inc bx
+ sub bx, word[esi + pcx_header.ymin]
+ mov [ysize], bx
- cmp [esi+pcx_header.bpp], 1
- jz .monochrome
- cmp byte[esi+pcx_header.nplanes], 3
- jnz .indexed
+ cmp [esi + pcx_header.bpp], 1
+ jz .monochrome
+ cmp byte[esi + pcx_header.nplanes], 3
+ jnz .indexed
._24bit:
- stdcall img.create, eax, ebx, Image.bpp24
- mov [retvalue], eax
- test eax, eax
- jz .quit
+ stdcall img.create, eax, ebx, Image.bpp24
+ mov [retvalue], eax
+ test eax, eax
+ jz .quit
- movzx ebx, [xsize]
- movzx ecx, [ysize]
- mov edx, [eax+Image.Data]
+ movzx ebx, [xsize]
+ movzx ecx, [ysize]
+ mov edx, [eax+Image.Data]
- rol ebx, 16
- or ebx, ecx
- xor ebx, [edx]
- mov [eax+Image.Checksum], ebx
+ rol ebx, 16
+ or ebx, ecx
+ xor ebx, [edx]
+ mov [eax + Image.Checksum], ebx
- mov esi, [_data]
- add esi, 128
-; mov edi, [retvalue]
- mov edi, [eax+Image.Data]
- add edi, 2
- mov [line_begin], edi
- mov ebx, [total_bpl]
+ mov esi, [_data]
+ add esi, 128
+; mov edi, [retvalue]
+ mov edi, [eax + Image.Data]
+ add edi, 2
+ mov [line_begin], edi
+ mov ebx, [total_bpl]
._24bit.begin:
- mov ax, word[bpl]
+ mov ax, word[bpl]
._24bit.decode:
- call get_byte
+ call pcx._.get_byte
._24bit.write_sequence:
- mov [edi], dl
- dec ax
- add edi, [nplanes]
- dec dh
- jnz ._24bit.write_sequence
+ mov [edi], dl
+ dec ax
+ add edi, [nplanes]
+ dec dh
+ jnz ._24bit.write_sequence
- test ax, ax
- jz ._24bit.end_color_line
- jmp ._24bit.decode
+ test ax, ax
+ jz ._24bit.end_color_line
+ jmp ._24bit.decode
- ._24bit.end_color_line:
- test ebx, ebx
- jz ._24bit.end_full_line
- dec [line_begin]
- mov edi, [line_begin]
- jmp ._24bit.begin
+ ._24bit.end_color_line:
+ test ebx, ebx
+ jz ._24bit.end_full_line
+ dec [line_begin]
+ mov edi, [line_begin]
+ jmp ._24bit.begin
._24bit.end_full_line:
- dec word[ysize]
- jz .quit
- mov ebx, [total_bpl]
- add edi, 2
- mov [line_begin], edi
- jmp ._24bit.begin
+ dec word[ysize]
+ jz .quit
+ mov ebx, [total_bpl]
+ add edi, 2
+ mov [line_begin], edi
+ jmp ._24bit.begin
.indexed:
- stdcall img.create, eax, ebx, Image.bpp8
- mov [retvalue], eax
- test eax, eax
- jz .quit
+ stdcall img.create, eax, ebx, Image.bpp8
+ mov [retvalue], eax
+ test eax, eax
+ jz .quit
- movzx ebx, [xsize]
- movzx ecx, [ysize]
- mov edx, [eax+Image.Data]
+ movzx ebx, [xsize]
+ movzx ecx, [ysize]
+ mov edx, [eax + Image.Data]
- rol ebx, 16
- or ebx, ecx
- xor ebx, [edx]
- mov [eax+Image.Checksum], ebx
+ rol ebx, 16
+ or ebx, ecx
+ xor ebx, [edx]
+ mov [eax + Image.Checksum], ebx
- mov esi, [_data]
- add esi, [_length]
- sub esi, 768
- mov edi, [eax+Image.Palette]
- mov cx, 256
- @@:
- mov ebx, [esi]
- bswap ebx
- shr ebx, 8
- mov [edi], ebx
- add edi, 4
- add esi, 3
- dec cx
- jnz @b
+ mov esi, [_data]
+ add esi, [_length]
+ sub esi, 768
+ mov edi, [eax + Image.Palette]
+ mov cx, 256
+ @@:
+ mov ebx, [esi]
+ bswap ebx
+ shr ebx, 8
+ mov [edi], ebx
+ add edi, 4
+ add esi, 3
+ dec cx
+ jnz @b
- mov esi, [_data]
- add esi, 128
-; mov edi, [retvalue]
- mov edi, [eax+Image.Data]
+ mov esi, [_data]
+ add esi, 128
+; mov edi, [retvalue]
+ mov edi, [eax + Image.Data]
.indexed.begin:
- mov ax, word[bpl]
+ mov ax, word[bpl]
.indexed.decode:
- call get_byte
+ call pcx._.get_byte
.indexed.write_sequence:
- mov [edi], dl
- inc edi
- dec ax
- dec dh
- jnz .indexed.write_sequence
+ mov [edi], dl
+ inc edi
+ dec ax
+ dec dh
+ jnz .indexed.write_sequence
- test ax, ax
- jz .indexed.end_line
- jmp .indexed.decode
+ test ax, ax
+ jz .indexed.end_line
+ jmp .indexed.decode
.indexed.end_line:
- dec word[ysize]
- jz .quit
- jmp .indexed.begin
+ dec word[ysize]
+ jz .quit
+ jmp .indexed.begin
.monochrome:
- stdcall img.create, eax, ebx, Image.bpp1
- mov [retvalue], eax
- test eax, eax
- jz .quit
+ stdcall img.create, eax, ebx, Image.bpp1
+ mov [retvalue], eax
+ test eax, eax
+ jz .quit
- movzx ebx, [xsize]
- movzx ecx, [ysize]
- mov edx, [eax+Image.Data]
+ movzx ebx, [xsize]
+ movzx ecx, [ysize]
+ mov edx, [eax + Image.Data]
- rol ebx, 16
- or ebx, ecx
- xor ebx, [edx]
- mov [eax+Image.Checksum], ebx
+ rol ebx, 16
+ or ebx, ecx
+ xor ebx, [edx]
+ mov [eax + Image.Checksum], ebx
- mov edi, [eax+Image.Palette]
- mov [edi], dword 0x00000000
- mov [edi+4], dword 0x00ffffff
+ mov edi, [eax + Image.Palette]
+ mov [edi], dword 0x00000000
+ mov [edi + 4], dword 0x00ffffff
- mov esi, [_data]
- add esi, 128
-; mov edi, [retvalue]
- mov edi, [eax+Image.Data]
+ mov esi, [_data]
+ add esi, 128
+; mov edi, [retvalue]
+ mov edi, [eax + Image.Data]
.monochrome.begin:
- mov ebx, [total_bpl]
- mov ax, [xsize]
+ mov ebx, [total_bpl]
+ mov ax, [xsize]
.monochrome.decode:
- call get_byte
+ call pcx._.get_byte
.monochrome.write_sequence:
- mov [edi], dl
- inc edi
- cmp ax, 8
- jng .monochrome.is_last_byte_in_line
- sub ax, 8
- dec dh
- jnz .monochrome.write_sequence
- jmp .monochrome.decode
+ mov [edi], dl
+ inc edi
+ cmp ax, 8
+ jng .monochrome.is_last_byte_in_line
+ sub ax, 8
+ dec dh
+ jnz .monochrome.write_sequence
+ jmp .monochrome.decode
.monochrome.is_last_byte_in_line:
- test ebx, ebx
- jng @f
- call get_byte
- jmp .monochrome.is_last_byte_in_line
- @@:
- dec word[ysize]
- jnz .monochrome.begin
- jmp .quit
+ test ebx, ebx
+ jng @f
+ call pcx._.get_byte
+ jmp .monochrome.is_last_byte_in_line
+ @@:
+ dec word[ysize]
+ jnz .monochrome.begin
+ jmp .quit
.quit:
- popa
- mov eax, [retvalue]
- ret
-
+ popa
+ mov eax, [retvalue]
+ ret
endp
-
;;================================================================================================;;
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
@@ -297,8 +295,8 @@ proc img.encode.pcx _img, _p_length, _options ;/////////////////////////////////
;< eax = 0 (error) or pointer to encoded data ;;
;< _p_length = encoded data length ;;
;;================================================================================================;;
- xor eax, eax
- ret
+ xor eax, eax
+ ret
endp
@@ -309,25 +307,26 @@ endp
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
-proc get_byte
+proc pcx._.get_byte
- mov dh, byte[esi]
- inc esi
- cmp dh, 0xC0
- jnb .cycle1
- mov dl, dh
- mov dh, 1
- jmp .exit1
+ mov dh, byte[esi]
+ inc esi
+ cmp dh, 0xC0
+ jnb .cycle1
+ mov dl, dh
+ mov dh, 1
+ jmp .exit1
.cycle1:
- and dh, 0x3F
- mov dl, byte[esi]
- inc esi
+ and dh, 0x3F
+ mov dl, byte[esi]
+ inc esi
.exit1:
- movzx ecx, dh
- sub ebx, ecx
-
- ret
+ movzx ecx, dh
+ sub ebx, ecx
+ ret
endp
+
+
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
@@ -335,5 +334,3 @@ endp
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
-
-;
\ No newline at end of file
diff --git a/programs/develop/libraries/libs-dev/libimg/pcx/pcx.inc b/programs/develop/libraries/libs-dev/libimg/pcx/pcx.inc
index 6be0be0e27..a5996e7956 100644
--- a/programs/develop/libraries/libs-dev/libimg/pcx/pcx.inc
+++ b/programs/develop/libraries/libs-dev/libimg/pcx/pcx.inc
@@ -1,5 +1,5 @@
;;================================================================================================;;
-;;//// pcx.inc //// (c) dunkaist, 2010 ///////////////////////////////////////////////////////////;;
+;;//// pcx.inc //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
@@ -17,21 +17,21 @@
;; ;;
;;================================================================================================;;
-struct pcx_header
- magic_number rb 1
- version rb 1
- encoding rb 1
- bpp rb 1
- xmin rw 1
- ymin rw 1
- xmax rw 1
- ymax rw 1
- hres rw 1
- vres rw 1
- colormap rb 48
- reserved rb 1
- nplanes rb 1
- bpl rw 1
- palette_info rw 1
- filler rb 58
-ends
\ No newline at end of file
+struct pcx_header
+ magic_number rb 1
+ version rb 1
+ encoding rb 1
+ bpp rb 1
+ xmin rw 1
+ ymin rw 1
+ xmax rw 1
+ ymax rw 1
+ hres rw 1
+ vres rw 1
+ colormap rb 48
+ reserved rb 1
+ nplanes rb 1
+ bpl rw 1
+ palette_info rw 1
+ filler rb 58
+ends
diff --git a/programs/develop/libraries/libs-dev/libimg/pnm/pbm.asm b/programs/develop/libraries/libs-dev/libimg/pnm/pbm.asm
new file mode 100644
index 0000000000..0afee4ff92
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/pnm/pbm.asm
@@ -0,0 +1,54 @@
+.pbm:
+ stdcall img.create, [width], [height], Image.bpp1
+ test eax, eax
+ jz .quit
+ mov [retvalue], eax
+ mov ebx, eax
+
+ mov edi, [ebx+Image.Palette]
+ mov [edi], dword 0x00ffffff
+ mov [edi + 4], dword 0x00000000
+
+ cmp [data_type], PNM_ASCII
+ je .pbm.ascii
+
+ .pbm.raw:
+ mov ecx, [ebx+Image.Width]
+ add ecx, 7
+ shr ecx, 3
+ imul ecx, [ebx+Image.Height]
+ mov edi, [ebx+Image.Data]
+ rep movsb
+ jmp .quit
+
+ .pbm.ascii:
+ mov edi, [ebx+Image.Data]
+ .pbm.next_line:
+ mov edx, [width]
+ mov ecx, 7
+ xor eax, eax
+ .pbm.next_char:
+ lodsb
+ cmp al, ' '
+ jna .pbm.next_char
+ .pbm.get_number:
+ cmp al, '1'
+ sete bl
+ shl bl, cl
+ or ah, bl
+ dec ecx
+ jns @f
+ shr eax, 8
+ stosb
+ mov ecx, 7
+ @@:
+ dec edx
+ jnz .pbm.next_char
+ test byte[width], 0x07
+ jz @f
+ shr eax, 8
+ stosb
+ @@:
+ dec [height]
+ jnz .pbm.next_line
+ jmp .quit
diff --git a/programs/develop/libraries/libs-dev/libimg/pnm/pgm.asm b/programs/develop/libraries/libs-dev/libimg/pnm/pgm.asm
new file mode 100644
index 0000000000..8892767138
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/pnm/pgm.asm
@@ -0,0 +1,72 @@
+.pgm:
+ stdcall img.create, [width], [height], Image.bpp8
+ test eax, eax
+ jz .quit
+ mov [retvalue], eax
+ mov ebx, eax
+
+ mov edi, [ebx+Image.Palette]
+ mov eax, 0xff000000
+ @@:
+ stosd
+ add eax, 0x00010101
+ jnc @b
+
+ mov edi, [ebx+Image.Data]
+ mov ecx, [ebx+Image.Width]
+ imul ecx, [ebx+Image.Height]
+
+ cmp [data_type], PNM_ASCII
+ je .pgm.ascii
+
+ .pgm.raw:
+ cmp [maxval], 0xff
+ jne .pgm.raw.scale
+ rep movsb
+ jmp .quit
+
+ .pgm.raw.scale:
+ mov edx, [maxval]
+ mov eax, 0
+ @@:
+ lodsb
+ mov ebx, eax
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ stosb
+ dec ecx
+ jnz @b
+ jmp .quit
+
+ .pgm.ascii:
+ xor eax, eax
+ cmp [maxval], 0xff
+ jne .pgm.ascii.scale
+ .pgm.ascii.next_char:
+ lodsb
+ cmp al, ' '
+ jna .pgm.ascii.next_char
+ call pnm._.get_number
+ mov eax, ebx
+ stosb
+ dec ecx
+ jnz .pgm.ascii.next_char
+ jmp .quit
+
+ .pgm.ascii.scale:
+ mov edx, [maxval]
+ .pgm.ascii.scale.next_char:
+ lodsb
+ cmp al, ' '
+ jna .pgm.ascii.scale.next_char
+ call pnm._.get_number
+ mov eax, ebx
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ stosb
+ dec ecx
+ jnz .pgm.ascii.scale.next_char
+ jmp .quit
+
diff --git a/programs/develop/libraries/libs-dev/libimg/pnm/pnm.asm b/programs/develop/libraries/libs-dev/libimg/pnm/pnm.asm
new file mode 100644
index 0000000000..fab111b84c
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/pnm/pnm.asm
@@ -0,0 +1,230 @@
+;;================================================================================================;;
+;;//// pnm.asm //// (c) dunkaist, 2012 ///////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;; ;;
+;; 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 . ;;
+;; ;;
+;;================================================================================================;;
+
+include 'pnm.inc'
+
+;;================================================================================================;;
+proc img.is.pnm _data, _length ;//////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Determine if raw data could be decoded (is in pnm format) ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _data = raw data as read from file/stream ;;
+;> _length = data length ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = false / true ;;
+;;================================================================================================;;
+
+ xor eax, eax
+
+ mov ecx, [_data]
+ mov cx, word[ecx]
+ xchg cl, ch
+ cmp cx, '1P'
+ jb .is_not_pnm
+ cmp cx, '6P'
+ ja .is_not_pnm
+
+ .is_pnm:
+ inc eax
+ .is_not_pnm:
+ ret
+
+endp
+
+;;================================================================================================;;
+proc img.decode.pnm _data, _length, _options ;////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Decode data into image if it contains correctly formed raw data in pnm format ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _data = raw data as read from file/stream ;;
+;> _length = data length ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = 0 (error) or pointer to image ;;
+;;================================================================================================;;
+locals
+ width rd 1
+ height rd 1
+ pnm_type rd 1
+ data_type rd 1 ; raw or ascii
+ maxval rd 1
+ retvalue rd 1
+endl
+
+ pusha
+
+ mov esi, [_data]
+ lodsw
+ cmp ax, 'P1'
+ jne @f
+ mov [pnm_type], PNM_PBM
+ mov [data_type], PNM_ASCII
+ jmp .parse_header
+ @@:
+ cmp ax, 'P2'
+ jne @f
+ mov [pnm_type], PNM_PGM
+ mov [data_type], PNM_ASCII
+ jmp .parse_header
+ @@:
+ cmp ax, 'P3'
+ jne @f
+ mov [pnm_type], PNM_PPM
+ mov [data_type], PNM_ASCII
+ jmp .parse_header
+ @@:
+ cmp ax, 'P4'
+ jne @f
+ mov [pnm_type], PNM_PBM
+ mov [data_type], PNM_RAW
+ jmp .parse_header
+ @@:
+ cmp ax, 'P5'
+ jne @f
+ mov [pnm_type], PNM_PGM
+ mov [data_type], PNM_RAW
+ jmp .parse_header
+ @@:
+ cmp ax, 'P6'
+ jne @f
+ mov [pnm_type], PNM_PPM
+ mov [data_type], PNM_RAW
+ jmp .parse_header
+ @@:
+
+ .parse_header:
+ xor eax, eax
+ mov [width], eax
+ mov [height], eax
+ mov [maxval], eax
+
+ .next_char:
+ lodsb
+ cmp al, '#'
+ jb .next_char
+ ja .read_number
+ .comment:
+ mov edi, esi
+ mov al, 0x0A
+ mov ecx, edi
+ sub ecx, [_data]
+ neg ecx
+ add ecx, [_length]
+ repne scasb
+ mov esi, edi
+ jmp .next_char
+
+ .read_number:
+ sub eax, 0x30
+ mov ebx, eax
+ @@:
+ lodsb
+ cmp al, '0'
+ jb .number_done
+ sub eax, 0x30
+ imul ebx, 10
+ add ebx, eax
+ jmp @b
+
+ .number_done:
+ cmp [width], 0
+ jne @f
+ mov [width], ebx
+ jmp .next_char
+ @@:
+ cmp [height], 0
+ jne @f
+ mov [height], ebx
+ cmp [pnm_type], PNM_PBM
+ je .header_parsed
+ jmp .next_char
+ @@:
+ mov [maxval], ebx
+
+ .header_parsed:
+
+ mov eax, [pnm_type]
+ cmp eax, PNM_PBM
+ je .pbm
+ cmp eax, PNM_PGM
+ je .pgm
+ cmp eax, PNM_PPM
+ je .ppm
+ jmp .quit
+
+
+include 'pbm.asm'
+include 'pgm.asm'
+include 'ppm.asm'
+
+ .quit:
+ popa
+ mov eax, [retvalue]
+ ret
+
+endp
+
+
+
+;;================================================================================================;;
+proc img.encode.pnm _img, _p_length, _options ;///////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Encode image into raw data in pnm format ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _img = pointer to image ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = 0 (error) or pointer to encoded data ;;
+;< _p_length = encoded data length ;;
+;;================================================================================================;;
+ xor eax, eax
+ ret
+endp
+
+
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;! Below are private procs you should never call directly from your code ;;
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+proc pnm._.get_number
+ sub eax, '0'
+ mov ebx, eax
+ @@:
+ lodsb
+ cmp al, '0'
+ jb .quit
+ sub eax, '0'
+ lea eax, [ebx*8 + eax]
+ lea ebx, [ebx*2 + eax]
+; imul ebx, 10
+; add ebx, eax
+ jmp @b
+ .quit:
+ ret
+endp
+
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;! Below is private data you should never use directly from your code ;;
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+
diff --git a/programs/develop/libraries/libs-dev/libimg/pnm/pnm.inc b/programs/develop/libraries/libs-dev/libimg/pnm/pnm.inc
new file mode 100644
index 0000000000..7bf2538c80
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/pnm/pnm.inc
@@ -0,0 +1,26 @@
+;;================================================================================================;;
+;;//// pnm.inc //// (c) dunkaist, 2012 ///////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;; ;;
+;; 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 . ;;
+;; ;;
+;;================================================================================================;;
+
+PNM_RAW = 0
+PNM_ASCII = 1
+
+PNM_PBM = 0
+PNM_PGM = 1
+PNM_PPM = 2
+
diff --git a/programs/develop/libraries/libs-dev/libimg/pnm/ppm.asm b/programs/develop/libraries/libs-dev/libimg/pnm/ppm.asm
new file mode 100644
index 0000000000..dfcc909d2f
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/pnm/ppm.asm
@@ -0,0 +1,117 @@
+.ppm:
+ stdcall img.create, [width], [height], Image.bpp24
+ test eax, eax
+ jz .quit
+ mov [retvalue], eax
+ mov ebx, eax
+
+ mov edi, [ebx + Image.Data]
+ mov ecx, [ebx + Image.Width]
+ imul ecx, [ebx + Image.Height]
+
+ cmp [data_type], PNM_ASCII
+ je .ppm.ascii
+
+ .ppm.raw:
+ cmp [maxval], 0xff
+ jne .ppm.raw.scale
+ @@:
+ lodsw
+ xchg al, ah
+ movsb
+ stosw
+ dec ecx
+ jnz @b
+ jmp .quit
+ .ppm.raw.scale:
+ mov edx, [maxval]
+ xor eax, eax
+ @@:
+ lodsb
+ mov ebx, eax
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ stosb
+ lodsb
+ mov ebx, eax
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ stosb
+ lodsb
+ mov ebx, eax
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ stosb
+ dec ecx
+ jnz @b
+ jmp .quit
+
+ .ppm.ascii:
+ xor eax, eax
+ cmp [maxval], 0xff
+ jne .ppm.ascii.scale
+ .ppm.ascii.next_char:
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov [edi + 2], bl
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov [edi + 1], bl
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov [edi + 0], bl
+ add edi, 3
+ dec ecx
+ jnz .ppm.ascii.next_char
+ jmp .quit
+
+ .ppm.ascii.scale:
+ mov edx, [maxval]
+ .ppm.ascii.scale.next_char:
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov eax, ebx
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ mov [edi + 2], al
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov eax, ebx
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ mov [edi + 1], al
+ @@:
+ lodsb
+ cmp al, ' '
+ jna @b
+ call pnm._.get_number
+ mov eax, ebx
+ shl eax, 8
+ sub eax, ebx
+ div dl
+ mov [edi + 0], al
+ add edi, 3
+ dec ecx
+ jnz .ppm.ascii.next_char
+ jmp .quit
+
diff --git a/programs/develop/libraries/libs-dev/libimg/tiff/huffman.asm b/programs/develop/libraries/libs-dev/libimg/tiff/huffman.asm
new file mode 100644
index 0000000000..e55e60a300
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/tiff/huffman.asm
@@ -0,0 +1,430 @@
+tiff._.huffman_tree_white.begin:
+ dd 0x00000000, .0
+ .1 dd 0x00000000, .10
+ .11 dd 0x00000000, .110
+ .111 dd 0x00000000, .1110
+ .1111 dd 0x80000000 + 7
+ .1110 dd 0x80000000 + 6
+ .110 dd 0x00000000, .1100
+ .1101 dd 0x00000000, .11010
+ .11011 dd 0x80000000 + 64
+ .11010 dd 0x00000000, .110100
+ .110101 dd 0x80000000 + 15
+ .110100 dd 0x80000000 + 14
+ .1100 dd 0x80000000 + 5
+ .10 dd 0x00000000, .100
+ .101 dd 0x00000000, .1010
+ .1011 dd 0x80000000 + 4
+ .1010 dd 0x00000000, .10100
+ .10101 dd 0x00000000, .101010
+ .101011 dd 0x80000000 + 17
+ .101010 dd 0x80000000 + 16
+ .10100 dd 0x80000000 + 9
+ .100 dd 0x00000000, .1000
+ .1001 dd 0x00000000, .10010
+ .10011 dd 0x80000000 + 8
+ .10010 dd 0x80000000 + 128
+ .1000 dd 0x80000000 + 3
+ .0 dd 0x00000000, .00
+ .01 dd 0x00000000, .010
+ .011 dd 0x00000000, .0110
+ .0111 dd 0x80000000 + 2
+ .0110 dd 0x00000000, .01100
+ .01101 dd 0x00000000, .011010
+ .011011 dd 0x00000000, .0110110
+ .0110111 dd 0x80000000 + 256
+ .0110110 dd 0x00000000, .01101100
+ .01101101 dd 0x00000000, .011011010
+ .011011011 dd 0x80000000 + 1408
+ .011011010 dd 0x80000000 + 1344
+ .01101100 dd 0x00000000, .011011000
+ .011011001 dd 0x80000000 + 1280
+ .011011000 dd 0x80000000 + 1216
+ .011010 dd 0x00000000, .0110100
+ .0110101 dd 0x00000000, .01101010
+ .01101011 dd 0x00000000, .011010110
+ .011010111 dd 0x80000000 + 1152
+ .011010110 dd 0x80000000 + 1088
+ .01101010 dd 0x00000000, .011010100
+ .011010101 dd 0x80000000 + 1024
+ .011010100 dd 0x80000000 + 960
+ .0110100 dd 0x00000000, .01101000
+ .01101001 dd 0x00000000, .011010010
+ .011010011 dd 0x80000000 + 896
+ .011010010 dd 0x80000000 + 832
+ .01101000 dd 0x80000000 + 576
+ .01100 dd 0x00000000, .011000
+ .011001 dd 0x00000000, .0110010
+ .0110011 dd 0x00000000, .01100110
+ .01100111 dd 0x80000000 + 640
+ .01100110 dd 0x00000000, .011001100
+ .011001101 dd 0x80000000 + 768
+ .011001100 dd 0x80000000 + 704
+ .0110010 dd 0x00000000, .01100100
+ .01100101 dd 0x80000000 + 512
+ .01100100 dd 0x80000000 + 448
+ .011000 dd 0x80000000 + 1664
+ .010 dd 0x00000000, .0100
+ .0101 dd 0x00000000, .01010
+ .01011 dd 0x00000000, .010110
+ .010111 dd 0x80000000 + 192
+ .010110 dd 0x00000000, .0101100
+ .0101101 dd 0x00000000, .01011010
+ .01011011 dd 0x80000000 + 58
+ .01011010 dd 0x80000000 + 57
+ .0101100 dd 0x00000000, .01011000
+ .01011001 dd 0x80000000 + 56
+ .01011000 dd 0x80000000 + 55
+ .01010 dd 0x00000000, .010100
+ .010101 dd 0x00000000, .0101010
+ .0101011 dd 0x80000000 + 25
+ .0101010 dd 0x00000000, .01010100
+ .01010101 dd 0x80000000 + 52
+ .01010100 dd 0x80000000 + 51
+ .010100 dd 0x00000000, .0101000
+ .0101001 dd 0x00000000, .01010010
+ .01010011 dd 0x80000000 + 50
+ .01010010 dd 0x80000000 + 49
+ .0101000 dd 0x80000000 + 24
+ .0100 dd 0x00000000, .01000
+ .01001 dd 0x00000000, .010010
+ .010011 dd 0x00000000, .0100110
+ .0100111 dd 0x80000000 + 18
+ .0100110 dd 0x00000000, .01001100
+ .01001101 dd 0x00000000, .010011010
+ .010011011 dd 0x80000000 + 1728
+ .010011010 dd 0x80000000 + 1600
+ .01001100 dd 0x00000000, .010011000
+ .010011001 dd 0x80000000 + 1536
+ .010011000 dd 0x80000000 + 1472
+ .010010 dd 0x00000000, .0100100
+ .0100101 dd 0x00000000, .01001010
+ .01001011 dd 0x80000000 + 60
+ .01001010 dd 0x80000000 + 59
+ .0100100 dd 0x80000000 + 27
+ .01000 dd 0x80000000 + 11
+ .00 dd 0x00000000, .000
+ .001 dd 0x00000000, .0010
+ .0011 dd 0x00000000, .00110
+ .00111 dd 0x80000000 + 10
+ .00110 dd 0x00000000, .001100
+ .001101 dd 0x00000000, .0011010
+ .0011011 dd 0x00000000, .00110110
+ .00110111 dd 0x80000000 + 384
+ .00110110 dd 0x80000000 + 320
+ .0011010 dd 0x00000000, .00110100
+ .00110101 dd 0x80000000 + 0
+ .00110100 dd 0x80000000 + 63
+ .001100 dd 0x00000000, .0011000
+ .0011001 dd 0x00000000, .00110010
+ .00110011 dd 0x80000000 + 62
+ .00110010 dd 0x80000000 + 61
+ .0011000 dd 0x80000000 + 28
+ .0010 dd 0x00000000, .00100
+ .00101 dd 0x00000000, .001010
+ .001011 dd 0x00000000, .0010110
+ .0010111 dd 0x80000000 + 21
+ .0010110 dd 0x00000000, .00101100
+ .00101101 dd 0x80000000 + 44
+ .00101100 dd 0x80000000 + 43
+ .001010 dd 0x00000000, .0010100
+ .0010101 dd 0x00000000, .00101010
+ .00101011 dd 0x80000000 + 42
+ .00101010 dd 0x80000000 + 41
+ .0010100 dd 0x00000000, .00101000
+ .00101001 dd 0x80000000 + 40
+ .00101000 dd 0x80000000 + 39
+ .00100 dd 0x00000000, .001000
+ .001001 dd 0x00000000, .0010010
+ .0010011 dd 0x80000000 + 26
+ .0010010 dd 0x00000000, .00100100
+ .00100101 dd 0x80000000 + 54
+ .00100100 dd 0x80000000 + 53
+ .001000 dd 0x80000000 + 12
+ .000 dd 0x00000000, .0000
+ .0001 dd 0x00000000, .00010
+ .00011 dd 0x00000000, .000110
+ .000111 dd 0x80000000 + 1
+ .000110 dd 0x00000000, .0001100
+ .0001101 dd 0x00000000, .00011010
+ .00011011 dd 0x80000000 + 32
+ .00011010 dd 0x80000000 + 31
+ .0001100 dd 0x80000000 + 19
+ .00010 dd 0x00000000, .000100
+ .000101 dd 0x00000000, .0001010
+ .0001011 dd 0x00000000, .00010110
+ .00010111 dd 0x80000000 + 38
+ .00010110 dd 0x80000000 + 37
+ .0001010 dd 0x00000000, .00010100
+ .00010101 dd 0x80000000 + 36
+ .00010100 dd 0x80000000 + 35
+ .000100 dd 0x00000000, .0001000
+ .0001001 dd 0x00000000, .00010010
+ .00010011 dd 0x80000000 + 34
+ .00010010 dd 0x80000000 + 33
+ .0001000 dd 0x80000000 + 20
+ .0000 dd 0x00000000, .00000
+ .00001 dd 0x00000000, .000010
+ .000011 dd 0x80000000 + 13
+ .000010 dd 0x00000000, .0000100
+ .0000101 dd 0x00000000, .00001010
+ .00001011 dd 0x80000000 + 48
+ .00001010 dd 0x80000000 + 47
+ .0000100 dd 0x80000000 + 23
+ .00000 dd 0x00000000, .000000
+ .000001 dd 0x00000000, .0000010
+ .0000011 dd 0x80000000 + 22
+ .0000010 dd 0x00000000, .00000100
+ .00000101 dd 0x80000000 + 46
+ .00000100 dd 0x80000000 + 45
+ .000000 dd 0x00000000, .0000000
+ .0000001 dd 0x00000000, .00000010
+ .00000011 dd 0x80000000 + 30
+ .00000010 dd 0x80000000 + 29
+ .0000000 dd 0x00000000, .00000000
+ .00000001 dd 0x00000000, .000000010
+ .000000011 dd 0x00000000, .0000000110
+ .0000000111 dd 0x00000000, .00000001110
+ .00000001111 dd 0x00000000, .000000011110
+ .000000011111 dd 0x80000000 + 2560
+ .000000011110 dd 0x80000000 + 2496
+ .00000001110 dd 0x00000000, .000000011100
+ .000000011101 dd 0x80000000 + 2432
+ .000000011100 dd 0x80000000 + 2368
+ .0000000110 dd 0x00000000, .00000001100
+ .00000001101 dd 0x80000000 + 1920
+ .00000001100 dd 0x80000000 + 1856
+ .000000010 dd 0x00000000, .0000000100
+ .0000000101 dd 0x00000000, .00000001010
+ .00000001011 dd 0x00000000, .000000010110
+ .000000010111 dd 0x80000000 + 2304
+ .000000010110 dd 0x80000000 + 2240
+ .00000001010 dd 0x00000000, .000000010100
+ .000000010101 dd 0x80000000 + 2176
+ .000000010100 dd 0x80000000 + 2112
+ .0000000100 dd 0x00000000, .00000001000
+ .00000001001 dd 0x00000000, .000000010010
+ .000000010011 dd 0x80000000 + 2048
+ .000000010010 dd 0x80000000 + 1984
+ .00000001000 dd 0x80000000 + 1792
+ .00000000 dd 0x00000010, .000000000
+ .000000000 dd 0x00000010, .0000000000
+ .0000000000 dd 0x00000010, .00000000000
+ .00000000000 dd 0x00000011, .000000000001
+ .000000000001 dd 0x80000000 + 0xffff
+tiff._.huffman_tree_white.end:
+
+tiff._.huffman_tree_black.begin:
+ dd 0x00000000, .0
+ .1 dd 0x00000000, .10
+ .11 dd 0x80000000 + 2
+ .10 dd 0x80000000 + 3
+ .0 dd 0x00000000, .00
+ .01 dd 0x00000000, .010
+ .011 dd 0x80000000 + 4
+ .010 dd 0x80000000 + 1
+ .00 dd 0x00000000, .000
+ .001 dd 0x00000000, .0010
+ .0011 dd 0x80000000 + 5
+ .0010 dd 0x80000000 + 6
+ .000 dd 0x00000000, .0000
+ .0001 dd 0x00000000, .00010
+ .00011 dd 0x80000000 + 7
+ .00010 dd 0x00000000, .000100
+ .000101 dd 0x80000000 + 8
+ .000100 dd 0x80000000 + 9
+ .0000 dd 0x00000000, .00000
+ .00001 dd 0x00000000, .000010
+ .000011 dd 0x00000000, .0000110
+ .0000111 dd 0x80000000 + 12
+ .0000110 dd 0x00000000, .00001100
+ .00001101 dd 0x00000000, .000011010
+ .000011011 dd 0x00000000, .0000110110
+ .0000110111 dd 0x80000000 + 0
+ .0000110110 dd 0x00000000, .00001101100
+ .00001101101 dd 0x00000000, .000011011010
+ .000011011011 dd 0x80000000 + 43
+ .000011011010 dd 0x80000000 + 42
+ .00001101100 dd 0x80000000 + 21
+ .000011010 dd 0x00000000, .0000110100
+ .0000110101 dd 0x00000000, .00001101010
+ .00001101011 dd 0x00000000, .000011010110
+ .000011010111 dd 0x80000000 + 39
+ .000011010110 dd 0x80000000 + 38
+ .00001101010 dd 0x00000000, .000011010100
+ .000011010101 dd 0x80000000 + 37
+ .000011010100 dd 0x80000000 + 36
+ .0000110100 dd 0x00000000, .00001101000
+ .00001101001 dd 0x00000000, .000011010010
+ .000011010011 dd 0x80000000 + 35
+ .000011010010 dd 0x80000000 + 34
+ .00001101000 dd 0x80000000 + 20
+ .00001100 dd 0x00000000, .000011000
+ .000011001 dd 0x00000000, .0000110010
+ .0000110011 dd 0x00000000, .00001100110
+ .00001100111 dd 0x80000000 + 19
+ .00001100110 dd 0x00000000, .000011001100
+ .000011001101 dd 0x80000000 + 29
+ .000011001100 dd 0x80000000 + 28
+ .0000110010 dd 0x00000000, .00001100100
+ .00001100101 dd 0x00000000, .000011001010
+ .000011001011 dd 0x80000000 + 27
+ .000011001010 dd 0x80000000 + 26
+ .00001100100 dd 0x00000000, .000011001000
+ .000011001001 dd 0x80000000 + 192
+ .000011001000 dd 0x80000000 + 128
+ .000011000 dd 0x80000000 + 15
+ .000010 dd 0x00000000, .0000100
+ .0000101 dd 0x80000000 + 11
+ .0000100 dd 0x80000000 + 10
+ .00000 dd 0x00000000, .000000
+ .000001 dd 0x00000000, .0000010
+ .0000011 dd 0x00000000, .00000110
+ .00000111 dd 0x80000000 + 14
+ .00000110 dd 0x00000000, .000001100
+ .000001101 dd 0x00000000, .0000011010
+ .0000011011 dd 0x00000000, .00000110110
+ .00000110111 dd 0x80000000 + 22
+ .00000110110 dd 0x00000000, .000001101100
+ .000001101101 dd 0x80000000 + 41
+ .000001101100 dd 0x80000000 + 40
+ .0000011010 dd 0x00000000, .00000110100
+ .00000110101 dd 0x00000000, .000001101010
+ .000001101011 dd 0x80000000 + 33
+ .000001101010 dd 0x80000000 + 32
+ .00000110100 dd 0x00000000, .000001101000
+ .000001101001 dd 0x80000000 + 31
+ .000001101000 dd 0x80000000 + 30
+ .000001100 dd 0x00000000, .0000011000
+ .0000011001 dd 0x00000000, .00000110010
+ .00000110011 dd 0x00000000, .000001100110
+ .000001100111 dd 0x80000000 + 63
+ .000001100110 dd 0x80000000 + 62
+ .00000110010 dd 0x00000000, .000001100100
+ .000001100101 dd 0x80000000 + 49
+ .000001100100 dd 0x80000000 + 48
+ .0000011000 dd 0x80000000 + 17
+ .0000010 dd 0x00000000, .00000100
+ .00000101 dd 0x00000000, .000001010
+ .000001011 dd 0x00000000, .0000010110
+ .0000010111 dd 0x80000000 + 16
+ .0000010110 dd 0x00000000, .00000101100
+ .00000101101 dd 0x00000000, .000001011010
+ .000001011011 dd 0x80000000 + 256
+ .000001011010 dd 0x80000000 + 61
+ .00000101100 dd 0x00000000, .000001011000
+ .000001011001 dd 0x80000000 + 58
+ .000001011000 dd 0x80000000 + 57
+ .000001010 dd 0x00000000, .0000010100
+ .0000010101 dd 0x00000000, .00000101010
+ .00000101011 dd 0x00000000, .000001010110
+ .000001010111 dd 0x80000000 + 47
+ .000001010110 dd 0x80000000 + 46
+ .00000101010 dd 0x00000000, .000001010100
+ .000001010101 dd 0x80000000 + 45
+ .000001010100 dd 0x80000000 + 44
+ .0000010100 dd 0x00000000, .00000101000
+ .00000101001 dd 0x00000000, .000001010010
+ .000001010011 dd 0x80000000 + 51
+ .000001010010 dd 0x80000000 + 50
+ .00000101000 dd 0x80000000 + 23
+ .00000100 dd 0x80000000 + 13
+ .000000 dd 0x00000000, .0000000
+ .0000001 dd 0x00000000, .00000010
+ .00000011 dd 0x00000000, .000000110
+ .000000111 dd 0x00000000, .0000001110
+ .0000001111 dd 0x80000000 + 64
+ .0000001110 dd 0x00000000, .00000011100
+ .00000011101 dd 0x00000000, .000000111010
+ .000000111011 dd 0x00000000, .0000001110110
+ .0000001110111 dd 0x80000000 + 1216
+ .0000001110110 dd 0x80000000 + 1152
+ .000000111010 dd 0x00000000, .0000001110100
+ .0000001110101 dd 0x80000000 + 1088
+ .0000001110100 dd 0x80000000 + 1024
+ .00000011100 dd 0x00000000, .000000111000
+ .000000111001 dd 0x00000000, .0000001110010
+ .0000001110011 dd 0x80000000 + 960
+ .0000001110010 dd 0x80000000 + 896
+ .000000111000 dd 0x80000000 + 54
+ .000000110 dd 0x00000000, .0000001100
+ .0000001101 dd 0x00000000, .00000011010
+ .00000011011 dd 0x00000000, .000000110110
+ .000000110111 dd 0x80000000 + 53
+ .000000110110 dd 0x00000000, .0000001101100
+ .0000001101101 dd 0x80000000 + 576
+ .0000001101100 dd 0x80000000 + 512
+ .00000011010 dd 0x00000000, .000000110100
+ .000000110101 dd 0x80000000 + 448
+ .000000110100 dd 0x80000000 + 384
+ .0000001100 dd 0x00000000, .00000011000
+ .00000011001 dd 0x00000000, .000000110010
+ .000000110011 dd 0x80000000 + 320
+ .000000110010 dd 0x00000000, .0000001100100
+ .0000001100101 dd 0x80000000 + 1728
+ .0000001100100 dd 0x80000000 + 1664
+ .00000011000 dd 0x80000000 + 25
+ .00000010 dd 0x00000000, .000000100
+ .000000101 dd 0x00000000, .0000001010
+ .0000001011 dd 0x00000000, .00000010110
+ .00000010111 dd 0x80000000 + 24
+ .00000010110 dd 0x00000000, .000000101100
+ .000000101101 dd 0x00000000, .0000001011010
+ .0000001011011 dd 0x80000000 + 1600
+ .0000001011010 dd 0x80000000 + 1536
+ .000000101100 dd 0x80000000 + 60
+ .0000001010 dd 0x00000000, .00000010100
+ .00000010101 dd 0x00000000, .000000101010
+ .000000101011 dd 0x80000000 + 59
+ .000000101010 dd 0x00000000, .0000001010100
+ .0000001010101 dd 0x80000000 + 1472
+ .0000001010100 dd 0x80000000 + 1408
+ .00000010100 dd 0x00000000, .000000101000
+ .000000101001 dd 0x00000000, .0000001010010
+ .0000001010011 dd 0x80000000 + 1344
+ .0000001010010 dd 0x80000000 + 1280
+ .000000101000 dd 0x80000000 + 56
+ .000000100 dd 0x00000000, .0000001000
+ .0000001001 dd 0x00000000, .00000010010
+ .00000010011 dd 0x00000000, .000000100110
+ .000000100111 dd 0x80000000 + 55
+ .000000100110 dd 0x00000000, .0000001001100
+ .0000001001101 dd 0x80000000 + 832
+ .0000001001100 dd 0x80000000 + 768
+ .00000010010 dd 0x00000000, .000000100100
+ .000000100101 dd 0x00000000, .0000001001010
+ .0000001001011 dd 0x80000000 + 704
+ .0000001001010 dd 0x80000000 + 640
+ .000000100100 dd 0x80000000 + 52
+ .0000001000 dd 0x80000000 + 18
+ .0000000 dd 0x00000000, .00000000
+ .00000001 dd 0x00000000, .000000010
+ .000000011 dd 0x00000000, .0000000110
+ .0000000111 dd 0x00000000, .00000001110
+ .00000001111 dd 0x00000000, .000000011110
+ .000000011111 dd 0x80000000 + 2560
+ .000000011110 dd 0x80000000 + 2496
+ .00000001110 dd 0x00000000, .000000011100
+ .000000011101 dd 0x80000000 + 2432
+ .000000011100 dd 0x80000000 + 2368
+ .0000000110 dd 0x00000000, .00000001100
+ .00000001101 dd 0x80000000 + 1920
+ .00000001100 dd 0x80000000 + 1856
+ .000000010 dd 0x00000000, .0000000100
+ .0000000101 dd 0x00000000, .00000001010
+ .00000001011 dd 0x00000000, .000000010110
+ .000000010111 dd 0x80000000 + 2304
+ .000000010110 dd 0x80000000 + 2240
+ .00000001010 dd 0x00000000, .000000010100
+ .000000010101 dd 0x80000000 + 2176
+ .000000010100 dd 0x80000000 + 2112
+ .0000000100 dd 0x00000000, .00000001000
+ .00000001001 dd 0x00000000, .000000010010
+ .000000010011 dd 0x80000000 + 2048
+ .000000010010 dd 0x80000000 + 1984
+ .00000001000 dd 0x80000000 + 1792
+ .00000000 dd 0x00000010, .000000000
+ .000000000 dd 0x00000010, .0000000000
+ .0000000000 dd 0x00000010, .00000000000
+ .00000000000 dd 0x80000000 + 0xffff
+tiff._.huffman_tree_black.end:
diff --git a/programs/develop/libraries/libs-dev/libimg/tiff/tiff.asm b/programs/develop/libraries/libs-dev/libimg/tiff/tiff.asm
new file mode 100644
index 0000000000..d38646f7cd
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/tiff/tiff.asm
@@ -0,0 +1,853 @@
+;;================================================================================================;;
+;;//// tiff.asm //// (c) dunkaist, 2011-2012 /////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;; ;;
+;; 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 . ;;
+;; ;;
+;;================================================================================================;;
+
+include 'tiff.inc'
+;include '../../../../../system/board/trunk/debug.inc'
+
+;;================================================================================================;;
+proc img.is.tiff _data, _length ;/////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Determine if raw data could be decoded (is in tiff format) ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _data = raw data as read from file/stream ;;
+;> _length = data length ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = false / true ;;
+;;================================================================================================;;
+
+ push esi
+
+ mov esi, [_data]
+ lodsw
+ cmp ax, word 'II'
+ je .little_endian
+ cmp ax, word 'MM'
+ je .big_endian
+ jmp .is_not_tiff
+
+ .little_endian:
+ lodsw
+ cmp ax, 0x002A
+ je .is_tiff
+ jmp .is_not_tiff
+
+ .big_endian:
+ lodsw
+ cmp ax, 0x2A00
+ je .is_tiff
+
+ .is_not_tiff:
+ pop esi
+ xor eax, eax
+ ret
+
+ .is_tiff:
+ pop esi
+ xor eax, eax
+ inc eax
+ ret
+endp
+
+;;================================================================================================;;
+proc img.decode.tiff _data, _length, _options ;///////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Decode data into image if it contains correctly formed raw data in tiff format ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _data = raw data as read from file/stream ;;
+;> _length = data length ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = 0 (error) or pointer to image ;;
+;;================================================================================================;;
+locals
+ _endianness rd 1 ; 0 stands for LE, otherwise BE
+ retvalue rd 1 ; 0 (error) or pointer to image
+endl
+
+ push ebx edx esi edi
+
+ mov esi, [_data]
+ lodsw
+ mov [_endianness], 0
+ cmp ax, word 'II'
+ seta byte[_endianness]
+
+ lodsw_
+ lodsd_
+ @@:
+ stdcall tiff._.parse_IFD, [_data], eax, [_endianness]
+ mov ebx, eax
+ mov [retvalue], eax
+ lodsd_
+ test eax, eax
+; jnz @b
+
+
+ .quit:
+ mov eax, [retvalue]
+ pop edi esi edx ebx
+ ret
+endp
+
+
+;;================================================================================================;;
+proc img.encode.tiff _img, _p_length, _options ;//////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? Encode image into raw data in tiff format ;;
+;;------------------------------------------------------------------------------------------------;;
+;> _img = pointer to image ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = 0 (error) or pointer to encoded data ;;
+;< _p_length = encoded data length ;;
+;;================================================================================================;;
+ xor eax, eax
+ ret
+endp
+
+
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;! Below are private procs you should never call directly from your code ;;
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+proc tiff._.parse_IFD _data, _IFD, _endianness
+locals
+ extended rd 1
+ retvalue rd 1
+ decompress rd 1
+endl
+ push ebx edx edi
+ mov [retvalue], 0
+
+ invoke mem.alloc, sizeof.tiff_extra
+ test eax, eax
+ jz .quit
+ mov [extended], eax
+ mov ebx, eax
+ mov edi, eax
+ mov ecx, sizeof.tiff_extra/4
+ xor eax, eax
+ rep stosd
+
+ mov esi, [_IFD]
+ add esi, [_data]
+ lodsw_
+ movzx ecx, ax
+ @@:
+ push ecx
+ stdcall tiff._.parse_IFDE, [_data], [_endianness]
+ pop ecx
+ dec ecx
+ jnz @b
+
+ call tiff._.define_image_type
+
+ stdcall img.create, [ebx + tiff_extra.image_width], [ebx + tiff_extra.image_height], eax
+ test eax, eax
+ jz .quit
+ mov [retvalue], eax
+ mov edx, eax
+ mov [edx + Image.Extended], ebx
+
+ cmp [ebx+tiff_extra.compression], TIFF.COMPRESSION.UNCOMPRESSED
+ jne @f
+ mov [decompress], tiff._.decompress.uncompressed
+ jmp .decompressor_defined
+ @@:
+ cmp [ebx + tiff_extra.compression], TIFF.COMPRESSION.PACKBITS
+ jne @f
+ mov [decompress], tiff._.decompress.packbits
+ jmp .decompressor_defined
+ @@:
+ mov [decompress], tiff._.decompress.ccitt1d
+ jmp .decompressor_defined
+ jmp .quit
+ .decompressor_defined:
+
+ push esi ; fixme!!
+
+ mov ecx, [edx + Image.Type]
+ dec ecx
+ jz .bpp8
+ dec ecx
+ jz .bpp24
+ dec ecx
+ jz .bpp32
+ dec ecx
+ dec ecx ; tiff doesn't handle 15bpp images
+ jz .bpp16
+ dec ecx
+ jz .bpp1
+ dec ecx
+ jz .bpp4
+;error report!!
+
+ .bpp1:
+ .bpp1.palette:
+ mov edi, [edx+Image.Palette]
+ cmp [ebx + tiff_extra.photometric], TIFF.PHOTOMETRIC.BLACK_IS_ZERO
+ jne .bpp1.white_is_zero
+ .bpp1.black_is_zero:
+ mov [edi], dword 0x00000000
+ mov [edi + 4], dword 0x00ffffff
+ jmp .common
+ .bpp1.white_is_zero:
+ mov [edi], dword 0x00ffffff
+ mov [edi + 4], dword 0x00000000
+ jmp .common
+
+ .bpp4:
+ jmp .common
+
+ .bpp8:
+ cmp [ebx + tiff_extra.palette], 0
+ je .bpp8.grayscale
+
+ mov esi, [ebx + tiff_extra.palette]
+ mov ah, 2
+ .bpp8.channel:
+ mov edi, eax
+ and edi, 0x0000ff00
+ shr edi, 8
+ add edi, [edx + Image.Palette]
+ mov ecx, 256
+ @@:
+ lodsb
+ stosb
+ lodsb
+ add edi, 3
+ dec ecx
+ jnz @b
+ dec ah
+ jns .bpp8.channel
+ jmp .common
+ .bpp8.grayscale:
+ mov edi, [edx + Image.Palette]
+ mov eax, 0xff000000
+ @@:
+ stosd
+ add eax, 0x00010101
+ jnc @b
+ jmp .common
+
+ .bpp16:
+ jmp .common
+
+ .bpp24:
+ jmp .common
+
+ .bpp32:
+ jmp .common
+
+
+ .common:
+ mov edi, [edx+Image.Data]
+ mov esi, [ebx+tiff_extra.strip_offsets]
+ mov edx, [ebx+tiff_extra.strip_byte_counts]
+
+
+ cmp [ebx + tiff_extra.strip_offsets_length], TIFF.IFDE_TYPE_LENGTH.SHORT
+ jne .l_x
+ cmp [ebx + tiff_extra.strip_byte_counts_length], TIFF.IFDE_TYPE_LENGTH.SHORT
+ jne .s_l
+ jmp .s_s
+ .l_x: cmp [ebx + tiff_extra.strip_byte_counts_length], TIFF.IFDE_TYPE_LENGTH.SHORT
+ jne .l_l
+ jmp .l_s
+
+ .s_s:
+ xor eax, eax
+ lodsw_
+ push esi
+ mov esi, eax
+ add esi, [_data]
+ xor ecx, ecx
+ mov cx, word[edx]
+ test [_endianness], 1
+ jz @f
+ xchg cl, ch
+ @@:
+ add edx, 2
+ stdcall [decompress], [retvalue]
+ pop esi
+ dec [ebx + tiff_extra.offsets_number]
+ jnz .s_s
+ jmp .decoded
+
+ .s_l:
+ xor eax, eax
+ lodsw_
+ push esi
+ mov esi, eax
+ add esi, [_data]
+ mov ecx, [edx]
+ test [_endianness], 1
+ jz @f
+ bswap ecx
+ @@:
+ add edx, 4
+ stdcall [decompress], [retvalue]
+ pop esi
+ dec [ebx + tiff_extra.offsets_number]
+ jnz .s_l
+ jmp .decoded
+
+ .l_s:
+ lodsd_
+ push esi
+ mov esi, eax
+ add esi, [_data]
+ xor ecx, ecx
+ mov cx, word[edx]
+ test [_endianness], 1
+ jz @f
+ xchg cl, ch
+ @@:
+ add edx, 2
+ stdcall [decompress], [retvalue]
+ pop esi
+ dec [ebx + tiff_extra.offsets_number]
+ jnz .l_s
+ jmp .decoded
+
+ .l_l:
+ lodsd_
+ push esi
+ mov esi, eax
+ add esi, [_data]
+ mov ecx, [edx]
+ test [_endianness], 1
+ jz @f
+ bswap ecx
+ @@:
+ add edx, 4
+ stdcall [decompress], [retvalue]
+ pop esi
+ dec [ebx + tiff_extra.offsets_number]
+ jnz .l_l
+ jmp .decoded
+
+
+ .decoded:
+ cmp [ebx + tiff_extra.samples_per_pixel], 3
+ jne .pop_quit
+ mov eax, [retvalue]
+ mov esi, [eax + Image.Data]
+ mov edi, [eax + Image.Data]
+ mov ecx, [eax + Image.Width]
+ imul ecx, [eax + Image.Height]
+ @@:
+ lodsw
+ movsb
+ mov byte[esi - 1], al
+ add edi, 2
+ dec ecx
+ jnz @b
+
+
+ .pop_quit:
+ pop esi
+ .quit:
+ pop edi edx ebx
+ mov eax, [retvalue]
+ ret
+endp
+
+proc tiff._.parse_IFDE _data, _endianness
+
+ push ebx edx edi
+
+ lodsw_
+ mov edx, tiff.IFDE_tag_table.begin
+ mov ecx, (tiff.IFDE_tag_table.end-tiff.IFDE_tag_table.begin)/8
+ .tag:
+ cmp ax, word[edx]
+ jne @f
+ lodsw_
+ jmp dword[edx + 4]
+ @@:
+ add edx, 8
+ dec ecx
+ jnz .tag
+ .tag_default: ; unknown/unsupported/uninteresting/unimportant
+ lodsw
+ lodsd
+ lodsd
+ jmp .quit ; just skip it
+
+ .tag_100:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ lodsd
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.image_width], eax
+ lodsw
+ jmp .quit
+ @@:
+ cmp ax, TIFF.IFDE_TYPE.LONG
+ jne @f
+ lodsd
+ lodsd_
+ mov [ebx + tiff_extra.image_width], eax
+ jmp .quit
+ @@:
+ jmp .quit
+
+ .tag_101:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ lodsd
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.image_height], eax
+ lodsw
+ jmp .quit
+ @@:
+ cmp ax, TIFF.IFDE_TYPE.LONG
+ jne @f
+ lodsd
+ lodsd_
+ mov [ebx + tiff_extra.image_height], eax
+ jmp .quit
+ @@:
+ jmp .quit
+
+ .tag_102:
+ lodsd_
+ imul eax, TIFF.IFDE_TYPE_LENGTH.SHORT
+ cmp eax, 4
+ ja @f
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.bits_per_sample], eax
+ lodsw
+ jmp .quit
+ @@:
+ lodsd_
+ add eax, [_data]
+ push esi
+ mov esi, eax
+ xor eax, eax
+ lodsw_
+ pop esi
+ mov [ebx + tiff_extra.bits_per_sample], eax
+ jmp .quit
+
+ .tag_103:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ lodsd
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.compression], eax
+ lodsw
+ jmp .quit
+ @@:
+ jmp .quit
+
+ .tag_106:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ lodsd
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.photometric], eax
+ lodsw
+ jmp .quit
+ @@:
+
+ jmp .quit
+
+ .tag_111:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ mov [ebx + tiff_extra.strip_offsets_length], TIFF.IFDE_TYPE_LENGTH.SHORT
+ jmp .tag_111.common
+ @@:
+ mov [ebx + tiff_extra.strip_offsets_length], TIFF.IFDE_TYPE_LENGTH.LONG
+ .tag_111.common:
+ lodsd_
+ mov [ebx + tiff_extra.offsets_number], eax
+ imul eax, [ebx+tiff_extra.strip_offsets_length]
+ cmp eax, 4
+ ja @f
+ mov [ebx + tiff_extra.strip_offsets], esi
+ lodsd
+ jmp .quit
+ @@:
+ lodsd_
+ add eax, [_data]
+ mov [ebx + tiff_extra.strip_offsets], eax
+ jmp .quit
+
+ .tag_115:
+ lodsd_
+ imul eax, TIFF.IFDE_TYPE_LENGTH.SHORT
+ cmp eax, 4
+ ja @f
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.samples_per_pixel], eax
+ lodsw
+ jmp .quit
+ @@:
+ lodsd_
+ add eax, [_data]
+ movzx eax, word[eax]
+ jmp .quit
+
+ .tag_116:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ lodsd
+ xor eax, eax
+ lodsw_
+ mov [ebx + tiff_extra.rows_per_strip], eax
+ lodsw
+ jmp .quit
+ @@:
+ lodsd
+ lodsd_
+ mov [ebx + tiff_extra.rows_per_strip], eax
+ jmp .quit
+
+ .tag_117:
+ cmp ax, TIFF.IFDE_TYPE.SHORT
+ jne @f
+ mov [ebx + tiff_extra.strip_byte_counts_length], TIFF.IFDE_TYPE_LENGTH.SHORT
+ jmp .tag_117.common
+ @@:
+ mov [ebx + tiff_extra.strip_byte_counts_length], TIFF.IFDE_TYPE_LENGTH.LONG
+ .tag_117.common:
+ lodsd_
+ imul eax, [ebx + tiff_extra.strip_byte_counts_length]
+ cmp eax, 4
+ ja @f
+ mov [ebx + tiff_extra.strip_byte_counts], esi
+ lodsd
+ jmp .quit
+ @@:
+ lodsd_
+ add eax, [_data]
+ mov [ebx + tiff_extra.strip_byte_counts], eax
+ jmp .quit
+
+ .tag_140:
+ lodsd
+ lodsd_
+ add eax, [_data]
+ mov [ebx + tiff_extra.palette], eax
+ jmp .quit
+
+ .quit:
+ pop edi edx ebx
+ ret
+endp
+
+
+proc tiff._.define_image_type
+
+ xor eax, eax
+
+ cmp [ebx + tiff_extra.bits_per_sample], 1
+ jg .not_bilevel
+ mov eax, Image.bpp1
+ jmp .quit
+ .not_bilevel:
+ cmp [ebx + tiff_extra.palette], 0
+ je .without_palette
+ cmp [ebx + tiff_extra.bits_per_sample], 4
+ jne @f
+ mov eax, Image.bpp4
+ jmp .quit
+ @@:
+ cmp [ebx + tiff_extra.bits_per_sample], 8
+ jne @f
+ mov eax, Image.bpp8
+ jmp .quit
+ @@:
+ jmp .quit
+ .without_palette:
+ cmp [ebx + tiff_extra.samples_per_pixel], 1
+ jg .not_grayscale
+ cmp [ebx + tiff_extra.bits_per_sample], 4
+ jne @f
+ mov eax, Image.bpp4
+ jmp .quit
+ @@:
+ cmp [ebx + tiff_extra.bits_per_sample], 8
+ jne @f
+ mov eax, Image.bpp8
+ jmp .quit
+ .not_grayscale:
+ cmp [ebx + tiff_extra.samples_per_pixel], 3
+ jne @f
+ mov eax, Image.bpp24
+ jmp .quit
+ @@:
+ jmp .quit
+ .quit:
+ ret
+endp
+
+
+proc tiff._.decompress.uncompressed _image
+
+ rep movsb
+ ret
+endp
+
+
+proc tiff._.decompress.packbits _image
+
+ push ebx ecx edx esi
+
+ mov edx, ecx
+
+ .decode:
+ lodsb
+ dec edx
+ cmp al, 0xff
+ jbe .different
+ cmp al, 0x80
+ jne .identical
+ test edx, edx
+ jz .quit
+ jmp .decode
+
+ .identical:
+ neg al
+ inc al
+ movzx ecx, al
+ dec edx
+ lodsb
+ rep stosb
+ test edx, edx
+ jnz .decode
+ jmp .quit
+
+ .different:
+ movzx ecx, al
+ inc ecx
+ sub edx, ecx
+ rep movsb
+ test edx, edx
+ jnz .decode
+
+ .quit:
+ pop esi edx ecx ebx
+ ret
+endp
+
+
+proc tiff._.decompress.ccitt1d _image
+locals
+ current_tree rd 1
+ old_tree rd 1
+ width rd 1
+ height rd 1
+ width_left rd 1
+ is_makeup rd 1
+endl
+ push ebx ecx edx esi
+ mov [is_makeup], 0
+
+ mov ebx, [_image]
+ push [ebx + Image.Height]
+ pop [height]
+ push [ebx + Image.Width]
+ pop [width]
+
+ mov edx, esi
+ .next_scanline:
+ push [width]
+ pop [width_left]
+ dec [height]
+ js .error
+ mov [current_tree], tiff._.huffman_tree_white.begin
+ mov [old_tree], tiff._.huffman_tree_black.begin
+ mov ebx, 0
+ mov ecx, 8
+ .next_run:
+ mov esi, [current_tree]
+ .branch:
+ lodsd
+ btr eax, 31
+ jnc .not_a_leaf
+ cmp eax, 63
+ seta byte[is_makeup]
+ ja @f
+ push [current_tree]
+ push [old_tree]
+ pop [current_tree]
+ pop [old_tree]
+ @@:
+ stdcall tiff._.write_run, [width_left], [current_tree]
+ mov [width_left], eax
+ test byte[is_makeup], 0x01
+ jnz .next_run
+ test eax, eax
+ jnz .next_run
+ jmp .next_scanline
+ .not_a_leaf:
+ test bh, bh
+ jnz @f
+ mov bl, byte[edx]
+ inc edx
+ mov bh, 8
+ @@:
+ test al, 0x02
+ jz .not_a_corner
+ dec bh
+ sal bl, 1
+ lahf
+ and ah, 0x03
+ cmp al, ah
+ jne .error
+ mov esi, [esi]
+ jmp .branch
+ .not_a_corner:
+ lodsd
+ dec bh
+ sal bl, 1
+ jc .branch
+ mov esi, eax
+ jmp .branch
+ .error:
+ .quit:
+ pop esi edx ecx ebx
+ ret
+endp
+
+
+proc tiff._.write_run _width_left, _current_tree
+
+ push ebx
+
+ test eax, eax
+ jz .done
+ sub [_width_left], eax
+ js .error
+ cmp esi, tiff._.huffman_tree_black.begin
+ seta bh
+
+ cmp ecx, eax
+ ja .one_byte
+ .many_bytes:
+ mov bl, [edi]
+ @@:
+ shl bl, 1
+ or bl, bh
+ dec eax
+ dec ecx
+ jnz @b
+ mov [edi], bl
+ inc edi
+ mov ecx, eax
+ and eax, 0x07
+ shr ecx, 3
+
+ push eax
+ xor eax, eax
+ test bh, bh
+ jz @f
+ dec al
+ @@:
+ rep stosb
+ pop eax
+
+ mov ecx, 8
+ test eax, eax
+ jz .done
+
+ .one_byte:
+ mov bl, [edi]
+ @@:
+ shl bl, 1
+ or bl, bh
+ dec ecx
+ dec eax
+ jnz @b
+ mov byte[edi], bl
+
+ cmp [_width_left], 0
+ jne .done
+ mov bl, [edi]
+ shl bl, cl
+ mov byte[edi], bl
+ inc edi
+ .done:
+ mov eax, [_width_left]
+ jmp .quit
+ .error:
+ .quit:
+ pop ebx
+ ret
+endp
+
+
+proc tiff._.get_word _endianness
+
+ lodsw
+ test [_endianness], 1
+ jnz @f
+ ret
+ @@:
+ xchg al, ah
+ ret
+endp
+
+
+proc tiff._.get_dword _endianness
+
+ lodsd
+ test [_endianness], 1
+ jnz @f
+ ret
+ @@:
+ bswap eax
+ ret
+
+ ret
+endp
+
+
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;! Below is private data you should never use directly from your code ;;
+;;================================================================================================;;
+;;////////////////////////////////////////////////////////////////////////////////////////////////;;
+;;================================================================================================;;
+tiff.IFDE_tag_table.begin:
+ .tag_100: dd 0x0100, tiff._.parse_IFDE.tag_100 ; image width
+ .tag_101: dd 0x0101, tiff._.parse_IFDE.tag_101 ; image height (this is called 'length' in spec)
+ .tag_102: dd 0x0102, tiff._.parse_IFDE.tag_102 ; bits per sample
+ .tag_103: dd 0x0103, tiff._.parse_IFDE.tag_103 ; compression
+ .tag_106: dd 0x0106, tiff._.parse_IFDE.tag_106 ; photometric interpretation
+ .tag_111: dd 0x0111, tiff._.parse_IFDE.tag_111 ; strip offsets
+ .tag_115: dd 0x0115, tiff._.parse_IFDE.tag_115 ; samples per pixel
+ .tag_116: dd 0x0116, tiff._.parse_IFDE.tag_116 ; rows per strip
+ .tag_117: dd 0x0117, tiff._.parse_IFDE.tag_117 ; strip byte counts
+ .tag_140: dd 0x0140, tiff._.parse_IFDE.tag_140 ; color map
+tiff.IFDE_tag_table.end:
+
+include 'huffman.asm' ; huffman trees for ccitt1d compression method
diff --git a/programs/develop/libraries/libs-dev/libimg/tiff/tiff.inc b/programs/develop/libraries/libs-dev/libimg/tiff/tiff.inc
new file mode 100644
index 0000000000..2894bbf03d
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/tiff/tiff.inc
@@ -0,0 +1,97 @@
+;;================================================================================================;;
+;;//// tiff.inc //// (c) dunkaist, 2011-2012 /////////////////////////////////////////////////////;;
+;;================================================================================================;;
+;; ;;
+;; 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 . ;;
+;; ;;
+;;================================================================================================;;
+
+struct tiff_header
+ magic_1 rw 1
+ magic_2 rw 1
+ first_IFD rd 1
+ends
+
+struct tiff_extra
+ image_width rd 1 ; SHORT or LONG
+ image_height rd 1 ; SHORT or LONG
+ bits_per_sample rd 1 ; SHORT
+ samples_per_pixel rd 1 ; SHORT
+ compression rd 1 ; SHORT
+ photometric rd 1 ; SHORT
+ offsets_number rd 1
+ strip_offsets rd 1 ; SHORT or LONG
+ strip_offsets_length rd 1
+ rows_per_strip rd 1 ; SHORT or LONG
+ strip_byte_counts rd 1 ; LONG or SHORT
+ strip_byte_counts_length rd 1
+ palette rd 1 ; SHORT
+ palette_size rd 1 ; in colors, not samples
+ends
+
+
+TIFF.IFDE_TYPE.BYTE = 1
+TIFF.IFDE_TYPE.ASCII = 2
+TIFF.IFDE_TYPE.SHORT = 3
+TIFF.IFDE_TYPE.LONG = 4
+TIFF.IFDE_TYPE.RATIONAL = 5
+TIFF.IFDE_TYPE.SBYTE = 6
+TIFF.IFDE_TYPE.UNDEFINED = 7
+TIFF.IFDE_TYPE.SSHORT = 8
+TIFF.IFDE_TYPE.SLONG = 9
+TIFF.IFDE_TYPE.SRATIONAL = 10
+TIFF.IFDE_TYPE.FLOAT = 11
+TIFF.IFDE_TYPE.DOUBLE = 12
+
+TIFF.IFDE_TYPE_LENGTH.BYTE = 1
+TIFF.IFDE_TYPE_LENGTH.ASCII = 1
+TIFF.IFDE_TYPE_LENGTH.SHORT = 2
+TIFF.IFDE_TYPE_LENGTH.LONG = 4
+TIFF.IFDE_TYPE_LENGTH.RATIONAL = 8
+TIFF.IFDE_TYPE_LENGTH.SBYTE = 1
+TIFF.IFDE_TYPE_LENGTH.UNDEFINED = 1
+TIFF.IFDE_TYPE_LENGTH.SSHORT = 2
+TIFF.IFDE_TYPE_LENGTH.SLONG = 4
+TIFF.IFDE_TYPE_LENGTH.SRATIONAL = 8
+TIFF.IFDE_TYPE_LENGTH.FLOAT = 4
+TIFF.IFDE_TYPE_LENGTH.DOUBLE = 8
+
+TIFF.COMPRESSION.UNCOMPRESSED = 1
+TIFF.COMPRESSION.CCITT1D = 2
+TIFF.COMPRESSION.GROUP3FAX = 3
+TIFF.COMPRESSION.GROUP4FAX = 4
+TIFF.COMPRESSION.LZW = 5
+TIFF.COMPRESSION.JPEG = 6
+TIFF.COMPRESSION.PACKBITS = 32773
+
+TIFF.PHOTOMETRIC.WHITE_IS_ZERO = 0
+TIFF.PHOTOMETRIC.BLACK_IS_ZERO = 1
+TIFF.PHOTOMETRIC.RGB = 2
+TIFF.PHOTOMETRIC.RGB_PALETTE = 3
+TIFF.PHOTOMETRIC.MASK = 4
+TIFF.PHOTOMETRIC.CMYK = 5
+TIFF.PHOTOMETRIC.YCbCr = 6
+TIFF.PHOTOMETRIC.CIELAB = 8
+
+
+macro lodsw_
+{
+ stdcall tiff._.get_word, [_endianness]
+}
+
+macro lodsd_
+{
+ stdcall tiff._.get_dword, [_endianness]
+}
+
diff --git a/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.asm b/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.asm
new file mode 100644
index 0000000000..3998b6cb3b
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.asm
@@ -0,0 +1,821 @@
+proc xcf._.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
+ punpcklbw mm1, mm1
+ punpcklbw mm1, 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 xcf._.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
+ punpcklbw mm1, mm1
+ punpcklbw mm1, 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 xcf._.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 xcf._.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 xcf._.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 xcf._.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 xcf._.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 xcf._.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 xcf._.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 xcf._.composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+ pushad
+
+ pxor mm4, mm4
+ movd mm4, [xcf._.random_b]
+ movd mm1, [xcf._.random_a]
+ movd mm2, [xcf._.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 xcf._.composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+ pushad
+
+ pxor mm4, mm4
+ movd mm4, [xcf._.random_b]
+ movd mm1, [xcf._.random_a]
+ movd mm2, [xcf._.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 xcf._.composite_rgb_03 ; Multiply
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+ pmullw mm3, mm2
+ psrlw mm3, 8
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_04 ; Screen
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+ movq mm5, [xcf._.mmx_00ff]
+ movq mm4, mm5
+ psubw mm4, mm2
+ psubw mm3, mm5
+ pmullw mm3, mm4
+ psrlw mm3, 8
+ paddw mm3, mm5
+ ret
+endp
+
+
+proc xcf._.composite_rgb_05 ; Overlay
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+ movq mm4, [xcf._.mmx_00ff]
+ psubw mm4, mm2
+ pmullw mm3, mm4
+ psrlw mm3, 7
+ paddw mm3, mm2
+ pmullw mm3, mm2
+ psrlw mm3, 8
+
+ ret
+endp
+
+
+proc xcf._.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 xcf._.composite_rgb_07 ; Addition
+
+ paddusb mm3, mm2
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_08 ; Subtract
+
+ movq mm4, mm2
+ psubusb mm4, mm3
+ movq mm3, mm4
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_09 ; Darken Only
+
+ pminub mm3, mm2
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_10 ; Lighten Only
+
+ pmaxub mm3, mm2
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_11 ; Hue (H of HSV)
+ push eax ebx ecx edx
+
+ movd eax, mm3
+ movd ebx, mm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.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 xcf._.hsv2rgb
+
+ movd mm3, eax
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_12 ; Saturation (S of HSV)
+ push eax ebx ecx edx
+
+ movd eax, mm3
+ movd ebx, mm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ah, bh
+ rol eax, 8
+ rol ebx, 8
+ mov al, bl
+
+ call xcf._.hsv2rgb
+
+
+ movd mm3, eax
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_13 ; Color (H and S of HSL)
+ push eax ebx ecx edx
+
+ movd eax, mm3
+ movd ebx, mm2
+
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+
+ mov al, bl
+
+ call xcf._.hsl2rgb
+
+
+ movd mm3, eax
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_14 ; Value (V of HSV)
+ push eax ebx ecx edx
+
+ movd eax, mm3
+ movd ebx, mm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ax, bx
+ rol eax, 8
+ rol ebx, 8
+
+ call xcf._.hsv2rgb
+
+
+ movd mm3, eax
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.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 xcf._.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 xcf._.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 xcf._.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 xcf._.composite_rgb_20 ; Grain Extract
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+ movq mm4, mm2
+ psubw mm3, [xcf._.mmx_0080]
+ psubw mm4, mm3
+ movq mm3, mm4
+ packuswb mm3, mm0
+ punpcklbw mm3, mm0
+ ret
+endp
+
+
+proc xcf._.composite_rgb_21 ; Grain Merge
+
+ punpcklbw mm2, mm0
+ punpcklbw mm3, mm0
+ paddw mm3, mm2
+ psubusw mm3, [xcf._.mmx_0080]
+ packuswb mm3, mm0
+ punpcklbw mm3, mm0
+ ret
+endp
+
+
+; starting numbers for pseudo-random number generator
+xcf._.random_a dd 1103515245
+xcf._.random_b dd 777
+xcf._.random_c dd 12345
+
+xcf._.mmx_0080 dq 0x0080008000800080
+xcf._.mmx_00ff dq 0x00ff00ff00ff00ff
+xcf._.mmx_0100 dq 0x0100010001000100
diff --git a/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.inc b/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.inc
deleted file mode 100644
index 57284ad032..0000000000
--- a/programs/develop/libraries/libs-dev/libimg/xcf/composite_mmx.inc
+++ /dev/null
@@ -1,828 +0,0 @@
-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
\ No newline at end of file
diff --git a/programs/develop/libraries/libs-dev/libimg/xcf/composite_sse.asm b/programs/develop/libraries/libs-dev/libimg/xcf/composite_sse.asm
new file mode 100644
index 0000000000..31d711b465
--- /dev/null
+++ b/programs/develop/libraries/libs-dev/libimg/xcf/composite_sse.asm
@@ -0,0 +1,1315 @@
+proc xcf._.blend_rgb
+
+ push eax ebx
+
+ 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 xmm1, eax
+
+ pop ebx eax
+ push ebx
+
+ shr eax, 8
+ shr ebx, 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 ebx, xmm1
+ ror ebx, 16
+ mov bx, ax
+ rol ebx, 16
+ movd xmm1, ebx
+
+ pop ebx
+
+; movdqu xmm1, xword[xcf._.xmm_000000ff]
+; movdqa xmm4, xmm1
+; movdqa xmm5, xmm1
+; movdqa xmm6, xmm2
+; psrldq xmm6, 3
+; pand xmm6, xmm1
+; psubw xmm4, xmm6
+; movdqa xmm6, xmm3
+; psrldq xmm6, 3
+; pand xmm6, xmm1
+; psubw xmm5, xmm6
+; pmullw xmm4, xmm5
+; psrlw xmm4, 8
+; psubw xmm1, xmm4
+; movdqa xmm4, xmm1
+; movdqa xmm1, xmm6
+; divps xmm1, xmm4
+; packuswb xmm1, xmm0
+; packuswb xmm1, xmm0
+; punpcklbw xmm1, xmm1
+
+ punpcklbw xmm1, xmm1
+ punpcklbw xmm1, xmm0
+
+ movdqa xmm7, xmm1
+ psrlw xmm7, 7
+ paddw xmm1, xmm7
+
+ psubw xmm3, xmm2
+ pmullw xmm3, xmm1
+ psllw xmm2, 8
+ paddw xmm3, xmm2
+ pinsrw xmm3, ebx, 3
+ shr ebx, 8
+ pinsrw xmm3, ebx, 7
+ psrlw xmm3, 8
+ packuswb xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.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 xmm1, eax
+ punpcklbw xmm1, xmm1
+ punpcklbw xmm1, xmm0
+
+ movq xmm7, xmm1
+ psrlw xmm7, 7
+ paddw xmm1, xmm7
+
+ psubw xmm3, xmm2
+ pmullw xmm3, xmm1
+ psllw xmm2, 8
+ paddw xmm3, xmm2
+ pinsrw xmm3, ebx, 1
+ psrlw xmm3, 8
+ packuswb xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.merge_32 _copy_width, _copy_height, _img_total_bpl, _bottom_total_bpl
+
+ pxor xmm0, xmm0
+
+ .line:
+ mov ecx, [_copy_width]
+ bt ecx, 0
+ jnc .even
+ .odd:
+ movd xmm2, [edi]
+ movd xmm3, [esi]
+ add esi, 4
+
+ movdqa xmm4, xmm2
+ pminub xmm4, xmm3
+ pextrw eax, xmm4, 3
+ pextrw ebx, xmm4, 1
+ mov al, bh
+
+ push eax
+ pextrw eax, xmm2, 3
+ pextrw ebx, xmm2, 1
+ mov bl, ah
+ shl ebx, 8
+ pop eax
+
+ call edx
+ call xcf._.blend_rgb
+ movd [edi], xmm3
+ add edi, 4
+
+ cmp ecx, 1
+ je .done
+
+ .even:
+ sub ecx, 2
+ .pixel:
+ movq xmm2, [edi]
+ movq xmm3, [esi]
+ add esi, 8
+
+ movdqa xmm4, xmm2
+ pminub xmm4, xmm3
+ pextrw eax, xmm4, 3
+ pextrw ebx, xmm4, 1
+ mov al, bh
+
+ push eax
+ pextrw eax, xmm2, 3
+ pextrw ebx, xmm2, 1
+ mov bl, ah
+ shl ebx, 8
+ pop eax
+
+ call edx
+ call xcf._.blend_rgb
+ movq [edi], xmm3
+ add edi, 8
+ sub ecx, 2
+ jns .pixel
+ add esi, [_img_total_bpl]
+ add edi, [_bottom_total_bpl]
+ dec [_copy_height]
+ jnz .line
+ .done:
+ ret
+endp
+
+
+proc xcf._.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 xmm2, ebx
+ movd xmm3, eax
+ shr eax, 8
+ cmp al, bh
+ jna @f
+ mov al, bh
+ @@:
+ pxor xmm0, xmm0
+ call edx
+ call xcf._.blend_gray
+ movd eax, xmm3
+ stosw
+ dec ecx
+ jnz .gray_pixel
+ add esi, [_img_total_bpl]
+ add edi, [_bottom_total_bpl]
+ dec [_copy_height]
+ jnz .gray_line
+ ret
+endp
+
+
+proc xcf._.composite_rgb_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+
+ pxor xmm0, xmm0
+
+ .line:
+ mov ecx, [_copy_width]
+ bt ecx, 0
+ jnc .even
+ .odd:
+ movlpd xmm2, [edi]
+ movlpd xmm3, [esi]
+ add esi, 4
+
+ pextrw eax, xmm3, 3
+ pextrw ebx, xmm3, 1
+ mov al, bh
+
+ push eax
+ pextrw eax, xmm2, 3
+ pextrw ebx, xmm2, 1
+ mov bl, ah
+ shl ebx, 8
+ pop eax
+
+ xchg al, bh
+ mov ah, bh
+ neg al
+ neg ah
+ dec al
+ dec ah
+ mul ah
+ neg ah
+ dec ah
+ xchg ah, bh
+
+ mov al, 0xff
+ cmp ah, bh
+ je @f
+ inc al
+ div bh
+ @@:
+ mov ah, al
+ movd xmm1, eax
+
+ punpcklbw xmm1, xmm1
+ punpcklbw xmm1, xmm0
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ psubsw xmm3, xmm2
+ pmullw xmm3, xmm1
+ psllw xmm2, 8
+ paddw xmm3, xmm2
+ pinsrw xmm3, ebx, 3
+ shr ebx, 8
+ pinsrw xmm3, ebx, 7
+ psrlw xmm3, 8
+ packuswb xmm3, xmm0
+
+ movd [edi], xmm3
+ add edi, 4
+
+ cmp ecx, 1
+ je .done
+
+ .even:
+ sub ecx, 2
+ .pixel:
+ movlpd xmm2, [edi]
+ movlpd xmm3, [esi]
+ add esi, 8
+
+ pextrw eax, xmm3, 3
+ pextrw ebx, xmm3, 1
+ mov al, bh
+
+ push eax
+ pextrw eax, xmm2, 3
+ pextrw ebx, xmm2, 1
+ mov bl, ah
+ shl ebx, 8
+ pop eax
+
+
+ push eax ebx
+
+ xchg al, bh
+ mov ah, bh
+ neg al
+ neg ah
+ dec al
+ dec ah
+ mul ah
+ neg ah
+ dec ah
+ xchg ah, bh
+
+ mov al, 0xff
+ cmp ah, bh
+ je @f
+ inc al
+ div bh
+ @@:
+ mov ah, al
+ movd xmm1, eax
+
+ pop ebx eax
+ push ebx
+
+ shr eax, 8
+ shr ebx, 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 ebx, xmm1
+ ror ebx, 16
+ mov bx, ax
+ rol ebx, 16
+ movd xmm1, ebx
+
+ pop ebx
+
+ punpcklbw xmm1, xmm1
+ punpcklbw xmm1, xmm0
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ psubsw xmm3, xmm2
+ pmullw xmm3, xmm1
+ psllw xmm2, 8
+ paddw xmm3, xmm2
+ pinsrw xmm3, ebx, 3
+ shr ebx, 8
+ pinsrw xmm3, ebx, 7
+ psrlw xmm3, 8
+ packuswb xmm3, xmm0
+
+ movq [edi], xmm3
+ add edi, 8
+ sub ecx, 2
+ jns .pixel
+ add esi, [_img_total_bpl]
+ add edi, [_bottom_total_bpl]
+ dec [_copy_height]
+ jnz .line
+ .done:
+ ret
+endp
+
+
+proc xcf._.composite_gray_00 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+
+ .line:
+ mov ecx, [_copy_width]
+ .pixel:
+ mov bx, [edi]
+ lodsw
+ movd xmm2, ebx
+ movd xmm3, 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 xmm1, eax
+ pxor xmm0, xmm0
+ punpcklbw xmm1, xmm1
+ punpcklbw xmm1, xmm0
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ psubw xmm3, xmm2
+ pmullw xmm3, xmm1
+ psllw xmm2, 8
+ paddw xmm3, xmm2
+ pinsrw xmm3, ebx, 1
+ psrlw xmm3, 8
+ packuswb xmm3, xmm0
+ movd eax, xmm3
+ stosw
+
+ dec ecx
+ jnz .pixel
+ add esi, [_img_total_bpl]
+ add edi, [_bottom_total_bpl]
+ dec [_copy_height]
+ jnz .line
+
+ ret
+endp
+
+
+proc xcf._.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 xcf._.composite_rgb_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+ pushad
+
+ pxor xmm4, xmm4
+ movd xmm4, [xcf._.random_b]
+ movd xmm1, [xcf._.random_a]
+ movd xmm2, [xcf._.random_c]
+
+ .line:
+ mov ecx, [_copy_width]
+ .pixel:
+ mov ebx, [edi]
+ lodsd
+
+ movq xmm0, xmm4
+ pmuludq xmm0, xmm1
+ paddq xmm0, xmm2
+ movd edx, xmm0
+ movd xmm4, edx
+ pxor xmm0, xmm0
+
+ 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 xcf._.composite_gray_01 _copy_width, _copy_height, _bottom_total_bpl, _img_total_bpl
+ pushad
+
+ pxor xmm4, xmm4
+ movd xmm4, [xcf._.random_b]
+ movd xmm1, [xcf._.random_a]
+ movd xmm2, [xcf._.random_c]
+
+ .line:
+ mov ecx, [_copy_width]
+ .pixel:
+ mov ebx, [edi]
+ lodsw
+
+ movq xmm0, xmm4
+ pmuludq xmm0, xmm1
+ paddq xmm0, xmm2
+ movd edx, xmm0
+ movd xmm4, edx
+ pxor xmm0, xmm0
+
+ 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 xcf._.composite_rgb_03 ; Multiply
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+ pmullw xmm3, xmm2
+ psrlw xmm3, 8
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_04 ; Screen
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+ movdqu xmm5, xword[xcf._.xmm_00ff]
+ movdqa xmm4, xmm5
+ psubw xmm4, xmm2
+ psubw xmm3, xmm5
+ pmullw xmm3, xmm4
+ psrlw xmm3, 8
+ paddw xmm3, xmm5
+ ret
+endp
+
+
+proc xcf._.composite_rgb_05 ; Overlay
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+ movdqu xmm4, xword[xcf._.xmm_00ff]
+ psubw xmm4, xmm2
+ pmullw xmm3, xmm4
+ psrlw xmm3, 7
+ paddw xmm3, xmm2
+ pmullw xmm3, xmm2
+ psrlw xmm3, 8
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_06 ; Difference
+
+ movdqa xmm4, xmm3
+ pminub xmm4, xmm2
+ pmaxub xmm3, xmm2
+ psubusb xmm3, xmm4
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_07 ; Addition
+
+ paddusb xmm3, xmm2
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_08 ; Subtract
+
+ movdqa xmm4, xmm2
+ psubusb xmm4, xmm3
+ movq xmm3, xmm4
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_09 ; Darken Only
+
+ pminub xmm3, xmm2
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_10 ; Lighten Only
+
+ pmaxub xmm3, xmm2
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ ret
+endp
+
+
+proc xcf._.composite_rgb_11 ; Hue (H of HSV)
+ push eax ebx ecx edx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.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 xcf._.hsv2rgb
+
+ push eax
+
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.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 xcf._.hsv2rgb
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_12 ; Saturation (S of HSV)
+ push eax ebx ecx edx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ah, bh
+ rol eax, 8
+ rol ebx, 8
+ mov al, bl
+
+ call xcf._.hsv2rgb
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ah, bh
+ rol eax, 8
+ rol ebx, 8
+ mov al, bl
+
+ call xcf._.hsv2rgb
+
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_13 ; Color (H and S of HSL)
+ push eax ebx ecx edx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+
+ mov al, bl
+
+ call xcf._.hsl2rgb
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+ call xcf._.rgb2hsl
+ xchg eax, ebx
+
+ mov al, bl
+
+ call xcf._.hsl2rgb
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_14 ; Value (V of HSV)
+ push eax ebx ecx edx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ax, bx
+ rol eax, 8
+ rol ebx, 8
+
+ call xcf._.hsv2rgb
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+ call xcf._.rgb2hsv
+ xchg eax, ebx
+
+ ror eax, 8
+ ror ebx, 8
+ mov ax, bx
+ rol eax, 8
+ rol ebx, 8
+
+ call xcf._.hsv2rgb
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ .quit:
+ pop edx ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_15 ; Divide
+ push eax ebx ecx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ 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
+
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+
+ rol eax, 8
+ rol ebx, 8
+
+ xchg eax, ebx
+
+ mov ecx, 3
+
+ .color2:
+ rol eax, 8
+ rol ebx, 8
+ shl ax, 8
+ test bl, bl
+ jz .clamp12
+ cmp ah, bl
+ jae .clamp22
+ div bl
+ jmp .done2
+ .clamp12:
+ mov al, 0xff
+ test ah, ah
+ jnz @f
+ not al
+ @@:
+ jmp .done2
+ .clamp22:
+ mov al, 0xff
+ jmp .done2
+ .done2:
+ mov ah, al
+ loop .color2
+
+ ror eax, 8
+
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ pop ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_16 ; Dodge
+ push eax ebx ecx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ 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
+
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+
+ rol eax, 8
+ rol ebx, 8
+
+ xchg eax, ebx
+
+ mov ecx, 3
+
+ .color2:
+ rol eax, 8
+ rol ebx, 8
+ shl ax, 8
+ neg bl
+ add bl, 0xff
+ test bl, bl
+ jz .clamp12
+ cmp ah, bl
+ jae .clamp22
+ div bl
+ jmp .done2
+ .clamp12:
+ mov al, 0xff
+ test ah, ah
+ jnz @f
+ not al
+ @@:
+ jmp .done2
+ .clamp22:
+ mov al, 0xff
+ jmp .done2
+ .done2:
+ mov ah, al
+ loop .color2
+
+ ror eax, 8
+
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ pop ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_17 ; Burn
+ push eax ebx ecx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ 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
+
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+
+ rol eax, 8
+ rol ebx, 8
+
+ xchg eax, ebx
+
+ mov ecx, 3
+
+ .color2:
+ rol eax, 8
+ rol ebx, 8
+ shl ax, 8
+ neg ah
+ add ah, 0xff
+ test bl, bl
+ jz .clamp12
+ cmp ah, bl
+ jae .clamp22
+ div bl
+ jmp .done2
+ .clamp12:
+ mov al, 0xff
+ test ah, ah
+ jnz @f
+ not al
+ @@:
+ jmp .done2
+ .clamp22:
+ mov al, 0xff
+ jmp .done2
+ .done2:
+ mov ah, al
+ neg ah
+ add ah, 0xff
+ loop .color2
+
+ ror eax, 8
+
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ pop ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_18 ; Hard Light
+ push eax ebx ecx
+
+ movd eax, xmm3
+ movd ebx, xmm2
+
+ 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
+
+
+ push eax
+ movq xmm1, xmm3
+ psrldq xmm1, 4
+ movd eax, xmm1
+ movq xmm1, xmm2
+ psrldq xmm1, 4
+ movd ebx, xmm1
+
+
+ rol eax, 8
+ rol ebx, 8
+
+ mov ecx, 3
+
+ .color2:
+ rol eax, 8
+ rol ebx, 8
+ cmp al, 127
+ jna .part12
+ mov ah, 0xff
+ sub ah, bl
+ neg al
+ add al, 0xff
+ mul ah
+ shl ax, 1
+ neg ah
+ add ah, 0xff
+ jmp .done2
+ .part12:
+ mul bl
+ shl ax, 1
+ .done2:
+ loop .color2
+
+ ror eax, 8
+
+
+ movd xmm3, eax
+ pslldq xmm3, 4
+ pop eax
+ movd xmm1, eax
+ paddq xmm3, xmm1
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+
+ pop ecx ebx eax
+ ret
+endp
+
+
+proc xcf._.composite_rgb_20 ; Grain Extract
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+ movdqu xmm4, xmm2
+ psubw xmm3, xword[xcf._.xmm_0080]
+ psubw xmm4, xmm3
+ movdqa xmm3, xmm4
+ packuswb xmm3, xmm0
+ punpcklbw xmm3, xmm0
+ ret
+endp
+
+
+proc xcf._.composite_rgb_21 ; Grain Merge
+
+ punpcklbw xmm2, xmm0
+ punpcklbw xmm3, xmm0
+ paddw xmm3, xmm2
+ psubusw xmm3, xword[xcf._.xmm_0080]
+ packuswb xmm3, xmm0
+ punpcklbw xmm3, xmm0
+ ret
+endp
+
+
+; starting numbers for pseudo-random number generator
+xcf._.random_a dd 1103515245
+xcf._.random_b dd 777
+xcf._.random_c dd 12345
+
+xcf._.xmm_8080 dq 0x8080808080808080, 0x8080808080808080
+xcf._.xmm_0080 dq 0x0080008000800080, 0x0080008000800080
+xcf._.xmm_00ff dq 0x00ff00ff00ff00ff, 0x00ff00ff00ff00ff
+xcf._.xmm_0100 dq 0x0100010001000100, 0x0100010001000100
+xcf._.xmm_000000ff dq 0x000000ff000000ff, 0x0000000000000000
diff --git a/programs/develop/libraries/libs-dev/libimg/xcf/xcf.asm b/programs/develop/libraries/libs-dev/libimg/xcf/xcf.asm
index d88fb12136..a250da4d28 100644
--- a/programs/develop/libraries/libs-dev/libimg/xcf/xcf.asm
+++ b/programs/develop/libraries/libs-dev/libimg/xcf/xcf.asm
@@ -1,5 +1,5 @@
;;================================================================================================;;
-;;//// xcf.asm //// (c) dunkaist, 2011 ///////////////////////////////////////////////////////////;;
+;;//// xcf.asm //// (c) dunkaist, 2011-2012 //////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
@@ -26,15 +26,14 @@
;; http://docs.gimp.org/en/gimp-concepts-layer-modes.html ;;
;; ;;
;;================================================================================================;;
-include 'xcf.inc'
-;include '../../../../system/board/trunk/debug.inc'
+include 'xcf.inc'
+;include '../../../../../system/board/trunk/debug.inc'
-COMPOSITE_MODE equ MMX
+COMPOSITE_MODE equ MMX
+; MMX | pretty fast and compatible
+; SSE | a bit faster, but may be unsupported by some CPUs
-MAX_LAYERS equ 255
-
-DEBUG_STANDARD equ TRUE
-DEBUG_FBOUNDS equ FALSE
+MAX_LAYERS = 255
;;================================================================================================;;
proc img.is.xcf _data, _length ;//////////////////////////////////////////////////////////////////;;
@@ -47,37 +46,37 @@ proc img.is.xcf _data, _length ;////////////////////////////////////////////////
;< eax = false / true ;;
;;================================================================================================;;
- push edi
- xor eax, eax
+ push edi
+ xor eax, eax
- mov edi, [_data]
+ mov edi, [_data]
- cmp dword[edi+xcf_header.magic_string], 'gimp'
- jne .is_not_xcf
- cmp dword[edi+xcf_header.magic_string+4], ' xcf'
- jne .is_not_xcf
+ cmp dword[edi + xcf_header.magic_string], 'gimp'
+ jne .is_not_xcf
+ cmp dword[edi + xcf_header.magic_string + 4], ' xcf'
+ jne .is_not_xcf
- cmp [edi+xcf_header.version], 'file'
- je @f
- cmp [edi+xcf_header.version], 'v001'
- je @f
- cmp [edi+xcf_header.version], 'v002'
- je @f
- jmp .is_not_xcf
-@@:
+ cmp [edi + xcf_header.version], 'file'
+ je @f
+ cmp [edi + xcf_header.version], 'v001'
+ je @f
+ cmp [edi + xcf_header.version], 'v002'
+ je @f
+ jmp .is_not_xcf
+ @@:
- cmp byte[edi+xcf_header.reserved], 0
- jne .is_not_xcf
+ cmp byte[edi + xcf_header.reserved], 0
+ jne .is_not_xcf
-.is_xcf:
- inc eax
-
-.is_not_xcf:
- pop edi
- ret
+ .is_xcf:
+ inc eax
+ .is_not_xcf:
+ pop edi
+ ret
endp
+
;;================================================================================================;;
proc img.decode.xcf _data, _length, _options ;////////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
@@ -89,147 +88,149 @@ proc img.decode.xcf _data, _length, _options ;//////////////////////////////////
;< eax = 0 (error) or pointer to image ;;
;;================================================================================================;;
locals
-count rd 1
-retvalue rd 1 ; 0 (error) or pointer to image
+ layer_count rd 1
+ retvalue rd 1
endl
- push ebx esi edi
+ push ebx esi edi
- mov esi, [_data]
- add esi, xcf_header.width
-
- lodsd
- bswap eax
- mov ebx, eax
- lodsd
- bswap eax
- mov edx, eax
-
- lodsd
- bswap eax
- test eax, eax
- jz .process_rgb
- dec eax
- jz .process_grayscale
- dec eax
- jz .process_indexed
- jmp .error
+ mov esi, [_data]
+ add esi, xcf_header.width
+
+ lodsd
+ bswap eax
+ mov ebx, eax
+ lodsd
+ bswap eax
+ mov edx, eax
+
+ lodsd
+ bswap eax
+ test eax, eax
+ jz .process_rgb
+ dec eax
+ jz .process_grayscale
+ dec eax
+ jz .process_indexed
+ jmp .error
-.process_rgb:
-
- stdcall img.create, ebx, edx, Image.bpp32
- mov [retvalue], eax
- test eax, eax
- jz .error
+ .process_rgb:
- mov ebx, eax
+ stdcall img.create, ebx, edx, Image.bpp32
+ mov [retvalue], eax
+ test eax, eax
+ jz .error
- mov edx, XCF_BASETYPE_RGB
+ mov ebx, eax
- jmp .common_process
+ mov edx, XCF_BASETYPE_RGB
-.process_grayscale:
+ jmp .common_process
- stdcall img.create, ebx, edx, Image.bpp8
- mov [retvalue], eax
- test eax, eax
- jz .error
+ .process_grayscale:
- mov ebx, eax
+ stdcall img.create, ebx, edx, Image.bpp8
+ mov [retvalue], eax
+ test eax, eax
+ jz .error
- mov eax, [ebx + Image.Width]
- imul [ebx + Image.Height]
- shl eax, 1
- mov [ebx+Image.Palette], eax
- add eax, 256*4
- invoke mem.realloc, [ebx + Image.Data], eax
- mov [ebx + Image.Data], eax
- add [ebx + Image.Palette], eax
+ mov ebx, eax
- mov edi, [ebx+Image.Palette]
- mov eax, 0xff000000
-@@: stosd
- add eax, 0x00010101
- jnc @b
+ mov eax, [ebx + Image.Width]
+ imul [ebx + Image.Height]
+ shl eax, 1
+ mov [ebx + Image.Palette], eax
+ add eax, 256*4
+ invoke mem.realloc, [ebx + Image.Data], eax
+ mov [ebx + Image.Data], eax
+ add [ebx + Image.Palette], eax
- mov edx, XCF_BASETYPE_GRAY
-
- jmp .common_process
+ mov edi, [ebx + Image.Palette]
+ mov eax, 0xff000000
+ @@:
+ stosd
+ add eax, 0x00010101
+ jnc @b
+
+ mov edx, XCF_BASETYPE_GRAY
+
+ jmp .common_process
-.process_indexed:
+ .process_indexed:
- stdcall img.create, ebx, edx, Image.bpp8
- mov [retvalue], eax
- test eax, eax
- jz .error
+ stdcall img.create, ebx, edx, Image.bpp8
+ mov [retvalue], eax
+ test eax, eax
+ jz .error
- mov ebx, eax
+ mov ebx, eax
- mov eax, [ebx + Image.Width]
- imul [ebx + Image.Height]
- shl eax, 1
- mov [ebx+Image.Palette], eax
- add eax, 256*4
- invoke mem.realloc, [ebx + Image.Data], eax
- mov [ebx + Image.Data], eax
- add [ebx + Image.Palette], eax
+ mov eax, [ebx + Image.Width]
+ imul [ebx + Image.Height]
+ shl eax, 1
+ mov [ebx + Image.Palette], eax
+ add eax, 256*4
+ invoke mem.realloc, [ebx + Image.Data], eax
+ mov [ebx + Image.Data], eax
+ add [ebx + Image.Palette], eax
- mov edx, XCF_BASETYPE_INDEXED
-; jmp .common_process
+ mov edx, XCF_BASETYPE_INDEXED
+; jmp .common_process
-.common_process:
+ .common_process:
- invoke mem.alloc, sizeof.xcf_ext
- or eax, eax
- jz .error
- mov [ebx+Image.Extended], eax
- mov [eax+xcf_ext.opacity], 0xffffffff
- mov [eax+xcf_ext.type], edx
+ invoke mem.alloc, sizeof.xcf_ext
+ or eax, eax
+ jz .error
+ mov [ebx + Image.Extended], eax
+ mov [eax + xcf_ext.opacity], 0xffffffff
+ mov [eax + xcf_ext.type], edx
- stdcall parse_properties, ebx
+ stdcall xcf._.parse_properties, ebx
- mov edi, esi
- mov eax, 0
- mov ecx, MAX_LAYERS
- mov [count], MAX_LAYERS-1
- repne scasd
- sub [count], ecx
- mov esi, edi
- mov ecx, 0
+ mov edi, esi
+ xor eax, eax
+ mov ecx, MAX_LAYERS
+ mov [layer_count], MAX_LAYERS-1
+ repne scasd
+ sub [layer_count], ecx
+ mov esi, edi
+ xor ecx, ecx
-.still: sub esi, 8
- lodsd
- bswap eax
+ .still:
+ sub esi, 8
+ lodsd
+ bswap eax
- push ecx
- stdcall decode_layer, eax, [_data]
- pop ecx
- test eax, eax
- jz @f
- push ecx
- stdcall merge_down, eax, [retvalue], ecx
- pop ecx
- add ecx, 1
-@@: dec [count]
- jnz .still
-; jmp .quit
+ push ecx
+ stdcall xcf._.decode_layer, eax, [_data]
+ pop ecx
+ test eax, eax
+ jz @f
+ push ecx
+ stdcall xcf._.merge_down, eax, [retvalue], ecx
+ pop ecx
+ add ecx, 1
+ @@:
+ dec [layer_count]
+ jnz .still
+ cmp [ebx + Image.Type], Image.bpp8
+ jne .quit
+ stdcall xcf._.pack_8a, ebx
+ jmp .quit
- cmp [ebx+Image.Type], Image.bpp8
- jne .quit
- stdcall pack_8a, ebx
- jmp .quit
-
-.error: mov [retvalue], 0
-.quit: pop edi esi ebx
- mov eax, [retvalue]
- ret
+ .error:
+ mov [retvalue], 0
+ .quit:
+ pop edi esi ebx
+ mov eax, [retvalue]
+ ret
endp
-
;;================================================================================================;;
proc img.encode.xcf _img, _p_length, _options ;///////////////////////////////////////////////////;;
;;------------------------------------------------------------------------------------------------;;
@@ -240,8 +241,8 @@ proc img.encode.xcf _img, _p_length, _options ;/////////////////////////////////
;< eax = 0 (error) or pointer to encoded data ;;
;< _p_length = encoded data length ;;
;;================================================================================================;;
- xor eax, eax
- ret
+ xor eax, eax
+ ret
endp
@@ -252,1056 +253,1128 @@ endp
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
-proc parse_properties _img
+proc xcf._.parse_properties _img
- mov ebx, [_img]
-.begin:
- lodsd
- bswap eax
+ mov ebx, [_img]
+ .begin:
+ lodsd
+ bswap eax
- mov ecx, (xcf_prop_table_end-xcf_prop_table_begin)/8
- mov edi, xcf_prop_table_begin
+ mov ecx, (xcf._.prop_table_end - xcf._.prop_table_begin)/8
+ mov edi, xcf._.prop_table_begin
-.still:
- cmp eax, [edi]
- jne @f
- jmp dword[edi+4]
-@@:
- add edi, 8
- dec ecx
- jnz .still
- lodsd ; skip
- bswap eax ; uninteresting
- add esi, eax ; property
- jmp .begin
+ .still:
+ cmp eax, [edi]
+ jne @f
+ jmp dword[edi + 4]
+ @@:
+ add edi, 8
+ dec ecx
+ jnz .still
+ lodsd
+ bswap eax
+ add esi, eax
+ jmp .begin
-parse_prop_00: ; PROP_END
- lodsd
- ret
-
-parse_prop_01: ; PROP_COLORMAP
- lodsd
- mov ecx, [ebx+Image.Extended]
- cmp [ecx+xcf_ext.type], XCF_BASETYPE_INDEXED
- je @f
- bswap eax
- add esi, eax
- jmp parse_properties.begin
-@@:
- lodsd
- bswap eax
- mov ecx, eax
- mov edi, [ebx+Image.Palette]
+ .00: ; PROP_END
+ lodsd
+ ret
-@@: lodsd
- sub esi, 1
- bswap eax
- shr eax, 8
- or eax, 0xff000000
- stosd
- dec ecx
- jnz @b
- jmp parse_properties.begin
+ .01: ; PROP_COLORMAP
+ lodsd
+ mov ecx, [ebx + Image.Extended]
+ cmp [ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
+ je @f
+ bswap eax
+ add esi, eax
+ jmp xcf._.parse_properties.begin
+ @@:
+ lodsd
+ bswap eax
+ mov ecx, eax
+ mov edi, [ebx + Image.Palette]
-parse_prop_06: ; PROP_OPACITY
- lodsd
- lodsd
- bswap eax
- mov ecx, [ebx+Image.Extended]
- mov [ecx+xcf_ext.opacity], eax
- jmp parse_properties.begin
+ @@:
+ lodsd
+ sub esi, 1
+ bswap eax
+ shr eax, 8
+ or eax, 0xff000000
+ stosd
+ dec ecx
+ jnz @b
+ jmp xcf._.parse_properties.begin
-parse_prop_07: ; PROP_MODE
- lodsd
- lodsd
- bswap eax
- mov ecx, [ebx+Image.Extended]
- mov [ecx+xcf_ext.layer_mode], eax
- jmp parse_properties.begin
+ .06: ; PROP_OPACITY
+ lodsd
+ lodsd
+ bswap eax
+ mov ecx, [ebx + Image.Extended]
+ mov [ecx + xcf_ext.opacity], eax
+ jmp xcf._.parse_properties.begin
-parse_prop_08: ; PROP_VISIBLE
- lodsd
- lodsd
- bswap eax
- mov ecx, [ebx+Image.Extended]
- mov [ecx+xcf_ext.visible], eax
- jmp parse_properties.begin
+ .07: ; PROP_MODE
+ lodsd
+ lodsd
+ bswap eax
+ mov ecx, [ebx + Image.Extended]
+ mov [ecx + xcf_ext.layer_mode], eax
+ jmp xcf._.parse_properties.begin
-parse_prop_11: ; PROP_APPLY_MASK
- lodsd
- lodsd
- bswap eax
- mov ecx, [ebx+Image.Extended]
- mov [ecx+xcf_ext.apply_mask], eax
- jmp parse_properties.begin
+ .08: ; PROP_VISIBLE
+ lodsd
+ lodsd
+ bswap eax
+ mov ecx, [ebx + Image.Extended]
+ mov [ecx + xcf_ext.visible], eax
+ jmp xcf._.parse_properties.begin
-parse_prop_15: ; PROP_OFFSETS
- lodsd
- lodsd
- mov ecx, [ebx+Image.Extended]
- bswap eax
- mov [ecx+xcf_ext.offset_x], eax
- lodsd
- bswap eax
- mov [ecx+xcf_ext.offset_y], eax
- jmp parse_properties.begin
+ .11: ; PROP_APPLY_MASK
+ lodsd
+ lodsd
+ bswap eax
+ mov ecx, [ebx + Image.Extended]
+ mov [ecx + xcf_ext.apply_mask], eax
+ jmp xcf._.parse_properties.begin
+
+ .15: ; PROP_OFFSETS
+ lodsd
+ lodsd
+ mov ecx, [ebx + Image.Extended]
+ bswap eax
+ mov [ecx + xcf_ext.offset_x], eax
+ lodsd
+ bswap eax
+ mov [ecx + xcf_ext.offset_y], eax
+ jmp xcf._.parse_properties.begin
endp
-proc decode_channel _channel_begin, _data
+proc xcf._.decode_channel _channel_begin, _data
locals
-channel_width rd 1
-channel_height rd 1
-planes_todo rd 1
-total_bpl rd 1
+ channel_width rd 1
+ channel_height rd 1
+ planes_todo rd 1
+ total_bpl rd 1
endl
- push ebx esi edi
- mov esi, [_channel_begin]
- add esi, [_data]
- lodsd
- bswap eax
- mov [channel_width], eax
- mov [total_bpl], eax
- lodsd
- bswap eax
- mov [channel_height], eax
- lodsd
- bswap eax
- add esi, eax
+ push ebx esi edi
+ mov esi, [_channel_begin]
+ add esi, [_data]
+ lodsd
+ bswap eax
+ mov [channel_width], eax
+ mov [total_bpl], eax
+ lodsd
+ bswap eax
+ mov [channel_height], eax
+ lodsd
+ bswap eax
+ add esi, eax
- stdcall img.create, [channel_width], [channel_height], Image.bpp8
- mov ebx, eax
- test ebx, ebx
- jz .quit
- invoke mem.alloc, sizeof.xcf_ext
- or eax, eax
- jz .error
- mov [ebx+Image.Extended], eax
+ stdcall img.create, [channel_width], [channel_height], Image.bpp8
+ mov ebx, eax
+ test ebx, ebx
+ jz .quit
+ invoke mem.alloc, sizeof.xcf_ext
+ or eax, eax
+ jz .error
+ mov [ebx + Image.Extended], eax
- stdcall parse_properties, ebx
+ stdcall xcf._.parse_properties, ebx
- lodsd
- bswap eax
- mov esi, eax
- add esi, [_data]
- lodsd
- lodsd
- lodsd
- bswap eax
- mov [planes_todo], eax
- lodsd
- bswap eax
- mov esi, eax
- add esi, [_data]
- lodsd
- lodsd
+ lodsd
+ bswap eax
+ mov esi, eax
+ add esi, [_data]
+ lodsd
+ lodsd
+ lodsd
+ bswap eax
+ mov [planes_todo], eax
+ lodsd
+ bswap eax
+ mov esi, eax
+ add esi, [_data]
+ lodsd
+ lodsd
- mov edi, [ebx+Image.Data]
- mov ecx, 0
-@@: lodsd
- test eax, eax
- jz .quit
- bswap eax
- add eax, [_data]
- stdcall decode_tile, eax, [channel_width], [channel_height], [total_bpl], [planes_todo], 1
- add ecx, 1
- jmp @b
-
-.error: stdcall img.destroy, ebx
- mov ebx, 0
-.quit: mov eax, ebx
- pop edi esi ebx
- ret
+ mov edi, [ebx + Image.Data]
+ mov ecx, 0
+ @@:
+ lodsd
+ test eax, eax
+ jz .quit
+ bswap eax
+ add eax, [_data]
+ stdcall xcf._.decode_tile, eax, [channel_width], [channel_height], [total_bpl], [planes_todo], 1
+ add ecx, 1
+ jmp @b
+
+ .error:
+ stdcall img.destroy, ebx
+ mov ebx, 0
+ .quit:
+ mov eax, ebx
+ pop edi esi ebx
+ ret
endp
-proc decode_layer _layer_begin, _data
+proc xcf._.decode_layer _layer_begin, _data
locals
-layer_width rd 1
-layer_height rd 1
-planes_todo rd 1
-total_bpl rd 1
-color_step rd 1
+ layer_width rd 1
+ layer_height rd 1
+ planes_todo rd 1
+ total_bpl rd 1
+ color_step rd 1
endl
- push ebx esi edi
- mov esi, [_layer_begin]
- add esi, [_data]
- lodsd
- bswap eax
- mov [layer_width], eax
- mov [total_bpl], eax
- shl [total_bpl], 1
- lodsd
- bswap eax
- mov [layer_height], eax
- lodsd
- bswap eax
- mov edx, Image.bpp16
- mov [color_step], 1
- cmp eax, 2
- jge @f
- mov [color_step], 3
- mov edx, Image.bpp32
- shl [total_bpl], 1
-@@: stdcall img.create, [layer_width], [layer_height], edx
- mov ebx, eax
- test ebx, ebx
- jz .quit
- invoke mem.alloc, sizeof.xcf_ext
- or eax, eax
- jz .error
- mov [ebx+Image.Extended], eax
+ push ebx esi edi
+ mov esi, [_layer_begin]
+ add esi, [_data]
+ lodsd
+ bswap eax
+ mov [layer_width], eax
+ mov [total_bpl], eax
+ shl [total_bpl], 1
+ lodsd
+ bswap eax
+ mov [layer_height], eax
+ lodsd
+ bswap eax
+ mov edx, Image.bpp16
+ mov [color_step], 1
+ cmp eax, 2
+ jge @f
+ mov [color_step], 3
+ mov edx, Image.bpp32
+ shl [total_bpl], 1
+ @@:
+ stdcall img.create, [layer_width], [layer_height], edx
+ mov ebx, eax
+ test ebx, ebx
+ jz .quit
+ invoke mem.alloc, sizeof.xcf_ext
+ or eax, eax
+ jz .error
+ mov [ebx + Image.Extended], eax
- lodsd
- bswap eax
- add esi, eax
- stdcall parse_properties, ebx
- mov edx, [ebx+Image.Extended]
- or [edx+xcf_ext.visible], 0
- jz .unvisible
+ lodsd
+ bswap eax
+ add esi, eax
+ stdcall xcf._.parse_properties, ebx
+ mov edx, [ebx + Image.Extended]
+ or [edx + xcf_ext.visible], 0
+ jz .unvisible
- lodsd
- bswap eax
- push esi
- mov esi, eax
- add esi, [_data]
- lodsd
- lodsd
- lodsd
- bswap eax
- mov [planes_todo], eax
-; mov ecx, [ebx+Image.Extended]
-; mov [ecx+xcf_ext.planes], eax
- lodsd
- bswap eax
- mov esi, eax
- add esi, [_data]
- lodsd
- lodsd
+ lodsd
+ bswap eax
+ push esi
+ mov esi, eax
+ add esi, [_data]
+ lodsd
+ lodsd
+ lodsd
+ bswap eax
+ mov [planes_todo], eax
+; mov ecx, [ebx + Image.Extended]
+; mov [ecx + xcf_ext.planes], eax
+ lodsd
+ bswap eax
+ mov esi, eax
+ add esi, [_data]
+ lodsd
+ lodsd
- mov edi, [ebx+Image.Data]
- mov ecx, 0
-@@: lodsd
- test eax, eax
- jz @f
- bswap eax
- add eax, [_data]
- stdcall decode_tile, eax, [layer_width], [layer_height], [total_bpl], [planes_todo], 0
- add ecx, 1
- jmp @b
-@@:
+ mov edi, [ebx + Image.Data]
+ mov ecx, 0
+ @@:
+ lodsd
+ test eax, eax
+ jz @f
+ bswap eax
+ add eax, [_data]
+ stdcall xcf._.decode_tile, eax, [layer_width], [layer_height], [total_bpl], [planes_todo], 0
+ add ecx, 1
+ jmp @b
+ @@:
- stdcall apply_opacity, ebx, [color_step]
+ stdcall xcf._.apply_opacity, ebx, [color_step]
- pop esi
- lodsd
- bswap eax
- test eax, eax
- jz .quit
-
- stdcall decode_channel, eax, [_data]
- test eax, eax
- jz .error
+ pop esi
+ lodsd
+ bswap eax
+ test eax, eax
+ jz .quit
- mov edx, [ebx+Image.Extended]
- cmp [edx+xcf_ext.apply_mask], 0
- je .quit
+ stdcall xcf._.decode_channel, eax, [_data]
+ test eax, eax
+ jz .error
- stdcall apply_alpha_mask, ebx, eax, [color_step]
- jmp .quit
+ mov edx, [ebx + Image.Extended]
+ cmp [edx + xcf_ext.apply_mask], 0
+ je .quit
-.unvisible:
-.error: stdcall img.destroy, ebx
- mov ebx, 0
-.quit: mov eax, ebx
- pop edi esi ebx
- ret
+ stdcall xcf._.apply_alpha_mask, ebx, eax, [color_step]
+ jmp .quit
+
+ .unvisible:
+ .error:
+ stdcall img.destroy, ebx
+ mov ebx, 0
+ .quit:
+ mov eax, ebx
+ pop edi esi ebx
+ ret
endp
-proc decode_tile _tile_data, _width, _height, _total_bpl, _bytes_pp, _is_channel
+proc xcf._.decode_tile _tile_data, _width, _height, _total_bpl, _bytes_pp, _is_channel
locals
-tile_x rd 1
-tile_y rd 1
-tile_width rd 1
-tile_height rd 1
-planes_todo rd 1
-color_step rd 1
+ tile_x rd 1
+ tile_y rd 1
+ tile_width rd 1
+ tile_height rd 1
+ planes_todo rd 1
+ color_step rd 1
endl
- push ebx ecx edx esi edi
- pushd [_bytes_pp]
- popd [planes_todo]
-
- cmp [_is_channel], 1
- je @f
- test [_bytes_pp], 0x01
- jz @f
- add [_bytes_pp], 1
-@@:
- mov ebx, [_bytes_pp]
- sub ebx, 1
- mov [color_step], ebx
+ push ebx ecx edx esi edi
+ pushd [_bytes_pp]
+ popd [planes_todo]
- mov esi, [_tile_data]
- mov eax, ecx
- mov ebx, [_width]
- dec ebx
- shr ebx, 6
- inc ebx
- mov edx, 0
- div bx
- mov [tile_x], edx
- mov [tile_y], eax
+ cmp [_is_channel], 1
+ je @f
+ test [_bytes_pp], 0x01
+ jz @f
+ add [_bytes_pp], 1
+ @@:
+ mov ebx, [_bytes_pp]
+ sub ebx, 1
+ mov [color_step], ebx
- mov [tile_width], 64
- mov ebx, [_width]
- test ebx, 0x0000003F
- jz @f
- dec ebx
- shr ebx, 6
- cmp ebx, [tile_x]
- jne @f
- mov ebx, [_width]
- and ebx, 0x0000003F
- mov [tile_width], ebx
-@@:
+ mov esi, [_tile_data]
+ mov eax, ecx
+ mov ebx, [_width]
+ dec ebx
+ shr ebx, 6
+ inc ebx
+ mov edx, 0
+ div bx
+ mov [tile_x], edx
+ mov [tile_y], eax
- mov [tile_height], 64
- mov ebx, [_height]
- test ebx, 0x0000003F
- jz @f
- dec ebx
- shr ebx, 6
- cmp ebx, [tile_y]
- jne @f
- mov ebx, [_height]
- and ebx, 0x0000003F
- mov [tile_height], ebx
-@@:
+ mov [tile_width], 64
+ mov ebx, [_width]
+ test ebx, 0x0000003F
+ jz @f
+ dec ebx
+ shr ebx, 6
+ cmp ebx, [tile_x]
+ jne @f
+ mov ebx, [_width]
+ and ebx, 0x0000003F
+ mov [tile_width], ebx
+ @@:
+
+ mov [tile_height], 64
+ mov ebx, [_height]
+ test ebx, 0x0000003F
+ jz @f
+ dec ebx
+ shr ebx, 6
+ cmp ebx, [tile_y]
+ jne @f
+ mov ebx, [_height]
+ and ebx, 0x0000003F
+ mov [tile_height], ebx
+ @@:
- mov eax, [_total_bpl]
- shl eax, 6
- mul [tile_y]
- add edi, eax
+ mov eax, [_total_bpl]
+ shl eax, 6
+ mul [tile_y]
+ add edi, eax
- mov eax, [tile_x]
- shl eax, 6
- imul eax, [_bytes_pp]
- add edi, eax
+ mov eax, [tile_x]
+ shl eax, 6
+ imul eax, [_bytes_pp]
+ add edi, eax
- cmp [_is_channel], 1
- jne @f
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- jmp .quit
-@@:
- mov eax, [planes_todo]
- dec eax
- jz .p1
- dec eax
- jz .p2
- dec eax
- jz .p3
- jmp .p4
-.p1:
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- add edi, 1
- stdcall fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
- jmp .quit
-.p2:
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- add edi, 1
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- jmp .quit
-.p3:
- add edi, 2
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- sub edi, 1
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- sub edi, 1
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- add edi, 3
- stdcall fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
- jmp .quit
-.p4:
- add edi, 2
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- sub edi, 1
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- sub edi, 1
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
- add edi, 3
- stdcall decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
-; jmp .quit
+ cmp [_is_channel], 1
+ jne @f
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ jmp .quit
+ @@:
+ mov eax, [planes_todo]
+ dec eax
+ jz .p1
+ dec eax
+ jz .p2
+ dec eax
+ jz .p3
+ jmp .p4
+ .p1:
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ add edi, 1
+ stdcall xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
+ jmp .quit
+ .p2:
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ add edi, 1
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ jmp .quit
+ .p3:
+ add edi, 2
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ sub edi, 1
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ sub edi, 1
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ add edi, 3
+ stdcall xcf._.fill_color, [tile_width], [tile_height], [_total_bpl], [_bytes_pp], [color_step]
+ jmp .quit
+ .p4:
+ add edi, 2
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ sub edi, 1
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ sub edi, 1
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+ add edi, 3
+ stdcall xcf._.decode_color, [tile_width], [tile_height], [color_step], [_total_bpl], [_bytes_pp]
+; jmp .quit
-.quit: pop edi esi edx ecx ebx
- ret
+ .quit:
+ pop edi esi edx ecx ebx
+ ret
endp
-proc fill_color _tile_width, _tile_height, _total_bpl, _bytes_pp, _color_step
- push ebx
- mov edx, [_color_step]
- mov ebx, [_total_bpl]
- mov eax, [_bytes_pp]
- mul byte[_tile_width]
- sub ebx, eax
-
- mov ch, byte[_tile_height]
- mov al, 0xff
-.still: mov cl, byte[_tile_width]
-@@: stosb
- add edi, edx
- dec cl
- jnz @b
- add edi, ebx
- dec ch
- jnz .still
- pop ebx
- ret
+proc xcf._.fill_color _tile_width, _tile_height, _total_bpl, _bytes_pp, _color_step
+ push ebx
+ mov edx, [_color_step]
+ mov ebx, [_total_bpl]
+ mov eax, [_bytes_pp]
+ mul byte[_tile_width]
+ sub ebx, eax
+
+ mov ch, byte[_tile_height]
+ mov al, 0xff
+ .line:
+ mov cl, byte[_tile_width]
+ @@:
+ stosb
+ add edi, edx
+ dec cl
+ jnz @b
+ add edi, ebx
+ dec ch
+ jnz .line
+ pop ebx
+ ret
endp
-proc decode_color _tile_width, _tile_height, _color_step, _total_bpl, _bytes_pp
+proc xcf._.decode_color _tile_width, _tile_height, _color_step, _total_bpl, _bytes_pp
locals
-level_width rd 1
-level_height rd 1
-line_step rd 1 ; [_total_bpl]-[_tile_width]*[_bytes_pp]
+ level_width rd 1
+ level_height rd 1
+ line_step rd 1 ; [_total_bpl] - [_tile_width]*[_bytes_pp]
endl
- push edi
+ push edi
- mov ebx, [_total_bpl]
- movzx eax, byte[_bytes_pp]
- mul byte[_tile_width]
- sub ebx, eax
- mov [line_step], ebx
- mov ebx, [_tile_height]
- mov edx, [_tile_width]
+ mov ebx, [_total_bpl]
+ movzx eax, byte[_bytes_pp]
+ mul byte[_tile_width]
+ sub ebx, eax
+ mov [line_step], ebx
+ mov ebx, [_tile_height]
+ mov edx, [_tile_width]
-.decode:lodsb
- cmp al, 127
- je .long_identical
- jb .short_identical
- test al, 0x7f
- jz .long_different
- jmp .short_different
+ .decode:
+ lodsb
+ cmp al, 127
+ je .long_identical
+ jb .short_identical
+ test al, 0x7f
+ jz .long_different
+ jmp .short_different
-.short_identical:
- movzx ecx, al
- add ecx, 1
- lodsb
- jmp .step1
-.long_identical:
- mov ecx, 0
- lodsw
- mov cx, ax
- xchg cl, ch
- lodsb
-.step1: cmp cx, dx
- je .step2
- jl .step3
- xchg cx, dx
- sub dx, cx
- sub bx, 1
-@@: stosb
- add edi, [_color_step]
- loop @b
- mov cx, dx
- mov edx, [_tile_width]
- add edi, [line_step]
- jmp .step1
+ .short_identical:
+ movzx ecx, al
+ add ecx, 1
+ lodsb
+ jmp .step1
+ .long_identical:
+ mov ecx, 0
+ lodsw
+ mov cx, ax
+ xchg cl, ch
+ lodsb
+ .step1:
+ cmp cx, dx
+ je .step2
+ jl .step3
+ xchg cx, dx
+ sub dx, cx
+ sub bx, 1
+ @@:
+ stosb
+ add edi, [_color_step]
+ loop @b
+ mov cx, dx
+ mov edx, [_tile_width]
+ add edi, [line_step]
+ jmp .step1
-.step2:
-@@: stosb
- add edi, [_color_step]
- loop @b
- mov edx, [_tile_width]
- add edi, [line_step]
- dec bx
- jz .quit
- jmp .decode
-.step3: sub dx, cx
-@@: stosb
- add edi, [_color_step]
- loop @b
- jmp .decode
+ .step2:
+ @@:
+ stosb
+ add edi, [_color_step]
+ loop @b
+ mov edx, [_tile_width]
+ add edi, [line_step]
+ dec bx
+ jz .quit
+ jmp .decode
+ .step3:
+ sub dx, cx
+ @@:
+ stosb
+ add edi, [_color_step]
+ loop @b
+ jmp .decode
-.short_different:
- movzx ecx, al
- neg cx
- add cx, 256
- jmp .step4
-.long_different:
- mov ecx, 0
- lodsb
- mov ch, al
- lodsb
- mov cl, al
-.step4: cmp cx, dx
- je .step5
- jl .step6
- xchg cx, dx
- sub dx, cx
- sub bx, 1
-@@: movsb
- add edi, [_color_step]
- loop @b
- mov cx, dx
- mov edx, [_tile_width]
- add edi, [line_step]
- jmp .step4
+ .short_different:
+ movzx ecx, al
+ neg cx
+ add cx, 256
+ jmp .step4
+ .long_different:
+ mov ecx, 0
+ lodsb
+ mov ch, al
+ lodsb
+ mov cl, al
+ .step4:
+ cmp cx, dx
+ je .step5
+ jl .step6
+ xchg cx, dx
+ sub dx, cx
+ sub bx, 1
+ @@:
+ movsb
+ add edi, [_color_step]
+ loop @b
+ mov cx, dx
+ mov edx, [_tile_width]
+ add edi, [line_step]
+ jmp .step4
-.step5:
-@@: movsb
- add edi, [_color_step]
- loop @b
- mov edx, [_tile_width]
- add edi, [line_step]
- dec bx
- jz .quit
- jmp .decode
+ .step5:
+ @@:
+ movsb
+ add edi, [_color_step]
+ loop @b
+ mov edx, [_tile_width]
+ add edi, [line_step]
+ dec bx
+ jz .quit
+ jmp .decode
-.step6: sub dx, cx
-@@: movsb
- add edi, [_color_step]
- loop @b
- jmp .decode
+ .step6:
+ sub dx, cx
+ @@:
+ movsb
+ add edi, [_color_step]
+ loop @b
+ jmp .decode
-.quit: pop edi
- ret
+ .quit:
+ pop edi
+ ret
endp
-proc merge_down _img, _bottom, _layer_number
+proc xcf._.merge_down _img, _bottom, _layer_number
locals
-copy_width rd 1
-copy_height rd 1
-img_x1 rd 1
-img_y1 rd 1
-bottom_x1 rd 1
-bottom_y1 rd 1
-img_total_bpl rd 1
-bottom_total_bpl rd 1
-img_length rd 1
-bottom_length rd 1
+ copy_width rd 1
+ copy_height rd 1
+ img_x1 rd 1
+ img_y1 rd 1
+ bottom_x1 rd 1
+ bottom_y1 rd 1
+ img_total_bpl rd 1
+ bottom_total_bpl rd 1
+ img_length rd 1
+ bottom_length rd 1
endl
- push ebx esi edi
+ push ebx esi edi
- mov ebx, [_bottom]
- mov edx, [_img]
+ mov ebx, [_bottom]
+ mov edx, [_img]
- mov [img_x1], 0
- push [edx+Image.Width]
- pop [img_length]
+ mov [img_x1], 0
+ push [edx + Image.Width]
+ pop [img_length]
- mov [bottom_x1], 0
- mov ecx, [ebx+Image.Width]
- mov [bottom_length], ecx
+ mov [bottom_x1], 0
+ mov ecx, [ebx + Image.Width]
+ mov [bottom_length], ecx
- mov eax, [edx+Image.Extended]
- movsx eax, word[eax+xcf_ext.offset_x]
- cmp eax, 0
- jg .greater_x
- jl .lesser_x
- mov [copy_width], ecx
- jmp .done_x
-.greater_x:
- add [bottom_x1], eax
- sub [bottom_length], eax
- jns .label_x
- mov [copy_width], 0
- jmp .done_x
-.lesser_x:
- sub [img_x1], eax
- add [img_length], eax
- jns .label_x
- mov [copy_width], 0
- jmp .done_x
-.label_x:
- mov ecx, [img_length]
- cmp ecx, [bottom_length]
- jng @f
- mov ecx, [bottom_length]
-@@:
- mov [copy_width], ecx
-.done_x:
+ mov eax, [edx + Image.Extended]
+ movsx eax, word[eax + xcf_ext.offset_x]
+ cmp eax, 0
+ jg .greater_x
+ jl .lesser_x
+ mov [copy_width], ecx
+ jmp .done_x
+ .greater_x:
+ add [bottom_x1], eax
+ sub [bottom_length], eax
+ jns .label_x
+ mov [copy_width], 0
+ jmp .done_x
+ .lesser_x:
+ sub [img_x1], eax
+ add [img_length], eax
+ jns .label_x
+ mov [copy_width], 0
+ jmp .done_x
+ .label_x:
+ mov ecx, [img_length]
+ cmp ecx, [bottom_length]
+ jng @f
+ mov ecx, [bottom_length]
+ @@:
+ mov [copy_width], ecx
+ .done_x:
- mov [img_y1], 0
- push [edx+Image.Height]
- pop [img_length]
+ mov [img_y1], 0
+ push [edx + Image.Height]
+ pop [img_length]
- mov [bottom_y1], 0
- mov ecx, [ebx+Image.Height]
- mov [bottom_length], ecx
+ mov [bottom_y1], 0
+ mov ecx, [ebx + Image.Height]
+ mov [bottom_length], ecx
- mov eax, [edx+Image.Extended]
- movsx eax, word[eax+xcf_ext.offset_y]
- cmp eax, 0
- jg .greater_y
- jl .lesser_y
- mov [copy_height], ecx
- jmp .done_y
-.greater_y:
- add [bottom_y1], eax
- sub [bottom_length], eax
- jns .label_y
- mov [copy_height], 0
- jmp .done_y
-.lesser_y:
- sub [img_y1], eax
- add [img_length], eax
- jns .label_y
- mov [copy_height], 0
- jmp .done_y
-.label_y:
- mov ecx, [img_length]
- cmp ecx, [bottom_length]
- jng @f
- mov ecx, [bottom_length]
-@@:
- mov [copy_height], ecx
-.done_y:
+ mov eax, [edx + Image.Extended]
+ movsx eax, word[eax + xcf_ext.offset_y]
+ cmp eax, 0
+ jg .greater_y
+ jl .lesser_y
+ mov [copy_height], ecx
+ jmp .done_y
+ .greater_y:
+ add [bottom_y1], eax
+ sub [bottom_length], eax
+ jns .label_y
+ mov [copy_height], 0
+ jmp .done_y
+ .lesser_y:
+ sub [img_y1], eax
+ add [img_length], eax
+ jns .label_y
+ mov [copy_height], 0
+ jmp .done_y
+ .label_y:
+ mov ecx, [img_length]
+ cmp ecx, [bottom_length]
+ jng @f
+ mov ecx, [bottom_length]
+ @@:
+ mov [copy_height], ecx
+ .done_y:
- mov esi, [edx+Image.Data]
- mov edi, [ebx+Image.Data]
+ mov esi, [edx + Image.Data]
+ mov edi, [ebx + Image.Data]
- mov eax, [edx+Image.Width]
- imul eax, [img_y1]
- add eax, [img_x1]
- shl eax, 1
- cmp [edx+Image.Width], Image.bpp16
- je @f
- shl eax, 1
-@@: add esi, eax
+ mov eax, [edx + Image.Width]
+ imul eax, [img_y1]
+ add eax, [img_x1]
+ shl eax, 1
+ cmp [edx + Image.Width], Image.bpp16
+ je @f
+ shl eax, 1
+ @@:
+ add esi, eax
- mov eax, [ebx+Image.Width]
- imul eax, [bottom_y1]
- add eax, [bottom_x1]
- shl eax, 1
- cmp [ebx+Image.Width], Image.bpp8
- je @f
- shl eax, 1
-@@: add edi, eax
+ mov eax, [ebx + Image.Width]
+ imul eax, [bottom_y1]
+ add eax, [bottom_x1]
+ shl eax, 1
+ cmp [ebx + Image.Width], Image.bpp8
+ je @f
+ shl eax, 1
+ @@:
+ add edi, eax
- mov eax, [edx+Image.Width]
- sub eax, [copy_width]
- shl eax, 1
- cmp [edx+Image.Width], Image.bpp16
- je @f
- shl eax, 1
-@@: mov [img_total_bpl], eax
+ mov eax, [edx + Image.Width]
+ sub eax, [copy_width]
+ shl eax, 1
+ cmp [edx + Image.Width], Image.bpp16
+ je @f
+ shl eax, 1
+ @@:
+ mov [img_total_bpl], eax
- mov eax, [ebx+Image.Width]
- sub eax, [copy_width]
- shl eax, 1
- cmp [ebx+Image.Width], Image.bpp8
- je @f
- shl eax, 1
-@@: mov [bottom_total_bpl], eax
+ mov eax, [ebx + Image.Width]
+ sub eax, [copy_width]
+ shl eax, 1
+ cmp [ebx + Image.Width], Image.bpp8
+ je @f
+ shl eax, 1
+ @@:
+ mov [bottom_total_bpl], eax
- cmp [_layer_number], 0
- jne .not_first
- mov ecx, [copy_width]
- imul ecx, [copy_height]
- cmp [ebx+Image.Type], Image.bpp8
- je .bpp8
-.bpp32: rep movsd
- jmp .done
-.bpp8: rep movsw
- jmp .done
-.not_first:
+ cmp [_layer_number], 0
+ jne .not_first
+ mov ecx, [copy_width]
+ imul ecx, [copy_height]
+ cmp [ebx + Image.Type], Image.bpp8
+ je .bpp8a
+ .bpp32:
+ rep movsd
+ jmp .done
+ .bpp8a:
+ rep movsw
+ jmp .done
+ .not_first:
- push edi
- mov ecx, [edx+Image.Extended]
- mov eax, [ecx+xcf_ext.layer_mode]
+ push edi
+ mov ecx, [edx + Image.Extended]
+ mov eax, [ecx + xcf_ext.layer_mode]
- mov ecx, [ebx+Image.Extended]
- mov ecx, [ecx+xcf_ext.type]
-
- cmp ecx, XCF_BASETYPE_RGB
- jne @f
- mov edx, 4
- jmp .type_defined
-@@:
- cmp ecx, XCF_BASETYPE_GRAY
- jne @f
- mov edx, 8
- jmp .type_defined
-@@:
- mov edx, 12
-.type_defined:
- mov ecx, (composite_table_end-composite_table_begin)/8
- mov edi, composite_table_begin
+ mov ecx, [ebx + Image.Extended]
+ mov ecx, [ecx + xcf_ext.type]
-.still:
- cmp eax, [edi]
- jne @f
- add edi, edx
- mov edx, [edi]
- jmp .composite_found
-@@:
- add edi, 16
- dec ecx
- jnz .still
+ cmp ecx, XCF_BASETYPE_RGB
+ jne @f
+ mov edx, 4
+ jmp .type_defined
+ @@:
+ cmp ecx, XCF_BASETYPE_GRAY
+ jne @f
+ mov edx, 8
+ jmp .type_defined
+ @@:
+ mov edx, 12
+ .type_defined:
+ mov ecx, (xcf._.composite_table.end - xcf._.composite_table.begin) / 8
+ mov edi, xcf._.composite_table.begin
-.composite_found:
- pop edi
+ .still:
+ cmp eax, [edi]
+ jne @f
+ add edi, edx
+ mov edx, [edi]
+ jmp .composite_found
+ @@:
+ add edi, 16
+ dec ecx
+ jnz .still
- mov ecx, [ebx+Image.Extended]
- cmp [ecx+xcf_ext.type], XCF_BASETYPE_INDEXED
- jne @f
- stdcall edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
- jmp .done
-@@:
- cmp eax, 1
- ja @f
- stdcall edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
- jmp .done
-@@:
+ .composite_found:
+ pop edi
+
+ mov ecx, [ebx + Image.Extended]
+ cmp [ecx + xcf_ext.type], XCF_BASETYPE_INDEXED
+ jne @f
+ stdcall edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
+ jmp .done
+ @@:
+ cmp eax, 1
+ ja @f
+ stdcall edx, [copy_width], [copy_height], [bottom_total_bpl], [img_total_bpl]
+ jmp .done
+ @@:
- cmp [ebx+Image.Type], Image.bpp8
- jne @f
- stdcall merge_8a, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
- jmp .done
-@@: stdcall merge_32, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
-; jmp .done
-.done:
- stdcall img.destroy, [_img]
- pop edi esi ebx
- ret
+ cmp [ebx + Image.Type], Image.bpp8
+ jne @f
+ stdcall xcf._.merge_8a, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
+ jmp .done
+ @@:
+ stdcall xcf._.merge_32, [copy_width], [copy_height], [img_total_bpl], [bottom_total_bpl]
+; jmp .done
+ .done:
+ stdcall img.destroy, [_img]
+ pop edi esi ebx
+ ret
endp
-proc pack_8a _img
- mov ebx, [_img]
- mov esi, [ebx+Image.Data]
- mov edi, [ebx+Image.Data]
- mov ecx, [ebx+Image.Width]
- mov edx, [ebx+Image.Height]
- imul ecx, edx
-@@: lodsw
- stosb
- dec ecx
- jnz @b
- ret
+proc xcf._.pack_8a _img
+ mov ebx, [_img]
+ mov esi, [ebx + Image.Data]
+ mov edi, esi
+ mov ecx, [ebx + Image.Width]
+ imul ecx, [ebx + Image.Height]
+ @@:
+ lodsw
+ stosb
+ dec ecx
+ jnz @b
+ ret
endp
-proc apply_opacity _img, _color_step
+proc xcf._.apply_opacity _img, _color_step
- push ebx
-
- mov edx, [ebx+Image.Extended]
- mov edx, [edx+xcf_ext.opacity]
- cmp dl, 0xff
- je .quit
+ push ebx
- mov ecx, [ebx+Image.Width]
- imul ecx, [ebx+Image.Height]
- mov esi, [ebx+Image.Data]
- mov ebx, [_color_step]
- add esi, ebx
- mov edi, esi
-@@: lodsb
- mul dl
- shr ax, 8
- stosb
- add esi, ebx
- add edi, ebx
- dec ecx
- jnz @b
-
-.quit: pop ebx
- ret
+ mov edx, [ebx + Image.Extended]
+ mov edx, [edx + xcf_ext.opacity]
+ cmp dl, 0xff
+ je .quit
+
+ mov ecx, [ebx + Image.Width]
+ imul ecx, [ebx + Image.Height]
+ mov esi, [ebx + Image.Data]
+ mov ebx, [_color_step]
+ add esi, ebx
+ mov edi, esi
+ @@:
+ lodsb
+ mul dl
+ shr ax, 8
+ stosb
+ add esi, ebx
+ add edi, ebx
+ dec ecx
+ jnz @b
+
+ .quit:
+ pop ebx
+ ret
endp
-proc apply_alpha_mask _img, _mask, _color_step
+proc xcf._.apply_alpha_mask _img, _mask, _color_step
- push ebx
+ push ebx
- mov ebx, [_img]
- mov esi, [_mask]
- mov esi, [esi+Image.Data]
- mov edi, [ebx+Image.Data]
- mov ecx, [ebx+Image.Width]
- imul ecx, [ebx+Image.Height]
- mov ebx, [_color_step]
- add edi, ebx
-@@:
- lodsb
- mul byte[edi]
- shr ax, 8
- stosb
- add edi, ebx
- dec ecx
- jnz @b
+ mov ebx, [_img]
+ mov esi, [_mask]
+ mov esi, [esi + Image.Data]
+ mov edi, [ebx + Image.Data]
+ mov ecx, [ebx + Image.Width]
+ imul ecx, [ebx + Image.Height]
+ mov ebx, [_color_step]
+ add edi, ebx
+ @@:
+ lodsb
+ mul byte[edi]
+ shr ax, 8
+ stosb
+ add edi, ebx
+ dec ecx
+ jnz @b
- stdcall img.destroy, [_mask]
- pop ebx
- ret
+ stdcall img.destroy, [_mask]
+ pop ebx
+ ret
endp
-proc pixel_rgb2hsv
+;;================================================================================================;;
+proc xcf._.rgb2hsv ;///////////////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? convert color from RGB to HSV space ;;
+;;------------------------------------------------------------------------------------------------;;
+;> eax = color (0xAARRGGBB) ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = color (0xAAHHSSVV) ;;
+;;================================================================================================;;
locals
-vsha rd 1
-max rd 1
-min rd 1
-med rd 1
+ vsha rd 1
+ max rd 1
+ min rd 1
+ med rd 1
endl
- push ebx ecx edx
+ push ebx ecx edx
- mov [vsha], eax
- movzx eax, byte[vsha] ; eax = al = blue
- movzx ecx, byte[vsha+1] ; ecx = cl = green
- movzx edx, byte[vsha+2] ; edx = dl = red
+ mov [vsha], eax
+ movzx eax, byte[vsha] ; eax = al = blue
+ movzx ecx, byte[vsha+1] ; ecx = cl = green
+ movzx edx, byte[vsha+2] ; edx = dl = red
- cmp al, cl
- jne @f
- cmp al, dl
- jne @f
- ror eax, 8
- mov ax, 0
- rol eax, 8
- jmp .quit
+ cmp al, cl
+ jne @f
+ cmp al, dl
+ jne @f
+ ror eax, 8
+ mov ax, 0
+ rol eax, 8
+ jmp .quit
-@@: cmp dl, cl
- ja @f
- cmp dl, al
- ja @f
- mov byte[min], dl
- jmp .min_found
-@@: cmp cl, al
- ja @f
- cmp cl, dl
- ja @f
- mov byte[min], cl
- jmp .min_found
-@@: mov byte[min], al
-; jmp .min_found
-.min_found:
+ @@:
+ cmp dl, cl
+ ja @f
+ cmp dl, al
+ ja @f
+ mov byte[min], dl
+ jmp .min_found
+ @@:
+ cmp cl, al
+ ja @f
+ cmp cl, dl
+ ja @f
+ mov byte[min], cl
+ jmp .min_found
+ @@:
+ mov byte[min], al
+; jmp .min_found
+ .min_found:
- cmp dl, cl
- jb @f
- cmp dl, al
- jb @f
- mov byte[max], dl
- sub cx, ax
- mov dx, cx
- mov cx, 0
- jmp .max_found
-@@: cmp cl, al
- jb @f
- cmp cl, dl
- jb @f
- mov byte[max], cl
- sub ax, dx
- mov dx, ax
- mov cx, 85
- jmp .max_found
-@@: mov byte[max], al
- sub dx, cx
- mov cx, 171
-; jmp .max_found
-.max_found:
+ cmp dl, cl
+ jb @f
+ cmp dl, al
+ jb @f
+ mov byte[max], dl
+ sub cx, ax
+ mov dx, cx
+ mov cx, 0
+ jmp .max_found
+ @@:
+ cmp cl, al
+ jb @f
+ cmp cl, dl
+ jb @f
+ mov byte[max], cl
+ sub ax, dx
+ mov dx, ax
+ mov cx, 85
+ jmp .max_found
+ @@:
+ mov byte[max], al
+ sub dx, cx
+ mov cx, 171
+; jmp .max_found
+ .max_found:
- mov al, byte[max]
- sub al, byte[min]
- mov byte[med], al
+ mov al, byte[max]
+ sub al, byte[min]
+ mov byte[med], al
- imul dx, 43
- movsx eax, dx
- ror eax, 16
- mov dx, ax
- rol eax, 16
- mov byte[med+1], 0
- idiv word[med]
- add al, cl
- mov byte[vsha+2], al
-
- mov al, byte[max]
- mov byte[vsha], al
+ imul dx, 43
+ movsx eax, dx
+ ror eax, 16
+ mov dx, ax
+ rol eax, 16
+ mov byte[med + 1], 0
+ idiv word[med]
+ add al, cl
+ mov byte[vsha + 2], al
- mov byte[vsha+1], 0
- test al, al
- jz @f
- mov byte[vsha+1], 0xff
- cmp al, byte[med]
- je @f
- mov al, byte[med]
- shl ax, 8
- div byte[max]
- mov byte[vsha+1], al
-@@:
- mov eax, [vsha]
+ mov al, byte[max]
+ mov byte[vsha], al
-.quit: pop edx ecx ebx
- ret
+ mov byte[vsha + 1], 0
+ test al, al
+ jz @f
+ mov byte[vsha + 1], 0xff
+ cmp al, byte[med]
+ je @f
+ mov al, byte[med]
+ shl ax, 8
+ div byte[max]
+ mov byte[vsha + 1], al
+ @@:
+ mov eax, [vsha]
+
+ .quit:
+ pop edx ecx ebx
+ ret
endp
-proc pixel_hsv2rgb
+;;================================================================================================;;
+proc xcf._.hsv2rgb ;///////////////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? convert color from HSV to RGB space ;;
+;;------------------------------------------------------------------------------------------------;;
+;> eax = color (0xAAHHSSVV) ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = color (0xAARRGGBB) ;;
+;;================================================================================================;;
locals
-vsha rd 1
-f rb 1
-c rb 1
-x rb 1
+ vsha rd 1
+ f rb 1
+ c rb 1
+ x rb 1
endl
- push ebx ecx edx
+ push ebx ecx edx
- mov [vsha], eax
- mov bl, byte[vsha+1]
- mul bl
- mov byte[c], ah
-
- movzx eax, byte[vsha+2]
- cmp eax, 43
- ja @f
- lea eax, [eax*3]
- shl eax, 1
- mov ebx, eax
- shr ebx, 7
- sub eax, ebx
- shr ebx, 1
- sub eax, ebx
- jmp .ok
+ mov [vsha], eax
+ mov bl, byte[vsha + 1]
+ mul bl
+ mov byte[c], ah
-@@: cmp eax, 86
- ja @f
- sub eax, 44
- lea eax, [eax*3]
- shl eax, 1
- neg al
- add al, 0xff
- jmp .ok
+ movzx eax, byte[vsha + 2]
+ cmp eax, 43
+ ja @f
+ lea eax, [eax*3]
+ shl eax, 1
+ mov ebx, eax
+ shr ebx, 7
+ sub eax, ebx
+ shr ebx, 1
+ sub eax, ebx
+ jmp .ok
-@@: cmp eax, 129
- ja @f
- sub eax, 87
- lea eax, [eax*3]
- shl eax, 1
- jmp .ok
+ @@:
+ cmp eax, 86
+ ja @f
+ sub eax, 44
+ lea eax, [eax*3]
+ shl eax, 1
+ neg al
+ add al, 0xff
+ jmp .ok
-@@: cmp eax, 171
- ja @f
- sub eax, 130
- lea eax, [eax*3]
- shl eax, 1
- neg al
- add al, 0xff
- jmp .ok
+ @@:
+ cmp eax, 129
+ ja @f
+ sub eax, 87
+ lea eax, [eax*3]
+ shl eax, 1
+ jmp .ok
-@@: cmp eax, 214
- ja @f
- sub eax, 172
- lea eax, [eax*3]
- shl eax, 1
- jmp .ok
-@@:
- sub eax, 215
- lea eax, [eax*3]
- shl eax, 1
- neg al
- add al, 0xff
-; jmp .ok
-.ok:
-
- neg al
- add al, 0xff
- neg al
- add al, 0xff
-; shr ax, 8
- mul byte[c]
- mov byte[x], ah
+ @@:
+ cmp eax, 171
+ ja @f
+ sub eax, 130
+ lea eax, [eax*3]
+ shl eax, 1
+ neg al
+ add al, 0xff
+ jmp .ok
+
+ @@:
+ cmp eax, 214
+ ja @f
+ sub eax, 172
+ lea eax, [eax*3]
+ shl eax, 1
+ jmp .ok
+ @@:
+ sub eax, 215
+ lea eax, [eax*3]
+ shl eax, 1
+ neg al
+ add al, 0xff
+; jmp .ok
+ .ok:
+
+ neg al
+ add al, 0xff
+ neg al
+ add al, 0xff
+; shr ax, 8
+ mul byte[c]
+ mov byte[x], ah
- mov al, byte[vsha+2]
- cmp al, 43
- jae @f
- mov eax, [vsha]
- shr eax, 8
- mov ah, byte[c]
- shl eax, 8
- mov ah, byte[x]
- mov al, 0
- jmp .done
+ mov al, byte[vsha+2]
+ cmp al, 43
+ jae @f
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, byte[c]
+ shl eax, 8
+ mov ah, byte[x]
+ mov al, 0
+ jmp .done
-@@: cmp al, 86
- jae @f
- mov eax, [vsha]
- shr eax, 8
- mov ah, byte[x]
- shl eax, 8
- mov ah, byte[c]
- mov al, 0
- jmp .done
-
-@@: cmp al, 129
- jae @f
- mov eax, [vsha]
- shr eax, 8
- mov ah, 0
- shl eax, 8
- mov ah, byte[c]
- mov al, byte[x]
- jmp .done
+ @@:
+ cmp al, 86
+ jae @f
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, byte[x]
+ shl eax, 8
+ mov ah, byte[c]
+ mov al, 0
+ jmp .done
-@@: cmp al, 171
- jae @f
- mov eax, [vsha]
- shr eax, 8
- mov ah, 0
- shl eax, 8
- mov ah, byte[x]
- mov al, byte[c]
- jmp .done
+ @@:
+ cmp al, 129
+ jae @f
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, 0
+ shl eax, 8
+ mov ah, byte[c]
+ mov al, byte[x]
+ jmp .done
-@@: cmp al, 214
- jae @f
- mov eax, [vsha]
- shr eax, 8
- mov ah, byte[x]
- shl eax, 8
- mov ah, 0
- mov al, byte[c]
- jmp .done
+ @@:
+ cmp al, 171
+ jae @f
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, 0
+ shl eax, 8
+ mov ah, byte[x]
+ mov al, byte[c]
+ jmp .done
-@@: mov eax, [vsha]
- shr eax, 8
- mov ah, byte[c]
- shl eax, 8
- mov ah, 0
- mov al, byte[x]
-; jmp .done
+ @@:
+ cmp al, 214
+ jae @f
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, byte[x]
+ shl eax, 8
+ mov ah, 0
+ mov al, byte[c]
+ jmp .done
-.done:
- mov bl, byte[vsha]
- sub bl, byte[c]
- ror eax, 8
- add ah, bl
- rol eax, 8
- add ah, bl
- add al, bl
+ @@:
+ mov eax, [vsha]
+ shr eax, 8
+ mov ah, byte[c]
+ shl eax, 8
+ mov ah, 0
+ mov al, byte[x]
+; jmp .done
-.quit: pop edx ecx ebx
- ret
+ .done:
+ mov bl, byte[vsha]
+ sub bl, byte[c]
+ ror eax, 8
+ add ah, bl
+ rol eax, 8
+ add ah, bl
+ add al, bl
+
+ .quit:
+ pop edx ecx ebx
+ ret
endp
-proc pixel_rgb2hsl
+;;================================================================================================;;
+proc xcf._.rgb2hsl ;///////////////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? convert color from RGB to HSL space ;;
+;;------------------------------------------------------------------------------------------------;;
+;> eax = color (0xAARRGGBB) ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = color (0xAAHHSSLL) ;;
+;;================================================================================================;;
; http://www.asmcommunity.net/board/index.php?topic=7425
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish. That's why I made this post, to share."
; so pixel_rgb2hsl procedure is based on code by Greg Hoyer (iblis). thanks!
@@ -1324,84 +1397,98 @@ proc pixel_rgb2hsl
; Luminance values to floating point, and then divide by 255. ;
;--------------------------------------------------------------;
locals
-bgra rd 1
+ bgra rd 1
endl
- push ebx esi edi
+ push ebx esi edi
- mov [bgra], eax
+ mov [bgra], eax
- movzx esi, byte[bgra+0]
- movzx edi, byte[bgra+1]
- movzx ebx, byte[bgra+2]
- mov cl, -1
- cmp esi, edi
- ja .cmp1
- xchg esi, edi
- neg cl
- shl cl, 1
-.cmp1: cmp edi, ebx
- jb .cmp2
- xchg edi, ebx
- neg cl
-.cmp2: cmp esi, ebx
- ja .cmp3
- xchg esi, ebx
- not cl
-.cmp3: neg ebx
- add ebx, esi
- mov eax, edi
- add edi, esi
- jz .done
- sub esi, eax
- jz .done
- mov eax, esi
- shl eax, 8
- sub eax, esi
- push edi
- cmp edi, 0xff
- jbe .csat
- neg edi
- add edi, 510
-.csat: xor edx, edx
- div edi
- pop edi
- shr edi, 1
- shl eax, 8
- or edi, eax
- add cl, 3
- jnc .noneg
- neg ebx
-.noneg: shl cl, 2
- mov eax, 0x13135db9
- shr eax, cl
- and eax, 7
- mul esi
- add eax, ebx
- mov ebx, eax
- shl eax, 8
- sub eax, ebx
- mov ebx, esi
- shl esi, 1
- lea ebx, [ebx*4+esi]
- xor edx, edx
- div ebx
- shl eax, 16
- or eax, edi
-.done: bswap eax
- shr eax, 8
+ movzx esi, byte[bgra + 0]
+ movzx edi, byte[bgra + 1]
+ movzx ebx, byte[bgra + 2]
+ mov cl, -1
+ cmp esi, edi
+ ja .cmp1
+ xchg esi, edi
+ neg cl
+ shl cl, 1
+ .cmp1:
+ cmp edi, ebx
+ jb .cmp2
+ xchg edi, ebx
+ neg cl
+ .cmp2:
+ cmp esi, ebx
+ ja .cmp3
+ xchg esi, ebx
+ not cl
+ .cmp3:
+ neg ebx
+ add ebx, esi
+ mov eax, edi
+ add edi, esi
+ jz .done
+ sub esi, eax
+ jz .done
+ mov eax, esi
+ shl eax, 8
+ sub eax, esi
+ push edi
+ cmp edi, 0xff
+ jbe .csat
+ neg edi
+ add edi, 510
+ .csat:
+ xor edx, edx
+ div edi
+ pop edi
+ shr edi, 1
+ shl eax, 8
+ or edi, eax
+ add cl, 3
+ jnc .noneg
+ neg ebx
+ .noneg:
+ shl cl, 2
+ mov eax, 0x13135db9
+ shr eax, cl
+ and eax, 7
+ mul esi
+ add eax, ebx
+ mov ebx, eax
+ shl eax, 8
+ sub eax, ebx
+ mov ebx, esi
+ shl esi, 1
+ lea ebx, [ebx*4 + esi]
+ xor edx, edx
+ div ebx
+ shl eax, 16
+ or eax, edi
+ .done:
+ bswap eax
+ shr eax, 8
- mov bl, byte[bgra+3]
- bswap eax
- mov al, bl
- ror eax, 8
+ mov bl, byte[bgra + 3]
+ bswap eax
+ mov al, bl
+ ror eax, 8
- pop edi esi ebx
- ret
+ pop edi esi ebx
+ ret
endp
-proc pixel_hsl2rgb
+;;================================================================================================;;
+proc xcf._.hsl2rgb ;///////////////////////////////////////////////////////////////////////////;;
+;;------------------------------------------------------------------------------------------------;;
+;? convert color from HSL to RGB space ;;
+;;------------------------------------------------------------------------------------------------;;
+;> eax = color (0xAAHHSSLL) ;;
+;;------------------------------------------------------------------------------------------------;;
+;< eax = color (0xAARRGGBB) ;;
+;;================================================================================================;;
; http://www.asmcommunity.net/board/index.php?topic=7425
; iblis: "I don't know what X-Filez is, but yes you may use it however you wish. That's why I made this post, to share."
; so pixel_hsl2rgb procedure is based on code by Greg Hoyer (iblis). thanks!
@@ -1423,109 +1510,116 @@ proc pixel_hsl2rgb
; ...where x represents any one of the HSL values. ;
;--------------------------------------------------------------;
locals
-lsha rd 1
+ lsha rd 1
endl
- push ebx esi edi
-
- mov [lsha], eax
+ push ebx esi edi
- movzx ebx, byte[lsha+0]
- lea esi, [ebx*2]
- movzx edi, byte[lsha+1]
- xor eax, eax
- mov cl, 1
- cmp bl, 0x7f
- ja .lcase
- dec al
- xor ecx, ecx
-.lcase: add eax, edi
- mul ebx
- or ecx, ecx
- jz .scase
- neg eax
- mov ecx, ebx
- add ecx, edi
- mov edx, ecx
- shl ecx, 8
- sub ecx, edx
- add eax, ecx
-.scase: xor edx, edx
- xor ecx, ecx
- dec cl
- mov edi, ecx
- div ecx
- jz .done
- mov ecx, eax
- sub esi, eax
- movzx eax, byte[lsha+2]
- mov ebx, eax
- shl eax, 1
- lea eax, [ebx*4+eax]
- xor edx, edx
- div edi
- mov ebx, eax
- mov eax, ecx
- sub eax, esi
- mul edx
- push ebx
- mov ebx, ecx
- shl ebx, 8
- sub ebx, ecx
- sub ebx, eax
- xchg eax, ebx
- xor edx, edx
- div edi
- shl eax, 24
- or ecx, eax
- mov eax, esi
- shl eax, 8
- sub eax, esi
- shl esi, 16
- or ecx, esi
- add eax, ebx
- xor edx, edx
- div edi
- mov ch, al
- mov eax, ecx
- pop ecx
- cmp cl, 6
- jz .done
- or ecx, ecx
- jz .done
- bswap eax
- rol eax, 8
- xchg ah, al
- dec ecx
- jz .done
- ror eax, 8
- xchg ah, al
- dec ecx
- jz .done
- rol eax, 8
- xchg ah, al
- dec ecx
- jz .done
- bswap eax
- rol eax, 8
- xchg ah, al
- dec ecx
- jz .done
- ror eax, 8
- xchg ah, al
-.done: and eax, 0x00ffffff
+ mov [lsha], eax
- mov bl, byte[lsha+3]
- bswap eax
- mov al, bl
- ror eax, 8
+ movzx ebx, byte[lsha + 0]
+ lea esi, [ebx*2]
+ movzx edi, byte[lsha + 1]
+ xor eax, eax
+ mov cl, 1
+ cmp bl, 0x7f
+ ja .lcase
+ dec al
+ xor ecx, ecx
+ .lcase:
+ add eax, edi
+ mul ebx
+ or ecx, ecx
+ jz .scase
+ neg eax
+ mov ecx, ebx
+ add ecx, edi
+ mov edx, ecx
+ shl ecx, 8
+ sub ecx, edx
+ add eax, ecx
+ .scase:
+ xor edx, edx
+ xor ecx, ecx
+ dec cl
+ mov edi, ecx
+ div ecx
+ jz .done
+ mov ecx, eax
+ sub esi, eax
+ movzx eax, byte[lsha + 2]
+ mov ebx, eax
+ shl eax, 1
+ lea eax, [ebx*4 + eax]
+ xor edx, edx
+ div edi
+ mov ebx, eax
+ mov eax, ecx
+ sub eax, esi
+ mul edx
+ push ebx
+ mov ebx, ecx
+ shl ebx, 8
+ sub ebx, ecx
+ sub ebx, eax
+ xchg eax, ebx
+ xor edx, edx
+ div edi
+ shl eax, 24
+ or ecx, eax
+ mov eax, esi
+ shl eax, 8
+ sub eax, esi
+ shl esi, 16
+ or ecx, esi
+ add eax, ebx
+ xor edx, edx
+ div edi
+ mov ch, al
+ mov eax, ecx
+ pop ecx
+ cmp cl, 6
+ jz .done
+ or ecx, ecx
+ jz .done
+ bswap eax
+ rol eax, 8
+ xchg ah, al
+ dec ecx
+ jz .done
+ ror eax, 8
+ xchg ah, al
+ dec ecx
+ jz .done
+ rol eax, 8
+ xchg ah, al
+ dec ecx
+ jz .done
+ bswap eax
+ rol eax, 8
+ xchg ah, al
+ dec ecx
+ jz .done
+ ror eax, 8
+ xchg ah, al
+ .done:
+ and eax, 0x00ffffff
- pop edi esi ebx
- ret
+ mov bl, byte[lsha + 3]
+ bswap eax
+ mov al, bl
+ ror eax, 8
+
+ pop edi esi ebx
+
+
+ ret
endp
-match =MMX,COMPOSITE_MODE{include 'composite_mmx.inc'}
+match =MMX, COMPOSITE_MODE{include 'composite_mmx.asm'}
+match =SSE, COMPOSITE_MODE{include 'composite_sse.asm'}
+
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
@@ -1533,41 +1627,37 @@ match =MMX,COMPOSITE_MODE{include 'composite_mmx.inc'}
;;================================================================================================;;
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
;;================================================================================================;;
-xcf_prop_table_begin:
-dd 00, parse_prop_00
-dd 01, parse_prop_01
-dd 06, parse_prop_06
-dd 07, parse_prop_07
-dd 08, parse_prop_08
-dd 11, parse_prop_11
-dd 15, parse_prop_15
-xcf_prop_table_end:
+xcf._.prop_table_begin:
+ dd 00, xcf._.parse_properties.00
+ dd 01, xcf._.parse_properties.01
+ dd 06, xcf._.parse_properties.06
+ dd 07, xcf._.parse_properties.07
+ dd 08, xcf._.parse_properties.08
+ dd 11, xcf._.parse_properties.11
+ dd 15, xcf._.parse_properties.15
+xcf._.prop_table_end:
-composite_table_begin:
-.p00 dd 00, composite_rgb_00, composite_gray_00, composite_indexed_00 ; Normal
-.p01 dd 01, composite_rgb_01, composite_gray_01, composite_gray_01 ; Dissolve : random dithering to discrete alpha
-;.p02 dd 02, composite_rgb_02, 0, composite_indexed_02 ; Behind : not selectable in the GIMP UI. not implemented
-.p03 dd 03, composite_rgb_03, composite_rgb_03, composite_indexed_00 ; Multiply
-.p04 dd 04, composite_rgb_04, composite_rgb_04, composite_indexed_00 ; Screen
-.p05 dd 05, composite_rgb_05, composite_rgb_05, composite_indexed_00 ; Overlay
-.p06 dd 06, composite_rgb_06, composite_rgb_06, composite_indexed_00 ; Difference
-.p07 dd 07, composite_rgb_07, composite_rgb_07, composite_indexed_00 ; Addition
-.p08 dd 08, composite_rgb_08, composite_rgb_08, composite_indexed_00 ; Subtract
-.p09 dd 09, composite_rgb_09, composite_rgb_09, composite_indexed_00 ; Darken Only
-.p10 dd 10, composite_rgb_10, composite_rgb_10, composite_indexed_00 ; Lighten Only
-.p11 dd 11, composite_rgb_11, composite_gray_00, composite_indexed_00 ; Hue (H of HSV)
-.p12 dd 12, composite_rgb_12, composite_gray_00, composite_indexed_00 ; Saturation (S of HSV)
-.p13 dd 13, composite_rgb_13, composite_gray_00, composite_indexed_00 ; Color (H and S of HSL)
-.p14 dd 14, composite_rgb_14, composite_gray_00, composite_indexed_00 ; Value (V of HSV)
-.p15 dd 15, composite_rgb_15, composite_rgb_15, composite_indexed_00 ; Divide
-.p16 dd 16, composite_rgb_16, composite_rgb_16, composite_indexed_00 ; Dodge
-.p17 dd 17, composite_rgb_17, composite_rgb_17, composite_indexed_00 ; Burn
-.p18 dd 18, composite_rgb_18, composite_rgb_18, composite_indexed_00 ; Hard Light
-.p19 dd 19, composite_rgb_05, composite_rgb_05, composite_indexed_00 ; Soft Light : XCF version >= 2 only ('soft light' == 'overlay')
-.p20 dd 20, composite_rgb_20, composite_rgb_20, composite_indexed_00 ; Grain Extract : XCF version >= 2 only
-.p21 dd 21, composite_rgb_21, composite_rgb_21, composite_indexed_00 ; Grain Merge : XCF version >= 2 only
-composite_table_end:
-
-random_a dd 1103515245
-random_b dd 777
-random_c dd 12345
\ No newline at end of file
+xcf._.composite_table.begin:
+ .p00 dd 00, xcf._.composite_rgb_00, xcf._.composite_gray_00, xcf._.composite_indexed_00 ; Normal
+ .p01 dd 01, xcf._.composite_rgb_01, xcf._.composite_gray_01, xcf._.composite_gray_01 ; Dissolve : random dithering to discrete alpha
+; .p02 dd 02, xcf._.composite_rgb_02, 0, xcf._.composite_indexed_02 ; Behind : not selectable in the GIMP UI. not implemented
+ .p03 dd 03, xcf._.composite_rgb_03, xcf._.composite_rgb_03, xcf._.composite_indexed_00 ; Multiply
+ .p04 dd 04, xcf._.composite_rgb_04, xcf._.composite_rgb_04, xcf._.composite_indexed_00 ; Screen
+ .p05 dd 05, xcf._.composite_rgb_05, xcf._.composite_rgb_05, xcf._.composite_indexed_00 ; Overlay
+ .p06 dd 06, xcf._.composite_rgb_06, xcf._.composite_rgb_06, xcf._.composite_indexed_00 ; Difference
+ .p07 dd 07, xcf._.composite_rgb_07, xcf._.composite_rgb_07, xcf._.composite_indexed_00 ; Addition
+ .p08 dd 08, xcf._.composite_rgb_08, xcf._.composite_rgb_08, xcf._.composite_indexed_00 ; Subtract
+ .p09 dd 09, xcf._.composite_rgb_09, xcf._.composite_rgb_09, xcf._.composite_indexed_00 ; Darken Only
+ .p10 dd 10, xcf._.composite_rgb_10, xcf._.composite_rgb_10, xcf._.composite_indexed_00 ; Lighten Only
+ .p11 dd 11, xcf._.composite_rgb_11, xcf._.composite_gray_00, xcf._.composite_indexed_00 ; Hue (H of HSV)
+ .p12 dd 12, xcf._.composite_rgb_12, xcf._.composite_gray_00, xcf._.composite_indexed_00 ; Saturation (S of HSV)
+ .p13 dd 13, xcf._.composite_rgb_13, xcf._.composite_gray_00, xcf._.composite_indexed_00 ; Color (H and S of HSL)
+ .p14 dd 14, xcf._.composite_rgb_14, xcf._.composite_gray_00, xcf._.composite_indexed_00 ; Value (V of HSV)
+ .p15 dd 15, xcf._.composite_rgb_15, xcf._.composite_rgb_15, xcf._.composite_indexed_00 ; Divide
+ .p16 dd 16, xcf._.composite_rgb_16, xcf._.composite_rgb_16, xcf._.composite_indexed_00 ; Dodge
+ .p17 dd 17, xcf._.composite_rgb_17, xcf._.composite_rgb_17, xcf._.composite_indexed_00 ; Burn
+ .p18 dd 18, xcf._.composite_rgb_18, xcf._.composite_rgb_18, xcf._.composite_indexed_00 ; Hard Light
+ .p19 dd 19, xcf._.composite_rgb_05, xcf._.composite_rgb_05, xcf._.composite_indexed_00 ; Soft Light : XCF >= 2 only ('soft light' == 'overlay')
+ .p20 dd 20, xcf._.composite_rgb_20, xcf._.composite_rgb_20, xcf._.composite_indexed_00 ; Grain Extract : XCF >= 2 only
+ .p21 dd 21, xcf._.composite_rgb_21, xcf._.composite_rgb_21, xcf._.composite_indexed_00 ; Grain Merge : XCF >= 2 only
+xcf._.composite_table.end:
diff --git a/programs/develop/libraries/libs-dev/libimg/xcf/xcf.inc b/programs/develop/libraries/libs-dev/libimg/xcf/xcf.inc
index 2c521df8f7..237457696d 100644
--- a/programs/develop/libraries/libs-dev/libimg/xcf/xcf.inc
+++ b/programs/develop/libraries/libs-dev/libimg/xcf/xcf.inc
@@ -1,5 +1,5 @@
;;================================================================================================;;
-;;//// xcf.inc //// (c) dunkaist, 2011 ///////////////////////////////////////////////////////////;;
+;;//// xcf.inc //// (c) dunkaist, 2011-2012 //////////////////////////////////////////////////////;;
;;================================================================================================;;
;; ;;
;; This file is part of Common development libraries (Libs-Dev). ;;
@@ -17,26 +17,26 @@
;; ;;
;;================================================================================================;;
-struct xcf_header
- magic_string rb 9
- version rd 1
- reserved rb 1
- width rd 1
- height rd 1
- base_type rd 1
+XCF_BASETYPE_RGB = 0
+XCF_BASETYPE_GRAY = 1
+XCF_BASETYPE_INDEXED = 2
+
+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
\ No newline at end of file
+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