Revision dae0d1e2

View differences:

libavcodec/pcx.c
43 43
 * @return advanced src pointer
44 44
 */
45 45
static const uint8_t *pcx_rle_decode(const uint8_t *src, uint8_t *dst,
46
                            unsigned int bytes_per_scanline) {
46
                            unsigned int bytes_per_scanline, int compressed) {
47 47
    unsigned int i = 0;
48 48
    unsigned char run, value;
49 49

  
50
    while (i<bytes_per_scanline) {
51
        run = 1;
52
        value = *src++;
53
        if (value >= 0xc0) {
54
            run = value & 0x3f;
50
    if (compressed) {
51
        while (i<bytes_per_scanline) {
52
            run = 1;
55 53
            value = *src++;
54
            if (value >= 0xc0) {
55
                run = value & 0x3f;
56
                value = *src++;
57
            }
58
            while (i<bytes_per_scanline && run--)
59
                dst[i++] = value;
56 60
        }
57
        while (i<bytes_per_scanline && run--)
58
            dst[i++] = value;
61
    } else {
62
        memcpy(dst, src, bytes_per_scanline);
63
        src += bytes_per_scanline;
59 64
    }
60 65

  
61 66
    return src;
......
76 81
    PCXContext * const s = avctx->priv_data;
77 82
    AVFrame *picture = data;
78 83
    AVFrame * const p = &s->picture;
79
    int xmin, ymin, xmax, ymax;
84
    int compressed, xmin, ymin, xmax, ymax;
80 85
    unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x,
81 86
                 bytes_per_scanline;
82 87
    uint8_t *ptr;
83 88
    uint8_t const *bufstart = buf;
84 89

  
85
    if (buf[0] != 0x0a || buf[1] > 5 || buf[1] == 1 || buf[2] != 1) {
90
    if (buf[0] != 0x0a || buf[1] > 5) {
86 91
        av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n");
87 92
        return -1;
88 93
    }
89 94

  
95
    compressed = buf[2];
90 96
    xmin = AV_RL16(buf+ 4);
91 97
    ymin = AV_RL16(buf+ 6);
92 98
    xmax = AV_RL16(buf+ 8);
......
151 157
        uint8_t scanline[bytes_per_scanline];
152 158

  
153 159
        for (y=0; y<h; y++) {
154
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline);
160
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
155 161

  
156 162
            for (x=0; x<w; x++) {
157 163
                ptr[3*x  ] = scanline[x                    ];
......
167 173
        const uint8_t *palstart = bufstart + buf_size - 769;
168 174

  
169 175
        for (y=0; y<h; y++, ptr+=stride) {
170
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline);
176
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
171 177
            memcpy(ptr, scanline, w);
172 178
        }
173 179

  
......
187 193
        for (y=0; y<h; y++) {
188 194
            init_get_bits(&s, scanline, bytes_per_scanline<<3);
189 195

  
190
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline);
196
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
191 197

  
192 198
            for (x=0; x<w; x++)
193 199
                ptr[x] = get_bits(&s, bits_per_pixel);
......
199 205
        int i;
200 206

  
201 207
        for (y=0; y<h; y++) {
202
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline);
208
            buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
203 209

  
204 210
            for (x=0; x<w; x++) {
205 211
                int m = 0x80 >> (x&7), v = 0;

Also available in: Unified diff