]> git.sesse.net Git - vlc/blob - modules/video_filter/extract.c
convert a few printfs to msg_Dbg.
[vlc] / modules / video_filter / extract.c
1 /*****************************************************************************
2  * extract.c : Extract RGB components
3  *****************************************************************************
4  * Copyright (C) 2000-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea .t videolan d@t org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc_vout.h>
32
33 #include "vlc_filter.h"
34
35 #include "math.h"
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40 static int  Create      ( vlc_object_t * );
41 static void Destroy     ( vlc_object_t * );
42
43 static picture_t *Filter( filter_t *, picture_t * );
44 static int ExtractCallback( vlc_object_t *, char const *,
45                             vlc_value_t, vlc_value_t, void * );
46
47 static void get_red_from_yuv420( picture_t *, picture_t *, int, int, int );
48 static void get_green_from_yuv420( picture_t *, picture_t *, int, int, int );
49 static void get_blue_from_yuv420( picture_t *, picture_t *, int, int, int );
50 static void get_red_from_yuv422( picture_t *, picture_t *, int, int, int );
51 static void get_green_from_yuv422( picture_t *, picture_t *, int, int, int );
52 static void get_blue_from_yuv422( picture_t *, picture_t *, int, int, int );
53 static void make_projection_matrix( filter_t *, int color, int *matrix );
54 static void get_custom_from_yuv420( picture_t *, picture_t *, int, int, int, int * );
55 static void get_custom_from_yuv422( picture_t *, picture_t *, int, int, int, int * );
56
57
58 #define COMPONENT_TEXT N_("RGB component to extract")
59 #define COMPONENT_LONGTEXT N_("RGB component to extract. 0 for Red, 1 for Green and 2 for Blue.")
60 #define FILTER_PREFIX "extract-"
61
62 static int pi_component_values[] = { 0xFF0000, 0x00FF00, 0x0000FF };
63 static const char *ppsz_component_descriptions[] = { "Red", "Green", "Blue" };
64
65 /*****************************************************************************
66  * Module descriptor
67  *****************************************************************************/
68 vlc_module_begin();
69     set_description( _("Extract RGB component video filter") );
70     set_shortname( _("Extract" ));
71     set_category( CAT_VIDEO );
72     set_subcategory( SUBCAT_VIDEO_VFILTER );
73     set_capability( "video filter2", 0 );
74     add_shortcut( "extract" );
75
76     add_integer_with_range( FILTER_PREFIX "component", 0xFF0000, 1, 0xFFFFFF,
77                  NULL, COMPONENT_TEXT, COMPONENT_LONGTEXT, VLC_FALSE );
78         change_integer_list( pi_component_values, ppsz_component_descriptions, 0 );
79
80     set_callbacks( Create, Destroy );
81 vlc_module_end();
82
83 static const char *ppsz_filter_options[] = {
84     "component", NULL
85 };
86
87 enum { RED=0xFF0000, GREEN=0x00FF00, BLUE=0x0000FF };
88 struct filter_sys_t
89 {
90     int i_color;
91     int *projection_matrix;
92 };
93
94 /*****************************************************************************
95  * Create
96  *****************************************************************************/
97 static int Create( vlc_object_t *p_this )
98 {
99     filter_t *p_filter = (filter_t *)p_this;
100
101     /* Allocate structure */
102     p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
103     if( p_filter->p_sys == NULL )
104     {
105         msg_Err( p_filter, "out of memory" );
106         return VLC_ENOMEM;
107     }
108     p_filter->p_sys->projection_matrix = malloc( 9 * sizeof( int ) );
109     if( !p_filter->p_sys->projection_matrix )
110     {
111         free( p_filter->p_sys );
112         msg_Err( p_filter, "out of memory" );
113         return VLC_ENOMEM;
114     }
115
116     config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options,
117                        p_filter->p_cfg );
118
119     p_filter->p_sys->i_color = var_CreateGetIntegerCommand( p_filter,
120                                                FILTER_PREFIX "component" );
121     var_AddCallback( p_filter, FILTER_PREFIX "component",
122                      ExtractCallback, p_filter->p_sys );
123     switch( p_filter->p_sys->i_color )
124     {
125         case RED:
126         case GREEN:
127         case BLUE:
128             break;
129         default:
130             make_projection_matrix( p_filter, p_filter->p_sys->i_color,
131                                     p_filter->p_sys->projection_matrix );
132             break;
133     }
134
135     p_filter->pf_video_filter = Filter;
136
137     return VLC_SUCCESS;
138 }
139
140 /*****************************************************************************
141  * Destroy
142  *****************************************************************************/
143 static void Destroy( vlc_object_t *p_this )
144 {
145     filter_t *p_filter = (filter_t *)p_this;
146
147     free( p_filter->p_sys->projection_matrix );
148     free( p_filter->p_sys );
149 }
150
151 /*****************************************************************************
152  * Render
153  *****************************************************************************/
154 static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
155 {
156     picture_t *p_outpic;
157
158     if( !p_pic ) return NULL;
159
160     p_outpic = p_filter->pf_vout_buffer_new( p_filter );
161     if( !p_outpic )
162     {
163         msg_Warn( p_filter, "can't get output picture" );
164         if( p_pic->pf_release )
165             p_pic->pf_release( p_pic );
166         return NULL;
167     }
168
169     switch( p_pic->format.i_chroma )
170     {
171         case VLC_FOURCC('I','4','2','0'):
172         case VLC_FOURCC('I','Y','U','V'):
173         case VLC_FOURCC('J','4','2','0'):
174         case VLC_FOURCC('Y','V','1','2'):
175             switch( p_filter->p_sys->i_color )
176             {
177                 case RED:
178                     get_red_from_yuv420( p_pic, p_outpic,
179                                          Y_PLANE, U_PLANE, V_PLANE );
180                     break;
181                 case GREEN:
182                     get_green_from_yuv420( p_pic, p_outpic,
183                                            Y_PLANE, U_PLANE, V_PLANE );
184                     break;
185                 case BLUE:
186                     get_blue_from_yuv420( p_pic, p_outpic,
187                                           Y_PLANE, U_PLANE, V_PLANE );
188                     break;
189                 default:
190                     get_custom_from_yuv420( p_pic, p_outpic,
191                                             Y_PLANE, U_PLANE, V_PLANE,
192                                             p_filter->p_sys->projection_matrix);
193                     break;
194             }
195             break;
196
197         case VLC_FOURCC('I','4','2','2'):
198         case VLC_FOURCC('J','4','2','2'):
199             switch( p_filter->p_sys->i_color )
200             {
201                 case RED:
202                     get_red_from_yuv422( p_pic, p_outpic,
203                                          Y_PLANE, U_PLANE, V_PLANE );
204                     break;
205                 case GREEN:
206                     get_green_from_yuv422( p_pic, p_outpic,
207                                            Y_PLANE, U_PLANE, V_PLANE );
208                     break;
209                 case BLUE:
210                     get_blue_from_yuv422( p_pic, p_outpic,
211                                           Y_PLANE, U_PLANE, V_PLANE );
212                     break;
213                 default:
214                     get_custom_from_yuv422( p_pic, p_outpic,
215                                             Y_PLANE, U_PLANE, V_PLANE,
216                                             p_filter->p_sys->projection_matrix);
217                     break;
218             }
219             break;
220
221         default:
222             msg_Warn( p_filter, "Unsupported input chroma (%4s)",
223                       (char*)&(p_pic->format.i_chroma) );
224             if( p_pic->pf_release )
225                 p_pic->pf_release( p_pic );
226             return NULL;
227     }
228
229     p_outpic->date = p_pic->date;
230     p_outpic->b_force = p_pic->b_force;
231     p_outpic->i_nb_fields = p_pic->i_nb_fields;
232     p_outpic->b_progressive = p_pic->b_progressive;
233     p_outpic->b_top_field_first = p_pic->b_top_field_first;
234
235     if( p_pic->pf_release )
236         p_pic->pf_release( p_pic );
237
238     return p_outpic;
239 }
240
241 inline uint8_t crop( int a );
242 inline uint8_t crop( int a )
243 {
244     if( a < 0 ) return 0;
245     if( a > 255 ) return 255;
246     else return (uint8_t)a;
247 }
248
249 #define U 128
250 #define V 128
251
252 static void mmult( double *res, double *a, double *b )
253 {
254     int i, j, k;
255     for( i = 0; i < 3; i++ )
256     {
257         for( j = 0; j < 3; j++ )
258         {
259             res[ i*3 + j ] = 0.;
260             for( k = 0; k < 3; k++ )
261             {
262                 res[ i*3 + j ] += a[ i*3 + k ] * b[ k*3 + j ];
263             }
264         }
265     }
266 }
267 static void make_projection_matrix( filter_t *p_filter, int color, int *matrix )
268 {
269     double left_matrix[9] =
270         {  76.24500,  149.68500,  29.07000,
271           -43.02765,  -84.47235, 127.50000,
272           127.50000, -106.76534, -20.73466 };
273     double right_matrix[9] =
274         { 257.00392,   0.00000,  360.31950,
275           257.00392, -88.44438, -183.53583,
276           257.00392, 455.41095,    0.00000 };
277     double red = ((double)(( 0xFF0000 & color )>>16))/255.;
278     double green = ((double)(( 0x00FF00 & color )>>8))/255.;
279     double blue = ((double)( 0x0000FF & color ))/255.;
280     double norm = sqrt( red*red + green*green + blue*blue );
281     red /= norm;
282     green /= norm;
283     blue /= norm;
284     /* XXX: We might still need to norm the rgb_matrix */
285     double rgb_matrix[9] =
286         { red*red,    red*green,   red*blue,
287           red*green,  green*green, green*blue,
288           red*blue,   green*blue,  blue*blue };
289     double result1[9];
290     double result[9];
291     int i;
292     msg_Dbg( p_filter, "red: %f", red );
293     msg_Dbg( p_filter, "green: %f", green );
294     msg_Dbg( p_filter, "blue: %f", blue );
295     mmult( result1, rgb_matrix, right_matrix );
296     mmult( result, left_matrix, result1 );
297     for( i = 0; i < 9; i++ )
298     {
299         matrix[i] = (int)result[i];
300     }
301     msg_Dbg( p_filter, "Projection matrix:" );
302     msg_Dbg( p_filter, "%6d %6d %6d", matrix[0], matrix[1], matrix[2] );
303     msg_Dbg( p_filter, "%6d %6d %6d", matrix[3], matrix[4], matrix[5] );
304     msg_Dbg( p_filter, "%6d %6d %6d", matrix[6], matrix[7], matrix[8] );
305 }
306
307 static void get_custom_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
308                                     int yp, int up, int vp, int *m )
309 {
310     uint8_t *y1in = p_inpic->p[yp].p_pixels;
311     uint8_t *y2in;
312     uint8_t *uin  = p_inpic->p[up].p_pixels;
313     uint8_t *vin  = p_inpic->p[vp].p_pixels;
314
315     uint8_t *y1out = p_outpic->p[yp].p_pixels;
316     uint8_t *y2out;
317     uint8_t *uout  = p_outpic->p[up].p_pixels;
318     uint8_t *vout  = p_outpic->p[vp].p_pixels;
319
320     const int i_pitch = p_inpic->p[yp].i_pitch;
321     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
322     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
323
324     const int i_uv_pitch = p_inpic->p[up].i_pitch;
325     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
326
327     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
328     while( y1in < yend )
329     {
330         const uint8_t *y1end = y1in + i_visible_pitch;
331         y2in  = y1in + i_pitch;
332         y2out = y1out + i_pitch;
333         while( y1in < y1end )
334         {
335             *uout++ = crop( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
336                       / 65536 + U );
337             *vout++ = crop( (*y1in * m[6] + (*uin-U) * m[7] + (*vin-V) * m[8])
338                       / 65536 + V );
339             *y1out++ = crop( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
340                        / 65536 );
341             *y1out++ = crop( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
342                        / 65536 );
343             *y2out++ = crop( (*y2in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
344                        / 65536 );
345             *y2out++ = crop( (*y2in++ * m[0] + (*uin++ - U) * m[1] + (*vin++ -V) * m[2])
346                        / 65536 );
347         }
348         y1in  += 2*i_pitch - i_visible_pitch;
349         y1out += 2*i_pitch - i_visible_pitch;
350         uin   += i_uv_pitch - i_uv_visible_pitch;
351         uout  += i_uv_pitch - i_uv_visible_pitch;
352         vin   += i_uv_pitch - i_uv_visible_pitch;
353         vout  += i_uv_pitch - i_uv_visible_pitch;
354     }
355 }
356 static void get_custom_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
357                                     int yp, int up, int vp, int *m )
358 {
359     uint8_t *y1in = p_inpic->p[yp].p_pixels;
360     uint8_t *uin  = p_inpic->p[up].p_pixels;
361     uint8_t *vin  = p_inpic->p[vp].p_pixels;
362
363     uint8_t *y1out = p_outpic->p[yp].p_pixels;
364     uint8_t *uout  = p_outpic->p[up].p_pixels;
365     uint8_t *vout  = p_outpic->p[vp].p_pixels;
366
367     const int i_pitch = p_inpic->p[yp].i_pitch;
368     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
369     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
370
371     const int i_uv_pitch = p_inpic->p[up].i_pitch;
372     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
373
374     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
375     while( y1in < yend )
376     {
377         const uint8_t *y1end = y1in + i_visible_pitch;
378         while( y1in < y1end )
379         {
380             *uout++ = crop( (*y1in * m[3] + (*uin-U) * m[4] + (*vin-V) * m[5])
381                       / 65536 + U );
382             *vout++ = crop( (*y1in * m[6] + (*uin-U) * m[7] + (*vin-V) * m[8])
383                       / 65536 + V );
384             *y1out++ = crop( (*y1in++ * m[0] + (*uin-U) * m[1] + (*vin-V) * m[2])
385                        / 65536 );
386             *y1out++ = crop( (*y1in++ * m[0] + (*uin++ -U) * m[1] + (*vin++ -V) * m[2])
387                        / 65536 );
388         }
389         y1in  += i_pitch - i_visible_pitch;
390         y1out += i_pitch - i_visible_pitch;
391         uin   += i_uv_pitch - i_uv_visible_pitch;
392         uout  += i_uv_pitch - i_uv_visible_pitch;
393         vin   += i_uv_pitch - i_uv_visible_pitch;
394         vout  += i_uv_pitch - i_uv_visible_pitch;
395     }
396 }
397
398 static void get_red_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
399                                  int yp, int up, int vp )
400 {
401     uint8_t *y1in = p_inpic->p[yp].p_pixels;
402     uint8_t *y2in;
403     uint8_t *vin  = p_inpic->p[vp].p_pixels;
404
405     uint8_t *y1out = p_outpic->p[yp].p_pixels;
406     uint8_t *y2out;
407     uint8_t *uout  = p_outpic->p[up].p_pixels;
408     uint8_t *vout  = p_outpic->p[vp].p_pixels;
409
410     const int i_pitch = p_inpic->p[yp].i_pitch;
411     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
412     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
413
414     const int i_uv_pitch = p_inpic->p[up].i_pitch;
415     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
416
417     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
418     while( y1in < yend )
419     {
420         const uint8_t *y1end = y1in + i_visible_pitch;
421         y2in  = y1in + i_pitch;
422         y2out = y1out + i_pitch;
423         while( y1in < y1end )
424         {
425 /*
426 19595   0   27473
427 -11058  0   -15504
428 32768   0   45941
429 */
430             *uout++ = crop( (*y1in * -11058 + (*vin - V) * -15504)
431                       / 65536 + U );
432             *vout++ = crop( (*y1in * 32768 + (*vin - V) * 45941)
433                       / 65536 + V );
434             *y1out++ = crop( (*y1in++ * 19595 + (*vin - V) * 27473)
435                        / 65536 );
436             *y1out++ = crop( (*y1in++ * 19595 + (*vin - V) * 27473)
437                        / 65536 );
438             *y2out++ = crop( (*y2in++ * 19594 + (*vin - V) * 27473)
439                        / 65536 );
440             *y2out++ = crop( (*y2in++ * 19594 + (*vin++ - V) * 27473)
441                        / 65536 );
442         }
443         y1in  += 2*i_pitch - i_visible_pitch;
444         y1out += 2*i_pitch - i_visible_pitch;
445         uout  += i_uv_pitch - i_uv_visible_pitch;
446         vin   += i_uv_pitch - i_uv_visible_pitch;
447         vout  += i_uv_pitch - i_uv_visible_pitch;
448     }
449 }
450
451 static void get_green_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
452                                  int yp, int up, int vp )
453 {
454     uint8_t *y1in = p_inpic->p[yp].p_pixels;
455     uint8_t *y2in;
456     uint8_t *uin  = p_inpic->p[up].p_pixels;
457     uint8_t *vin  = p_inpic->p[vp].p_pixels;
458
459     uint8_t *y1out = p_outpic->p[yp].p_pixels;
460     uint8_t *y2out;
461     uint8_t *uout  = p_outpic->p[up].p_pixels;
462     uint8_t *vout  = p_outpic->p[vp].p_pixels;
463
464     const int i_pitch = p_inpic->p[yp].i_pitch;
465     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
466     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
467
468     const int i_uv_pitch = p_inpic->p[up].i_pitch;
469     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
470
471     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
472     while( y1in < yend )
473     {
474         const uint8_t *y1end = y1in + i_visible_pitch;
475         y2in  = y1in + i_pitch;
476         y2out = y1out + i_pitch;
477         while( y1in < y1end )
478         {
479 /*
480 38470   -13239  -27473
481 -21710  7471    15504
482 -27439  9443    19595
483 */
484             *uout++ = crop( (*y1in * -21710 + (*uin-U) * 7471 + (*vin-V) * 15504)
485                       / 65536 + U );
486             *vout++ = crop( (*y1in * -27439 + (*uin-U) * 9443 + (*vin-V) * 19595)
487                       / 65536 + V );
488             *y1out++ = crop( (*y1in++ * 38470 + (*uin-U) * -13239 + (*vin-V) * -27473)
489                        / 65536 );
490             *y1out++ = crop( (*y1in++ * 38470 + (*uin-U) * -13239 + (*vin-V) * -27473)
491                        / 65536 );
492             *y2out++ = crop( (*y2in++ * 38470 + (*uin-U) * -13239 + (*vin-V) * -27473)
493                        / 65536 );
494             *y2out++ = crop( (*y2in++ * 38470 + (*uin++ - U) * -13239 + (*vin++ -V) * -27473)
495                        / 65536 );
496         }
497         y1in  += 2*i_pitch - i_visible_pitch;
498         y1out += 2*i_pitch - i_visible_pitch;
499         uin   += i_uv_pitch - i_uv_visible_pitch;
500         uout  += i_uv_pitch - i_uv_visible_pitch;
501         vin   += i_uv_pitch - i_uv_visible_pitch;
502         vout  += i_uv_pitch - i_uv_visible_pitch;
503     }
504 }
505
506 static void get_blue_from_yuv420( picture_t *p_inpic, picture_t *p_outpic,
507                                  int yp, int up, int vp )
508 {
509     uint8_t *y1in = p_inpic->p[yp].p_pixels;
510     uint8_t *y2in;
511     uint8_t *uin  = p_inpic->p[up].p_pixels;
512
513     uint8_t *y1out = p_outpic->p[yp].p_pixels;
514     uint8_t *y2out;
515     uint8_t *uout  = p_outpic->p[up].p_pixels;
516     uint8_t *vout  = p_outpic->p[vp].p_pixels;
517
518     const int i_pitch = p_inpic->p[yp].i_pitch;
519     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
520     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
521
522     const int i_uv_pitch = p_inpic->p[up].i_pitch;
523     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
524
525     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
526     while( y1in < yend )
527     {
528         const uint8_t *y1end = y1in + i_visible_pitch;
529         y2in  = y1in + i_pitch;
530         y2out = y1out + i_pitch;
531         while( y1in < y1end )
532         {
533 /*
534 7471    13239   0
535 32768   58065   0
536 -5329   -9443   0
537 */
538             *uout++ = crop( (*y1in* 32768 + (*uin - U) * 58065 )
539                       / 65536 + U );
540             *vout++ = crop( (*y1in * -5329 + (*uin - U) * -9443 )
541                       / 65536 + V );
542             *y1out++ = crop( (*y1in++ * 7471 + (*uin - U) * 13239 )
543                        / 65536 );
544             *y1out++ = crop( (*y1in++ * 7471 + (*uin - U) * 13239 )
545                        / 65536 );
546             *y2out++ = crop( (*y2in++ * 7471 + (*uin - U) * 13239 )
547                        / 65536 );
548             *y2out++ = crop( (*y2in++ * 7471 + (*uin++ - U) * 13239 )
549                        / 65536 );
550         }
551         y1in  += 2*i_pitch - i_visible_pitch;
552         y1out += 2*i_pitch - i_visible_pitch;
553         uin   += i_uv_pitch - i_uv_visible_pitch;
554         uout  += i_uv_pitch - i_uv_visible_pitch;
555         vout  += i_uv_pitch - i_uv_visible_pitch;
556     }
557 }
558
559 static void get_red_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
560                                  int yp, int up, int vp )
561 {
562     uint8_t *y1in = p_inpic->p[yp].p_pixels;
563     uint8_t *vin  = p_inpic->p[vp].p_pixels;
564
565     uint8_t *y1out = p_outpic->p[yp].p_pixels;
566     uint8_t *uout  = p_outpic->p[up].p_pixels;
567     uint8_t *vout  = p_outpic->p[vp].p_pixels;
568
569     const int i_pitch = p_inpic->p[yp].i_pitch;
570     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
571     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
572
573     const int i_uv_pitch = p_inpic->p[up].i_pitch;
574     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
575
576     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
577     while( y1in < yend )
578     {
579         const uint8_t *y1end = y1in + i_visible_pitch;
580         while( y1in < y1end )
581         {
582 /*
583 19595   0   27473
584 -11058  0   -15504
585 32768   0   45941
586 */
587             *uout++ = crop( (*y1in * -11058 + (*vin - V) * -15504)
588                       / 65536 + U );
589             *vout++ = crop( (*y1in * 32768 + (*vin - V) * 45941)
590                       / 65536 + V );
591             *y1out++ = crop( (*y1in++ * 19595 + (*vin - V) * 27473)
592                        / 65536 );
593             *y1out++ = crop( (*y1in++ * 19595 + (*vin++ - V) * 27473)
594                        / 65536 );
595         }
596         y1in  += i_pitch - i_visible_pitch;
597         y1out += i_pitch - i_visible_pitch;
598         uout  += i_uv_pitch - i_uv_visible_pitch;
599         vin   += i_uv_pitch - i_uv_visible_pitch;
600         vout  += i_uv_pitch - i_uv_visible_pitch;
601     }
602 }
603
604 static void get_green_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
605                                    int yp, int up, int vp )
606 {
607     uint8_t *y1in = p_inpic->p[yp].p_pixels;
608     uint8_t *uin  = p_inpic->p[up].p_pixels;
609     uint8_t *vin  = p_inpic->p[vp].p_pixels;
610
611     uint8_t *y1out = p_outpic->p[yp].p_pixels;
612     uint8_t *uout  = p_outpic->p[up].p_pixels;
613     uint8_t *vout  = p_outpic->p[vp].p_pixels;
614
615     const int i_pitch = p_inpic->p[yp].i_pitch;
616     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
617     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
618
619     const int i_uv_pitch = p_inpic->p[up].i_pitch;
620     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
621
622     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
623     while( y1in < yend )
624     {
625         const uint8_t *y1end = y1in + i_visible_pitch;
626         while( y1in < y1end )
627         {
628 /*
629 38470   -13239  -27473
630 -21710  7471    15504
631 -27439  9443    19595
632 */
633             *uout++ = crop( (*y1in * -21710 + (*uin-U) * 7471 + (*vin-V) * 15504)
634                       / 65536 + U );
635             *vout++ = crop( (*y1in * -27439 + (*uin-U) * 9443 + (*vin-V) * 19595)
636                       / 65536 + V );
637             *y1out++ = crop( (*y1in++ * 38470 + (*uin-U) * -13239 + (*vin-V) * -27473)
638                        / 65536 );
639             *y1out++ = crop( (*y1in++ * 38470 + (*uin++-U) * -13239 + (*vin++-V) * -27473)
640                        / 65536 );
641         }
642         y1in  += i_pitch - i_visible_pitch;
643         y1out += i_pitch - i_visible_pitch;
644         uin   += i_uv_pitch - i_uv_visible_pitch;
645         uout  += i_uv_pitch - i_uv_visible_pitch;
646         vin   += i_uv_pitch - i_uv_visible_pitch;
647         vout  += i_uv_pitch - i_uv_visible_pitch;
648     }
649 }
650
651 static void get_blue_from_yuv422( picture_t *p_inpic, picture_t *p_outpic,
652                                  int yp, int up, int vp )
653 {
654     uint8_t *y1in = p_inpic->p[yp].p_pixels;
655     uint8_t *uin  = p_inpic->p[up].p_pixels;
656
657     uint8_t *y1out = p_outpic->p[yp].p_pixels;
658     uint8_t *uout  = p_outpic->p[up].p_pixels;
659     uint8_t *vout  = p_outpic->p[vp].p_pixels;
660
661     const int i_pitch = p_inpic->p[yp].i_pitch;
662     const int i_visible_pitch = p_inpic->p[yp].i_visible_pitch;
663     const int i_visible_lines = p_inpic->p[yp].i_visible_lines;
664
665     const int i_uv_pitch = p_inpic->p[up].i_pitch;
666     const int i_uv_visible_pitch = p_inpic->p[up].i_visible_pitch;
667
668     const uint8_t *yend = y1in + i_visible_lines * i_pitch;
669     while( y1in < yend )
670     {
671         const uint8_t *y1end = y1in + i_visible_pitch;
672         while( y1in < y1end )
673         {
674 /*
675 7471    13239   0
676 32768   58065   0
677 -5329   -9443   0
678 */
679             *uout++ = crop( (*y1in* 32768 + (*uin - U) * 58065 )
680                       / 65536 + U );
681             *vout++ = crop( (*y1in * -5329 + (*uin - U) * -9443 )
682                       / 65536 + V );
683             *y1out++ = crop( (*y1in++ * 7471 + (*uin - U) * 13239 )
684                        / 65536 );
685             *y1out++ = crop( (*y1in++ * 7471 + (*uin++ - U) * 13239 )
686                        / 65536 );
687         }
688         y1in  += i_pitch - i_visible_pitch;
689         y1out += i_pitch - i_visible_pitch;
690         uin   += i_uv_pitch - i_uv_visible_pitch;
691         uout  += i_uv_pitch - i_uv_visible_pitch;
692         vout  += i_uv_pitch - i_uv_visible_pitch;
693     }
694 }
695
696 static int ExtractCallback( vlc_object_t *p_this, char const *psz_var,
697                             vlc_value_t oldval, vlc_value_t newval,
698                             void *p_data )
699 {
700     filter_sys_t *p_sys = (filter_sys_t *)p_data;
701
702     if( !strcmp( psz_var, FILTER_PREFIX "component" ) )
703     {
704         p_sys->i_color = newval.i_int;
705         switch( p_sys->i_color )
706         {
707             case RED:
708             case GREEN:
709             case BLUE:
710                 break;
711             default:
712                 make_projection_matrix( (filter_t *)p_this, p_sys->i_color,
713                                         p_sys->projection_matrix );
714                 break;
715         }
716     }
717     else
718     {
719         msg_Warn( p_this, "Unknown callback command." );
720     }
721     return VLC_SUCCESS;
722 }