~ppsspp/ppsspp/ffmpeg-upstream

« back to all changes in this revision

Viewing changes to libavcodec/pngdec.c

  • Committer: Sérgio Benjamim
  • Date: 2015-07-20 03:55:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150720035505-i1jj1zcjcnd0mc7w
Updated to 2.7.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
542
542
        return AVERROR_INVALIDDATA;
543
543
    }
544
544
 
545
 
    s->width  = bytestream2_get_be32(&s->gb);
546
 
    s->height = bytestream2_get_be32(&s->gb);
 
545
    if (s->state & PNG_IHDR) {
 
546
        av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
 
547
        return AVERROR_INVALIDDATA;
 
548
    }
 
549
 
 
550
    s->width  = s->cur_w = bytestream2_get_be32(&s->gb);
 
551
    s->height = s->cur_h = bytestream2_get_be32(&s->gb);
547
552
    if (av_image_check_size(s->width, s->height, 0, avctx)) {
548
 
        s->width = s->height = 0;
 
553
        s->cur_w = s->cur_h = s->width = s->height = 0;
549
554
        av_log(avctx, AV_LOG_ERROR, "Invalid image size\n");
550
555
        return AVERROR_INVALIDDATA;
551
556
    }
552
 
    if (s->cur_w == 0 && s->cur_h == 0) {
553
 
        // Only set cur_w/h if update_thread_context() has not set it
554
 
        s->cur_w = s->width;
555
 
        s->cur_h = s->height;
556
 
    }
557
557
    s->bit_depth        = bytestream2_get_byte(&s->gb);
558
558
    s->color_type       = bytestream2_get_byte(&s->gb);
559
559
    s->compression_type = bytestream2_get_byte(&s->gb);
815
815
                             uint32_t length)
816
816
{
817
817
    uint32_t sequence_number;
 
818
    int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
818
819
 
819
820
    if (length != 26)
820
821
        return AVERROR_INVALIDDATA;
821
822
 
 
823
    if (!(s->state & PNG_IHDR)) {
 
824
        av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");
 
825
        return AVERROR_INVALIDDATA;
 
826
    }
 
827
 
822
828
    s->last_w = s->cur_w;
823
829
    s->last_h = s->cur_h;
824
830
    s->last_x_offset = s->x_offset;
826
832
    s->last_dispose_op = s->dispose_op;
827
833
 
828
834
    sequence_number = bytestream2_get_be32(&s->gb);
829
 
    s->cur_w        = bytestream2_get_be32(&s->gb);
830
 
    s->cur_h        = bytestream2_get_be32(&s->gb);
831
 
    s->x_offset     = bytestream2_get_be32(&s->gb);
832
 
    s->y_offset     = bytestream2_get_be32(&s->gb);
 
835
    cur_w           = bytestream2_get_be32(&s->gb);
 
836
    cur_h           = bytestream2_get_be32(&s->gb);
 
837
    x_offset        = bytestream2_get_be32(&s->gb);
 
838
    y_offset        = bytestream2_get_be32(&s->gb);
833
839
    bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */
834
 
    s->dispose_op   = bytestream2_get_byte(&s->gb);
835
 
    s->blend_op     = bytestream2_get_byte(&s->gb);
 
840
    dispose_op      = bytestream2_get_byte(&s->gb);
 
841
    blend_op        = bytestream2_get_byte(&s->gb);
836
842
    bytestream2_skip(&s->gb, 4); /* crc */
837
843
 
838
844
    if (sequence_number == 0 &&
839
 
        (s->cur_w != s->width ||
840
 
         s->cur_h != s->height ||
841
 
         s->x_offset != 0 ||
842
 
         s->y_offset != 0) ||
843
 
        s->cur_w <= 0 || s->cur_h <= 0 ||
844
 
        s->x_offset < 0 || s->y_offset < 0 ||
845
 
        s->cur_w > s->width - s->x_offset|| s->cur_h > s->height - s->y_offset)
 
845
        (cur_w != s->width ||
 
846
         cur_h != s->height ||
 
847
         x_offset != 0 ||
 
848
         y_offset != 0) ||
 
849
        cur_w <= 0 || cur_h <= 0 ||
 
850
        x_offset < 0 || y_offset < 0 ||
 
851
        cur_w > s->width - x_offset|| cur_h > s->height - y_offset)
846
852
            return AVERROR_INVALIDDATA;
847
853
 
848
854
    if (sequence_number == 0 && s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
863
869
        s->dispose_op = APNG_BLEND_OP_SOURCE;
864
870
    }
865
871
 
 
872
    s->cur_w      = cur_w;
 
873
    s->cur_h      = cur_h;
 
874
    s->x_offset   = x_offset;
 
875
    s->y_offset   = y_offset;
 
876
    s->dispose_op = dispose_op;
 
877
    s->blend_op   = blend_op;
 
878
 
866
879
    return 0;
867
880
}
868
881
 
1259
1272
        (ret = ff_thread_ref_frame(&pdst->picture, &psrc->picture)) < 0)
1260
1273
        return ret;
1261
1274
    if (CONFIG_APNG_DECODER && dst->codec_id == AV_CODEC_ID_APNG) {
 
1275
        pdst->width             = psrc->width;
 
1276
        pdst->height            = psrc->height;
 
1277
        pdst->bit_depth         = psrc->bit_depth;
 
1278
        pdst->color_type        = psrc->color_type;
 
1279
        pdst->compression_type  = psrc->compression_type;
 
1280
        pdst->interlace_type    = psrc->interlace_type;
 
1281
        pdst->filter_type       = psrc->filter_type;
1262
1282
        pdst->cur_w = psrc->cur_w;
1263
1283
        pdst->cur_h = psrc->cur_h;
1264
1284
        pdst->x_offset = psrc->x_offset;
1265
1285
        pdst->y_offset = psrc->y_offset;
 
1286
 
1266
1287
        pdst->dispose_op = psrc->dispose_op;
1267
1288
 
 
1289
        memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette));
 
1290
 
 
1291
        pdst->state |= psrc->state & (PNG_IHDR | PNG_PLTE);
 
1292
 
1268
1293
        ff_thread_release_buffer(dst, &pdst->last_picture);
1269
1294
        if (psrc->last_picture.f->data[0])
1270
1295
            return ff_thread_ref_frame(&pdst->last_picture, &psrc->last_picture);