Skip to content

Commit

Permalink
Merge pull request #6 from Giphy/gif-transparency-fix-deployed
Browse files Browse the repository at this point in the history
Gif transparency fix deployed
  • Loading branch information
cyburgee authored Jun 30, 2020
2 parents 2fc69e5 + 9f697ed commit 42b0cd6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libavcodec/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,
while (*y_start < y_end) {
int is_trans = 1;
for (int i = 0; i < w; i++) {
if (buf[w * *y_start + i] != trans) {
if (buf[linesize * *y_start + i] != trans) {
is_trans = 0;
break;
}
Expand All @@ -148,10 +148,10 @@ static void gif_crop_translucent(AVCodecContext *avctx,
}

// crop bottom
while (y_end < h) {
while (y_end > *y_start) {
int is_trans = 1;
for (int i = 0; i < w; i++) {
if (buf[w * y_end + i] != trans) {
if (buf[linesize * y_end + i] != trans) {
is_trans = 0;
break;
}
Expand All @@ -165,7 +165,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,
while (*x_start < x_end) {
int is_trans = 1;
for (int i = *y_start; i < y_end; i++) {
if (buf[w * i + *x_start] != trans) {
if (buf[linesize * i + *x_start] != trans) {
is_trans = 0;
break;
}
Expand All @@ -176,10 +176,10 @@ static void gif_crop_translucent(AVCodecContext *avctx,
}

// crop right
while (x_end < w) {
while (x_end > *x_start) {
int is_trans = 1;
for (int i = *y_start; i < y_end; i++) {
if (buf[w * i + x_end] != trans) {
if (buf[linesize * i + x_end] != trans) {
is_trans = 0;
break;
}
Expand All @@ -191,6 +191,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,

*height = y_end + 1 - *y_start;
*width = x_end + 1 - *x_start;

av_log(avctx, AV_LOG_DEBUG,"%dx%d image at pos (%d;%d) [area:%dx%d]\n",
*width, *height, *x_start, *y_start, avctx->width, avctx->height);
}
Expand Down Expand Up @@ -267,7 +268,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) && s->last_frame && !palette;
const uint8_t *ptr;

if (!s->image && avctx->frame_number && is_image_translucent(avctx, buf, linesize)) {
if (!s->image && is_image_translucent(avctx, buf, linesize)) {
gif_crop_translucent(avctx, buf, linesize, &width, &height, &x_start, &y_start);
honor_transparency = 0;
disposal = GCE_DISPOSAL_BACKGROUND;
Expand Down

0 comments on commit 42b0cd6

Please sign in to comment.