diff options
author | Benjamin Dahse <ronoueb@gmail.com> | 2017-06-14 15:56:58 +0200 |
---|---|---|
committer | Benjamin Dahse <ronoueb@gmail.com> | 2017-06-14 15:56:58 +0200 |
commit | 075997c5634ff71bdb7d8640f3edea5f77482da0 (patch) | |
tree | efedcdf89335b85a1648cd00423fb49ba045ec03 /core | |
parent | ffe61e63d145b6e12a9f259259bb097777e7f1ae (diff) |
Rewrite Image::blit_rect to use the following algorithm:
1. Let r1 be the source rectangle clipped against the entire source image rectangle.
2. Let r2 be r1 offset by p_dest, clipped against the entire destination image rectangle.
3. Copy pixels from r1 to r2.
Diffstat (limited to 'core')
-rw-r--r-- | core/image.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/image.cpp b/core/image.cpp index 94b01d9332..380b307020 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1612,11 +1612,11 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po ERR_FAIL_COND(srcdsize == 0); ERR_FAIL_COND(format != p_src->format); - Rect2i local_src_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest + p_src_rect.position, p_src_rect.size)); - - if (local_src_rect.size.x <= 0 || local_src_rect.size.y <= 0) + Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect); + if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) return; - Rect2i src_rect(p_src_rect.position + (local_src_rect.position - p_dest), local_src_rect.size); + + Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest, clipped_src_rect.size)); PoolVector<uint8_t>::Write wp = data.write(); uint8_t *dst_data_ptr = wp.ptr(); @@ -1626,15 +1626,15 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po int pixel_size = get_format_pixel_size(format); - for (int i = 0; i < src_rect.size.y; i++) { + for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < src_rect.size.x; j++) { + for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = src_rect.position.x + j; - int src_y = src_rect.position.y + i; + int src_x = clipped_src_rect.position.x + j; + int src_y = clipped_src_rect.position.y + i; - int dst_x = local_src_rect.position.x + j; - int dst_y = local_src_rect.position.y + i; + int dst_x = dest_rect.position.x + j; + int dst_y = dest_rect.position.y + i; const uint8_t *src = &src_data_ptr[(src_y * p_src->width + src_x) * pixel_size]; uint8_t *dst = &dst_data_ptr[(dst_y * width + dst_x) * pixel_size]; |