summaryrefslogtreecommitdiff
path: root/libavcodec/tiff.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-05-13 04:40:40 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-13 04:40:40 +0200
commit72153419b52c96b1ed4a1bfb7e7793ddde7d71b2 (patch)
tree2e5b40aecf44ad40dd0d6bf122fd8918a889805e /libavcodec/tiff.c
parent410ca3bc2d5e95078f3d6698a2f9e53c2fd24f95 (diff)
parent552a99957f7c6f6ed13795caee7ab7b9deb5d76e (diff)
Merge remote branch 'qatar/master'
* qatar/master: (33 commits) rtpdec_qdm2: Don't try to parse data packet if no configuration is received ac3enc: put the counting of stereo rematrixing bits in the same place to make the code easier to understand. ac3enc: clean up count_frame_bits() and count_frame_bits_fixed() mpegvideo: make FF_DEBUG_DCT_COEFF output coeffs via av_log() instead of just via AVFrame. srtdec: make sure we don't write past the end of buffer wmaenc: improve channel count and bitrate error handling in encode_init() matroskaenc: make sure we don't produce invalid file with no codec ID matroskadec: check that pointers were initialized before accessing them lavf: fix function name in compute_pkt_fields2 av_dlog message lavf: fix av_find_best_stream when providing a wanted stream. lavf: fix av_find_best_stream when decoder_ret is given and using a related stream. ffmpeg: factorize quality calculation tiff: add support for SamplesPerPixel tag in tiff_decode_tag() tiff: Prefer enum TiffCompr over int for TiffContext.compr. mov: Support edit list atom version 1. configure: Enable libpostproc automatically if GPL code is enabled. Cosmetics: fix prototypes in oggdec oggdec: fix memleak with continuous streams. matroskaenc: add missing new line in av_log() call dnxhdenc: add AVClass in private context. ... swscale changes largely rewritten by me or replaced by baptsites due to lots of bugs in ronalds code. Above code is also just in case its not obvios to a large extended duplicates that where cherry picked from ffmpeg. Conflicts: configure ffmpeg.c libavformat/matroskaenc.c libavutil/pixfmt.h libswscale/ppc/swscale_template.c libswscale/swscale.c libswscale/swscale_template.c libswscale/utils.c libswscale/x86/swscale_template.c tests/fate/h264.mak tests/ref/lavfi/pixdesc_le tests/ref/lavfi/pixfmts_copy_le tests/ref/lavfi/pixfmts_null_le tests/ref/lavfi/pixfmts_scale_le tests/ref/lavfi/pixfmts_vflip_le Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/tiff.c')
-rw-r--r--libavcodec/tiff.c122
1 files changed, 65 insertions, 57 deletions
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 7e7ae0f007..587ddc604f 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -38,7 +38,7 @@ typedef struct TiffContext {
AVFrame picture;
int width, height;
- unsigned int bpp;
+ unsigned int bpp, bppcount;
int le;
enum TiffCompr compr;
int invert;
@@ -214,6 +214,55 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
return 0;
}
+static int init_image(TiffContext *s)
+{
+ int i, ret;
+ uint32_t *pal;
+
+ switch (s->bpp * 10 + s->bppcount) {
+ case 11:
+ s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
+ break;
+ case 81:
+ s->avctx->pix_fmt = PIX_FMT_PAL8;
+ break;
+ case 243:
+ s->avctx->pix_fmt = PIX_FMT_RGB24;
+ break;
+ case 161:
+ s->avctx->pix_fmt = PIX_FMT_GRAY16BE;
+ break;
+ case 324:
+ s->avctx->pix_fmt = PIX_FMT_RGBA;
+ break;
+ case 483:
+ s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE;
+ break;
+ default:
+ av_log(s->avctx, AV_LOG_ERROR,
+ "This format is not supported (bpp=%d, bppcount=%d)\n",
+ s->bpp, s->bppcount);
+ return AVERROR_INVALIDDATA;
+ }
+ if (s->width != s->avctx->width || s->height != s->avctx->height) {
+ if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
+ return ret;
+ avcodec_set_dimensions(s->avctx, s->width, s->height);
+ }
+ if (s->picture.data[0])
+ s->avctx->release_buffer(s->avctx, &s->picture);
+ if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0) {
+ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return ret;
+ }
+ if (s->bpp == 8 && s->picture.data[1]){
+ /* make default grayscale pal */
+ pal = (uint32_t *) s->picture.data[1];
+ for (i = 0; i < 256; i++)
+ pal[i] = i * 0x010101;
+ }
+ return 0;
+}
static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
{
@@ -267,6 +316,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
s->height = value;
break;
case TIFF_BPP:
+ s->bppcount = count;
if(count > 4){
av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count);
return -1;
@@ -286,46 +336,16 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
s->bpp = -1;
}
}
- switch(s->bpp*10 + count){
- case 11:
- s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
- break;
- case 81:
- s->avctx->pix_fmt = PIX_FMT_PAL8;
- break;
- case 243:
- s->avctx->pix_fmt = PIX_FMT_RGB24;
- break;
- case 161:
- s->avctx->pix_fmt = PIX_FMT_GRAY16BE;
- break;
- case 324:
- s->avctx->pix_fmt = PIX_FMT_RGBA;
- break;
- case 483:
- s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE;
- break;
- default:
- av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count);
- return -1;
- }
- if(s->width != s->avctx->width || s->height != s->avctx->height){
- if(av_image_check_size(s->width, s->height, 0, s->avctx))
- return -1;
- avcodec_set_dimensions(s->avctx, s->width, s->height);
- }
- if(s->picture.data[0])
- s->avctx->release_buffer(s->avctx, &s->picture);
- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
- if(s->bpp == 8){
- /* make default grayscale pal */
- pal = (uint32_t *) s->picture.data[1];
- for(i = 0; i < 256; i++)
- pal[i] = i * 0x010101;
- }
+ break;
+ case TIFF_SAMPLES_PER_PIXEL:
+ if (count != 1) {
+ av_log(s->avctx, AV_LOG_ERROR,
+ "Samples per pixel requires a single value, many provided\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (s->bppcount == 1)
+ s->bpp *= value;
+ s->bppcount = value;
break;
case TIFF_COMPR:
s->compr = value;
@@ -468,7 +488,7 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *picture = data;
AVFrame * const p= (AVFrame*)&s->picture;
const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
- int id, le, off;
+ int id, le, off, ret;
int i, j, entries;
int stride, soff, ssize;
uint8_t *dst;
@@ -509,21 +529,9 @@ static int decode_frame(AVCodecContext *avctx,
return -1;
}
/* now we have the data and may start decoding */
- if(!p->data[0]){
- s->bpp = 1;
- avctx->pix_fmt = PIX_FMT_MONOBLACK;
- if(s->width != s->avctx->width || s->height != s->avctx->height){
- if(av_image_check_size(s->width, s->height, 0, s->avctx))
- return -1;
- avcodec_set_dimensions(s->avctx, s->width, s->height);
- }
- if(s->picture.data[0])
- s->avctx->release_buffer(s->avctx, &s->picture);
- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
- }
- }
+ if ((ret = init_image(s)) < 0)
+ return ret;
+
if(s->strips == 1 && !s->stripsize){
av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
s->stripsize = buf_size - s->stripoff;