summaryrefslogtreecommitdiffstats
path: root/gst/deinterlace2/tvtime/greedyh.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/deinterlace2/tvtime/greedyh.c')
-rw-r--r--gst/deinterlace2/tvtime/greedyh.c266
1 files changed, 216 insertions, 50 deletions
diff --git a/gst/deinterlace2/tvtime/greedyh.c b/gst/deinterlace2/tvtime/greedyh.c
index 623c2d8b..f9d33e74 100644
--- a/gst/deinterlace2/tvtime/greedyh.c
+++ b/gst/deinterlace2/tvtime/greedyh.c
@@ -41,51 +41,244 @@
#include "gstdeinterlace2.h"
#include "speedy.h"
+static const unsigned int GreedyMaxComb = 5;
+static const unsigned int GreedyMotionThreshold = 25;
+static const unsigned int GreedyMotionSense = 30;
-#define MAXCOMB_DEFAULT 5
-#define MOTIONTHRESHOLD_DEFAULT 25
-#define MOTIONSENSE_DEFAULT 30
+void
+greedyDScaler_C (uint8_t * L1, uint8_t * L2, uint8_t * L3, uint8_t * L2P,
+ uint8_t * Dest, int size)
+{
+ int Pos;
+ uint8_t l1_l, l1_1_l, l3_l, l3_1_l;
+ uint8_t l1_c, l1_1_c, l3_c, l3_1_c;
+ uint8_t avg_l, avg_c, avg_l_1, avg_c_1;
+ uint8_t avg_l__1 = 0, avg_c__1 = 0;
+ uint8_t avg_s_l, avg_s_c;
+ uint8_t avg_sc_l, avg_sc_c;
+ uint8_t best_l, best_c;
+ uint16_t mov_l;
+ uint8_t out_l, out_c;
+ uint8_t l2_l, l2_c, lp2_l, lp2_c;
+ uint8_t l2_l_diff, l2_c_diff, lp2_l_diff, lp2_c_diff;
+ uint8_t min_l, min_c, max_l, max_c;
+
+ for (Pos = 0; Pos < size; Pos += 2) {
+ l1_l = L1[0];
+ l1_c = L1[1];
+ l3_l = L3[0];
+ l3_c = L3[1];
+
+ if (Pos == size - 1) {
+ l1_1_l = l1_l;
+ l1_1_c = l1_c;
+ l3_1_l = l3_l;
+ l3_1_c = l3_c;
+ } else {
+ l1_1_l = L1[2];
+ l1_1_c = L1[3];
+ l3_1_l = L3[2];
+ l3_1_c = L3[3];
+ }
+
+ /* Average of L1 and L3 */
+ avg_l = (l1_l + l3_l) / 2;
+ avg_c = (l1_c + l3_c) / 2;
+
+ /* Average of next L1 and next L3 */
+ avg_l_1 = (l1_1_l + l3_1_l) / 2;
+ avg_c_1 = (l1_1_c + l3_1_c) / 2;
+
+ /* Calculate average of one pixel forward and previous */
+ avg_s_l = (avg_l__1 + avg_l_1) / 2;
+ avg_s_c = (avg_c__1 + avg_c_1) / 2;
+
+ /* Calculate average of center and surrounding pixels */
+ avg_sc_l = (avg_l + avg_s_l) / 2;
+ avg_sc_c = (avg_c + avg_s_c) / 2;
+
+ /* move forward */
+ avg_l__1 = avg_l;
+ avg_c__1 = avg_c;
+
+ /* Get best L2/L2P, i.e. least diff from above average */
+ l2_l = L2[0];
+ l2_c = L2[1];
+ lp2_l = L2P[0];
+ lp2_c = L2P[1];
+
+ l2_l_diff = ABS (l2_l - avg_sc_l);
+ l2_c_diff = ABS (l2_c - avg_sc_c);
+
+ lp2_l_diff = ABS (lp2_l - avg_sc_l);
+ lp2_c_diff = ABS (lp2_c - avg_sc_c);
+
+ if (l2_l_diff > lp2_l_diff)
+ best_l = lp2_l;
+ else
+ best_l = l2_l;
+
+ if (l2_c_diff > lp2_c_diff)
+ best_c = lp2_c;
+ else
+ best_c = l2_c;
+
+ /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
+ max_l = MAX (l1_l, l3_l);
+ min_l = MIN (l1_l, l3_l);
-unsigned int GreedyMaxComb;
+ if (max_l < 256 - GreedyMaxComb)
+ max_l += GreedyMaxComb;
+ else
+ max_l = 255;
-unsigned int GreedyMotionThreshold;
+ if (min_l > GreedyMaxComb)
+ min_l -= GreedyMaxComb;
+ else
+ min_l = 0;
-unsigned int GreedyMotionSense;
+ max_c = MAX (l1_c, l3_c);
+ min_c = MIN (l1_c, l3_c);
+ if (max_c < 256 - GreedyMaxComb)
+ max_c += GreedyMaxComb;
+ else
+ max_c = 255;
-#define IS_SSE
-#define SSE_TYPE SSE
-#define FUNCT_NAME greedyDScaler_SSE
+ if (min_c > GreedyMaxComb)
+ min_c -= GreedyMaxComb;
+ else
+ min_c = 0;
+
+ out_l = CLAMP (best_l, min_l, max_l);
+ out_c = CLAMP (best_c, min_c, max_c);
+
+ /* Do motion compensation for luma, i.e. how much
+ * the weave pixel differs */
+ mov_l = ABS (l2_l - lp2_l);
+ if (mov_l > GreedyMotionThreshold)
+ mov_l -= GreedyMotionThreshold;
+ else
+ mov_l = 0;
+
+ mov_l = mov_l * GreedyMotionSense;
+ if (mov_l > 256)
+ mov_l = 256;
+
+ /* Weighted sum on clipped weave pixel and average */
+ out_l = (out_l * (256 - mov_l) + avg_sc_l * mov_l) / 256;
+
+ Dest[0] = out_l;
+ Dest[1] = out_c;
+
+ Dest += 2;
+ L1 += 2;
+ L2 += 2;
+ L3 += 2;
+ L2P += 2;
+ }
+}
+
+#define IS_MMXEXT
+#define SIMD_TYPE MMXEXT
+#define FUNCT_NAME greedyDScaler_MMXEXT
#include "greedyh.asm"
-#undef SSE_TYPE
-#undef IS_SSE
+#undef SIMD_TYPE
+#undef IS_MMXEXT
#undef FUNCT_NAME
-#define IS_3DNOW
+#define IS_TDNOW
+#define SIMD_TYPE TDNOW
#define FUNCT_NAME greedyDScaler_3DNOW
-#define SSE_TYPE 3DNOW
#include "greedyh.asm"
-#undef SSE_TYPE
-#undef IS_3DNOW
+#undef SIMD_TYPE
+#undef IS_TDNOW
#undef FUNCT_NAME
#define IS_MMX
-#define SSE_TYPE MMX
+#define SIMD_TYPE MMX
#define FUNCT_NAME greedyDScaler_MMX
#include "greedyh.asm"
-#undef SSE_TYPE
+#undef SIMD_TYPE
#undef IS_MMX
#undef FUNCT_NAME
-void
+static void
deinterlace_frame_di_greedyh (GstDeinterlace2 * object)
{
- if (object->cpu_feature_flags & OIL_IMPL_FLAG_SSE) {
- greedyh_filter_sse (object);
+ void (*func) (uint8_t * L1, uint8_t * L2, uint8_t * L3, uint8_t * L2P,
+ uint8_t * Dest, int size);
+
+ int InfoIsOdd = 0;
+ int Line;
+ unsigned int Pitch = object->field_stride;
+
+ unsigned char *L1; // ptr to Line1, of 3
+ unsigned char *L2; // ptr to Line2, the weave line
+ unsigned char *L3; // ptr to Line3
+
+ unsigned char *L2P; // ptr to prev Line2
+ unsigned char *Dest = GST_BUFFER_DATA (object->out_buf);
+
+ if (object->cpu_feature_flags & OIL_IMPL_FLAG_MMXEXT) {
+ func = greedyDScaler_MMXEXT;
} else if (object->cpu_feature_flags & OIL_IMPL_FLAG_3DNOW) {
- greedyh_filter_3dnow (object);
+ func = greedyDScaler_3DNOW;
+ } else if (object->cpu_feature_flags & OIL_IMPL_FLAG_MMX) {
+ func = greedyDScaler_MMX;
} else {
- greedyh_filter_mmx (object);
+ func = greedyDScaler_C;
+ }
+
+ // copy first even line no matter what, and the first odd line if we're
+ // processing an EVEN field. (note diff from other deint rtns.)
+
+ if (object->field_history[object->history_count - 1].flags ==
+ PICTURE_INTERLACED_BOTTOM) {
+ InfoIsOdd = 1;
+
+ L1 = GST_BUFFER_DATA (object->field_history[object->history_count - 2].buf);
+ L2 = GST_BUFFER_DATA (object->field_history[object->history_count - 1].buf);
+ L3 = L1 + Pitch;
+ L2P =
+ GST_BUFFER_DATA (object->field_history[object->history_count - 3].buf);
+
+ // copy first even line
+ object->pMemcpy (Dest, L1, object->line_length);
+ Dest += object->output_stride;
+ } else {
+ InfoIsOdd = 0;
+ L1 = GST_BUFFER_DATA (object->field_history[object->history_count - 2].buf);
+ L2 = GST_BUFFER_DATA (object->field_history[object->history_count -
+ 1].buf) + Pitch;
+ L3 = L1 + Pitch;
+ L2P =
+ GST_BUFFER_DATA (object->field_history[object->history_count - 3].buf) +
+ Pitch;
+
+ // copy first even line
+ object->pMemcpy (Dest, GST_BUFFER_DATA (object->field_history[0].buf),
+ object->line_length);
+ Dest += object->output_stride;
+ // then first odd line
+ object->pMemcpy (Dest, L1, object->line_length);
+ Dest += object->output_stride;
+ }
+
+ for (Line = 0; Line < (object->field_height - 1); ++Line) {
+ func (L1, L2, L3, L2P, Dest, object->line_length);
+ Dest += object->output_stride;
+ object->pMemcpy (Dest, L3, object->line_length);
+ Dest += object->output_stride;
+
+ L1 += Pitch;
+ L2 += Pitch;
+ L3 += Pitch;
+ L2P += Pitch;
+ }
+
+ if (InfoIsOdd) {
+ object->pMemcpy (Dest, L2, object->line_length);
}
}
@@ -94,7 +287,7 @@ static deinterlace_method_t greedyh_method = {
"Motion Adaptive: Advanced Detection",
"AdaptiveAdvanced",
4,
- OIL_IMPL_FLAG_MMX,
+ 0,
0,
0,
0,
@@ -117,32 +310,5 @@ static deinterlace_method_t greedyh_method = {
deinterlace_method_t *
dscaler_greedyh_get_method (void)
{
- greedyh_init ();
return &greedyh_method;
}
-
-void
-greedyh_init (void)
-{
- GreedyMaxComb = MAXCOMB_DEFAULT;
- GreedyMotionThreshold = MOTIONTHRESHOLD_DEFAULT;
- GreedyMotionSense = MOTIONSENSE_DEFAULT;
-}
-
-void
-greedyh_filter_mmx (GstDeinterlace2 * object)
-{
- greedyDScaler_MMX (object);
-}
-
-void
-greedyh_filter_3dnow (GstDeinterlace2 * object)
-{
- greedyDScaler_3DNOW (object);
-}
-
-void
-greedyh_filter_sse (GstDeinterlace2 * object)
-{
- greedyDScaler_SSE (object);
-}