static int decode_frame(AVCodecContext *avctx,

                        void *data,

                        int *got_frame,

                        AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    DPXContext *const s = avctx->priv_data;

    AVFrame *picture  = data;

    AVFrame *const p = &s->picture;

    uint8_t *ptr[AV_NUM_DATA_POINTERS];



    unsigned int offset;

    int magic_num, endian;

    int x, y, i, ret;

    int w, h, bits_per_color, descriptor, elements, packing, total_size;



    unsigned int rgbBuffer = 0;

    int n_datum = 0;



    if (avpkt->size <= 1634) {

        av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n");

        return AVERROR_INVALIDDATA;

    }



    magic_num = AV_RB32(buf);

    buf += 4;



    /* Check if the files "magic number" is "SDPX" which means it uses

     * big-endian or XPDS which is for little-endian files */

    if (magic_num == AV_RL32("SDPX")) {

        endian = 0;

    } else if (magic_num == AV_RB32("SDPX")) {

        endian = 1;

    } else {

        av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n");

        return AVERROR_INVALIDDATA;

    }



    offset = read32(&buf, endian);

    if (avpkt->size <= offset) {

        av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n");

        return AVERROR_INVALIDDATA;

    }

    // Need to end in 0x304 offset from start of file

    buf = avpkt->data + 0x304;

    w = read32(&buf, endian);

    h = read32(&buf, endian);

    if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)

        return ret;



    if (w != avctx->width || h != avctx->height)

        avcodec_set_dimensions(avctx, w, h);



    // Need to end in 0x320 to read the descriptor

    buf += 20;

    descriptor = buf[0];



    // Need to end in 0x323 to read the bits per color

    buf += 3;

    avctx->bits_per_raw_sample =

    bits_per_color = buf[0];

    buf++;

    packing = *((uint16_t*)buf);



    buf += 824;

    avctx->sample_aspect_ratio.num = read32(&buf, endian);

    avctx->sample_aspect_ratio.den = read32(&buf, endian);

    if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)

        av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den,

                   avctx->sample_aspect_ratio.num,  avctx->sample_aspect_ratio.den,

                  0x10000);

    else

        avctx->sample_aspect_ratio = (AVRational){ 0, 1 };



    switch (descriptor) {

        case 51: // RGBA

            elements = 4;

            break;

        case 50: // RGB

            elements = 3;

            break;

        default:

            av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor);

            return AVERROR_INVALIDDATA;

    }



    switch (bits_per_color) {

        case 8:

            if (elements == 4) {

                avctx->pix_fmt = AV_PIX_FMT_RGBA;

            } else {

                avctx->pix_fmt = AV_PIX_FMT_RGB24;

            }

            total_size = avctx->width * avctx->height * elements;

            break;

        case 10:

            if (!packing) {

                av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n");

                return -1;

            }

            avctx->pix_fmt = AV_PIX_FMT_GBRP10;

            total_size = (avctx->width * avctx->height * elements + 2) / 3 * 4;

            break;

        case 12:

            if (!packing) {

                av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n");

                return -1;

            }

            if (endian) {

                avctx->pix_fmt = AV_PIX_FMT_GBRP12BE;

            } else {

                avctx->pix_fmt = AV_PIX_FMT_GBRP12LE;

            }

            total_size = 2 * avctx->width * avctx->height * elements;

            break;

        case 16:

            if (endian) {

                avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGB48BE;

            } else {

                avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGB48LE;

            }

            total_size = 2 * avctx->width * avctx->height * elements;

            break;

        default:

            av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color);

            return AVERROR_INVALIDDATA;

    }



    if (s->picture.data[0])

        avctx->release_buffer(avctx, &s->picture);

    if ((ret = ff_get_buffer(avctx, p)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }



    // Move pointer to offset from start of file

    buf =  avpkt->data + offset;



    for (i=0; i<AV_NUM_DATA_POINTERS; i++)

        ptr[i] = p->data[i];



    if (total_size > avpkt->size) {

        av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n");

        return AVERROR_INVALIDDATA;

    }

    switch (bits_per_color) {

    case 10:

        for (x = 0; x < avctx->height; x++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (y = 0; y < avctx->width; y++) {

                *dst[2]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                *dst[0]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                *dst[1]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                // For 10 bit, ignore alpha

                if (elements == 4)

                    read10in32(&buf, &rgbBuffer,

                               &n_datum, endian);

            }

            for (i = 0; i < 3; i++)

                ptr[i] += p->linesize[i];

        }

        break;

    case 12:

        for (x = 0; x < avctx->height; x++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (y = 0; y < avctx->width; y++) {

                *dst[2] = *((uint16_t*)buf);

                *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12);

                dst[2]++;

                buf += 2;

                *dst[0] = *((uint16_t*)buf);

                *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12);

                dst[0]++;

                buf += 2;

                *dst[1] = *((uint16_t*)buf);

                *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12);

                dst[1]++;

                buf += 2;

                // For 12 bit, ignore alpha

                if (elements == 4)

                    buf += 2;

            }

            for (i = 0; i < 3; i++)

                ptr[i] += p->linesize[i];

        }

        break;

    case 16:

        elements *= 2;

    case 8:

        for (x = 0; x < avctx->height; x++) {

            memcpy(ptr[0], buf, elements*avctx->width);

            ptr[0] += p->linesize[0];

            buf += elements*avctx->width;

        }

        break;

    }



    *picture   = s->picture;

    *got_frame = 1;



    return buf_size;

}

