]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/grain.c
smf: reorder code, no functional changes
[vlc] / modules / video_filter / grain.c
index 4103ff963420e71453e906e04fbdcdcd1a8e0fba..f3102bdf957d753735f6eb233f642701558e7b16 100644 (file)
@@ -6,19 +6,19 @@
  *
  * 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
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -68,11 +68,11 @@ vlc_module_begin()
     set_category(CAT_VIDEO)
     set_subcategory(SUBCAT_VIDEO_VFILTER)
     add_float_with_range(CFG_PREFIX "variance", 2.0, VARIANCE_MIN, VARIANCE_MAX,
-                         NULL, VARIANCE_TEXT, VARIANCE_LONGTEXT, false)
+                         VARIANCE_TEXT, VARIANCE_LONGTEXT, false)
     add_integer_with_range(CFG_PREFIX "period-min", 1, PERIOD_MIN, PERIOD_MAX,
-                           NULL, PERIOD_MIN_TEXT, PERIOD_MIN_LONGTEXT, false)
+                           PERIOD_MIN_TEXT, PERIOD_MIN_LONGTEXT, false)
     add_integer_with_range(CFG_PREFIX "period-max", 3*PERIOD_MAX/4, PERIOD_MIN, PERIOD_MAX,
-                           NULL, PERIOD_MAX_TEXT, PERIOD_MAX_LONGTEXT, false)
+                           PERIOD_MAX_TEXT, PERIOD_MAX_LONGTEXT, false)
     set_callbacks(Open, Close)
 vlc_module_end()
 
@@ -156,6 +156,7 @@ static void BlockBlendC(uint8_t *dst, size_t dst_pitch,
 #ifdef CAN_COMPILE_SSE2
 #define _STRING(x) #x
 #define STRING(x) _STRING(x)
+VLC_SSE
 static void BlockBlendSse2(uint8_t *dst, size_t dst_pitch,
                            const uint8_t *src, size_t src_pitch,
                            const int16_t *noise)
@@ -186,7 +187,7 @@ static void BlockBlendSse2(uint8_t *dst, size_t dst_pitch,
                 [src1]"r"(&src[(2*i+0) * src_pitch]),
                 [src2]"r"(&src[(2*i+1) * src_pitch]),
                 [noise]"r"(&noise[2*i * BANK_SIZE])
-            : "memory");
+            : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "memory");
     }
 #else
 #   error "BLEND_SIZE unsupported"
@@ -240,7 +241,8 @@ static void PlaneFilter(filter_t *filter,
             if (w >= BLEND_SIZE && h >= BLEND_SIZE)
                 sys->blend(dstp, dst->i_pitch, srcp, src->i_pitch, noise);
             else
-                BlockBlend(dstp, dst->i_pitch, srcp, src->i_pitch, noise, w, h);
+                BlockBlend(dstp, dst->i_pitch, srcp, src->i_pitch, noise,
+                           __MIN(w, BLEND_SIZE), __MIN(h, BLEND_SIZE));
         }
     }
     if (sys->emms)
@@ -258,7 +260,7 @@ static picture_t *Filter(filter_t *filter, picture_t *src)
     }
 
     vlc_mutex_lock(&sys->cfg.lock);
-    const double variance = __MIN(__MAX(sys->cfg.variance, VARIANCE_MIN), VARIANCE_MAX);
+    const double variance = VLC_CLIP(sys->cfg.variance, VARIANCE_MIN, VARIANCE_MAX);
     vlc_mutex_unlock(&sys->cfg.lock);
 
     const int scale = 256 * sqrt(variance);
@@ -352,7 +354,7 @@ static int Generate(int16_t *bank, int h_min, int h_max, int v_min, int v_max)
                 vq =  (int)( v * correction * 127 + 0.5);
             else
                 vq = -(int)(-v * correction * 127 + 0.5);
-            bank[i * N + j] = __MIN(__MAX(vq, INT16_MIN), INT16_MAX);
+            bank[i * N + j] = VLC_CLIP(vq, INT16_MIN, INT16_MAX);
         }
     }
     //mtime_t mul_duration = mdate() - tmul_0;
@@ -367,11 +369,10 @@ static int Callback(vlc_object_t *object, char const *cmd,
 {
     filter_t     *filter = (filter_t *)object;
     filter_sys_t *sys = filter->p_sys;
-    VLC_UNUSED(oldval); VLC_UNUSED(data);
+    VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
 
     vlc_mutex_lock(&sys->cfg.lock);
-    //if (!strcmp(cmd, CFG_PREFIX "variance"))
-        sys->cfg.variance = newval.f_float;
+    sys->cfg.variance = newval.f_float;
     vlc_mutex_unlock(&sys->cfg.lock);
 
     return VLC_SUCCESS;
@@ -383,7 +384,7 @@ static int Open(vlc_object_t *object)
 
     const vlc_chroma_description_t *chroma =
         vlc_fourcc_GetChromaDescription(filter->fmt_in.video.i_chroma);
-    if (!chroma || chroma->plane_count < 3) {
+    if (!chroma || chroma->plane_count < 3 || chroma->pixel_size != 1) {
         msg_Err(filter, "Unsupported chroma (%4.4s)",
                 (char*)&(filter->fmt_in.video.i_chroma));
         return VLC_EGENERIC;
@@ -398,8 +399,8 @@ static int Open(vlc_object_t *object)
 
     int cutoff_low = BANK_SIZE - var_InheritInteger(filter, CFG_PREFIX "period-max");
     int cutoff_high= BANK_SIZE - var_InheritInteger(filter, CFG_PREFIX "period-min");
-    cutoff_low  = __MIN(__MAX(cutoff_low,  1), BANK_SIZE - 1);
-    cutoff_high = __MIN(__MAX(cutoff_high, 1), BANK_SIZE - 1);
+    cutoff_low  = VLC_CLIP(cutoff_low, 1, BANK_SIZE - 1);
+    cutoff_high = VLC_CLIP(cutoff_high, 1, BANK_SIZE - 1);
     if (Generate(sys->bank, cutoff_low, cutoff_high, cutoff_low, cutoff_high)) {
         free(sys);
         return VLC_EGENERIC;
@@ -408,7 +409,7 @@ static int Open(vlc_object_t *object)
     sys->blend = BlockBlendC;
     sys->emms  = NULL;
 #if defined(CAN_COMPILE_SSE2) && 1
-    if (vlc_CPU() & CPU_CAPABILITY_SSE2) {
+    if (vlc_CPU_SSE2()) {
         sys->blend = BlockBlendSse2;
         sys->emms  = Emms;
     }
@@ -428,6 +429,7 @@ static void Close(vlc_object_t *object)
     filter_t     *filter = (filter_t *)object;
     filter_sys_t *sys    = filter->p_sys;
 
+    var_DelCallback(filter, CFG_PREFIX "variance", Callback, NULL);
     vlc_mutex_destroy(&sys->cfg.lock);
     free(sys);
 }