Subversion Repositories Kolibri OS

Rev

Rev 2388 | Rev 2691 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1569 dunkaist 1
;;================================================================================================;;
2388 dunkaist 2
;;//// pcx.asm //// (c) dunkaist, 2010,2012 //////////////////////////////////////////////////////;;
1569 dunkaist 3
;;================================================================================================;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
19
 
2388 dunkaist 20
include	'pcx.inc'
1728 clevermous 21
;include '../../../../system/board/trunk/debug.inc'
1569 dunkaist 22
 
23
;;================================================================================================;;
24
proc img.is.pcx _data, _length ;//////////////////////////////////////////////////////////////////;;
25
;;------------------------------------------------------------------------------------------------;;
1921 dunkaist 26
;? Determine if raw data could be decoded (is in pcx format)                                      ;;
1569 dunkaist 27
;;------------------------------------------------------------------------------------------------;;
28
;> _data = raw data as read from file/stream                                                      ;;
29
;> _length = data length                                                                          ;;
30
;;------------------------------------------------------------------------------------------------;;
31
;< eax = false / true                                                                             ;;
32
;;================================================================================================;;
33
 
2388 dunkaist 34
	push	ecx edi
35
	xor	eax, eax
1569 dunkaist 36
 
2388 dunkaist 37
	mov	edi, [_data]
1569 dunkaist 38
 
2397 dunkaist 39
	cmp	byte[edi + pcx_header.magic_number], 0x0A
2388 dunkaist 40
	jne	.is_not_pcx
2397 dunkaist 41
	cmp	byte[edi + pcx_header.version], 5
2388 dunkaist 42
	jne	.is_not_pcx
2397 dunkaist 43
	cmp	byte[edi + pcx_header.encoding], 1
2388 dunkaist 44
	jne	.is_not_pcx
2397 dunkaist 45
	cmp	byte[edi + pcx_header.reserved], 0
2388 dunkaist 46
	jne	.is_not_pcx
1569 dunkaist 47
 
2388 dunkaist 48
	add	edi, pcx_header.filler
49
	xor	al, al
50
	mov	ecx, 58
51
	cld
52
	repe	scasb
53
	test	ecx, ecx
54
	jnz	.is_not_pcx
1569 dunkaist 55
 
2388 dunkaist 56
  .is_pcx:
57
	inc	eax
1569 dunkaist 58
 
2388 dunkaist 59
  .is_not_pcx:
60
	pop	edi ecx
61
	ret
1569 dunkaist 62
endp
63
 
2388 dunkaist 64
 
1569 dunkaist 65
;;================================================================================================;;
66
proc img.decode.pcx _data, _length, _options ;////////////////////////////////////////////////////;;
67
;;------------------------------------------------------------------------------------------------;;
1921 dunkaist 68
;? Decode data into image if it contains correctly formed raw data in pcx format                  ;;
1569 dunkaist 69
;;------------------------------------------------------------------------------------------------;;
70
;> _data = raw data as read from file/stream                                                      ;;
71
;> _length = data length                                                                          ;;
72
;;------------------------------------------------------------------------------------------------;;
73
;< eax = 0 (error) or pointer to image                                                            ;;
74
;;================================================================================================;;
75
locals
2388 dunkaist 76
	nplanes			rd	1
2397 dunkaist 77
	xsize			rd	1
78
	ysize			rd	1
79
	bpl			rd	1
2388 dunkaist 80
	total_bpl		rd	1
81
	line_begin		rd	1
82
	retvalue		rd	1		; 0 (error) or pointer to image
1569 dunkaist 83
endl
84
 
2388 dunkaist 85
	pusha
1569 dunkaist 86
 
2388 dunkaist 87
	mov	esi, [_data]
88
	movzx	eax, byte[esi + pcx_header.nplanes]
89
	mov	[nplanes], eax
2397 dunkaist 90
	movzx	ebx, word[esi + pcx_header.bpl]
91
	mov	[bpl], ebx
