Skip to content

Commit

Permalink
Better preserve position when making an image empty.
Browse files Browse the repository at this point in the history
Previous code could set left to (uint16_t) -1 on a total crop.
Don't!
  • Loading branch information
kohler committed Oct 11, 2023
1 parent 06d5336 commit 76b1f02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/giffunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ Gif_CopyImage(Gif_Image *src)
void Gif_MakeImageEmpty(Gif_Image* gfi) {
Gif_ReleaseUncompressedImage(gfi);
Gif_ReleaseCompressedImage(gfi);
gfi->left = gfi->top = 0;
gfi->width = gfi->height = 1;
gfi->left = gfi->left < 0xFFFE ? gfi->left : 0xFFFE;
gfi->top = gfi->top < 0xFFFE ? gfi->top : 0xFFFE;
gfi->width = 1;
gfi->height = 1;
gfi->transparent = 0;
Gif_CreateUncompressedImage(gfi, 0);
gfi->img[0][0] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,9 @@ analyze_crop(int nmerger, Gt_Crop* crop, int compress_immediately)
}
}

if (t > b)
if (t > b) {
crop->w = crop->h = 0;
else {
} else {
crop->x = l;
crop->y = t;
crop->w = r - l;
Expand Down
8 changes: 4 additions & 4 deletions src/xform.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,18 @@ crop_image(Gif_Image* gfi, Gt_Frame* fr, int preserve_total_crop)
gfi->img[j] = old_img[c.y + j] + c.x;
gfi->img[c.h] = 0;
Gif_DeleteArray(old_img);
gfi->left += c.x - fr->left_offset;
gfi->top += c.y - fr->top_offset;
gfi->width = c.w;
gfi->height = c.h;
} else if (preserve_total_crop)
} else if (preserve_total_crop) {
Gif_MakeImageEmpty(gfi);
else {
} else {
Gif_DeleteArray(gfi->img);
gfi->img = 0;
gfi->width = gfi->height = 0;
}

gfi->left += c.x - fr->left_offset;
gfi->top += c.y - fr->top_offset;
return gfi->img != 0;
}

Expand Down

0 comments on commit 76b1f02

Please sign in to comment.