Subversion Repositories Kolibri OS

Rev

Rev 3053 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3053 Rev 6807
Line 15... Line 15...
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
Line -... Line 19...
-
 
19
 
-
 
20
 
-
 
21
;;================================================================================================;;
-
 
22
proc img.get_scaled_size _width, _height, _scale_type, _param1, _param2                           ;;
-
 
23
;;------------------------------------------------------------------------------------------------;;
-
 
24
;? calculate resulting width and height if image of _width and _height is scaled via _scale_type  ;;
-
 
25
;;------------------------------------------------------------------------------------------------;;
-
 
26
;> [_width]      = width of input image                                                           ;;
-
 
27
;> [_height]     = height of input image                                                          ;;
-
 
28
;> [_scale_type] = see libimg.inc (LIBIMG_SCALE_*)                                                ;;
-
 
29
;> [_param1]     = depends on _scale_type, see libimg.inc                                         ;;
-
 
30
;> [_param2]     = depends on _scale_type, see libimg.inc                                         ;;
-
 
31
;;------------------------------------------------------------------------------------------------;;
-
 
32
;< eax = width                                                                                    ;;
-
 
33
;< ecx = height                                                                                   ;;
-
 
34
;;================================================================================================;;
-
 
35
        push    ebx esi edi
-
 
36
        mov     eax, [_scale_type]
-
 
37
        cmp     eax, LIBIMG_SCALE_FIT_MIN
-
 
38
        jz      .fit_min
-
 
39
 
-
 
40
  .fit_min:
-
 
41
        xor     edx, edx
-
 
42
        mov     eax, [_width]
-
 
43
        shl     eax, 1
-
 
44
        mov     ecx, [_param1]
-
 
45
        add     eax, ecx
-
 
46
        shl     eax, 15
-
 
47
        div     ecx
-
 
48
        mov     ebx, eax
-
 
49
 
-
 
50
        xor     edx, edx
-
 
51
        mov     eax, [_height]
-
 
52
        shl     eax, 1
-
 
53
        mov     ecx, [_param2]
-
 
54
        add     eax, ecx
-
 
55
        shl     eax, 15
-
 
56
        div     ecx
-
 
57
 
-
 
58
        cmp     eax, ebx
-
 
59
        ja      .fit_height
-
 
60
        jmp     .fit_width
-
 
61
 
-
 
62
        jmp     .quit
-
 
63
  .fit_max:
-
 
64
        jmp     .quit
-
 
65
  .fit_width:
-
 
66
        xor     edx, edx
-
 
67
        mov     eax, [_width]
-
 
68
        shl     eax, 16
-
 
69
        div     [_param1]
-
 
70
        mov     ecx, eax
-
 
71
        xor     edx, edx
-
 
72
        mov     eax, [_height]
-
 
73
        shl     eax, 16
-
 
74
        mov     ebx, ecx
-
 
75
        shr     ebx, 1
-
 
76
        add     eax, ebx
-
 
77
        div     ecx
-
 
78
        mov     ecx, eax
-
 
79
        mov     eax, [_param1]
-
 
80
        jmp     .quit
-
 
81
  .fit_height:
-
 
82
        xor     edx, edx
-
 
83
        mov     eax, [_height]
-
 
84
        shl     eax, 16
-
 
85
        div     [_param2]
-
 
86
        mov     ecx, eax
-
 
87
        xor     edx, edx
-
 
88
        mov     eax, [_width]
-
 
89
        shl     eax, 16
-
 
90
        mov     ebx, ecx
-
 
91
        shr     ebx, 1
-
 
92
        add     eax, ebx
-
 
93
        div     ecx
-
 
94
        mov     ecx, [_param2]
-
 
95
        jmp     .quit
-
 
96
 
-
 
97
  .quit:
-
 
98
        pop     edi esi ebx
-
 
99
        ret
-
 
100
endp
-
 
101
 
19
 
102
 
