Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1951 mario79 1
;*****************************************************************************
2
; Scaling RAW image plugin - for zSea image viewer
3
; Copyright (c) 2009 - 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
; Scaling 32b, 24b, 16b, 8b
29
 
30
format MS COFF
31
 
32
public EXPORTS
33
 
34
section '.flat' code readable align 16
35
 
1954 mario79 36
;include	'macros.inc'
1951 mario79 37
include	'../../../../macros.inc'
38
;---------------------------------------------------------------------
39
START:
40
	pushad
1958 mario79 41
	mov	edi,dword [esp+56]
42
	mov	esi,dword [esp+52]
43
	mov	edx,dword [esp+48]
44
	mov	ecx,dword [esp+44]
45
	mov	ebx,dword [esp+40]
46
	mov	eax,dword [esp+36]
1951 mario79 47
	mov [pointer],eax
48
	test bx,bx
49
	jnz  @f
50
	inc  bx
51
@@:
52
	ror ebx,16
53
	test bx,bx
54
	jnz  @f
55
	inc  bx
56
@@:
57
	rol ebx,16
58
	mov [new_size],ebx
59
	mov [start_coordinates],ecx
60
	mov [scaling_mode],edx
61
	mov [filtering],esi
62
	mov [background_color],edi
63
	mov eax,[eax+4]
64
	mov [image_file],eax
65
 
66
	mov  esi,[eax+28]
67
    add  esi,eax
68
 
69
	mov  ebx,[eax+20]
70
	add  ebx,eax
71
	mov  [palette],ebx
72
 
73
	mov ebx,[eax+12]
74
	mov [resolution],ebx
75
	cmp  ebx,32
76
	jne  @f
77
	mov  ebp,dword START.32
78
	jmp  .1
79
@@:
80
	cmp  ebx,24
81
	jne  @f
82
	mov  ebp,dword START.24
83
	jmp  .1
84
@@:
85
	cmp  ebx,16
86
	jne  @f
87
	mov  ebp,dword START.16
88
	jmp  .1
89
@@:
90
	cmp  ebx,15
91
	jne  @f
92
	inc  ebx
93
	mov  ebp,dword START.16
94
	jmp  .1
95
@@:
96
	cmp  ebx,8
97
	jne  @f
98
	mov  ebp,dword START.8
99
@@:
100
.1:
101
	shr  ebx,3
102
	mov  [bytes_to_pixel],ebx
103
 
104
	mov  ebx,[eax+8]
105
	mov  [y],ebx
106
	mov  ebx,[eax+4]
107
	mov  [x],ebx
108
	imul ebx,[bytes_to_pixel]
109
	mov  [size_x],ebx
110
 
111
	mov  eax,100
112
	shl  eax,12
113
	mov  ebx,[scaling_mode]
114
	test ebx,ebx
115
	jnz  @f
116
	inc  ebx
117
@@:
118
	xor  edx,edx
119
	div  ebx
120
	mov  [scaling_delta],eax
121
 
122
	call .get_memory
123
	cmp  [scaling_mode],0
124
	jne  @f
125
	call .scaling
126
	jmp  .ret_ok
127
@@:
128
	call .scaling_2
129
 
130
;---------------------------------------------------------------------
131
.ret_ok:
132
	mcall 68,13,[area_for_x]
133
	mov ebx,[pointer]
134
	mov  eax,[raw_area]
135
	mov  [ebx+20],eax  ; store RAW pointer
136
;	movzx eax,word [new_size.x1]
137
;	mov [ebx+24],esi  ;eax
138
;	movzx eax,word [new_size.y1]
139
;	mov [ebx+28],eax
140
;	mov eax,[size_x]
141
;	mov [ebx+32],eax
142
;	mov eax,[bytes_to_pixel]
143
;	mov [ebx+36],eax
144
;	mov eax,[x]
145
;	mov [ebx+40],eax
146
;	mov eax,[y]
147
;	mov [ebx+44],eax
148
.exit:
149
	popad
1958 mario79 150
	ret	24
1951 mario79 151
;---------------------------------------------------------------------
152
align 4
153
.scaling:
154
	xor ecx,ecx
155
.y:
156
	xor ebx,ebx
157
;-------------------------
158
.x:
159
	call ebp
160
	inc  ebx
161
	cmp  bx,[new_size.x1]
162
	jb   .x
163
;-------------------------
164
	inc  ecx
