static int pxr24_uncompress(EXRContext *s, const uint8_t *src,

                            int compressed_size, int uncompressed_size,

                            EXRThreadData *td)

{

    unsigned long dest_len, expected_len = 0;

    const uint8_t *in = td->tmp;

    uint8_t *out;

    int c, i, j;



    for (i = 0; i < s->nb_channels; i++) {

        if (s->channels[i].pixel_type == EXR_FLOAT) {

            expected_len += (td->xsize * td->ysize * 3);/* PRX 24 store float in 24 bit instead of 32 */

        } else if (s->channels[i].pixel_type == EXR_HALF) {

            expected_len += (td->xsize * td->ysize * 2);

        } else {//UINT 32

            expected_len += (td->xsize * td->ysize * 4);

        }

    }



    dest_len = expected_len;



    if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK) {

        return AVERROR_INVALIDDATA;

    } else if (dest_len != expected_len) {

        return AVERROR_INVALIDDATA;

    }



    out = td->uncompressed_data;

    for (i = 0; i < td->ysize; i++)

        for (c = 0; c < s->nb_channels; c++) {

            EXRChannel *channel = &s->channels[c];

            const uint8_t *ptr[4];

            uint32_t pixel = 0;



            switch (channel->pixel_type) {

            case EXR_FLOAT:

                ptr[0] = in;

                ptr[1] = ptr[0] + td->xsize;

                ptr[2] = ptr[1] + td->xsize;

                in     = ptr[2] + td->xsize;



                for (j = 0; j < td->xsize; ++j) {

                    uint32_t diff = (*(ptr[0]++) << 24) |

                                    (*(ptr[1]++) << 16) |

                                    (*(ptr[2]++) << 8);

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            case EXR_HALF:

                ptr[0] = in;

                ptr[1] = ptr[0] + td->xsize;

                in     = ptr[1] + td->xsize;

                for (j = 0; j < td->xsize; j++) {

                    uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++);



                    pixel += diff;

                    bytestream_put_le16(&out, pixel);

                }

                break;

            case EXR_UINT:

                ptr[0] = in;

                ptr[1] = ptr[0] + s->xdelta;

                ptr[2] = ptr[1] + s->xdelta;

                ptr[3] = ptr[2] + s->xdelta;

                in     = ptr[3] + s->xdelta;



                for (j = 0; j < s->xdelta; ++j) {

                    uint32_t diff = (*(ptr[0]++) << 24) |

                    (*(ptr[1]++) << 16) |

                    (*(ptr[2]++) << 8 ) |

                    (*(ptr[3]++));

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            default:

                return AVERROR_INVALIDDATA;

            }

        }



    return 0;

}

static int pxr24_uncompress(EXRContext *s, const uint8_t *src,

                            int compressed_size, int uncompressed_size,

                            EXRThreadData *td)

