Subversion Repositories Kolibri OS

Rev

Rev 1921 | Rev 2397 | 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
 
2388 dunkaist 39
	cmp	[edi + pcx_header.magic_number], 10
40
	jne	.is_not_pcx
41
	cmp	[edi + pcx_header.version], 5
42
	jne	.is_not_pcx
43
	cmp	[edi + pcx_header.encoding], 1
44
	jne	.is_not_pcx
45
	cmp	[edi + pcx_header.reserved], 0
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
77
	xsize			rw	1
78
	ysize			rw	1
79
	bpl			rw	1
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
90
	mov	bx, word[esi + pcx_header.bpl]
91
	mov	[bpl], bx
92
	mul	bx
93
	shl	eax, 16
94
	mov	ax, dx
95
	ror	eax, 16
96
	mov	[total_bpl], eax
1569 dunkaist 97
 
2388 dunkaist 98
	movzx	eax, word[esi + pcx_header.xmax]
99
	inc	ax
100
	sub	ax, word[esi + pcx_header.xmin]
101
	mov	[xsize], ax
1569 dunkaist 102
 
2388 dunkaist 103
	movzx	ebx, word[esi + pcx_header.ymax]
104
	inc	bx
105
	sub	bx, word[esi + pcx_header.ymin]
106
	mov	[ysize], bx
1569 dunkaist 107
 
1593 dunkaist 108
 
2388 dunkaist 109
	cmp	[esi + pcx_header.bpp], 1
110
	jz	.monochrome
111
	cmp	byte[esi + pcx_header.nplanes], 3
112
	jnz	.indexed
1593 dunkaist 113
 
114
 
115
  ._24bit:
116
 
2388 dunkaist 117
	stdcall	img.create, eax, ebx, Image.bpp24
118
	mov	[retvalue], eax
119
	test	eax, eax
120
	jz	.quit
1569 dunkaist 121
 
2388 dunkaist 122
	movzx	ebx, [xsize]
123
	movzx	ecx, [ysize]
124
	mov	edx, [eax+Image.Data]
1569 dunkaist 125
 
2388 dunkaist 126
	rol	ebx, 16
127
	or	ebx, ecx
128
	xor	ebx, [edx]
129
	mov	[eax + Image.Checksum], ebx
1569 dunkaist 130
 
131
 
2388 dunkaist 132
	mov	esi, [_data]
133
	add	esi, 128
134
;	mov	edi, [retvalue]
135
	mov	edi, [eax + Image.Data]
136
	add	edi, 2
137
	mov	[line_begin], edi
138
	mov	ebx, [total_bpl]
1569 dunkaist 139
 
1593 dunkaist 140
  ._24bit.begin:
2388 dunkaist 141
	mov	ax, word[bpl]
1593 dunkaist 142
  ._24bit.decode:
2388 dunkaist 143
	call	pcx._.get_byte
1593 dunkaist 144
  ._24bit.write_sequence:
2388 dunkaist 145
	mov	[edi], dl
146
	dec	ax
147
	add	edi, [nplanes]
148
	dec	dh
149
	jnz	._24bit.write_sequence
1569 dunkaist 150
 
2388 dunkaist 151
	test	ax, ax
152
	jz	._24bit.end_color_line
153
	jmp	._24bit.decode
1569 dunkaist 154
 
2388 dunkaist 155
  ._24bit.end_color_line:
156
	test	ebx, ebx
157
	jz	._24bit.end_full_line
158
	dec	[line_begin]
159
	mov	edi, [line_begin]
160
	jmp	._24bit.begin
1569 dunkaist 161
 
1593 dunkaist 162
  ._24bit.end_full_line:
2388 dunkaist 163
	dec	word[ysize]
164
	jz	.quit
165
	mov	ebx, [total_bpl]
166
	add	edi, 2
167
	mov	[line_begin], edi
168
	jmp	._24bit.begin
1569 dunkaist 169
 
1572 dunkaist 170
 
1593 dunkaist 171
  .indexed:
1572 dunkaist 172
 
2388 dunkaist 173
	stdcall	img.create, eax, ebx, Image.bpp8
174
	mov	[retvalue], eax
175
	test	eax, eax
176
	jz	.quit
1572 dunkaist 177
 
2388 dunkaist 178
	movzx	ebx, [xsize]
179
	movzx	ecx, [ysize]
180
	mov	edx, [eax + Image.Data]
1593 dunkaist 181
 
2388 dunkaist 182
	rol	ebx, 16
183
	or	ebx, ecx
184
	xor	ebx, [edx]
185
	mov	[eax + Image.Checksum], ebx
1593 dunkaist 186
 
2388 dunkaist 187
	mov	esi, [_data]
188
	add	esi, [_length]
189
	sub	esi, 768
190
	mov	edi, [eax + Image.Palette]
191
	mov	cx, 256
192
    @@:
193
	mov	ebx, [esi]
194
	bswap	ebx
195
	shr	ebx, 8
196
	mov	[edi], ebx
197
	add	edi, 4
198
	add	esi, 3
199
	dec	cx
200
	jnz	@b
1572 dunkaist 201
 
2388 dunkaist 202
	mov	esi, [_data]
203
	add	esi, 128
204
;	mov	edi, [retvalue]
205
	mov	edi, [eax + Image.Data]
1572 dunkaist 206
 
