in libs/screen/image.cpp [362:400]
void mapRect(Image_ img, int x, int y, int w, int h, Buffer map) {
if (w == 0 || h == 0 || x >= img->width() || y >= img->height())
return;
if (img->bpp() != 4 || map->length < 16)
return;
int x2 = x + w - 1;
int y2 = y + h - 1;
if (x2 < 0 || y2 < 0)
return;
img->clamp(&x2, &y2);
img->clamp(&x, &y);
w = x2 - x + 1;
h = y2 - y + 1;
img->makeWritable();
auto bh = img->byteHeight();
auto m = map->data;
uint8_t *p = img->pix(x, y);
while (w-- > 0) {
auto ptr = p;
unsigned shift = y & 1;
for (int i = 0; i < h; i++) {
if (shift) {
*ptr = (m[*ptr >> 4] << 4) | (*ptr & 0x0f);
ptr++;
shift = 0;
} else {
*ptr = (m[*ptr & 0xf] & 0xf) | (*ptr & 0xf0);
shift = 1;
}
}
p += bh;
}
}