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