Pi Firmware: added diff_N_frames_by_sample and improved logging

Change-Id: I4710a9424b4234699f2dce9aaf3d3a692ca04082
pull/11/head
David Banks 2018-11-06 10:26:23 +00:00
rodzic aac5b1f026
commit 430a2a161a
3 zmienionych plików z 54 dodań i 18 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ typedef struct {
} cpld_t;
int *diff_N_frames(int n, int mode7, int elk, int chars_per_line);
int *diff_N_frames_by_sample(int n, int mode7, int elk, int chars_per_line);
int analyze_mode7_alignment();

Wyświetl plik

@ -239,11 +239,21 @@ static void cpld_calibrate(int elk, int chars_per_line) {
config->sp_offset[j] = i;
}
write_config(config);
rgb_metric = diff_N_frames(NUM_CAL_FRAMES, mode7, elk, chars_per_line);
metric = rgb_metric[CHAN_RED] + rgb_metric[CHAN_GREEN] + rgb_metric[CHAN_BLUE];
rgb_metric = diff_N_frames_by_sample(NUM_CAL_FRAMES, mode7, elk, chars_per_line);
metric = 0;
printf("INFO: offset = %d: metrics = ", i);
for (int j = 0; j < NUM_OFFSETS; j++) {
int per_sample = 0;
for (int c = 0; c < NUM_CHANNELS; c++) {
per_sample += rgb_metric[j * NUM_CHANNELS + c];
}
metric += per_sample;
printf("%6d", per_sample);
}
printf("; total = %7d\r\n", metric);
metrics[i] = metric;
osd_sp(config, 1, metric);
log_info("offset = %d: metric = %5d", i, metric);
if (metric < min_metric) {
min_metric = metric;
}
@ -320,6 +330,7 @@ static void cpld_calibrate(int elk, int chars_per_line) {
osd_sp(config, 1, *errors);
log_info("Calibration complete");
log_sp(config);
log_info("Final errors = %d", *errors);
}
static void cpld_set_mode(int mode) {

Wyświetl plik

@ -492,14 +492,33 @@ static void start_core(int core, func_ptr func) {
// =============================================================
int *diff_N_frames(int n, int mode7, int elk, int chars_per_line) {
static int result[3];
// Calculate frame differences, broken out by channel and by sample point (A..F)
int *by_offset = diff_N_frames_by_sample(n, mode7, elk, chars_per_line);
// Collapse the offset dimension
for (int i = 0; i < NUM_CHANNELS; i++) {
result[i] = 0;
for (int j = 0; j < NUM_OFFSETS; j++) {
result[i] += by_offset[i + j * NUM_CHANNELS];
}
}
return result;
}
int *diff_N_frames_by_sample(int n, int mode7, int elk, int chars_per_line) {
unsigned int ret;
static int sum[3];
static int min[3];
static int max[3];
static int diff[3];
for (int i = 0; i < 3; i++) {
// NUM_CHANNELS is 3 (Red, Green, Blue)
// NUM_OFFSETS is 6 (Sample Offset A..Sample Offset F)
static int sum[NUM_CHANNELS * NUM_OFFSETS];
static int min[NUM_CHANNELS * NUM_OFFSETS];
static int max[NUM_CHANNELS * NUM_OFFSETS];
static int diff[NUM_CHANNELS * NUM_OFFSETS];
for (int i = 0; i < NUM_CHANNELS * NUM_OFFSETS; i++) {
sum[i] = 0;
min[i] = INT_MAX;
max[i] = INT_MIN;
@ -526,9 +545,10 @@ int *diff_N_frames(int n, int mode7, int elk, int chars_per_line) {
#endif
for (int i = 0; i < n; i++) {
diff[0] = 0;
diff[1] = 0;
diff[2] = 0;
for (int j = 0; j < NUM_CHANNELS * NUM_OFFSETS; j++) {
diff[j] = 0;
}
#ifdef INSTRUMENT_CAL
t = _get_cycle_counter();
@ -592,17 +612,20 @@ int *diff_N_frames(int n, int mode7, int elk, int chars_per_line) {
uint32_t d = (*fbp++) ^ (*lastp++);
// Mask out OSD
d &= 0x77777777;
// Work out the starting index
int index = NUM_CHANNELS * ((x << 1) % 6);
while (d) {
if (d & 0x01) {
diff[0]++;
diff[index]++;
}
if (d & 0x02) {
diff[1]++;
diff[index + 1]++;
}
if (d & 0x04) {
diff[2]++;
diff[index + 2]++;
}
d >>= 4;
index = (index + 3) % (NUM_CHANNELS * NUM_OFFSETS);
}
}
}
@ -612,7 +635,7 @@ int *diff_N_frames(int n, int mode7, int elk, int chars_per_line) {
#endif
// Accumulate the result
for (int j = 0; j < 3; j++) {
for (int j = 0; j < NUM_CHANNELS * NUM_OFFSETS; j++) {
sum[j] += diff[j];
if (diff[j] < min[j]) {
min[j] = diff[j];
@ -624,9 +647,10 @@ int *diff_N_frames(int n, int mode7, int elk, int chars_per_line) {
}
#if 0
for (int j = 0; j < 3; j++) {
int mean = sum[j] / n;
log_debug("channel %d: diff: sum = %d mean = %d, min = %d, max = %d", j, sum[j], mean, min[j], max[j]);
for (int i = 0; i < NUM_OFFSETS; i++) {
for (int j = 0; j < NUM_CHANNELS; j++) {
log_debug("offset %d channel %d diff: sum = %d min = %d, max = %d", i, j, sum[i * NUM_CHANNELS + j], min[i * NUM_CHANNELS + j], max[i * NUM_CHANNELS + j]);
}
}
#endif