{

    unsigned long dest_len, expected_len = 0;

    const uint8_t *in = td->tmp;

    uint8_t *out;

    int c, i, j;



    for (i = 0; i < s->nb_channels; i++) {

        if (s->channels[i].pixel_type == EXR_FLOAT) {

            expected_len += (td->xsize * td->ysize * 3);

        } else if (s->channels[i].pixel_type == EXR_HALF) {

            expected_len += (td->xsize * td->ysize * 2);

        } else {

            expected_len += (td->xsize * td->ysize * 4);

        }

    }



    dest_len = expected_len;



    if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK) {

        return AVERROR_INVALIDDATA;

    } else if (dest_len != expected_len) {

        return AVERROR_INVALIDDATA;

    }



    out = td->uncompressed_data;

    for (i = 0; i < td->ysize; i++)

        for (c = 0; c < s->nb_channels; c++) {

            EXRChannel *channel = &s->channels[c];

            const uint8_t *ptr[4];

            uint32_t pixel = 0;



            switch (channel->pixel_type) {

            case EXR_FLOAT:

                ptr[0] = in;

                ptr[1] = ptr[0] + td->xsize;

                ptr[2] = ptr[1] + td->xsize;

                in     = ptr[2] + td->xsize;



                for (j = 0; j < td->xsize; ++j) {

                    uint32_t diff = (*(ptr[0]++) << 24) |

                                    (*(ptr[1]++) << 16) |

                                    (*(ptr[2]++) << 8);

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            case EXR_HALF:

                ptr[0] = in;

                ptr[1] = ptr[0] + td->xsize;

                in     = ptr[1] + td->xsize;

                for (j = 0; j < td->xsize; j++) {

                    uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++);



                    pixel += diff;

                    bytestream_put_le16(&out, pixel);

                }

                break;

            case EXR_UINT:

                ptr[0] = in;

                ptr[1] = ptr[0] + s->xdelta;

                ptr[2] = ptr[1] + s->xdelta;

                ptr[3] = ptr[2] + s->xdelta;

                in     = ptr[3] + s->xdelta;



                for (j = 0; j < s->xdelta; ++j) {

                    uint32_t diff = (*(ptr[0]++) << 24) |

                    (*(ptr[1]++) << 16) |

                    (*(ptr[2]++) << 8 ) |

                    (*(ptr[3]++));

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            default:

                return AVERROR_INVALIDDATA;

            }

        }



    return 0;

}

                    uint32_t diff = (*(ptr[0]++) << 24) |
static int FUNC_0(EXRContext *VAR_0, const uint8_t *VAR_1,

                            int VAR_2, int VAR_3,

                            EXRThreadData *VAR_4)

{

    unsigned long VAR_5, VAR_6 = 0;

    const uint8_t *VAR_7 = VAR_4->tmp;

    uint8_t *out;

    int VAR_8, VAR_9, VAR_10;



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

        if (VAR_0->channels[VAR_9].pixel_type == EXR_FLOAT) {

            VAR_6 += (VAR_4->xsize * VAR_4->ysize * 3);

        } else if (VAR_0->channels[VAR_9].pixel_type == EXR_HALF) {

            VAR_6 += (VAR_4->xsize * VAR_4->ysize * 2);

        } else {

            VAR_6 += (VAR_4->xsize * VAR_4->ysize * 4);

        }

    }



    VAR_5 = VAR_6;



    if (uncompress(VAR_4->tmp, &VAR_5, VAR_1, VAR_2) != Z_OK) {

        return AVERROR_INVALIDDATA;

    } else if (VAR_5 != VAR_6) {

        return AVERROR_INVALIDDATA;

    }



    out = VAR_4->uncompressed_data;

    for (VAR_9 = 0; VAR_9 < VAR_4->ysize; VAR_9++)

        for (VAR_8 = 0; VAR_8 < VAR_0->nb_channels; VAR_8++) {

            EXRChannel *channel = &VAR_0->channels[VAR_8];

            const uint8_t *ptr[4];

            uint32_t pixel = 0;



            switch (channel->pixel_type) {

            case EXR_FLOAT:

                ptr[0] = VAR_7;

                ptr[1] = ptr[0] + VAR_4->xsize;

                ptr[2] = ptr[1] + VAR_4->xsize;

                VAR_7     = ptr[2] + VAR_4->xsize;



                for (VAR_10 = 0; VAR_10 < VAR_4->xsize; ++VAR_10) {

                    uint32_t diff = (*(ptr[0]++) << 24) |

                                    (*(ptr[1]++) << 16) |

                                    (*(ptr[2]++) << 8);

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            case EXR_HALF:

                ptr[0] = VAR_7;

                ptr[1] = ptr[0] + VAR_4->xsize;

                VAR_7     = ptr[1] + VAR_4->xsize;

                for (VAR_10 = 0; VAR_10 < VAR_4->xsize; VAR_10++) {

                    uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++);



                    pixel += diff;

                    bytestream_put_le16(&out, pixel);

                }

                break;

            case EXR_UINT:

                ptr[0] = VAR_7;

                ptr[1] = ptr[0] + VAR_0->xdelta;

                ptr[2] = ptr[1] + VAR_0->xdelta;

                ptr[3] = ptr[2] + VAR_0->xdelta;

                VAR_7     = ptr[3] + VAR_0->xdelta;



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

                    uint32_t diff = (*(ptr[0]++) << 24) |

                    (*(ptr[1]++) << 16) |

                    (*(ptr[2]++) << 8 ) |

                    (*(ptr[3]++));

                    pixel += diff;

                    bytestream_put_le32(&out, pixel);

                }

                break;

            default:

                return AVERROR_INVALIDDATA;

            }

        }



    return 0;

}

