1,5 → 1,5 |
;;================================================================================================;; |
;;//// pcx.asm //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;; |
;;//// pcx.asm //// (c) dunkaist, 2010,2012-2013 /////////////////////////////////////////////////;; |
;;================================================================================================;; |
;; ;; |
;; This file is part of Common development libraries (Libs-Dev). ;; |
30,33 → 30,27 |
;< eax = false / true ;; |
;;================================================================================================;; |
|
push ecx edi |
push edi |
xor eax, eax |
|
mov edi, [_data] |
|
cmp byte[edi + pcx_header.magic_number], 0x0A |
mov ecx, [edi] |
shl ecx, 8 |
cmp ecx, 0x01050a00 |
jne .is_not_pcx |
cmp byte[edi + pcx_header.version], 5 |
jne .is_not_pcx |
cmp byte[edi + pcx_header.encoding], 1 |
jne .is_not_pcx |
cmp byte[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 |
mov ecx, 58/2 |
repe scasw |
jne .is_not_pcx |
|
.is_pcx: |
inc eax |
|
.is_not_pcx: |
pop edi ecx |
pop edi |
ret |
endp |
|
72,12 → 66,13 |
;< eax = 0 (error) or pointer to image ;; |
;;================================================================================================;; |
locals |
nplanes rd 1 |
xsize rd 1 |
ysize rd 1 |
bpl rd 1 |
total_bpl rd 1 |
num_planes rd 1 |
width rd 1 |
height rd 1 |
bp_plane rd 1 |
bp_scanline rd 1 |
line_begin rd 1 |
cur_scanline rd 1 |
retvalue rd 1 ; 0 (error) or pointer to image |
endl |
|
85,21 → 80,21 |
|
mov esi, [_data] |
movzx eax, byte[esi + pcx_header.nplanes] |
mov [nplanes], eax |
mov [num_planes], eax |
movzx ebx, word[esi + pcx_header.bpl] |
mov [bpl], ebx |
mov [bp_plane], ebx |
imul eax, ebx |
mov [total_bpl], eax |
mov [bp_scanline], eax |
|
movzx eax, word[esi + pcx_header.xmax] |
sub ax, word[esi + pcx_header.xmin] |
inc eax |
mov [xsize], eax |
mov [width], eax |
|
movzx ebx, word[esi + pcx_header.ymax] |
sub bx, word[esi + pcx_header.ymin] |
inc ebx |
mov [ysize], ebx |
mov [height], ebx |
|
cmp [esi + pcx_header.bpp], 1 |
jz .monochrome |
108,56 → 103,36 |
|
|
.24bit: |
stdcall img.create, [bp_plane], 1, Image.bpp24 |
mov [cur_scanline], eax |
test eax, eax |
jz .quit |
|
stdcall img.create, eax, ebx, Image.bpp24 |
stdcall img.create, [width], [height], Image.bpp24 |
mov [retvalue], eax |
test eax, eax |
jz .quit |
|
mov esi, [_data] |
add esi, 128 ; skip header |
mov edi, [eax + Image.Data] |
add edi, 2 |
mov [line_begin], edi |
add esi, sizeof.pcx_header |
mov edx, [eax + Image.Data] |
|
.24bit.scanline: |
mov ebx, [total_bpl] |
.24bit.color_line: |
mov edx, [bpl] |
.24bit.next_byte: |
mov edi, [cur_scanline] |
mov ebx, [bp_scanline] |
@@: |
call pcx._.get_byte |
sub edx, ecx |
@@: |
mov [edi], al |
add edi, [nplanes] |
dec ecx |
rep stosb |
test ebx, ebx |
jnz @b |
stdcall pcx._.scanline_unpack, [width], [cur_scanline], [num_planes] |
dec [height] |
jnz .24bit.scanline |
jmp .quit |
|
test edx, edx |
jnz .24bit.next_byte |
|
.24bit.end_color_line: |
test ebx, ebx |
jz .24bit.end_full_line |
dec [line_begin] |
mov edi, [line_begin] |
jmp .24bit.color_line |
|
.24bit.end_full_line: |
dec [ysize] |
jz .quit |
add edi, 2 |
bt [xsize], 0 |
jnc @f |
sub edi, 3 |
@@: |
mov [line_begin], edi |
jmp .24bit.scanline |
|
|
.indexed: |
|
stdcall img.create, eax, ebx, Image.bpp8i |
stdcall img.create, [width], [height], Image.bpp8i |
mov [retvalue], eax |
test eax, eax |
jz .quit |
165,42 → 140,40 |
mov ebx, eax |
mov esi, [_data] |
add esi, [_length] |
sub esi, 768 |
sub esi, 256*3 ; rgb triplets |
mov edi, [eax + Image.Palette] |
mov ecx, 256 |
xor eax, eax |
mov eax, 0x0000ff00 |
@@: |
lodsw |
xchg al, ah |
shl eax, 8 |
lodsb |
stosd |
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 |
dec ecx |
jnz @b |
|
mov esi, [_data] |
add esi, 128 |
add esi, sizeof.pcx_header |
mov edi, [ebx + Image.Data] |
|
.indexed.line: |
mov ebx, [total_bpl] |
.indexed.next_byte: |
.indexed.scanline: |
mov ebx, [bp_scanline] |
@@: |
call pcx._.get_byte |
@@: |
stosb |
dec ecx |
rep stosb |
test ebx, ebx |
jnz @b |
test ebx, ebx |
jnz .indexed.next_byte |
|
dec [ysize] |
jnz .indexed.line |
dec [height] |
jnz .indexed.scanline |
jmp .quit |
|
|
.monochrome: |
|
stdcall img.create, eax, ebx, Image.bpp1 |
stdcall img.create, [width], [height], Image.bpp1 |
mov [retvalue], eax |
test eax, eax |
jz .quit |
210,25 → 183,20 |
mov [edi + 4], dword 0xffffffff |
|
mov esi, [_data] |
add esi, 128 |
add esi, sizeof.pcx_header |
mov edi, [eax + Image.Data] |
|
|
.monochrome.line: |
mov ebx, [total_bpl] |
.monochrome.next_byte: |
.monochrome.scanline: |
mov ebx, [bp_scanline] |
@@: |
call pcx._.get_byte |
@@: |
stosb |
dec ecx |
rep stosb |
test ebx, ebx |
jnz @b |
test ebx, ebx |
jnz .monochrome.next_byte |
dec [ysize] |
jnz .monochrome.line |
dec [height] |
jnz .monochrome.scanline |
; jmp .quit |
|
|
.quit: |
popa |
mov eax, [retvalue] |
262,20 → 230,47 |
;;================================================================================================;; |
proc pcx._.get_byte |
|
xor ecx, ecx |
mov ecx, 1 |
xor eax, eax |
lodsb |
cmp al, 0xC0 |
setb cl |
jb .done |
and al, 0x3F |
mov cl, al |
cmp eax, 0xc0 |
jb @f |
and eax, 0x3f |
mov ecx, eax |
lodsb |
.done: |
@@: |
sub ebx, ecx |
ret |
endp |
|
|
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 |
;;================================================================================================;; |
;;////////////////////////////////////////////////////////////////////////////////////////////////;; |
;;================================================================================================;; |