~ppsspp/ppsspp/ffmpeg

« back to all changes in this revision

Viewing changes to libavcodec/png_parser.c

  • Committer: Henrik Rydgård
  • Date: 2014-01-03 10:44:32 UTC
  • Revision ID: git-v1:87c6c126784b1718bfa448ecf2e6a9fef781eb4e
Update our ffmpeg snapshot to a clone of the official repository.

This is because Maxim's at3plus support has been officially merged!

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "parser.h"
28
28
#include "png.h"
29
29
 
30
 
typedef struct PNGParseContext
31
 
{
 
30
typedef struct PNGParseContext {
32
31
    ParseContext pc;
33
 
    uint32_t index;
34
 
    uint32_t chunk_length;
35
 
    uint32_t remaining_size;
 
32
    uint32_t chunk_pos;           ///< position inside current chunk
 
33
    uint32_t chunk_length;        ///< length of the current chunk
 
34
    uint32_t remaining_size;      ///< remaining size of the current chunk
36
35
} PNGParseContext;
37
36
 
38
37
static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx,
60
59
            }
61
60
        }
62
61
        ppc->pc.state64 = state64;
63
 
    } else
64
 
        if (ppc->remaining_size) {
65
 
            i = FFMIN(ppc->remaining_size, buf_size);
66
 
            ppc->remaining_size -= i;
67
 
            if (ppc->remaining_size)
68
 
                goto flush;
69
 
            if (ppc->index == -1) {
70
 
                next = i;
71
 
                goto flush;
72
 
            }
 
62
    } else if (ppc->remaining_size) {
 
63
        i = FFMIN(ppc->remaining_size, buf_size);
 
64
        ppc->remaining_size -= i;
 
65
        if (ppc->remaining_size)
 
66
            goto flush;
 
67
        if (ppc->chunk_pos == -1) {
 
68
            next = i;
 
69
            goto flush;
73
70
        }
 
71
    }
74
72
 
75
 
    for (;ppc->pc.frame_start_found && i < buf_size; i++) {
76
 
        ppc->pc.state = (ppc->pc.state<<8) | buf[i];
77
 
        if (ppc->index == 3) {
 
73
    for (; ppc->pc.frame_start_found && i < buf_size; i++) {
 
74
        ppc->pc.state = (ppc->pc.state << 8) | buf[i];
 
75
        if (ppc->chunk_pos == 3) {
78
76
            ppc->chunk_length = ppc->pc.state;
79
77
            if (ppc->chunk_length > 0x7fffffff) {
80
 
                ppc->index = ppc->pc.frame_start_found = 0;
 
78
                ppc->chunk_pos = ppc->pc.frame_start_found = 0;
81
79
                goto flush;
82
80
            }
83
81
            ppc->chunk_length += 4;
84
 
        } else if (ppc->index == 7) {
 
82
        } else if (ppc->chunk_pos == 7) {
85
83
            if (ppc->chunk_length >= buf_size - i)
86
 
                    ppc->remaining_size = ppc->chunk_length - buf_size + i + 1;
 
84
                ppc->remaining_size = ppc->chunk_length - buf_size + i + 1;
87
85
            if (ppc->pc.state == MKBETAG('I', 'E', 'N', 'D')) {
88
86
                if (ppc->remaining_size)
89
 
                    ppc->index = -1;
 
87
                    ppc->chunk_pos = -1;
90
88
                else
91
89
                    next = ppc->chunk_length + i + 1;
92
90
                break;
93
91
            } else {
94
 
                ppc->index = 0;
 
92
                ppc->chunk_pos = 0;
95
93
                if (ppc->remaining_size)
96
94
                    break;
97
95
                else
99
97
                continue;
100
98
            }
101
99
        }
102
 
        ppc->index++;
 
100
        ppc->chunk_pos++;
103
101
    }
 
102
 
104
103
flush:
105
104
    if (ff_combine_frame(&ppc->pc, next, &buf, &buf_size) < 0)
106
105
        return buf_size;
107
106
 
108
 
    ppc->index = ppc->pc.frame_start_found = 0;
 
107
    ppc->chunk_pos = ppc->pc.frame_start_found = 0;
109
108
 
110
109
    *poutbuf      = buf;
111
110
    *poutbuf_size = buf_size;