Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
; pcx.inc
2
; Copyright (c) 2002 Thomas Mathys
3
; killer@vantage.ch
4
;
5
; This program is free software; you can redistribute it and/or modify
6
; it under the terms of the GNU General Public License as published by
7
; the Free Software Foundation; either version 2 of the License, or
8
; (at your option) any later version.
9
;
10
; This program is distributed in the hope that it will be useful,
11
; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
; GNU General Public License for more details.
14
;
15
; You should have received a copy of the GNU General Public License
16
; along with this program; if not, write to the Free Software
17
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
19
%ifndef _PCX_INC
20
%define _PCX_INC
21
 
22
 
23
;**********************************************************
24
; pcx header
25
;**********************************************************
26
 
27
PCXHEADER_SIZE	equ	128
28
struc PCXHEADER
29
	.id:		resb	1	; id, should be 10
30
	.version:	resb	1	; pcx version
31
	.encoding:	resb	1	; 1 = rle
32
	.bpp:		resb	1	; bits per pixel
33
	.xmin:		resw	1	; image dimensions
34
	.ymin:		resw	1
35
	.xmax:		resw	1
36
	.ymax:		resw	1
37
	.hdpi:		resw	1	; horizontal resolution in dpi
38
	.vdpi:		resw	1	; verttical resolution in dpi
39
	.colormap:	resb	48	; 16 color palette
40
	.reserved1:	resb	1
41
	.nplanes:	resb	1	; # of color planes
42
	.bytesperline:	resw	1	; # of bytes per scanline. always even
43
	.palinfo:	resw	1	; 1 = color/bw, 2 = grayscale
44
	.hscreensize:	resw	1	; horizontal screen size
45
	.vscreensize:	resw	1	; vertical screen size
46
	.reserved2:	resb	54
47
endstruc
48
 
49
 
50
section .text
51
 
52
 
53
 
54
;**********************************************************
55
; lousy pcx decoder. reads only 8 bit rle packed color images (pcx version 5)
56
; oh, and yes, currently it can't read images with an odd width.
57
;
58
; the routine does not only decode the image data, it converts
59
; it also to a menuetos putimage compatible format (24 bit, rrggbb)
60
;
61
; input		:	esi	address of the pcx file in memory
62
;			edi	pointer to the memory where the depacked
63
;				image data should go. (width*height*3 bytes)
64
;			ebx	file size in bytes
65
;
66
; output	:	decoded image in [edi]
67
;
68
; destroys	:	nothing
69
;
70
;**********************************************************
71
 
72
loadPCX:
73
	pushad
74
	pushfd
75
 
76
	; calculate number of pixels to decode.
77
	; this is actually wrong, because if the image has an odd
78
	; width, there will be an unused pixel at the end of each
79
	; scanline.
80
	movzx eax,word [esi+PCXHEADER.xmax]	; eax = image width
81
	sub ax,[esi+PCXHEADER.xmin]
82
	inc eax
83
	movzx ecx,word [esi+PCXHEADER.ymax]	; ecx = image height
84
	sub cx,[esi+PCXHEADER.ymin]
85
	inc ecx
86
	mul ecx
87
	mov ebp,eax				; ebp = # of pixels to decode
88
 
89
	; move ebx to beginning of palette and
90
	; esi to beginning of packed image data
91
	sub ebx,768
92
	add ebx,esi
93
	add esi,PCXHEADER_SIZE
94
 
95
	; decode image data
96
	xor ecx,ecx				; clear bits 8..31 !
97
	xor eax,eax				;	"
98
.decode:
99
	lodsb					; read byte from input stream
100
	cmp al,192				; encoded/unencoded byte ?
101
	jae short .encoded
102
	lea edx,[eax*2+eax]			; read color values from
103
	mov al,[ebx+edx+2]			; palette and store them
104
	stosb					; in the destination image
105
	mov al,[ebx+edx+1]
106
	stosb
107
	mov al,[ebx+edx+0]
108
	stosb
109
	dec ebp					; one less to go...
110
	jmp short .continue
111
.encoded:
112
	and al,00111111b			; calc # of times to repeat
113
	mov cl,al
114
	lodsb					; read data byte
115
	lea edx,[eax*2+eax]			; read color values from palette
116
	mov al,[ebx+edx+2]
117
	mov ah,[ebx+edx+1]
118
	mov dl,[ebx+edx+0]
119
.bla:						; write color values
120
	stosb
121
	mov [edi],ah
122
	inc edi
123
	mov [edi],dl
124
	inc edi
125
	dec ebp					; one less to go...
126
	loop .bla
127
	xor ah,ah				; reset ah to 0 !
128
.continue:
129
	or ebp,ebp				; all pixels decoded ?
130
	jnz short .decode
131
 
132
	popfd
133
	popad
134
	ret
135
 
136
 
137
%endif