| 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 |
|
|---|
| 29 |
#ifdef HAVE_CONFIG_H |
|---|
| 30 |
# include "config.h" |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
#include <errno.h> |
|---|
| 34 |
#include <math.h> |
|---|
| 35 |
|
|---|
| 36 |
#include <vlc_common.h> |
|---|
| 37 |
#include <vlc_plugin.h> |
|---|
| 38 |
#include <vlc_sout.h> |
|---|
| 39 |
#include <vlc_vout.h> |
|---|
| 40 |
|
|---|
| 41 |
#include "vlc_filter.h" |
|---|
| 42 |
#include "filter_picture.h" |
|---|
| 43 |
|
|---|
| 44 |
#ifndef M_PI |
|---|
| 45 |
# define M_PI 3.14159265358979323846 |
|---|
| 46 |
#endif |
|---|
| 47 |
|
|---|
| 48 |
#define eight_times( x ) x x x x x x x x |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int Create ( vlc_object_t * ); |
|---|
| 54 |
static void Destroy ( vlc_object_t * ); |
|---|
| 55 |
|
|---|
| 56 |
static picture_t *FilterPlanar( filter_t *, picture_t * ); |
|---|
| 57 |
static picture_t *FilterPacked( filter_t *, picture_t * ); |
|---|
| 58 |
static int AdjustCallback( vlc_object_t *p_this, char const *psz_var, |
|---|
| 59 |
vlc_value_t oldval, vlc_value_t newval, |
|---|
| 60 |
void *p_data ); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
#define THRES_TEXT N_("Brightness threshold") |
|---|
| 67 |
#define THRES_LONGTEXT N_("When this mode is enabled, pixels will be " \ |
|---|
| 68 |
"shown as black or white. The threshold value will be the brighness " \ |
|---|
| 69 |
"defined below." ) |
|---|
| 70 |
#define CONT_TEXT N_("Image contrast (0-2)") |
|---|
| 71 |
#define CONT_LONGTEXT N_("Set the image contrast, between 0 and 2. Defaults to 1.") |
|---|
| 72 |
#define HUE_TEXT N_("Image hue (0-360)") |
|---|
| 73 |
#define HUE_LONGTEXT N_("Set the image hue, between 0 and 360. Defaults to 0.") |
|---|
| 74 |
#define SAT_TEXT N_("Image saturation (0-3)") |
|---|
| 75 |
#define SAT_LONGTEXT N_("Set the image saturation, between 0 and 3. Defaults to 1.") |
|---|
| 76 |
#define LUM_TEXT N_("Image brightness (0-2)") |
|---|
| 77 |
#define LUM_LONGTEXT N_("Set the image brightness, between 0 and 2. Defaults to 1.") |
|---|
| 78 |
#define GAMMA_TEXT N_("Image gamma (0-10)") |
|---|
| 79 |
#define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1.") |
|---|
| 80 |
|
|---|
| 81 |
vlc_module_begin(); |
|---|
| 82 |
set_description( N_("Image properties filter") ); |
|---|
| 83 |
set_shortname( N_("Image adjust" )); |
|---|
| 84 |
set_category( CAT_VIDEO ); |
|---|
| 85 |
set_subcategory( SUBCAT_VIDEO_VFILTER ); |
|---|
| 86 |
set_capability( "video filter2", 0 ); |
|---|
| 87 |
|
|---|
| 88 |
add_float_with_range( "contrast", 1.0, 0.0, 2.0, NULL, |
|---|
| 89 |
CONT_TEXT, CONT_LONGTEXT, false ); |
|---|
| 90 |
add_float_with_range( "brightness", 1.0, 0.0, 2.0, NULL, |
|---|
| 91 |
LUM_TEXT, LUM_LONGTEXT, false ); |
|---|
| 92 |
add_integer_with_range( "hue", 0, 0, 360, NULL, |
|---|
| 93 |
HUE_TEXT, HUE_LONGTEXT, false ); |
|---|
| 94 |
add_float_with_range( "saturation", 1.0, 0.0, 3.0, NULL, |
|---|
| 95 |
SAT_TEXT, SAT_LONGTEXT, false ); |
|---|
| 96 |
add_float_with_range( "gamma", 1.0, 0.01, 10.0, NULL, |
|---|
| 97 |
GAMMA_TEXT, GAMMA_LONGTEXT, false ); |
|---|
| 98 |
|
|---|
| 99 |
add_bool( "brightness-threshold", 0, NULL, |
|---|
| 100 |
THRES_TEXT, THRES_LONGTEXT, false ); |
|---|
| 101 |
|
|---|
| 102 |
add_shortcut( "adjust" ); |
|---|
| 103 |
set_callbacks( Create, Destroy ); |
|---|
| 104 |
vlc_module_end(); |
|---|
| 105 |
|
|---|
| 106 |
static const char *const ppsz_filter_options[] = { |
|---|
| 107 |
"contrast", "brightness", "hue", "saturation", "gamma", |
|---|
| 108 |
"brightness-threshold", NULL |
|---|
| 109 |
}; |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
struct filter_sys_t |
|---|
| 115 |
{ |
|---|
| 116 |
double f_contrast; |
|---|
| 117 |
double f_brightness; |
|---|
| 118 |
int i_hue; |
|---|
| 119 |
double f_saturation; |
|---|
| 120 |
double f_gamma; |
|---|
| 121 |
bool b_brightness_threshold; |
|---|
| 122 |
}; |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
static int Create( vlc_object_t *p_this ) |
|---|
| 128 |
{ |
|---|
| 129 |
filter_t *p_filter = (filter_t *)p_this; |
|---|
| 130 |
filter_sys_t *p_sys; |
|---|
| 131 |
|
|---|
| 132 |
switch( p_filter->fmt_in.video.i_chroma ) |
|---|
| 133 |
{ |
|---|
| 134 |
CASE_PLANAR_YUV |
|---|
| 135 |
|
|---|
| 136 |
p_filter->pf_video_filter = FilterPlanar; |
|---|
| 137 |
break; |
|---|
| 138 |
|
|---|
| 139 |
CASE_PACKED_YUV_422 |
|---|
| 140 |
|
|---|
| 141 |
p_filter->pf_video_filter = FilterPacked; |
|---|
| 142 |
break; |
|---|
| 143 |
|
|---|
| 144 |
default: |
|---|
| 145 |
msg_Err( p_filter, "Unsupported input chroma (%4s)", |
|---|
| 146 |
(char*)&(p_filter->fmt_in.video.i_chroma) ); |
|---|
| 147 |
return VLC_EGENERIC; |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ) |
|---|
| 151 |
{ |
|---|
| 152 |
msg_Err( p_filter, "Input and output chromas don't match" ); |
|---|
| 153 |
return VLC_EGENERIC; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); |
|---|
| 158 |
if( p_filter->p_sys == NULL ) |
|---|
| 159 |
return VLC_ENOMEM; |
|---|
| 160 |
p_sys = p_filter->p_sys; |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
config_ChainParse( p_filter, "", ppsz_filter_options, |
|---|
| 165 |
p_filter->p_cfg ); |
|---|
| 166 |
|
|---|
| 167 |
p_sys->f_contrast = var_CreateGetFloatCommand( p_filter, "contrast" ); |
|---|
| 168 |
p_sys->f_brightness = var_CreateGetFloatCommand( p_filter, "brightness" ); |
|---|
| 169 |
p_sys->i_hue = var_CreateGetIntegerCommand( p_filter, "hue" ); |
|---|
| 170 |
p_sys->f_saturation = var_CreateGetFloatCommand( p_filter, "saturation" ); |
|---|
| 171 |
p_sys->f_gamma = var_CreateGetFloatCommand( p_filter, "gamma" ); |
|---|
| 172 |
p_sys->b_brightness_threshold = |
|---|
| 173 |
var_CreateGetBoolCommand( p_filter, "brightness-threshold" ); |
|---|
| 174 |
|
|---|
| 175 |
var_AddCallback( p_filter, "contrast", AdjustCallback, p_sys ); |
|---|
| 176 |
var_AddCallback( p_filter, "brightness", AdjustCallback, p_sys ); |
|---|
| 177 |
var_AddCallback( p_filter, "hue", AdjustCallback, p_sys ); |
|---|
| 178 |
var_AddCallback( p_filter, "saturation", AdjustCallback, p_sys ); |
|---|
| 179 |
var_AddCallback( p_filter, "gamma", AdjustCallback, p_sys ); |
|---|
| 180 |
var_AddCallback( p_filter, "brightness-threshold", |
|---|
| 181 |
AdjustCallback, p_sys ); |
|---|
| 182 |
|
|---|
| 183 |
return VLC_SUCCESS; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 190 |
{ |
|---|
| 191 |
filter_t *p_filter = (filter_t *)p_this; |
|---|
| 192 |
free( p_filter->p_sys ); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
static picture_t *FilterPlanar( filter_t *p_filter, picture_t *p_pic ) |
|---|
| 199 |
{ |
|---|
| 200 |
int pi_luma[256]; |
|---|
| 201 |
int pi_gamma[256]; |
|---|
| 202 |
|
|---|
| 203 |
picture_t *p_outpic; |
|---|
| 204 |
uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end; |
|---|
| 205 |
uint8_t *p_out, *p_out_v; |
|---|
| 206 |
|
|---|
| 207 |
bool b_thres; |
|---|
| 208 |
double f_hue; |
|---|
| 209 |
double f_gamma; |
|---|
| 210 |
int32_t i_cont, i_lum; |
|---|
| 211 |
int i_sat, i_sin, i_cos, i_x, i_y; |
|---|
| 212 |
int i; |
|---|
| 213 |
|
|---|
| 214 |
filter_sys_t *p_sys = p_filter->p_sys; |
|---|
| 215 |
|
|---|
| 216 |
if( !p_pic ) return NULL; |
|---|
| 217 |
|
|---|
| 218 |
p_outpic = filter_NewPicture( p_filter ); |
|---|
| 219 |
if( !p_outpic ) |
|---|
| 220 |
{ |
|---|
| 221 |
picture_Release( p_pic ); |
|---|
| 222 |
return NULL; |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
i_cont = (int)( p_sys->f_contrast * 255 ); |
|---|
| 227 |
i_lum = (int)( (p_sys->f_brightness - 1.0)*255 ); |
|---|
| 228 |
f_hue = (float)( p_sys->i_hue * M_PI / 180 ); |
|---|
| 229 |
i_sat = (int)( p_sys->f_saturation * 256 ); |
|---|
| 230 |
f_gamma = 1.0 / p_sys->f_gamma; |
|---|
| 231 |
b_thres = p_sys->b_brightness_threshold; |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
if( b_thres != true ) |
|---|
| 237 |
{ |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
i_lum += 128 - i_cont / 2; |
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 245 |
{ |
|---|
| 246 |
pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0); |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 251 |
{ |
|---|
| 252 |
pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)]; |
|---|
| 253 |
} |
|---|
| 254 |
} |
|---|
| 255 |
else |
|---|
| 256 |
{ |
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 262 |
{ |
|---|
| 263 |
pi_luma[ i ] = (i < i_lum) ? 0 : 255; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
i_sat = 0; |
|---|
| 270 |
} |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
p_in = p_pic->p[Y_PLANE].p_pixels; |
|---|
| 277 |
p_in_end = p_in + p_pic->p[Y_PLANE].i_visible_lines |
|---|
| 278 |
* p_pic->p[Y_PLANE].i_pitch - 8; |
|---|
| 279 |
|
|---|
| 280 |
p_out = p_outpic->p[Y_PLANE].p_pixels; |
|---|
| 281 |
|
|---|
| 282 |
for( ; p_in < p_in_end ; ) |
|---|
| 283 |
{ |
|---|
| 284 |
p_line_end = p_in + p_pic->p[Y_PLANE].i_visible_pitch - 8; |
|---|
| 285 |
|
|---|
| 286 |
for( ; p_in < p_line_end ; ) |
|---|
| 287 |
{ |
|---|
| 288 |
|
|---|
| 289 |
*p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ]; |
|---|
| 290 |
*p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ]; |
|---|
| 291 |
*p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ]; |
|---|
| 292 |
*p_out++ = pi_luma[ *p_in++ ]; *p_out++ = pi_luma[ *p_in++ ]; |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
p_line_end += 8; |
|---|
| 296 |
|
|---|
| 297 |
for( ; p_in < p_line_end ; ) |
|---|
| 298 |
{ |
|---|
| 299 |
*p_out++ = pi_luma[ *p_in++ ]; |
|---|
| 300 |
} |
|---|
| 301 |
|
|---|
| 302 |
p_in += p_pic->p[Y_PLANE].i_pitch |
|---|
| 303 |
- p_pic->p[Y_PLANE].i_visible_pitch; |
|---|
| 304 |
p_out += p_outpic->p[Y_PLANE].i_pitch |
|---|
| 305 |
- p_outpic->p[Y_PLANE].i_visible_pitch; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
p_in = p_pic->p[U_PLANE].p_pixels; |
|---|
| 313 |
p_in_v = p_pic->p[V_PLANE].p_pixels; |
|---|
| 314 |
p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines |
|---|
| 315 |
* p_pic->p[U_PLANE].i_pitch - 8; |
|---|
| 316 |
|
|---|
| 317 |
p_out = p_outpic->p[U_PLANE].p_pixels; |
|---|
| 318 |
p_out_v = p_outpic->p[V_PLANE].p_pixels; |
|---|
| 319 |
|
|---|
| 320 |
i_sin = sin(f_hue) * 256; |
|---|
| 321 |
i_cos = cos(f_hue) * 256; |
|---|
| 322 |
|
|---|
| 323 |
i_x = ( cos(f_hue) + sin(f_hue) ) * 32768; |
|---|
| 324 |
i_y = ( cos(f_hue) - sin(f_hue) ) * 32768; |
|---|
| 325 |
|
|---|
| 326 |
if ( i_sat > 256 ) |
|---|
| 327 |
{ |
|---|
| 328 |
#define WRITE_UV_CLIP() \ |
|---|
| 329 |
i_u = *p_in++ ; i_v = *p_in_v++ ; \ |
|---|
| 330 |
*p_out++ = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \ |
|---|
| 331 |
* i_sat) >> 8) + 128); \ |
|---|
| 332 |
*p_out_v++ = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \ |
|---|
| 333 |
* i_sat) >> 8) + 128) |
|---|
| 334 |
|
|---|
| 335 |
uint8_t i_u, i_v; |
|---|
| 336 |
|
|---|
| 337 |
for( ; p_in < p_in_end ; ) |
|---|
| 338 |
{ |
|---|
| 339 |
p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8; |
|---|
| 340 |
|
|---|
| 341 |
for( ; p_in < p_line_end ; ) |
|---|
| 342 |
{ |
|---|
| 343 |
|
|---|
| 344 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 345 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 346 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 347 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
p_line_end += 8; |
|---|
| 351 |
|
|---|
| 352 |
for( ; p_in < p_line_end ; ) |
|---|
| 353 |
{ |
|---|
| 354 |
WRITE_UV_CLIP(); |
|---|
| 355 |
} |
|---|
| 356 |
|
|---|
| 357 |
p_in += p_pic->p[U_PLANE].i_pitch |
|---|
| 358 |
- p_pic->p[U_PLANE].i_visible_pitch; |
|---|
| 359 |
p_in_v += p_pic->p[V_PLANE].i_pitch |
|---|
| 360 |
- p_pic->p[V_PLANE].i_visible_pitch; |
|---|
| 361 |
p_out += p_outpic->p[U_PLANE].i_pitch |
|---|
| 362 |
- p_outpic->p[U_PLANE].i_visible_pitch; |
|---|
| 363 |
p_out_v += p_outpic->p[V_PLANE].i_pitch |
|---|
| 364 |
- p_outpic->p[V_PLANE].i_visible_pitch; |
|---|
| 365 |
} |
|---|
| 366 |
#undef WRITE_UV_CLIP |
|---|
| 367 |
} |
|---|
| 368 |
else |
|---|
| 369 |
{ |
|---|
| 370 |
#define WRITE_UV() \ |
|---|
| 371 |
i_u = *p_in++ ; i_v = *p_in_v++ ; \ |
|---|
| 372 |
*p_out++ = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \ |
|---|
| 373 |
* i_sat) >> 8) + 128; \ |
|---|
| 374 |
*p_out_v++ = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \ |
|---|
| 375 |
* i_sat) >> 8) + 128 |
|---|
| 376 |
|
|---|
| 377 |
uint8_t i_u, i_v; |
|---|
| 378 |
|
|---|
| 379 |
for( ; p_in < p_in_end ; ) |
|---|
| 380 |
{ |
|---|
| 381 |
p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8; |
|---|
| 382 |
|
|---|
| 383 |
for( ; p_in < p_line_end ; ) |
|---|
| 384 |
{ |
|---|
| 385 |
|
|---|
| 386 |
WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV(); |
|---|
| 387 |
WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV(); |
|---|
| 388 |
} |
|---|
| 389 |
|
|---|
| 390 |
p_line_end += 8; |
|---|
| 391 |
|
|---|
| 392 |
for( ; p_in < p_line_end ; ) |
|---|
| 393 |
{ |
|---|
| 394 |
WRITE_UV(); |
|---|
| 395 |
} |
|---|
| 396 |
|
|---|
| 397 |
p_in += p_pic->p[U_PLANE].i_pitch |
|---|
| 398 |
- p_pic->p[U_PLANE].i_visible_pitch; |
|---|
| 399 |
p_in_v += p_pic->p[V_PLANE].i_pitch |
|---|
| 400 |
- p_pic->p[V_PLANE].i_visible_pitch; |
|---|
| 401 |
p_out += p_outpic->p[U_PLANE].i_pitch |
|---|
| 402 |
- p_outpic->p[U_PLANE].i_visible_pitch; |
|---|
| 403 |
p_out_v += p_outpic->p[V_PLANE].i_pitch |
|---|
| 404 |
- p_outpic->p[V_PLANE].i_visible_pitch; |
|---|
| 405 |
} |
|---|
| 406 |
#undef WRITE_UV |
|---|
| 407 |
} |
|---|
| 408 |
|
|---|
| 409 |
return CopyInfoAndRelease( p_outpic, p_pic ); |
|---|
| 410 |
} |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
static picture_t *FilterPacked( filter_t *p_filter, picture_t *p_pic ) |
|---|
| 416 |
{ |
|---|
| 417 |
int pi_luma[256]; |
|---|
| 418 |
int pi_gamma[256]; |
|---|
| 419 |
|
|---|
| 420 |
picture_t *p_outpic; |
|---|
| 421 |
uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end; |
|---|
| 422 |
uint8_t *p_out, *p_out_v; |
|---|
| 423 |
int i_y_offset, i_u_offset, i_v_offset; |
|---|
| 424 |
|
|---|
| 425 |
int i_lines, i_visible_lines, i_pitch, i_visible_pitch; |
|---|
| 426 |
|
|---|
| 427 |
bool b_thres; |
|---|
| 428 |
double f_hue; |
|---|
| 429 |
double f_gamma; |
|---|
| 430 |
int32_t i_cont, i_lum; |
|---|
| 431 |
int i_sat, i_sin, i_cos, i_x, i_y; |
|---|
| 432 |
int i; |
|---|
| 433 |
|
|---|
| 434 |
filter_sys_t *p_sys = p_filter->p_sys; |
|---|
| 435 |
|
|---|
| 436 |
if( !p_pic ) return NULL; |
|---|
| 437 |
|
|---|
| 438 |
i_lines = p_pic->p->i_lines; |
|---|
| 439 |
i_visible_lines = p_pic->p->i_visible_lines; |
|---|
| 440 |
i_pitch = p_pic->p->i_pitch; |
|---|
| 441 |
i_visible_pitch = p_pic->p->i_visible_pitch; |
|---|
| 442 |
|
|---|
| 443 |
if( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset, |
|---|
| 444 |
&i_u_offset, &i_v_offset ) != VLC_SUCCESS ) |
|---|
| 445 |
{ |
|---|
| 446 |
msg_Warn( p_filter, "Unsupported input chroma (%4s)", |
|---|
| 447 |
(char*)&(p_pic->format.i_chroma) ); |
|---|
| 448 |
|
|---|
| 449 |
picture_Release( p_pic ); |
|---|
| 450 |
return NULL; |
|---|
| 451 |
} |
|---|
| 452 |
|
|---|
| 453 |
p_outpic = p_filter->pf_vout_buffer_new( p_filter ); |
|---|
| 454 |
if( !p_outpic ) |
|---|
| 455 |
{ |
|---|
| 456 |
msg_Warn( p_filter, "can't get output picture" ); |
|---|
| 457 |
|
|---|
| 458 |
picture_Release( p_pic ); |
|---|
| 459 |
return NULL; |
|---|
| 460 |
} |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
i_cont = (int)( p_sys->f_contrast * 255 ); |
|---|
| 464 |
i_lum = (int)( (p_sys->f_brightness - 1.0)*255 ); |
|---|
| 465 |
f_hue = (float)( p_sys->i_hue * M_PI / 180 ); |
|---|
| 466 |
i_sat = (int)( p_sys->f_saturation * 256 ); |
|---|
| 467 |
f_gamma = 1.0 / p_sys->f_gamma; |
|---|
| 468 |
b_thres = p_sys->b_brightness_threshold; |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
if( b_thres != true ) |
|---|
| 474 |
{ |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
i_lum += 128 - i_cont / 2; |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 482 |
{ |
|---|
| 483 |
pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0); |
|---|
| 484 |
} |
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 488 |
{ |
|---|
| 489 |
pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)]; |
|---|
| 490 |
} |
|---|
| 491 |
} |
|---|
| 492 |
else |
|---|
| 493 |
{ |
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
for( i = 0 ; i < 256 ; i++ ) |
|---|
| 499 |
{ |
|---|
| 500 |
pi_luma[ i ] = (i < i_lum) ? 0 : 255; |
|---|
| 501 |
} |
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
i_sat = 0; |
|---|
| 507 |
} |
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
p_in = p_pic->p->p_pixels + i_y_offset; |
|---|
| 514 |
p_in_end = p_in + p_pic->p->i_visible_lines * p_pic->p->i_pitch - 8 * 4; |
|---|
| 515 |
|
|---|
| 516 |
p_out = p_outpic->p->p_pixels + i_y_offset; |
|---|
| 517 |
|
|---|
| 518 |
for( ; p_in < p_in_end ; ) |
|---|
| 519 |
{ |
|---|
| 520 |
p_line_end = p_in + i_visible_pitch - 8 * 4; |
|---|
| 521 |
|
|---|
| 522 |
for( ; p_in < p_line_end ; ) |
|---|
| 523 |
{ |
|---|
| 524 |
|
|---|
| 525 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 526 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 527 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 528 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 529 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 530 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 531 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 532 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 533 |
} |
|---|
| 534 |
|
|---|
| 535 |
p_line_end += 8 * 4; |
|---|
| 536 |
|
|---|
| 537 |
for( ; p_in < p_line_end ; ) |
|---|
| 538 |
{ |
|---|
| 539 |
*p_out = pi_luma[ *p_in ]; p_in += 2; p_out += 2; |
|---|
| 540 |
} |
|---|
| 541 |
|
|---|
| 542 |
p_in += i_pitch - p_pic->p->i_visible_pitch; |
|---|
| 543 |
p_out += i_pitch - p_outpic->p->i_visible_pitch; |
|---|
| 544 |
} |
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
p_in = p_pic->p->p_pixels + i_u_offset; |
|---|
| 551 |
p_in_v = p_pic->p->p_pixels + i_v_offset; |
|---|
| 552 |
p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4; |
|---|
| 553 |
|
|---|
| 554 |
p_out = p_outpic->p->p_pixels + i_u_offset; |
|---|
| 555 |
p_out_v = p_outpic->p->p_pixels + i_v_offset; |
|---|
| 556 |
|
|---|
| 557 |
i_sin = sin(f_hue) * 256; |
|---|
| 558 |
i_cos = cos(f_hue) * 256; |
|---|
| 559 |
|
|---|
| 560 |
i_x = ( cos(f_hue) + sin(f_hue) ) * 32768; |
|---|
| 561 |
i_y = ( cos(f_hue) - sin(f_hue) ) * 32768; |
|---|
| 562 |
|
|---|
| 563 |
if ( i_sat > 256 ) |
|---|
| 564 |
{ |
|---|
| 565 |
#define WRITE_UV_CLIP() \ |
|---|
| 566 |
i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \ |
|---|
| 567 |
*p_out = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \ |
|---|
| 568 |
* i_sat) >> 8) + 128); \ |
|---|
| 569 |
p_out += 4; \ |
|---|
| 570 |
*p_out_v = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \ |
|---|
| 571 |
* i_sat) >> 8) + 128); \ |
|---|
| 572 |
p_out_v += 4 |
|---|
| 573 |
|
|---|
| 574 |
uint8_t i_u, i_v; |
|---|
| 575 |
|
|---|
| 576 |
for( ; p_in < p_in_end ; ) |
|---|
| 577 |
{ |
|---|
| 578 |
p_line_end = p_in + i_visible_pitch - 8 * 4; |
|---|
| 579 |
|
|---|
| 580 |
for( ; p_in < p_line_end ; ) |
|---|
| 581 |
{ |
|---|
| 582 |
|
|---|
| 583 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 584 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 585 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 586 |
WRITE_UV_CLIP(); WRITE_UV_CLIP(); |
|---|
| 587 |
} |
|---|
| 588 |
|
|---|
| 589 |
p_line_end += 8 * 4; |
|---|
| 590 |
|
|---|
| 591 |
for( ; p_in < p_line_end ; ) |
|---|
| 592 |
{ |
|---|
| 593 |
WRITE_UV_CLIP(); |
|---|
| 594 |
} |
|---|
| 595 |
|
|---|
| 596 |
p_in += i_pitch - i_visible_pitch; |
|---|
| 597 |
p_in_v += i_pitch - i_visible_pitch; |
|---|
| 598 |
p_out += i_pitch - i_visible_pitch; |
|---|
| 599 |
p_out_v += i_pitch - i_visible_pitch; |
|---|
| 600 |
} |
|---|
| 601 |
#undef WRITE_UV_CLIP |
|---|
| 602 |
} |
|---|
| 603 |
else |
|---|
| 604 |
{ |
|---|
| 605 |
#define WRITE_UV() \ |
|---|
| 606 |
i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \ |
|---|
| 607 |
*p_out = (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \ |
|---|
| 608 |
* i_sat) >> 8) + 128; \ |
|---|
| 609 |
p_out += 4; \ |
|---|
| 610 |
*p_out_v = (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \ |
|---|
| 611 |
* i_sat) >> 8) + 128; \ |
|---|
| 612 |
p_out_v += 4 |
|---|
| 613 |
|
|---|
| 614 |
uint8_t i_u, i_v; |
|---|
| 615 |
|
|---|
| 616 |
for( ; p_in < p_in_end ; ) |
|---|
| 617 |
{ |
|---|
| 618 |
p_line_end = p_in + i_visible_pitch - 8 * 4; |
|---|
| 619 |
|
|---|
| 620 |
for( ; p_in < p_line_end ; ) |
|---|
| 621 |
{ |
|---|
| 622 |
|
|---|
| 623 |
WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV(); |
|---|
| 624 |
WRITE_UV(); WRITE_UV(); WRITE_UV(); WRITE_UV(); |
|---|
| 625 |
} |
|---|
| 626 |
|
|---|
| 627 |
p_line_end += 8 * 4; |
|---|
| 628 |
|
|---|
| 629 |
for( ; p_in < p_line_end ; ) |
|---|
| 630 |
{ |
|---|
| 631 |
WRITE_UV(); |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
p_in += i_pitch - i_visible_pitch; |
|---|
| 635 |
p_in_v += i_pitch - i_visible_pitch; |
|---|
| 636 |
p_out += i_pitch - i_visible_pitch; |
|---|
| 637 |
p_out_v += i_pitch - i_visible_pitch; |
|---|
| 638 |
} |
|---|
| 639 |
#undef WRITE_UV |
|---|
| 640 |
} |
|---|
| 641 |
|
|---|
| 642 |
return CopyInfoAndRelease( p_outpic, p_pic ); |
|---|
| 643 |
} |
|---|
| 644 |
|
|---|
| 645 |
static int AdjustCallback( vlc_object_t *p_this, char const *psz_var, |
|---|
| 646 |
vlc_value_t oldval, vlc_value_t newval, |
|---|
| 647 |
void *p_data ) |
|---|
| 648 |
{ |
|---|
| 649 |
VLC_UNUSED(p_this); VLC_UNUSED(oldval); |
|---|
| 650 |
filter_sys_t *p_sys = (filter_sys_t *)p_data; |
|---|
| 651 |
|
|---|
| 652 |
if( !strcmp( psz_var, "contrast" ) ) |
|---|
| 653 |
p_sys->f_contrast = newval.f_float; |
|---|
| 654 |
else if( !strcmp( psz_var, "brightness" ) ) |
|---|
| 655 |
p_sys->f_brightness = newval.f_float; |
|---|
| 656 |
else if( !strcmp( psz_var, "hue" ) ) |
|---|
| 657 |
p_sys->i_hue = newval.i_int; |
|---|
| 658 |
else if( !strcmp( psz_var, "saturation" ) ) |
|---|
| 659 |
p_sys->f_saturation = newval.f_float; |
|---|
| 660 |
else if( !strcmp( psz_var, "gamma" ) ) |
|---|
| 661 |
p_sys->f_gamma = newval.f_float; |
|---|
| 662 |
else if( !strcmp( psz_var, "brightness-threshold" ) ) |
|---|
| 663 |
p_sys->b_brightness_threshold = newval.b_bool; |
|---|
| 664 |
else |
|---|
| 665 |
return VLC_EGENERIC; |
|---|
| 666 |
return VLC_SUCCESS; |
|---|
| 667 |
} |
|---|