Refactor INTERPOLATED_PIXEL_ADJUSTMENT calculations just to codepaths actually touching the internal framebuffers

This commit is contained in:
Aaron Culliney 2015-05-28 23:23:21 -07:00
parent aee1111cb0
commit cb72d483c0
8 changed files with 55 additions and 57 deletions

View File

@ -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);
}
// ----------------------------------------------------------------------------

View File

@ -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<row_max; row++, idx+=message_cols+1) {
interface_printMessage(fb, fb_pix_width, col, row, cs, &message[ idx ]);
int fb_pix_width = (message_cols*FONT80_WIDTH_PIXELS);
for (int row=0, idx=0; row<message_rows; row++, idx+=message_cols+1) {
_interface_plotLine(fb, fb_pix_width, 0, 0, row, cs, &message[ idx ]);
}
}
@ -148,12 +146,25 @@ void interface_printMessageCentered(uint8_t *fb, int fb_cols, int fb_rows, inter
#ifdef INTERFACE_CLASSIC
static void _interface_plotMessageCentered(uint8_t *fb, int fb_cols, int fb_rows, interface_colorscheme_t cs, char *message, const int message_cols, const 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;
assert(fb_pix_width == SCANWIDTH);
int row_max = row + message_rows;
for (int idx=0; row<row_max; row++, idx+=message_cols+1) {
_interface_plotLine(fb, fb_pix_width, _INTERPOLATED_PIXEL_ADJUSTMENT_PRE, col, row, cs, &message[ idx ]);
}
}
static struct stat statbuf = { 0 };
static int altdrive = 0;
bool in_interface = false;
void video_plotchar(const int col, const int row, const interface_colorscheme_t cs, const uint8_t c) {
interface_plotChar(video__fb1, SCANWIDTH, col, row, cs, c);
unsigned int off = row * SCANWIDTH * FONT_HEIGHT_PIXELS + col * FONT80_WIDTH_PIXELS + _INTERPOLATED_PIXEL_ADJUSTMENT_PRE;
interface_plotChar(video__fb1+off, SCANWIDTH, cs, c);
}
void copy_and_pad_string(char *dest, const char* src, const char c, const int len, const char cap) {
@ -186,7 +197,7 @@ static void pad_string(char *s, const char c, const int len) {
}
void c_interface_print( int x, int y, const interface_colorscheme_t cs, const char *s ) {
interface_printMessage(video__fb1, SCANWIDTH, x, y, cs, s);
_interface_plotLine(video__fb1, SCANWIDTH, _INTERPOLATED_PIXEL_ADJUSTMENT_PRE, x, y, cs, s);
}
/* -------------------------------------------------------------------------
@ -207,7 +218,7 @@ void c_interface_translate_screen( char screen[24][INTERFACE_SCREEN_X+1] ) {
}
void c_interface_print_submenu_centered( char *submenu, const int message_cols, const int message_rows ) {
interface_printMessageCentered(video__fb1, INTERFACE_SCREEN_X, TEXT_ROWS, RED_ON_BLACK, submenu, message_cols, message_rows);
_interface_plotMessageCentered(video__fb1, INTERFACE_SCREEN_X, TEXT_ROWS, RED_ON_BLACK, submenu, message_cols, message_rows);
}
/* ------------------------------------------------------------------------- */

View File

@ -39,14 +39,11 @@ void c_interface_translate_screen(char screen[24][INTERFACE_SCREEN_X+1]);
void c_interface_select_diskette(int);
#endif
// Plots a character into the specified framebuffer
void interface_plotChar(uint8_t *fb, int fb_pix_width, int col, int row, interface_colorscheme_t cs, uint8_t c);
// Plot character at pixel buffer offset
void interface_plotChar(uint8_t *fboff, int fb_pix_width, interface_colorscheme_t cs, uint8_t c);
// Plots a string/template into the specified framebuffer
void interface_printMessage(uint8_t *fb, int fb_pix_width, int col, int row, interface_colorscheme_t cs, const char *message);
// Plots a string/template into the specified framebuffer
void interface_printMessageCentered(uint8_t *fb, int fb_cols, int fb_rows, interface_colorscheme_t cs, char *message, int message_cols, int message_rows);
// Plot message into pixel buffer
void interface_plotMessage(uint8_t *fb, interface_colorscheme_t cs, char *message, int message_cols, int message_rows);
#if INTERFACE_TOUCH
typedef enum interface_touch_event_t {

View File

@ -38,7 +38,7 @@ static void _alertToModel(char *message, unsigned int messageCols, unsigned int
mdlDestroyModel(&messageModel);
const unsigned int fbWidth = ((messageCols * FONT80_WIDTH_PIXELS) + INTERPOLATED_PIXEL_ADJUSTMENT);
const unsigned int fbWidth = (messageCols * FONT80_WIDTH_PIXELS);
const unsigned int fbHeight = (messageRows * FONT_HEIGHT_PIXELS);
messageModel = mdlCreateQuad(-0.3, -0.3, 0.7, 0.7, MODEL_DEPTH, fbWidth, fbHeight, GL_RGBA/*RGBA_8888*/, (GLCustom){

View File

@ -29,7 +29,7 @@ void glhud_setupDefault(GLModel *parent) {
uint8_t *fb = hudElement->pixels;
// 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;

View File

@ -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

View File

@ -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; i<FONT_HEIGHT_PIXELS; i++) {
@ -228,14 +227,13 @@ static inline bool _is_point_on_keyboard(float x, float y) {
static inline void _screen_to_keyboard(float x, float y, OUTPARM int *col, OUTPARM int *row) {
GLModelHUDKeyboard *hudKeyboard = (GLModelHUDKeyboard *)(kbd.model->custom);
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) {

View File

@ -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) {