diff --git a/src/r_patch.c b/src/r_patch.c index dab600ed1..4c4cdc019 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -235,7 +235,7 @@ column_t *Patch_GetColumn(patch_t *patch, unsigned column) void *Patch_GetPixel(patch_t *patch, INT32 x, INT32 y) { - if (x < 0 || x >= patch->width) + if (x < 0 || x >= patch->width || y < 0 || y >= patch->height) return NULL; if (Patch_NeedsUpdate(patch)) @@ -244,6 +244,17 @@ void *Patch_GetPixel(patch_t *patch, INT32 x, INT32 y) if (patch->columns == NULL) return NULL; + bitarray_t *pixels_opaque = Patch_GetOpaqueRegions(patch); + if (pixels_opaque) + { + size_t position = (x * patch->height) + y; + + if (!in_bit_array(pixels_opaque, position)) + return NULL; + + return &patch->pixels[position]; + } + column_t *column = &patch->columns[x]; for (unsigned i = 0; i < column->num_posts; i++)