20
;;================================================================================================;;
103
;;================================================================================================;;
21
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
104
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
22
;;------------------------------------------------------------------------------------------------;;
105
;;------------------------------------------------------------------------------------------------;;
23
;? scale _image                                                                                   ;;
106
;? scale _image                                                                                   ;;
24
;;------------------------------------------------------------------------------------------------;;
107
;;------------------------------------------------------------------------------------------------;;
25
;> [_src]         = pointer to source image                                                       ;;
108
;> [_src]         = pointer to source image                                                       ;;
26
;> [_crop_x]      = left coord of cropping rect                                                   ;;
109
;> [_crop_x]      = left coord of cropping rect                                                   ;;
27
;> [_crop_y]      = top coord of cropping rect                                                    ;;
110
;> [_crop_y]      = top coord of cropping rect                                                    ;;
28
;> [_crop_width]  = width of cropping rect                                                        ;;
111
;> [_crop_width]  = width of cropping rect                                                        ;;
29
;> [_crop_height] = height of cropping rect                                                       ;;
112
;> [_crop_height] = height of cropping rect                                                       ;;
30
;> [_dst]         = pointer to resulting image / 0                                                ;;
113
;> [_dst]         = pointer to resulting image, 0 to create new one                               ;;
-
 
114
;> [_scale]       = scaling method, see libimg.inc (LIBIMG_SCALE_*)                               ;;
-
 
115
;> [_inter]       = interpolation algorithm, see libimg.inc (LIBIMG_INTER_*)                      ;;
-
 
116
;> [_param1]      = depends on _scale, see libimg.inc                                             ;;
-
 
117
;> [_param2]      = depends on _scale, see libimg.inc                                             ;;
-
 
118
;;------------------------------------------------------------------------------------------------;;
-
 
119
;< eax = 0 / pointer to scaled image                                                              ;;
-
 
120
;< ecx = error code / undefined                                                                   ;;
-
 
121
;;================================================================================================;;
-
 
122
        push    ebx esi edi 0 0
-
 
123
        mov     ebx, [_src]
-
 
124
    @@:
-
 
125
        mov     eax, [ebx + Image.Previous]
-
 
126
        test    eax, eax
-
 
127
        jz      .loop
-
 
128
        mov     ebx, eax
-
 
129
        jmp     @b
-
 
130
  .loop:
-
 
131
        stdcall img.scale.layer, ebx, [_crop_x], [_crop_y], [_crop_width], [_crop_height], [_dst], [_scale], [_inter], [_param1], [_param2]
-
 
132
        test    eax, eax
-
 
133
        jz      .error
-
 
134
        cmp     dword[esp + 4], 0
-
 
135
        jnz     @f
-
 
136
        mov     [esp + 4], eax
-
 
137
    @@:
-
 
138
        mov     ecx, [esp]
-
 
139
        jecxz   @f
-
 
140
        mov     [ecx + Image.Next], eax
-
 
141
    @@:
-
 
142
        push    [ebx + Image.Flags]
-
 
143
        pop     [eax + Image.Flags]
-
 
144
        push    [ebx + Image.Delay]
-
 
145
        pop     [eax + Image.Delay]
-
 
146
        mov     [eax + Image.Previous], ecx
-
 
147
        mov     [esp], eax
-
 
148
        mov     ebx, [ebx + Image.Next]
-
 
149
        test    ebx, ebx
-
 
150
        jnz     .loop
-
 
151
  .quit:
-
 
152
        pop     eax eax edi esi ebx
-
 
153
        ret
-
 
154
  .error:
-
 
155
        pop     eax eax edi esi ebx
-
 
156
        ret
-
 
157
endp
-
 
158
 
-
 
159
 
-
 
160
;;================================================================================================;;
-
 
161
proc img.scale.layer _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
-
 
162
;;------------------------------------------------------------------------------------------------;;
-
 
163
;? scale _image layer                                                                             ;;
31
;> [_scale]       = how to change width and height. see libimg.inc                                ;;
164
;;------------------------------------------------------------------------------------------------;;
-
 
165
;> [_src]         = pointer to source image                                                       ;;
-
 
166
;> [_crop_x]      = left coord of cropping rect                                                   ;;
-
 
167
;> [_crop_y]      = top coord of cropping rect                                                    ;;
-
 
168
;> [_crop_width]  = width of cropping rect                                                        ;;
-
 
169
;> [_crop_height] = height of cropping rect                                                       ;;
-
 
170
;> [_dst]         = pointer to resulting image, 0 to create new one                               ;;
-
 
