Subversion Repositories Kolibri OS

Rev

Rev 1951 | Rev 1958 | Go to most recent revision | 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]
1951 mario79 45
	mov [pointer],eax
46
	mov eax,[eax+4]
47
	mov [image_file],eax
1956 mario79 48
	mov  esi,[eax+28]
49
	add  esi,eax
1951 mario79 50
	mov  edi,esi
51
	mov  ecx,[eax+32]
52
;	xor  ebx,ebx
53
;	mov  [raw_area],ebx
54
 
55
;	mov  ebx,[pointer]
56
;	movzx  eax,word [eax+18]
57
;	mov  [ebx+24],eax
58
;	jmp  .ret_ok
59
 
60
	cmp [eax+16],word 16
61
	je  .16b
62
	cmp [eax+12],dword 1
63
	je  .1b
64
	cmp [eax+12],dword 2
65
	je  .2b
66
	cmp [eax+12],dword 4
67
	je  .4b
68
;---------------------------------------------------------------------
69
.ret_ok:
70
;	mov ebx,[pointer]
71
;	mov  eax,[raw_area]
72
;	mov  [ebx+20],eax  ; store RAW pointer
73
;	mov  [ebx+24],ecx
74
 
75
	mov  ebx,[image_file]
76
	cmp  [ebx+18],word 2
77
	jne  @f
78
	mov  eax,[ebx+12]
79
	shr  eax,1
80
	mov  [ebx+12],eax
81
@@:
82
 
83
	popad
1956 mario79 84
	ret	4
1951 mario79 85
;---------------------------------------------------------------------
86
.less_8b:
87
	mov edx,[image_file]
88
	mov ecx,[area_size]
89
	add ecx,[edx+28]
90
	mcall 68,20
91
	mov  [image_file],eax
92
 
93
 
94
	mov ecx,[area_size]
95
	mov  eax,ecx
96
	shr  ecx,2
97
	test eax,3
1956 mario79 98
	jz  @f
99
	inc  ecx
1951 mario79 100
@@:
101
	mov  esi,[raw_area]
102
	mov  edi,[image_file]
103
	add  edi,[edi+28]
104
	cld
105
	rep movsd
106
 
107
	mov  ecx,[raw_area]
108
	mcall 68,13
109
	mov eax,[image_file]
110
	mov ebx,[pointer]
111
	mov [ebx+4],eax
112
	popad
1956 mario79 113
	ret	4
1951 mario79 114
;---------------------------------------------------------------------
115
.16b:
1956 mario79 116
	cmp  [eax+18],word 3
1951 mario79 117
	je   @f   ;.convert_16_in_8
1956 mario79 118
	cmp  [eax+18],word 4
1951 mario79 119
	jne  .16b_1
120
@@:
1956 mario79 121
	xor  ebx,ebx
1951 mario79 122
	mov  bx,[eax+18]
123
 
124
	xchg  eax,ecx
125
	xor  edx,edx
126
	div  ebx
127
	xchg  ecx,eax
128
 
129
	shr  ecx,1
130
 
131
	mov  [eax+16],word 8
1956 mario79 132
	mov  ebx,[eax+12]
1951 mario79 133
	shr  ebx,1
134
	mov  [eax+12],ebx
135
 
136
	mov  ebx,eax
137
;	jmp  .ret_ok
138
 
139
.convert_16_in_8:   ; converting 16 bit sample to 8 bit
140
	cld
141
	lodsw
142
	mov al,ah
143
	stosb
144
 
145
	lodsw
146
	mov al,ah
147
	stosb
148
 
149
	lodsw
150
	mov al,ah
151
	stosb
152
 
153
	cmp [ebx+18],word 4
154
	jne @f
155
	lodsw
156
	mov al,ah
157
	stosb
158
@@:
159
	dec ecx
160
	jnz .convert_16_in_8
161
	jmp .16b_end
162
;---------------------------------------------------------------------
163
.16b_1:
1956 mario79 164
	cmp  [eax+18],word 1
