static int decode_header(PSDContext * s)

{

    int signature, version, color_mode, compression;

    int64_t len_section;

    int ret = 0;



    if (bytestream2_get_bytes_left(&s->gb) < 30) {/* File header section + color map data section length */

        av_log(s->avctx, AV_LOG_ERROR, "Header too short to parse.\n");

        return AVERROR_INVALIDDATA;

    }



    signature = bytestream2_get_le32(&s->gb);

    if (signature != MKTAG('8','B','P','S')) {

        av_log(s->avctx, AV_LOG_ERROR, "Wrong signature %d.\n", signature);

        return AVERROR_INVALIDDATA;

    }



    version = bytestream2_get_be16(&s->gb);

    if (version != 1) {

        av_log(s->avctx, AV_LOG_ERROR, "Wrong version %d.\n", version);

        return AVERROR_INVALIDDATA;

    }



    bytestream2_skip(&s->gb, 6);/* reserved */



    s->channel_count = bytestream2_get_be16(&s->gb);

    if ((s->channel_count < 1) || (s->channel_count > 56)) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid channel count %d.\n", s->channel_count);

        return AVERROR_INVALIDDATA;

    }



    s->height = bytestream2_get_be32(&s->gb);



    if ((s->height > 30000) && (s->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(s->avctx, AV_LOG_ERROR,

               "Height > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    s->width = bytestream2_get_be32(&s->gb);

    if ((s->width > 30000) && (s->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(s->avctx, AV_LOG_ERROR,

               "Width > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    if ((ret = ff_set_dimensions(s->avctx, s->width, s->height)) < 0)

        return ret;



    s->channel_depth = bytestream2_get_be16(&s->gb);



    color_mode = bytestream2_get_be16(&s->gb);

    switch (color_mode) {

    case 0:

        s->color_mode = PSD_BITMAP;

        break;

    case 1:

        s->color_mode = PSD_GRAYSCALE;

        break;

    case 2:

        s->color_mode = PSD_INDEXED;

        break;

    case 3:

        s->color_mode = PSD_RGB;

        break;

    case 4:

        s->color_mode = PSD_CMYK;

        break;

    case 7:

        s->color_mode = PSD_MULTICHANNEL;

        break;

    case 8:

        s->color_mode = PSD_DUOTONE;

        break;

    case 9:

        s->color_mode = PSD_LAB;

        break;

    default:

        av_log(s->avctx, AV_LOG_ERROR, "Unknown color mode %d.\n", color_mode);

        return AVERROR_INVALIDDATA;

    }



    /* color map data */

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for color map data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < (len_section + 4)) { /* section and len next section */

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    /* image ressources */

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for image ressources section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < (len_section + 4)) { /* section and len next section */

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    /* layers and masks */

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for layers and masks data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < len_section) {

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    /* image section */

    if (bytestream2_get_bytes_left(&s->gb) < 2) {

        av_log(s->avctx, AV_LOG_ERROR, "File without image data section.\n");

        return AVERROR_INVALIDDATA;

    }



    s->compression = bytestream2_get_be16(&s->gb);

    switch (s->compression) {

    case 0:

    case 1:

        break;

    case 2:

        avpriv_request_sample(s->avctx, "ZIP without predictor compression");

        return AVERROR_PATCHWELCOME;

        break;

    case 3:

        avpriv_request_sample(s->avctx, "ZIP with predictor compression");

        return AVERROR_PATCHWELCOME;

        break;

    default:

        av_log(s->avctx, AV_LOG_ERROR, "Unknown compression %d.\n", compression);

        return AVERROR_INVALIDDATA;

    }



    return ret;

}

static int decode_header(PSDContext * s)

{

    int signature, version, color_mode, compression;

    int64_t len_section;

    int ret = 0;



    if (bytestream2_get_bytes_left(&s->gb) < 30) {

        av_log(s->avctx, AV_LOG_ERROR, "Header too short to parse.\n");

        return AVERROR_INVALIDDATA;

    }



    signature = bytestream2_get_le32(&s->gb);

    if (signature != MKTAG('8','B','P','S')) {

        av_log(s->avctx, AV_LOG_ERROR, "Wrong signature %d.\n", signature);

        return AVERROR_INVALIDDATA;

    }



    version = bytestream2_get_be16(&s->gb);

    if (version != 1) {

        av_log(s->avctx, AV_LOG_ERROR, "Wrong version %d.\n", version);

        return AVERROR_INVALIDDATA;

    }



    bytestream2_skip(&s->gb, 6);



    s->channel_count = bytestream2_get_be16(&s->gb);

    if ((s->channel_count < 1) || (s->channel_count > 56)) {

        av_log(s->avctx, AV_LOG_ERROR, "Invalid channel count %d.\n", s->channel_count);

        return AVERROR_INVALIDDATA;

    }



    s->height = bytestream2_get_be32(&s->gb);



    if ((s->height > 30000) && (s->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(s->avctx, AV_LOG_ERROR,

               "Height > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    s->width = bytestream2_get_be32(&s->gb);

    if ((s->width > 30000) && (s->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(s->avctx, AV_LOG_ERROR,

               "Width > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    if ((ret = ff_set_dimensions(s->avctx, s->width, s->height)) < 0)

        return ret;



    s->channel_depth = bytestream2_get_be16(&s->gb);



    color_mode = bytestream2_get_be16(&s->gb);

    switch (color_mode) {

    case 0:

        s->color_mode = PSD_BITMAP;

        break;

    case 1:

        s->color_mode = PSD_GRAYSCALE;

        break;

    case 2:

        s->color_mode = PSD_INDEXED;

        break;

    case 3:

        s->color_mode = PSD_RGB;

        break;

    case 4:

        s->color_mode = PSD_CMYK;

        break;

    case 7:

        s->color_mode = PSD_MULTICHANNEL;

        break;

    case 8:

        s->color_mode = PSD_DUOTONE;

        break;

    case 9:

        s->color_mode = PSD_LAB;

        break;

    default:

        av_log(s->avctx, AV_LOG_ERROR, "Unknown color mode %d.\n", color_mode);

        return AVERROR_INVALIDDATA;

    }



    

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for color map data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < (len_section + 4)) { 

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for image ressources section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < (len_section + 4)) { 

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    

    len_section = bytestream2_get_be32(&s->gb);

    if (len_section < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "Negative size for layers and masks data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&s->gb) < len_section) {

        av_log(s->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&s->gb, len_section);



    

    if (bytestream2_get_bytes_left(&s->gb) < 2) {

        av_log(s->avctx, AV_LOG_ERROR, "File without image data section.\n");

        return AVERROR_INVALIDDATA;

    }



    s->compression = bytestream2_get_be16(&s->gb);

    switch (s->compression) {

    case 0:

    case 1:

        break;

    case 2:

        avpriv_request_sample(s->avctx, "ZIP without predictor compression");

        return AVERROR_PATCHWELCOME;

        break;

    case 3:

        avpriv_request_sample(s->avctx, "ZIP with predictor compression");

        return AVERROR_PATCHWELCOME;

        break;

    default:

        av_log(s->avctx, AV_LOG_ERROR, "Unknown compression %d.\n", compression);

        return AVERROR_INVALIDDATA;

    }



    return ret;

}

    int signature, version, color_mode, compression;         av_log(s->avctx, AV_LOG_ERROR, "Unknown compression %d.\n", compression);
static int FUNC_0(PSDContext * VAR_0)

{

    int VAR_1, VAR_2, VAR_3, VAR_4;

    int64_t len_section;

    int VAR_5 = 0;



    if (bytestream2_get_bytes_left(&VAR_0->gb) < 30) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Header too short to parse.\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_1 = bytestream2_get_le32(&VAR_0->gb);

    if (VAR_1 != MKTAG('8','B','P','S')) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Wrong VAR_1 %d.\n", VAR_1);

        return AVERROR_INVALIDDATA;

    }



    VAR_2 = bytestream2_get_be16(&VAR_0->gb);

    if (VAR_2 != 1) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Wrong VAR_2 %d.\n", VAR_2);

        return AVERROR_INVALIDDATA;

    }



    bytestream2_skip(&VAR_0->gb, 6);



    VAR_0->channel_count = bytestream2_get_be16(&VAR_0->gb);

    if ((VAR_0->channel_count < 1) || (VAR_0->channel_count > 56)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid channel count %d.\n", VAR_0->channel_count);

        return AVERROR_INVALIDDATA;

    }



    VAR_0->height = bytestream2_get_be32(&VAR_0->gb);



    if ((VAR_0->height > 30000) && (VAR_0->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "Height > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    VAR_0->width = bytestream2_get_be32(&VAR_0->gb);

    if ((VAR_0->width > 30000) && (VAR_0->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR,

               "Width > 30000 is experimental, add "

               "'-strict %d' if you want to try to decode the picture.\n",

               FF_COMPLIANCE_EXPERIMENTAL);

        return AVERROR_EXPERIMENTAL;

    }



    if ((VAR_5 = ff_set_dimensions(VAR_0->avctx, VAR_0->width, VAR_0->height)) < 0)

        return VAR_5;



    VAR_0->channel_depth = bytestream2_get_be16(&VAR_0->gb);



    VAR_3 = bytestream2_get_be16(&VAR_0->gb);

    switch (VAR_3) {

    case 0:

        VAR_0->VAR_3 = PSD_BITMAP;

        break;

    case 1:

        VAR_0->VAR_3 = PSD_GRAYSCALE;

        break;

    case 2:

        VAR_0->VAR_3 = PSD_INDEXED;

        break;

    case 3:

        VAR_0->VAR_3 = PSD_RGB;

        break;

    case 4:

        VAR_0->VAR_3 = PSD_CMYK;

        break;

    case 7:

        VAR_0->VAR_3 = PSD_MULTICHANNEL;

        break;

    case 8:

        VAR_0->VAR_3 = PSD_DUOTONE;

        break;

    case 9:

        VAR_0->VAR_3 = PSD_LAB;

        break;

    default:

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Unknown color mode %d.\n", VAR_3);

        return AVERROR_INVALIDDATA;

    }



    

    len_section = bytestream2_get_be32(&VAR_0->gb);

    if (len_section < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for color map data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&VAR_0->gb) < (len_section + 4)) { 

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&VAR_0->gb, len_section);



    

    len_section = bytestream2_get_be32(&VAR_0->gb);

    if (len_section < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for image ressources section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&VAR_0->gb) < (len_section + 4)) { 

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&VAR_0->gb, len_section);



    

    len_section = bytestream2_get_be32(&VAR_0->gb);

    if (len_section < 0) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for layers and masks data section.\n");

        return AVERROR_INVALIDDATA;

    }



    if (bytestream2_get_bytes_left(&VAR_0->gb) < len_section) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n");

        return AVERROR_INVALIDDATA;

    }

    bytestream2_skip(&VAR_0->gb, len_section);



    

    if (bytestream2_get_bytes_left(&VAR_0->gb) < 2) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "File without image data section.\n");

        return AVERROR_INVALIDDATA;

    }



    VAR_0->VAR_4 = bytestream2_get_be16(&VAR_0->gb);

    switch (VAR_0->VAR_4) {

    case 0:

    case 1:

        break;

    case 2:

        avpriv_request_sample(VAR_0->avctx, "ZIP without predictor VAR_4");

        return AVERROR_PATCHWELCOME;

        break;

    case 3:

        avpriv_request_sample(VAR_0->avctx, "ZIP with predictor VAR_4");

        return AVERROR_PATCHWELCOME;

        break;

    default:

        av_log(VAR_0->avctx, AV_LOG_ERROR, "Unknown VAR_4 %d.\n", VAR_4);

        return AVERROR_INVALIDDATA;

    }



    return VAR_5;

}

static int FUNC_0(PSDContext * VAR_0)
{ int VAR_1, VAR_2, VAR_3, VAR_4; int64_t len_section; int VAR_5 = 0; if (bytestream2_get_bytes_left(&VAR_0->gb) < 30) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Header too short to parse.\n"); return AVERROR_INVALIDDATA; } VAR_1 = bytestream2_get_le32(&VAR_0->gb); if (VAR_1 != MKTAG('8','B','P','S')) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Wrong VAR_1 %d.\n", VAR_1); return AVERROR_INVALIDDATA; } VAR_2 = bytestream2_get_be16(&VAR_0->gb); if (VAR_2 != 1) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Wrong VAR_2 %d.\n", VAR_2); return AVERROR_INVALIDDATA; } bytestream2_skip(&VAR_0->gb, 6); VAR_0->channel_count = bytestream2_get_be16(&VAR_0->gb); if ((VAR_0->channel_count < 1) || (VAR_0->channel_count > 56)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Invalid channel count %d.\n", VAR_0->channel_count); return AVERROR_INVALIDDATA; } VAR_0->height = bytestream2_get_be32(&VAR_0->gb); if ((VAR_0->height > 30000) && (VAR_0->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Height > 30000 is experimental, add "
"'-strict %d' if you want to try to decode the picture.\n",
FF_COMPLIANCE_EXPERIMENTAL); return AVERROR_EXPERIMENTAL; } VAR_0->width = bytestream2_get_be32(&VAR_0->gb); if ((VAR_0->width > 30000) && (VAR_0->avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL)) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Width > 30000 is experimental, add "
"'-strict %d' if you want to try to decode the picture.\n",
FF_COMPLIANCE_EXPERIMENTAL); return AVERROR_EXPERIMENTAL; } if ((VAR_5 = ff_set_dimensions(VAR_0->avctx, VAR_0->width, VAR_0->height)) < 0)
return VAR_5; VAR_0->channel_depth = bytestream2_get_be16(&VAR_0->gb); VAR_3 = bytestream2_get_be16(&VAR_0->gb); switch (VAR_3) { case 0:
VAR_0->VAR_3 = PSD_BITMAP; break; case 1:
VAR_0->VAR_3 = PSD_GRAYSCALE; break; case 2:
VAR_0->VAR_3 = PSD_INDEXED; break; case 3:
VAR_0->VAR_3 = PSD_RGB; break; case 4:
VAR_0->VAR_3 = PSD_CMYK; break; case 7:
VAR_0->VAR_3 = PSD_MULTICHANNEL; break; case 8:
VAR_0->VAR_3 = PSD_DUOTONE; break; case 9:
VAR_0->VAR_3 = PSD_LAB; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "Unknown color mode %d.\n", VAR_3); return AVERROR_INVALIDDATA; } len_section = bytestream2_get_be32(&VAR_0->gb); if (len_section < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for color map data section.\n"); return AVERROR_INVALIDDATA; } if (bytestream2_get_bytes_left(&VAR_0->gb) < (len_section + 4)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(&VAR_0->gb, len_section); len_section = bytestream2_get_be32(&VAR_0->gb); if (len_section < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for image ressources section.\n"); return AVERROR_INVALIDDATA; } if (bytestream2_get_bytes_left(&VAR_0->gb) < (len_section + 4)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(&VAR_0->gb, len_section); len_section = bytestream2_get_be32(&VAR_0->gb); if (len_section < 0) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Negative size for layers and masks data section.\n"); return AVERROR_INVALIDDATA; } if (bytestream2_get_bytes_left(&VAR_0->gb) < len_section) { av_log(VAR_0->avctx, AV_LOG_ERROR, "Incomplete file.\n"); return AVERROR_INVALIDDATA; } bytestream2_skip(&VAR_0->gb, len_section); if (bytestream2_get_bytes_left(&VAR_0->gb) < 2) { av_log(VAR_0->avctx, AV_LOG_ERROR, "File without image data section.\n"); return AVERROR_INVALIDDATA; } VAR_0->VAR_4 = bytestream2_get_be16(&VAR_0->gb); switch (VAR_0->VAR_4) { case 0:
case 1:
break; case 2:
avpriv_request_sample(VAR_0->avctx, "ZIP without predictor VAR_4"); return AVERROR_PATCHWELCOME; break; case 3:
avpriv_request_sample(VAR_0->avctx, "ZIP with predictor VAR_4"); return AVERROR_PATCHWELCOME; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR, "Unknown VAR_4 %d.\n", VAR_4); return AVERROR_INVALIDDATA; } return VAR_5; }