Subversion Repositories Kolibri OS

Rev

Rev 1958 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1951 mario79 1
;*****************************************************************************
2
; RAW to RAW convert plugin - for zSea image viewer
3
; Copyright (c) 2008-2011, Marat Zakiyanov aka Mario79, aka Mario
4
; All rights reserved.
5
;
6
; Redistribution and use in source and binary forms, with or without
7
; modification, are permitted provided that the following conditions are met:
8
;	 * Redistributions of source code must retain the above copyright
9
;	   notice, this list of conditions and the following disclaimer.
10
;	 * Redistributions in binary form must reproduce the above copyright
11
;	   notice, this list of conditions and the following disclaimer in the
12
;	   documentation and/or other materials provided with the distribution.
13
;	 * Neither the name of the  nor the
14
;	   names of its contributors may be used to endorse or promote products
15
;	   derived from this software without specific prior written permission.
16
;
17
; THIS SOFTWARE IS PROVIDED BY Marat Zakiyanov ''AS IS'' AND ANY
18
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
; DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY
21
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
;*****************************************************************************
28
 
29
; Convert:
30
; 16b in 8b
31
; 1b,2b,3b in 8b
32
 
33
format MS COFF
34
 
35
public EXPORTS
36
 
37
section '.flat' code readable align 16
38
 
39
;include    'macros.inc'
40
include    '../../../../macros.inc'
41
;---------------------------------------------------------------------
42
START:
43
	pushad
1956 mario79 44
	mov	eax,dword [esp+36]
2163 mario79 45
	mov	[pointer],eax
46
	mov	eax,[eax+4]
47
	mov	[image_file],eax
48
	mov	esi,[eax+28]
49
	add	esi,eax
50
	mov	edi,esi
51
	mov	ecx,[eax+32]
1951 mario79 52
 
2163 mario79 53
	cmp	[eax+16],word 16
54
	je	.16b
55
	cmp	[eax+12],dword 1
56
	je	.1b
57
	cmp	[eax+12],dword 2
58
	je	.2b
59
	cmp	[eax+12],dword 4
60
	je	.4b
1951 mario79 61
;---------------------------------------------------------------------
62
.ret_ok:
2163 mario79 63
	mov	ebx,[image_file]
64
	cmp	[ebx+18],word 2
65
	jne	@f
66
	mov	eax,[ebx+12]
67
	shr	eax,1
68
	mov	[ebx+12],eax
1951 mario79 69
@@:
70
	popad
1956 mario79 71
	ret	4
1951 mario79 72
;---------------------------------------------------------------------
73
.less_8b:
2163 mario79 74
	mov	edx,[image_file]
75
	mov	ecx,[area_size]
76
	add	ecx,[edx+28]
77
	mcall	68,20
78
	mov	[image_file],eax
1951 mario79 79
 
2163 mario79 80
	mov	ecx,[area_size]
81
	mov	eax,ecx
82
	shr	ecx,2
83
	test	eax,3
84
	jz	@f
85
	inc	ecx
1951 mario79 86
@@:
2163 mario79 87
	mov	esi,[raw_area]
88
	mov	edi,[image_file]
89
	add	edi,[edi+28]
1951 mario79 90
	cld
2163 mario79 91
	rep	movsd
92
 
93
	mcall	68,13,[raw_area]
94
	mov	eax,[image_file]
95
	mov	ebx,[pointer]
96
	mov	[ebx+4],eax
1951 mario79 97
	popad
1956 mario79 98
	ret	4
1951 mario79 99
;---------------------------------------------------------------------
100
.16b:
2163 mario79 101
; eax - RAW image_file
102
	cmp	[eax+18],word 3
103
	je	@f
104
	cmp	[eax+18],word 4
105
	jne	.16b_1
1951 mario79 106
@@:
2163 mario79 107
	xor	ebx,ebx
108
	mov	bx,[eax+18]
1951 mario79 109
 
2163 mario79 110
	xchg	eax,ecx
111
	xor	edx,edx
112
	div	ebx
113
	xchg	ecx,eax
1951 mario79 114
 
2163 mario79 115
	shr	ecx,1
1951 mario79 116
 
2163 mario79 117
	mov	[eax+16],word 8
