Skip to content
Snippets Groups Projects
Commit 9904ac4b authored by Andre Offringa's avatar Andre Offringa
Browse files

Merge branch 'fix-out-of-bounds-bug' into 'master'

Fix possible out of bounds errors in AddToImage()

See merge request !119
parents 27e0f4cc 8dcc7cff
No related branches found
No related tags found
1 merge request!119Fix possible out of bounds errors in AddToImage()
Pipeline #47913 passed
......@@ -119,7 +119,10 @@ class FacetImage {
/**
* Add this facet to the provided full image and weight image,
* using a specified weight mask.
* using a specified weight mask. In case the facet extends beyond
* the right (high x) or bottom (high y) edges, the facet image is
* trimmed on this side to fall inside the full image. This
* situation might arise because of the alignment requirements.
* @param[in,out] image Full image to which the data from this facet will be
* added.
* @param[in,out] weight Weight image (same size as the full image) that will
......
......@@ -135,8 +135,12 @@ void FacetImage::AddWithMask(float* image, float* weight,
float* image_y = image + OffsetY() * image_width_ + OffsetX();
float* weight_y = weight + OffsetY() * image_width_ + OffsetX();
for (size_t y = 0; y != Height(); ++y) {
for (size_t x = 0; x != Width(); ++x) {
// Because of alignment, the facet's bounding box may slightly extend past
// the full image size, so make sure not to cross the boundary:
const size_t max_x = std::min(Width(), image_width_ - OffsetX());
const size_t max_y = std::min(Height(), image_height_ - OffsetY());
for (size_t y = 0; y != max_y; ++y) {
for (size_t x = 0; x != max_x; ++x) {
// Note that OffsetX() was already added above to image_y
image_y[x] += mask_y[x] * data_y[x];
weight_y[x] += mask_y[x];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment