Mercurial > libavcodec.hg
annotate tiff.c @ 12495:fac8063ed1e7 libavcodec
Allow float values for libmp3lame quality.
Patch by James Darnley, james D darnley A gmail
| author | cehoyos |
|---|---|
| date | Wed, 15 Sep 2010 22:10:13 +0000 |
| parents | ffb3668ff7af |
| children |
| rev | line source |
|---|---|
| 4013 | 1 /* |
| 2 * TIFF image decoder | |
| 3 * Copyright (c) 2006 Konstantin Shishkov | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
|
4782
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
21 |
|
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
22 /** |
|
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
23 * TIFF image decoder |
|
11644
7dd2a45249a9
Remove explicit filename from Doxygen @file commands.
diego
parents:
11560
diff
changeset
|
24 * @file |
|
4782
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
25 * @author Konstantin Shishkov |
|
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
26 */ |
| 4013 | 27 #include "avcodec.h" |
| 8590 | 28 #if CONFIG_ZLIB |
| 4013 | 29 #include <zlib.h> |
| 30 #endif | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
31 #include "lzw.h" |
|
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4405
diff
changeset
|
32 #include "tiff.h" |
| 8491 | 33 #include "faxcompr.h" |
|
10501
bdf4a9ca162a
Move ff_reverse in libavcodec to av_reverse in libavutil.
cehoyos
parents:
10337
diff
changeset
|
34 #include "libavutil/common.h" |
|
10635
2938c3bc34c7
lzw.h does not need get_bits.h, tiff.c needs intreadwrite.h for AV_R* though
bcoudurier
parents:
10501
diff
changeset
|
35 #include "libavutil/intreadwrite.h" |
|
12372
914f484bb476
Remove use of the deprecated function avcodec_check_dimensions(), use
stefano
parents:
11644
diff
changeset
|
36 #include "libavcore/imgutils.h" |
| 4190 | 37 |
| 4013 | 38 typedef struct TiffContext { |
| 39 AVCodecContext *avctx; | |
| 40 AVFrame picture; | |
| 41 | |
| 42 int width, height; | |
| 43 unsigned int bpp; | |
| 44 int le; | |
| 45 int compr; | |
| 4186 | 46 int invert; |
| 8491 | 47 int fax_opts; |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
48 int predictor; |
|
10264
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
49 int fill_order; |
| 4013 | 50 |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
51 int strips, rps, sstype; |
| 4013 | 52 int sot; |
| 6256 | 53 const uint8_t* stripdata; |
| 54 const uint8_t* stripsizes; | |
| 4013 | 55 int stripsize, stripoff; |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
56 LZWState *lzw; |
| 4013 | 57 } TiffContext; |
| 58 | |
| 6256 | 59 static int tget_short(const uint8_t **p, int le){ |
| 4364 | 60 int v = le ? AV_RL16(*p) : AV_RB16(*p); |
| 4013 | 61 *p += 2; |
| 62 return v; | |
| 63 } | |
| 64 | |
| 6256 | 65 static int tget_long(const uint8_t **p, int le){ |
| 4364 | 66 int v = le ? AV_RL32(*p) : AV_RB32(*p); |
| 4013 | 67 *p += 4; |
| 68 return v; | |
| 69 } | |
| 70 | |
| 6256 | 71 static int tget(const uint8_t **p, int type, int le){ |
| 4013 | 72 switch(type){ |
| 73 case TIFF_BYTE : return *(*p)++; | |
| 74 case TIFF_SHORT: return tget_short(p, le); | |
| 75 case TIFF_LONG : return tget_long (p, le); | |
| 76 default : return -1; | |
| 77 } | |
| 78 } | |
| 79 | |
|
10299
a1654cd1b5b9
Do not compile ZLib data uncompressing function in TIFF decoder when ZLib is
kostya
parents:
10296
diff
changeset
|
80 #if CONFIG_ZLIB |
|
10296
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
81 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, int size) |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
82 { |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
83 z_stream zstream; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
84 int zret; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
85 |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
86 memset(&zstream, 0, sizeof(zstream)); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
87 zstream.next_in = src; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
88 zstream.avail_in = size; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
89 zstream.next_out = dst; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
90 zstream.avail_out = *len; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
91 zret = inflateInit(&zstream); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
92 if (zret != Z_OK) { |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
93 av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
94 return zret; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
95 } |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
96 zret = inflate(&zstream, Z_SYNC_FLUSH); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
97 inflateEnd(&zstream); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
98 *len = zstream.total_out; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
99 return zret == Z_STREAM_END ? Z_OK : zret; |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
100 } |
|
10299
a1654cd1b5b9
Do not compile ZLib data uncompressing function in TIFF decoder when ZLib is
kostya
parents:
10296
diff
changeset
|
101 #endif |
|
10296
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
102 |
| 6256 | 103 static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){ |
| 4013 | 104 int c, line, pixels, code; |
| 6256 | 105 const uint8_t *ssrc = src; |
|
8426
898722eb4fd2
Calculate line size variable correctly for lower bitdepths and use it for raw data copying
kostya
parents:
8366
diff
changeset
|
106 int width = s->width * s->bpp >> 3; |
| 8590 | 107 #if CONFIG_ZLIB |
| 4013 | 108 uint8_t *zbuf; unsigned long outlen; |
| 109 | |
| 110 if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){ | |
|
10296
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
111 int ret; |
| 4013 | 112 outlen = width * lines; |
| 113 zbuf = av_malloc(outlen); | |
|
10296
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
114 ret = tiff_uncompress(zbuf, &outlen, src, size); |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
115 if(ret != Z_OK){ |
|
a919d9583abd
Looks like ZLib uncompress() cannot deal with some kinds of TIFF deflated data,
kostya
parents:
10264
diff
changeset
|
116 av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu) with error %d\n", outlen, (unsigned long)width * lines, ret); |
| 4013 | 117 av_free(zbuf); |
| 118 return -1; | |
| 119 } | |
| 120 src = zbuf; | |
| 121 for(line = 0; line < lines; line++){ | |
| 122 memcpy(dst, src, width); | |
| 123 dst += stride; | |
| 124 src += width; | |
| 125 } | |
| 126 av_free(zbuf); | |
| 127 return 0; | |
| 128 } | |
| 129 #endif | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
130 if(s->compr == TIFF_LZW){ |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
131 if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){ |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
132 av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
133 return -1; |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
134 } |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
135 } |
| 8491 | 136 if(s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 || s->compr == TIFF_G4){ |
| 137 int i, ret = 0; | |
| 138 uint8_t *src2 = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); | |
| 139 | |
| 140 if(!src2 || (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE < (unsigned)size){ | |
| 141 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n"); | |
| 142 return -1; | |
| 143 } | |
|
10337
d1014913ad1b
Do not attempt to decode TIFF files containing fax data with uncompressed
kostya
parents:
10324
diff
changeset
|
144 if(s->fax_opts & 2){ |
|
d1014913ad1b
Do not attempt to decode TIFF files containing fax data with uncompressed
kostya
parents:
10324
diff
changeset
|
145 av_log(s->avctx, AV_LOG_ERROR, "Uncompressed fax mode is not supported (yet)\n"); |
|
d1014913ad1b
Do not attempt to decode TIFF files containing fax data with uncompressed
kostya
parents:
10324
diff
changeset
|
146 av_free(src2); |
|
d1014913ad1b
Do not attempt to decode TIFF files containing fax data with uncompressed
kostya
parents:
10324
diff
changeset
|
147 return -1; |
|
d1014913ad1b
Do not attempt to decode TIFF files containing fax data with uncompressed
kostya
parents:
10324
diff
changeset
|
148 } |
|
10264
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
149 if(!s->fill_order){ |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
150 memcpy(src2, src, size); |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
151 }else{ |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
152 for(i = 0; i < size; i++) |
|
10501
bdf4a9ca162a
Move ff_reverse in libavcodec to av_reverse in libavutil.
cehoyos
parents:
10337
diff
changeset
|
153 src2[i] = av_reverse[src[i]]; |
|
10264
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
154 } |
| 8491 | 155 memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
| 156 switch(s->compr){ | |
| 157 case TIFF_CCITT_RLE: | |
| 158 case TIFF_G3: | |
| 159 case TIFF_G4: | |
|
10304
370d05e51d90
Finally distinguish TIFF_CCITT_RLE and TIFF_G3 1-D case, so both of them
kostya
parents:
10303
diff
changeset
|
160 ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts); |
| 8491 | 161 break; |
| 162 } | |
| 163 av_free(src2); | |
| 164 return ret; | |
| 165 } | |
| 4013 | 166 for(line = 0; line < lines; line++){ |
| 167 if(src - ssrc > size){ | |
| 168 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); | |
| 169 return -1; | |
| 170 } | |
| 171 switch(s->compr){ | |
| 172 case TIFF_RAW: | |
|
8426
898722eb4fd2
Calculate line size variable correctly for lower bitdepths and use it for raw data copying
kostya
parents:
8366
diff
changeset
|
173 memcpy(dst, src, width); |
|
898722eb4fd2
Calculate line size variable correctly for lower bitdepths and use it for raw data copying
kostya
parents:
8366
diff
changeset
|
174 src += width; |
| 4013 | 175 break; |
| 176 case TIFF_PACKBITS: | |
| 177 for(pixels = 0; pixels < width;){ | |
| 178 code = (int8_t)*src++; | |
| 179 if(code >= 0){ | |
| 180 code++; | |
| 181 if(pixels + code > width){ | |
| 182 av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n"); | |
| 183 return -1; | |
| 184 } | |
| 185 memcpy(dst + pixels, src, code); | |
| 186 src += code; | |
| 187 pixels += code; | |
| 188 }else if(code != -128){ // -127..-1 | |
| 189 code = (-code) + 1; | |
| 190 if(pixels + code > width){ | |
| 191 av_log(s->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); | |
| 192 return -1; | |
| 193 } | |
| 194 c = *src++; | |
| 195 memset(dst + pixels, c, code); | |
| 196 pixels += code; | |
| 197 } | |
| 198 } | |
| 199 break; | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
200 case TIFF_LZW: |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
201 pixels = ff_lzw_decode(s->lzw, dst, width); |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
202 if(pixels < width){ |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
203 av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width); |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
204 return -1; |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
205 } |
|
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
206 break; |
| 4013 | 207 } |
| 208 dst += stride; | |
| 209 } | |
| 210 return 0; | |
| 211 } | |
| 212 | |
| 213 | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
214 static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf) |
| 4013 | 215 { |
| 216 int tag, type, count, off, value = 0; | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
217 int i, j; |
| 5261 | 218 uint32_t *pal; |
| 6256 | 219 const uint8_t *rp, *gp, *bp; |
| 4013 | 220 |
| 221 tag = tget_short(&buf, s->le); | |
| 222 type = tget_short(&buf, s->le); | |
| 223 count = tget_long(&buf, s->le); | |
| 224 off = tget_long(&buf, s->le); | |
| 225 | |
| 226 if(count == 1){ | |
| 227 switch(type){ | |
| 228 case TIFF_BYTE: | |
| 229 case TIFF_SHORT: | |
| 230 buf -= 4; | |
| 231 value = tget(&buf, type, s->le); | |
| 232 buf = NULL; | |
| 233 break; | |
| 234 case TIFF_LONG: | |
| 235 value = off; | |
| 236 buf = NULL; | |
| 237 break; | |
|
8366
3bbfd02865d7
4l: TIFF stores short strings inside tag, do not interpret it is as an offset
kostya
parents:
7040
diff
changeset
|
238 case TIFF_STRING: |
|
3bbfd02865d7
4l: TIFF stores short strings inside tag, do not interpret it is as an offset
kostya
parents:
7040
diff
changeset
|
239 if(count <= 4){ |
|
3bbfd02865d7
4l: TIFF stores short strings inside tag, do not interpret it is as an offset
kostya
parents:
7040
diff
changeset
|
240 buf -= 4; |
|
3bbfd02865d7
4l: TIFF stores short strings inside tag, do not interpret it is as an offset
kostya
parents:
7040
diff
changeset
|
241 break; |
|
3bbfd02865d7
4l: TIFF stores short strings inside tag, do not interpret it is as an offset
kostya
parents:
7040
diff
changeset
|
242 } |
| 4013 | 243 default: |
| 244 value = -1; | |
| 245 buf = start + off; | |
| 246 } | |
| 4190 | 247 }else if(type_sizes[type] * count <= 4){ |
| 248 buf -= 4; | |
| 4013 | 249 }else{ |
| 250 buf = start + off; | |
| 251 } | |
| 252 | |
| 253 if(buf && (buf < start || buf > end_buf)){ | |
| 254 av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | |
| 255 return -1; | |
| 256 } | |
| 257 | |
| 258 switch(tag){ | |
| 259 case TIFF_WIDTH: | |
| 260 s->width = value; | |
| 261 break; | |
| 262 case TIFF_HEIGHT: | |
| 263 s->height = value; | |
| 264 break; | |
| 265 case TIFF_BPP: | |
| 266 if(count == 1) s->bpp = value; | |
| 267 else{ | |
| 268 switch(type){ | |
| 269 case TIFF_BYTE: | |
| 4183 | 270 s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) + ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF); |
| 4013 | 271 break; |
| 272 case TIFF_SHORT: | |
| 273 case TIFF_LONG: | |
| 4183 | 274 s->bpp = 0; |
| 275 for(i = 0; i < count; i++) s->bpp += tget(&buf, type, s->le); | |
| 4013 | 276 break; |
| 277 default: | |
| 278 s->bpp = -1; | |
| 279 } | |
| 280 } | |
|
9784
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
281 if(count > 4){ |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
282 av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count); |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
283 return -1; |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
284 } |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
285 switch(s->bpp*10 + count){ |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
286 case 11: |
| 8427 | 287 s->avctx->pix_fmt = PIX_FMT_MONOBLACK; |
| 288 break; | |
|
9784
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
289 case 81: |
| 4186 | 290 s->avctx->pix_fmt = PIX_FMT_PAL8; |
| 291 break; | |
|
9784
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
292 case 243: |
| 4186 | 293 s->avctx->pix_fmt = PIX_FMT_RGB24; |
| 294 break; | |
|
9784
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
295 case 161: |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
296 s->avctx->pix_fmt = PIX_FMT_GRAY16BE; |
| 4193 | 297 break; |
|
9784
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
298 case 324: |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
299 s->avctx->pix_fmt = PIX_FMT_RGBA; |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
300 break; |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
301 case 483: |
|
2142607ddc2e
Check combined depth and number of components in TIFF decoder, thus eliminating
kostya
parents:
9611
diff
changeset
|
302 s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE; |
|
9611
8074df653392
Add 32-bit RGB support to TIFF decoder and extend a bit 'unsupported format' message
kostya
parents:
9553
diff
changeset
|
303 break; |
| 4186 | 304 default: |
|
9611
8074df653392
Add 32-bit RGB support to TIFF decoder and extend a bit 'unsupported format' message
kostya
parents:
9553
diff
changeset
|
305 av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count); |
| 4013 | 306 return -1; |
| 307 } | |
| 4186 | 308 if(s->width != s->avctx->width || s->height != s->avctx->height){ |
|
12462
ffb3668ff7af
Use new imgutils.h API names, fix deprecation warnings.
stefano
parents:
12372
diff
changeset
|
309 if(av_image_check_size(s->width, s->height, 0, s->avctx)) |
| 4186 | 310 return -1; |
| 311 avcodec_set_dimensions(s->avctx, s->width, s->height); | |
| 312 } | |
| 313 if(s->picture.data[0]) | |
| 314 s->avctx->release_buffer(s->avctx, &s->picture); | |
| 315 if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ | |
| 316 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | |
| 317 return -1; | |
| 318 } | |
| 319 if(s->bpp == 8){ | |
| 320 /* make default grayscale pal */ | |
| 5261 | 321 pal = (uint32_t *) s->picture.data[1]; |
| 4186 | 322 for(i = 0; i < 256; i++) |
| 323 pal[i] = i * 0x010101; | |
| 324 } | |
| 4013 | 325 break; |
| 326 case TIFF_COMPR: | |
| 327 s->compr = value; | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
328 s->predictor = 0; |
| 4013 | 329 switch(s->compr){ |
| 330 case TIFF_RAW: | |
| 331 case TIFF_PACKBITS: | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
332 case TIFF_LZW: |
| 8491 | 333 case TIFF_CCITT_RLE: |
| 334 break; | |
| 335 case TIFF_G3: | |
| 336 case TIFF_G4: | |
| 337 s->fax_opts = 0; | |
| 4013 | 338 break; |
| 339 case TIFF_DEFLATE: | |
| 340 case TIFF_ADOBE_DEFLATE: | |
| 8590 | 341 #if CONFIG_ZLIB |
| 4013 | 342 break; |
| 343 #else | |
| 344 av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n"); | |
| 345 return -1; | |
| 346 #endif | |
| 4184 | 347 case TIFF_JPEG: |
| 348 case TIFF_NEWJPEG: | |
| 349 av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n"); | |
| 350 return -1; | |
| 4013 | 351 default: |
| 352 av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n", s->compr); | |
| 353 return -1; | |
| 354 } | |
| 355 break; | |
| 356 case TIFF_ROWSPERSTRIP: | |
| 8428 | 357 if(type == TIFF_LONG && value == -1) |
| 358 value = s->avctx->height; | |
| 4185 | 359 if(value < 1){ |
| 4013 | 360 av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n"); |
| 361 return -1; | |
| 362 } | |
| 363 s->rps = value; | |
| 364 break; | |
| 365 case TIFF_STRIP_OFFS: | |
| 366 if(count == 1){ | |
| 367 s->stripdata = NULL; | |
| 368 s->stripoff = value; | |
| 369 }else | |
| 370 s->stripdata = start + off; | |
| 371 s->strips = count; | |
|
4405
48952197d91f
Some TIFFs do not set rows per strip for single strip.
kostya
parents:
4364
diff
changeset
|
372 if(s->strips == 1) s->rps = s->height; |
| 4013 | 373 s->sot = type; |
| 374 if(s->stripdata > end_buf){ | |
| 375 av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | |
| 376 return -1; | |
| 377 } | |
| 378 break; | |
| 379 case TIFF_STRIP_SIZE: | |
| 380 if(count == 1){ | |
| 381 s->stripsizes = NULL; | |
| 382 s->stripsize = value; | |
| 383 s->strips = 1; | |
| 384 }else{ | |
| 385 s->stripsizes = start + off; | |
| 386 } | |
| 387 s->strips = count; | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
388 s->sstype = type; |
| 4013 | 389 if(s->stripsizes > end_buf){ |
| 390 av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | |
| 391 return -1; | |
| 392 } | |
| 393 break; | |
| 394 case TIFF_PREDICTOR: | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
395 s->predictor = value; |
| 4013 | 396 break; |
| 4186 | 397 case TIFF_INVERT: |
| 398 switch(value){ | |
| 399 case 0: | |
| 400 s->invert = 1; | |
| 401 break; | |
| 402 case 1: | |
| 403 s->invert = 0; | |
| 404 break; | |
|
4187
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
405 case 2: |
|
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
406 case 3: |
|
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
407 break; |
|
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
408 default: |
|
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
409 av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n", value); |
|
46f12596304f
Print error message for unsupported mode (RGB planar,CMYK,YCrCb)
kostya
parents:
4186
diff
changeset
|
410 return -1; |
| 4186 | 411 } |
| 412 break; | |
|
10264
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
413 case TIFF_FILL_ORDER: |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
414 if(value < 1 || value > 2){ |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
415 av_log(s->avctx, AV_LOG_ERROR, "Unknown FillOrder value %d, trying default one\n", value); |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
416 value = 1; |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
417 } |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
418 s->fill_order = value - 1; |
|
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
419 break; |
| 4186 | 420 case TIFF_PAL: |
| 421 if(s->avctx->pix_fmt != PIX_FMT_PAL8){ | |
| 422 av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); | |
| 423 return -1; | |
| 424 } | |
| 5261 | 425 pal = (uint32_t *) s->picture.data[1]; |
| 4190 | 426 off = type_sizes[type]; |
| 4186 | 427 rp = buf; |
| 428 gp = buf + count / 3 * off; | |
| 429 bp = buf + count / 3 * off * 2; | |
| 4190 | 430 off = (type_sizes[type] - 1) << 3; |
| 4186 | 431 for(i = 0; i < count / 3; i++){ |
| 432 j = (tget(&rp, type, s->le) >> off) << 16; | |
| 433 j |= (tget(&gp, type, s->le) >> off) << 8; | |
| 434 j |= tget(&bp, type, s->le) >> off; | |
| 435 pal[i] = j; | |
| 436 } | |
| 4192 | 437 break; |
| 438 case TIFF_PLANAR: | |
| 439 if(value == 2){ | |
| 440 av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n"); | |
| 441 return -1; | |
| 442 } | |
| 443 break; | |
| 8491 | 444 case TIFF_T4OPTIONS: |
|
10303
8a49525f2b1e
Make TIFF decoder load compression options only for corresponding codec
kostya
parents:
10299
diff
changeset
|
445 if(s->compr == TIFF_G3) |
|
8a49525f2b1e
Make TIFF decoder load compression options only for corresponding codec
kostya
parents:
10299
diff
changeset
|
446 s->fax_opts = value; |
|
8a49525f2b1e
Make TIFF decoder load compression options only for corresponding codec
kostya
parents:
10299
diff
changeset
|
447 break; |
| 8491 | 448 case TIFF_T6OPTIONS: |
|
10303
8a49525f2b1e
Make TIFF decoder load compression options only for corresponding codec
kostya
parents:
10299
diff
changeset
|
449 if(s->compr == TIFF_G4) |
|
8a49525f2b1e
Make TIFF decoder load compression options only for corresponding codec
kostya
parents:
10299
diff
changeset
|
450 s->fax_opts = value; |
| 8491 | 451 break; |
| 4013 | 452 } |
| 453 return 0; | |
| 454 } | |
| 455 | |
| 456 static int decode_frame(AVCodecContext *avctx, | |
| 457 void *data, int *data_size, | |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
458 AVPacket *avpkt) |
| 4013 | 459 { |
|
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
460 const uint8_t *buf = avpkt->data; |
|
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
461 int buf_size = avpkt->size; |
| 4013 | 462 TiffContext * const s = avctx->priv_data; |
| 463 AVFrame *picture = data; | |
| 464 AVFrame * const p= (AVFrame*)&s->picture; | |
| 6256 | 465 const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; |
| 4013 | 466 int id, le, off; |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
467 int i, j, entries; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
468 int stride, soff, ssize; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
469 uint8_t *dst; |
| 4013 | 470 |
| 471 //parse image header | |
| 4364 | 472 id = AV_RL16(buf); buf += 2; |
| 4013 | 473 if(id == 0x4949) le = 1; |
| 474 else if(id == 0x4D4D) le = 0; | |
| 475 else{ | |
| 476 av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); | |
| 477 return -1; | |
| 478 } | |
| 479 s->le = le; | |
| 4186 | 480 s->invert = 0; |
| 5962 | 481 s->compr = TIFF_RAW; |
|
10264
f9efc2bd005d
Support both LSB and MSB orders for TIFF CCITT G.x compressed data.
kostya
parents:
9812
diff
changeset
|
482 s->fill_order = 0; |
| 4013 | 483 // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number |
| 484 // that further identifies the file as a TIFF file" | |
| 485 if(tget_short(&buf, le) != 42){ | |
| 486 av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n"); | |
| 487 return -1; | |
| 488 } | |
| 489 /* parse image file directory */ | |
| 490 off = tget_long(&buf, le); | |
| 491 if(orig_buf + off + 14 >= end_buf){ | |
| 492 av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n"); | |
| 493 return -1; | |
| 494 } | |
| 495 buf = orig_buf + off; | |
| 496 entries = tget_short(&buf, le); | |
| 497 for(i = 0; i < entries; i++){ | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
498 if(tiff_decode_tag(s, orig_buf, buf, end_buf) < 0) |
| 4013 | 499 return -1; |
| 500 buf += 12; | |
| 501 } | |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
502 if(!s->stripdata && !s->stripoff){ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
503 av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
504 return -1; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
505 } |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
506 /* now we have the data and may start decoding */ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
507 if(!p->data[0]){ |
|
10324
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
508 s->bpp = 1; |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
509 avctx->pix_fmt = PIX_FMT_MONOBLACK; |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
510 if(s->width != s->avctx->width || s->height != s->avctx->height){ |
|
12462
ffb3668ff7af
Use new imgutils.h API names, fix deprecation warnings.
stefano
parents:
12372
diff
changeset
|
511 if(av_image_check_size(s->width, s->height, 0, s->avctx)) |
|
10324
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
512 return -1; |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
513 avcodec_set_dimensions(s->avctx, s->width, s->height); |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
514 } |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
515 if(s->picture.data[0]) |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
516 s->avctx->release_buffer(s->avctx, &s->picture); |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
517 if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
518 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
519 return -1; |
|
5bbe55451800
When BitsPerSample tag is not present in TIFF, that means file is
kostya
parents:
10304
diff
changeset
|
520 } |
|
8429
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
521 } |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
522 if(s->strips == 1 && !s->stripsize){ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
523 av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
524 s->stripsize = buf_size - s->stripoff; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
525 } |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
526 stride = p->linesize[0]; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
527 dst = p->data[0]; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
528 for(i = 0; i < s->height; i += s->rps){ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
529 if(s->stripsizes) |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
530 ssize = tget(&s->stripsizes, s->sstype, s->le); |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
531 else |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
532 ssize = s->stripsize; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
533 |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
534 if(s->stripdata){ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
535 soff = tget(&s->stripdata, s->sot, s->le); |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
536 }else |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
537 soff = s->stripoff; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
538 if(tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize, FFMIN(s->rps, s->height - i)) < 0) |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
539 break; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
540 dst += s->rps * stride; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
541 } |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
542 if(s->predictor == 2){ |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
543 dst = p->data[0]; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
544 soff = s->bpp >> 3; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
545 ssize = s->width * soff; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
546 for(i = 0; i < s->height; i++) { |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
547 for(j = soff; j < ssize; j++) |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
548 dst[j] += dst[j - soff]; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
549 dst += stride; |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
550 } |
|
b3ecaba81501
Decode TIFF image only after all tags have been decoded
kostya
parents:
8428
diff
changeset
|
551 } |
| 4013 | 552 |
| 4186 | 553 if(s->invert){ |
| 554 uint8_t *src; | |
| 555 int j; | |
| 556 | |
| 557 src = s->picture.data[0]; | |
| 558 for(j = 0; j < s->height; j++){ | |
| 559 for(i = 0; i < s->picture.linesize[0]; i++) | |
| 560 src[i] = 255 - src[i]; | |
| 561 src += s->picture.linesize[0]; | |
| 562 } | |
| 563 } | |
| 4013 | 564 *picture= *(AVFrame*)&s->picture; |
| 565 *data_size = sizeof(AVPicture); | |
| 566 | |
| 567 return buf_size; | |
| 568 } | |
| 569 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6256
diff
changeset
|
570 static av_cold int tiff_init(AVCodecContext *avctx){ |
| 4013 | 571 TiffContext *s = avctx->priv_data; |
| 572 | |
| 573 s->width = 0; | |
| 574 s->height = 0; | |
| 575 s->avctx = avctx; | |
| 576 avcodec_get_frame_defaults((AVFrame*)&s->picture); | |
| 577 avctx->coded_frame= (AVFrame*)&s->picture; | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
578 ff_lzw_decode_open(&s->lzw); |
| 8491 | 579 ff_ccitt_unpack_init(); |
| 4013 | 580 |
| 581 return 0; | |
| 582 } | |
| 583 | |
|
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6256
diff
changeset
|
584 static av_cold int tiff_end(AVCodecContext *avctx) |
| 4013 | 585 { |
| 586 TiffContext * const s = avctx->priv_data; | |
| 587 | |
|
4080
f426c81afc9e
LZW decoder as separate module plus TIFF LZW support
kostya
parents:
4079
diff
changeset
|
588 ff_lzw_decode_close(&s->lzw); |
| 4013 | 589 if(s->picture.data[0]) |
| 590 avctx->release_buffer(avctx, &s->picture); | |
| 591 return 0; | |
| 592 } | |
| 593 | |
| 594 AVCodec tiff_decoder = { | |
| 595 "tiff", | |
|
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10635
diff
changeset
|
596 AVMEDIA_TYPE_VIDEO, |
| 4013 | 597 CODEC_ID_TIFF, |
| 598 sizeof(TiffContext), | |
| 599 tiff_init, | |
| 600 NULL, | |
| 601 tiff_end, | |
| 602 decode_frame, | |
|
9812
58d29c191e5a
tiff image decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents:
9784
diff
changeset
|
603 CODEC_CAP_DR1, |
| 6722 | 604 NULL, |
|
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6722
diff
changeset
|
605 .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
| 4013 | 606 }; |