1951 mario79 165
	je   @f  ;.convert_16_in_8_1
1956 mario79 166
	cmp  [eax+18],word 2
1951 mario79 167
	jne  .16b_end
168
@@:
169
	shr  ecx,1
170
 
171
	mov  [eax+16],word 8
1956 mario79 172
	mov  ebx,[eax+12]
1951 mario79 173
	shr  ebx,1
174
	mov  [eax+12],ebx
175
 
176
.convert_16_in_8_1:
1956 mario79 177
	cld
178
	lodsw
179
;	shr ax,8
1951 mario79 180
;	mov al,ah
1956 mario79 181
	stosb
182
	dec ecx
183
	jnz .convert_16_in_8_1
1951 mario79 184
;---------------------------------------------------------------------
185
.16b_end:
1956 mario79 186
	xor  eax,eax
1951 mario79 187
	mov  [raw_area],eax
188
	jmp .ret_ok
189
;---------------------------------------------------------------------
190
.4b:
191
	call .get_memory
192
	mov  edx,ebx
193
	inc  ebx
194
	shr  ebx,1
195
.4b_1:
196
	push ebx edi
197
@@:
198
	cld
199
	lodsb
200
	shl  eax,8
201
	mov  al,ah
202
	and  ah,0xf
203
	shr  al,4
204
	stosw
205
 
206
	dec  ebx
207
	jnz  @b
208
	pop  edi ebx
209
	add  edi,edx
210
	dec  ecx
211
	jnz  .4b_1
212
 
213
	jmp .less_8b  ;.ret_ok
214
;---------------------------------------------------------------------
215
.2b:
216
	call .get_memory
1956 mario79 217
;	jmp .ret_ok
1951 mario79 218
;	shr  ecx,1
219
	mov  edx,ebx
220
	mov  eax,ebx
221
	shr  ebx,2
222
	test eax,3
1956 mario79 223
	jz  @f
224
	inc  ebx
1951 mario79 225
@@:
226
	mov  ebp,ebx
227
.2b_1:
228
	push ebp edi
229
@@:
230
	cld
231
	lodsb
232
 
233
	mov  bl,al
234
 
235
	and  al,11b
236
	shl  ax,8
237
 
238
	mov  al,bl
239
	shr  al,2
240
	and  al,11b
241
	shl  eax,8
242
 
243
	mov  al,bl
244
	shr  al,4
245
	and  al,11b
246
	shl  eax,8
247
 
248
	mov  al,bl
249
	shr  al,6
250
	and  al,11b
251
 
252
	stosd
253
 
254
	dec  ebp
255
	jnz  @b
256
	pop  edi ebp
257
 
258
	add  edi,edx
259
	dec  ecx
260
	jnz  .2b_1
261
 
262
	jmp .less_8b  ;.ret_ok
263
;---------------------------------------------------------------------
264
.1b:
265
	call .get_memory
266
	mov  edx,ebx
267
	mov  eax,ebx
268
	shr  ebx,3
269
	test eax,7
1956 mario79 270
	jz  @f
271
	inc  ebx
1951 mario79 272
@@:
273
	mov  ebp,ebx
274
.1b_1:
275
	push ebp edi
276
@@:
277
	cld
278
	lodsb
279
 
280
	mov  bl,al
281
	shr  al,4
282
	and  al,1b
283
	shl  ax,8
284
 
285
	mov  al,bl
286
	shr  al,5
287
	and  al,1b
288
	shl  eax,8
289
 
290
	mov  al,bl
291
	shr  al,6
292
	and  al,1b
293
	shl  eax,8
294
 
295
	mov  al,bl
296
	shr  al,7
297
;	and  al,1b
298
;	shl  eax,8
299
 
300
	stosd
301
 
302
	mov  al,bl
303
	and  al,1b
304
	shl  ax,8
305
 
306
	mov  al,bl
307
	shr  al,1
