From 50842917f64606507fc08173e7789438c9fb44f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Mon, 27 Oct 2014 16:48:06 +0100 Subject: Clarify pixel address computation --- autistdraw.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/autistdraw.c b/autistdraw.c index f6dd2ec..258f24b 100644 --- a/autistdraw.c +++ b/autistdraw.c @@ -74,6 +74,8 @@ struct client struct msg_reader msg_reader; ///< Client message reader }; +#define BITMAP_PIXEL(app, x, y) (app)->bitmap[(y) * (app)->bitmap_w + (x)] + typedef struct app_context app_context_t; struct app_context { @@ -370,15 +372,10 @@ redraw_canvas (app_context_t *app) int x = app->corner_x; for (int screen_x = 0; screen_x < COLS; screen_x++, x++) { - uint8_t color; - if (!is_in_bitmap_data (app, x, y)) - color = 0; - else - { - int data_x = x - app->bitmap_x; - int data_y = y - app->bitmap_y; - color = app->bitmap[data_y * app->bitmap_w + data_x]; - } + uint8_t color = 0; + if (is_in_bitmap_data (app, x, y)) + color = BITMAP_PIXEL (app, + x - app->bitmap_x, y - app->bitmap_y); addch (app->palette[color]); } @@ -445,10 +442,7 @@ static void draw_point (app_context_t *app, int x, int y, uint8_t color) { make_place_for_point (app, x, y); - - int data_x = x - app->bitmap_x; - int data_y = y - app->bitmap_y; - app->bitmap[data_y * app->bitmap_w + data_x] = color; + BITMAP_PIXEL (app, x - app->bitmap_x, y - app->bitmap_y) = color; if (is_visible (app, x, y)) { @@ -572,8 +566,8 @@ export_ansi (app_context_t *app) const char *color = NULL; for (size_t column = 0; column < w; column++) { - const char *new_color = color_to_ansi (app->bitmap[ - (y + row) * app->bitmap_w + (x + column)]); + const char *new_color = color_to_ansi + (BITMAP_PIXEL (app, x + column, y + row)); if (color != new_color) fputs (new_color, fp); color = new_color; @@ -648,8 +642,8 @@ export_irc (app_context_t *app) int color = MIRC_NONE; for (size_t column = 0; column < w; column++) { - int new_color = color_to_mirc (app->bitmap[ - (y + row) * app->bitmap_w + (x + column)]); + int new_color = color_to_mirc + (BITMAP_PIXEL (app, x + column, y + row)); if (color != new_color) fprintf (fp, "\x03%02d,%02d", new_color, new_color); color = new_color; -- cgit v1.2.3