92
	imul	eax, ebx
2388 dunkaist 93
	mov	[total_bpl], eax
1569 dunkaist 94
 
2388 dunkaist 95
	movzx	eax, word[esi + pcx_header.xmax]
96
	sub	ax, word[esi + pcx_header.xmin]
2397 dunkaist 97
	inc	eax
98
	mov	[xsize], eax
1569 dunkaist 99
 
2388 dunkaist 100
	movzx	ebx, word[esi + pcx_header.ymax]
101
	sub	bx, word[esi + pcx_header.ymin]
2397 dunkaist 102
	inc	ebx
103
	mov	[ysize], ebx
1569 dunkaist 104
 
2388 dunkaist 105
	cmp	[esi + pcx_header.bpp], 1
106
	jz	.monochrome
107
	cmp	byte[esi + pcx_header.nplanes], 3
108
	jnz	.indexed
1593 dunkaist 109
 
110
 
2397 dunkaist 111
  .24bit:
1593 dunkaist 112
 
2388 dunkaist 113
	stdcall	img.create, eax, ebx, Image.bpp24
114
	mov	[retvalue], eax
115
	test	eax, eax
116
	jz	.quit
1569 dunkaist 117
 
2388 dunkaist 118
	mov	esi, [_data]
2397 dunkaist 119
	add	esi, 128			; skip header
2388 dunkaist 120
	mov	edi, [eax + Image.Data]
121
	add	edi, 2
122
	mov	[line_begin], edi
2397 dunkaist 123
 
124
  .24bit.scanline:
2388 dunkaist 125
	mov	ebx, [total_bpl]
2397 dunkaist 126
  .24bit.color_line:
127
	mov	edx, [bpl]
128
  .24bit.next_byte:
2388 dunkaist 129
	call	pcx._.get_byte
2397 dunkaist 130
	sub	edx, ecx
131
    @@:
132
	mov	[edi], al
2388 dunkaist 133
	add	edi, [nplanes]
2397 dunkaist 134
	dec	ecx
135
	jnz	@b
1569 dunkaist 136
 
2397 dunkaist 137
	test	edx, edx
138
	jnz	.24bit.next_byte
1569 dunkaist 139
 
2397 dunkaist 140
  .24bit.end_color_line:
2388 dunkaist 141
	test	ebx, ebx
2397 dunkaist 142
	jz	.24bit.end_full_line
2388 dunkaist 143
	dec	[line_begin]
144
	mov	edi, [line_begin]
2397 dunkaist 145
	jmp	.24bit.color_line
1569 dunkaist 146
 
2397 dunkaist 147
  .24bit.end_full_line:
148
	dec	[ysize]
2388 dunkaist 149
	jz	.quit
150
	add	edi, 2
2397 dunkaist 151
	bt	[xsize], 0
152
	jnc	@f
153
	sub	edi, 3
154
    @@:
2388 dunkaist 155
	mov	[line_begin], edi
2397 dunkaist 156
	jmp	.24bit.scanline
1569 dunkaist 157
 
1572 dunkaist 158
 
1593 dunkaist 159
  .indexed:
1572 dunkaist 160
 
2388 dunkaist 161
	stdcall	img.create, eax, ebx, Image.bpp8
162
	mov	[retvalue], eax
163
	test	eax, eax
164
	jz	.quit
1572 dunkaist 165
 
2397 dunkaist 166
	mov	ebx, eax
2388 dunkaist 167
	mov	esi, [_data]
168
	add	esi, [_length]
169
	sub	esi, 768
170
	mov	edi, [eax + Image.Palette]
2397 dunkaist 171
	mov	ecx, 256
172
	xor	eax, eax
2388 dunkaist 173
    @@:
2397 dunkaist 174
	lodsw
175
	xchg	al, ah
176
	shl	eax, 8
177
	lodsb
178
	stosd
179
	dec	ecx
2388 dunkaist 180
	jnz	@b
1572 dunkaist 181
 
