Revision bbc572a2

View differences:

libavcodec/tiff.c
40 40
    AVFrame picture;
41 41

  
42 42
    int width, height;
43
    unsigned int bpp;
43
    unsigned int bpp, bppcount;
44 44
    int le;
45 45
    enum TiffCompr compr;
46 46
    int invert;
......
216 216
    return 0;
217 217
}
218 218

  
219
static int init_image(TiffContext *s)
220
{
221
    int i, ret;
222
    uint32_t *pal;
223

  
224
    switch (s->bpp * 10 + s->bppcount) {
225
    case 11:
226
        s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
227
        break;
228
    case 81:
229
        s->avctx->pix_fmt = PIX_FMT_PAL8;
230
        break;
231
    case 243:
232
        s->avctx->pix_fmt = PIX_FMT_RGB24;
233
        break;
234
    case 161:
235
        s->avctx->pix_fmt = PIX_FMT_GRAY16BE;
236
        break;
237
    case 324:
238
        s->avctx->pix_fmt = PIX_FMT_RGBA;
239
        break;
240
    case 483:
241
        s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE;
242
        break;
243
    default:
244
        av_log(s->avctx, AV_LOG_ERROR,
245
               "This format is not supported (bpp=%d, bppcount=%d)\n",
246
               s->bpp, s->bppcount);
247
        return AVERROR_INVALIDDATA;
248
    }
249
    if (s->width != s->avctx->width || s->height != s->avctx->height) {
250
        if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
251
            return ret;
252
        avcodec_set_dimensions(s->avctx, s->width, s->height);
253
    }
254
    if (s->picture.data[0])
255
        s->avctx->release_buffer(s->avctx, &s->picture);
256
    if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0) {
257
        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
258
        return ret;
259
    }
260
    if (s->bpp == 8 && s->picture.data[1]){
261
        /* make default grayscale pal */
262
        pal = (uint32_t *) s->picture.data[1];
263
        for (i = 0; i < 256; i++)
264
            pal[i] = i * 0x010101;
265
    }
266
    return 0;
267
}
219 268

  
220 269
static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
221 270
{
......
269 318
        s->height = value;
270 319
        break;
271 320
    case TIFF_BPP:
321
        s->bppcount = count;
272 322
        if(count > 4){
273 323
            av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count);
274 324
            return -1;
......
288 338
                s->bpp = -1;
289 339
            }
290 340
        }
291
        switch(s->bpp*10 + count){
292
        case 11:
293
            s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
294
            break;
295
        case 81:
296
            s->avctx->pix_fmt = PIX_FMT_PAL8;
297
            break;
298
        case 243:
299
            s->avctx->pix_fmt = PIX_FMT_RGB24;
300
            break;
301
        case 161:
302
            s->avctx->pix_fmt = PIX_FMT_GRAY16BE;
303
            break;
304
        case 324:
305
            s->avctx->pix_fmt = PIX_FMT_RGBA;
306
            break;
307
        case 483:
308
            s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE;
309
            break;
310
        default:
311
            av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count);
312
            return -1;
313
        }
314
        if(s->width != s->avctx->width || s->height != s->avctx->height){
315
            if(av_image_check_size(s->width, s->height, 0, s->avctx))
316
                return -1;
317
            avcodec_set_dimensions(s->avctx, s->width, s->height);
318
        }
319
        if(s->picture.data[0])
320
            s->avctx->release_buffer(s->avctx, &s->picture);
321
        if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
322
            av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
323
            return -1;
324
        }
325
        if(s->bpp == 8){
326
            /* make default grayscale pal */
327
            pal = (uint32_t *) s->picture.data[1];
328
            for(i = 0; i < 256; i++)
329
                pal[i] = i * 0x010101;
330
        }
341
        break;
342
    case TIFF_SAMPLES_PER_PIXEL:
343
        if (count != 1) {
344
            av_log(s->avctx, AV_LOG_ERROR,
345
                   "Samples per pixel requires a single value, many provided\n");
346
            return AVERROR_INVALIDDATA;
347
        }
348
        if (s->bppcount == 1)
349
            s->bpp *= value;
350
        s->bppcount = value;
331 351
        break;
332 352
    case TIFF_COMPR:
333 353
        s->compr = value;
......
469 489
    AVFrame *picture = data;
470 490
    AVFrame * const p= (AVFrame*)&s->picture;
471 491
    const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
472
    int id, le, off;
492
    int id, le, off, ret;
473 493
    int i, j, entries;
474 494
    int stride, soff, ssize;
475 495
    uint8_t *dst;
......
510 530
        return -1;
511 531
    }
512 532
    /* now we have the data and may start decoding */
513
    if(!p->data[0]){
514
        s->bpp = 1;
515
        avctx->pix_fmt = PIX_FMT_MONOBLACK;
516
        if(s->width != s->avctx->width || s->height != s->avctx->height){
517
            if(av_image_check_size(s->width, s->height, 0, s->avctx))
518
                return -1;
519
            avcodec_set_dimensions(s->avctx, s->width, s->height);
520
        }
521
        if(s->picture.data[0])
522
            s->avctx->release_buffer(s->avctx, &s->picture);
523
        if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
524
            av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
525
            return -1;
526
        }
527
    }
533
    if ((ret = init_image(s)) < 0)
534
        return ret;
535

  
528 536
    if(s->strips == 1 && !s->stripsize){
529 537
        av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
530 538
        s->stripsize = buf_size - s->stripoff;

Also available in: Unified diff