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