static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                             const uint8_t *src, int size, int lines)
{
    PutByteContext pb;
    int c, line, pixels, code, ret;
    int width = ((s->width * s->bpp) + 7) >> 3;

    if (size <= 0)
        return AVERROR_INVALIDDATA;

    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
#if CONFIG_ZLIB
        return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
#else
        av_log(s->avctx, AV_LOG_ERROR,
               "zlib support not enabled, "
               "deflate compression not supported\n");
        return AVERROR(ENOSYS);
#endif
    }
    if (s->compr == TIFF_LZW) {
        if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
            av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
            return ret;
        }
        for (line = 0; line < lines; line++) {
            pixels = ff_lzw_decode(s->lzw, dst, width);
            if (pixels < width) {
                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
                       pixels, width);
                return AVERROR_INVALIDDATA;
            }
            dst += stride;
        }
        return 0;
    }
    if (s->compr == TIFF_CCITT_RLE ||
        s->compr == TIFF_G3        ||
        s->compr == TIFF_G4) {
        return tiff_unpack_fax(s, dst, stride, src, size, lines);
    }

    bytestream2_init(&s->gb, src, size);
    bytestream2_init_writer(&pb, dst, stride * lines);

    for (line = 0; line < lines; line++) {
        if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))
            break;
        bytestream2_seek_p(&pb, stride * line, SEEK_SET);
        switch (s->compr) {
        case TIFF_RAW:
            if (!s->fill_order) {
                bytestream2_copy_buffer(&pb, &s->gb, width);
            } else {
                int i;
                for (i = 0; i < width; i++)
                    bytestream2_put_byte(&pb, ff_reverse[bytestream2_get_byte(&s->gb)]);
            }
            break;
        case TIFF_PACKBITS:
            for (pixels = 0; pixels < width;) {
                code = ff_u8_to_s8(bytestream2_get_byte(&s->gb));
                if (code >= 0) {
                    code++;
                    bytestream2_copy_buffer(&pb, &s->gb, code);
                    pixels += code;
                } else if (code != -128) { // -127..-1
                    code = (-code) + 1;
                    c    = bytestream2_get_byte(&s->gb);
                    bytestream2_set_buffer(&pb, c, code);
                    pixels += code;
                }
            }
            break;
        }
    }
    return 0;
}