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