From 5eb987a25b10b23d1edb94dd17e80e223e9be31f Mon Sep 17 00:00:00 2001 From: David Banks Date: Sun, 10 Mar 2019 11:02:05 +0000 Subject: [PATCH] Fixed: Calibration errors with half height frame buffers (#40) Change-Id: I6792399e5a1a234c3b1b66226c5ee0447e759f0b --- src/defs.h | 4 ++-- src/geometry.c | 4 ++-- src/rgb_to_hdmi.c | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/defs.h b/src/defs.h index 4d9860d7..a8e2cfb9 100644 --- a/src/defs.h +++ b/src/defs.h @@ -147,8 +147,8 @@ typedef struct { unsigned char *fb; // framebuffer base address int pitch; // framebuffer pitch (in bytes per line) int width; // framebuffer width (in pixels) - int height; // framebuffer height (in pixels) - int heightx2; // framebuffer height (in pixels) + int height; // framebuffer height (in pixels, after any doubling is applied) + int heightx2; // if 1 then double frame buffer height int bpp; // framebuffer bits per pixel (4 or 8) int chars_per_line; // active 8-pixel characters per line (83 in Modes 0..6, but 63 in Mode 7) int nlines; // number of active lines to capture each field diff --git a/src/geometry.c b/src/geometry.c index bba45a48..d2fbc2cc 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -34,8 +34,8 @@ typedef struct { int h_width; // active horizontal width (in 8-bit characters) int v_height; // active vertical height (in lines) int fb_width; // framebuffer width in pixels - int fb_height; // framebuffer height in pixels - int fb_heightx2; // framebuffer height in pixels + int fb_height; // framebuffer height (in pixels, before and doubling is applied) + int fb_heightx2; // if 1 then double frame buffer height int fb_bpp; // framebuffer bits per pixel int clock; // cpld clock (in Hz) int line_len; // number of clocks per horizontal line diff --git a/src/rgb_to_hdmi.c b/src/rgb_to_hdmi.c index 8038ed61..58a88e1d 100644 --- a/src/rgb_to_hdmi.c +++ b/src/rgb_to_hdmi.c @@ -840,37 +840,40 @@ int *diff_N_frames_by_sample(capture_info_t *capinfo, int n, int mode7, int elk) uint32_t *lastp = (uint32_t *)last; for (int y = 0; y < capinfo->height; y++) { int skip = 0; - // As v_offset increases, e.g. by one, the screen image moves up one scan line, which is two frame buffer lines - // So line N in the framebuffer corresponds to line N + 2 in the image - int line = y + (capinfo->v_offset - 20) * 2; + // Calculate the capture scan line number (allowing for a double hight framebuffer) + // (capinfo->height is the framebuffer height after any doubling) + int line = capinfo->heightx2 ? (y >> 1) : y; + // As v_offset increases, e.g. by one, the screen image moves up one capture line + // (the hardcoded constant of 20 relates to the BBC video format) + line += (capinfo->v_offset - 20); // Skip lines that might contain flashing cursor // (the cursor rows were determined empirically) if (line >= 0) { if (elk) { // Eliminate cursor lines in 32 row modes (0,1,2,4,5) - if (!mode7 && ((line >> 1) % 8) == 5) { + if (!mode7 && (line % 8) == 5) { skip = 1; } // Eliminate cursor lines in 25 row modes (3, 6) - if (!mode7 && ((line >> 1) % 10) == 3) { + if (!mode7 && (line % 10) == 3) { skip = 1; } // Eliminate cursor lines in mode 7 // (this case is untested as I don't have a Jafa board) - if (mode7 && ((line % 20) == 14 || (line % 20) == 15)) { + if (mode7 && (line % 10) == 7) { skip = 1; } } else { // Eliminate cursor lines in 32 row modes (0,1,2,4,5) - if (!mode7 && ((line >> 1) % 8) == 7) { + if (!mode7 && (line % 8) == 7) { skip = 1; } // Eliminate cursor lines in 25 row modes (3, 6) - if (!mode7 && ((line >> 1) % 10) >= 5 && ((line >> 1) % 10) <= 7) { + if (!mode7 && (line % 10) >= 5 && (line % 10) <= 7) { skip = 1; } // Eliminate cursor lines in mode 7 - if (mode7 && ((line % 20) == 14 || (line % 20) == 15)) { + if (mode7 && (line % 10) == 7) { skip = 1; } }