118
	mov	ebx,[eax+12]
119
	shr	ebx,1
120
	mov	[eax+12],ebx
1951 mario79 121
 
2163 mario79 122
	mov	ebx,eax
1951 mario79 123
 
124
.convert_16_in_8:   ; converting 16 bit sample to 8 bit
125
	cld
126
	lodsw
2163 mario79 127
	mov	al,ah
1951 mario79 128
	stosb
129
 
130
	lodsw
2163 mario79 131
	mov	al,ah
1951 mario79 132
	stosb
133
 
134
	lodsw
2163 mario79 135
	mov	al,ah
1951 mario79 136
	stosb
137
 
2163 mario79 138
	cmp	[ebx+18],word 4
139
	jne	@f
1951 mario79 140
	lodsw
2163 mario79 141
	mov	al,ah
1951 mario79 142
	stosb
143
@@:
2163 mario79 144
	dec	ecx
145
	jnz	.convert_16_in_8
146
 
147
	jmp	.16b_end
1951 mario79 148
;---------------------------------------------------------------------
149
.16b_1:
2163 mario79 150
; eax - RAW image_file
151
	cmp	[eax+18],word 1
152
	je	@f
153
	cmp	[eax+18],word 2
154
	jne	.16b_end
1951 mario79 155
@@:
2163 mario79 156
	shr	ecx,1
1951 mario79 157
 
2163 mario79 158
	mov	[eax+16],word 8
159
	mov	ebx,[eax+12]
160
	shr	ebx,1
161
	mov	[eax+12],ebx
1951 mario79 162
 
163
.convert_16_in_8_1:
1956 mario79 164
	cld
165
	lodsw
166
	stosb
2163 mario79 167
	dec	ecx
168
	jnz	.convert_16_in_8_1
1951 mario79 169
;---------------------------------------------------------------------
170
.16b_end:
2163 mario79 171
	xor	eax,eax
172
	mov	[raw_area],eax
173
	jmp	.ret_ok
1951 mario79 174
;---------------------------------------------------------------------
175
.4b:
2163 mario79 176
	call	.get_memory
177
	mov	edx,ebx
178
	inc	ebx
179
	shr	ebx,1
1951 mario79 180
.4b_1:
2163 mario79 181
	push	ebx edi
1951 mario79 182
@@:
183
	cld
184
	lodsb
2163 mario79 185
	shl	eax,8
186
	mov	al,ah
187
	and	ah,0xf
188
	shr	al,4
1951 mario79 189
	stosw
190
 
2163 mario79 191
	dec	ebx
192
	jnz	@b
193
	pop	edi ebx
194
	add	edi,edx
195
	dec	ecx
196
	jnz	.4b_1
1951 mario79 197
 
2163 mario79 198
	jmp	.less_8b
1951 mario79 199
;---------------------------------------------------------------------
200
.2b:
2163 mario79 201
	call	.get_memory
202
	mov	edx,ebx
203
	mov	eax,ebx
204
	shr	ebx,2
205
	test	eax,3
206
	jz	@f
207
	inc	ebx
1951 mario79 208
@@:
2163 mario79 209
	mov	ebp,ebx
1951 mario79 210
.2b_1:
2163 mario79 211
	push	ebp edi
1951 mario79 212
@@:
213
	cld
214
	lodsb
215
 
2163 mario79 216
	mov	bl,al
1951 mario79 217
 
2163 mario79 218
	and	al,11b
219
	shl	ax,8
1951 mario79 220
 
2163 mario79 221
	mov	al,bl
222
	shr	al,2
223
	and	al,11b
224
	shl	eax,8
1951 mario79 225
 
2163 mario79 226
	mov	al,bl
227
	shr	al,4
228
	and	al,11b
229
	shl	eax,8
1951 mario79 230
 
2163 mario79 231
	mov	al,bl
232
	shr	al,6
233
	and	al,11b
1951 mario79 234
 
235
	stosd
236
 
2163 mario79 237
	dec	ebp
238
	jnz	@b
239
	pop	edi ebp
1951 mario79 240
 
2163 mario79 241
	add	edi,edx
242
	dec	ecx
243
	jnz	.2b_1
