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