static int decode_frame(AVCodecContext *avctx,

                        void *data,

                        int *got_frame,

                        AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    DPXContext *const s = avctx->priv_data;

    AVFrame *picture  = data;

    AVFrame *const p = &s->picture;

    uint8_t *ptr[AV_NUM_DATA_POINTERS];



    unsigned int offset;

    int magic_num, endian;

    int x, y, i, ret;

    int w, h, bits_per_color, descriptor, elements, packing, total_size;



    unsigned int rgbBuffer = 0;

    int n_datum = 0;



    if (avpkt->size <= 1634) {

        av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n");

        return AVERROR_INVALIDDATA;

    }



    magic_num = AV_RB32(buf);

    buf += 4;



    



    if (magic_num == AV_RL32("SDPX")) {

        endian = 0;

    } else if (magic_num == AV_RB32("SDPX")) {

        endian = 1;

    } else {

        av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n");

        return AVERROR_INVALIDDATA;

    }



    offset = read32(&buf, endian);

    if (avpkt->size <= offset) {

        av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n");

        return AVERROR_INVALIDDATA;

    }

    

    buf = avpkt->data + 0x304;

    w = read32(&buf, endian);

    h = read32(&buf, endian);

    if ((ret = av_image_check_size(w, h, 0, avctx)) < 0)

        return ret;



    if (w != avctx->width || h != avctx->height)

        avcodec_set_dimensions(avctx, w, h);



    

    buf += 20;

    descriptor = buf[0];



    

    buf += 3;

    avctx->bits_per_raw_sample =

    bits_per_color = buf[0];

    buf++;

    packing = *((uint16_t*)buf);



    buf += 824;

    avctx->sample_aspect_ratio.num = read32(&buf, endian);

    avctx->sample_aspect_ratio.den = read32(&buf, endian);

    if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)

        av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den,

                   avctx->sample_aspect_ratio.num,  avctx->sample_aspect_ratio.den,

                  0x10000);

    else

        avctx->sample_aspect_ratio = (AVRational){ 0, 1 };



    switch (descriptor) {

        case 51: 

            elements = 4;

            break;

        case 50: 

            elements = 3;

            break;

        default:

            av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor);

            return AVERROR_INVALIDDATA;

    }



    switch (bits_per_color) {

        case 8:

            if (elements == 4) {

                avctx->pix_fmt = AV_PIX_FMT_RGBA;

            } else {

                avctx->pix_fmt = AV_PIX_FMT_RGB24;

            }

            total_size = avctx->width * avctx->height * elements;

            break;

        case 10:

            if (!packing) {

                av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n");

                return -1;

            }

            avctx->pix_fmt = AV_PIX_FMT_GBRP10;

            total_size = (avctx->width * avctx->height * elements + 2) / 3 * 4;

            break;

        case 12:

            if (!packing) {

                av_log(avctx, AV_LOG_ERROR, "Packing to 16bit required\n");

                return -1;

            }

            if (endian) {

                avctx->pix_fmt = AV_PIX_FMT_GBRP12BE;

            } else {

                avctx->pix_fmt = AV_PIX_FMT_GBRP12LE;

            }

            total_size = 2 * avctx->width * avctx->height * elements;

            break;

        case 16:

            if (endian) {

                avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGB48BE;

            } else {

                avctx->pix_fmt = elements == 4 ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGB48LE;

            }

            total_size = 2 * avctx->width * avctx->height * elements;

            break;

        default:

            av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color);

            return AVERROR_INVALIDDATA;

    }



    if (s->picture.data[0])

        avctx->release_buffer(avctx, &s->picture);

    if ((ret = ff_get_buffer(avctx, p)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }



    

    buf =  avpkt->data + offset;



    for (i=0; i<AV_NUM_DATA_POINTERS; i++)

        ptr[i] = p->data[i];



    if (total_size > avpkt->size) {

        av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n");

        return AVERROR_INVALIDDATA;

    }

    switch (bits_per_color) {

    case 10:

        for (x = 0; x < avctx->height; x++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (y = 0; y < avctx->width; y++) {

                *dst[2]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                *dst[0]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                *dst[1]++ = read10in32(&buf, &rgbBuffer,

                                       &n_datum, endian);

                

                if (elements == 4)

                    read10in32(&buf, &rgbBuffer,

                               &n_datum, endian);

            }

            for (i = 0; i < 3; i++)

                ptr[i] += p->linesize[i];

        }

        break;

    case 12:

        for (x = 0; x < avctx->height; x++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (y = 0; y < avctx->width; y++) {

                *dst[2] = *((uint16_t*)buf);

                *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12);

                dst[2]++;

                buf += 2;

                *dst[0] = *((uint16_t*)buf);

                *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12);

                dst[0]++;

                buf += 2;

                *dst[1] = *((uint16_t*)buf);

                *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12);

                dst[1]++;

                buf += 2;

                

                if (elements == 4)

                    buf += 2;

            }

            for (i = 0; i < 3; i++)

                ptr[i] += p->linesize[i];

        }

        break;

    case 16:

        elements *= 2;

    case 8:

        for (x = 0; x < avctx->height; x++) {

            memcpy(ptr[0], buf, elements*avctx->width);

            ptr[0] += p->linesize[0];

            buf += elements*avctx->width;

        }

        break;

    }



    *picture   = s->picture;

    *got_frame = 1;



    return buf_size;

}

