Clarify pixel address computation

This commit is contained in:
Přemysl Eric Janouch 2014-10-27 16:48:06 +01:00
parent ac22d17491
commit 50842917f6
1 changed files with 11 additions and 17 deletions

View File

@ -74,6 +74,8 @@ struct client
struct msg_reader msg_reader; ///< Client message reader 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; typedef struct app_context app_context_t;
struct app_context struct app_context
{ {
@ -370,15 +372,10 @@ redraw_canvas (app_context_t *app)
int x = app->corner_x; int x = app->corner_x;
for (int screen_x = 0; screen_x < COLS; screen_x++, x++) for (int screen_x = 0; screen_x < COLS; screen_x++, x++)
{ {
uint8_t color; uint8_t color = 0;
if (!is_in_bitmap_data (app, x, y)) if (is_in_bitmap_data (app, x, y))
color = 0; color = BITMAP_PIXEL (app,
else x - app->bitmap_x, y - app->bitmap_y);
{
int data_x = x - app->bitmap_x;
int data_y = y - app->bitmap_y;
color = app->bitmap[data_y * app->bitmap_w + data_x];
}
addch (app->palette[color]); addch (app->palette[color]);
} }
@ -445,10 +442,7 @@ static void
draw_point (app_context_t *app, int x, int y, uint8_t color) draw_point (app_context_t *app, int x, int y, uint8_t color)
{ {
make_place_for_point (app, x, y); make_place_for_point (app, x, y);
BITMAP_PIXEL (app, x - app->bitmap_x, y - app->bitmap_y) = color;
int data_x = x - app->bitmap_x;
int data_y = y - app->bitmap_y;
app->bitmap[data_y * app->bitmap_w + data_x] = color;
if (is_visible (app, x, y)) if (is_visible (app, x, y))
{ {
@ -572,8 +566,8 @@ export_ansi (app_context_t *app)
const char *color = NULL; const char *color = NULL;
for (size_t column = 0; column < w; column++) for (size_t column = 0; column < w; column++)
{ {
const char *new_color = color_to_ansi (app->bitmap[ const char *new_color = color_to_ansi
(y + row) * app->bitmap_w + (x + column)]); (BITMAP_PIXEL (app, x + column, y + row));
if (color != new_color) if (color != new_color)
fputs (new_color, fp); fputs (new_color, fp);
color = new_color; color = new_color;
@ -648,8 +642,8 @@ export_irc (app_context_t *app)
int color = MIRC_NONE; int color = MIRC_NONE;
for (size_t column = 0; column < w; column++) for (size_t column = 0; column < w; column++)
{ {
int new_color = color_to_mirc (app->bitmap[ int new_color = color_to_mirc
(y + row) * app->bitmap_w + (x + column)]); (BITMAP_PIXEL (app, x + column, y + row));
if (color != new_color) if (color != new_color)
fprintf (fp, "\x03%02d,%02d", new_color, new_color); fprintf (fp, "\x03%02d,%02d", new_color, new_color);
color = new_color; color = new_color;