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