24
24
25
25
#include <math.h>
26
26
#include <stdlib.h>
27
+ #include <string.h>
27
28
#include "frei0r.h"
28
29
29
30
/**
@@ -330,6 +331,36 @@ static void copy_pair_as_yuv(struct secamiz0r *self, uint8_t *dst_even, uint8_t
330
331
}
331
332
}
332
333
334
+ /**
335
+ * Moves line back and forth.
336
+ */
337
+ static void shift_line (struct secamiz0r * self , uint8_t * line , int shift )
338
+ {
339
+ if (shift < 0 ) {
340
+ int nshift = - shift ;
341
+
342
+ for (size_t i = 0 ; i < self -> width - nshift ; i ++ ) {
343
+ // memcpy(&line[i * 4], &line[(i * 4) + (nshift * 4)], 4);
344
+ line [i * 4 + 0 ] = line [(i * 4 ) + (nshift * 4 ) + 0 ];
345
+ }
346
+
347
+ for (size_t i = self -> width - nshift ; i < self -> width ; i ++ ) {
348
+ line [i * 4 + 0 ] = 0 ;
349
+ line [i * 4 + 1 ] = 128 ;
350
+ }
351
+ } else if (shift > 0 ) {
352
+ for (size_t i = self -> width - 1 ; i >= shift ; i -- ) {
353
+ // memcpy(&line[i * 4], &line[(i * 4) - (shift * 4)], 4);
354
+ line [i * 4 + 0 ] = line [(i * 4 ) - (shift * 4 ) + 0 ];
355
+ }
356
+
357
+ for (size_t i = 0 ; i < shift ; i ++ ) {
358
+ line [i * 4 + 0 ] = 0 ;
359
+ line [i * 4 + 1 ] = 128 ;
360
+ }
361
+ }
362
+ }
363
+
333
364
/**
334
365
* Filtering Stage 2.1. The loop inside this function works on two consecutive
335
366
* lines copied in Stage 1. It aims to detect areas where luminance level is
@@ -339,6 +370,7 @@ static void copy_pair_as_yuv(struct secamiz0r *self, uint8_t *dst_even, uint8_t
339
370
* some point the sum is larger than a threshold value, we mark this pixel.
340
371
*
341
372
* (Addition: also take the blue-ish or cyan-ish areas into the account).
373
+ * (Addition: shift lines a few pixels to the side to simulate bad sync).
342
374
*/
343
375
static void prefilter_pair (struct secamiz0r * self , uint8_t * even , uint8_t * odd )
344
376
{
@@ -372,6 +404,14 @@ static void prefilter_pair(struct secamiz0r *self, uint8_t *even, uint8_t *odd)
372
404
y_even_oscillation /= 2 ;
373
405
y_odd_oscillation /= 2 ;
374
406
}
407
+
408
+ // Addition: simulate bad deinterlace and bad sync.
409
+
410
+ int even_extra_shift = (self -> luma_noise > 80 ) ? (r_even % 4 ) : 0 ;
411
+ int odd_extra_shift = (self -> luma_noise > 80 ) ? (r_odd % 4 ) : 0 ;
412
+
413
+ shift_line (self , even , (self -> frame_count % 2 ) + even_extra_shift );
414
+ shift_line (self , odd , !(self -> frame_count % 2 ) + odd_extra_shift );
375
415
}
376
416
377
417
/**
0 commit comments