2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
2013-05-10 14:28:39 +02:00
|
|
|
;;//// pcx.asm //// (c) dunkaist, 2010,2012-2013 /////////////////////////////////////////////////;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
|
|
|
;; ;;
|
|
|
|
;; 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/>. ;;
|
|
|
|
;; ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
include 'pcx.inc'
|
2010-08-17 00:01:31 +02:00
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2011-05-02 19:26:50 +02:00
|
|
|
;? Determine if raw data could be decoded (is in pcx format) ;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _data = raw data as read from file/stream ;;
|
|
|
|
;> _length = data length ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = false / true ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
push edi
|
2012-02-23 23:09:09 +01:00
|
|
|
xor eax, eax
|
|
|
|
|
|
|
|
mov edi, [_data]
|
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
mov ecx, [edi]
|
|
|
|
shl ecx, 8
|
|
|
|
cmp ecx, 0x01050a00
|
2012-02-23 23:09:09 +01:00
|
|
|
jne .is_not_pcx
|
2012-02-24 18:47:42 +01:00
|
|
|
cmp byte[edi + pcx_header.reserved], 0
|
2012-02-23 23:09:09 +01:00
|
|
|
jne .is_not_pcx
|
|
|
|
|
|
|
|
add edi, pcx_header.filler
|
2013-05-10 14:28:39 +02:00
|
|
|
mov ecx, 58/2
|
|
|
|
repe scasw
|
|
|
|
jne .is_not_pcx
|
2012-02-23 23:09:09 +01:00
|
|
|
|
|
|
|
.is_pcx:
|
|
|
|
inc eax
|
|
|
|
.is_not_pcx:
|
2013-05-10 14:28:39 +02:00
|
|
|
pop edi
|
2012-02-23 23:09:09 +01:00
|
|
|
ret
|
2010-08-17 00:01:31 +02:00
|
|
|
endp
|
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
|
2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
|
|
|
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2011-05-02 19:26:50 +02:00
|
|
|
;? Decode data into image if it contains correctly formed raw data in pcx format ;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;> _data = raw data as read from file/stream ;;
|
|
|
|
;> _length = data length ;;
|
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
|
|
|
;< eax = 0 (error) or pointer to image ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
locals
|
2013-05-10 14:28:39 +02:00
|
|
|
num_planes rd 1
|
|
|
|
width rd 1
|
|
|
|
height rd 1
|
|
|
|
bp_plane rd 1
|
|
|
|
bp_scanline rd 1
|
2012-02-23 23:09:09 +01:00
|
|
|
line_begin rd 1
|
2013-05-10 14:28:39 +02:00
|
|
|
cur_scanline rd 1
|
2012-02-23 23:09:09 +01:00
|
|
|
retvalue rd 1 ; 0 (error) or pointer to image
|
2010-08-17 00:01:31 +02:00
|
|
|
endl
|
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
pusha
|
2010-08-17 00:01:31 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
mov esi, [_data]
|
|
|
|
movzx eax, byte[esi + pcx_header.nplanes]
|
2013-05-10 14:28:39 +02:00
|
|
|
mov [num_planes], eax
|
2012-02-24 18:47:42 +01:00
|
|
|
movzx ebx, word[esi + pcx_header.bpl]
|
2013-05-10 14:28:39 +02:00
|
|
|
mov [bp_plane], ebx
|
2012-02-24 18:47:42 +01:00
|
|
|
imul eax, ebx
|
2013-05-10 14:28:39 +02:00
|
|
|
mov [bp_scanline], eax
|
2010-08-17 00:01:31 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
movzx eax, word[esi + pcx_header.xmax]
|
|
|
|
sub ax, word[esi + pcx_header.xmin]
|
2012-02-24 18:47:42 +01:00
|
|
|
inc eax
|
2013-05-10 14:28:39 +02:00
|
|
|
mov [width], eax
|
2010-08-17 00:01:31 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
movzx ebx, word[esi + pcx_header.ymax]
|
|
|
|
sub bx, word[esi + pcx_header.ymin]
|
2012-02-24 18:47:42 +01:00
|
|
|
inc ebx
|
2013-05-10 14:28:39 +02:00
|
|
|
mov [height], ebx
|
2010-08-25 16:59:27 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
cmp [esi + pcx_header.bpp], 1
|
|
|
|
jz .monochrome
|
|
|
|
cmp byte[esi + pcx_header.nplanes], 3
|
|
|
|
jnz .indexed
|
2010-08-25 16:59:27 +02:00
|
|
|
|
|
|
|
|
2012-02-24 18:47:42 +01:00
|
|
|
.24bit:
|
2013-05-10 14:28:39 +02:00
|
|
|
stdcall img.create, [bp_plane], 1, Image.bpp24
|
|
|
|
mov [cur_scanline], eax
|
|
|
|
test eax, eax
|
|
|
|
jz .quit
|
2010-08-25 16:59:27 +02:00
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
stdcall img.create, [width], [height], Image.bpp24
|
2012-02-23 23:09:09 +01:00
|
|
|
mov [retvalue], eax
|
|
|
|
test eax, eax
|
|
|
|
jz .quit
|
2010-08-17 00:01:31 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
mov esi, [_data]
|
2013-05-10 14:28:39 +02:00
|
|
|
add esi, sizeof.pcx_header
|
|
|
|
mov edx, [eax + Image.Data]
|
2010-08-17 00:01:31 +02:00
|
|
|
|
2012-02-24 18:47:42 +01:00
|
|
|
.24bit.scanline:
|
2013-05-10 14:28:39 +02:00
|
|
|
mov edi, [cur_scanline]
|
|
|
|
mov ebx, [bp_scanline]
|
2012-02-24 18:47:42 +01:00
|
|
|
@@:
|
2013-05-10 14:28:39 +02:00
|
|
|
call pcx._.get_byte
|
|
|
|
rep stosb
|
|
|
|
test ebx, ebx
|
|
|
|
jnz @b
|
|
|
|
stdcall pcx._.scanline_unpack, [width], [cur_scanline], [num_planes]
|
|
|
|
dec [height]
|
|
|
|
jnz .24bit.scanline
|
|
|
|
jmp .quit
|
2010-08-19 22:22:50 +02:00
|
|
|
|
|
|
|
|
2010-08-25 16:59:27 +02:00
|
|
|
.indexed:
|
2013-05-10 14:28:39 +02:00
|
|
|
stdcall img.create, [width], [height], Image.bpp8i
|
2012-02-23 23:09:09 +01:00
|
|
|
mov [retvalue], eax
|
|
|
|
test eax, eax
|
|
|
|
jz .quit
|
|
|
|
|
2012-02-24 18:47:42 +01:00
|
|
|
mov ebx, eax
|
2012-02-23 23:09:09 +01:00
|
|
|
mov esi, [_data]
|
|
|
|
add esi, [_length]
|
2013-05-10 14:28:39 +02:00
|
|
|
sub esi, 256*3 ; rgb triplets
|
2012-02-23 23:09:09 +01:00
|
|
|
mov edi, [eax + Image.Palette]
|
2012-02-24 18:47:42 +01:00
|
|
|
mov ecx, 256
|
2013-05-10 14:28:39 +02:00
|
|
|
mov eax, 0x0000ff00
|
2012-02-23 23:09:09 +01:00
|
|
|
@@:
|
2013-05-10 14:28:39 +02:00
|
|
|
mov al, [esi + 0]
|
|
|
|
mov [edi + 2], ax
|
|
|
|
mov al, [esi + 1]
|
|
|
|
mov [edi + 1], al
|
|
|
|
mov al, [esi + 2]
|
|
|
|
mov [edi + 0], al
|
|
|
|
add esi, 3
|
|
|
|
add edi, 4
|
2012-02-24 18:47:42 +01:00
|
|
|
dec ecx
|
2012-02-23 23:09:09 +01:00
|
|
|
jnz @b
|
|
|
|
|
|
|
|
mov esi, [_data]
|
2013-05-10 14:28:39 +02:00
|
|
|
add esi, sizeof.pcx_header
|
2012-02-24 18:47:42 +01:00
|
|
|
mov edi, [ebx + Image.Data]
|
2010-08-25 16:59:27 +02:00
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
.indexed.scanline:
|
|
|
|
mov ebx, [bp_scanline]
|
2012-02-24 18:47:42 +01:00
|
|
|
@@:
|
2013-05-10 14:28:39 +02:00
|
|
|
call pcx._.get_byte
|
|
|
|
rep stosb
|
2012-02-24 18:47:42 +01:00
|
|
|
test ebx, ebx
|
2013-05-10 14:28:39 +02:00
|
|
|
jnz @b
|
|
|
|
dec [height]
|
|
|
|
jnz .indexed.scanline
|
2012-02-24 18:47:42 +01:00
|
|
|
jmp .quit
|
2010-08-19 22:22:50 +02:00
|
|
|
|
|
|
|
|
2010-08-25 16:59:27 +02:00
|
|
|
.monochrome:
|
2013-05-10 14:28:39 +02:00
|
|
|
stdcall img.create, [width], [height], Image.bpp1
|
2012-02-23 23:09:09 +01:00
|
|
|
mov [retvalue], eax
|
|
|
|
test eax, eax
|
|
|
|
jz .quit
|
2010-08-19 22:22:50 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
mov edi, [eax + Image.Palette]
|
2012-02-24 18:47:42 +01:00
|
|
|
mov [edi], dword 0xff000000
|
|
|
|
mov [edi + 4], dword 0xffffffff
|
2010-08-19 22:22:50 +02:00
|
|
|
|
2012-02-23 23:09:09 +01:00
|
|
|
mov esi, [_data]
|
2013-05-10 14:28:39 +02:00
|
|
|
add esi, sizeof.pcx_header
|
2012-02-23 23:09:09 +01:00
|
|
|
mov edi, [eax + Image.Data]
|
2010-08-19 22:22:50 +02:00
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
.monochrome.scanline:
|
|
|
|
mov ebx, [bp_scanline]
|
2012-02-23 23:09:09 +01:00
|
|
|
@@:
|
2013-05-10 14:28:39 +02:00
|
|
|
call pcx._.get_byte
|
|
|
|
rep stosb
|
2012-02-24 18:47:42 +01:00
|
|
|
test ebx, ebx
|
2013-05-10 14:28:39 +02:00
|
|
|
jnz @b
|
|
|
|
dec [height]
|
|
|
|
jnz .monochrome.scanline
|
2012-02-24 18:47:42 +01:00
|
|
|
; jmp .quit
|
2010-08-25 16:59:27 +02:00
|
|
|
|
2010-08-19 22:22:50 +02:00
|
|
|
.quit:
|
2012-02-23 23:09:09 +01:00
|
|
|
popa
|
|
|
|
mov eax, [retvalue]
|
|
|
|
ret
|
2010-08-17 00:01:31 +02:00
|
|
|
endp
|
|
|
|
|
2010-08-19 22:22:50 +02:00
|
|
|
|
2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
2012-05-26 20:26:46 +02:00
|
|
|
proc img.encode.pcx _img, _common, _specific ;////////////////////////////////////////////////////;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2012-05-26 20:26:46 +02:00
|
|
|
;? Encode image into raw data in pcx format ;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2012-05-26 20:26:46 +02:00
|
|
|
;> [_img] = pointer to image ;;
|
|
|
|
;> [_common] = format independent options ;;
|
|
|
|
;> [_specific] = 0 / pointer to the structure of format specific options ;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;------------------------------------------------------------------------------------------------;;
|
2012-05-26 20:26:46 +02:00
|
|
|
;< eax = 0 / pointer to encoded data ;;
|
|
|
|
;< ecx = error code / the size of encoded data ;;
|
2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
2012-02-23 23:09:09 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-08-17 00:01:31 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Below are private procs you should never call directly from your code ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
2012-02-23 23:09:09 +01:00
|
|
|
proc pcx._.get_byte
|
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
mov ecx, 1
|
|
|
|
xor eax, eax
|
2012-02-24 18:47:42 +01:00
|
|
|
lodsb
|
2013-05-10 14:28:39 +02:00
|
|
|
cmp eax, 0xc0
|
|
|
|
jb @f
|
|
|
|
and eax, 0x3f
|
|
|
|
mov ecx, eax
|
2012-02-24 18:47:42 +01:00
|
|
|
lodsb
|
2013-05-10 14:28:39 +02:00
|
|
|
@@:
|
2012-02-23 23:09:09 +01:00
|
|
|
sub ebx, ecx
|
|
|
|
ret
|
2010-08-25 16:59:27 +02:00
|
|
|
endp
|
2012-02-23 23:09:09 +01:00
|
|
|
|
|
|
|
|
2013-05-10 14:28:39 +02:00
|
|
|
proc pcx._.scanline_unpack _width, _scanline, _num_planes
|
|
|
|
push esi
|
|
|
|
|
|
|
|
mov esi, [_scanline]
|
|
|
|
mov ebx, [_num_planes]
|
|
|
|
dec ebx
|
|
|
|
|
|
|
|
.plane:
|
|
|
|
mov ecx, [_width]
|
|
|
|
mov edi, edx
|
|
|
|
add edi, ebx
|
|
|
|
@@:
|
|
|
|
mov al, [esi]
|
|
|
|
mov [edi], al
|
|
|
|
add esi, 1
|
|
|
|
add edi, [_num_planes]
|
|
|
|
dec ecx
|
|
|
|
jnz @b
|
|
|
|
bt dword[_width], 0
|
|
|
|
adc esi, 0
|
|
|
|
dec ebx
|
|
|
|
jns .plane
|
|
|
|
|
|
|
|
mov edx, edi
|
|
|
|
pop esi
|
|
|
|
ret
|
|
|
|
endp
|
2010-08-17 00:01:31 +02:00
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;! Below is private data you should never use directly from your code ;;
|
|
|
|
;;================================================================================================;;
|
|
|
|
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
|
|
|
|
;;================================================================================================;;
|