forked from KolibriOS/kolibrios
libimg:
1. tiff (baseline) support 2. pnm (portable anymap) bilevel, grayscale (8bpp), pixmap (24bpp) support 3. xcf: optional layer merging/blending with sse (default is mmx) 4'. new formatting for my old code. more readable for now git-svn-id: svn://kolibrios.org@2388 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
54
programs/develop/libraries/libs-dev/libimg/pnm/pbm.asm
Normal file
54
programs/develop/libraries/libs-dev/libimg/pnm/pbm.asm
Normal file
@@ -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
|
72
programs/develop/libraries/libs-dev/libimg/pnm/pgm.asm
Normal file
72
programs/develop/libraries/libs-dev/libimg/pnm/pgm.asm
Normal file
@@ -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
|
||||
|
230
programs/develop/libraries/libs-dev/libimg/pnm/pnm.asm
Normal file
230
programs/develop/libraries/libs-dev/libimg/pnm/pnm.asm
Normal file
@@ -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 <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
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 ;;
|
||||
;;================================================================================================;;
|
||||
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
||||
;;================================================================================================;;
|
||||
|
26
programs/develop/libraries/libs-dev/libimg/pnm/pnm.inc
Normal file
26
programs/develop/libraries/libs-dev/libimg/pnm/pnm.inc
Normal file
@@ -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 <http://www.gnu.org/licenses/>. ;;
|
||||
;; ;;
|
||||
;;================================================================================================;;
|
||||
|
||||
PNM_RAW = 0
|
||||
PNM_ASCII = 1
|
||||
|
||||
PNM_PBM = 0
|
||||
PNM_PGM = 1
|
||||
PNM_PPM = 2
|
||||
|
117
programs/develop/libraries/libs-dev/libimg/pnm/ppm.asm
Normal file
117
programs/develop/libraries/libs-dev/libimg/pnm/ppm.asm
Normal file
@@ -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
|
||||
|
Reference in New Issue
Block a user