interim 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;
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 ) + ( ( j & 1 ) << 1 ) + 1 ];
146 }
147 }
148
149 *dest++ = ( y + 0xffff ) >> SCALE_SHIFT;
150 *dest++ = ( uv + 0xffff ) >> SCALE_SHIFT;
151
152 x += x_step;
153 }
154
155 return dest;
156 }
157
158 #ifdef USE_MMX
159 static inline guchar *
160 scale_line_22_33_mmx_stub ( int *weights, int n_x, int n_y,
161 guchar *dest, int dest_x, guchar *dest_end,
162 guchar **src,
163 int x_init, int x_step, int src_width )
164 {
165 guint32 mmx_weights[ 16 ][ 8 ];
166 int j;
167
168 for ( j = 0; j < 16; j++ )
169 {
170 mmx_weights[ j ][ 0 ] = 0x00010001 * ( weights[ 4 * j ] >> 8 );
171 mmx_weights[ j ][ 1 ] = 0x00010001 * ( weights[ 4 * j ] >> 8 );
172 mmx_weights[ j ][ 2 ] = 0x00010001 * ( weights[ 4 * j + 1 ] >> 8 );
173 mmx_weights[ j ][ 3 ] = 0x00010001 * ( weights[ 4 * j + 1 ] >> 8 );
174 mmx_weights[ j ][ 4 ] = 0x00010001 * ( weights[ 4 * j + 2 ] >> 8 );
175 mmx_weights[ j ][ 5 ] = 0x00010001 * ( weights[ 4 * j + 2 ] >> 8 );
176 mmx_weights[ j ][ 6 ] = 0x00010001 * ( weights[ 4 * j + 3 ] >> 8 );
177 mmx_weights[ j ][ 7 ] = 0x00010001 * ( weights[ 4 * j + 3 ] >> 8 );
178 }
179
180 return pixops_scale_line_22_33_mmx ( mmx_weights, dest, src[ 0 ], src[ 1 ], x_step, dest_end, x_init );
181 }
182 #endif /* USE_MMX */
183
184 static inline guchar *
185 scale_line_22_33 ( int *weights, int n_x, int n_y,
186 guchar *dest, int dest_x, guchar *dest_end,
187 guchar **src,
188 int x_init, int x_step, int src_width )
189 {
190 int x = x_init;
191 guchar *src0 = src[ 0 ];
192 guchar *src1 = src[ 1 ];
193
194 while ( dest < dest_end )
195 {
196 unsigned int y, uv;
197 int x_scaled = x >> SCALE_SHIFT;
198 int *pixel_weights;
199 guchar *q0, *q1;
200 int w1, w2, w3, w4;
201 int x_aligned = ( ( x_scaled >> 1 ) << 2 );
202 int uv_index = ( ( x_scaled & 1 ) << 1 ) + 1;
203
204 // fprintf( stderr, "%d %d | ", x_scaled, x_aligned );
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 // *dest++ = ( q0[ 0 ] + q0[ 2 ] + q1[ 0 ] + q1[ 2 ] ) >> 2;
222
223 q0 = src0 + x_aligned;
224 q1 = src1 + x_aligned;
225
226 uv = w1 * q0[ uv_index ];
227 uv += w2 * q0[ uv_index ];
228 uv += w3 * q1[ uv_index ];
229 uv += w4 * q1[ uv_index ];
230 *dest++ = ( uv + 0x8000 ) >> 16;
231 // *dest++ = ( q0[ uv_index ] + q1[ uv_index ] ) >> 1;
232 // *dest++ = 128;
233
234 x += x_step;
235 }
236
237 return dest;
238 }
239
240
241 static inline void
242 process_pixel ( int *weights, int n_x, int n_y,
243 guchar *dest, int dest_x, int dest_channels,
244 guchar **src, int src_channels,
245 int x_start, int src_width )
246 {
247 unsigned int y = 0, uv = 0;
248 int i, j;
249
250 for ( i = 0; i < n_y; i++ )
251 {
252 int *line_weights = weights + n_x * i;
253
254 for ( j = 0; j < n_x; j++ )
255 {
256 unsigned int ta = 0xff * line_weights[ j ];
257
258 if ( x_start + j < 0 )
259 {
260 y += ta * src[ i ][ 0 ];
261 uv += ta * src[ i ][ ( ( j & 1 ) << 1 ) + 1 ];
262 }
263 else if ( x_start + j < src_width )
264 {
265 y += ta * src[ i ][ ( x_start + j ) << 1 ];
266 uv += ta * src[ i ][ ( ( ( x_start + j ) >> 1 ) << 2) + ( ( j & 1 ) << 1 ) + 1 ];
267 }
268 else
269 {
270 y += ta * src[ i ][ ( src_width - 1 ) << 1 ];
271 uv += ta * src[ i ][ ( ( ( src_width - 1 ) >> 1 ) << 2) + ( ( j & 1 ) << 1 ) + 1 ];
272 }
273 }
274 }
275
276 *dest++ = ( y + 0xffffff ) >> 24;
277 *dest++ = ( uv + 0xffffff ) >> 24;
278 }
279
280
281 static inline void
282 correct_total ( int *weights,
283 int n_x,
284 int n_y,
285 int total,
286 double overall_alpha )
287 {
288 int correction = ( int ) ( 0.5 + 65536 * overall_alpha ) - total;
289 int remaining, c, d, i;
290
291 if ( correction != 0 )
292 {
293 remaining = correction;
294 for ( d = 1, c = correction; c != 0 && remaining != 0; d++, c = correction / d )
295 for ( i = n_x * n_y - 1; i >= 0 && c != 0 && remaining != 0; i-- )
296 if ( *( weights + i ) + c >= 0 )
297 {
298 *( weights + i ) += c;
299 remaining -= c;
300 if ( ( 0 < remaining && remaining < c ) ||
301 ( 0 > remaining && remaining > c ) )
302 c = remaining;
303 }
304 }
305 }
306
307
308 static inline int *
309 make_filter_table ( PixopsFilter *filter )
310 {
311 int i_offset, j_offset;
312 int n_x = filter->x.n;
313 int n_y = filter->y.n;
314 int *weights = g_new ( int, SUBSAMPLE * SUBSAMPLE * n_x * n_y );
315
316 for ( i_offset = 0; i_offset < SUBSAMPLE; i_offset++ )
317 for ( j_offset = 0; j_offset < SUBSAMPLE; j_offset++ )
318 {
319 double weight;
320 int *pixel_weights = weights + ( ( i_offset * SUBSAMPLE ) + j_offset ) * n_x * n_y;
321 int total = 0;
322 int i, j;
323
324 for ( i = 0; i < n_y; i++ )
325 for ( j = 0; j < n_x; j++ )
326 {
327 weight = filter->x.weights[ ( j_offset * n_x ) + j ] *
328 filter->y.weights[ ( i_offset * n_y ) + i ] *
329 filter->overall_alpha * 65536 + 0.5;
330
331 total += ( int ) weight;
332
333 *( pixel_weights + n_x * i + j ) = weight;
334 }
335
336 correct_total ( pixel_weights, n_x, n_y, total, filter->overall_alpha );
337 }
338
339 return weights;
340 }
341
342
343 static inline void
344 pixops_process ( guchar *dest_buf,
345 int render_x0,
346 int render_y0,
347 int render_x1,
348 int render_y1,
349 int dest_rowstride,
350 int dest_channels,
351 gboolean dest_has_alpha,
352 const guchar *src_buf,
353 int src_width,
354 int src_height,
355 int src_rowstride,
356 int src_channels,
357 gboolean src_has_alpha,
358 double scale_x,
359 double scale_y,
360 int check_x,
361 int check_y,
362 int check_size,
363 guint32 color1,
364 guint32 color2,
365 PixopsFilter *filter,
366 PixopsLineFunc line_func )
367 {
368 int i, j;
369 int x, y; /* X and Y position in source (fixed_point) */
370
371 guchar **line_bufs = g_new ( guchar *, filter->y.n );
372 int *filter_weights = make_filter_table ( filter );
373
374 int x_step = ( 1 << SCALE_SHIFT ) / scale_x; /* X step in source (fixed point) */
375 int y_step = ( 1 << SCALE_SHIFT ) / scale_y; /* Y step in source (fixed point) */
376
377 int check_shift = check_size ? get_check_shift ( check_size ) : 0;
378
379 int scaled_x_offset = floor ( filter->x.offset * ( 1 << SCALE_SHIFT ) );
380
381 /* Compute the index where we run off the end of the source buffer. The furthest
382 * source pixel we access at index i is:
383 *
384 * ((render_x0 + i) * x_step + scaled_x_offset) >> SCALE_SHIFT + filter->x.n - 1
385 *
386 * So, run_end_index is the smallest i for which this pixel is src_width, i.e, for which:
387 *
388 * (i + render_x0) * x_step >= ((src_width - filter->x.n + 1) << SCALE_SHIFT) - scaled_x_offset
389 *
390 */
391 #define MYDIV(a,b) ((a) > 0 ? (a) / (b) : ((a) - (b) + 1) / (b)) /* Division so that -1/5 = -1 */
392
393 int run_end_x = ( ( ( src_width - filter->x.n + 1 ) << SCALE_SHIFT ) - scaled_x_offset );
394 int run_end_index = MYDIV ( run_end_x + x_step - 1, x_step ) - render_x0;
395 run_end_index = MIN ( run_end_index, render_x1 - render_x0 );
396
397 y = render_y0 * y_step + floor ( filter->y.offset * ( 1 << SCALE_SHIFT ) );
398 for ( i = 0; i < ( render_y1 - render_y0 ); i++ )
399 {
400 int dest_x;
401 int y_start = y >> SCALE_SHIFT;
402 int x_start;
403 int *run_weights = filter_weights +
404 ( ( y >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) *
405 filter->x.n * filter->y.n * SUBSAMPLE;
406 guchar *new_outbuf;
407 guint32 tcolor1, tcolor2;
408
409 guchar *outbuf = dest_buf + dest_rowstride * i;
410 guchar *outbuf_end = outbuf + dest_channels * ( render_x1 - render_x0 );
411
412 if ( ( ( i + check_y ) >> check_shift ) & 1 )
413 {
414 tcolor1 = color2;
415 tcolor2 = color1;
416 }
417 else
418 {
419 tcolor1 = color1;
420 tcolor2 = color2;
421 }
422
423 for ( j = 0; j < filter->y.n; j++ )
424 {
425 if ( y_start < 0 )
426 line_bufs[ j ] = ( guchar * ) src_buf;
427 else if ( y_start < src_height )
428 line_bufs[ j ] = ( guchar * ) src_buf + src_rowstride * y_start;
429 else
430 line_bufs[ j ] = ( guchar * ) src_buf + src_rowstride * ( src_height - 1 );
431
432 y_start++;
433 }
434
435 dest_x = check_x;
436 x = render_x0 * x_step + scaled_x_offset;
437 x_start = x >> SCALE_SHIFT;
438
439 while ( 0 && x_start < 0 && outbuf < outbuf_end )
440 {
441 process_pixel ( run_weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * ( filter->x.n * filter->y.n ),
442 filter->x.n, filter->y.n,
443 outbuf, dest_x, dest_channels,
444 line_bufs, src_channels,
445 x >> SCALE_SHIFT, src_width );
446
447 x += x_step;
448 x_start = x >> SCALE_SHIFT;
449 dest_x++;
450 outbuf += dest_channels;
451 }
452 run_end_index = 720;
453
454 new_outbuf = ( *line_func ) ( run_weights, filter->x.n, filter->y.n,
455 outbuf, dest_x,
456 dest_buf + dest_rowstride * i + run_end_index * dest_channels,
457 line_bufs,
458 x, x_step, src_width );
459
460 dest_x += ( new_outbuf - outbuf ) / dest_channels;
461
462 x = ( dest_x - check_x + render_x0 ) * x_step + scaled_x_offset;
463 outbuf = new_outbuf;
464
465 while ( 0 && outbuf < outbuf_end )
466 {
467 process_pixel ( run_weights + ( ( x >> ( SCALE_SHIFT - SUBSAMPLE_BITS ) ) & SUBSAMPLE_MASK ) * ( filter->x.n * filter->y.n ),
468 filter->x.n, filter->y.n,
469 outbuf, dest_x, dest_channels,
470 line_bufs, src_channels,
471 x >> SCALE_SHIFT, src_width );
472
473 x += x_step;
474 dest_x++;
475 outbuf += dest_channels;
476 }
477
478 y += y_step;
479 }
480
481 g_free ( line_bufs );
482 g_free ( filter_weights );
483 }
484
485
486 /* Compute weights for reconstruction by replication followed by
487 * sampling with a box filter
488 */
489 static inline void
490 tile_make_weights ( PixopsFilterDimension *dim,
491 double scale )
492 {
493 int n = ceil ( 1 / scale + 1 );
494 double *pixel_weights = g_new ( double, SUBSAMPLE * n );
495 int offset;
496 int i;
497
498 dim->n = n;
499 dim->offset = 0;
500 dim->weights = pixel_weights;
501
502 for ( offset = 0; offset < SUBSAMPLE; offset++ )
503 {
504 double x = ( double ) offset / SUBSAMPLE;
505 double a = x + 1 / scale;
506
507 for ( i = 0; i < n; i++ )
508 {
509 if ( i < x )
510 {
511 if ( i + 1 > x )
512 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - x ) * scale;
513 else
514 *( pixel_weights++ ) = 0;
515 }
516 else
517 {
518 if ( a > i )
519 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - i ) * scale;
520 else
521 *( pixel_weights++ ) = 0;
522 }
523 }
524 }
525 }
526
527 /* Compute weights for a filter that, for minification
528 * is the same as 'tiles', and for magnification, is bilinear
529 * reconstruction followed by a sampling with a delta function.
530 */
531 static inline void
532 bilinear_magnify_make_weights ( PixopsFilterDimension *dim,
533 double scale )
534 {
535 double * pixel_weights;
536 int n;
537 int offset;
538 int i;
539
540 if ( scale > 1.0 ) /* Linear */
541 {
542 n = 2;
543 dim->offset = 0.5 * ( 1 / scale - 1 );
544 }
545 else /* Tile */
546 {
547 n = ceil ( 1.0 + 1.0 / scale );
548 dim->offset = 0.0;
549 }
550
551 dim->n = n;
552 dim->weights = g_new ( double, SUBSAMPLE * n );
553
554 pixel_weights = dim->weights;
555
556 for ( offset = 0; offset < SUBSAMPLE; offset++ )
557 {
558 double x = ( double ) offset / SUBSAMPLE;
559
560 if ( scale > 1.0 ) /* Linear */
561 {
562 for ( i = 0; i < n; i++ )
563 *( pixel_weights++ ) = ( ( ( i == 0 ) ? ( 1 - x ) : x ) / scale ) * scale;
564 }
565 else /* Tile */
566 {
567 double a = x + 1 / scale;
568
569 /* x
570 * ---------|--.-|----|--.-|------- SRC
571 * ------------|---------|--------- DEST
572 */
573 for ( i = 0; i < n; i++ )
574 {
575 if ( i < x )
576 {
577 if ( i + 1 > x )
578 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - x ) * scale;
579 else
580 *( pixel_weights++ ) = 0;
581 }
582 else
583 {
584 if ( a > i )
585 * ( pixel_weights++ ) = ( MIN ( i + 1, a ) - i ) * scale;
586 else
587 *( pixel_weights++ ) = 0;
588 }
589 }
590 }
591 }
592 }
593
594 /* Computes the integral from b0 to b1 of
595 *
596 * f(x) = x; 0 <= x < 1
597 * f(x) = 0; otherwise
598 *
599 * We combine two of these to compute the convolution of
600 * a box filter with a triangular spike.
601 */
602 static inline double
603 linear_box_half ( double b0, double b1 )
604 {
605 double a0, a1;
606 double x0, x1;
607
608 a0 = 0.;
609 a1 = 1.;
610
611 if ( a0 < b0 )
612 {
613 if ( a1 > b0 )
614 {
615 x0 = b0;
616 x1 = MIN ( a1, b1 );
617 }
618 else
619 return 0;
620 }
621 else
622 {
623 if ( b1 > a0 )
624 {
625 x0 = a0;
626 x1 = MIN ( a1, b1 );
627 }
628 else
629 return 0;
630 }
631
632 return 0.5 * ( x1 * x1 - x0 * x0 );
633 }
634
635 /* Compute weights for reconstructing with bilinear
636 * interpolation, then sampling with a box filter
637 */
638 static inline void
639 bilinear_box_make_weights ( PixopsFilterDimension *dim,
640 double scale )
641 {
642 int n = ceil ( 1 / scale + 2.0 );
643 double *pixel_weights = g_new ( double, SUBSAMPLE * n );
644 double w;
645 int offset, i;
646
647 dim->offset = -1.0;
648 dim->n = n;
649 dim->weights = pixel_weights;
650
651 for ( offset = 0 ; offset < SUBSAMPLE; offset++ )
652 {
653 double x = ( double ) offset / SUBSAMPLE;
654 double a = x + 1 / scale;
655
656 for ( i = 0; i < n; i++ )
657 {
658 w = linear_box_half ( 0.5 + i - a, 0.5 + i - x );
659 w += linear_box_half ( 1.5 + x - i, 1.5 + a - i );
660
661 *( pixel_weights++ ) = w * scale;
662 }
663 }
664 }
665
666
667 static inline void
668 make_weights ( PixopsFilter *filter,
669 PixopsInterpType interp_type,
670 double scale_x,
671 double scale_y )
672 {
673 switch ( interp_type )
674 {
675 case PIXOPS_INTERP_NEAREST:
676 g_assert_not_reached ();
677 break;
678
679 case PIXOPS_INTERP_TILES:
680 tile_make_weights ( &filter->x, scale_x );
681 tile_make_weights ( &filter->y, scale_y );
682 break;
683
684 case PIXOPS_INTERP_BILINEAR:
685 bilinear_magnify_make_weights ( &filter->x, scale_x );
686 bilinear_magnify_make_weights ( &filter->y, scale_y );
687 break;
688
689 case PIXOPS_INTERP_HYPER:
690 bilinear_box_make_weights ( &filter->x, scale_x );
691 bilinear_box_make_weights ( &filter->y, scale_y );
692 break;
693 }
694 }
695
696
697 void
698 yuv422_scale ( guchar *dest_buf,
699 int render_x0,
700 int render_y0,
701 int render_x1,
702 int render_y1,
703 int dest_rowstride,
704 int dest_channels,
705 gboolean dest_has_alpha,
706 const guchar *src_buf,
707 int src_width,
708 int src_height,
709 int src_rowstride,
710 int src_channels,
711 gboolean src_has_alpha,
712 double scale_x,
713 double scale_y,
714 PixopsInterpType interp_type )
715 {
716 PixopsFilter filter;
717 PixopsLineFunc line_func;
718
719 #ifdef USE_MMX
720 gboolean found_mmx = pixops_have_mmx();
721 #endif
722
723 //g_return_if_fail ( !( dest_channels == 3 && dest_has_alpha ) );
724 //g_return_if_fail ( !( src_channels == 3 && src_has_alpha ) );
725 //g_return_if_fail ( !( src_has_alpha && !dest_has_alpha ) );
726
727 if ( scale_x == 0 || scale_y == 0 )
728 return ;
729
730 if ( interp_type == PIXOPS_INTERP_NEAREST )
731 {
732 pixops_scale_nearest ( dest_buf, render_x0, render_y0, render_x1, render_y1,
733 dest_rowstride,
734 src_buf, src_width, src_height, src_rowstride,
735 scale_x, scale_y );
736 return;
737 }
738
739 filter.overall_alpha = 1.0;
740 make_weights ( &filter, interp_type, scale_x, scale_y );
741
742 fprintf( stderr, "RESCALE: %d %d\n", filter.x.n, filter.y.n );
743 if ( filter.x.n == 2 && filter.y.n == 2 )
744 {
745 #ifdef USE_MMX
746 if ( 0 && found_mmx )
747 line_func = scale_line_22_33_mmx_stub;
748 else
749 #endif
750
751 line_func = scale_line_22_33;
752 }
753 else
754 line_func = scale_line;
755
756 pixops_process ( dest_buf, render_x0, render_y0, render_x1, render_y1,
757 dest_rowstride, dest_channels, dest_has_alpha,
758 src_buf, src_width, src_height, src_rowstride, src_channels,
759 src_has_alpha, scale_x, scale_y, 0, 0, 0, 0, 0,
760 &filter, line_func );
761
762 g_free ( filter.x.weights );
763 g_free ( filter.y.weights );
764 }
765