165
	cmp  cx,[new_size.y1]
166
	jb   .y
167
	ret
168
;---------------------------------------------------------------------
169
align 4
170
.scaling_2:
171
	xor  eax,eax
172
	mov  ax,[start_coordinates.y]
173
	imul eax,[size_x]
174
	add  esi,eax
175
	xor  eax,eax
176
	mov  ax,[start_coordinates.x]
177
	imul eax,[bytes_to_pixel]
178
	add  esi,eax
179
 
180
	xor  eax,eax
181
	dec  eax
182
	mov [temp_y],eax
183
 
184
	xor ecx,ecx
185
align 4
186
.y_2:
187
	xor ebx,ebx
188
;-------------------------
189
align 4
190
.x_2:
191
	call ebp
192
	inc  ebx
193
	cmp  bx,[new_size.x1]
194
	jb   .x_2
195
;-------------------------
196
	inc  ecx
197
	cmp  cx,[new_size.y1]
198
	jb   .y_2
199
	ret
200
;---------------------------------------------------------------------
201
align 4
202
.32:
203
	push ecx ebx
204
	call .calculate_pixel
205
	mov  eax,[ecx]
206
	call .check_filtering_32
207
	pop  ebx ecx
208
	cld
209
	stosd
210
	ret
211
;---------------------------------------------------------------------
212
align 4
213
.24:
214
	push ecx ebx
215
	call .calculate_pixel
216
	mov  eax,[ecx]
217
	call .check_filtering_24
218
	cld
219
	stosw
220
	shr  eax,16
221
	pop  ebx ecx
222
	cld
223
	stosb
224
	ret
225
;---------------------------------------------------------------------
226
align 4
227
.16:
228
	push ecx ebx
229
	call .calculate_pixel
230
	xor  eax,eax
231
	mov  ax,[ecx]
232
	call .check_filtering_16
233
	pop  ebx ecx
234
	cld
235
	stosw
236
	ret
237
;---------------------------------------------------------------------
238
align 4
239
.8:
240
	push ecx ebx
241
	call .calculate_pixel
242
	cmp  [filtering],0
243
	jne   @f
244
	mov  al,[ecx]
245
	pop  ebx ecx
246
	cld
247
	stosb
248
	ret
249
@@:
250
	call .check_filtering_8
251
	cld
252
	stosw
253
	shr  eax,16
254
	pop  ebx ecx
255
	cld
256
	stosb
257
	ret
258
 
259
;---------------------------------------------------------------------
260
align 4
261
.calculate_pixel:
262
	test ecx,ecx
263
	jz   .offset_x
264
;.offset_y:
265
	mov  eax,ecx
266
 
267
	mov  ecx,[temp_y]
268
	cmp  eax,ecx
269
	jne  .new_y
270
	mov  eax,[temp_y_offset]
271
	mov  ecx,eax
272
	jmp  .offset_x
273
;--------------------------------
274
align 4
275
.new_y:
276
	mov  [temp_y],eax
277
 
278
	mov  ebx,[scaling_mode]
279
	test ebx,ebx
280
	jz  @f
281
	imul eax,[scaling_delta]
282
;--------------------------------
283
	push ebx
284
	mov  ebx,eax
285
	shr  eax,12
286
	and  ebx,0xFFF
287
	shl  ebx,7  ;multiply 128
288
	shr  ebx,12
289
	mov  [next_pixel_y],ebx
290
	pop  ebx
291
;--------------------------------
292
	jmp  .ex_1
293
align 4
294
@@:
295
;--------------------------------
296
	imul eax,dword [y]
297
	mov bx,word [new_size.y1]
298
;--------------------------------
299
align 4
300
.y_div:
301
	test ebx,ebx
302
	jnz  @f
303
	inc  ebx
304
align 4
305
@@:
306
	xor  edx,edx
307
	div  ebx
308
;--------------------------------
309
	push eax
310
	mov  eax,edx
311
	shl  eax,7  ;multiply 128
312
	xor  edx,edx
313
	div  ebx
314
	mov  [next_pixel_y],eax
315
	pop  eax
316
;--------------------------------
317
align 4
318
.ex_1:
319
	mov  [temp_y1],eax
320
	imul eax,[size_x]
321
 
322
	mov  [temp_y_offset],eax
323
	mov  ecx,eax
324
align 4
325
.offset_x:
326
	test ebx,ebx
327
	jz   .finish