308
	and  al,1b
309
	shl  eax,8
310
 
311
	mov  al,bl
312
	shr  al,2
313
	and  al,1b
314
	shl  eax,8
315
 
316
	mov  al,bl
317
	shr  al,3
318
	and  al,1b
319
 
320
	stosd
321
 
322
	dec  ebp
323
	jnz  @b
324
	pop  edi ebp
325
 
326
	add  edi,edx
327
	dec  ecx
328
	jnz  .1b_1
329
	jmp .less_8b  ;.ret_ok
330
;---------------------------------------------------------------------
331
.get_memory:
332
	mov  ebx,dword 8
333
	mov  [eax+16],bx
334
	mov  [eax+12],ebx
335
;	mov  esi,[eax+28]
336
;	add  esi,eax
337
;	push ecx
338
	mov  ecx,[eax+4]
339
	imul ecx,[eax+8]
340
	push eax
341
	mov  [area_size],ecx
342
	mcall 68,12
343
;	pop  ecx
344
	mov  [raw_area],eax
345
	mov  edi,eax
346
	pop  eax
347
	mov  ebx,[eax+4]
348
	mov  ecx,[eax+8]
349
	ret
350
;---------------------------------------------------------------------
351
Convert24b:
352
	pushad
353
	mov [pointer],eax
354
	mov eax,[eax+4]
355
	mov [image_file],eax
356
 
1956 mario79 357
	mov  esi,[eax+28]
358
	add  esi,eax
1951 mario79 359
 
360
	mov  ebp,[eax+20]
1956 mario79 361
	add  ebp,eax
1951 mario79 362
 
363
	mov  ecx,[eax+4]
364
	imul ecx,[eax+8]
365
	push eax ecx
366
	lea  ecx,[ecx*3]
367
	mcall 68,12
368
	mov  [raw_area],eax
369
	mov  edi,eax
370
	pop  ecx eax
371
 
372
	cmp [eax+12],dword 32
373
	je  .32b
374
	cmp [eax+12],dword 16
375
	je  .16b
376
	cmp [eax+12],dword 15
377
	je  .15b
378
	cmp [eax+12],dword 8
379
	je  .8b
380
 
381
.ret_ok:
382
	mov ebx,[pointer]
383
	mov  eax,[raw_area]
384
	mov  [ebx+20],eax  ; store RAW pointer
385
	popad
1956 mario79 386
	ret	4
1951 mario79 387
 
388
;---------------------------------------------------------------------
389
.32b:
390
	cld
391
	lodsd
392
 
393
	stosw
394
	shr eax,16
395
	stosb
396
 
397
	dec  ecx
398
	jnz  .32b
399
 
400
	jmp  .ret_ok
401
;---------------------------------------------------------------------
402
.16b:
403
	cld
404
	lodsw
405
 
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
422
 
423
	cld
424
	stosw
425
	shr eax,16
426
	stosb
427
 
428
	dec  ecx
429
	jnz  .16b
430
 
431
	jmp  .ret_ok
432
;---------------------------------------------------------------------
433
.15b:
434
	cld
435
	lodsw
436
 
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
453
 
454
	cld
455
	stosw
456
	shr eax,16
457
	stosb
458
 
459
	dec  ecx
460
	jnz  .15b
461
 
462
	jmp  .ret_ok
463
;---------------------------------------------------------------------
464
.8b:
465
	xor  eax,eax
466
	cld
467
	lodsb
468
	shl  eax,2
469
	mov  eax,[eax+ebp]
470
 
471
	cld
472
	stosw
473
	shr eax,16
474
	stosb
475
 
476
	dec  ecx
477
	jnz  .8b
478
 
479
	jmp  .ret_ok
480
;---------------------------------------------------------------------
481
align 16
482
EXPORTS:
483
	dd      szStart,	START
484
	dd      szVersion,	0x00010001
485
	dd		szConv_24b,	Convert24b
486
	dd      0
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