eq2.c
来自「linux下的MPEG1」· C语言 代码 · 共 632 行 · 第 1/2 页
C
632 行
};static int set_parameters (xine_post_t *this_gen, void *param_gen) { post_plugin_eq2_t *this = (post_plugin_eq2_t *)this_gen; eq2_parameters_t *param = (eq2_parameters_t *)param_gen; vf_eq2_t *eq2 = &this->eq2; pthread_mutex_lock (&this->lock); if( &this->params != param ) memcpy( &this->params, param, sizeof(eq2_parameters_t) ); eq2->rgamma = param->rgamma; eq2->ggamma = param->ggamma; eq2->bgamma = param->bgamma; set_gamma (eq2, param->gamma); set_contrast (eq2, param->contrast); set_brightness (eq2, param->brightness); set_saturation (eq2, param->saturation); pthread_mutex_unlock (&this->lock); return 1;}static int get_parameters (xine_post_t *this_gen, void *param_gen) { post_plugin_eq2_t *this = (post_plugin_eq2_t *)this_gen; eq2_parameters_t *param = (eq2_parameters_t *)param_gen; memcpy( param, &this->params, sizeof(eq2_parameters_t) ); return 1;} static xine_post_api_descr_t * get_param_descr (void) { return ¶m_descr;}static char * get_help (void) { return _("Alternative software equalizer that uses lookup tables (very slow), " "allowing gamma correction in addition to simple brightness, " "contrast and saturation adjustment.\n" "Note that it uses the same MMX optimized code as 'eq' if all " "gamma values are 1.0.\n" "\n" "Parameters\n" " gamma\n" " brightness\n" " contrast\n" " saturation\n" " rgamma (gamma for the red component)\n" " ggamma (gamma for the green component)\n" " bgamma (gamma for the blue component)\n" "\n" "Value ranges are 0.1 - 10 for gammas, -2 - 2 for contrast " "(negative values result in a negative image), -1 - 1 for " "brightness and 0 - 3 for saturation.\n" "\n" "* mplayer's eq2 (C) Hampa Hug, Daniel Moreno, Richard Felker\n" );}static xine_post_api_t post_api = { set_parameters, get_parameters, get_param_descr, get_help,};/* plugin class functions */static post_plugin_t *eq2_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target);static char *eq2_get_identifier(post_class_t *class_gen);static char *eq2_get_description(post_class_t *class_gen);static void eq2_class_dispose(post_class_t *class_gen);/* plugin instance functions */static void eq2_dispose(post_plugin_t *this_gen);/* replaced video_port functions */static int eq2_get_property(xine_video_port_t *port_gen, int property);static int eq2_set_property(xine_video_port_t *port_gen, int property, int value);/* frame intercept check */static int eq2_intercept_frame(post_video_port_t *port, vo_frame_t *frame);/* replaced vo_frame functions */static int eq2_draw(vo_frame_t *frame, xine_stream_t *stream);void *eq2_init_plugin(xine_t *xine, void *data){ post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); if (!class) return NULL; class->open_plugin = eq2_open_plugin; class->get_identifier = eq2_get_identifier; class->get_description = eq2_get_description; class->dispose = eq2_class_dispose; return class;}static post_plugin_t *eq2_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target){ post_plugin_eq2_t *this = (post_plugin_eq2_t *)xine_xmalloc(sizeof(post_plugin_eq2_t)); post_in_t *input; xine_post_in_t *input_api; post_out_t *output; post_video_port_t *port; vf_eq2_t *eq2; int i; if (!this || !video_target || !video_target[0]) { free(this); return NULL; } _x_post_init(&this->post, 0, 1); eq2 = &this->eq2; for (i = 0; i < 3; i++) { eq2->buf[i] = NULL; eq2->buf_w[i] = 0; eq2->buf_h[i] = 0; eq2->param[i].adjust = NULL; eq2->param[i].c = 1.0; eq2->param[i].b = 0.0; eq2->param[i].g = 1.0; eq2->param[i].lut_clean = 0; } eq2->gamma = this->params.gamma = 1.0; eq2->contrast = this->params.contrast = 1.0; eq2->brightness = this->params.brightness = 0.0; eq2->saturation = this->params.saturation = 1.0; eq2->rgamma = this->params.rgamma = 1.0; eq2->ggamma = this->params.ggamma = 1.0; eq2->bgamma = this->params.bgamma = 1.0; pthread_mutex_init(&this->lock, NULL); port = _x_post_intercept_video_port(&this->post, video_target[0], &input, &output); port->new_port.get_property = eq2_get_property; port->new_port.set_property = eq2_set_property; port->intercept_frame = eq2_intercept_frame; port->new_frame->draw = eq2_draw; input_api = &this->params_input; input_api->name = "parameters"; input_api->type = XINE_POST_DATA_PARAMETERS; input_api->data = &post_api; xine_list_push_back(this->post.input, input_api); input->xine_in.name = "video"; output->xine_out.name = "eqd video"; this->post.xine_post.video_input[0] = &port->new_port; this->post.dispose = eq2_dispose; set_parameters ((xine_post_t *)this, &this->params); return &this->post;}static char *eq2_get_identifier(post_class_t *class_gen){ return "eq2";}static char *eq2_get_description(post_class_t *class_gen){ return "Software video equalizer";}static void eq2_class_dispose(post_class_t *class_gen){ free(class_gen);}static void eq2_dispose(post_plugin_t *this_gen){ post_plugin_eq2_t *this = (post_plugin_eq2_t *)this_gen; if (_x_post_dispose(this_gen)) { pthread_mutex_destroy(&this->lock); free(this); }}static int eq2_get_property(xine_video_port_t *port_gen, int property) { post_video_port_t *port = (post_video_port_t *)port_gen; post_plugin_eq2_t *this = (post_plugin_eq2_t *)port->post; if( property == XINE_PARAM_VO_BRIGHTNESS ) return 65535 * (this->params.brightness + 1.0) / 2.0; else if( property == XINE_PARAM_VO_CONTRAST ) return 65535 * (this->params.contrast) / 2.0; else if( property == XINE_PARAM_VO_SATURATION ) return 65535 * (this->params.saturation) / 2.0; else return port->original_port->get_property(port->original_port, property);}static int eq2_set_property(xine_video_port_t *port_gen, int property, int value) { post_video_port_t *port = (post_video_port_t *)port_gen; post_plugin_eq2_t *this = (post_plugin_eq2_t *)port->post; if( property == XINE_PARAM_VO_BRIGHTNESS ) { this->params.brightness = (2.0 * value / 65535) - 1.0; set_parameters ((xine_post_t *)this, &this->params); return value; } else if( property == XINE_PARAM_VO_CONTRAST ) { this->params.contrast = (2.0 * value / 65535); set_parameters ((xine_post_t *)this, &this->params); return value; } else if( property == XINE_PARAM_VO_SATURATION ) { this->params.saturation = (2.0 * value / 65535); set_parameters ((xine_post_t *)this, &this->params); return value; } else return port->original_port->set_property(port->original_port, property, value);}static int eq2_intercept_frame(post_video_port_t *port, vo_frame_t *frame){ return (frame->format == XINE_IMGFMT_YV12 || frame->format == XINE_IMGFMT_YUY2);}static int eq2_draw(vo_frame_t *frame, xine_stream_t *stream){ post_video_port_t *port = (post_video_port_t *)frame->port; post_plugin_eq2_t *this = (post_plugin_eq2_t *)port->post; vo_frame_t *out_frame; vo_frame_t *yv12_frame; vf_eq2_t *eq2 = &this->eq2; int skip; int i; if( !frame->bad_frame && (eq2->param[0].adjust || eq2->param[1].adjust || eq2->param[2].adjust) ) { /* convert to YV12 if needed */ if( frame->format != XINE_IMGFMT_YV12 ) { yv12_frame = port->original_port->get_frame(port->original_port, frame->width, frame->height, frame->ratio, XINE_IMGFMT_YV12, frame->flags | VO_BOTH_FIELDS); _x_post_frame_copy_down(frame, yv12_frame); yuy2_to_yv12(frame->base[0], frame->pitches[0], yv12_frame->base[0], yv12_frame->pitches[0], yv12_frame->base[1], yv12_frame->pitches[1], yv12_frame->base[2], yv12_frame->pitches[2], frame->width, frame->height); } else { yv12_frame = frame; yv12_frame->lock(yv12_frame); } out_frame = port->original_port->get_frame(port->original_port, frame->width, frame->height, frame->ratio, XINE_IMGFMT_YV12, frame->flags | VO_BOTH_FIELDS); _x_post_frame_copy_down(frame, out_frame); pthread_mutex_lock (&this->lock); for (i = 0; i < 3; i++) { int height, width; height = (i==0) ? frame->height : frame->height/2; width = (i==0) ? frame->width : frame->width/2; if (eq2->param[i].adjust != NULL) { eq2->param[i].adjust (&eq2->param[i], out_frame->base[i], yv12_frame->base[i], width, height, out_frame->pitches[i], yv12_frame->pitches[i]); } else { xine_fast_memcpy(out_frame->base[i],yv12_frame->base[i], yv12_frame->pitches[i] * height); } } pthread_mutex_unlock (&this->lock); skip = out_frame->draw(out_frame, stream); _x_post_frame_copy_up(frame, out_frame); out_frame->free(out_frame); yv12_frame->free(yv12_frame); } else { _x_post_frame_copy_down(frame, frame->next); skip = frame->next->draw(frame->next, stream); _x_post_frame_copy_up(frame, frame->next); } return skip;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?