171
;> [_scale]       = scaling method, see libimg.inc (LIBIMG_SCALE_*)                               ;;
32
;> [_inter]       = interpolation algorithm                                                       ;;
172
;> [_inter]       = interpolation algorithm, see libimg.inc (LIBIMG_INTER_*)                      ;;
33
;> [_param1]      = see libimg.inc                                                                ;;
173
;> [_param1]      = depends on _scale, see libimg.inc                                             ;;
34
;> [_param2]      = see libimg.inc                                                                ;;
174
;> [_param2]      = depends on _scale, see libimg.inc                                             ;;
35
;;------------------------------------------------------------------------------------------------;;
175
;;------------------------------------------------------------------------------------------------;;
36
;< eax = 0 / pointer to scaled image                                                              ;;
176
;< eax = 0 / pointer to scaled image                                                              ;;
37
;< ecx = error code / undefined                                                                   ;;
177
;< ecx = error code / undefined                                                                   ;;
38
;;================================================================================================;;
178
;;================================================================================================;;
Line 61... Line 201...
61
	dst_x			rd 1
201
        dst_x           rd 1
62
	dst_y			rd 1
202
        dst_y           rd 1
63
	rem_x			rd 1
203
        rem_x           rd 1
64
	rem_y			rd 1
204
        rem_y           rd 1
65
endl
205
endl
-
 
206
        push    ebx esi edi
66
	mov	ebx, [_src]
207
        mov     ebx, [_src]
67
	push	[ebx + Image.Width]
208
        push    [ebx + Image.Width]
68
	pop	[src_width_pixels]
209
        pop     [src_width_pixels]
69
	push	[ebx + Image.Height]
210
        push    [ebx + Image.Height]
70
	pop	[src_height_pixels]
211
        pop     [src_height_pixels]
Line 125... Line 266...
125
  .scale_type.integer:
266
  .scale_type.integer:
126
	jmp	.integer
267
        jmp     .integer
127
  .scale_type.tile:
268
  .scale_type.tile:
128
	jmp	.tile
269
        jmp     .tile
129
  .scale_type.fit_rect:
270
  .scale_type.fit_rect:
130
	mov	eax, [_param1]
-
 
131
	shl	eax, 16
-
 
132
	add	eax, 0x00008000
-
 
133
	xor	edx, edx
-
 
134
	div	[src_width_pixels]
-
 
135
	mov	ebx, eax
-
 
136
	mov	eax, [_param2]
-
 
137
	shl	eax, 16
-
 
138
	add	eax, 0x00008000
-
 
139
	xor	edx, edx
-
 
140
	div	[src_height_pixels]
-
 
141
	mov	ecx, eax
-
 
142
	cmp	ebx, ecx
-
 
143
	jb	@f
-
 
144
	mov	ebx, ecx
-
 
145
    @@:
-
 
146
	jmp	.scale_type.fit_common
-
 
147
  .scale_type.fit_max:
271
  .scale_type.fit_max:
148
	mov	eax, [_param1]
-
 
149
	shl	eax, 16
-
 
150
	add	eax, 0x00008000
-
 
151
	xor	edx, edx
-
 
152
	div	[src_width_pixels]
-
 
153
	mov	ebx, eax
-
 
154
	mov	eax, [_param2]
-
 
155
	shl	eax, 16
-
 
156
	add	eax, 0x00008000
-
 
157
	xor	edx, edx
-
 
158
	div	[src_height_pixels]
-
 
159
	mov	ecx, eax
-
 
160
	cmp	ebx, ecx
-
 
161
	ja	@f
-
 
162
	mov	ebx, ecx
-
 
163
    @@:
-
 
164
	jmp	.scale_type.fit_common
-
 
165
  .scale_type.fit_width:
272
  .scale_type.fit_width:
166
	mov	eax, [_param1]
-
 
167
	shl	eax, 16
-
 
168
	add	eax, 0x00008000
-
 
169
	xor	edx, edx
-
 
170
	div	[src_width_pixels]
-
 
171
	mov	ebx, eax
-
 
172
	jmp	.scale_type.fit_common
-
 
173
  .scale_type.fit_height:
273
  .scale_type.fit_height:
174
	mov	eax, [_param2]
274
        mov     eax, [_src]
175
	shl	eax, 16
-
 
176
	add	eax, 0x00008000
-
 
177
	xor	edx, edx
-
 
178
	div	[src_height_pixels]
-
 
179
	mov	ebx, eax
-
 
180
	jmp	.scale_type.fit_common
275
        stdcall img.get_scaled_size, [eax + Image.Width], [eax + Image.Height], [_scale], [_param1], [_param2]
181
  .scale_type.fit_common:
-
 
182
	mov	eax, [src_width_pixels]
