Revision 042e0add

View differences:

libavcodec/png.c
23 23
#include "png.h"
24 24

  
25 25
const uint8_t ff_pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
26
const uint8_t ff_mngsig[8] = {138, 77, 78, 71, 13, 10, 26, 10};
26 27

  
27 28
/* Mask to determine which y pixels are valid in a pass */
28 29
const uint8_t ff_png_pass_ymask[NB_PASSES] = {
libavcodec/png.h
34 34
#define PNG_COLOR_TYPE_RGB_ALPHA  (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
35 35
#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
36 36

  
37
#define PNG_FILTER_TYPE_LOCO   64
37 38
#define PNG_FILTER_VALUE_NONE  0
38 39
#define PNG_FILTER_VALUE_SUB   1
39 40
#define PNG_FILTER_VALUE_UP    2
......
49 50
#define NB_PASSES 7
50 51

  
51 52
extern const uint8_t ff_pngsig[8];
53
extern const uint8_t ff_mngsig[8];
52 54

  
53 55
/* Mask to determine which y pixels are valid in a pass */
54 56
extern const uint8_t ff_png_pass_ymask[NB_PASSES];
libavcodec/pngdec.c
234 234
    }
235 235
}
236 236

  
237
static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width)
237
static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco)
238 238
{
239 239
    int j;
240 240
    unsigned int r, g, b, a;
......
244 244
        g = src[1];
245 245
        b = src[2];
246 246
        a = src[3];
247
        if(loco) {
248
            r = (r+g)&0xff;
249
            b = (b+g)&0xff;
250
        }
247 251
        *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
248 252
        dst += 4;
249 253
        src += 4;
250 254
    }
251 255
}
252 256

  
257
static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco)
258
{
259
    if(loco)
260
        convert_to_rgb32_loco(dst, src, width, 1);
261
    else
262
        convert_to_rgb32_loco(dst, src, width, 0);
263
}
264

  
265
static void deloco_rgb24(uint8_t *dst, int size)
266
{
267
    int i;
268
    for(i=0; i<size; i+=3) {
269
        int g = dst[i+1];
270
        dst[i+0] += g;
271
        dst[i+2] += g;
272
    }
273
}
274

  
253 275
/* process exactly one decompressed row */
254 276
static void png_handle_row(PNGDecContext *s)
255 277
{
......
262 284
        if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
263 285
            png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
264 286
                           s->last_row, s->row_size, s->bpp);
265
            convert_to_rgb32(ptr, s->tmp_row, s->width);
287
            convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO);
266 288
            FFSWAP(uint8_t*, s->last_row, s->tmp_row);
267 289
        } else {
268 290
            /* in normal case, we avoid one copy */
......
274 296
            png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1,
275 297
                           last_row, s->row_size, s->bpp);
276 298
        }
299
        /* loco lags by 1 row so that it doesn't interfere with top prediction */
300
        if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
301
            s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0)
302
            deloco_rgb24(ptr - s->image_linesize, s->row_size);
277 303
        s->y++;
278 304
        if (s->y == s->height) {
279 305
            s->state |= PNG_ALLIMAGE;
306
            if (s->filter_type == PNG_FILTER_TYPE_LOCO &&
307
                s->color_type == PNG_COLOR_TYPE_RGB)
308
                deloco_rgb24(ptr, s->row_size);
280 309
        }
281 310
    } else {
282 311
        got_line = 0;
......
363 392
    s->bytestream_end= buf + buf_size;
364 393

  
365 394
    /* check signature */
366
    if (memcmp(s->bytestream, ff_pngsig, 8) != 0)
395
    if (memcmp(s->bytestream, ff_pngsig, 8) != 0 &&
396
        memcmp(s->bytestream, ff_mngsig, 8) != 0)
367 397
        return -1;
368 398
    s->bytestream+= 8;
369 399
    s->y=
libavformat/img2.c
41 41
    { CODEC_ID_MJPEG     , "jpg"},
42 42
    { CODEC_ID_LJPEG     , "ljpg"},
43 43
    { CODEC_ID_PNG       , "png"},
44
    { CODEC_ID_PNG       , "mng"},
44 45
    { CODEC_ID_PPM       , "ppm"},
45 46
    { CODEC_ID_PGM       , "pgm"},
46 47
    { CODEC_ID_PGMYUV    , "pgmyuv"},

Also available in: Unified diff