2388 dunkaist 182
	mov	esi, [_data]
183
	add	esi, 128
2397 dunkaist 184
	mov	edi, [ebx + Image.Data]
1572 dunkaist 185
 
2397 dunkaist 186
  .indexed.line:
187
	mov	ebx, [total_bpl]
188
  .indexed.next_byte:
2388 dunkaist 189
	call	pcx._.get_byte
2397 dunkaist 190
    @@:
191
	stosb
192
	dec	ecx
193
	jnz	@b
194
	test	ebx, ebx
195
	jnz	.indexed.next_byte
1572 dunkaist 196
 
2397 dunkaist 197
	dec	[ysize]
198
	jnz	.indexed.line
199
	jmp	.quit
1572 dunkaist 200
 
201
 
1593 dunkaist 202
  .monochrome:
1572 dunkaist 203
 
2388 dunkaist 204
	stdcall	img.create, eax, ebx, Image.bpp1
205
	mov	[retvalue], eax
206
	test	eax, eax
207
	jz	.quit
1572 dunkaist 208
 
2388 dunkaist 209
	mov	edi, [eax + Image.Palette]
2397 dunkaist 210
	mov	[edi], dword 0xff000000
211
	mov	[edi + 4], dword 0xffffffff
1572 dunkaist 212
 
2388 dunkaist 213
	mov	esi, [_data]
214
	add	esi, 128
215
	mov	edi, [eax + Image.Data]
1572 dunkaist 216
 
1593 dunkaist 217
 
2397 dunkaist 218
  .monochrome.line:
2388 dunkaist 219
	mov	ebx, [total_bpl]
2397 dunkaist 220
  .monochrome.next_byte:
2388 dunkaist 221
	call	pcx._.get_byte
2397 dunkaist 222
    @@:
223
	stosb
224
	dec	ecx
225
	jnz	@b
2388 dunkaist 226
	test	ebx, ebx
2397 dunkaist 227
	jnz	.monochrome.next_byte
228
	dec	[ysize]
229
	jnz	.monochrome.line
230
;	jmp	.quit
1572 dunkaist 231
 
1593 dunkaist 232
 
1572 dunkaist 233
  .quit:
2388 dunkaist 234
	popa
235
	mov	eax, [retvalue]
236
	ret
1569 dunkaist 237
endp
238
 
1572 dunkaist 239
 
1569 dunkaist 240
;;================================================================================================;;
241
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
242
;;------------------------------------------------------------------------------------------------;;
1921 dunkaist 243
;? Encode image into raw data in pcx format                                                     ;;
1569 dunkaist 244
;;------------------------------------------------------------------------------------------------;;
245
;> _img = pointer to image                                                                        ;;
246
;;------------------------------------------------------------------------------------------------;;
247
;< eax = 0 (error) or pointer to encoded data                                                     ;;
248
;< _p_length = encoded data length                                                                ;;
249
;;================================================================================================;;
2388 dunkaist 250
	xor	eax, eax
251
	ret
1569 dunkaist 252
endp
253
 
254
 
255
;;================================================================================================;;
256
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
257
;;================================================================================================;;
258
;! Below are private procs you should never call directly from your code                          ;;
259
;;================================================================================================;;
260
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
261
;;================================================================================================;;
2388 dunkaist 262
proc	pcx._.get_byte
1569 dunkaist 263
 
2397 dunkaist 264
	xor	ecx, ecx
265
	lodsb
266
	cmp	al, 0xC0
267
	setb	cl
268
	jb	.done
269
	and	al, 0x3F
270
	mov	cl, al
271
	lodsb
272
  .done:
2388 dunkaist 273
	sub	ebx, ecx
274
	ret
275
endp
1593 dunkaist 276
 
2388 dunkaist 277
 
1569 dunkaist 278
;;================================================================================================;;
279
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
280
;;================================================================================================;;
281
;! Below is private data you should never use directly from your code                             ;;
282
;;================================================================================================;;
283
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
284
;;================================================================================================;;