1593 dunkaist 207
  .indexed.begin:
2388 dunkaist 208
	mov	ax, word[bpl]
1593 dunkaist 209
  .indexed.decode:
2388 dunkaist 210
	call	pcx._.get_byte
1593 dunkaist 211
  .indexed.write_sequence:
2388 dunkaist 212
	mov	[edi], dl
213
	inc	edi
214
	dec	ax
215
	dec	dh
216
	jnz	.indexed.write_sequence
1572 dunkaist 217
 
2388 dunkaist 218
	test	ax, ax
219
	jz	.indexed.end_line
220
	jmp	.indexed.decode
1572 dunkaist 221
 
1593 dunkaist 222
  .indexed.end_line:
2388 dunkaist 223
	dec	word[ysize]
224
	jz	.quit
225
	jmp	.indexed.begin
1572 dunkaist 226
 
227
 
1593 dunkaist 228
  .monochrome:
1572 dunkaist 229
 
2388 dunkaist 230
	stdcall	img.create, eax, ebx, Image.bpp1
231
	mov	[retvalue], eax
232
	test	eax, eax
233
	jz	.quit
1572 dunkaist 234
 
2388 dunkaist 235
	movzx	ebx, [xsize]
236
	movzx	ecx, [ysize]
237
	mov	edx, [eax + Image.Data]
1572 dunkaist 238
 
2388 dunkaist 239
	rol	ebx, 16
240
	or	ebx, ecx
241
	xor	ebx, [edx]
242
	mov	[eax + Image.Checksum], ebx
1572 dunkaist 243
 
2388 dunkaist 244
	mov	edi, [eax + Image.Palette]
245
	mov	[edi], dword 0x00000000
246
	mov	[edi + 4], dword 0x00ffffff
1572 dunkaist 247
 
2388 dunkaist 248
	mov	esi, [_data]
249
	add	esi, 128
250
;	mov	edi, [retvalue]
251
	mov	edi, [eax + Image.Data]
1572 dunkaist 252
 
1593 dunkaist 253
 
254
  .monochrome.begin:
2388 dunkaist 255
	mov	ebx, [total_bpl]
256
	mov	ax, [xsize]
1572 dunkaist 257
 
1593 dunkaist 258
  .monochrome.decode:
2388 dunkaist 259
	call	pcx._.get_byte
1593 dunkaist 260
  .monochrome.write_sequence:
2388 dunkaist 261
	mov	[edi], dl
262
	inc	edi
263
	cmp	ax, 8
264
	jng	.monochrome.is_last_byte_in_line
265
	sub	ax, 8
266
	dec	dh
267
	jnz	.monochrome.write_sequence
268
	jmp	.monochrome.decode
1572 dunkaist 269
 
1593 dunkaist 270
  .monochrome.is_last_byte_in_line:
2388 dunkaist 271
	test	ebx, ebx
272
	jng	@f
273
	call	pcx._.get_byte
274
	jmp	.monochrome.is_last_byte_in_line
275
    @@:
276
	dec	word[ysize]
277
	jnz	.monochrome.begin
278
	jmp	.quit
1572 dunkaist 279
 
1593 dunkaist 280
 
1572 dunkaist 281
  .quit:
2388 dunkaist 282
	popa
283
	mov	eax, [retvalue]
284
	ret
1569 dunkaist 285
endp
286
 
1572 dunkaist 287
 
1569 dunkaist 288
;;================================================================================================;;
289
proc img.encode.pcx _img, _p_length, _options ;///////////////////////////////////////////////////;;
290
;;------------------------------------------------------------------------------------------------;;
1921 dunkaist 291
;? Encode image into raw data in pcx format                                                     ;;
1569 dunkaist 292
;;------------------------------------------------------------------------------------------------;;
293
;> _img = pointer to image                                                                        ;;
294
;;------------------------------------------------------------------------------------------------;;
295
;< eax = 0 (error) or pointer to encoded data                                                     ;;
296
;< _p_length = encoded data length                                                                ;;
297
;;================================================================================================;;
2388 dunkaist 298
	xor	eax, eax
299
	ret
1569 dunkaist 300
endp
301
 
302
 
303
;;================================================================================================;;
304
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
305
;;================================================================================================;;
306
;! Below are private procs you should never call directly from your code                          ;;
307
;;================================================================================================;;
308
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
309
;;================================================================================================;;
2388 dunkaist 310
proc	pcx._.get_byte
1569 dunkaist 311
 
2388 dunkaist 312
	mov	dh, byte[esi]
313
	inc	esi
314
	cmp	dh, 0xC0
315
	jnb	.cycle1
316
	mov	dl, dh
317
	mov	dh, 1
318
	jmp	.exit1
1593 dunkaist 319
  .cycle1:
2388 dunkaist 320
	and	dh, 0x3F
321
	mov	dl, byte[esi]
322
	inc	esi
1593 dunkaist 323
  .exit1:
2388 dunkaist 324
	movzx	ecx, dh
325
	sub	ebx, ecx
326
	ret
327
endp
1593 dunkaist 328
 
2388 dunkaist 329
 
1569 dunkaist 330
;;================================================================================================;;
331
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
332
;;================================================================================================;;
333
;! Below is private data you should never use directly from your code                             ;;
334
;;================================================================================================;;
335
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
336
;;================================================================================================;;