Skip to content

Commit

Permalink
Fix painting on none 256 aligned images.
Browse files Browse the repository at this point in the history
Internally the update tiles are 256x256. Due to some miscalculations
tiles were not generated correctly if the dimension of the image wasn't
a multifold of 256.
  • Loading branch information
jeroenbakker-atmind committed Mar 1, 2022
1 parent 34f6a99 commit 4a4701b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions source/blender/blenkernel/intern/image_partial_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ struct TileChangeset {
tile_width = image_buffer->x;
tile_height = image_buffer->y;

int chunk_x_len = tile_width / CHUNK_SIZE;
int chunk_y_len = tile_height / CHUNK_SIZE;
int chunk_x_len = (tile_width + CHUNK_SIZE - 1) / CHUNK_SIZE;
int chunk_y_len = (tile_height + CHUNK_SIZE - 1) / CHUNK_SIZE;
init_chunks(chunk_x_len, chunk_y_len);
return true;
}
Expand Down
16 changes: 15 additions & 1 deletion source/blender/draw/engines/image/image_drawing_mode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,21 @@ template<typename TextureMethod> class ScreenSpaceDrawingMode : public AbstractD
BLI_assert(float_buffer->rect == nullptr);
BLI_assert(src->rect_float == nullptr);
BLI_assert(src->rect != nullptr);
IMB_float_from_rect_ex(float_buffer, src, &iterator.changed_region.region);

/* Calculate the overlap between the updated region and the buffer size. Partial Update Checker
* always returns a tile (256x256). Which could lay partially outside the buffer when using
* different resolutions.
*/
rcti buffer_rect;
BLI_rcti_init(&buffer_rect, 0, float_buffer->x, 0, float_buffer->y);
rcti clipped_update_region;
const bool has_overlap = BLI_rcti_isect(
&buffer_rect, &iterator.changed_region.region, &clipped_update_region);
if (!has_overlap) {
return;
}

IMB_float_from_rect_ex(float_buffer, src, &clipped_update_region);
}

void do_partial_update(PartialUpdateChecker<ImageTileData>::CollectResult &iterator,
Expand Down

0 comments on commit 4a4701b

Please sign in to comment.