1951 mario79 244
 
2163 mario79 245
	jmp	.less_8b
1951 mario79 246
;---------------------------------------------------------------------
247
.1b:
2163 mario79 248
	call	.get_memory
249
	mov	edx,ebx
250
	mov	eax,ebx
251
	shr	ebx,3
252
	test	eax,7
253
	jz	@f
254
	inc	ebx
1951 mario79 255
@@:
2163 mario79 256
	mov	ebp,ebx
1951 mario79 257
.1b_1:
2163 mario79 258
	push	ebp edi
1951 mario79 259
@@:
260
	cld
261
	lodsb
262
 
2163 mario79 263
	mov	bl,al
264
	shr	al,4
265
	and	al,1b
266
	shl	ax,8
1951 mario79 267
 
2163 mario79 268
	mov	al,bl
269
	shr	al,5
270
	and	al,1b
271
	shl	eax,8
1951 mario79 272
 
2163 mario79 273
	mov	al,bl
274
	shr	al,6
275
	and	al,1b
276
	shl	eax,8
1951 mario79 277
 
2163 mario79 278
	mov	al,bl
279
	shr	al,7
1951 mario79 280
 
281
	stosd
282
 
2163 mario79 283
	mov	al,bl
284
	and	al,1b
285
	shl	ax,8
1951 mario79 286
 
2163 mario79 287
	mov	al,bl
288
	shr	al,1
289
	and	al,1b
290
	shl	eax,8
1951 mario79 291
 
2163 mario79 292
	mov	al,bl
293
	shr	al,2
294
	and	al,1b
295
	shl	eax,8
1951 mario79 296
 
2163 mario79 297
	mov	al,bl
298
	shr	al,3
299
	and	al,1b
1951 mario79 300
 
301
	stosd
302
 
2163 mario79 303
	dec	ebp
304
	jnz	@b
305
	pop	edi ebp
1951 mario79 306
 
2163 mario79 307
	add	edi,edx
308
	dec	ecx
309
	jnz	.1b_1
310
 
311
	jmp	.less_8b
1951 mario79 312
;---------------------------------------------------------------------
313
.get_memory:
2163 mario79 314
; eax - RAW image_file
315
	mov	ebx,dword 8
316
	mov	[eax+16],bx
317
	mov	[eax+12],ebx
318
	mov	ecx,[eax+4]
319
	imul	ecx,[eax+8]
320
	push	eax
321
	mov	[area_size],ecx
322
	mcall	68,12
323
	mov	[raw_area],eax
324
	mov	edi,eax
325
	pop	eax
326
	mov	ebx,[eax+4]
327
	mov	ecx,[eax+8]
1951 mario79 328
	ret
329
;---------------------------------------------------------------------
330
Convert24b:
331
	pushad
1958 mario79 332
	mov	eax,dword [esp+36]
2163 mario79 333
	mov	[pointer],eax
334
	mov	eax,[eax+4]
335
	mov	[image_file],eax
1951 mario79 336
 
2163 mario79 337
	mov	esi,[eax+28]
338
	add	esi,eax
1951 mario79 339
 
2163 mario79 340
	mov	ebp,[eax+20]
341
	add	ebp,eax
1951 mario79 342
 
2163 mario79 343
	mov	ecx,[eax+4]
344
	imul	ecx,[eax+8]
345
	push	eax ecx
346
	lea	ecx,[ecx*3]
347
	mov	edx,ecx
348
	add	ecx,44		; header
349
	mcall	68,12		;get new RAW area
350
	mov	[raw_area],eax
351
	mov	edi,eax
352
 
353
	push	esi
354
	mov	esi,[image_file]
355
	mov	ecx,3
356
	cld
357
	rep	movsd			;copy the 3 first dword for the structure of RAW
358
	pop	esi
359
 
360
	sub	edi,12
361
	mov	[edi+12],dword 24	;overall depth of the pixel
362
	mov	[edi+16],word 8		;channel depth of the pixel
363
	xor	eax,eax
364
	mov	[edi+20],eax		;palette area pointer
365
	mov	[edi+24],eax		;palette area size
366
	mov	[edi+28],dword 44	;rgb area pointer
