assembling: Fix copying only partial tile on overhang

If the tile in question was hanging over the left edge we would not be
copying the full available width. Fix this and change the test to catch
the error condition (by forcing a too small image and overlap both
ways).

Simplify the code by only selecting the starting point inside the
image/frame and then just checking the both image and frame boundary in
the loop. Not quite as efficient, but it really shouldn't matter too
much here.
This commit is contained in:
Benjamin Berg
2021-06-23 17:42:59 +02:00
parent 1ed2b23902
commit 51cab75b1e
2 changed files with 20 additions and 53 deletions

View File

@@ -62,6 +62,7 @@ test_frame_assembling (void)
int test_height;
guchar *data;
struct fpi_frame_asmbl_ctx ctx = { 0, };
gint xborder = 5;
g_autoptr(FpImage) fp_img = NULL;
GSList *frames = NULL;
@@ -79,7 +80,7 @@ test_frame_assembling (void)
ctx.get_pixel = cairo_get_pixel;
ctx.frame_width = width;
ctx.frame_height = 20;
ctx.image_width = width;
ctx.image_width = width - 2 * xborder;
g_assert (height > ctx.frame_height);
@@ -118,8 +119,8 @@ test_frame_assembling (void)
/* The FpImage and cairo surface need to be identical in the test area */
for (int y = 0; y < test_height; y++)
for (int x = 0; x < width; x++)
g_assert_cmpint (data[x * 4 + y * stride + 1], ==, fp_img->data[x + y * width]);
for (int x = 0; x < ctx.image_width; x++)
g_assert_cmpint (data[(x + xborder) * 4 + y * stride + 1], ==, fp_img->data[x + y * ctx.image_width]);
g_slist_free_full (frames, g_free);
cairo_surface_destroy (img);