static int FUNC_0(AVCodecContext *VAR_0,

                        void *VAR_1,

                        int *VAR_2,

                        AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5       = VAR_3->size;

    DPXContext *const s = VAR_0->priv_data;

    AVFrame *picture  = VAR_1;

    AVFrame *const p = &s->picture;

    uint8_t *ptr[AV_NUM_DATA_POINTERS];



    unsigned int VAR_6;

    int VAR_7, VAR_8;

    int VAR_9, VAR_10, VAR_11, VAR_12;

    int VAR_13, VAR_14, VAR_15, VAR_16, VAR_17, VAR_18, VAR_19;



    unsigned int VAR_20 = 0;

    int VAR_21 = 0;



    if (VAR_3->size <= 1634) {

        av_log(VAR_0, AV_LOG_ERROR, "Packet too small for DPX header\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_7 = AV_RB32(VAR_4);

    VAR_4 += 4;



    



    if (VAR_7 == AV_RL32("SDPX")) {

        VAR_8 = 0;

    } else if (VAR_7 == AV_RB32("SDPX")) {

        VAR_8 = 1;

    } else {

        av_log(VAR_0, AV_LOG_ERROR, "DPX marker not found\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_6 = read32(&VAR_4, VAR_8);

    if (VAR_3->size <= VAR_6) {

        av_log(VAR_0, AV_LOG_ERROR, "Invalid VAR_1 start VAR_6\n");

        return AVERROR_INVALIDDATA;

    }

    

    VAR_4 = VAR_3->VAR_1 + 0x304;

    VAR_13 = read32(&VAR_4, VAR_8);

    VAR_14 = read32(&VAR_4, VAR_8);

    if ((VAR_12 = av_image_check_size(VAR_13, VAR_14, 0, VAR_0)) < 0)

        return VAR_12;



    if (VAR_13 != VAR_0->width || VAR_14 != VAR_0->height)

        avcodec_set_dimensions(VAR_0, VAR_13, VAR_14);



    

    VAR_4 += 20;

    VAR_16 = VAR_4[0];



    

    VAR_4 += 3;

    VAR_0->bits_per_raw_sample =

    VAR_15 = VAR_4[0];

    VAR_4++;

    VAR_18 = *((uint16_t*)VAR_4);



    VAR_4 += 824;

    VAR_0->sample_aspect_ratio.num = read32(&VAR_4, VAR_8);

    VAR_0->sample_aspect_ratio.den = read32(&VAR_4, VAR_8);

    if (VAR_0->sample_aspect_ratio.num > 0 && VAR_0->sample_aspect_ratio.den > 0)

        av_reduce(&VAR_0->sample_aspect_ratio.num, &VAR_0->sample_aspect_ratio.den,

                   VAR_0->sample_aspect_ratio.num,  VAR_0->sample_aspect_ratio.den,

                  0x10000);

    else

        VAR_0->sample_aspect_ratio = (AVRational){ 0, 1 };



    switch (VAR_16) {

        case 51: 

            VAR_17 = 4;

            break;

        case 50: 

            VAR_17 = 3;

            break;

        default:

            av_log(VAR_0, AV_LOG_ERROR, "Unsupported VAR_16 %d\n", VAR_16);

            return AVERROR_INVALIDDATA;

    }



    switch (VAR_15) {

        case 8:

            if (VAR_17 == 4) {

                VAR_0->pix_fmt = AV_PIX_FMT_RGBA;

            } else {

                VAR_0->pix_fmt = AV_PIX_FMT_RGB24;

            }

            VAR_19 = VAR_0->width * VAR_0->height * VAR_17;

            break;

        case 10:

            if (!VAR_18) {

                av_log(VAR_0, AV_LOG_ERROR, "Packing to 32bit required\n");

                return -1;

            }

            VAR_0->pix_fmt = AV_PIX_FMT_GBRP10;

            VAR_19 = (VAR_0->width * VAR_0->height * VAR_17 + 2) / 3 * 4;

            break;

        case 12:

            if (!VAR_18) {

                av_log(VAR_0, AV_LOG_ERROR, "Packing to 16bit required\n");

                return -1;

            }

            if (VAR_8) {

                VAR_0->pix_fmt = AV_PIX_FMT_GBRP12BE;

            } else {

                VAR_0->pix_fmt = AV_PIX_FMT_GBRP12LE;

            }

            VAR_19 = 2 * VAR_0->width * VAR_0->height * VAR_17;

            break;

        case 16:

            if (VAR_8) {

                VAR_0->pix_fmt = VAR_17 == 4 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGB48BE;

            } else {

                VAR_0->pix_fmt = VAR_17 == 4 ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGB48LE;

            }

            VAR_19 = 2 * VAR_0->width * VAR_0->height * VAR_17;

            break;

        default:

            av_log(VAR_0, AV_LOG_ERROR, "Unsupported color depth : %d\n", VAR_15);

            return AVERROR_INVALIDDATA;

    }



    if (s->picture.VAR_1[0])

        VAR_0->release_buffer(VAR_0, &s->picture);

    if ((VAR_12 = ff_get_buffer(VAR_0, p)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n");

        return VAR_12;

    }



    

    VAR_4 =  VAR_3->VAR_1 + VAR_6;



    for (VAR_11=0; VAR_11<AV_NUM_DATA_POINTERS; VAR_11++)

        ptr[VAR_11] = p->VAR_1[VAR_11];



    if (VAR_19 > VAR_3->size) {

        av_log(VAR_0, AV_LOG_ERROR, "Overread buffer. Invalid header?\n");

        return AVERROR_INVALIDDATA;

    }

    switch (VAR_15) {

    case 10:

        for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (VAR_10 = 0; VAR_10 < VAR_0->width; VAR_10++) {

                *dst[2]++ = read10in32(&VAR_4, &VAR_20,

                                       &VAR_21, VAR_8);

                *dst[0]++ = read10in32(&VAR_4, &VAR_20,

                                       &VAR_21, VAR_8);

                *dst[1]++ = read10in32(&VAR_4, &VAR_20,

                                       &VAR_21, VAR_8);

                

                if (VAR_17 == 4)

                    read10in32(&VAR_4, &VAR_20,

                               &VAR_21, VAR_8);

            }

            for (VAR_11 = 0; VAR_11 < 3; VAR_11++)

                ptr[VAR_11] += p->linesize[VAR_11];

        }

        break;

    case 12:

        for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) {

            uint16_t *dst[3] = {(uint16_t*)ptr[0],

                                (uint16_t*)ptr[1],

                                (uint16_t*)ptr[2]};

            for (VAR_10 = 0; VAR_10 < VAR_0->width; VAR_10++) {

                *dst[2] = *((uint16_t*)VAR_4);

                *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12);

                dst[2]++;

                VAR_4 += 2;

                *dst[0] = *((uint16_t*)VAR_4);

                *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12);

                dst[0]++;

                VAR_4 += 2;

                *dst[1] = *((uint16_t*)VAR_4);

                *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12);

                dst[1]++;

                VAR_4 += 2;

                

                if (VAR_17 == 4)

                    VAR_4 += 2;

            }

            for (VAR_11 = 0; VAR_11 < 3; VAR_11++)

                ptr[VAR_11] += p->linesize[VAR_11];

        }

        break;

    case 16:

        VAR_17 *= 2;

    case 8:

        for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) {

            memcpy(ptr[0], VAR_4, VAR_17*VAR_0->width);

            ptr[0] += p->linesize[0];

            VAR_4 += VAR_17*VAR_0->width;

        }

        break;

    }



    *picture   = s->picture;

    *VAR_2 = 1;



    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1,
