| 241 | } |
| 242 | |
| 243 | static Pen doGetTile_map(int x, int y, int32_t * df::graphic_viewportst::*texpos_field) { |
| 244 | auto &vp = gps->main_viewport; |
| 245 | |
| 246 | if (x < 0 || x >= vp->dim_x || y < 0 || y >= vp->dim_y) |
| 247 | return Pen(0, 0, 0, -1); |
| 248 | |
| 249 | size_t max_index = vp->dim_x * vp->dim_y - 1; |
| 250 | size_t index = (x * vp->dim_y) + y; |
| 251 | |
| 252 | if (index < 0 || index > max_index) |
| 253 | return Pen(0, 0, 0, -1); |
| 254 | |
| 255 | int tile = 0; |
| 256 | if (!texpos_field) { |
| 257 | tile = vp->screentexpos_interface[index]; |
| 258 | if (tile == 0) |
| 259 | tile = vp->screentexpos[index]; |
| 260 | if (tile == 0) |
| 261 | tile = vp->screentexpos_item[index]; |
| 262 | if (tile == 0) |
| 263 | tile = vp->screentexpos_building_one[index]; |
| 264 | if (tile == 0) |
| 265 | tile = vp->screentexpos_background_two[index]; |
| 266 | if (tile == 0) |
| 267 | tile = vp->screentexpos_background[index]; |
| 268 | } else { |
| 269 | tile = (vp->*texpos_field)[index]; |
| 270 | } |
| 271 | |
| 272 | char ch = 0; |
| 273 | uint8_t fg = 0; |
| 274 | uint8_t bg = 0; |
| 275 | return Pen(ch, fg, bg, tile, false); |
| 276 | } |
| 277 | |
| 278 | static uint8_t to_16_bit_color(uint8_t *rgb) { |
| 279 | for (uint8_t c = 0; c < 16; ++c) { |