367
	mov	[edi+32],edx		;rgb area size
368
	mov	[edi+36],eax		;transparency area pointer
369
	mov	[edi+40],eax		;transparency area size
370
	pop	ecx eax
371
 
372
	add	edi,44
1951 mario79 373
 
2163 mario79 374
	cmp	[eax+12],dword 32
375
	je	.32b
376
	cmp	[eax+12],dword 16
377
	je	.16b
378
	cmp	[eax+12],dword 15
379
	je	.15b
380
	cmp	[eax+12],dword 8
381
	je	.8b
1951 mario79 382
 
383
.ret_ok:
2163 mario79 384
	mov	ebx,[pointer]
385
	mov	eax,[raw_area]
386
	mov	[ebx+20],eax  ; store RAW pointer
1951 mario79 387
	popad
1956 mario79 388
	ret	4
1951 mario79 389
;---------------------------------------------------------------------
390
.32b:
391
	cld
392
	lodsd
393
	stosw
2163 mario79 394
	shr	eax,16
1951 mario79 395
	stosb
396
 
2163 mario79 397
	dec	ecx
398
	jnz	.32b
1951 mario79 399
 
2163 mario79 400
	jmp	.ret_ok
1951 mario79 401
;---------------------------------------------------------------------
402
.16b:
403
	cld
404
	lodsw
405
 
2163 mario79 406
	xor	ebx,ebx
407
	ror	ax,11
408
	mov	bl,al
409
	and	bl,11111b
410
	shl	bl,3
411
	shl	ebx,8
412
	rol	ax,6
413
	mov	bl,al
414
	and	bl,111111b
415
	shl	bl,2
416
	shl	ebx,8
417
	rol	ax,5
418
	mov	bl,al
419
	and	bl,11111b
420
	shl	bl,3
421
	mov	eax,ebx
1951 mario79 422
 
423
	cld
424
	stosw
2163 mario79 425
	shr	eax,16
1951 mario79 426
	stosb
427
 
2163 mario79 428
	dec	ecx
429
	jnz	.16b
1951 mario79 430
 
2163 mario79 431
	jmp	.ret_ok
1951 mario79 432
;---------------------------------------------------------------------
433
.15b:
434
	cld
435
	lodsw
436
 
2163 mario79 437
	xor	ebx,ebx
438
	ror	ax,10
439
	mov	bl,al
440
	and	bl,11111b
441
	shl	bl,3
442
	shl	ebx,8
443
	rol	ax,5
444
	mov	bl,al
445
	and	bl,11111b
446
	shl	bl,3
447
	shl	ebx,8
448
	rol	ax,5
449
	mov	bl,al
450
	and	bl,11111b
451
	shl	bl,3
452
	mov	eax,ebx
1951 mario79 453
 
454
	cld
455
	stosw
2163 mario79 456
	shr	eax,16
1951 mario79 457
	stosb
458
 
2163 mario79 459
	dec	ecx
460
	jnz	.15b
1951 mario79 461
 
2163 mario79 462
	jmp	.ret_ok
1951 mario79 463
;---------------------------------------------------------------------
464
.8b:
2163 mario79 465
	xor	eax,eax
1951 mario79 466
	cld
467
	lodsb
2163 mario79 468
	shl	eax,2
469
	mov	eax,[eax+ebp]
1951 mario79 470
 
471
	cld
472
	stosw
2163 mario79 473
	shr	eax,16
1951 mario79 474
	stosb
475
 
2163 mario79 476
	dec	ecx
477
	jnz	.8b
1951 mario79 478
 
2163 mario79 479
	jmp	.ret_ok
1951 mario79 480
;---------------------------------------------------------------------
481
align 16
482
EXPORTS:
2163 mario79 483
	dd szStart,	START
484
	dd szVersion,	0x00010003
485
	dd szConv_24b,	Convert24b
486
	dd 0
1951 mario79 487
 
488
szStart		db 'START',0
489
szVersion	db 'version',0
490
szConv_24b	db 'Convert24b',0
491
pointer		dd 0
492
image_file	dd 0
493
;delta		dd 0
494
;resolution	dd 0
495
;compression	dd 0
496
raw_area	dd 0
497
area_size	dd 0