int *VAR_2,
AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5       = VAR_3->size; DPXContext *const s = VAR_0->priv_data; AVFrame *picture  = VAR_1; AVFrame *const p = &s->picture; uint8_t *ptr[AV_NUM_DATA_POINTERS]; unsigned int VAR_6; int VAR_7, VAR_8; int VAR_9, VAR_10, VAR_11, VAR_12; int VAR_13, VAR_14, VAR_15, VAR_16, VAR_17, VAR_18, VAR_19; unsigned int VAR_20 = 0; int VAR_21 = 0; if (VAR_3->size <= 1634) { av_log(VAR_0, AV_LOG_ERROR, "Packet too small for DPX header\n"); return AVERROR_INVALIDDATA; } VAR_7 = AV_RB32(VAR_4); VAR_4 += 4; if (VAR_7 == AV_RL32("SDPX")) { VAR_8 = 0; } else if (VAR_7 == AV_RB32("SDPX")) { VAR_8 = 1; } else { av_log(VAR_0, AV_LOG_ERROR, "DPX marker not found\n"); return AVERROR_INVALIDDATA; } VAR_6 = read32(&VAR_4, VAR_8); if (VAR_3->size <= VAR_6) { av_log(VAR_0, AV_LOG_ERROR, "Invalid VAR_1 start VAR_6\n"); return AVERROR_INVALIDDATA; } VAR_4 = VAR_3->VAR_1 + 0x304; VAR_13 = read32(&VAR_4, VAR_8); VAR_14 = read32(&VAR_4, VAR_8); if ((VAR_12 = av_image_check_size(VAR_13, VAR_14, 0, VAR_0)) < 0)
return VAR_12; if (VAR_13 != VAR_0->width || VAR_14 != VAR_0->height)
avcodec_set_dimensions(VAR_0, VAR_13, VAR_14); VAR_4 += 20; VAR_16 = VAR_4[0]; VAR_4 += 3; VAR_0->bits_per_raw_sample =
VAR_15 = VAR_4[0]; VAR_4++; VAR_18 = *((uint16_t*)VAR_4); VAR_4 += 824; VAR_0->sample_aspect_ratio.num = read32(&VAR_4, VAR_8); VAR_0->sample_aspect_ratio.den = read32(&VAR_4, VAR_8); if (VAR_0->sample_aspect_ratio.num > 0 && VAR_0->sample_aspect_ratio.den > 0)
av_reduce(&VAR_0->sample_aspect_ratio.num, &VAR_0->sample_aspect_ratio.den,
VAR_0->sample_aspect_ratio.num,  VAR_0->sample_aspect_ratio.den,
0x10000); else
VAR_0->sample_aspect_ratio = (AVRational){ 0, 1 }; switch (VAR_16) { case 51:
VAR_17 = 4; break; case 50:
VAR_17 = 3; break; default:
av_log(VAR_0, AV_LOG_ERROR, "Unsupported VAR_16 %d\n", VAR_16); return AVERROR_INVALIDDATA; } switch (VAR_15) { case 8:
if (VAR_17 == 4) { VAR_0->pix_fmt = AV_PIX_FMT_RGBA; } else { VAR_0->pix_fmt = AV_PIX_FMT_RGB24; } VAR_19 = VAR_0->width * VAR_0->height * VAR_17; break; case 10:
if (!VAR_18) { av_log(VAR_0, AV_LOG_ERROR, "Packing to 32bit required\n"); return -1; } VAR_0->pix_fmt = AV_PIX_FMT_GBRP10; VAR_19 = (VAR_0->width * VAR_0->height * VAR_17 + 2) / 3 * 4; break; case 12:
if (!VAR_18) { av_log(VAR_0, AV_LOG_ERROR, "Packing to 16bit required\n"); return -1; } if (VAR_8) { VAR_0->pix_fmt = AV_PIX_FMT_GBRP12BE; } else { VAR_0->pix_fmt = AV_PIX_FMT_GBRP12LE; } VAR_19 = 2 * VAR_0->width * VAR_0->height * VAR_17; break; case 16:
if (VAR_8) { VAR_0->pix_fmt = VAR_17 == 4 ? AV_PIX_FMT_RGBA64BE : AV_PIX_FMT_RGB48BE; } else { VAR_0->pix_fmt = VAR_17 == 4 ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGB48LE; } VAR_19 = 2 * VAR_0->width * VAR_0->height * VAR_17; break; default:
av_log(VAR_0, AV_LOG_ERROR, "Unsupported color depth : %d\n", VAR_15); return AVERROR_INVALIDDATA; } if (s->picture.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->picture); if ((VAR_12 = ff_get_buffer(VAR_0, p)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return VAR_12; } VAR_4 =  VAR_3->VAR_1 + VAR_6; for (VAR_11=0; VAR_11<AV_NUM_DATA_POINTERS; VAR_11++) ptr[VAR_11] = p->VAR_1[VAR_11]; if (VAR_19 > VAR_3->size) { av_log(VAR_0, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); return AVERROR_INVALIDDATA; } switch (VAR_15) { case 10:
for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) { uint16_t *dst[3] = {(uint16_t*)ptr[0], (uint16_t*)ptr[1],
(uint16_t*)ptr[2]}; for (VAR_10 = 0; VAR_10 < VAR_0->width; VAR_10++) { *dst[2]++ = read10in32(&VAR_4, &VAR_20,
&VAR_21, VAR_8); *dst[0]++ = read10in32(&VAR_4, &VAR_20,
&VAR_21, VAR_8); *dst[1]++ = read10in32(&VAR_4, &VAR_20,
&VAR_21, VAR_8); if (VAR_17 == 4)
read10in32(&VAR_4, &VAR_20,
&VAR_21, VAR_8); } for (VAR_11 = 0; VAR_11 < 3; VAR_11++) ptr[VAR_11] += p->linesize[VAR_11]; } break; case 12:
for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) { uint16_t *dst[3] = {(uint16_t*)ptr[0], (uint16_t*)ptr[1],
(uint16_t*)ptr[2]}; for (VAR_10 = 0; VAR_10 < VAR_0->width; VAR_10++) { *dst[2] = *((uint16_t*)VAR_4); *dst[2] = (*dst[2] >> 4) | (*dst[2] << 12); dst[2]++; VAR_4 += 2; *dst[0] = *((uint16_t*)VAR_4); *dst[0] = (*dst[0] >> 4) | (*dst[0] << 12); dst[0]++; VAR_4 += 2; *dst[1] = *((uint16_t*)VAR_4); *dst[1] = (*dst[1] >> 4) | (*dst[1] << 12); dst[1]++; VAR_4 += 2; if (VAR_17 == 4)
VAR_4 += 2; } for (VAR_11 = 0; VAR_11 < 3; VAR_11++) ptr[VAR_11] += p->linesize[VAR_11]; } break; case 16:
VAR_17 *= 2; case 8:
for (VAR_9 = 0; VAR_9 < VAR_0->height; VAR_9++) { memcpy(ptr[0], VAR_4, VAR_17*VAR_0->width); ptr[0] += p->linesize[0]; VAR_4 += VAR_17*VAR_0->width; } break; } *picture   = s->picture; *VAR_2 = 1; return VAR_5; }