static int FUNC_0(EXRContext *VAR_0, const uint8_t *VAR_1,
int VAR_2, int VAR_3,
EXRThreadData *VAR_4)
{ unsigned long VAR_5, VAR_6 = 0; const uint8_t *VAR_7 = VAR_4->tmp; uint8_t *out; int VAR_8, VAR_9, VAR_10; for (VAR_9 = 0; VAR_9 < VAR_0->nb_channels; VAR_9++) { if (VAR_0->channels[VAR_9].pixel_type == EXR_FLOAT) { VAR_6 += (VAR_4->xsize * VAR_4->ysize * 3); } else if (VAR_0->channels[VAR_9].pixel_type == EXR_HALF) { VAR_6 += (VAR_4->xsize * VAR_4->ysize * 2); } else { VAR_6 += (VAR_4->xsize * VAR_4->ysize * 4); } } VAR_5 = VAR_6; if (uncompress(VAR_4->tmp, &VAR_5, VAR_1, VAR_2) != Z_OK) { return AVERROR_INVALIDDATA; } else if (VAR_5 != VAR_6) { return AVERROR_INVALIDDATA; } out = VAR_4->uncompressed_data; for (VAR_9 = 0; VAR_9 < VAR_4->ysize; VAR_9++) for (VAR_8 = 0; VAR_8 < VAR_0->nb_channels; VAR_8++) { EXRChannel *channel = &VAR_0->channels[VAR_8]; const uint8_t *ptr[4]; uint32_t pixel = 0; switch (channel->pixel_type) { case EXR_FLOAT:
ptr[0] = VAR_7; ptr[1] = ptr[0] + VAR_4->xsize; ptr[2] = ptr[1] + VAR_4->xsize; VAR_7     = ptr[2] + VAR_4->xsize; for (VAR_10 = 0; VAR_10 < VAR_4->xsize; ++VAR_10) { uint32_t diff = (*(ptr[0]++) << 24) |
(*(ptr[1]++) << 16) |
(*(ptr[2]++) << 8); pixel += diff; bytestream_put_le32(&out, pixel); } break; case EXR_HALF:
ptr[0] = VAR_7; ptr[1] = ptr[0] + VAR_4->xsize; VAR_7     = ptr[1] + VAR_4->xsize; for (VAR_10 = 0; VAR_10 < VAR_4->xsize; VAR_10++) { uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++); pixel += diff; bytestream_put_le16(&out, pixel); } break; case EXR_UINT:
ptr[0] = VAR_7; ptr[1] = ptr[0] + VAR_0->xdelta; ptr[2] = ptr[1] + VAR_0->xdelta; ptr[3] = ptr[2] + VAR_0->xdelta; VAR_7     = ptr[3] + VAR_0->xdelta; for (VAR_10 = 0; VAR_10 < VAR_0->xdelta; ++VAR_10) { uint32_t diff = (*(ptr[0]++) << 24) |
(*(ptr[1]++) << 16) |
(*(ptr[2]++) << 8 ) |
(*(ptr[3]++)); pixel += diff; bytestream_put_le32(&out, pixel); } break; default:
return AVERROR_INVALIDDATA; } } return 0; }