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