/*****************************************************************************
- * gradfun.c: wrapper for the gradfun filter from mplayer
+ * gradfun.c: wrapper for the gradfun filter from libav
*****************************************************************************
* Copyright (C) 2010 Laurent Aimar
* $Id$
*
* Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
*
- * This program 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
+ * Based on the work of: Nolan Lum and Loren Merritt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#define RADIUS_TEXT N_("Radius")
#define RADIUS_LONGTEXT N_("Radius in pixels")
-#define STRENGTH_MIN (0.51)
+#define STRENGTH_MIN (0.51f)
#define STRENGTH_MAX (255)
#define STRENGTH_TEXT N_("Strength")
#define STRENGTH_LONGTEXT N_("Strength used to modify the value of a pixel")
vlc_module_begin()
set_description(N_("Gradfun video filter"))
set_shortname(N_("Gradfun"))
- set_help("Debanding algorithm")
+ set_help(N_("Debanding algorithm"))
set_capability("video filter2", 0)
set_category(CAT_VIDEO)
set_subcategory(SUBCAT_VIDEO_VFILTER)
float strength;
int radius;
const vlc_chroma_description_t *chroma;
- void *base_buf;
struct vf_priv_s cfg;
};
const vlc_fourcc_t fourcc = filter->fmt_in.video.i_chroma;
const vlc_chroma_description_t *chroma = vlc_fourcc_GetChromaDescription(fourcc);
- if (!chroma || chroma->plane_count < 3) {
+ if (!chroma || chroma->plane_count < 3 || chroma->pixel_size != 1) {
msg_Err(filter, "Unsupported chroma (%4.4s)", (char*)&fourcc);
return VLC_EGENERIC;
}
sys->radius = var_CreateGetIntegerCommand(filter, CFG_PREFIX "radius");
var_AddCallback(filter, CFG_PREFIX "strength", Callback, NULL);
var_AddCallback(filter, CFG_PREFIX "radius", Callback, NULL);
- sys->base_buf = NULL;
+ sys->cfg.buf = NULL;
struct vf_priv_s *cfg = &sys->cfg;
cfg->thresh = 0.0;
cfg->radius = 0;
cfg->buf = NULL;
- cfg->filter_line = filter_line_c;
- cfg->blur_line = blur_line_c;
#if HAVE_SSE2 && HAVE_6REGS
- if (vlc_CPU() & CPU_CAPABILITY_SSE2)
+ if (vlc_CPU_SSE2())
cfg->blur_line = blur_line_sse2;
+ else
#endif
-#if HAVE_MMX2
- if (vlc_CPU() & CPU_CAPABILITY_MMXEXT)
- cfg->filter_line = filter_line_mmx2;
-#endif
+ cfg->blur_line = blur_line_c;
#if HAVE_SSSE3
- if (vlc_CPU() & CPU_CAPABILITY_SSSE3)
+ if (vlc_CPU_SSSE3())
cfg->filter_line = filter_line_ssse3;
+ else
+#endif
+#if HAVE_MMX2
+ if (vlc_CPU_MMXEXT())
+ cfg->filter_line = filter_line_mmx2;
+ else
#endif
+ cfg->filter_line = filter_line_c;
filter->p_sys = sys;
filter->pf_video_filter = Filter;
var_DelCallback(filter, CFG_PREFIX "radius", Callback, NULL);
var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);
- free(sys->base_buf);
+ vlc_free(sys->cfg.buf);
vlc_mutex_destroy(&sys->lock);
free(sys);
}
}
vlc_mutex_lock(&sys->lock);
- float strength = __MIN(__MAX(sys->strength, STRENGTH_MIN), STRENGTH_MAX);
- int radius = __MIN(__MAX((sys->radius + 1) & ~1, RADIUS_MIN), RADIUS_MAX);
+ float strength = VLC_CLIP(sys->strength, STRENGTH_MIN, STRENGTH_MAX);
+ int radius = VLC_CLIP((sys->radius + 1) & ~1, RADIUS_MIN, RADIUS_MAX);
vlc_mutex_unlock(&sys->lock);
const video_format_t *fmt = &filter->fmt_in.video;
cfg->thresh = (1 << 15) / strength;
if (cfg->radius != radius) {
cfg->radius = radius;
- cfg->buf = vlc_memalign(&sys->base_buf, 16,
+ cfg->buf = vlc_memalign(16,
(((fmt->i_width + 15) & ~15) * (cfg->radius + 1) / 2 + 32) * sizeof(*cfg->buf));
}
int h = fmt->i_height * chroma->p[i].h.num / chroma->p[i].h.den;
int r = (cfg->radius * chroma->p[i].w.num / chroma->p[i].w.den +
cfg->radius * chroma->p[i].h.num / chroma->p[i].h.den) / 2;
- r = __MIN(__MAX((r + 1) & ~1, RADIUS_MIN), RADIUS_MAX);
+ r = VLC_CLIP((r + 1) & ~1, RADIUS_MIN, RADIUS_MAX);
if (__MIN(w, h) > 2 * r && cfg->buf) {
filter_plane(cfg, dstp->p_pixels, srcp->p_pixels,
w, h, dstp->i_pitch, srcp->i_pitch, r);