Skip to content

Commit f92eec0

Browse files
committedJul 20, 2024
Add bad deinterlace/sync simulation
1 parent 72a1dfd commit f92eec0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎secamiz0r.c

+40
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <math.h>
2626
#include <stdlib.h>
27+
#include <string.h>
2728
#include "frei0r.h"
2829

2930
/**
@@ -330,6 +331,36 @@ static void copy_pair_as_yuv(struct secamiz0r *self, uint8_t *dst_even, uint8_t
330331
}
331332
}
332333

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+
333364
/**
334365
* Filtering Stage 2.1. The loop inside this function works on two consecutive
335366
* 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
339370
* some point the sum is larger than a threshold value, we mark this pixel.
340371
*
341372
* (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).
342374
*/
343375
static void prefilter_pair(struct secamiz0r *self, uint8_t *even, uint8_t *odd)
344376
{
@@ -372,6 +404,14 @@ static void prefilter_pair(struct secamiz0r *self, uint8_t *even, uint8_t *odd)
372404
y_even_oscillation /= 2;
373405
y_odd_oscillation /= 2;
374406
}
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);
375415
}
376416

377417
/**

0 commit comments

Comments
 (0)
Failed to load comments.