328
	mov  eax,[esp+4]   ;ebx
329
 
330
	mov edx,[esp+8]
331
	test edx,edx
332
	jz  .continue
333
	shl eax,3
334
	add eax,[area_for_x]
335
	mov edx,[eax+4]
336
	mov [next_pixel_x],edx
337
	mov eax,[eax]
338
	jmp .ex_3
339
;--------------------------------
340
align 4
341
.continue:
342
	mov  ebx,[scaling_mode]
343
	test ebx,ebx
344
	jz  @f
345
	imul eax,[scaling_delta]
346
;--------------------------------
347
	mov  ebx,eax
348
	shr  eax,12
349
	and  ebx,0xFFF
350
	shl  ebx,7  ;multiply 128
351
	shr  ebx,12
352
	mov  [next_pixel_x],ebx
353
;--------------------------------
354
	jmp  .ex_2
355
;--------------------------------
356
align 4
357
@@:
358
	imul eax,dword [x]
359
	mov  bx,word [new_size.x1]
360
;--------------------------------
361
align 4
362
.x_div:
363
	test ebx,ebx
364
	jnz  @f
365
	inc  ebx
366
align 4
367
@@:
368
	xor  edx,edx
369
	div  ebx
370
;--------------------------------
371
	push eax
372
	mov  eax,edx
373
	shl  eax,7  ;multiply 128
374
	xor  edx,edx
375
	div  ebx
376
	mov  [next_pixel_x],eax
377
	pop  eax
378
;--------------------------------
379
align 4
380
.ex_2:
381
	mov  edx,[bytes_to_pixel]
382
	mov  ebx,eax
383
	xor  eax,eax
384
align 4
385
@@:
386
	add eax,ebx
387
	dec  edx
388
	jnz   @r
389
 
390
	mov ebx,[esp+4]
391
	shl ebx,3
392
	add ebx,[area_for_x]
393
	mov [ebx],eax
394
	mov edx,[next_pixel_x]
395
	mov [ebx+4],edx
396
align 4
397
.ex_3:
398
	mov [temp_x1],eax
399
	add  ecx,eax
400
align 4
401
.finish:
402
	add  ecx,esi
403
	ret
404
;---------------------------------------------------------------------
405
align 4
406
.get_memory:
407
 
408
	xor  ecx,ecx
409
	mov  cx,[new_size.x1]
410
	shl  ecx,3
411
	mcall 68,12
412
	mov  [area_for_x],eax
413
 
414
	xor   ecx,ecx
415
	mov   ebx,[new_size]
416
	mov   cx,bx
417
	shr   ebx,16
418
	imul ecx,ebx  ;[eax+8]
419
	mov  eax,[bytes_to_pixel]
420
	cmp  eax,1
421
	jne  @f
422
	mov  eax,3
423
@@:
424
	imul ecx,eax
425
	mcall 68,12
426
	mov  [raw_area],eax
427
	mov  edi,eax
428
	ret
429
;---------------------------------------------------------------------
430
include 'b_filter.inc'
431
;---------------------------------------------------------------------
432
align 4
433
EXPORTS:
434
	dd      szStart,	START
1958 mario79 435
	dd      szVersion,	0x00010002
1951 mario79 436
	dd      0
437
 
438
szStart		db 'START',0
439
szVersion	db 'version',0
440
 
441
align 4
442
pointer		dd 0
443
image_file	dd 0
444
new_size:
445
.y1:			dw 0
446
.x1:			dw 0
447
 
448
x:  dd 0
449
y:  dd 0
450
 
451
size_x		dd 0
452
bytes_to_pixel dd 0
453
 
454
start_coordinates:
455
.y	dw 0
456
.x	dw 0
457
 
458
scaling_mode	dd 0
459
raw_area	dd 0
460
scaling_delta dd 0
461
 
462
area_for_x dd 0
463
 
464
temp_y dd 0
465
temp_y_offset dd 0
466
 
467
resolution dd 0
468
 
469
filtering dd 0
470
 
471
next_pixel_y dd 0
472
next_pixel_x dd 0
473
 
474
temp_y1 dd 0
475
temp_x1 dd 0
476
 
477
B_sample dd 0
478
G_sample dd 0
479
R_sample dd 0
480
 
481
B_sample_1 dd 0
482
G_sample_1 dd 0
483
R_sample_1 dd 0
484
 
485
palette dd 0
486
 
487
background_color dd 0