-
 
183
	mul	ebx
-
 
184
	shr	eax, 16
-
 
185
	mov	[dst_width_pixels], eax
276
        mov     [_param1], eax
186
	imul	eax, [bytes_per_pixel]
-
 
187
	mov	[dst_width_bytes], eax
-
 
188
	mov	eax, [src_height_pixels]
-
 
189
	mul	ebx
-
 
190
	shr	eax, 16
-
 
191
	mov	[dst_height_pixels], eax
277
        mov     [_param2], ecx
192
	jmp	.define_inter
-
 
193
  .scale_type.stretch:
278
  .scale_type.stretch:
194
	mov	eax, [_param1]
279
        mov     eax, [_param1]
195
	mov	[dst_width_pixels], eax
280
        mov     [dst_width_pixels], eax
196
	imul	eax, [bytes_per_pixel]
281
        imul    eax, [bytes_per_pixel]
197
	mov	[dst_width_bytes], eax
282
        mov     [dst_width_bytes], eax
Line 220... Line 305...
220
	jnz	@f
305
        jnz     @f
221
	stdcall	img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
306
        stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
222
	test	eax, eax
307
        test    eax, eax
223
	jz	.error
308
        jz      .error
224
	mov	[_dst], eax
309
        mov     [_dst], eax
-
 
310
        mov     edi, [_src]
-
 
311
        push    [edi + Image.Flags]
-
 
312
        pop     [eax + Image.Flags]
-
 
313
        push    [edi + Image.Delay]
-
 
314
        pop     [eax + Image.Delay]
-
 
315
        push    [edi + Image.Previous]
-
 
316
        pop     [eax + Image.Previous]
-
 
317
        push    [edi + Image.Next]
-
 
318
        pop     [eax + Image.Next]
225
    @@:
319
    @@:
226
	mov	edi, [eax + Image.Data]
320
        mov     edi, [eax + Image.Data]
227
	mov	[dst_data], edi
321
        mov     [dst_data], edi
Line 228... Line 322...
228
 
322
 
Line 378... Line 472...
378
	jnz	@f
472
        jnz @f
379
	stdcall	img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
473
        stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
380
	test	eax, eax
474
        test    eax, eax
381
	jz	.error
475
        jz  .error
382
	mov	[_dst], eax
476
        mov [_dst], eax
-
 
477
        mov     edi, [_src]
-
 
478
        push    [edi + Image.Flags]
-
 
479
        pop     [eax + Image.Flags]
-
 
480
        push    [edi + Image.Delay]
-
 
481
        pop     [eax + Image.Delay]
-
 
482
        push    [edi + Image.Previous]
-
 
483
        pop     [eax + Image.Previous]
-
 
484
        push    [edi + Image.Next]
-
 
485
        pop     [eax + Image.Next]
383
    @@:
486
        @@:
384
	mov	edi, [eax + Image.Data]
487
        mov edi, [eax + Image.Data]
385
	mov	[dst_data], edi
488
        mov [dst_data], edi
Line 386... Line 489...
386
 
489
 
Line 433... Line 536...
433
	jnz	@f
536
        jnz @f
434
	stdcall	img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
537
        stdcall img.create, [dst_width_pixels], [dst_height_pixels], [src_type]
435
	test	eax, eax
538
        test    eax, eax
436
	jz	.error
539
        jz  .error
437
	mov	[_dst], eax
540
        mov [_dst], eax
-
 
541
        mov     edi, [_src]
-
 
542
        push    [edi + Image.Flags]
-
 
543
        pop     [eax + Image.Flags]
-
 
544
        push    [edi + Image.Delay]
-
 
545
        pop     [eax + Image.Delay]
-
 
546
        push    [edi + Image.Previous]
-
 
547
        pop     [eax + Image.Previous]
-
 
548
        push    [edi + Image.Next]
-
 
549
        pop     [eax + Image.Next]
438
    @@:
550
    @@:
439
	mov	edi, [eax + Image.Data]
551
        mov edi, [eax + Image.Data]
440
	mov	[dst_data], edi
552
        mov [dst_data], edi
Line 441... Line 553...
441
 
553
 
Line 703... Line 815...
703
 
815
 
704
 
816
 
705
  .error:
817
  .error:
-
 
818
            xor     eax, eax
706
	xor	eax, eax
819
  .quit:
707
  .quit:
-
 
708
	ret
820
            pop     edi esi ebx