+ int *width, int *height,
+ int *x_start, int *y_start)
+{
+ GIFContext *s = avctx->priv_data;
+ int trans = s->transparent_index;
+
+ /* Crop image */
+ if ((s->flags & GF_OFFSETTING) && trans >= 0) {
+ const int w = avctx->width;
+ const int h = avctx->height;
+ int x_end = w - 1,
+ y_end = h - 1;
+
+ // crop top
+ while (*y_start < y_end) {
+ int is_trans = 1;
+ for (int i = 0; i < w; i++) {
+ if (buf[linesize * *y_start + i] != trans) {
+ is_trans = 0;
+ break;
+ }
+ }
+
+ if (!is_trans)
+ break;
+ (*y_start)++;
+ }
+
+ // crop bottom
+ while (y_end > *y_start) {
+ int is_trans = 1;
+ for (int i = 0; i < w; i++) {
+ if (buf[linesize * y_end + i] != trans) {
+ is_trans = 0;
+ break;
+ }
+ }
+ if (!is_trans)
+ break;
+ y_end--;
+ }
+
+ // crop left
+ while (*x_start < x_end) {
+ int is_trans = 1;
+ for (int i = *y_start; i < y_end; i++) {
+ if (buf[linesize * i + *x_start] != trans) {
+ is_trans = 0;
+ break;
+ }
+ }
+ if (!is_trans)
+ break;
+ (*x_start)++;
+ }
+
+ // crop right
+ while (x_end > *x_start) {
+ int is_trans = 1;
+ for (int i = *y_start; i < y_end; i++) {
+ if (buf[linesize * i + x_end] != trans) {
+ is_trans = 0;
+ break;
+ }
+ }
+ if (!is_trans)
+ break;
+ x_end--;
+ }
+
+ *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);
+ }
+}
+
+static void gif_crop_opaque(AVCodecContext *avctx,
+ const uint32_t *palette,
+ const uint8_t *buf, const int linesize,
+ int *width, int *height, int *x_start, int *y_start)