Subversion Repositories Kolibri OS

Rev

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