near final rescale improvements?
[melted] / src / modules / gtk2 / pixops.c
1 /* GdkPixbuf library - Scaling and compositing functions
2 *
3 * Copyright (C) 1999 The Free Software Foundation
4 *
5 * Author: Owen Taylor <otaylor@redhat.com>
6 * Modified for YUV422 by Dan Dennedy <dan@dennedy.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 #include <math.h>
25 #include <glib.h>
26 #include <stdio.h>
27
28 #include "pixops.h"
29
30 #define SUBSAMPLE_BITS 4
31 #define SUBSAMPLE (1 << SUBSAMPLE_BITS)
32 #define SUBSAMPLE_MASK ((1 << SUBSAMPLE_BITS)-1)
33 #define SCALE_SHIFT 16
34
35 typedef struct _PixopsFilter PixopsFilter;
36 typedef struct _PixopsFilterDimension PixopsFilterDimension;
37
38 struct _PixopsFilterDimension
39 {
40 int n;
41 double offset;
42 double *weights;
43 };
44
45 struct _PixopsFilter
46 {
47 PixopsFilterDimension x;
48 PixopsFilterDimension y;
49 double overall_alpha;
50 };
51
52 typedef guchar *( *PixopsLineFunc ) ( int *weights, int n_x, int n_y,
53 guchar *dest, int dest_x, guchar *dest_end,
54 guchar **src,
55 int x_init, int x_step, int src_width );
56
57 typedef void ( *PixopsPixelFunc ) ( guchar *dest, guint y1, guint cr, guint y2, guint cb );
58
59
60 /* mmx function declarations */
61 #ifdef USE_MMX
62 guchar *pixops_scale_line_22_33_mmx ( guint32 weights[ 16 ][ 8 ], guchar *p, guchar *q1, guchar *q2, int x_step, guchar *p_stop, int x_init );
63 int pixops_have_mmx ( void );
64 #endif
65
66 static inline int
67 get_check_shift ( int check_size )
68 {
69 int check_shift = 0;
70 g_return_val_if_fail ( check_size >= 0, 4 );
71
72 while ( !( check_size & 1 ) )
73 {
74 check_shift++;
75 check_size >>= 1;
76 }
77
78 return check_shift;
79 }
80
81 static inline void
82 pixops_scale_nearest ( guchar *dest_buf,
83 int render_x0,
84 int render_y0,
85 int render_x1,
86 int render_y1,
87 int dest_rowstride,
88 const guchar *src_buf,
89 int src_width,
90 int src_height,
91 int src_rowstride,
92 double scale_x,
93 double scale_y )
94 {
95 register int i, j;
96 register int x;
97 register int x_step = ( 1 << SCALE_SHIFT ) / scale_x;
98 register int y_step = ( 1 << SCALE_SHIFT ) / scale_y;
99
100 for ( i = 0; i < ( render_y1 - render_y0 ); i++ )
101 {
102 const guchar *src = src_buf + ( ( ( i + render_y0 ) * y_step + ( y_step >> 1 ) ) >> SCALE_SHIFT ) * src_rowstride;
103 guchar *dest = dest_buf + i * dest_rowstride;
104
105 x = render_x0 * x_step + ( x_step >> 1 );
106
107 for ( j = 0; j < ( render_x1 - render_x0 ); j++ )
108 {
109 int x_scaled = x >> SCALE_SHIFT;
110 *dest++ = src[ x_scaled << 1 ];
111 *dest++ = src[ ( ( x_scaled >> 1 ) << 2 ) + ( ( j & 1 ) << 1 ) + 1 ];
112 x += x_step;
113 }
114 }
115 }
116
117
118 static inline guchar *
119 scale_line ( int *weights, int n_x, int n_y,
120 guchar *dest, int dest_x, guchar *dest_end,
121 guchar **src,
122 int x_init, int x_step, int src_width )
123 {
124 int x = x_init;
125 register int i, j, dx = 0;
126
127 while ( dest < dest_end )
128 {
129 int x_scaled = x >> SCALE_SHIFT;
130 int *pixel_weights;
131 unsigned int y = 0, uv = 0;
132
133 pixel_weights = weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * n_x * n_y;
134
135 for ( i = 0; i < n_y; i++ )
136 {
137 int *line_weights = pixel_weights + n_x * i;
138 guchar *q = src[ i ];
139
140 for ( j = 0; j < n_x; j ++ )
141 {
142 unsigned int ta = line_weights[ j ];
143
144 y += ta * q[ ( x_scaled << 1 ) ];
145 uv += ta * q[ ( ( x_scaled >> 1 ) << 2 ) + ( ( dx & 1 ) << 1 ) + 1 ];
146 }
147 }
148
149 *dest++ = ( y + 0xffff ) >> SCALE_SHIFT;
150 *dest++ = ( uv + 0xffff ) >> SCALE_SHIFT;
151
152 x += x_step;
153 dx++;
154 }
155
156 return dest;
157 }
158
159 #ifdef USE_MMX
160 static inline guchar *
161 scale_line_22_33_mmx_stub ( int *weights, int n_x, int n_y,
162 guchar *dest, int dest_x, guchar *dest_end,
163 guchar **src,
164 int x_init, int x_step, int src_width )
165 {
166 guint32 mmx_weights[ 16 ][ 8 ];
167 int j;
168
169 for ( j = 0; j < 16; j++ )
170 {
171 mmx_weights[ j ][ 0 ] = 0x00010001 * ( weights[ 4 * j ] >> 8 );
172 mmx_weights[ j ][ 1 ] = 0x00010001 * ( weights[ 4 * j ] >> 8 );
173 mmx_weights[ j ][ 2 ] = 0x00010001 * ( weights[ 4 * j + 1 ] >> 8 );
174 mmx_weights[ j ][ 3 ] = 0x00010001 * ( weights[ 4 * j + 1 ] >> 8 );
175 mmx_weights[ j ][ 4 ] = 0x00010001 * ( weights[ 4 * j + 2 ] >> 8 );
176 mmx_weights[ j ][ 5 ] = 0x00010001 * ( weights[ 4 * j + 2 ] >> 8 );
177 mmx_weights[ j ][ 6 ] = 0x00010001 * ( weights[ 4 * j + 3 ] >> 8 );
178 mmx_weights[ j ][ 7 ] = 0x00010001 * ( weights[ 4 * j + 3 ] >> 8 );
179 }
180
181 return pixops_scale_line_22_33_mmx ( mmx_weights, dest, src[ 0 ], src[ 1 ], x_step, dest_end, x_init );
182 }
183 #endif /* USE_MMX */
184
185 static inline guchar *
186 scale_line_22_33 ( int *weights, int n_x, int n_y,
187 guchar *dest, int dest_x, guchar *dest_end,
188 guchar **src,
189 int x_init, int x_step, int src_width )
190 {
191 int x = x_init;
192 guchar *src0 = src[ 0 ];
193 guchar *src1 = src[ 1 ];
194 int dx = 0;
195
196 while ( dest < dest_end )
197 {
198 unsigned int y, uv;
199 int x_scaled = x >> SCALE_SHIFT;
200 int *pixel_weights;
201 guchar *q0, *q1;
202 int w1, w2, w3, w4;
203 int x_aligned = ( ( x_scaled >> 1 ) << 2 );
204 int uv_index = ( ( dx & 1 ) << 1 ) + 1;
205
206 pixel_weights = weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * 4;
207
208 w1 = pixel_weights[ 0 ];
209 w2 = pixel_weights[ 1 ];
210 w3 = pixel_weights[ 2 ];
211 w4 = pixel_weights[ 3 ];
212
213 q0 = src0 + ( x_scaled << 1 );
214 q1 = src1 + ( x_scaled << 1 );
215
216 y = w1 * q0[ 0 ];
217 y += w2 * q0[ 2 ];
218 y += w3 * q1[ 0 ];
219 y += w4 * q1[ 2 ];
220 *dest++ = ( y + 0x8000 ) >> 16;
221
222 q0 = src0 + x_aligned;
223 q1 = src1 + x_aligned;
224
225 uv = w1 * q0[ uv_index ];
226 uv += w2 * q0[ uv_index ];
227 uv += w3 * q1[ uv_index ];
228 uv += w4 * q1[ uv_index ];
229 *dest++ = ( uv + 0x8000 ) >> 16;
230
231 x += x_step;
232 dx++;
233 }
234
235 return dest;
236 }
237
238
239 static inline void
240 process_pixel ( int *weights, int n_x, int n_y,
241 guchar *dest, int dest_x, int dest_channels,
242 guchar **src, int src_channels,
243 int x_start, int src_width )
244 {
245 register unsigned int y = 0, uv = 0;
246 register int i, j, dx = 0;
247
248 for ( i = 0; i < n_y; i++ )
249 {
250 int *line_weights = weights + n_x * i;
251
252 for ( j = 0; j < n_x; j++ )
253 {
254 unsigned int ta = 0xff * line_weights[ j ];
255
256 if ( x_start + j < 0 )
257 {
258 y += ta * src[ i ][ 0 ];
259 uv += ta * src[ i ][ ( ( dx & 1 ) << 1 ) + 1 ];
260 }
261 else if ( x_start + j < src_width )
262 {
263 y += ta * src[ i ][ ( x_start + j ) << 1 ];
264 uv += ta * src[ i ][ ( ( ( x_start + j ) >> 1 ) << 2) + ( ( dx & 1 ) << 1 ) + 1 ];
265 }
266 else
267 {
268 y += ta * src[ i ][ ( src_width - 1 ) << 1 ];
269 uv += ta * src[ i ][ ( ( ( src_width - 1 ) >> 1 ) << 2) + ( ( dx & 1 ) << 1 ) + 1 ];
270 }
271 }
272 }
273
274 *dest++ = ( y + 0xffffff ) >> 24;
275 *dest++ = ( uv + 0xffffff ) >> 24;
276 dx++;
277 }
278
279
280 static inline void
281 correct_total ( int *weights,
282 int n_x,
283 int n_y,
284 int total,
285 double overall_alpha )
286 {
287 int correction = ( int ) ( 0.5 + 65536 * overall_alpha ) - total;
288 int remaining, c, d, i;
289
290 if ( correction != 0 )
291 {
292 remaining = correction;
293 for ( d = 1, c = correction; c != 0 && remaining != 0; d++, c = correction / d )
294 for ( i = n_x * n_y - 1; i >= 0 && c != 0 && remaining != 0; i-- )
295 if ( *( weights + i ) + c >= 0 )
296 {
297 *( weights + i ) += c;
298 remaining -= c;
299 if ( ( 0 < remaining && remaining < c ) ||
300 ( 0 > remaining && remaining > c ) )
301 c = remaining;
302 }
303 }
304 }
305
306
307 static inline int *
308 make_filter_table ( PixopsFilter *filter )
309 {
310 int i_offset, j_offset;
311 int n_x = filter->x.n;
312 int n_y = filter->y.n;
313 int *weights = g_new ( int, SUBSAMPLE * SUBSAMPLE * n_x * n_y );
314
315 for ( i_offset = 0; i_offset < SUBSAMPLE; i_offset++ )
316 for ( j_offset = 0; j_offset < SUBSAMPLE; j_offset++ )
317 {
318 double weight;
319 int *pixel_weights = weights + ( ( i_offset * SUBSAMPLE ) + j_offset ) * n_x * n_y;
320 int total = 0;
321 int i, j;
322
323 for ( i = 0; i < n_y; i++ )
324 for ( j = 0; j < n_x; j++ )
325 {
326 weight = filter->x.weights[ ( j_offset * n_x ) + j ] *
327 filter->y.weights[ ( i_offset * n_y ) + i ] *
328 filter->overall_alpha * 65536 + 0.5;
329
330 total += ( int ) weight;
331
332 *( pixel_weights + n_x * i + j ) = weight;
333 }
334
335 correct_total ( pixel_weights, n_x, n_y, total, filter->overall_alpha );
336 }
337
338 return weights;
339 }
340
341
342 static inline void
343 pixops_process ( guchar *dest_buf,
344 int render_x0,
345 int render_y0,
346 int render_x1,
347 int render_y1,
348 int dest_rowstride,
349 int dest_channels,
350 gboolean dest_has_alpha,
351 const guchar *src_buf,
352 int src_width,
353 int src_height,
354 int src_rowstride,
355 int src_channels,
356 gboolean src_has_alpha,
357 double scale_x,
358 double scale_y,
359 int check_x,
360 int check_y,
361 int check_size,
362 guint32 color1,
363 guint32 color2,
364 PixopsFilter *filter,
365 PixopsLineFunc line_func )
366 {
367 int i, j;
368 int x, y; /* X and Y position in source (fixed_point) */
369
370 guchar **line_bufs = g_new ( guchar *, filter->y.n );
371 int *filter_weights = make_filter_table ( filter );
372
373 int x_step = ( 1 << SCALE_SHIFT ) / scale_x; /* X step in source (fixed point) */
374 int y_step = ( 1 << SCALE_SHIFT ) / scale_y; /* Y step in source (fixed point) */
375
376 int check_shift = check_size ? get_check_shift ( check_size ) : 0;
377
378 int scaled_x_offset = floor ( filter->x.offset * ( 1 << SCALE_SHIFT ) );
379
380 /* Compute the index where we run off the end of the source buffer. The furthest
381 * source pixel we access at index i is:
382 *
383 * ((render_x0 + i) * x_step + scaled_x_offset) >> SCALE_SHIFT + filter->x.n - 1
384 *
385 * So, run_end_index is the smallest i for which this pixel is src_width, i.e, for which:
386 *
387 * (i + render_x0) * x_step >= ((src_width - filter->x.n + 1) << SCALE_SHIFT) - scaled_x_offset
388 *
389 */
390 #define MYDIV(a,b) ((a) > 0 ? (a) / (b) : ((a) - (b) + 1) / (b)) /* Division so that -1/5 = -1 */
391
392 int run_end_x = ( ( ( src_width - filter->x.n + 1 ) << SCALE_SHIFT ) - scaled_x_offset );
393 int run_end_index = MYDIV ( run_end_x + x_step - 1, x_step ) - render_x0;
394 run_end_index = MIN ( run_end_index, render_x1 - render_x0 );
395
396 y = render_y0 * y_step + floor ( filter->y.offset * ( 1 << SCALE_SHIFT ) );
397 for ( i = 0; i < ( render_y1 - render_y0 ); i++ )
398 {
399 int dest_x;
400 int y_start = y >> SCALE_SHIFT;
401 int x_start;
402 int *run_weights = filter_weights +
403 ( ( y >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) *
404 filter->x.n * filter->y.n * SUBSAMPLE;
405 guchar *new_outbuf;
406 guint32 tcolor1, tcolor2;
407
408 guchar *outbuf = dest_buf + dest_rowstride * i;
409 guchar *outbuf_end = outbuf + dest_channels * ( render_x1 - render_x0 );
410
411 if ( ( ( i + check_y ) >> check_shift ) & 1 )
412 {
413 tcolor1 = color2;
414 tcolor2 = color1;
415 }
416 else
417 {
418 tcolor1 = color1;
419 tcolor2 = color2;
420 }
421
422 for ( j = 0; j < filter->y.n; j++ )
423 {
424 if ( y_start < 0 )
425 line_bufs[ j ] = ( guchar * ) src_buf;
426 else if ( y_start < src_height )
427 line_bufs[ j ] = ( guchar * ) src_buf + src_rowstride * y_start;
428 else
429 line_bufs[ j ] = ( guchar * ) src_buf + src_rowstride * ( src_height - 1 );
430
431 y_start++;
432 }
433
434 dest_x = check_x;
435 x = render_x0 * x_step + scaled_x_offset;
436 x_start = x >> SCALE_SHIFT;
437
438 while ( x_start < 0 && outbuf < outbuf_end )
439 {
440 process_pixel ( run_weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * ( filter->x.n * filter->y.n ),
441 filter->x.n, filter->y.n,
442 outbuf, dest_x, dest_channels,
443 line_bufs, src_channels,
444 x >> SCALE_SHIFT, src_width );
445
446 x += x_step;
447 x_start = x >> SCALE_SHIFT;
448 dest_x++;
449 outbuf += dest_channels;
450
451 process_pixel ( run_weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * ( filter->x.n * filter->y.n ),
452 filter->x.n, filter->y.n,
453 outbuf, dest_x, dest_channels,
454 line_bufs, src_channels,
455 x >> SCALE_SHIFT, src_width );
456
457 x += x_step;
458 x_start = x >> SCALE_SHIFT;
459 dest_x++;
460 outbuf += dest_channels;
461 }
462
463 new_outbuf = ( *line_func ) ( run_weights, filter->x.n, filter->y.n,
464 outbuf, dest_x,
465 dest_buf + dest_rowstride * i + run_end_index * dest_channels,
466 line_bufs,
467 x, x_step, src_width );
468
469 dest_x += ( new_outbuf - outbuf ) / dest_channels;
470
471 x = ( dest_x - check_x + render_x0 ) * x_step + scaled_x_offset;
472 outbuf = new_outbuf;
473
474 while ( outbuf < outbuf_end )
475 {
476 process_pixel ( run_weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * ( filter->x.n * filter->y.n ),
477 filter->x.n, filter->y.n,
478 outbuf, dest_x, dest_channels,
479 line_bufs, src_channels,
480 x >> SCALE_SHIFT, src_width );
481
482 x += x_step;
483 dest_x++;
484 outbuf += dest_channels;
485 }
486
487 y += y_step;
488 }
489
490 g_free ( line_bufs );
491 g_free ( filter_weights );
492 }
493
494
495 /* Compute weights for reconstruction by replication followed by
496 * sampling with a box filter
497 */
498 static inline void
499 tile_make_weights ( PixopsFilterDimension *dim,
500 double scale )
501 {
502 int n = ceil ( 1 / scale + 1 );
503 double *pixel_weights = g_new ( double, SUBSAMPLE * n );
504 int offset;
505 int i;
506
507 dim->n = n;
508 dim->offset = 0;
509 dim->weights = pixel_weights;
510
511 for ( offset = 0; offset < SUBSAMPLE; offset++ )
512 {
513 double x = ( double ) offset / SUBSAMPLE;
514 double a = x + 1 / scale;
515
516 for ( i = 0; i < n; i++ )
517 {
518 if ( i < x )
519 {
520 if ( i + 1 > x )
521 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - x ) * scale;
522 else
523 *( pixel_weights++ ) = 0;
524 }
525 else
526 {
527 if ( a > i )
528 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - i ) * scale;
529 else
530 *( pixel_weights++ ) = 0;
531 }
532 }
533 }
534 }
535
536 /* Compute weights for a filter that, for minification
537 * is the same as 'tiles', and for magnification, is bilinear
538 * reconstruction followed by a sampling with a delta function.
539 */
540 static inline void
541 bilinear_magnify_make_weights ( PixopsFilterDimension *dim,
542 double scale )
543 {
544 double * pixel_weights;
545 int n;
546 int offset;
547 int i;
548
549 if ( scale > 1.0 ) /* Linear */
550 {
551 n = 2;
552 dim->offset = 0.5 * ( 1 / scale - 1 );
553 }
554 else /* Tile */
555 {
556 n = ceil ( 1.0 + 1.0 / scale );
557 dim->offset = 0.0;
558 }
559
560 dim->n = n;
561 dim->weights = g_new ( double, SUBSAMPLE * n );
562
563 pixel_weights = dim->weights;
564
565 for ( offset = 0; offset < SUBSAMPLE; offset++ )
566 {
567 double x = ( double ) offset / SUBSAMPLE;
568
569 if ( scale > 1.0 ) /* Linear */
570 {
571 for ( i = 0; i < n; i++ )
572 *( pixel_weights++ ) = ( ( ( i == 0 ) ? ( 1 - x ) : x ) / scale ) * scale;
573 }
574 else /* Tile */
575 {
576 double a = x + 1 / scale;
577
578 /* x
579 * ---------|--.-|----|--.-|------- SRC
580 * ------------|---------|--------- DEST
581 */
582 for ( i = 0; i < n; i++ )
583 {
584 if ( i < x )
585 {
586 if ( i + 1 > x )
587 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - x ) * scale;
588 else
589 *( pixel_weights++ ) = 0;
590 }
591 else
592 {
593 if ( a > i )
594 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - i ) * scale;
595 else
596 *( pixel_weights++ ) = 0;
597 }
598 }
599 }
600 }
601 }
602
603 /* Computes the integral from b0 to b1 of
604 *
605 * f(x) = x; 0 <= x < 1
606 * f(x) = 0; otherwise
607 *
608 * We combine two of these to compute the convolution of
609 * a box filter with a triangular spike.
610 */
611 static inline double
612 linear_box_half ( double b0, double b1 )
613 {
614 double a0, a1;
615 double x0, x1;
616
617 a0 = 0.;
618 a1 = 1.;
619
620 if ( a0 < b0 )
621 {
622 if ( a1 > b0 )
623 {
624 x0 = b0;
625 x1 = MIN ( a1, b1 );
626 }
627 else
628 return 0;
629 }
630 else
631 {
632 if ( b1 > a0 )
633 {
634 x0 = a0;
635 x1 = MIN ( a1, b1 );
636 }
637 else
638 return 0;
639 }
640
641 return 0.5 * ( x1 * x1 - x0 * x0 );
642 }
643
644 /* Compute weights for reconstructing with bilinear
645 * interpolation, then sampling with a box filter
646 */
647 static inline void
648 bilinear_box_make_weights ( PixopsFilterDimension *dim,
649 double scale )
650 {
651 int n = ceil ( 1 / scale + 2.0 );
652 double *pixel_weights = g_new ( double, SUBSAMPLE * n );
653 double w;
654 int offset, i;
655
656 dim->offset = -1.0;
657 dim->n = n;
658 dim->weights = pixel_weights;
659
660 for ( offset = 0 ; offset < SUBSAMPLE; offset++ )
661 {
662 double x = ( double ) offset / SUBSAMPLE;
663 double a = x + 1 / scale;
664
665 for ( i = 0; i < n; i++ )
666 {
667 w = linear_box_half ( 0.5 + i - a, 0.5 + i - x );
668 w += linear_box_half ( 1.5 + x - i, 1.5 + a - i );
669
670 *( pixel_weights++ ) = w * scale;
671 }
672 }
673 }
674
675
676 static inline void
677 make_weights ( PixopsFilter *filter,
678 PixopsInterpType interp_type,
679 double scale_x,
680 double scale_y )
681 {
682 switch ( interp_type )
683 {
684 case PIXOPS_INTERP_NEAREST:
685 g_assert_not_reached ();
686 break;
687
688 case PIXOPS_INTERP_TILES:
689 tile_make_weights ( &filter->x, scale_x );
690 tile_make_weights ( &filter->y, scale_y );
691 break;
692
693 case PIXOPS_INTERP_BILINEAR:
694 bilinear_magnify_make_weights ( &filter->x, scale_x );
695 bilinear_magnify_make_weights ( &filter->y, scale_y );
696 break;
697
698 case PIXOPS_INTERP_HYPER:
699 bilinear_box_make_weights ( &filter->x, scale_x );
700 bilinear_box_make_weights ( &filter->y, scale_y );
701 break;
702 }
703 }
704
705
706 void
707 yuv422_scale ( guchar *dest_buf,
708 int render_x0,
709 int render_y0,
710 int render_x1,
711 int render_y1,
712 int dest_rowstride,
713 int dest_channels,
714 gboolean dest_has_alpha,
715 const guchar *src_buf,
716 int src_width,
717 int src_height,
718 int src_rowstride,
719 int src_channels,
720 gboolean src_has_alpha,
721 double scale_x,
722 double scale_y,
723 PixopsInterpType interp_type )
724 {
725 PixopsFilter filter;
726 PixopsLineFunc line_func;
727
728 #ifdef USE_MMX
729 gboolean found_mmx = pixops_have_mmx();
730 #endif
731
732 //g_return_if_fail ( !( dest_channels == 3 && dest_has_alpha ) );
733 //g_return_if_fail ( !( src_channels == 3 && src_has_alpha ) );
734 //g_return_if_fail ( !( src_has_alpha && !dest_has_alpha ) );
735
736 if ( scale_x == 0 || scale_y == 0 )
737 return ;
738
739 if ( interp_type == PIXOPS_INTERP_NEAREST )
740 {
741 pixops_scale_nearest ( dest_buf, render_x0, render_y0, render_x1, render_y1,
742 dest_rowstride,
743 src_buf, src_width, src_height, src_rowstride,
744 scale_x, scale_y );
745 return;
746 }
747
748 filter.overall_alpha = 1.0;
749 make_weights ( &filter, interp_type, scale_x, scale_y );
750
751 //fprintf( stderr, "RESCALE: %d %d\n", filter.x.n, filter.y.n );
752 if ( filter.x.n == 2 && filter.y.n == 2 )
753 {
754 #ifdef USE_MMX
755 if ( 0 && found_mmx )
756 line_func = scale_line_22_33_mmx_stub;
757 else
758 #endif
759
760 line_func = scale_line_22_33;
761 }
762 else
763 line_func = scale_line;
764
765 pixops_process ( dest_buf, render_x0, render_y0, render_x1, render_y1,
766 dest_rowstride, dest_channels, dest_has_alpha,
767 src_buf, src_width, src_height, src_rowstride, src_channels,
768 src_has_alpha, scale_x, scale_y, 0, 0, 0, 0, 0,
769 &filter, line_func );
770
771 g_free ( filter.x.weights );
772 g_free ( filter.y.weights );
773 }
774