From cb72d483c0fb04e6efb9d016b5939286362d8860 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Thu, 28 May 2015 23:23:21 -0700 Subject: [PATCH] Refactor INTERPOLATED_PIXEL_ADJUSTMENT calculations just to codepaths actually touching the internal framebuffers --- src/display.c | 22 +++++++++------------- src/interface.c | 35 +++++++++++++++++++++++------------ src/interface.h | 11 ++++------- src/video/glalert.c | 2 +- src/video/glhudmodel.c | 2 +- src/video/gltouchjoy.c | 6 ++---- src/video/gltouchkbd.c | 16 +++++++--------- src/video/gltouchmenu.c | 18 ++++++++---------- 8 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/display.c b/src/display.c index 877d1d3a..90cea709 100644 --- a/src/display.c +++ b/src/display.c @@ -724,21 +724,17 @@ GLUE_C_WRITE(video__write_2e_text1_mixed) // ---------------------------------------------------------------------------- // Classic interface and printing HUD messages -void interface_plotChar(uint8_t *fb, int fb_pix_width, int col, int row, interface_colorscheme_t cs, uint8_t c) { +void interface_plotChar(uint8_t *fboff, int fb_pix_width, interface_colorscheme_t cs, uint8_t c) { _vid_dirty = true; - - unsigned int off = row * fb_pix_width * FONT_HEIGHT_PIXELS + col * FONT80_WIDTH_PIXELS + _INTERPOLATED_PIXEL_ADJUSTMENT_PRE; - uint8_t *dst = fb + off; uint8_t *src = video__int_font[cs] + c * (FONT_GLYPH_X*FONT_GLYPH_Y); - - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); - _plot_char80(&dst, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); + _plot_char80(&fboff, &src, fb_pix_width); } // ---------------------------------------------------------------------------- diff --git a/src/interface.c b/src/interface.c index 16a31ec2..33e0a7c5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -125,21 +125,19 @@ static void _translate_screen_x_y(char *screen, const int xlen, const int ylen) // ---------------------------------------------------------------------------- // Menu/HUD message printing -void interface_printMessage(uint8_t *fb, int fb_pix_width, int col, int row, interface_colorscheme_t cs, const char *message) { +static void _interface_plotLine(uint8_t *fb, int fb_pix_width, int fb_pix_x_adjust, int col, int row, interface_colorscheme_t cs, const char *message) { for (; *message; col++, message++) { char c = *message; - interface_plotChar(fb, fb_pix_width, col, row, cs, c); + unsigned int off = row * fb_pix_width * FONT_HEIGHT_PIXELS + col * FONT80_WIDTH_PIXELS + fb_pix_x_adjust; + interface_plotChar(fb+off, fb_pix_width, cs, c); } } -void interface_printMessageCentered(uint8_t *fb, int fb_cols, int fb_rows, interface_colorscheme_t cs, char *message, const int message_cols, const int message_rows) { +void interface_plotMessage(uint8_t *fb, interface_colorscheme_t cs, char *message, int message_cols, int message_rows) { _translate_screen_x_y(message, message_cols, message_rows); - int col = (fb_cols - message_cols) >> 1; - int row = (fb_rows - message_rows) >> 1; - int fb_pix_width = (fb_cols*FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT; // HACK NOTE : interpolated pixel adjustment still necessary ... - int row_max = row + message_rows; - for (int idx=0; row> 1; + int row = (fb_rows - message_rows) >> 1; + int fb_pix_width = (fb_cols*FONT80_WIDTH_PIXELS)+INTERPOLATED_PIXEL_ADJUSTMENT; + assert(fb_pix_width == SCANWIDTH); + int row_max = row + message_rows; + for (int idx=0; rowpixels; // render template into indexed fb - interface_printMessageCentered(fb, cols, rows, hudElement->colorScheme, submenu, cols, rows); + interface_plotMessage(fb, hudElement->colorScheme, submenu, cols, rows); // generate RGBA_8888 from indexed color const unsigned int fb_w = hudElement->pixWidth; diff --git a/src/video/gltouchjoy.c b/src/video/gltouchjoy.c index 2cd263b4..4ad75c5e 100644 --- a/src/video/gltouchjoy.c +++ b/src/video/gltouchjoy.c @@ -26,12 +26,10 @@ #define BUTTON_TEMPLATE_COLS 1 #define BUTTON_TEMPLATE_ROWS 1 -// HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... -#define AXIS_FB_WIDTH ((AXIS_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT) +#define AXIS_FB_WIDTH (AXIS_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) #define AXIS_FB_HEIGHT (AXIS_TEMPLATE_ROWS * FONT_HEIGHT_PIXELS) -// HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... -#define BUTTON_FB_WIDTH ((BUTTON_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT) +#define BUTTON_FB_WIDTH (BUTTON_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) #define BUTTON_FB_HEIGHT (BUTTON_TEMPLATE_ROWS * FONT_HEIGHT_PIXELS) #define AXIS_OBJ_W 0.4 diff --git a/src/video/gltouchkbd.c b/src/video/gltouchkbd.c index 094087f4..1767cd35 100644 --- a/src/video/gltouchkbd.c +++ b/src/video/gltouchkbd.c @@ -26,8 +26,7 @@ #define ROW_WITH_ADJACENTS (KBD_TEMPLATE_ROWS-1) #define _ROWOFF 2 // main keyboard row offset -// HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... -#define KBD_FB_WIDTH ((KBD_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT) +#define KBD_FB_WIDTH (KBD_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) #define KBD_FB_HEIGHT (KBD_TEMPLATE_ROWS * FONT_HEIGHT_PIXELS) #define KBD_OBJ_W 2.0 @@ -177,7 +176,7 @@ static void _rerender_character(int col, int row, uint8_t *fb) { const unsigned int colCount = 1; const unsigned int pixCharsWidth = (FONT80_WIDTH_PIXELS+1)*colCount; const unsigned int rowStride = hudKeyboard->pixWidth - pixCharsWidth; - unsigned int srcIndex = (row * hudKeyboard->pixWidth * FONT_HEIGHT_PIXELS) + ((col * FONT80_WIDTH_PIXELS) + /*HACK FIXME:*/_INTERPOLATED_PIXEL_ADJUSTMENT_PRE); + unsigned int srcIndex = (row * hudKeyboard->pixWidth * FONT_HEIGHT_PIXELS) + (col * FONT80_WIDTH_PIXELS); unsigned int dstIndex = srcIndex * 4; for (unsigned int i=0; icustom); - const unsigned int keyW = touchport.kbdW / (hudKeyboard->tplWidth+1/* interpolated adjustment HACK NOTE FIXME TODO */); - const unsigned int keyH = touchport.kbdH / (hudKeyboard->tplHeight); - const int xOff = (keyW * 0.5); // HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... + const unsigned int keyW = touchport.kbdW / hudKeyboard->tplWidth; + const unsigned int keyH = touchport.kbdH / hudKeyboard->tplHeight; - *col = (x - (touchport.kbdX+xOff)) / keyW; + *col = (x - touchport.kbdX) / keyW; if (*col < 0) { *col = 0; - } /* interpolated adjustment HACK NOTE FIXME TODO */ else if (*col >= hudKeyboard->tplWidth) { + } else if (*col >= hudKeyboard->tplWidth) { *col = hudKeyboard->tplWidth-1; } *row = (y - touchport.kbdY) / keyH; @@ -243,7 +241,7 @@ static inline void _screen_to_keyboard(float x, float y, OUTPARM int *col, OUTPA *row = 0; } - LOG("SCREEN TO KEYBOARD : xOff:%d kbdX:%d kbdXMax:%d kbdW:%d keyW:%d ... scrn:(%f,%f)->kybd:(%d,%d)", xOff, touchport.kbdX, touchport.kbdXMax, touchport.kbdW, keyW, x, y, *col, *row); + LOG("SCREEN TO KEYBOARD : kbdX:%d kbdXMax:%d kbdW:%d keyW:%d ... scrn:(%f,%f)->kybd:(%d,%d)", touchport.kbdX, touchport.kbdXMax, touchport.kbdW, keyW, x, y, *col, *row); } static inline void _tap_key_at_point(float x, float y) { diff --git a/src/video/gltouchmenu.c b/src/video/gltouchmenu.c index 76d053c1..19e9bdc2 100644 --- a/src/video/gltouchmenu.c +++ b/src/video/gltouchmenu.c @@ -23,8 +23,7 @@ #define MENU_TEMPLATE_COLS 2 #define MENU_TEMPLATE_ROWS 2 -// HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... -#define MENU_FB_WIDTH ((MENU_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT) +#define MENU_FB_WIDTH (MENU_TEMPLATE_COLS * FONT80_WIDTH_PIXELS) #define MENU_FB_HEIGHT (MENU_TEMPLATE_ROWS * FONT_HEIGHT_PIXELS) #define MENU_OBJ_W 1/2.f @@ -176,28 +175,27 @@ static inline void _screen_to_menu(float x, float y, OUTPARM int *col, OUTPARM i GLModelHUDMenu *hudMenu = (GLModelHUDMenu *)(/* assuming both have same width/height */hudTopLeft.model->custom); - unsigned int keyW = (touchport.topLeftXMax - touchport.topLeftX) / (hudMenu->tplWidth+1/* interpolated adjustment HACK NOTE FIXME TODO */); - unsigned int keyH = (touchport.topLeftYMax - touchport.topLeftY) / (hudMenu->tplHeight); - const int xOff = (keyW * 0.5); // HACK NOTE FIXME TODO : interpolated pixel adjustment still necessary ... + unsigned int keyW = (touchport.topLeftXMax - touchport.topLeftX) / hudMenu->tplWidth; + unsigned int keyH = (touchport.topLeftYMax - touchport.topLeftY) / hudMenu->tplHeight; hudMenu = NULL; if (x < touchport.width/2) { *isTopLeft = true; hudMenu = (GLModelHUDMenu *)hudTopLeft.model->custom; - *col = (x - (touchport.topLeftX+xOff)) / keyW; + *col = (x - touchport.topLeftX) / keyW; *row = (y - touchport.topLeftY) / keyH; - LOG("SCREEN TO MENU : xOff:%d topLeftX:%d topLeftXMax:%d keyW:%d ... scrn:(%d,%d)->menu:(%d,%d)", xOff, touchport.topLeftX, touchport.topLeftXMax, keyW, (int)x, (int)y, *col, *row); + LOG("SCREEN TO MENU : topLeftX:%d topLeftXMax:%d keyW:%d ... scrn:(%d,%d)->menu:(%d,%d)", touchport.topLeftX, touchport.topLeftXMax, keyW, (int)x, (int)y, *col, *row); } else { *isTopLeft = false; hudMenu = (GLModelHUDMenu *)hudTopRight.model->custom; - *col = (x - (touchport.topRightX+xOff)) / keyW; + *col = (x - touchport.topRightX) / keyW; *row = (y - touchport.topRightY) / keyH; - LOG("SCREEN TO MENU : xOff:%d topRightX:%d topRightXMax:%d keyW:%d ... scrn:(%d,%d)->menu:(%d,%d)", xOff, touchport.topRightX, touchport.topRightXMax, keyW, (int)x, (int)y, *col, *row); + LOG("SCREEN TO MENU : topRightX:%d topRightXMax:%d keyW:%d ... scrn:(%d,%d)->menu:(%d,%d)", touchport.topRightX, touchport.topRightXMax, keyW, (int)x, (int)y, *col, *row); } if (*col < 0) { *col = 0; - } /* interpolated adjustment HACK NOTE FIXME TODO */ else if (*col >= hudMenu->tplWidth) { + } else if (*col >= hudMenu->tplWidth) { *col = hudMenu->tplWidth-1; } if (*row < 0) {