Debian Codegraph @

gst/deinterlace/tvtime/greedyh.c

raw symbols SCIP
1 /*
2 *
3 * GStreamer
4 * Copyright (C) 2004 Billy Biggs <[email protected]>
5 * Copyright (C) 2008,2010 Sebastian Dröge <[email protected]>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 /*
24 * Relicensed for GStreamer from GPL to LGPL with permit from Billy Biggs.
25 * See: http://bugzilla.gnome.org/show_bug.cgi?id=163578
26 */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "greedyhmacros.h"
33
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include <gst/gst.h>
38
39 #include "plugins.h"
40 #include "gstdeinterlacemethod.h"
41
42 #define GST_TYPE_DEINTERLACE_METHOD_GREEDY_H (gst_deinterlace_method_greedy_h_get_type ())
43 #define GST_IS_DEINTERLACE_METHOD_GREEDY_H(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_H))
44 #define GST_IS_DEINTERLACE_METHOD_GREEDY_H_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DEINTERLACE_METHOD_GREEDY_H))
45 #define GST_DEINTERLACE_METHOD_GREEDY_H_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_H, GstDeinterlaceMethodGreedyHClass))
46 #define GST_DEINTERLACE_METHOD_GREEDY_H(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DEINTERLACE_METHOD_GREEDY_H, GstDeinterlaceMethodGreedyH))
47 #define GST_DEINTERLACE_METHOD_GREEDY_H_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEINTERLACE_METHOD_GREEDY_H, GstDeinterlaceMethodGreedyHClass))
48 #define GST_DEINTERLACE_METHOD_GREEDY_H_CAST(obj) ((GstDeinterlaceMethodGreedyH*)(obj))
49
50 typedef struct
51 {
52 GstDeinterlaceMethod parent;
53
54 guint max_comb, motion_threshold, motion_sense;
55 } GstDeinterlaceMethodGreedyH;
56
57 typedef void (*ScanlineFunction) (GstDeinterlaceMethodGreedyH * self,
58 const guint8 * L2, const guint8 * L1, const guint8 * L3, const guint8 * L2P,
59 guint8 * Dest, gint width);
60
61 typedef struct
62 {
63 GstDeinterlaceMethodClass parent_class;
64 ScanlineFunction scanline_yuy2; /* This is for YVYU too */
65 ScanlineFunction scanline_uyvy;
66 ScanlineFunction scanline_ayuv;
67 ScanlineFunction scanline_planar_y;
68 ScanlineFunction scanline_planar_uv;
69 } GstDeinterlaceMethodGreedyHClass;
70
71 static void
72 greedyh_scanline_C_ayuv (GstDeinterlaceMethodGreedyH * self, const guint8 * L1,
73 const guint8 * L2, const guint8 * L3, const guint8 * L2P, guint8 * Dest,
74 gint width)
75 {
76 gint Pos, Comp;
77 guint8 l1, l1_1, l3, l3_1;
78 guint8 avg, avg_1;
79 guint8 avg__1[4] = { 0, };
80 guint8 avg_s;
81 guint8 avg_sc;
82 guint8 best;
83 guint16 mov;
84 guint8 out;
85 guint8 l2, lp2;
86 guint8 l2_diff, lp2_diff;
87 guint8 min, max;
88 guint max_comb = self->max_comb;
89 guint motion_sense = self->motion_sense;
90 guint motion_threshold = self->motion_threshold;
91
92 width /= 4;
93 for (Pos = 0; Pos < width; Pos++) {
94 for (Comp = 0; Comp < 4; Comp++) {
95 l1 = L1[0];
96 l3 = L3[0];
97
98 if (Pos == width - 1) {
99 l1_1 = l1;
100 l3_1 = l3;
101 } else {
102 l1_1 = L1[4];
103 l3_1 = L3[4];
104 }
105
106 /* Average of L1 and L3 */
107 avg = (l1 + l3) / 2;
108
109 if (Pos == 0) {
110 avg__1[Comp] = avg;
111 }
112
113 /* Average of next L1 and next L3 */
114 avg_1 = (l1_1 + l3_1) / 2;
115
116 /* Calculate average of one pixel forward and previous */
117 avg_s = (avg__1[Comp] + avg_1) / 2;
118
119 /* Calculate average of center and surrounding pixels */
120 avg_sc = (avg + avg_s) / 2;
121
122 /* move forward */
123 avg__1[Comp] = avg;
124
125 /* Get best L2/L2P, i.e. least diff from above average */
126 l2 = L2[0];
127 lp2 = L2P[0];
128
129 l2_diff = ABS (l2 - avg_sc);
130
131 lp2_diff = ABS (lp2 - avg_sc);
132
133 if (l2_diff > lp2_diff)
134 best = lp2;
135 else
136 best = l2;
137
138 /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
139 max = MAX (l1, l3);
140 min = MIN (l1, l3);
141
142 if (max < 256 - max_comb)
143 max += max_comb;
144 else
145 max = 255;
146
147 if (min > max_comb)
148 min -= max_comb;
149 else
150 min = 0;
151
152 out = CLAMP (best, min, max);
153
154 if (Comp < 2) {
155 /* Do motion compensation for luma, i.e. how much
156 * the weave pixel differs */
157 mov = ABS (l2 - lp2);
158 if (mov > motion_threshold)
159 mov -= motion_threshold;
160 else
161 mov = 0;
162
163 mov = mov * motion_sense;
164 if (mov > 256)
165 mov = 256;
166
167 /* Weighted sum on clipped weave pixel and average */
168 out = (out * (256 - mov) + avg_sc * mov) / 256;
169 }
170
171 Dest[0] = out;
172
173 Dest += 1;
174 L1 += 1;
175 L2 += 1;
176 L3 += 1;
177 L2P += 1;
178 }
179 }
180 }
181
182 static void
183 greedyh_scanline_C_yuy2 (GstDeinterlaceMethodGreedyH * self, const guint8 * L1,
184 const guint8 * L2, const guint8 * L3, const guint8 * L2P, guint8 * Dest,
185 gint width)
186 {
187 gint Pos;
188 guint8 l1_l, l1_1_l, l3_l, l3_1_l;
189 guint8 l1_c, l1_1_c, l3_c, l3_1_c;
190 guint8 avg_l, avg_c, avg_l_1, avg_c_1;
191 guint8 avg_l__1 = 0, avg_c__1 = 0;
192 guint8 avg_s_l, avg_s_c;
193 guint8 avg_sc_l, avg_sc_c;
194 guint8 best_l, best_c;
195 guint16 mov_l;
196 guint8 out_l, out_c;
197 guint8 l2_l, l2_c, lp2_l, lp2_c;
198 guint8 l2_l_diff, l2_c_diff, lp2_l_diff, lp2_c_diff;
199 guint8 min_l, min_c, max_l, max_c;
200 guint max_comb = self->max_comb;
201 guint motion_sense = self->motion_sense;
202 guint motion_threshold = self->motion_threshold;
203
204 width /= 2;
205 for (Pos = 0; Pos < width; Pos++) {
206 l1_l = L1[0];
207 l1_c = L1[1];
208 l3_l = L3[0];
209 l3_c = L3[1];
210
211 if (Pos == width - 1) {
212 l1_1_l = l1_l;
213 l1_1_c = l1_c;
214 l3_1_l = l3_l;
215 l3_1_c = l3_c;
216 } else {
217 l1_1_l = L1[2];
218 l1_1_c = L1[3];
219 l3_1_l = L3[2];
220 l3_1_c = L3[3];
221 }
222
223 /* Average of L1 and L3 */
224 avg_l = (l1_l + l3_l) / 2;
225 avg_c = (l1_c + l3_c) / 2;
226
227 if (Pos == 0) {
228 avg_l__1 = avg_l;
229 avg_c__1 = avg_c;
230 }
231
232 /* Average of next L1 and next L3 */
233 avg_l_1 = (l1_1_l + l3_1_l) / 2;
234 avg_c_1 = (l1_1_c + l3_1_c) / 2;
235
236 /* Calculate average of one pixel forward and previous */
237 avg_s_l = (avg_l__1 + avg_l_1) / 2;
238 avg_s_c = (avg_c__1 + avg_c_1) / 2;
239
240 /* Calculate average of center and surrounding pixels */
241 avg_sc_l = (avg_l + avg_s_l) / 2;
242 avg_sc_c = (avg_c + avg_s_c) / 2;
243
244 /* move forward */
245 avg_l__1 = avg_l;
246 avg_c__1 = avg_c;
247
248 /* Get best L2/L2P, i.e. least diff from above average */
249 l2_l = L2[0];
250 l2_c = L2[1];
251 lp2_l = L2P[0];
252 lp2_c = L2P[1];
253
254 l2_l_diff = ABS (l2_l - avg_sc_l);
255 l2_c_diff = ABS (l2_c - avg_sc_c);
256
257 lp2_l_diff = ABS (lp2_l - avg_sc_l);
258 lp2_c_diff = ABS (lp2_c - avg_sc_c);
259
260 if (l2_l_diff > lp2_l_diff)
261 best_l = lp2_l;
262 else
263 best_l = l2_l;
264
265 if (l2_c_diff > lp2_c_diff)
266 best_c = lp2_c;
267 else
268 best_c = l2_c;
269
270 /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
271 max_l = MAX (l1_l, l3_l);
272 min_l = MIN (l1_l, l3_l);
273
274 if (max_l < 256 - max_comb)
275 max_l += max_comb;
276 else
277 max_l = 255;
278
279 if (min_l > max_comb)
280 min_l -= max_comb;
281 else
282 min_l = 0;
283
284 max_c = MAX (l1_c, l3_c);
285 min_c = MIN (l1_c, l3_c);
286
287 if (max_c < 256 - max_comb)
288 max_c += max_comb;
289 else
290 max_c = 255;
291
292 if (min_c > max_comb)
293 min_c -= max_comb;
294 else
295 min_c = 0;
296
297 out_l = CLAMP (best_l, min_l, max_l);
298 out_c = CLAMP (best_c, min_c, max_c);
299
300 /* Do motion compensation for luma, i.e. how much
301 * the weave pixel differs */
302 mov_l = ABS (l2_l - lp2_l);
303 if (mov_l > motion_threshold)
304 mov_l -= motion_threshold;
305 else
306 mov_l = 0;
307
308 mov_l = mov_l * motion_sense;
309 if (mov_l > 256)
310 mov_l = 256;
311
312 /* Weighted sum on clipped weave pixel and average */
313 out_l = (out_l * (256 - mov_l) + avg_sc_l * mov_l) / 256;
314
315 Dest[0] = out_l;
316 Dest[1] = out_c;
317
318 Dest += 2;
319 L1 += 2;
320 L2 += 2;
321 L3 += 2;
322 L2P += 2;
323 }
324 }
325
326 static void
327 greedyh_scanline_C_uyvy (GstDeinterlaceMethodGreedyH * self, const guint8 * L1,
328 const guint8 * L2, const guint8 * L3, const guint8 * L2P, guint8 * Dest,
329 gint width)
330 {
331 gint Pos;
332 guint8 l1_l, l1_1_l, l3_l, l3_1_l;
333 guint8 l1_c, l1_1_c, l3_c, l3_1_c;
334 guint8 avg_l, avg_c, avg_l_1, avg_c_1;
335 guint8 avg_l__1 = 0, avg_c__1 = 0;
336 guint8 avg_s_l, avg_s_c;
337 guint8 avg_sc_l, avg_sc_c;
338 guint8 best_l, best_c;
339 guint16 mov_l;
340 guint8 out_l, out_c;
341 guint8 l2_l, l2_c, lp2_l, lp2_c;
342 guint8 l2_l_diff, l2_c_diff, lp2_l_diff, lp2_c_diff;
343 guint8 min_l, min_c, max_l, max_c;
344 guint max_comb = self->max_comb;
345 guint motion_sense = self->motion_sense;
346 guint motion_threshold = self->motion_threshold;
347
348 width /= 2;
349 for (Pos = 0; Pos < width; Pos++) {
350 l1_l = L1[1];
351 l1_c = L1[0];
352 l3_l = L3[1];
353 l3_c = L3[0];
354
355 if (Pos == width - 1) {
356 l1_1_l = l1_l;
357 l1_1_c = l1_c;
358 l3_1_l = l3_l;
359 l3_1_c = l3_c;
360 } else {
361 l1_1_l = L1[3];
362 l1_1_c = L1[2];
363 l3_1_l = L3[3];
364 l3_1_c = L3[2];
365 }
366
367 /* Average of L1 and L3 */
368 avg_l = (l1_l + l3_l) / 2;
369 avg_c = (l1_c + l3_c) / 2;
370
371 if (Pos == 0) {
372 avg_l__1 = avg_l;
373 avg_c__1 = avg_c;
374 }
375
376 /* Average of next L1 and next L3 */
377 avg_l_1 = (l1_1_l + l3_1_l) / 2;
378 avg_c_1 = (l1_1_c + l3_1_c) / 2;
379
380 /* Calculate average of one pixel forward and previous */
381 avg_s_l = (avg_l__1 + avg_l_1) / 2;
382 avg_s_c = (avg_c__1 + avg_c_1) / 2;
383
384 /* Calculate average of center and surrounding pixels */
385 avg_sc_l = (avg_l + avg_s_l) / 2;
386 avg_sc_c = (avg_c + avg_s_c) / 2;
387
388 /* move forward */
389 avg_l__1 = avg_l;
390 avg_c__1 = avg_c;
391
392 /* Get best L2/L2P, i.e. least diff from above average */
393 l2_l = L2[1];
394 l2_c = L2[0];
395 lp2_l = L2P[1];
396 lp2_c = L2P[0];
397
398 l2_l_diff = ABS (l2_l - avg_sc_l);
399 l2_c_diff = ABS (l2_c - avg_sc_c);
400
401 lp2_l_diff = ABS (lp2_l - avg_sc_l);
402 lp2_c_diff = ABS (lp2_c - avg_sc_c);
403
404 if (l2_l_diff > lp2_l_diff)
405 best_l = lp2_l;
406 else
407 best_l = l2_l;
408
409 if (l2_c_diff > lp2_c_diff)
410 best_c = lp2_c;
411 else
412 best_c = l2_c;
413
414 /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
415 max_l = MAX (l1_l, l3_l);
416 min_l = MIN (l1_l, l3_l);
417
418 if (max_l < 256 - max_comb)
419 max_l += max_comb;
420 else
421 max_l = 255;
422
423 if (min_l > max_comb)
424 min_l -= max_comb;
425 else
426 min_l = 0;
427
428 max_c = MAX (l1_c, l3_c);
429 min_c = MIN (l1_c, l3_c);
430
431 if (max_c < 256 - max_comb)
432 max_c += max_comb;
433 else
434 max_c = 255;
435
436 if (min_c > max_comb)
437 min_c -= max_comb;
438 else
439 min_c = 0;
440
441 out_l = CLAMP (best_l, min_l, max_l);
442 out_c = CLAMP (best_c, min_c, max_c);
443
444 /* Do motion compensation for luma, i.e. how much
445 * the weave pixel differs */
446 mov_l = ABS (l2_l - lp2_l);
447 if (mov_l > motion_threshold)
448 mov_l -= motion_threshold;
449 else
450 mov_l = 0;
451
452 mov_l = mov_l * motion_sense;
453 if (mov_l > 256)
454 mov_l = 256;
455
456 /* Weighted sum on clipped weave pixel and average */
457 out_l = (out_l * (256 - mov_l) + avg_sc_l * mov_l) / 256;
458
459 Dest[1] = out_l;
460 Dest[0] = out_c;
461
462 Dest += 2;
463 L1 += 2;
464 L2 += 2;
465 L3 += 2;
466 L2P += 2;
467 }
468 }
469
470 static void
471 greedyh_scanline_C_planar_y (GstDeinterlaceMethodGreedyH * self,
472 const guint8 * L1, const guint8 * L2, const guint8 * L3, const guint8 * L2P,
473 guint8 * Dest, gint width)
474 {
475 gint Pos;
476 guint8 l1, l1_1, l3, l3_1;
477 guint8 avg, avg_1;
478 guint8 avg__1 = 0;
479 guint8 avg_s;
480 guint8 avg_sc;
481 guint8 best;
482 guint16 mov;
483 guint8 out;
484 guint8 l2, lp2;
485 guint8 l2_diff, lp2_diff;
486 guint8 min, max;
487 guint max_comb = self->max_comb;
488 guint motion_sense = self->motion_sense;
489 guint motion_threshold = self->motion_threshold;
490
491 for (Pos = 0; Pos < width; Pos++) {
492 l1 = L1[0];
493 l3 = L3[0];
494
495 if (Pos == width - 1) {
496 l1_1 = l1;
497 l3_1 = l3;
498 } else {
499 l1_1 = L1[1];
500 l3_1 = L3[1];
501 }
502
503 /* Average of L1 and L3 */
504 avg = (l1 + l3) / 2;
505
506 if (Pos == 0) {
507 avg__1 = avg;
508 }
509
510 /* Average of next L1 and next L3 */
511 avg_1 = (l1_1 + l3_1) / 2;
512
513 /* Calculate average of one pixel forward and previous */
514 avg_s = (avg__1 + avg_1) / 2;
515
516 /* Calculate average of center and surrounding pixels */
517 avg_sc = (avg + avg_s) / 2;
518
519 /* move forward */
520 avg__1 = avg;
521
522 /* Get best L2/L2P, i.e. least diff from above average */
523 l2 = L2[0];
524 lp2 = L2P[0];
525
526 l2_diff = ABS (l2 - avg_sc);
527
528 lp2_diff = ABS (lp2 - avg_sc);
529
530 if (l2_diff > lp2_diff)
531 best = lp2;
532 else
533 best = l2;
534
535 /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
536 max = MAX (l1, l3);
537 min = MIN (l1, l3);
538
539 if (max < 256 - max_comb)
540 max += max_comb;
541 else
542 max = 255;
543
544 if (min > max_comb)
545 min -= max_comb;
546 else
547 min = 0;
548
549 out = CLAMP (best, min, max);
550
551 /* Do motion compensation for luma, i.e. how much
552 * the weave pixel differs */
553 mov = ABS (l2 - lp2);
554 if (mov > motion_threshold)
555 mov -= motion_threshold;
556 else
557 mov = 0;
558
559 mov = mov * motion_sense;
560 if (mov > 256)
561 mov = 256;
562
563 /* Weighted sum on clipped weave pixel and average */
564 out = (out * (256 - mov) + avg_sc * mov) / 256;
565
566 Dest[0] = out;
567
568 Dest += 1;
569 L1 += 1;
570 L2 += 1;
571 L3 += 1;
572 L2P += 1;
573 }
574 }
575
576 static void
577 greedyh_scanline_C_planar_uv (GstDeinterlaceMethodGreedyH * self,
578 const guint8 * L1, const guint8 * L2, const guint8 * L3, const guint8 * L2P,
579 guint8 * Dest, gint width)
580 {
581 gint Pos;
582 guint8 l1, l1_1, l3, l3_1;
583 guint8 avg, avg_1;
584 guint8 avg__1 = 0;
585 guint8 avg_s;
586 guint8 avg_sc;
587 guint8 best;
588 guint8 out;
589 guint8 l2, lp2;
590 guint8 l2_diff, lp2_diff;
591 guint8 min, max;
592 guint max_comb = self->max_comb;
593
594 for (Pos = 0; Pos < width; Pos++) {
595 l1 = L1[0];
596 l3 = L3[0];
597
598 if (Pos == width - 1) {
599 l1_1 = l1;
600 l3_1 = l3;
601 } else {
602 l1_1 = L1[1];
603 l3_1 = L3[1];
604 }
605
606 /* Average of L1 and L3 */
607 avg = (l1 + l3) / 2;
608
609 if (Pos == 0) {
610 avg__1 = avg;
611 }
612
613 /* Average of next L1 and next L3 */
614 avg_1 = (l1_1 + l3_1) / 2;
615
616 /* Calculate average of one pixel forward and previous */
617 avg_s = (avg__1 + avg_1) / 2;
618
619 /* Calculate average of center and surrounding pixels */
620 avg_sc = (avg + avg_s) / 2;
621
622 /* move forward */
623 avg__1 = avg;
624
625 /* Get best L2/L2P, i.e. least diff from above average */
626 l2 = L2[0];
627 lp2 = L2P[0];
628
629 l2_diff = ABS (l2 - avg_sc);
630
631 lp2_diff = ABS (lp2 - avg_sc);
632
633 if (l2_diff > lp2_diff)
634 best = lp2;
635 else
636 best = l2;
637
638 /* Clip this best L2/L2P by L1/L3 and allow to differ by GreedyMaxComb */
639 max = MAX (l1, l3);
640 min = MIN (l1, l3);
641
642 if (max < 256 - max_comb)
643 max += max_comb;
644 else
645 max = 255;
646
647 if (min > max_comb)
648 min -= max_comb;
649 else
650 min = 0;
651
652 out = CLAMP (best, min, max);
653
654 Dest[0] = out;
655
656 Dest += 1;
657 L1 += 1;
658 L2 += 1;
659 L3 += 1;
660 L2P += 1;
661 }
662 }
663
664 #ifdef BUILD_X86_ASM
665
666 #define IS_MMXEXT
667 #define SIMD_TYPE MMXEXT
668 #define C_FUNCT_YUY2 greedyh_scanline_C_yuy2
669 #define C_FUNCT_UYVY greedyh_scanline_C_uyvy
670 #define C_FUNCT_PLANAR_Y greedyh_scanline_C_planar_y
671 #define C_FUNCT_PLANAR_UV greedyh_scanline_C_planar_uv
672 #define FUNCT_NAME_YUY2 greedyh_scanline_MMXEXT_yuy2
673 #define FUNCT_NAME_UYVY greedyh_scanline_MMXEXT_uyvy
674 #define FUNCT_NAME_PLANAR_Y greedyh_scanline_MMXEXT_planar_y
675 #define FUNCT_NAME_PLANAR_UV greedyh_scanline_MMXEXT_planar_uv
676 #include "greedyh.asm"
677 #undef SIMD_TYPE
678 #undef IS_MMXEXT
679 #undef FUNCT_NAME_YUY2
680 #undef FUNCT_NAME_UYVY
681 #undef FUNCT_NAME_PLANAR_Y
682 #undef FUNCT_NAME_PLANAR_UV
683
684 #define IS_3DNOW
685 #define SIMD_TYPE 3DNOW
686 #define FUNCT_NAME_YUY2 greedyh_scanline_3DNOW_yuy2
687 #define FUNCT_NAME_UYVY greedyh_scanline_3DNOW_uyvy
688 #define FUNCT_NAME_PLANAR_Y greedyh_scanline_3DNOW_planar_y
689 #define FUNCT_NAME_PLANAR_UV greedyh_scanline_3DNOW_planar_uv
690 #include "greedyh.asm"
691 #undef SIMD_TYPE
692 #undef IS_3DNOW
693 #undef FUNCT_NAME_YUY2
694 #undef FUNCT_NAME_UYVY
695 #undef FUNCT_NAME_PLANAR_Y
696 #undef FUNCT_NAME_PLANAR_UV
697
698 #define IS_MMX
699 #define SIMD_TYPE MMX
700 #define FUNCT_NAME_YUY2 greedyh_scanline_MMX_yuy2
701 #define FUNCT_NAME_UYVY greedyh_scanline_MMX_uyvy
702 #define FUNCT_NAME_PLANAR_Y greedyh_scanline_MMX_planar_y
703 #define FUNCT_NAME_PLANAR_UV greedyh_scanline_MMX_planar_uv
704 #include "greedyh.asm"
705 #undef SIMD_TYPE
706 #undef IS_MMX
707 #undef FUNCT_NAME_YUY2
708 #undef FUNCT_NAME_UYVY
709 #undef FUNCT_NAME_PLANAR_Y
710 #undef FUNCT_NAME_PLANAR_UV
711 #undef C_FUNCT_YUY2
712 #undef C_FUNCT_PLANAR_Y
713 #undef C_FUNCT_PLANAR_UV
714
715 #endif
716
717 static void
718 deinterlace_frame_di_greedyh_plane (GstDeinterlaceMethodGreedyH * self,
719 const GstDeinterlaceField * history, guint history_count,
720 GstVideoFrame * outframe, int cur_field_idx, int plane,
721 ScanlineFunction scanline)
722 {
723 guint8 *Dest = GST_VIDEO_FRAME_COMP_DATA (outframe, plane);
724 gint RowStride = GST_VIDEO_FRAME_COMP_STRIDE (outframe, plane);
725 gint FieldHeight = GST_VIDEO_FRAME_COMP_HEIGHT (outframe, plane) / 2;
726 gint Pitch;
727 const guint8 *L1; // ptr to Line1, of 3
728 const guint8 *L2; // ptr to Line2, the weave line
729 const guint8 *L3; // ptr to Line3
730 const guint8 *L2P; // ptr to prev Line2
731 gint InfoIsOdd;
732 gint Line;
733 const GstVideoFrame *frame;
734
735 frame = history[cur_field_idx].frame;
736
737 L1 = GST_VIDEO_FRAME_COMP_DATA (frame, plane);
738 L2 = GST_VIDEO_FRAME_COMP_DATA (history[cur_field_idx + 1].frame, plane);
739 L2P = GST_VIDEO_FRAME_COMP_DATA (history[cur_field_idx - 1].frame, plane);
740
741 if (GST_VIDEO_INFO_INTERLACE_MODE (&frame->info) ==
742 GST_VIDEO_INTERLACE_MODE_ALTERNATE) {
743 Pitch = RowStride;
744 } else {
745 Pitch = RowStride * 2;
746 if (history[cur_field_idx].flags & PICTURE_INTERLACED_BOTTOM)
747 L1 += RowStride;
748 if (history[cur_field_idx + 1].flags & PICTURE_INTERLACED_BOTTOM)
749 L2 += RowStride;
750 if (history[cur_field_idx - 1].flags & PICTURE_INTERLACED_BOTTOM)
751 L2P += RowStride;
752 }
753
754 L3 = L1 + Pitch;
755
756 // copy first even line no matter what, and the first odd line if we're
757 // processing an EVEN field. (note diff from other deint rtns.)
758
759 InfoIsOdd = (history[cur_field_idx + 1].flags == PICTURE_INTERLACED_BOTTOM);
760 if (InfoIsOdd) {
761 // copy first even line
762 memcpy (Dest, L1, RowStride);
763 Dest += RowStride;
764 } else {
765 // copy first even line
766 memcpy (Dest, L1, RowStride);
767 Dest += RowStride;
768 // then first odd line
769 memcpy (Dest, L1, RowStride);
770 Dest += RowStride;
771
772 L2 += Pitch;
773 L2P += Pitch;
774 }
775
776 for (Line = 0; Line < (FieldHeight - 1); ++Line) {
777 scanline (self, L1, L2, L3, L2P, Dest, RowStride);
778 Dest += RowStride;
779 memcpy (Dest, L3, RowStride);
780 Dest += RowStride;
781
782 L1 += Pitch;
783 L2 += Pitch;
784 L3 += Pitch;
785 L2P += Pitch;
786 }
787
788 if (InfoIsOdd) {
789 memcpy (Dest, L2, RowStride);
790 }
791 }
792
793 static void
794 deinterlace_frame_di_greedyh_packed (GstDeinterlaceMethod * method,
795 const GstDeinterlaceField * history, guint history_count,
796 GstVideoFrame * outframe, int cur_field_idx)
797 {
798 GstDeinterlaceMethodGreedyH *self = GST_DEINTERLACE_METHOD_GREEDY_H (method);
799 GstDeinterlaceMethodGreedyHClass *klass =
800 GST_DEINTERLACE_METHOD_GREEDY_H_GET_CLASS (self);
801 ScanlineFunction scanline;
802
803 if (cur_field_idx + 2 > history_count || cur_field_idx < 1) {
804 GstDeinterlaceMethod *backup_method;
805
806 backup_method = g_object_new (gst_deinterlace_method_linear_get_type (),
807 NULL);
808
809 gst_deinterlace_method_setup (backup_method, method->vinfo);
810 gst_deinterlace_method_deinterlace_frame (backup_method,
811 history, history_count, outframe, cur_field_idx);
812
813 g_object_unref (backup_method);
814 return;
815 }
816
817 switch (GST_VIDEO_INFO_FORMAT (method->vinfo)) {
818 case GST_VIDEO_FORMAT_YUY2:
819 case GST_VIDEO_FORMAT_YVYU:
820 scanline = klass->scanline_yuy2;
821 break;
822 case GST_VIDEO_FORMAT_UYVY:
823 scanline = klass->scanline_uyvy;
824 break;
825 case GST_VIDEO_FORMAT_AYUV:
826 scanline = klass->scanline_ayuv;
827 break;
828 default:
829 g_assert_not_reached ();
830 return;
831 }
832
833 deinterlace_frame_di_greedyh_plane (self, history, history_count, outframe,
834 cur_field_idx, 0, scanline);
835 }
836
837 static void
838 deinterlace_frame_di_greedyh_planar (GstDeinterlaceMethod * method,
839 const GstDeinterlaceField * history, guint history_count,
840 GstVideoFrame * outframe, int cur_field_idx)
841 {
842 GstDeinterlaceMethodGreedyH *self = GST_DEINTERLACE_METHOD_GREEDY_H (method);
843 GstDeinterlaceMethodGreedyHClass *klass =
844 GST_DEINTERLACE_METHOD_GREEDY_H_GET_CLASS (self);
845
846 if (cur_field_idx + 2 > history_count || cur_field_idx < 1) {
847 GstDeinterlaceMethod *backup_method;
848
849 backup_method = g_object_new (gst_deinterlace_method_linear_get_type (),
850 NULL);
851
852 gst_deinterlace_method_setup (backup_method, method->vinfo);
853 gst_deinterlace_method_deinterlace_frame (backup_method,
854 history, history_count, outframe, cur_field_idx);
855
856 g_object_unref (backup_method);
857 return;
858 }
859
860 deinterlace_frame_di_greedyh_plane (self, history, history_count, outframe,
861 cur_field_idx, 0, klass->scanline_planar_y);
862 deinterlace_frame_di_greedyh_plane (self, history, history_count, outframe,
863 cur_field_idx, 1, klass->scanline_planar_uv);
864 deinterlace_frame_di_greedyh_plane (self, history, history_count, outframe,
865 cur_field_idx, 2, klass->scanline_planar_uv);
866 }
867
868 G_DEFINE_TYPE (GstDeinterlaceMethodGreedyH, gst_deinterlace_method_greedy_h,
869 GST_TYPE_DEINTERLACE_METHOD);
870
871 enum
872 {
873 PROP_0,
874 PROP_MAX_COMB,
875 PROP_MOTION_THRESHOLD,
876 PROP_MOTION_SENSE
877 };
878
879 static void
880 gst_deinterlace_method_greedy_h_set_property (GObject * object, guint prop_id,
881 const GValue * value, GParamSpec * pspec)
882 {
883 GstDeinterlaceMethodGreedyH *self = GST_DEINTERLACE_METHOD_GREEDY_H (object);
884
885 switch (prop_id) {
886 case PROP_MAX_COMB:
887 self->max_comb = g_value_get_uint (value);
888 break;
889 case PROP_MOTION_THRESHOLD:
890 self->motion_threshold = g_value_get_uint (value);
891 break;
892 case PROP_MOTION_SENSE:
893 self->motion_sense = g_value_get_uint (value);
894 break;
895 default:
896 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
897 }
898 }
899
900 static void
901 gst_deinterlace_method_greedy_h_get_property (GObject * object, guint prop_id,
902 GValue * value, GParamSpec * pspec)
903 {
904 GstDeinterlaceMethodGreedyH *self = GST_DEINTERLACE_METHOD_GREEDY_H (object);
905
906 switch (prop_id) {
907 case PROP_MAX_COMB:
908 g_value_set_uint (value, self->max_comb);
909 break;
910 case PROP_MOTION_THRESHOLD:
911 g_value_set_uint (value, self->motion_threshold);
912 break;
913 case PROP_MOTION_SENSE:
914 g_value_set_uint (value, self->motion_sense);
915 break;
916 default:
917 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
918 }
919 }
920
921 static void
922 gst_deinterlace_method_greedy_h_class_init (GstDeinterlaceMethodGreedyHClass *
923 klass)
924 {
925 GstDeinterlaceMethodClass *dim_class = (GstDeinterlaceMethodClass *) klass;
926 GObjectClass *gobject_class = (GObjectClass *) klass;
927 #ifdef BUILD_X86_ASM
928 const gboolean cpuid_mmx = gst_cpuid_supports_x86_mmx ();
929 const gboolean cpuid_mmxext = gst_cpuid_supports_x86_mmxext ();
930 const gboolean cpuid_3dnow = gst_cpuid_supports_x86_3dnow ();
931
932 GST_LOG ("cpuid: [mmx=%x, mmxext=%x, 3dnow=%x]",
933 cpuid_mmx, cpuid_mmxext, cpuid__3dnow);
934 #endif
935
936 gobject_class->set_property = gst_deinterlace_method_greedy_h_set_property;
937 gobject_class->get_property = gst_deinterlace_method_greedy_h_get_property;
938
939 g_object_class_install_property (gobject_class, PROP_MAX_COMB,
940 g_param_spec_uint ("max-comb",
941 "Max comb",
942 "Max Comb", 0, 255, 5, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
943 );
944
945 g_object_class_install_property (gobject_class, PROP_MOTION_THRESHOLD,
946 g_param_spec_uint ("motion-threshold",
947 "Motion Threshold",
948 "Motion Threshold",
949 0, 255, 25, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
950 );
951
952 g_object_class_install_property (gobject_class, PROP_MOTION_SENSE,
953 g_param_spec_uint ("motion-sense",
954 "Motion Sense",
955 "Motion Sense",
956 0, 255, 30, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
957 );
958
959 dim_class->fields_required = 4;
960 dim_class->name = "Motion Adaptive: Advanced Detection";
961 dim_class->nick = "greedyh";
962 dim_class->latency = 1;
963
964 dim_class->deinterlace_frame_yuy2 = deinterlace_frame_di_greedyh_packed;
965 dim_class->deinterlace_frame_yvyu = deinterlace_frame_di_greedyh_packed;
966 dim_class->deinterlace_frame_uyvy = deinterlace_frame_di_greedyh_packed;
967 dim_class->deinterlace_frame_ayuv = deinterlace_frame_di_greedyh_packed;
968 dim_class->deinterlace_frame_y444 = deinterlace_frame_di_greedyh_planar;
969 dim_class->deinterlace_frame_i420 = deinterlace_frame_di_greedyh_planar;
970 dim_class->deinterlace_frame_yv12 = deinterlace_frame_di_greedyh_planar;
971 dim_class->deinterlace_frame_y42b = deinterlace_frame_di_greedyh_planar;
972 dim_class->deinterlace_frame_y41b = deinterlace_frame_di_greedyh_planar;
973
974 #ifdef BUILD_X86_ASM
975 if (cpuid_mmxext) {
976 klass->scanline_yuy2 = greedyh_scanline_MMXEXT_yuy2;
977 klass->scanline_uyvy = greedyh_scanline_MMXEXT_uyvy;
978 } else if (cpuid_3dnow) {
979 klass->scanline_yuy2 = greedyh_scanline_3DNOW_yuy2;
980 klass->scanline_uyvy = greedyh_scanline_3DNOW_uyvy;
981 } else if (cpuid_mmx) {
982 klass->scanline_yuy2 = greedyh_scanline_MMX_yuy2;
983 klass->scanline_uyvy = greedyh_scanline_MMX_uyvy;
984 } else {
985 klass->scanline_yuy2 = greedyh_scanline_C_yuy2;
986 klass->scanline_uyvy = greedyh_scanline_C_uyvy;
987 }
988 #else
989 klass->scanline_yuy2 = greedyh_scanline_C_yuy2;
990 klass->scanline_uyvy = greedyh_scanline_C_uyvy;
991 #endif
992 /* TODO: MMX implementation of these two */
993 klass->scanline_ayuv = greedyh_scanline_C_ayuv;
994 klass->scanline_planar_y = greedyh_scanline_C_planar_y;
995 klass->scanline_planar_uv = greedyh_scanline_C_planar_uv;
996 }
997
998 static void
999 gst_deinterlace_method_greedy_h_init (GstDeinterlaceMethodGreedyH * self)
1000 {
1001 self->max_comb = 5;
1002 self->motion_threshold = 25;
1003 self->motion_sense = 30;
1004 }