diff options
author | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-06-29 18:56:24 +0000 |
---|---|---|
committer | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-06-29 18:56:24 +0000 |
commit | 5b65a3cddd0a1e963a1b683398dc5482c6e1c2c6 (patch) | |
tree | 383efd1c6d29b1684a36e8460629a63129028a9e | |
parent | 3181b8ec876d1b2aee28c743d7c5db95caa8a08a (diff) | |
download | xine-lib-5b65a3cddd0a1e963a1b683398dc5482c6e1c2c6.tar.gz xine-lib-5b65a3cddd0a1e963a1b683398dc5482c6e1c2c6.tar.bz2 |
port of some simple video filters from mplayer
CVS patchset: 5113
CVS date: 2003/06/29 18:56:24
-rw-r--r-- | src/post/planar/Makefile.am | 17 | ||||
-rw-r--r-- | src/post/planar/boxblur.c | 482 | ||||
-rw-r--r-- | src/post/planar/denoise3d.c | 497 | ||||
-rw-r--r-- | src/post/planar/eq.c | 513 | ||||
-rw-r--r-- | src/post/planar/eq2.c | 716 | ||||
-rw-r--r-- | src/post/planar/expand.c | 8 | ||||
-rw-r--r-- | src/post/planar/invert.c | 8 | ||||
-rw-r--r-- | src/post/planar/planar.c | 61 | ||||
-rw-r--r-- | src/post/planar/unsharp.c | 542 |
9 files changed, 2825 insertions, 19 deletions
diff --git a/src/post/planar/Makefile.am b/src/post/planar/Makefile.am index 2d7f9ac1a..4a4db3af4 100644 --- a/src/post/planar/Makefile.am +++ b/src/post/planar/Makefile.am @@ -4,17 +4,10 @@ AM_CFLAGS = @ANSI_FLAGS@ libdir = $(XINE_PLUGINDIR)/post -lib_LTLIBRARIES = xineplug_post_invert.la xineplug_post_expand.la -# xineplug_post_deinterlace.la +lib_LTLIBRARIES = xineplug_post_planar.la -xineplug_post_invert_la_SOURCES = invert.c -xineplug_post_invert_la_LIBADD = $(XINE_LIB) -xineplug_post_invert_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ +xineplug_post_planar_la_SOURCES = planar.c invert.c expand.c boxblur.c \ + denoise3d.c eq.c eq2.c unsharp.c +xineplug_post_planar_la_LIBADD = $(XINE_LIB) -lm +xineplug_post_planar_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ -xineplug_post_expand_la_SOURCES = expand.c -xineplug_post_expand_la_LIBADD = $(XINE_LIB) -xineplug_post_expand_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ - -# xineplug_post_deinterlace_la_SOURCES = deinterlace.c -# xineplug_post_deinterlace_la_LIBADD = $(XINE_LIB) -# xineplug_post_deinterlace_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ diff --git a/src/post/planar/boxblur.c b/src/post/planar/boxblur.c new file mode 100644 index 000000000..32aea491e --- /dev/null +++ b/src/post/planar/boxblur.c @@ -0,0 +1,482 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: boxblur.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * mplayer's boxblur + * Copyright (C) 2002 Michael Niedermayer <michaelni@gmx.at> + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" +#include <pthread.h> + +/* plugin class initialization function */ +void *boxblur_init_plugin(xine_t *xine, void *); + +#if 0 /* moved to planar.c */ +/* plugin catalog information */ +post_info_t boxblur_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "boxblur", XINE_VERSION_CODE, &boxblur_special_info, &boxblur_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; +#endif + +typedef struct post_plugin_boxblur_s post_plugin_boxblur_t; + +/* + * this is the struct used by "parameters api" + */ +typedef struct boxblur_parameters_s { + + int luma_radius; + int luma_power; + int chroma_radius; + int chroma_power; + +} boxblur_parameters_t; + +/* + * description of params struct + */ +START_PARAM_DESCR( boxblur_parameters_t ) +PARAM_ITEM( POST_PARAM_TYPE_INT, luma_radius, NULL, 0, 10, 0, + "radius of luma blur" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, luma_power, NULL, 0, 10, 0, + "power of luma blur" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, chroma_radius, NULL, -1, 10, 0, + "radius of chroma blur (-1 = same as luma)" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, chroma_power, NULL, -1, 10, 0, + "power of chroma blur (-1 = same as luma)" ) +END_PARAM_DESCR( param_descr ) + + +/* plugin structure */ +struct post_plugin_boxblur_s { + post_plugin_t post; + + /* private data */ + xine_video_port_t *vo_port; + xine_stream_t *stream; + + boxblur_parameters_t params; + + pthread_mutex_t lock; +}; + + +static int set_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)this_gen; + boxblur_parameters_t *param = (boxblur_parameters_t *)param_gen; + + pthread_mutex_lock (&this->lock); + + memcpy( &this->params, param, sizeof(boxblur_parameters_t) ); + + pthread_mutex_unlock (&this->lock); + + return 1; +} + +static int get_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)this_gen; + boxblur_parameters_t *param = (boxblur_parameters_t *)param_gen; + + + memcpy( param, &this->params, sizeof(boxblur_parameters_t) ); + + return 1; +} + +static xine_post_api_descr_t * get_param_descr (void) { + return ¶m_descr; +} + +static xine_post_api_t post_api = { + set_parameters, + get_parameters, + get_param_descr, +}; + +typedef struct post_boxblur_out_s post_boxblur_out_t; +struct post_boxblur_out_s { + xine_post_out_t xine_out; + + post_plugin_boxblur_t *plugin; +}; + +/* plugin class functions */ +static post_plugin_t *boxblur_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target); +static char *boxblur_get_identifier(post_class_t *class_gen); +static char *boxblur_get_description(post_class_t *class_gen); +static void boxblur_class_dispose(post_class_t *class_gen); + +/* plugin instance functions */ +static void boxblur_dispose(post_plugin_t *this_gen); + +/* rewire function */ +static int boxblur_rewire(xine_post_out_t *output, void *data); + +/* replaced video_port functions */ +static void boxblur_open(xine_video_port_t *port_gen, xine_stream_t *stream); +static vo_frame_t *boxblur_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags); +static void boxblur_close(xine_video_port_t *port_gen, xine_stream_t *stream); + +/* replaced vo_frame functions */ +static int boxblur_draw(vo_frame_t *frame, xine_stream_t *stream); + + +void *boxblur_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 = boxblur_open_plugin; + class->get_identifier = boxblur_get_identifier; + class->get_description = boxblur_get_description; + class->dispose = boxblur_class_dispose; + + return class; +} + + +static post_plugin_t *boxblur_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target) +{ + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)malloc(sizeof(post_plugin_boxblur_t)); + xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + xine_post_in_t *input_api = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + post_boxblur_out_t *output = (post_boxblur_out_t *)malloc(sizeof(post_boxblur_out_t)); + post_video_port_t *port; + + if (!this || !input || !output || !video_target || !video_target[0]) { + free(this); + free(input); + free(output); + return NULL; + } + + this->stream = NULL; + + this->params.luma_radius = 2; + this->params.luma_power = 1; + this->params.chroma_radius = -1; + this->params.chroma_power = -1; + + pthread_mutex_init (&this->lock, NULL); + + port = post_intercept_video_port(&this->post, video_target[0]); + /* replace with our own get_frame function */ + port->port.open = boxblur_open; + port->port.get_frame = boxblur_get_frame; + port->port.close = boxblur_close; + + input->name = "video"; + input->type = XINE_POST_DATA_VIDEO; + input->data = (xine_video_port_t *)&port->port; + + input_api->name = "parameters"; + input_api->type = XINE_POST_DATA_PARAMETERS; + input_api->data = &post_api; + + output->xine_out.name = "boxblured video"; + output->xine_out.type = XINE_POST_DATA_VIDEO; + output->xine_out.data = (xine_video_port_t **)&port->original_port; + output->xine_out.rewire = boxblur_rewire; + output->plugin = this; + + this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *)); + this->post.xine_post.audio_input[0] = NULL; + this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 2); + this->post.xine_post.video_input[0] = &port->port; + this->post.xine_post.video_input[1] = NULL; + + this->post.input = xine_list_new(); + this->post.output = xine_list_new(); + + xine_list_append_content(this->post.input, input); + xine_list_append_content(this->post.input, input_api); + xine_list_append_content(this->post.output, output); + + this->post.dispose = boxblur_dispose; + + return &this->post; +} + +static char *boxblur_get_identifier(post_class_t *class_gen) +{ + return "boxblur"; +} + +static char *boxblur_get_description(post_class_t *class_gen) +{ + return "box blur filter from mplayer"; +} + +static void boxblur_class_dispose(post_class_t *class_gen) +{ + free(class_gen); +} + + +static void boxblur_dispose(post_plugin_t *this_gen) +{ + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)this_gen; + post_boxblur_out_t *output = (post_boxblur_out_t *)xine_list_first_content(this->post.output); + xine_video_port_t *port = *(xine_video_port_t **)output->xine_out.data; + + if (this->stream) + port->close(port, this->stream); + + free(this->post.xine_post.audio_input); + free(this->post.xine_post.video_input); + free(xine_list_first_content(this->post.input)); + free(xine_list_first_content(this->post.output)); + xine_list_free(this->post.input); + xine_list_free(this->post.output); + free(this); +} + + +static int boxblur_rewire(xine_post_out_t *output_gen, void *data) +{ + post_boxblur_out_t *output = (post_boxblur_out_t *)output_gen; + xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; + xine_video_port_t *new_port = (xine_video_port_t *)data; + + if (!data) + return 0; + + if (output->plugin->stream) { + /* register our stream at the new output port */ + old_port->close(old_port, output->plugin->stream); + new_port->open(new_port, output->plugin->stream); + } + /* reconnect ourselves */ + *(xine_video_port_t **)output_gen->data = new_port; + + return 1; +} + +static void boxblur_open(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)port->post; + this->stream = stream; + port->original_port->open(port->original_port, stream); +} + +static vo_frame_t *boxblur_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + vo_frame_t *frame; + + frame = port->original_port->get_frame(port->original_port, + width, height, ratio_code, format, flags); + + post_intercept_video_frame(frame, port); + /* replace with our own draw function */ + frame->draw = boxblur_draw; + /* decoders should not copy the frames, since they won't be displayed */ + frame->copy = NULL; + + return frame; +} + +static void boxblur_close(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)port->post; + + this->stream = NULL; + + port->original_port->close(port->original_port, stream); +} + + +static inline void blur(uint8_t *dst, uint8_t *src, int w, int radius, int dstStep, int srcStep){ + int x; + const int length= radius*2 + 1; + const int inv= ((1<<16) + length/2)/length; + + int sum= 0; + + for(x=0; x<radius; x++){ + sum+= src[x*srcStep]<<1; + } + sum+= src[radius*srcStep]; + + for(x=0; x<=radius; x++){ + sum+= src[(radius+x)*srcStep] - src[(radius-x)*srcStep]; + dst[x*dstStep]= (sum*inv + (1<<15))>>16; + } + + for(; x<w-radius; x++){ + sum+= src[(radius+x)*srcStep] - src[(x-radius-1)*srcStep]; + dst[x*dstStep]= (sum*inv + (1<<15))>>16; + } + + for(; x<w; x++){ + sum+= src[(2*w-radius-x-1)*srcStep] - src[(x-radius-1)*srcStep]; + dst[x*dstStep]= (sum*inv + (1<<15))>>16; + } +} + +static inline void blur2(uint8_t *dst, uint8_t *src, int w, int radius, int power, int dstStep, int srcStep){ + uint8_t temp[2][4096]; + uint8_t *a= temp[0], *b=temp[1]; + + if(radius){ + blur(a, src, w, radius, 1, srcStep); + for(; power>2; power--){ + uint8_t *c; + blur(b, a, w, radius, 1, 1); + c=a; a=b; b=c; + } + if(power>1) + blur(dst, a, w, radius, dstStep, 1); + else{ + int i; + for(i=0; i<w; i++) + dst[i*dstStep]= a[i]; + } + }else{ + int i; + for(i=0; i<w; i++) + dst[i*dstStep]= src[i*srcStep]; + } +} + +static void hBlur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int radius, int power){ + int y; + + if(radius==0 && dst==src) return; + + for(y=0; y<h; y++){ + blur2(dst + y*dstStride, src + y*srcStride, w, radius, power, 1, 1); + } +} + +//FIXME optimize (x before y !!!) +static void vBlur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int radius, int power){ + int x; + + if(radius==0 && dst==src) return; + + for(x=0; x<w; x++){ + blur2(dst + x, src + x, h, radius, power, dstStride, srcStride); + } +} + + +static int boxblur_draw(vo_frame_t *frame, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)frame->port; + post_plugin_boxblur_t *this = (post_plugin_boxblur_t *)port->post; + vo_frame_t *out_frame; + vo_frame_t *yv12_frame; + int chroma_radius, chroma_power; + int cw, ch; + int skip; + + post_restore_video_frame(frame, port); + + if( !frame->bad_frame ) { + + + /* 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, VO_BOTH_FIELDS); + + yv12_frame->pts = frame->pts; + yv12_frame->duration = frame->duration; + extra_info_merge(yv12_frame->extra_info, frame->extra_info); + + /* FIXME: implement! */ + /* yuy2_to_yv12() */ + + } 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, VO_BOTH_FIELDS); + + + extra_info_merge(out_frame->extra_info, frame->extra_info); + + out_frame->pts = frame->pts; + out_frame->duration = frame->duration; + + pthread_mutex_lock (&this->lock); + + chroma_radius = (this->params.chroma_radius != -1) ? this->params.chroma_radius : + this->params.luma_radius; + chroma_power = (this->params.chroma_power != -1) ? this->params.chroma_power : + this->params.luma_power; + cw = yv12_frame->width/2; + ch = yv12_frame->height/2; + + hBlur(out_frame->base[0], yv12_frame->base[0], yv12_frame->width, yv12_frame->height, + out_frame->pitches[0], yv12_frame->pitches[0], this->params.luma_radius, this->params.luma_power); + hBlur(out_frame->base[1], yv12_frame->base[1], cw,ch, + out_frame->pitches[1], yv12_frame->pitches[1], chroma_radius, chroma_power); + hBlur(out_frame->base[2], yv12_frame->base[2], cw,ch, + out_frame->pitches[2], yv12_frame->pitches[2], chroma_radius, chroma_power); + + vBlur(out_frame->base[0], out_frame->base[0], yv12_frame->width, yv12_frame->height, + out_frame->pitches[0], out_frame->pitches[0], this->params.luma_radius, this->params.luma_power); + vBlur(out_frame->base[1], out_frame->base[1], cw,ch, + out_frame->pitches[1], out_frame->pitches[1], chroma_radius, chroma_power); + vBlur(out_frame->base[2], out_frame->base[2], cw,ch, + out_frame->pitches[2], out_frame->pitches[2], chroma_radius, chroma_power); + + pthread_mutex_unlock (&this->lock); + + skip = out_frame->draw(out_frame, stream); + + frame->vpts = out_frame->vpts; + + out_frame->free(out_frame); + yv12_frame->free(yv12_frame); + + } else { + skip = frame->draw(frame, stream); + } + + + return skip; +} diff --git a/src/post/planar/denoise3d.c b/src/post/planar/denoise3d.c new file mode 100644 index 000000000..53bab335f --- /dev/null +++ b/src/post/planar/denoise3d.c @@ -0,0 +1,497 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: denoise3d.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * mplayer's denoise3d + * Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org> + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" +#include <math.h> +#include <pthread.h> + +#define PARAM1_DEFAULT 4.0 +#define PARAM2_DEFAULT 3.0 +#define PARAM3_DEFAULT 6.0 +#define MAX_LINE_WIDTH 2048 + + +/* plugin class initialization function */ +void *denoise3d_init_plugin(xine_t *xine, void *); + + +#if 0 /* moved to planar.c */ +/* plugin catalog information */ +post_info_t denoise3d_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "denoise3d", XINE_VERSION_CODE, &denoise3d_special_info, &denoise3d_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; +#endif + +typedef struct post_plugin_denoise3d_s post_plugin_denoise3d_t; + + +/* + * this is the struct used by "parameters api" + */ +typedef struct denoise3d_parameters_s { + + double luma; + double chroma; + double time; + +} denoise3d_parameters_t; + +/* + * description of params struct + */ +START_PARAM_DESCR( denoise3d_parameters_t ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, luma, NULL, 0, 10, 0, + "spatial luma strength" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, chroma, NULL, 0, 10, 0, + "spatial chroma strength" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, time, NULL, 0, 10, 0, + "temporal strength" ) +END_PARAM_DESCR( param_descr ) + + +/* plugin structure */ +struct post_plugin_denoise3d_s { + post_plugin_t post; + + /* private data */ + xine_video_port_t *vo_port; + xine_stream_t *stream; + + denoise3d_parameters_t params; + + int Coefs[4][512]; + unsigned char Line[MAX_LINE_WIDTH]; + vo_frame_t *prev_frame; + + pthread_mutex_t lock; +}; + +#define ABS(A) ( (A) > 0 ? (A) : -(A) ) + +static void PrecalcCoefs(int *Ct, double Dist25) +{ + int i; + double Gamma, Simil; + + Gamma = log(0.25) / log(1.0 - Dist25/255.0); + + for (i = -256; i <= 255; i++) + { + Simil = 1.0 - ABS(i) / 255.0; + Ct[256+i] = pow(Simil, Gamma) * 65536; + } +} + +static int set_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)this_gen; + denoise3d_parameters_t *param = (denoise3d_parameters_t *)param_gen; + double ChromTmp; + + pthread_mutex_lock (&this->lock); + + if( &this->params != param ) + memcpy( &this->params, param, sizeof(denoise3d_parameters_t) ); + + ChromTmp = this->params.time * this->params.chroma / this->params.luma; + + PrecalcCoefs(this->Coefs[0], this->params.luma); + PrecalcCoefs(this->Coefs[1], this->params.time); + PrecalcCoefs(this->Coefs[2], this->params.chroma); + PrecalcCoefs(this->Coefs[3], ChromTmp); + + pthread_mutex_unlock (&this->lock); + + return 1; +} + +static int get_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)this_gen; + denoise3d_parameters_t *param = (denoise3d_parameters_t *)param_gen; + + + memcpy( param, &this->params, sizeof(denoise3d_parameters_t) ); + + return 1; +} + +static xine_post_api_descr_t * get_param_descr (void) { + return ¶m_descr; +} + +static xine_post_api_t post_api = { + set_parameters, + get_parameters, + get_param_descr, +}; + +typedef struct post_denoise3d_out_s post_denoise3d_out_t; +struct post_denoise3d_out_s { + xine_post_out_t xine_out; + + post_plugin_denoise3d_t *plugin; +}; + +/* plugin class functions */ +static post_plugin_t *denoise3d_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target); +static char *denoise3d_get_identifier(post_class_t *class_gen); +static char *denoise3d_get_description(post_class_t *class_gen); +static void denoise3d_class_dispose(post_class_t *class_gen); + +/* plugin instance functions */ +static void denoise3d_dispose(post_plugin_t *this_gen); + +/* rewire function */ +static int denoise3d_rewire(xine_post_out_t *output, void *data); + +/* replaced video_port functions */ +static void denoise3d_open(xine_video_port_t *port_gen, xine_stream_t *stream); +static vo_frame_t *denoise3d_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags); +static void denoise3d_close(xine_video_port_t *port_gen, xine_stream_t *stream); + +/* replaced vo_frame functions */ +static int denoise3d_draw(vo_frame_t *frame, xine_stream_t *stream); + + +void *denoise3d_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 = denoise3d_open_plugin; + class->get_identifier = denoise3d_get_identifier; + class->get_description = denoise3d_get_description; + class->dispose = denoise3d_class_dispose; + + return class; +} + + +static post_plugin_t *denoise3d_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target) +{ + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)malloc(sizeof(post_plugin_denoise3d_t)); + xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + xine_post_in_t *input_api = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + post_denoise3d_out_t *output = (post_denoise3d_out_t *)malloc(sizeof(post_denoise3d_out_t)); + post_video_port_t *port; + + if (!this || !input || !output || !video_target || !video_target[0]) { + free(this); + free(input); + free(output); + return NULL; + } + + this->stream = NULL; + + this->params.luma = PARAM1_DEFAULT; + this->params.chroma = PARAM2_DEFAULT; + this->params.time = PARAM3_DEFAULT; + this->prev_frame = NULL; + + pthread_mutex_init (&this->lock, NULL); + + port = post_intercept_video_port(&this->post, video_target[0]); + /* replace with our own get_frame function */ + port->port.open = denoise3d_open; + port->port.get_frame = denoise3d_get_frame; + port->port.close = denoise3d_close; + + input->name = "video"; + input->type = XINE_POST_DATA_VIDEO; + input->data = (xine_video_port_t *)&port->port; + + input_api->name = "parameters"; + input_api->type = XINE_POST_DATA_PARAMETERS; + input_api->data = &post_api; + + output->xine_out.name = "denoise3d video"; + output->xine_out.type = XINE_POST_DATA_VIDEO; + output->xine_out.data = (xine_video_port_t **)&port->original_port; + output->xine_out.rewire = denoise3d_rewire; + output->plugin = this; + + this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *)); + this->post.xine_post.audio_input[0] = NULL; + this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 2); + this->post.xine_post.video_input[0] = &port->port; + this->post.xine_post.video_input[1] = NULL; + + this->post.input = xine_list_new(); + this->post.output = xine_list_new(); + + xine_list_append_content(this->post.input, input); + xine_list_append_content(this->post.input, input_api); + xine_list_append_content(this->post.output, output); + + this->post.dispose = denoise3d_dispose; + + set_parameters ((xine_post_t *)this, &this->params); + + return &this->post; +} + +static char *denoise3d_get_identifier(post_class_t *class_gen) +{ + return "denoise3d"; +} + +static char *denoise3d_get_description(post_class_t *class_gen) +{ + return "3D Denoiser (variable lowpass filter)"; +} + +static void denoise3d_class_dispose(post_class_t *class_gen) +{ + free(class_gen); +} + + +static void denoise3d_dispose(post_plugin_t *this_gen) +{ + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)this_gen; + post_denoise3d_out_t *output = (post_denoise3d_out_t *)xine_list_first_content(this->post.output); + xine_video_port_t *port = *(xine_video_port_t **)output->xine_out.data; + + if (this->stream) + port->close(port, this->stream); + + free(this->post.xine_post.audio_input); + free(this->post.xine_post.video_input); + free(xine_list_first_content(this->post.input)); + free(xine_list_first_content(this->post.output)); + xine_list_free(this->post.input); + xine_list_free(this->post.output); + free(this); +} + + +static int denoise3d_rewire(xine_post_out_t *output_gen, void *data) +{ + post_denoise3d_out_t *output = (post_denoise3d_out_t *)output_gen; + xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; + xine_video_port_t *new_port = (xine_video_port_t *)data; + + if (!data) + return 0; + + if (output->plugin->stream) { + /* register our stream at the new output port */ + old_port->close(old_port, output->plugin->stream); + new_port->open(new_port, output->plugin->stream); + } + /* reconnect ourselves */ + *(xine_video_port_t **)output_gen->data = new_port; + + return 1; +} + +static void denoise3d_open(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)port->post; + this->stream = stream; + port->original_port->open(port->original_port, stream); +} + +static vo_frame_t *denoise3d_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + vo_frame_t *frame; + + frame = port->original_port->get_frame(port->original_port, + width, height, ratio_code, format, flags); + + post_intercept_video_frame(frame, port); + /* replace with our own draw function */ + frame->draw = denoise3d_draw; + /* decoders should not copy the frames, since they won't be displayed */ + frame->copy = NULL; + + return frame; +} + +static void denoise3d_close(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)port->post; + + if(this->prev_frame) { + this->prev_frame->free(this->prev_frame); + this->prev_frame = NULL; + } + + this->stream = NULL; + + port->original_port->close(port->original_port, stream); +} + +#define LowPass(Prev, Curr, Coef) (((Prev)*Coef[Prev - Curr] + (Curr)*(65536-(Coef[Prev - Curr]))) / 65536) + +static void deNoise(unsigned char *Frame, // mpi->planes[x] + unsigned char *FramePrev, // pmpi->planes[x] + unsigned char *FrameDest, // dmpi->planes[x] + unsigned char *LineAnt, // vf->priv->Line (width bytes) + int W, int H, int sStride, int pStride, int dStride, + int *Horizontal, int *Vertical, int *Temporal) +{ + int X, Y; + int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0; + unsigned char PixelAnt; + + /* First pixel has no left nor top neightbour. Only previous frame */ + LineAnt[0] = PixelAnt = Frame[0]; + FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal); + + /* Fist line has no top neightbour. Only left one for each pixel and + * last frame */ + for (X = 1; X < W; X++) + { + PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal); + LineAnt[X] = PixelAnt; + FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal); + } + + for (Y = 1; Y < H; Y++) + { + sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride; + /* First pixel on each line doesn't have previous pixel */ + PixelAnt = Frame[sLineOffs]; + LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical); + FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal); + + for (X = 1; X < W; X++) + { + /* The rest are normal */ + PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal); + LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical); + FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal); + } + } +} + + +static int denoise3d_draw(vo_frame_t *frame, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)frame->port; + post_plugin_denoise3d_t *this = (post_plugin_denoise3d_t *)port->post; + vo_frame_t *out_frame; + vo_frame_t *prev_frame; + vo_frame_t *yv12_frame; + int cw, ch; + int skip; + + post_restore_video_frame(frame, port); + + if( !frame->bad_frame ) { + + + /* 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, VO_BOTH_FIELDS); + + yv12_frame->pts = frame->pts; + yv12_frame->duration = frame->duration; + extra_info_merge(yv12_frame->extra_info, frame->extra_info); + + /* FIXME: implement! */ + /* yuy2_to_yv12() */ + + } 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, VO_BOTH_FIELDS); + + + extra_info_merge(out_frame->extra_info, frame->extra_info); + + out_frame->pts = frame->pts; + out_frame->duration = frame->duration; + + pthread_mutex_lock (&this->lock); + + cw = yv12_frame->width/2; + ch = yv12_frame->height/2; + prev_frame = (this->prev_frame) ? this->prev_frame : yv12_frame; + + deNoise(yv12_frame->base[0], prev_frame->base[0], out_frame->base[0], + this->Line, yv12_frame->width, yv12_frame->height, + yv12_frame->pitches[0], prev_frame->pitches[0], out_frame->pitches[0], + this->Coefs[0] + 256, + this->Coefs[0] + 256, + this->Coefs[1] + 256); + deNoise(yv12_frame->base[1], prev_frame->base[1], out_frame->base[1], + this->Line, cw, ch, + yv12_frame->pitches[1], prev_frame->pitches[1], out_frame->pitches[1], + this->Coefs[2] + 256, + this->Coefs[2] + 256, + this->Coefs[3] + 256); + deNoise(yv12_frame->base[2], prev_frame->base[2], out_frame->base[2], + this->Line, cw, ch, + yv12_frame->pitches[2], prev_frame->pitches[2], out_frame->pitches[2], + this->Coefs[2] + 256, + this->Coefs[2] + 256, + this->Coefs[3] + 256); + + pthread_mutex_unlock (&this->lock); + + skip = out_frame->draw(out_frame, stream); + + frame->vpts = out_frame->vpts; + + out_frame->free(out_frame); + + if(this->prev_frame) + this->prev_frame->free(this->prev_frame); + this->prev_frame = yv12_frame; + + } else { + skip = frame->draw(frame, stream); + } + + + return skip; +} diff --git a/src/post/planar/eq.c b/src/post/planar/eq.c new file mode 100644 index 000000000..af317e8c2 --- /dev/null +++ b/src/post/planar/eq.c @@ -0,0 +1,513 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: eq.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * mplayer's eq (soft video equalizer) + * Copyright (C) Richard Felker + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" +#include <pthread.h> + + +#ifdef ARCH_X86 +static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride, + int w, int h, int brightness, int contrast) +{ + int i; + int pel; + int dstep = dstride-w; + int sstep = sstride-w; + short brvec[4]; + short contvec[4]; + + contrast = ((contrast+100)*256*16)/100; + brightness = ((brightness+100)*511)/200-128 - contrast/32; + + brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; + contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; + + while (h--) { + asm volatile ( + "movq (%5), %%mm3 \n\t" + "movq (%6), %%mm4 \n\t" + "pxor %%mm0, %%mm0 \n\t" + "movl %4, %%eax\n\t" + ".balign 16 \n\t" + "1: \n\t" + "movq (%0), %%mm1 \n\t" + "movq (%0), %%mm2 \n\t" + "punpcklbw %%mm0, %%mm1 \n\t" + "punpckhbw %%mm0, %%mm2 \n\t" + "psllw $4, %%mm1 \n\t" + "psllw $4, %%mm2 \n\t" + "pmulhw %%mm4, %%mm1 \n\t" + "pmulhw %%mm4, %%mm2 \n\t" + "paddw %%mm3, %%mm1 \n\t" + "paddw %%mm3, %%mm2 \n\t" + "packuswb %%mm2, %%mm1 \n\t" + "addl $8, %0 \n\t" + "movq %%mm1, (%1) \n\t" + "addl $8, %1 \n\t" + "decl %%eax \n\t" + "jnz 1b \n\t" + : "=r" (src), "=r" (dest) + : "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec) + : "%eax" + ); + + for (i = w&7; i; i--) + { + pel = ((*src++* contrast)>>12) + brightness; + if(pel&768) pel = (-pel)>>31; + *dest++ = pel; + } + + src += sstep; + dest += dstep; + } + asm volatile ( "emms \n\t" ::: "memory" ); +} +#endif + +static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride, + int w, int h, int brightness, int contrast) +{ + int i; + int pel; + int dstep = dstride-w; + int sstep = sstride-w; + + contrast = ((contrast+100)*256*256)/100; + brightness = ((brightness+100)*511)/200-128 - contrast/512; + + while (h--) { + for (i = w; i; i--) + { + pel = ((*src++* contrast)>>16) + brightness; + if(pel&768) pel = (-pel)>>31; + *dest++ = pel; + } + src += sstep; + dest += dstep; + } +} + +static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride, + int w, int h, int brightness, int contrast); + + +/* plugin class initialization function */ +void *eq_init_plugin(xine_t *xine, void *); + +#if 0 /* moved to planar.c */ +/* plugin catalog information */ +post_info_t eq_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "eq", XINE_VERSION_CODE, &eq_special_info, &eq_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; +#endif + +typedef struct post_plugin_eq_s post_plugin_eq_t; + +/* + * this is the struct used by "parameters api" + */ +typedef struct eq_parameters_s { + + int brightness; + int contrast; + +} eq_parameters_t; + +/* + * description of params struct + */ +START_PARAM_DESCR( eq_parameters_t ) +PARAM_ITEM( POST_PARAM_TYPE_INT, brightness, NULL, -100, 100, 0, + "brightness" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, contrast, NULL, -100, 100, 0, + "contrast" ) +END_PARAM_DESCR( param_descr ) + + +/* plugin structure */ +struct post_plugin_eq_s { + post_plugin_t post; + + /* private data */ + xine_video_port_t *vo_port; + xine_stream_t *stream; + + eq_parameters_t params; + + pthread_mutex_t lock; +}; + + +static int set_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_eq_t *this = (post_plugin_eq_t *)this_gen; + eq_parameters_t *param = (eq_parameters_t *)param_gen; + + pthread_mutex_lock (&this->lock); + + memcpy( &this->params, param, sizeof(eq_parameters_t) ); + + pthread_mutex_unlock (&this->lock); + + return 1; +} + +static int get_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_eq_t *this = (post_plugin_eq_t *)this_gen; + eq_parameters_t *param = (eq_parameters_t *)param_gen; + + + memcpy( param, &this->params, sizeof(eq_parameters_t) ); + + return 1; +} + +static xine_post_api_descr_t * get_param_descr (void) { + return ¶m_descr; +} + +static xine_post_api_t post_api = { + set_parameters, + get_parameters, + get_param_descr, +}; + +typedef struct post_eq_out_s post_eq_out_t; +struct post_eq_out_s { + xine_post_out_t xine_out; + + post_plugin_eq_t *plugin; +}; + +/* plugin class functions */ +static post_plugin_t *eq_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target); +static char *eq_get_identifier(post_class_t *class_gen); +static char *eq_get_description(post_class_t *class_gen); +static void eq_class_dispose(post_class_t *class_gen); + +/* plugin instance functions */ +static void eq_dispose(post_plugin_t *this_gen); + +/* rewire function */ +static int eq_rewire(xine_post_out_t *output, void *data); + +/* replaced video_port functions */ +static int eq_get_property(xine_video_port_t *port_gen, int property); +static int eq_set_property(xine_video_port_t *port_gen, int property, int value); +static void eq_open(xine_video_port_t *port_gen, xine_stream_t *stream); +static vo_frame_t *eq_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags); +static void eq_close(xine_video_port_t *port_gen, xine_stream_t *stream); + +/* replaced vo_frame functions */ +static int eq_draw(vo_frame_t *frame, xine_stream_t *stream); + + +void *eq_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 = eq_open_plugin; + class->get_identifier = eq_get_identifier; + class->get_description = eq_get_description; + class->dispose = eq_class_dispose; + + return class; +} + + +static post_plugin_t *eq_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target) +{ + post_plugin_eq_t *this = (post_plugin_eq_t *)malloc(sizeof(post_plugin_eq_t)); + xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + xine_post_in_t *input_api = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + post_eq_out_t *output = (post_eq_out_t *)malloc(sizeof(post_eq_out_t)); + post_video_port_t *port; + + if (!this || !input || !output || !video_target || !video_target[0]) { + free(this); + free(input); + free(output); + return NULL; + } + + this->stream = NULL; + + process = process_C; +#ifdef ARCH_X86 + if( xine_mm_accel() & MM_ACCEL_X86_MMX ) + process = process_MMX; +#endif + + this->params.brightness = 0; + this->params.contrast = 0; + + pthread_mutex_init (&this->lock, NULL); + + port = post_intercept_video_port(&this->post, video_target[0]); + /* replace with our own get_frame function */ + port->port.open = eq_open; + port->port.get_frame = eq_get_frame; + port->port.close = eq_close; + port->port.get_property = eq_get_property; + port->port.set_property = eq_set_property; + + input->name = "video"; + input->type = XINE_POST_DATA_VIDEO; + input->data = (xine_video_port_t *)&port->port; + + input_api->name = "parameters"; + input_api->type = XINE_POST_DATA_PARAMETERS; + input_api->data = &post_api; + + output->xine_out.name = "eqd video"; + output->xine_out.type = XINE_POST_DATA_VIDEO; + output->xine_out.data = (xine_video_port_t **)&port->original_port; + output->xine_out.rewire = eq_rewire; + output->plugin = this; + + this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *)); + this->post.xine_post.audio_input[0] = NULL; + this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 2); + this->post.xine_post.video_input[0] = &port->port; + this->post.xine_post.video_input[1] = NULL; + + this->post.input = xine_list_new(); + this->post.output = xine_list_new(); + + xine_list_append_content(this->post.input, input); + xine_list_append_content(this->post.input, input_api); + xine_list_append_content(this->post.output, output); + + this->post.dispose = eq_dispose; + + return &this->post; +} + +static char *eq_get_identifier(post_class_t *class_gen) +{ + return "eq"; +} + +static char *eq_get_description(post_class_t *class_gen) +{ + return "soft video equalizer"; +} + +static void eq_class_dispose(post_class_t *class_gen) +{ + free(class_gen); +} + + +static void eq_dispose(post_plugin_t *this_gen) +{ + post_plugin_eq_t *this = (post_plugin_eq_t *)this_gen; + post_eq_out_t *output = (post_eq_out_t *)xine_list_first_content(this->post.output); + xine_video_port_t *port = *(xine_video_port_t **)output->xine_out.data; + + if (this->stream) + port->close(port, this->stream); + + free(this->post.xine_post.audio_input); + free(this->post.xine_post.video_input); + free(xine_list_first_content(this->post.input)); + free(xine_list_first_content(this->post.output)); + xine_list_free(this->post.input); + xine_list_free(this->post.output); + free(this); +} + + +static int eq_rewire(xine_post_out_t *output_gen, void *data) +{ + post_eq_out_t *output = (post_eq_out_t *)output_gen; + xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; + xine_video_port_t *new_port = (xine_video_port_t *)data; + + if (!data) + return 0; + + if (output->plugin->stream) { + /* register our stream at the new output port */ + old_port->close(old_port, output->plugin->stream); + new_port->open(new_port, output->plugin->stream); + } + /* reconnect ourselves */ + *(xine_video_port_t **)output_gen->data = new_port; + + return 1; +} + +static int eq_get_property(xine_video_port_t *port_gen, int property) { + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_eq_t *this = (post_plugin_eq_t *)port->post; + if( property == XINE_PARAM_VO_BRIGHTNESS ) + return 65535 * (this->params.brightness + 100) / 200; + else if( property == XINE_PARAM_VO_CONTRAST ) + return 65535 * (this->params.contrast + 100) / 200; + else + return port->original_port->get_property(port->original_port, property); +} + +static int eq_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_eq_t *this = (post_plugin_eq_t *)port->post; + if( property == XINE_PARAM_VO_BRIGHTNESS ) { + pthread_mutex_lock (&this->lock); + this->params.brightness = (200 * value / 65535) - 100; + pthread_mutex_unlock (&this->lock); + return value; + } else if( property == XINE_PARAM_VO_CONTRAST ) { + pthread_mutex_lock (&this->lock); + this->params.contrast = (200 * value / 65535) - 100; + pthread_mutex_unlock (&this->lock); + return value; + } else + return port->original_port->set_property(port->original_port, property, value); +} + +static void eq_open(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_eq_t *this = (post_plugin_eq_t *)port->post; + this->stream = stream; + port->original_port->open(port->original_port, stream); +} + +static vo_frame_t *eq_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + vo_frame_t *frame; + + frame = port->original_port->get_frame(port->original_port, + width, height, ratio_code, format, flags); + + post_intercept_video_frame(frame, port); + /* replace with our own draw function */ + frame->draw = eq_draw; + /* decoders should not copy the frames, since they won't be displayed */ + frame->copy = NULL; + + return frame; +} + +static void eq_close(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_eq_t *this = (post_plugin_eq_t *)port->post; + + this->stream = NULL; + + port->original_port->close(port->original_port, stream); +} + + + + +static int eq_draw(vo_frame_t *frame, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)frame->port; + post_plugin_eq_t *this = (post_plugin_eq_t *)port->post; + vo_frame_t *out_frame; + vo_frame_t *yv12_frame; + int skip; + + post_restore_video_frame(frame, port); + + if( !frame->bad_frame && + ((this->params.brightness != 0) || (this->params.contrast != 0)) ) { + + /* 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, VO_BOTH_FIELDS); + + yv12_frame->pts = frame->pts; + yv12_frame->duration = frame->duration; + extra_info_merge(yv12_frame->extra_info, frame->extra_info); + + /* FIXME: implement! */ + /* yuy2_to_yv12() */ + + } 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, VO_BOTH_FIELDS); + + + extra_info_merge(out_frame->extra_info, frame->extra_info); + + out_frame->pts = frame->pts; + out_frame->duration = frame->duration; + + pthread_mutex_lock (&this->lock); + + process(out_frame->base[0], out_frame->pitches[0], + yv12_frame->base[0], yv12_frame->pitches[0], + frame->width, frame->height, + this->params.brightness, this->params.contrast); + xine_fast_memcpy(out_frame->base[1],yv12_frame->base[1], + yv12_frame->pitches[1] * frame->height/2); + xine_fast_memcpy(out_frame->base[2],yv12_frame->base[2], + yv12_frame->pitches[2] * frame->height/2); + + pthread_mutex_unlock (&this->lock); + + skip = out_frame->draw(out_frame, stream); + + frame->vpts = out_frame->vpts; + + out_frame->free(out_frame); + yv12_frame->free(yv12_frame); + + } else { + skip = frame->draw(frame, stream); + } + + + return skip; +} diff --git a/src/post/planar/eq2.c b/src/post/planar/eq2.c new file mode 100644 index 000000000..599e5e4b0 --- /dev/null +++ b/src/post/planar/eq2.c @@ -0,0 +1,716 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: eq2.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * mplayer's eq2 (soft video equalizer) + * Software equalizer (brightness, contrast, gamma, saturation) + * + * Hampa Hug <hampa@hampa.ch> (original LUT gamma/contrast/brightness filter) + * Daniel Moreno <comac@comac.darktech.org> (saturation, R/G/B gamma support) + * Richard Felker (original MMX contrast/brightness code (vf_eq.c)) + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" +#include <math.h> +#include <pthread.h> + + +/* Per channel parameters */ +typedef struct eq2_param_t { + unsigned char lut[256]; + int lut_clean; + + void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src, + unsigned w, unsigned h, unsigned dstride, unsigned sstride); + + double c; + double b; + double g; +} eq2_param_t; + +typedef struct vf_priv_s { + eq2_param_t param[3]; + + double contrast; + double brightness; + double saturation; + + double gamma; + double rgamma; + double ggamma; + double bgamma; + + unsigned buf_w[3]; + unsigned buf_h[3]; + unsigned char *buf[3]; +} vf_eq2_t; + +static +void create_lut (eq2_param_t *par) +{ + unsigned i; + double g, v; + + g = par->g; + + if ((g < 0.001) || (g > 1000.0)) { + g = 1.0; + } + + g = 1.0 / g; + + for (i = 0; i < 256; i++) { + v = (double) i / 255.0; + v = par->c * (v - 0.5) + 0.5 + par->b; + + if (v <= 0.0) { + par->lut[i] = 0; + } + else { + v = pow (v, g); + + if (v >= 1.0) { + par->lut[i] = 255; + } + else { + par->lut[i] = (unsigned char) (256.0 * v); + } + } + } + + par->lut_clean = 1; +} + + +#ifdef ARCH_X86 +static +void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src, + unsigned w, unsigned h, unsigned dstride, unsigned sstride) +{ + unsigned i; + int contrast, brightness; + unsigned dstep, sstep; + int pel; + short brvec[4]; + short contvec[4]; + +// printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride); + + contrast = (int) (par->c * 256 * 16); + brightness = ((int) (100.0 * par->b + 100.0) * 511) / 200 - 128 - contrast / 32; + + brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; + contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; + + sstep = sstride - w; + dstep = dstride - w; + + while (h-- > 0) { + asm volatile ( + "movq (%5), %%mm3 \n\t" + "movq (%6), %%mm4 \n\t" + "pxor %%mm0, %%mm0 \n\t" + "movl %4, %%eax\n\t" + ".balign 16 \n\t" + "1: \n\t" + "movq (%0), %%mm1 \n\t" + "movq (%0), %%mm2 \n\t" + "punpcklbw %%mm0, %%mm1 \n\t" + "punpckhbw %%mm0, %%mm2 \n\t" + "psllw $4, %%mm1 \n\t" + "psllw $4, %%mm2 \n\t" + "pmulhw %%mm4, %%mm1 \n\t" + "pmulhw %%mm4, %%mm2 \n\t" + "paddw %%mm3, %%mm1 \n\t" + "paddw %%mm3, %%mm2 \n\t" + "packuswb %%mm2, %%mm1 \n\t" + "addl $8, %0 \n\t" + "movq %%mm1, (%1) \n\t" + "addl $8, %1 \n\t" + "decl %%eax \n\t" + "jnz 1b \n\t" + : "=r" (src), "=r" (dst) + : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec) + : "%eax" + ); + + for (i = w & 7; i > 0; i--) { + pel = ((*src++ * contrast) >> 12) + brightness; + if (pel & 768) { + pel = (-pel) >> 31; + } + *dst++ = pel; + } + + src += sstep; + dst += dstep; + } + + asm volatile ( "emms \n\t" ::: "memory" ); +} +#endif + +static +void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src, + unsigned w, unsigned h, unsigned dstride, unsigned sstride) +{ + unsigned i, j; + unsigned char *lut; + + if (!par->lut_clean) { + create_lut (par); + } + + lut = par->lut; + + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + dst[i] = lut[src[i]]; + } + + src += sstride; + dst += dstride; + } +} + +static +void check_values (eq2_param_t *par) +{ + /* yuck! floating point comparisons... */ + + if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) { + par->adjust = NULL; + } +#ifdef ARCH_X86 + else if (par->g == 1.0 && (xine_mm_accel() & MM_ACCEL_X86_MMX) ) { + par->adjust = &affine_1d_MMX; + } +#endif + else { + par->adjust = &apply_lut; + } +} + + +static +void set_contrast (vf_eq2_t *eq2, double c) +{ + eq2->contrast = c; + eq2->param[0].c = c; + eq2->param[0].lut_clean = 0; + check_values (&eq2->param[0]); +} + +static +void set_brightness (vf_eq2_t *eq2, double b) +{ + eq2->brightness = b; + eq2->param[0].b = b; + eq2->param[0].lut_clean = 0; + check_values (&eq2->param[0]); +} + +static +void set_gamma (vf_eq2_t *eq2, double g) +{ + eq2->gamma = g; + + eq2->param[0].g = eq2->gamma * eq2->ggamma; + eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma); + eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma); + + eq2->param[0].lut_clean = 0; + eq2->param[1].lut_clean = 0; + eq2->param[2].lut_clean = 0; + + check_values (&eq2->param[0]); + check_values (&eq2->param[1]); + check_values (&eq2->param[2]); +} + +static +void set_saturation (vf_eq2_t *eq2, double s) +{ + eq2->saturation = s; + + eq2->param[1].c = s; + eq2->param[2].c = s; + + eq2->param[1].lut_clean = 0; + eq2->param[2].lut_clean = 0; + + check_values (&eq2->param[1]); + check_values (&eq2->param[2]); +} + + +/* plugin class initialization function */ +void *eq2_init_plugin(xine_t *xine, void *); + +#if 0 /* moved to planar.c */ +/* plugin catalog information */ +post_info_t eq2_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "eq2", XINE_VERSION_CODE, &eq2_special_info, &eq2_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; +#endif + +typedef struct post_plugin_eq2_s post_plugin_eq2_t; + +/* + * this is the struct used by "parameters api" + */ +typedef struct eq2_parameters_s { + + double gamma; + double contrast; + double brightness; + double saturation; + + double rgamma; + double ggamma; + double bgamma; + +} eq2_parameters_t; + +/* + * description of params struct + */ +START_PARAM_DESCR( eq2_parameters_t ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, gamma, NULL, 0, 5, 0, + "gamma" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, brightness, NULL, -1, 1, 0, + "brightness" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, contrast, NULL, 0, 2, 0, + "contrast" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, saturation, NULL, 0, 2, 0, + "saturation" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, rgamma, NULL, 0, 5, 0, + "rgamma" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, ggamma, NULL, 0, 5, 0, + "ggamma" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, bgamma, NULL, 0, 5, 0, + "bgamma" ) +END_PARAM_DESCR( param_descr ) + + +/* plugin structure */ +struct post_plugin_eq2_s { + post_plugin_t post; + + /* private data */ + xine_video_port_t *vo_port; + xine_stream_t *stream; + + eq2_parameters_t params; + vf_eq2_t eq2; + + pthread_mutex_t lock; +}; + + +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 xine_post_api_t post_api = { + set_parameters, + get_parameters, + get_param_descr, +}; + +typedef struct post_eq2_out_s post_eq2_out_t; +struct post_eq2_out_s { + xine_post_out_t xine_out; + + post_plugin_eq2_t *plugin; +}; + +/* 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); + +/* rewire function */ +static int eq2_rewire(xine_post_out_t *output, void *data); + +/* 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); +static void eq2_open(xine_video_port_t *port_gen, xine_stream_t *stream); +static vo_frame_t *eq2_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags); +static void eq2_close(xine_video_port_t *port_gen, xine_stream_t *stream); + +/* 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 *)malloc(sizeof(post_plugin_eq2_t)); + xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + xine_post_in_t *input_api = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + post_eq2_out_t *output = (post_eq2_out_t *)malloc(sizeof(post_eq2_out_t)); + post_video_port_t *port; + vf_eq2_t *eq2; + int i; + + if (!this || !input || !output || !video_target || !video_target[0]) { + free(this); + free(input); + free(output); + return NULL; + } + + this->stream = NULL; + + 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 = post_intercept_video_port(&this->post, video_target[0]); + /* replace with our own get_frame function */ + port->port.open = eq2_open; + port->port.get_frame = eq2_get_frame; + port->port.close = eq2_close; + port->port.get_property = eq2_get_property; + port->port.set_property = eq2_set_property; + + input->name = "video"; + input->type = XINE_POST_DATA_VIDEO; + input->data = (xine_video_port_t *)&port->port; + + input_api->name = "parameters"; + input_api->type = XINE_POST_DATA_PARAMETERS; + input_api->data = &post_api; + + output->xine_out.name = "eqd video"; + output->xine_out.type = XINE_POST_DATA_VIDEO; + output->xine_out.data = (xine_video_port_t **)&port->original_port; + output->xine_out.rewire = eq2_rewire; + output->plugin = this; + + this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *)); + this->post.xine_post.audio_input[0] = NULL; + this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 2); + this->post.xine_post.video_input[0] = &port->port; + this->post.xine_post.video_input[1] = NULL; + + this->post.input = xine_list_new(); + this->post.output = xine_list_new(); + + xine_list_append_content(this->post.input, input); + xine_list_append_content(this->post.input, input_api); + xine_list_append_content(this->post.output, output); + + 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; + post_eq2_out_t *output = (post_eq2_out_t *)xine_list_first_content(this->post.output); + xine_video_port_t *port = *(xine_video_port_t **)output->xine_out.data; + + if (this->stream) + port->close(port, this->stream); + + free(this->post.xine_post.audio_input); + free(this->post.xine_post.video_input); + free(xine_list_first_content(this->post.input)); + free(xine_list_first_content(this->post.output)); + xine_list_free(this->post.input); + xine_list_free(this->post.output); + free(this); +} + + +static int eq2_rewire(xine_post_out_t *output_gen, void *data) +{ + post_eq2_out_t *output = (post_eq2_out_t *)output_gen; + xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; + xine_video_port_t *new_port = (xine_video_port_t *)data; + + if (!data) + return 0; + + if (output->plugin->stream) { + /* register our stream at the new output port */ + old_port->close(old_port, output->plugin->stream); + new_port->open(new_port, output->plugin->stream); + } + /* reconnect ourselves */ + *(xine_video_port_t **)output_gen->data = new_port; + + return 1; +} + +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.contrast) / 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 void eq2_open(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_eq2_t *this = (post_plugin_eq2_t *)port->post; + this->stream = stream; + port->original_port->open(port->original_port, stream); +} + +static vo_frame_t *eq2_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + vo_frame_t *frame; + + frame = port->original_port->get_frame(port->original_port, + width, height, ratio_code, format, flags); + + post_intercept_video_frame(frame, port); + /* replace with our own draw function */ + frame->draw = eq2_draw; + /* decoders should not copy the frames, since they won't be displayed */ + frame->copy = NULL; + + return frame; +} + +static void eq2_close(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_eq2_t *this = (post_plugin_eq2_t *)port->post; + + this->stream = NULL; + + port->original_port->close(port->original_port, stream); +} + + + + +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; + + post_restore_video_frame(frame, port); + + 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, VO_BOTH_FIELDS); + + yv12_frame->pts = frame->pts; + yv12_frame->duration = frame->duration; + extra_info_merge(yv12_frame->extra_info, frame->extra_info); + + /* FIXME: implement! */ + /* yuy2_to_yv12() */ + + } 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, VO_BOTH_FIELDS); + + + extra_info_merge(out_frame->extra_info, frame->extra_info); + + out_frame->pts = frame->pts; + out_frame->duration = frame->duration; + + pthread_mutex_lock (&this->lock); + + for (i = 0; i < 3; i++) { + int height; + height = (i==0) ? frame->height : frame->height/2; + + if (eq2->param[i].adjust != NULL) { + eq2->param[i].adjust (&eq2->param[i], out_frame->base[i], yv12_frame->base[i], + frame->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); + + frame->vpts = out_frame->vpts; + + out_frame->free(out_frame); + yv12_frame->free(yv12_frame); + + } else { + skip = frame->draw(frame, stream); + } + + + return skip; +} diff --git a/src/post/planar/expand.c b/src/post/planar/expand.c index ee4bd1042..01284b3e7 100644 --- a/src/post/planar/expand.c +++ b/src/post/planar/expand.c @@ -31,9 +31,9 @@ /* plugin class initialization function */ -static void *expand_init_plugin(xine_t *xine, void *); - +void *expand_init_plugin(xine_t *xine, void *); +#if 0 /* moved to planar.c */ /* plugin catalog information */ post_info_t expand_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; @@ -42,7 +42,7 @@ plugin_info_t xine_plugin_info[] = { { PLUGIN_POST, 3, "expand", XINE_VERSION_CODE, &expand_special_info, &expand_init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; - +#endif /* plugin structure */ typedef struct post_expand_out_s post_expand_out_t; @@ -77,7 +77,7 @@ static void expand_close(xine_video_port_t *port_gen, xine_stream_t *s static int expand_draw(vo_frame_t *frame, xine_stream_t *stream); -static void *expand_init_plugin(xine_t *xine, void *data) +void *expand_init_plugin(xine_t *xine, void *data) { post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); diff --git a/src/post/planar/invert.c b/src/post/planar/invert.c index 114c22e0b..968539de9 100644 --- a/src/post/planar/invert.c +++ b/src/post/planar/invert.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: invert.c,v 1.9 2003/05/31 18:33:30 miguelfreitas Exp $ + * $Id: invert.c,v 1.10 2003/06/29 18:56:24 miguelfreitas Exp $ */ /* @@ -29,8 +29,9 @@ /* plugin class initialization function */ -static void *invert_init_plugin(xine_t *xine, void *); +void *invert_init_plugin(xine_t *xine, void *); +#if 0 /* moved to planar.c */ /* plugin catalog information */ post_info_t invert_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; @@ -41,6 +42,7 @@ plugin_info_t xine_plugin_info[] = { { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; +#endif /* plugin structure */ typedef struct post_invert_out_s post_invert_out_t; @@ -75,7 +77,7 @@ static void invert_close(xine_video_port_t *port_gen, xine_stream_t *s static int invert_draw(vo_frame_t *frame, xine_stream_t *stream); -static void *invert_init_plugin(xine_t *xine, void *data) +void *invert_init_plugin(xine_t *xine, void *data) { post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); diff --git a/src/post/planar/planar.c b/src/post/planar/planar.c new file mode 100644 index 000000000..96e04da08 --- /dev/null +++ b/src/post/planar/planar.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: planar.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * catalog for planar post plugins + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" + +extern void *invert_init_plugin(xine_t *xine, void *); +post_info_t invert_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *expand_init_plugin(xine_t *xine, void *); +post_info_t expand_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *eq_init_plugin(xine_t *xine, void *); +post_info_t eq_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *boxblur_init_plugin(xine_t *xine, void *); +post_info_t boxblur_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *denoise3d_init_plugin(xine_t *xine, void *); +post_info_t denoise3d_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *eq2_init_plugin(xine_t *xine, void *); +post_info_t eq2_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +extern void *unsharp_init_plugin(xine_t *xine, void *); +post_info_t unsharp_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "expand", XINE_VERSION_CODE+1, &expand_special_info, &expand_init_plugin }, + { PLUGIN_POST, 3, "invert", XINE_VERSION_CODE+1, &invert_special_info, &invert_init_plugin }, + { PLUGIN_POST, 3, "eq", XINE_VERSION_CODE, &eq_special_info, &eq_init_plugin }, + { PLUGIN_POST, 3, "denoise3d", XINE_VERSION_CODE, &denoise3d_special_info, &denoise3d_init_plugin }, + { PLUGIN_POST, 3, "boxblur", XINE_VERSION_CODE, &boxblur_special_info, &boxblur_init_plugin }, + { PLUGIN_POST, 3, "eq2", XINE_VERSION_CODE, &eq2_special_info, &eq2_init_plugin }, + { PLUGIN_POST, 3, "unsharp", XINE_VERSION_CODE, &unsharp_special_info, &unsharp_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; + diff --git a/src/post/planar/unsharp.c b/src/post/planar/unsharp.c new file mode 100644 index 000000000..f293a1818 --- /dev/null +++ b/src/post/planar/unsharp.c @@ -0,0 +1,542 @@ +/* + * Copyright (C) 2000-2003 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * $Id: unsharp.c,v 1.1 2003/06/29 18:56:24 miguelfreitas Exp $ + * + * mplayer's unsharp + * Copyright (C) 2002 Rémi Guyomarch <rguyom@pobox.com> + */ + +#include "xine_internal.h" +#include "post.h" +#include "xineutils.h" +#include <pthread.h> + +#ifndef HAVE_MEMALIGN +#define memalign(a,b) malloc(b) +#endif + + +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +//===========================================================================// + +#define MIN_MATRIX_SIZE 3 +#define MAX_MATRIX_SIZE 63 + +typedef struct FilterParam { + int msizeX, msizeY; + double amount; + uint32_t *SC[MAX_MATRIX_SIZE-1]; +} FilterParam; + +struct vf_priv_s { + FilterParam lumaParam; + FilterParam chromaParam; + int width, height; +}; + + +//===========================================================================// + +/* This code is based on : + +An Efficient algorithm for Gaussian blur using finite-state machines +Frederick M. Waltz and John W. V. Miller + +SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII +Originally published Boston, Nov 98 + +*/ + +static void unsharp( uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp ) { + + uint32_t **SC = fp->SC; + uint32_t SR[MAX_MATRIX_SIZE-1], Tmp1, Tmp2; + uint8_t* src2 = src; // avoid gcc warning + + int32_t res; + int x, y, z; + int amount = fp->amount * 65536.0; + int stepsX = fp->msizeX/2; + int stepsY = fp->msizeY/2; + int scalebits = (stepsX+stepsY)*2; + int32_t halfscale = 1 << ((stepsX+stepsY)*2-1); + + if( !fp->amount ) { + if( src == dst ) + return; + if( dstStride == srcStride ) + xine_fast_memcpy( dst, src, srcStride*height ); + else + for( y=0; y<height; y++, dst+=dstStride, src+=srcStride ) + xine_fast_memcpy( dst, src, width ); + return; + } + + for( y=0; y<2*stepsY; y++ ) + memset( SC[y], 0, sizeof(SC[y][0]) * (width+2*stepsX) ); + + for( y=-stepsY; y<height+stepsY; y++ ) { + if( y < height ) src2 = src; + memset( SR, 0, sizeof(SR[0]) * (2*stepsX-1) ); + for( x=-stepsX; x<width+stepsX; x++ ) { + Tmp1 = x<=0 ? src2[0] : x>=width ? src2[width-1] : src2[x]; + for( z=0; z<stepsX*2; z+=2 ) { + Tmp2 = SR[z+0] + Tmp1; SR[z+0] = Tmp1; + Tmp1 = SR[z+1] + Tmp2; SR[z+1] = Tmp2; + } + for( z=0; z<stepsY*2; z+=2 ) { + Tmp2 = SC[z+0][x+stepsX] + Tmp1; SC[z+0][x+stepsX] = Tmp1; + Tmp1 = SC[z+1][x+stepsX] + Tmp2; SC[z+1][x+stepsX] = Tmp2; + } + if( x>=stepsX && y>=stepsY ) { + uint8_t* srx = src - stepsY*srcStride + x - stepsX; + uint8_t* dsx = dst - stepsY*dstStride + x - stepsX; + + res = (int32_t)*srx + ( ( ( (int32_t)*srx - (int32_t)((Tmp1+halfscale) >> scalebits) ) * amount ) >> 16 ); + *dsx = res>255 ? 255 : res<0 ? 0 : (uint8_t)res; + } + } + if( y >= 0 ) { + dst += dstStride; + src += srcStride; + } + } +} + + +/* plugin class initialization function */ +void *unsharp_init_plugin(xine_t *xine, void *); + +#if 0 /* moved to planar.c */ +/* plugin catalog information */ +post_info_t unsharp_special_info = { XINE_POST_TYPE_VIDEO_FILTER }; + +plugin_info_t xine_plugin_info[] = { + /* type, API, "name", version, special_info, init_function */ + { PLUGIN_POST, 3, "unsharp", XINE_VERSION_CODE, &unsharp_special_info, &unsharp_init_plugin }, + { PLUGIN_NONE, 0, "", 0, NULL, NULL } +}; +#endif + +typedef struct post_plugin_unsharp_s post_plugin_unsharp_t; + +/* + * this is the struct used by "parameters api" + */ +typedef struct unsharp_parameters_s { + + int luma_matrix_width; + int luma_matrix_height; + double luma_amount; + + int chroma_matrix_width; + int chroma_matrix_height; + double chroma_amount; + +} unsharp_parameters_t; + +/* + * description of params struct + */ +START_PARAM_DESCR( unsharp_parameters_t ) +PARAM_ITEM( POST_PARAM_TYPE_INT, luma_matrix_width, NULL, 3, 11, 0, + "width of the matrix (must be odd)" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, luma_matrix_height, NULL, 3, 11, 0, + "height of the matrix (must be odd)" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, luma_amount, NULL, -2, 2, 0, + "relative amount of sharpness/blur (=0 disable, <0 blur, >0 sharpen)" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, chroma_matrix_width, NULL, 3, 11, 0, + "width of the matrix (must be odd)" ) +PARAM_ITEM( POST_PARAM_TYPE_INT, chroma_matrix_height, NULL, 3, 11, 0, + "height of the matrix (must be odd)" ) +PARAM_ITEM( POST_PARAM_TYPE_DOUBLE, chroma_amount, NULL, -2, 2, 0, + "relative amount of sharpness/blur (=0 disable, <0 blur, >0 sharpen)" ) +END_PARAM_DESCR( param_descr ) + + +/* plugin structure */ +struct post_plugin_unsharp_s { + post_plugin_t post; + + /* private data */ + xine_video_port_t *vo_port; + xine_stream_t *stream; + + unsharp_parameters_t params; + struct vf_priv_s priv; + + pthread_mutex_t lock; +}; + + +static int set_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)this_gen; + unsharp_parameters_t *param = (unsharp_parameters_t *)param_gen; + FilterParam *fp; + + pthread_mutex_lock (&this->lock); + + if( &this->params != param ) + memcpy( &this->params, param, sizeof(unsharp_parameters_t) ); + + fp = &this->priv.lumaParam; + // min/max & odd + fp->msizeX = 1 | MIN( MAX( param->luma_matrix_width, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE ); + fp->msizeY = 1 | MIN( MAX( param->luma_matrix_height, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE ); + fp->amount = param->luma_amount; + + fp = &this->priv.chromaParam; + // min/max & odd + fp->msizeX = 1 | MIN( MAX( param->chroma_matrix_width, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE ); + fp->msizeY = 1 | MIN( MAX( param->chroma_matrix_height, MIN_MATRIX_SIZE ), MAX_MATRIX_SIZE ); + fp->amount = param->chroma_amount; + + this->priv.width = this->priv.height = 0; + + pthread_mutex_unlock (&this->lock); + + return 1; +} + +static int get_parameters (xine_post_t *this_gen, void *param_gen) { + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)this_gen; + unsharp_parameters_t *param = (unsharp_parameters_t *)param_gen; + + + memcpy( param, &this->params, sizeof(unsharp_parameters_t) ); + + return 1; +} + +static xine_post_api_descr_t * get_param_descr (void) { + return ¶m_descr; +} + +static xine_post_api_t post_api = { + set_parameters, + get_parameters, + get_param_descr, +}; + +typedef struct post_unsharp_out_s post_unsharp_out_t; +struct post_unsharp_out_s { + xine_post_out_t xine_out; + + post_plugin_unsharp_t *plugin; +}; + +/* plugin class functions */ +static post_plugin_t *unsharp_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target); +static char *unsharp_get_identifier(post_class_t *class_gen); +static char *unsharp_get_description(post_class_t *class_gen); +static void unsharp_class_dispose(post_class_t *class_gen); + +/* plugin instance functions */ +static void unsharp_dispose(post_plugin_t *this_gen); + +/* rewire function */ +static int unsharp_rewire(xine_post_out_t *output, void *data); + +/* replaced video_port functions */ +static void unsharp_open(xine_video_port_t *port_gen, xine_stream_t *stream); +static vo_frame_t *unsharp_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags); +static void unsharp_close(xine_video_port_t *port_gen, xine_stream_t *stream); + +/* replaced vo_frame functions */ +static int unsharp_draw(vo_frame_t *frame, xine_stream_t *stream); + + +void *unsharp_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 = unsharp_open_plugin; + class->get_identifier = unsharp_get_identifier; + class->get_description = unsharp_get_description; + class->dispose = unsharp_class_dispose; + + return class; +} + + +static post_plugin_t *unsharp_open_plugin(post_class_t *class_gen, int inputs, + xine_audio_port_t **audio_target, + xine_video_port_t **video_target) +{ + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)malloc(sizeof(post_plugin_unsharp_t)); + xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + xine_post_in_t *input_api = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); + post_unsharp_out_t *output = (post_unsharp_out_t *)malloc(sizeof(post_unsharp_out_t)); + post_video_port_t *port; + + if (!this || !input || !output || !video_target || !video_target[0]) { + free(this); + free(input); + free(output); + return NULL; + } + + this->stream = NULL; + + this->params.luma_matrix_width = 5; + this->params.luma_matrix_height = 5; + this->params.luma_amount = 0.0; + + this->params.chroma_matrix_width = 3; + this->params.chroma_matrix_height = 3; + this->params.chroma_amount = 0.0; + + pthread_mutex_init (&this->lock, NULL); + + port = post_intercept_video_port(&this->post, video_target[0]); + /* replace with our own get_frame function */ + port->port.open = unsharp_open; + port->port.get_frame = unsharp_get_frame; + port->port.close = unsharp_close; + + input->name = "video"; + input->type = XINE_POST_DATA_VIDEO; + input->data = (xine_video_port_t *)&port->port; + + input_api->name = "parameters"; + input_api->type = XINE_POST_DATA_PARAMETERS; + input_api->data = &post_api; + + output->xine_out.name = "unsharped video"; + output->xine_out.type = XINE_POST_DATA_VIDEO; + output->xine_out.data = (xine_video_port_t **)&port->original_port; + output->xine_out.rewire = unsharp_rewire; + output->plugin = this; + + this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *)); + this->post.xine_post.audio_input[0] = NULL; + this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 2); + this->post.xine_post.video_input[0] = &port->port; + this->post.xine_post.video_input[1] = NULL; + + this->post.input = xine_list_new(); + this->post.output = xine_list_new(); + + xine_list_append_content(this->post.input, input); + xine_list_append_content(this->post.input, input_api); + xine_list_append_content(this->post.output, output); + + set_parameters ((xine_post_t *)this, &this->params); + + this->post.dispose = unsharp_dispose; + + return &this->post; +} + +static char *unsharp_get_identifier(post_class_t *class_gen) +{ + return "unsharp"; +} + +static char *unsharp_get_description(post_class_t *class_gen) +{ + return "unsharp mask & gaussian blur"; +} + +static void unsharp_class_dispose(post_class_t *class_gen) +{ + free(class_gen); +} + + +static void unsharp_dispose(post_plugin_t *this_gen) +{ + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)this_gen; + post_unsharp_out_t *output = (post_unsharp_out_t *)xine_list_first_content(this->post.output); + xine_video_port_t *port = *(xine_video_port_t **)output->xine_out.data; + + if (this->stream) + port->close(port, this->stream); + + free(this->post.xine_post.audio_input); + free(this->post.xine_post.video_input); + free(xine_list_first_content(this->post.input)); + free(xine_list_first_content(this->post.output)); + xine_list_free(this->post.input); + xine_list_free(this->post.output); + free(this); +} + + +static int unsharp_rewire(xine_post_out_t *output_gen, void *data) +{ + post_unsharp_out_t *output = (post_unsharp_out_t *)output_gen; + xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; + xine_video_port_t *new_port = (xine_video_port_t *)data; + + if (!data) + return 0; + + if (output->plugin->stream) { + /* register our stream at the new output port */ + old_port->close(old_port, output->plugin->stream); + new_port->open(new_port, output->plugin->stream); + } + /* reconnect ourselves */ + *(xine_video_port_t **)output_gen->data = new_port; + + return 1; +} + +static void unsharp_open(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)port->post; + this->stream = stream; + port->original_port->open(port->original_port, stream); +} + +static vo_frame_t *unsharp_get_frame(xine_video_port_t *port_gen, uint32_t width, + uint32_t height, int ratio_code, + int format, int flags) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + vo_frame_t *frame; + + frame = port->original_port->get_frame(port->original_port, + width, height, ratio_code, format, flags); + + post_intercept_video_frame(frame, port); + /* replace with our own draw function */ + frame->draw = unsharp_draw; + /* decoders should not copy the frames, since they won't be displayed */ + frame->copy = NULL; + + return frame; +} + +static void unsharp_close(xine_video_port_t *port_gen, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)port_gen; + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)port->post; + + this->stream = NULL; + + port->original_port->close(port->original_port, stream); +} + + + + +static int unsharp_draw(vo_frame_t *frame, xine_stream_t *stream) +{ + post_video_port_t *port = (post_video_port_t *)frame->port; + post_plugin_unsharp_t *this = (post_plugin_unsharp_t *)port->post; + vo_frame_t *out_frame; + vo_frame_t *yv12_frame; + int skip; + + post_restore_video_frame(frame, port); + + if( !frame->bad_frame && + (this->priv.lumaParam.amount || this->priv.chromaParam.amount) ) { + + + /* 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, VO_BOTH_FIELDS); + + yv12_frame->pts = frame->pts; + yv12_frame->duration = frame->duration; + extra_info_merge(yv12_frame->extra_info, frame->extra_info); + + /* FIXME: implement! */ + /* yuy2_to_yv12() */ + + } 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, VO_BOTH_FIELDS); + + + extra_info_merge(out_frame->extra_info, frame->extra_info); + + out_frame->pts = frame->pts; + out_frame->duration = frame->duration; + + pthread_mutex_lock (&this->lock); + + if( frame->width != this->priv.width || frame->height != this->priv.height ) { + int z, stepsX, stepsY; + FilterParam *fp; + + this->priv.width = frame->width; + this->priv.height = frame->height; + + // allocate buffers + fp = &this->priv.lumaParam; + memset( fp->SC, 0, sizeof( fp->SC ) ); + stepsX = fp->msizeX/2; + stepsY = fp->msizeY/2; + for( z=0; z<2*stepsY; z++ ) + fp->SC[z] = memalign( 16, sizeof(*(fp->SC[z])) * (frame->width+2*stepsX) ); + + fp = &this->priv.chromaParam; + memset( fp->SC, 0, sizeof( fp->SC ) ); + stepsX = fp->msizeX/2; + stepsY = fp->msizeY/2; + for( z=0; z<2*stepsY; z++ ) + fp->SC[z] = memalign( 16, sizeof(*(fp->SC[z])) * (frame->width+2*stepsX) ); + } + + unsharp( out_frame->base[0], yv12_frame->base[0], out_frame->pitches[0], yv12_frame->pitches[0], yv12_frame->width, yv12_frame->height, &this->priv.lumaParam ); + unsharp( out_frame->base[1], yv12_frame->base[1], out_frame->pitches[1], yv12_frame->pitches[1], yv12_frame->width/2, yv12_frame->height/2, &this->priv.chromaParam ); + unsharp( out_frame->base[2], yv12_frame->base[2], out_frame->pitches[2], yv12_frame->pitches[2], yv12_frame->width/2, yv12_frame->height/2, &this->priv.chromaParam ); + + pthread_mutex_unlock (&this->lock); + + skip = out_frame->draw(out_frame, stream); + + frame->vpts = out_frame->vpts; + + out_frame->free(out_frame); + yv12_frame->free(yv12_frame); + + } else { + skip = frame->draw(frame, stream); + } + + + return skip; +} |