... | ... |
@@ -25,19 +25,20 @@ |
25 | 25 |
* @author Konstantin Shishkov |
26 | 26 |
*/ |
27 | 27 |
|
28 |
-#include "avcodec.h" |
|
29 | 28 |
#include "config.h" |
30 | 29 |
#if CONFIG_ZLIB |
31 | 30 |
#include <zlib.h> |
32 | 31 |
#endif |
33 |
-#include "lzw.h" |
|
34 |
-#include "tiff.h" |
|
35 |
-#include "faxcompr.h" |
|
36 |
-#include "internal.h" |
|
37 |
-#include "mathops.h" |
|
32 |
+ |
|
38 | 33 |
#include "libavutil/attributes.h" |
39 | 34 |
#include "libavutil/intreadwrite.h" |
40 | 35 |
#include "libavutil/imgutils.h" |
36 |
+#include "avcodec.h" |
|
37 |
+#include "faxcompr.h" |
|
38 |
+#include "internal.h" |
|
39 |
+#include "lzw.h" |
|
40 |
+#include "mathops.h" |
|
41 |
+#include "tiff.h" |
|
41 | 42 |
|
42 | 43 |
typedef struct TiffContext { |
43 | 44 |
AVCodecContext *avctx; |
... | ... |
@@ -78,10 +79,14 @@ static unsigned tget_long(const uint8_t **p, int le) |
78 | 78 |
static unsigned tget(const uint8_t **p, int type, int le) |
79 | 79 |
{ |
80 | 80 |
switch (type) { |
81 |
- case TIFF_BYTE : return *(*p)++; |
|
82 |
- case TIFF_SHORT: return tget_short(p, le); |
|
83 |
- case TIFF_LONG : return tget_long(p, le); |
|
84 |
- default : return UINT_MAX; |
|
81 |
+ case TIFF_BYTE: |
|
82 |
+ return *(*p)++; |
|
83 |
+ case TIFF_SHORT: |
|
84 |
+ return tget_short(p, le); |
|
85 |
+ case TIFF_LONG: |
|
86 |
+ return tget_long(p, le); |
|
87 |
+ default: |
|
88 |
+ return UINT_MAX; |
|
85 | 89 |
} |
86 | 90 |
} |
87 | 91 |
|
... | ... |
@@ -92,11 +97,11 @@ static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, |
92 | 92 |
z_stream zstream = { 0 }; |
93 | 93 |
int zret; |
94 | 94 |
|
95 |
- zstream.next_in = src; |
|
96 |
- zstream.avail_in = size; |
|
97 |
- zstream.next_out = dst; |
|
95 |
+ zstream.next_in = src; |
|
96 |
+ zstream.avail_in = size; |
|
97 |
+ zstream.next_out = dst; |
|
98 | 98 |
zstream.avail_out = *len; |
99 |
- zret = inflateInit(&zstream); |
|
99 |
+ zret = inflateInit(&zstream); |
|
100 | 100 |
if (zret != Z_OK) { |
101 | 101 |
av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret); |
102 | 102 |
return zret; |
... | ... |
@@ -113,7 +118,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
113 | 113 |
{ |
114 | 114 |
int c, line, pixels, code, ret; |
115 | 115 |
const uint8_t *ssrc = src; |
116 |
- int width = ((s->width * s->bpp) + 7) >> 3; |
|
116 |
+ int width = ((s->width * s->bpp) + 7) >> 3; |
|
117 | 117 |
|
118 | 118 |
if (size <= 0) |
119 | 119 |
return AVERROR_INVALIDDATA; |
... | ... |
@@ -124,7 +129,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
124 | 124 |
unsigned long outlen; |
125 | 125 |
int ret; |
126 | 126 |
outlen = width * lines; |
127 |
- zbuf = av_malloc(outlen); |
|
127 |
+ zbuf = av_malloc(outlen); |
|
128 | 128 |
if (!zbuf) |
129 | 129 |
return AVERROR(ENOMEM); |
130 | 130 |
ret = tiff_uncompress(zbuf, &outlen, src, size); |
... | ... |
@@ -151,8 +156,9 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
151 | 151 |
return ret; |
152 | 152 |
} |
153 | 153 |
} |
154 |
- if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 |
|
155 |
- || s->compr == TIFF_G4) { |
|
154 |
+ if (s->compr == TIFF_CCITT_RLE || |
|
155 |
+ s->compr == TIFF_G3 || |
|
156 |
+ s->compr == TIFF_G4) { |
|
156 | 157 |
int i, ret = 0; |
157 | 158 |
uint8_t *src2 = av_malloc((unsigned)size + |
158 | 159 |
FF_INPUT_BUFFER_PADDING_SIZE); |
... | ... |
@@ -206,7 +212,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
206 | 206 |
break; |
207 | 207 |
case TIFF_PACKBITS: |
208 | 208 |
for (pixels = 0; pixels < width;) { |
209 |
- code = (int8_t) * src++; |
|
209 |
+ code = (int8_t) *src++; |
|
210 | 210 |
if (code >= 0) { |
211 | 211 |
code++; |
212 | 212 |
if (pixels + code > width) { |
... | ... |
@@ -215,7 +221,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, |
215 | 215 |
return AVERROR_INVALIDDATA; |
216 | 216 |
} |
217 | 217 |
memcpy(dst + pixels, src, code); |
218 |
- src += code; |
|
218 |
+ src += code; |
|
219 | 219 |
pixels += code; |
220 | 220 |
} else if (code != -128) { // -127..-1 |
221 | 221 |
code = (-code) + 1; |
... | ... |
@@ -306,10 +312,10 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
306 | 306 |
|
307 | 307 |
if (end_buf - buf < 12) |
308 | 308 |
return AVERROR_INVALIDDATA; |
309 |
- tag = tget_short(&buf, s->le); |
|
310 |
- type = tget_short(&buf, s->le); |
|
309 |
+ tag = tget_short(&buf, s->le); |
|
310 |
+ type = tget_short(&buf, s->le); |
|
311 | 311 |
count = tget_long(&buf, s->le); |
312 |
- off = tget_long(&buf, s->le); |
|
312 |
+ off = tget_long(&buf, s->le); |
|
313 | 313 |
|
314 | 314 |
if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) { |
315 | 315 |
av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n", |
... | ... |
@@ -321,13 +327,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
321 | 321 |
switch (type) { |
322 | 322 |
case TIFF_BYTE: |
323 | 323 |
case TIFF_SHORT: |
324 |
- buf -= 4; |
|
324 |
+ buf -= 4; |
|
325 | 325 |
value = tget(&buf, type, s->le); |
326 |
- buf = NULL; |
|
326 |
+ buf = NULL; |
|
327 | 327 |
break; |
328 | 328 |
case TIFF_LONG: |
329 | 329 |
value = off; |
330 |
- buf = NULL; |
|
330 |
+ buf = NULL; |
|
331 | 331 |
break; |
332 | 332 |
case TIFF_STRING: |
333 | 333 |
if (count <= 4) { |
... | ... |
@@ -336,14 +342,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
336 | 336 |
} |
337 | 337 |
default: |
338 | 338 |
value = UINT_MAX; |
339 |
- buf = start + off; |
|
339 |
+ buf = start + off; |
|
340 | 340 |
} |
341 | 341 |
} else { |
342 |
- if (count <= 4 && type_sizes[type] * count <= 4) { |
|
342 |
+ if (count <= 4 && type_sizes[type] * count <= 4) |
|
343 | 343 |
buf -= 4; |
344 |
- } else { |
|
344 |
+ else |
|
345 | 345 |
buf = start + off; |
346 |
- } |
|
347 | 346 |
} |
348 | 347 |
|
349 | 348 |
if (buf && (buf < start || buf > end_buf)) { |
... | ... |
@@ -397,7 +402,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
397 | 397 |
s->bppcount = value; |
398 | 398 |
break; |
399 | 399 |
case TIFF_COMPR: |
400 |
- s->compr = value; |
|
400 |
+ s->compr = value; |
|
401 | 401 |
s->predictor = 0; |
402 | 402 |
switch (s->compr) { |
403 | 403 |
case TIFF_RAW: |
... | ... |
@@ -441,7 +446,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
441 | 441 |
case TIFF_STRIP_OFFS: |
442 | 442 |
if (count == 1) { |
443 | 443 |
s->stripdata = NULL; |
444 |
- s->stripoff = value; |
|
444 |
+ s->stripoff = value; |
|
445 | 445 |
} else |
446 | 446 |
s->stripdata = start + off; |
447 | 447 |
s->strips = count; |
... | ... |
@@ -457,8 +462,8 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
457 | 457 |
case TIFF_STRIP_SIZE: |
458 | 458 |
if (count == 1) { |
459 | 459 |
s->stripsizes = NULL; |
460 |
- s->stripsize = value; |
|
461 |
- s->strips = 1; |
|
460 |
+ s->stripsize = value; |
|
461 |
+ s->strips = 1; |
|
462 | 462 |
} else { |
463 | 463 |
s->stripsizes = start + off; |
464 | 464 |
} |
... | ... |
@@ -503,14 +508,14 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, |
503 | 503 |
off = type_sizes[type]; |
504 | 504 |
if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3) |
505 | 505 |
return AVERROR_INVALIDDATA; |
506 |
- rp = buf; |
|
507 |
- gp = buf + count / 3 * off; |
|
508 |
- bp = buf + count / 3 * off * 2; |
|
506 |
+ rp = buf; |
|
507 |
+ gp = buf + count / 3 * off; |
|
508 |
+ bp = buf + count / 3 * off * 2; |
|
509 | 509 |
off = (type_sizes[type] - 1) << 3; |
510 | 510 |
for (i = 0; i < count / 3; i++) { |
511 |
- j = (tget(&rp, type, s->le) >> off) << 16; |
|
512 |
- j |= (tget(&gp, type, s->le) >> off) << 8; |
|
513 |
- j |= tget(&bp, type, s->le) >> off; |
|
511 |
+ j = (tget(&rp, type, s->le) >> off) << 16; |
|
512 |
+ j |= (tget(&gp, type, s->le) >> off) << 8; |
|
513 |
+ j |= tget(&bp, type, s->le) >> off; |
|
514 | 514 |
pal[i] = j; |
515 | 515 |
} |
516 | 516 |
s->palette_is_set = 1; |
... | ... |
@@ -540,21 +545,20 @@ static int decode_frame(AVCodecContext *avctx, |
540 | 540 |
void *data, int *got_frame, AVPacket *avpkt) |
541 | 541 |
{ |
542 | 542 |
const uint8_t *buf = avpkt->data; |
543 |
- int buf_size = avpkt->size; |
|
543 |
+ int buf_size = avpkt->size; |
|
544 | 544 |
TiffContext *const s = avctx->priv_data; |
545 | 545 |
AVFrame *const p = data; |
546 | 546 |
const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; |
547 | 547 |
unsigned off; |
548 | 548 |
int id, le, ret; |
549 |
- int i, j, entries; |
|
550 |
- int stride; |
|
549 |
+ int i, j, entries, stride; |
|
551 | 550 |
unsigned soff, ssize; |
552 | 551 |
uint8_t *dst; |
553 | 552 |
|
554 |
- //parse image header |
|
553 |
+ // parse image header |
|
555 | 554 |
if (end_buf - buf < 8) |
556 | 555 |
return AVERROR_INVALIDDATA; |
557 |
- id = AV_RL16(buf); |
|
556 |
+ id = AV_RL16(buf); |
|
558 | 557 |
buf += 2; |
559 | 558 |
if (id == 0x4949) |
560 | 559 |
le = 1; |
... | ... |
@@ -564,9 +568,9 @@ static int decode_frame(AVCodecContext *avctx, |
564 | 564 |
av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); |
565 | 565 |
return AVERROR_INVALIDDATA; |
566 | 566 |
} |
567 |
- s->le = le; |
|
568 |
- s->invert = 0; |
|
569 |
- s->compr = TIFF_RAW; |
|
567 |
+ s->le = le; |
|
568 |
+ s->invert = 0; |
|
569 |
+ s->compr = TIFF_RAW; |
|
570 | 570 |
s->fill_order = 0; |
571 | 571 |
// As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number |
572 | 572 |
// that further identifies the file as a TIFF file" |
... | ... |
@@ -583,7 +587,7 @@ static int decode_frame(AVCodecContext *avctx, |
583 | 583 |
av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n"); |
584 | 584 |
return AVERROR_INVALIDDATA; |
585 | 585 |
} |
586 |
- buf = orig_buf + off; |
|
586 |
+ buf = orig_buf + off; |
|
587 | 587 |
entries = tget_short(&buf, le); |
588 | 588 |
for (i = 0; i < entries; i++) { |
589 | 589 |
if ((ret = tiff_decode_tag(s, orig_buf, buf, end_buf)) < 0) |
... | ... |
@@ -603,7 +607,7 @@ static int decode_frame(AVCodecContext *avctx, |
603 | 603 |
s->stripsize = buf_size - s->stripoff; |
604 | 604 |
} |
605 | 605 |
stride = p->linesize[0]; |
606 |
- dst = p->data[0]; |
|
606 |
+ dst = p->data[0]; |
|
607 | 607 |
for (i = 0; i < s->height; i += s->rps) { |
608 | 608 |
if (s->stripsizes) { |
609 | 609 |
if (s->stripsizes >= end_buf) |
... | ... |
@@ -629,8 +633,8 @@ static int decode_frame(AVCodecContext *avctx, |
629 | 629 |
dst += s->rps * stride; |
630 | 630 |
} |
631 | 631 |
if (s->predictor == 2) { |
632 |
- dst = p->data[0]; |
|
633 |
- soff = s->bpp >> 3; |
|
632 |
+ dst = p->data[0]; |
|
633 |
+ soff = s->bpp >> 3; |
|
634 | 634 |
ssize = s->width * soff; |
635 | 635 |
for (i = 0; i < s->height; i++) { |
636 | 636 |
for (j = soff; j < ssize; j++) |
... | ... |
@@ -659,9 +663,9 @@ static av_cold int tiff_init(AVCodecContext *avctx) |
659 | 659 |
{ |
660 | 660 |
TiffContext *s = avctx->priv_data; |
661 | 661 |
|
662 |
- s->width = 0; |
|
662 |
+ s->width = 0; |
|
663 | 663 |
s->height = 0; |
664 |
- s->avctx = avctx; |
|
664 |
+ s->avctx = avctx; |
|
665 | 665 |
ff_lzw_decode_open(&s->lzw); |
666 | 666 |
ff_ccitt_unpack_init(); |
667 | 667 |
|
... | ... |
@@ -678,6 +682,7 @@ static av_cold int tiff_end(AVCodecContext *avctx) |
678 | 678 |
|
679 | 679 |
AVCodec ff_tiff_decoder = { |
680 | 680 |
.name = "tiff", |
681 |
+ .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
|
681 | 682 |
.type = AVMEDIA_TYPE_VIDEO, |
682 | 683 |
.id = AV_CODEC_ID_TIFF, |
683 | 684 |
.priv_data_size = sizeof(TiffContext), |
... | ... |
@@ -685,5 +690,4 @@ AVCodec ff_tiff_decoder = { |
685 | 685 |
.close = tiff_end, |
686 | 686 |
.decode = decode_frame, |
687 | 687 |
.capabilities = CODEC_CAP_DR1, |
688 |
- .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
|
689 | 688 |
}; |
... | ... |
@@ -31,37 +31,37 @@ |
31 | 31 |
#include <stdint.h> |
32 | 32 |
|
33 | 33 |
/** abridged list of TIFF tags */ |
34 |
-enum TiffTags{ |
|
35 |
- TIFF_SUBFILE = 0xfe, |
|
36 |
- TIFF_WIDTH = 0x100, |
|
34 |
+enum TiffTags { |
|
35 |
+ TIFF_SUBFILE = 0xfe, |
|
36 |
+ TIFF_WIDTH = 0x100, |
|
37 | 37 |
TIFF_HEIGHT, |
38 | 38 |
TIFF_BPP, |
39 | 39 |
TIFF_COMPR, |
40 |
- TIFF_INVERT = 0x106, |
|
41 |
- TIFF_FILL_ORDER = 0x10A, |
|
42 |
- TIFF_STRIP_OFFS = 0x111, |
|
43 |
- TIFF_SAMPLES_PER_PIXEL = 0x115, |
|
44 |
- TIFF_ROWSPERSTRIP = 0x116, |
|
40 |
+ TIFF_INVERT = 0x106, |
|
41 |
+ TIFF_FILL_ORDER = 0x10A, |
|
42 |
+ TIFF_STRIP_OFFS = 0x111, |
|
43 |
+ TIFF_SAMPLES_PER_PIXEL = 0x115, |
|
44 |
+ TIFF_ROWSPERSTRIP = 0x116, |
|
45 | 45 |
TIFF_STRIP_SIZE, |
46 |
- TIFF_XRES = 0x11A, |
|
47 |
- TIFF_YRES = 0x11B, |
|
48 |
- TIFF_PLANAR = 0x11C, |
|
49 |
- TIFF_XPOS = 0x11E, |
|
50 |
- TIFF_YPOS = 0x11F, |
|
51 |
- TIFF_T4OPTIONS = 0x124, |
|
46 |
+ TIFF_XRES = 0x11A, |
|
47 |
+ TIFF_YRES = 0x11B, |
|
48 |
+ TIFF_PLANAR = 0x11C, |
|
49 |
+ TIFF_XPOS = 0x11E, |
|
50 |
+ TIFF_YPOS = 0x11F, |
|
51 |
+ TIFF_T4OPTIONS = 0x124, |
|
52 | 52 |
TIFF_T6OPTIONS, |
53 |
- TIFF_RES_UNIT = 0x128, |
|
54 |
- TIFF_SOFTWARE_NAME = 0x131, |
|
55 |
- TIFF_PREDICTOR = 0x13D, |
|
56 |
- TIFF_PAL = 0x140, |
|
53 |
+ TIFF_RES_UNIT = 0x128, |
|
54 |
+ TIFF_SOFTWARE_NAME = 0x131, |
|
55 |
+ TIFF_PREDICTOR = 0x13D, |
|
56 |
+ TIFF_PAL = 0x140, |
|
57 | 57 |
TIFF_YCBCR_COEFFICIENTS = 0x211, |
58 |
- TIFF_YCBCR_SUBSAMPLING = 0x212, |
|
59 |
- TIFF_YCBCR_POSITIONING = 0x213, |
|
60 |
- TIFF_REFERENCE_BW = 0x214, |
|
58 |
+ TIFF_YCBCR_SUBSAMPLING = 0x212, |
|
59 |
+ TIFF_YCBCR_POSITIONING = 0x213, |
|
60 |
+ TIFF_REFERENCE_BW = 0x214, |
|
61 | 61 |
}; |
62 | 62 |
|
63 | 63 |
/** list of TIFF compression types */ |
64 |
-enum TiffCompr{ |
|
64 |
+enum TiffCompr { |
|
65 | 65 |
TIFF_RAW = 1, |
66 | 66 |
TIFF_CCITT_RLE, |
67 | 67 |
TIFF_G3, |
... | ... |
@@ -71,10 +71,10 @@ enum TiffCompr{ |
71 | 71 |
TIFF_NEWJPEG, |
72 | 72 |
TIFF_ADOBE_DEFLATE, |
73 | 73 |
TIFF_PACKBITS = 0x8005, |
74 |
- TIFF_DEFLATE = 0x80B2 |
|
74 |
+ TIFF_DEFLATE = 0x80B2 |
|
75 | 75 |
}; |
76 | 76 |
|
77 |
-enum TiffTypes{ |
|
77 |
+enum TiffTypes { |
|
78 | 78 |
TIFF_BYTE = 1, |
79 | 79 |
TIFF_STRING, |
80 | 80 |
TIFF_SHORT, |
... | ... |
@@ -25,20 +25,20 @@ |
25 | 25 |
* @author Bartlomiej Wolowiec |
26 | 26 |
*/ |
27 | 27 |
|
28 |
-#include "libavutil/log.h" |
|
29 |
-#include "libavutil/opt.h" |
|
30 |
-#include "libavutil/pixdesc.h" |
|
31 |
- |
|
32 |
-#include "avcodec.h" |
|
33 | 28 |
#include "config.h" |
34 | 29 |
#if CONFIG_ZLIB |
35 | 30 |
#include <zlib.h> |
36 | 31 |
#endif |
32 |
+ |
|
33 |
+#include "libavutil/log.h" |
|
34 |
+#include "libavutil/opt.h" |
|
35 |
+#include "libavutil/pixdesc.h" |
|
36 |
+#include "avcodec.h" |
|
37 | 37 |
#include "bytestream.h" |
38 |
-#include "tiff.h" |
|
39 |
-#include "rle.h" |
|
40 | 38 |
#include "lzw.h" |
41 | 39 |
#include "put_bits.h" |
40 |
+#include "rle.h" |
|
41 |
+#include "tiff.h" |
|
42 | 42 |
|
43 | 43 |
#define TIFF_MAX_ENTRY 32 |
44 | 44 |
|
... | ... |
@@ -48,35 +48,34 @@ static const uint8_t type_sizes2[6] = { |
48 | 48 |
}; |
49 | 49 |
|
50 | 50 |
typedef struct TiffEncoderContext { |
51 |
- AVClass *class; ///< for private options |
|
51 |
+ AVClass *class; ///< for private options |
|
52 | 52 |
AVCodecContext *avctx; |
53 | 53 |
AVFrame picture; |
54 | 54 |
|
55 |
- int width; ///< picture width |
|
56 |
- int height; ///< picture height |
|
57 |
- unsigned int bpp; ///< bits per pixel |
|
58 |
- int compr; ///< compression level |
|
59 |
- int bpp_tab_size; ///< bpp_tab size |
|
60 |
- int photometric_interpretation; ///< photometric interpretation |
|
61 |
- int strips; ///< number of strips |
|
62 |
- int rps; ///< row per strip |
|
63 |
- uint8_t entries[TIFF_MAX_ENTRY*12]; ///< entires in header |
|
64 |
- int num_entries; ///< number of entires |
|
65 |
- uint8_t **buf; ///< actual position in buffer |
|
66 |
- uint8_t *buf_start; ///< pointer to first byte in buffer |
|
67 |
- int buf_size; ///< buffer size |
|
68 |
- uint16_t subsampling[2]; ///< YUV subsampling factors |
|
69 |
- struct LZWEncodeState *lzws; ///< LZW Encode state |
|
55 |
+ int width; ///< picture width |
|
56 |
+ int height; ///< picture height |
|
57 |
+ unsigned int bpp; ///< bits per pixel |
|
58 |
+ int compr; ///< compression level |
|
59 |
+ int bpp_tab_size; ///< bpp_tab size |
|
60 |
+ int photometric_interpretation; ///< photometric interpretation |
|
61 |
+ int strips; ///< number of strips |
|
62 |
+ int rps; ///< row per strip |
|
63 |
+ uint8_t entries[TIFF_MAX_ENTRY * 12]; ///< entries in header |
|
64 |
+ int num_entries; ///< number of entries |
|
65 |
+ uint8_t **buf; ///< actual position in buffer |
|
66 |
+ uint8_t *buf_start; ///< pointer to first byte in buffer |
|
67 |
+ int buf_size; ///< buffer size |
|
68 |
+ uint16_t subsampling[2]; ///< YUV subsampling factors |
|
69 |
+ struct LZWEncodeState *lzws; ///< LZW encode state |
|
70 | 70 |
} TiffEncoderContext; |
71 | 71 |
|
72 |
- |
|
73 | 72 |
/** |
74 | 73 |
* Check free space in buffer |
75 | 74 |
* @param s Tiff context |
76 | 75 |
* @param need Needed bytes |
77 | 76 |
* @return 0 - ok, 1 - no free space |
78 | 77 |
*/ |
79 |
-static inline int check_size(TiffEncoderContext * s, uint64_t need) |
|
78 |
+static inline int check_size(TiffEncoderContext *s, uint64_t need) |
|
80 | 79 |
{ |
81 | 80 |
if (s->buf_size < *s->buf - s->buf_start + need) { |
82 | 81 |
*s->buf = s->buf_start + s->buf_size + 1; |
... | ... |
@@ -95,12 +94,12 @@ static inline int check_size(TiffEncoderContext * s, uint64_t need) |
95 | 95 |
* @param type Type of values |
96 | 96 |
* @param flip =0 - normal copy, >0 - flip |
97 | 97 |
*/ |
98 |
-static void tnput(uint8_t ** p, int n, const uint8_t * val, enum TiffTypes type, |
|
98 |
+static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, |
|
99 | 99 |
int flip) |
100 | 100 |
{ |
101 | 101 |
int i; |
102 | 102 |
#if HAVE_BIGENDIAN |
103 |
- flip ^= ((int[]) {0, 0, 0, 1, 3, 3})[type]; |
|
103 |
+ flip ^= ((int[]) { 0, 0, 0, 1, 3, 3 })[type]; |
|
104 | 104 |
#endif |
105 | 105 |
for (i = 0; i < n * type_sizes2[type]; i++) |
106 | 106 |
*(*p)++ = val[i ^ flip]; |
... | ... |
@@ -114,9 +113,8 @@ static void tnput(uint8_t ** p, int n, const uint8_t * val, enum TiffTypes type, |
114 | 114 |
* @param count The number of values |
115 | 115 |
* @param ptr_val Pointer to values |
116 | 116 |
*/ |
117 |
-static void add_entry(TiffEncoderContext * s, |
|
118 |
- enum TiffTags tag, enum TiffTypes type, int count, |
|
119 |
- const void *ptr_val) |
|
117 |
+static void add_entry(TiffEncoderContext *s, enum TiffTags tag, |
|
118 |
+ enum TiffTypes type, int count, const void *ptr_val) |
|
120 | 119 |
{ |
121 | 120 |
uint8_t *entries_ptr = s->entries + 12 * s->num_entries; |
122 | 121 |
|
... | ... |
@@ -137,10 +135,11 @@ static void add_entry(TiffEncoderContext * s, |
137 | 137 |
s->num_entries++; |
138 | 138 |
} |
139 | 139 |
|
140 |
-static void add_entry1(TiffEncoderContext * s, |
|
141 |
- enum TiffTags tag, enum TiffTypes type, int val){ |
|
142 |
- uint16_t w = val; |
|
143 |
- uint32_t dw= val; |
|
140 |
+static void add_entry1(TiffEncoderContext *s, |
|
141 |
+ enum TiffTags tag, enum TiffTypes type, int val) |
|
142 |
+{ |
|
143 |
+ uint16_t w = val; |
|
144 |
+ uint32_t dw = val; |
|
144 | 145 |
add_entry(s, tag, type, 1, type == TIFF_SHORT ? (void *)&w : (void *)&dw); |
145 | 146 |
} |
146 | 147 |
|
... | ... |
@@ -154,22 +153,21 @@ static void add_entry1(TiffEncoderContext * s, |
154 | 154 |
* @param compr Compression method |
155 | 155 |
* @return Number of output bytes. If an output error is encountered, -1 returned |
156 | 156 |
*/ |
157 |
-static int encode_strip(TiffEncoderContext * s, const int8_t * src, |
|
158 |
- uint8_t * dst, int n, int compr) |
|
157 |
+static int encode_strip(TiffEncoderContext *s, const int8_t *src, |
|
158 |
+ uint8_t *dst, int n, int compr) |
|
159 | 159 |
{ |
160 |
- |
|
161 | 160 |
switch (compr) { |
162 | 161 |
#if CONFIG_ZLIB |
163 | 162 |
case TIFF_DEFLATE: |
164 | 163 |
case TIFF_ADOBE_DEFLATE: |
165 |
- { |
|
166 |
- unsigned long zlen = s->buf_size - (*s->buf - s->buf_start); |
|
167 |
- if (compress(dst, &zlen, src, n) != Z_OK) { |
|
168 |
- av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n"); |
|
169 |
- return -1; |
|
170 |
- } |
|
171 |
- return zlen; |
|
164 |
+ { |
|
165 |
+ unsigned long zlen = s->buf_size - (*s->buf - s->buf_start); |
|
166 |
+ if (compress(dst, &zlen, src, n) != Z_OK) { |
|
167 |
+ av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n"); |
|
168 |
+ return -1; |
|
172 | 169 |
} |
170 |
+ return zlen; |
|
171 |
+ } |
|
173 | 172 |
#endif |
174 | 173 |
case TIFF_RAW: |
175 | 174 |
if (check_size(s, n)) |
... | ... |
@@ -177,7 +175,8 @@ static int encode_strip(TiffEncoderContext * s, const int8_t * src, |
177 | 177 |
memcpy(dst, src, n); |
178 | 178 |
return n; |
179 | 179 |
case TIFF_PACKBITS: |
180 |
- return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), src, 1, n, 2, 0xff, -1, 0); |
|
180 |
+ return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), |
|
181 |
+ src, 1, n, 2, 0xff, -1, 0); |
|
181 | 182 |
case TIFF_LZW: |
182 | 183 |
return ff_lzw_encode(s->lzws, src, n); |
183 | 184 |
default: |
... | ... |
@@ -185,14 +184,14 @@ static int encode_strip(TiffEncoderContext * s, const int8_t * src, |
185 | 185 |
} |
186 | 186 |
} |
187 | 187 |
|
188 |
-static void pack_yuv(TiffEncoderContext * s, uint8_t * dst, int lnum) |
|
188 |
+static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum) |
|
189 | 189 |
{ |
190 | 190 |
AVFrame *p = &s->picture; |
191 | 191 |
int i, j, k; |
192 |
- int w = (s->width - 1) / s->subsampling[0] + 1; |
|
192 |
+ int w = (s->width - 1) / s->subsampling[0] + 1; |
|
193 | 193 |
uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; |
194 | 194 |
uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]]; |
195 |
- for (i = 0; i < w; i++){ |
|
195 |
+ for (i = 0; i < w; i++) { |
|
196 | 196 |
for (j = 0; j < s->subsampling[1]; j++) |
197 | 197 |
for (k = 0; k < s->subsampling[0]; k++) |
198 | 198 |
*dst++ = p->data[0][(lnum + j) * p->linesize[0] + |
... | ... |
@@ -202,7 +201,7 @@ static void pack_yuv(TiffEncoderContext * s, uint8_t * dst, int lnum) |
202 | 202 |
} |
203 | 203 |
} |
204 | 204 |
|
205 |
-static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
|
205 |
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
|
206 | 206 |
const AVFrame *pict, int *got_packet) |
207 | 207 |
{ |
208 | 208 |
TiffEncoderContext *s = avctx->priv_data; |
... | ... |
@@ -211,26 +210,26 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
211 | 211 |
uint8_t *ptr; |
212 | 212 |
uint8_t *offset; |
213 | 213 |
uint32_t strips; |
214 |
- uint32_t *strip_sizes = NULL; |
|
214 |
+ uint32_t *strip_sizes = NULL; |
|
215 | 215 |
uint32_t *strip_offsets = NULL; |
216 | 216 |
int bytes_per_row; |
217 |
- uint32_t res[2] = { 72, 1 }; // image resolution (72/1) |
|
217 |
+ uint32_t res[2] = { 72, 1 }; // image resolution (72/1) |
|
218 | 218 |
uint16_t bpp_tab[] = { 8, 8, 8, 8 }; |
219 | 219 |
int ret; |
220 | 220 |
int is_yuv = 0; |
221 | 221 |
uint8_t *yuv_line = NULL; |
222 | 222 |
int shift_h, shift_v; |
223 |
- const AVPixFmtDescriptor* pfd; |
|
223 |
+ const AVPixFmtDescriptor *pfd; |
|
224 | 224 |
|
225 | 225 |
s->avctx = avctx; |
226 | 226 |
|
227 |
- *p = *pict; |
|
228 |
- p->pict_type = AV_PICTURE_TYPE_I; |
|
229 |
- p->key_frame = 1; |
|
230 |
- avctx->coded_frame= &s->picture; |
|
227 |
+ *p = *pict; |
|
228 |
+ p->pict_type = AV_PICTURE_TYPE_I; |
|
229 |
+ p->key_frame = 1; |
|
230 |
+ avctx->coded_frame = &s->picture; |
|
231 | 231 |
|
232 |
- s->width = avctx->width; |
|
233 |
- s->height = avctx->height; |
|
232 |
+ s->width = avctx->width; |
|
233 |
+ s->height = avctx->height; |
|
234 | 234 |
s->subsampling[0] = 1; |
235 | 235 |
s->subsampling[1] = 1; |
236 | 236 |
|
... | ... |
@@ -240,43 +239,40 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
240 | 240 |
case AV_PIX_FMT_RGB24: |
241 | 241 |
case AV_PIX_FMT_GRAY8: |
242 | 242 |
case AV_PIX_FMT_PAL8: |
243 |
- pfd = av_pix_fmt_desc_get(avctx->pix_fmt); |
|
243 |
+ pfd = av_pix_fmt_desc_get(avctx->pix_fmt); |
|
244 | 244 |
s->bpp = av_get_bits_per_pixel(pfd); |
245 |
- if (pfd->flags & AV_PIX_FMT_FLAG_PAL) { |
|
245 |
+ if (pfd->flags & AV_PIX_FMT_FLAG_PAL) |
|
246 | 246 |
s->photometric_interpretation = 3; |
247 |
- } else if (pfd->flags & AV_PIX_FMT_FLAG_RGB) { |
|
247 |
+ else if (pfd->flags & AV_PIX_FMT_FLAG_RGB) |
|
248 | 248 |
s->photometric_interpretation = 2; |
249 |
- } else { |
|
249 |
+ else |
|
250 | 250 |
s->photometric_interpretation = 1; |
251 |
- } |
|
252 | 251 |
s->bpp_tab_size = pfd->nb_components; |
253 |
- for (i = 0; i < s->bpp_tab_size; i++) { |
|
252 |
+ for (i = 0; i < s->bpp_tab_size; i++) |
|
254 | 253 |
bpp_tab[i] = s->bpp / s->bpp_tab_size; |
255 |
- } |
|
256 | 254 |
break; |
257 | 255 |
case AV_PIX_FMT_MONOBLACK: |
258 |
- s->bpp = 1; |
|
256 |
+ s->bpp = 1; |
|
259 | 257 |
s->photometric_interpretation = 1; |
260 |
- s->bpp_tab_size = 0; |
|
258 |
+ s->bpp_tab_size = 0; |
|
261 | 259 |
break; |
262 | 260 |
case AV_PIX_FMT_MONOWHITE: |
263 |
- s->bpp = 1; |
|
261 |
+ s->bpp = 1; |
|
264 | 262 |
s->photometric_interpretation = 0; |
265 |
- s->bpp_tab_size = 0; |
|
263 |
+ s->bpp_tab_size = 0; |
|
266 | 264 |
break; |
267 | 265 |
case AV_PIX_FMT_YUV420P: |
268 | 266 |
case AV_PIX_FMT_YUV422P: |
269 | 267 |
case AV_PIX_FMT_YUV444P: |
270 | 268 |
case AV_PIX_FMT_YUV410P: |
271 | 269 |
case AV_PIX_FMT_YUV411P: |
270 |
+ av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v); |
|
272 | 271 |
s->photometric_interpretation = 6; |
273 |
- av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, |
|
274 |
- &shift_h, &shift_v); |
|
275 |
- s->bpp = 8 + (16 >> (shift_h + shift_v)); |
|
276 |
- s->subsampling[0] = 1 << shift_h; |
|
277 |
- s->subsampling[1] = 1 << shift_v; |
|
278 |
- s->bpp_tab_size = 3; |
|
279 |
- is_yuv = 1; |
|
272 |
+ s->bpp = 8 + (16 >> (shift_h + shift_v)); |
|
273 |
+ s->subsampling[0] = 1 << shift_h; |
|
274 |
+ s->subsampling[1] = 1 << shift_v; |
|
275 |
+ s->bpp_tab_size = 3; |
|
276 |
+ is_yuv = 1; |
|
280 | 277 |
break; |
281 | 278 |
default: |
282 | 279 |
av_log(s->avctx, AV_LOG_ERROR, |
... | ... |
@@ -284,18 +280,23 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
284 | 284 |
return -1; |
285 | 285 |
} |
286 | 286 |
|
287 |
- if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) |
|
288 |
- //best choose for DEFLATE |
|
287 |
+ if (s->compr == TIFF_DEFLATE || |
|
288 |
+ s->compr == TIFF_ADOBE_DEFLATE || |
|
289 |
+ s->compr == TIFF_LZW) |
|
290 |
+ // best choice for DEFLATE |
|
289 | 291 |
s->rps = s->height; |
290 | 292 |
else |
291 |
- s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); // suggest size of strip |
|
292 |
- s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // round rps up |
|
293 |
+ // suggest size of strip |
|
294 |
+ s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); |
|
295 |
+ // round rps up |
|
296 |
+ s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; |
|
293 | 297 |
|
294 | 298 |
strips = (s->height - 1) / s->rps + 1; |
295 | 299 |
|
296 | 300 |
if (!pkt->data && |
297 |
- (ret = av_new_packet(pkt, avctx->width * avctx->height * s->bpp * 2 + |
|
298 |
- avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0) { |
|
301 |
+ (ret = av_new_packet(pkt, |
|
302 |
+ avctx->width * avctx->height * s->bpp * 2 + |
|
303 |
+ avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0) { |
|
299 | 304 |
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); |
300 | 305 |
return ret; |
301 | 306 |
} |
... | ... |
@@ -314,18 +315,18 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
314 | 314 |
offset = ptr; |
315 | 315 |
bytestream_put_le32(&ptr, 0); |
316 | 316 |
|
317 |
- strip_sizes = av_mallocz(sizeof(*strip_sizes) * strips); |
|
317 |
+ strip_sizes = av_mallocz(sizeof(*strip_sizes) * strips); |
|
318 | 318 |
strip_offsets = av_mallocz(sizeof(*strip_offsets) * strips); |
319 | 319 |
if (!strip_sizes || !strip_offsets) { |
320 | 320 |
ret = AVERROR(ENOMEM); |
321 | 321 |
goto fail; |
322 | 322 |
} |
323 | 323 |
|
324 |
- bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp |
|
325 |
- * s->subsampling[0] * s->subsampling[1] + 7) >> 3; |
|
326 |
- if (is_yuv){ |
|
324 |
+ bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp * |
|
325 |
+ s->subsampling[0] * s->subsampling[1] + 7) >> 3; |
|
326 |
+ if (is_yuv) { |
|
327 | 327 |
yuv_line = av_malloc(bytes_per_row); |
328 |
- if (yuv_line == NULL){ |
|
328 |
+ if (yuv_line == NULL) { |
|
329 | 329 |
av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n"); |
330 | 330 |
ret = AVERROR(ENOMEM); |
331 | 331 |
goto fail; |
... | ... |
@@ -345,14 +346,13 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
345 | 345 |
goto fail; |
346 | 346 |
} |
347 | 347 |
strip_offsets[0] = ptr - pkt->data; |
348 |
- zn = 0; |
|
348 |
+ zn = 0; |
|
349 | 349 |
for (j = 0; j < s->rps; j++) { |
350 |
- if (is_yuv){ |
|
350 |
+ if (is_yuv) { |
|
351 | 351 |
pack_yuv(s, yuv_line, j); |
352 | 352 |
memcpy(zbuf + zn, yuv_line, bytes_per_row); |
353 | 353 |
j += s->subsampling[1] - 1; |
354 |
- } |
|
355 |
- else |
|
354 |
+ } else |
|
356 | 355 |
memcpy(zbuf + j * bytes_per_row, |
357 | 356 |
p->data[0] + j * p->linesize[0], bytes_per_row); |
358 | 357 |
zn += bytes_per_row; |
... | ... |
@@ -363,93 +363,93 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, |
363 | 363 |
av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); |
364 | 364 |
goto fail; |
365 | 365 |
} |
366 |
- ptr += ret; |
|
366 |
+ ptr += ret; |
|
367 | 367 |
strip_sizes[0] = ptr - pkt->data - strip_offsets[0]; |
368 | 368 |
} else |
369 | 369 |
#endif |
370 |
- { |
|
371 |
- if (s->compr == TIFF_LZW) { |
|
372 |
- s->lzws = av_malloc(ff_lzw_encode_state_size); |
|
373 |
- if (!s->lzws) { |
|
374 |
- ret = AVERROR(ENOMEM); |
|
375 |
- goto fail; |
|
376 |
- } |
|
370 |
+ if (s->compr == TIFF_LZW) { |
|
371 |
+ s->lzws = av_malloc(ff_lzw_encode_state_size); |
|
372 |
+ if (!s->lzws) { |
|
373 |
+ ret = AVERROR(ENOMEM); |
|
374 |
+ goto fail; |
|
377 | 375 |
} |
378 |
- for (i = 0; i < s->height; i++) { |
|
379 |
- if (strip_sizes[i / s->rps] == 0) { |
|
380 |
- if(s->compr == TIFF_LZW){ |
|
381 |
- ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), |
|
382 |
- 12, FF_LZW_TIFF, put_bits); |
|
383 |
- } |
|
384 |
- strip_offsets[i / s->rps] = ptr - pkt->data; |
|
385 |
- } |
|
386 |
- if (is_yuv){ |
|
387 |
- pack_yuv(s, yuv_line, i); |
|
388 |
- ret = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); |
|
389 |
- i += s->subsampling[1] - 1; |
|
390 |
- } |
|
391 |
- else |
|
392 |
- ret = encode_strip(s, p->data[0] + i * p->linesize[0], |
|
393 |
- ptr, bytes_per_row, s->compr); |
|
394 |
- if (ret < 0) { |
|
395 |
- av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); |
|
396 |
- goto fail; |
|
397 |
- } |
|
398 |
- strip_sizes[i / s->rps] += ret; |
|
399 |
- ptr += ret; |
|
400 |
- if(s->compr == TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){ |
|
401 |
- ret = ff_lzw_encode_flush(s->lzws, flush_put_bits); |
|
402 |
- strip_sizes[(i / s->rps )] += ret ; |
|
403 |
- ptr += ret; |
|
376 |
+ } |
|
377 |
+ for (i = 0; i < s->height; i++) { |
|
378 |
+ if (strip_sizes[i / s->rps] == 0) { |
|
379 |
+ if (s->compr == TIFF_LZW) { |
|
380 |
+ ff_lzw_encode_init(s->lzws, ptr, |
|
381 |
+ s->buf_size - (*s->buf - s->buf_start), |
|
382 |
+ 12, FF_LZW_TIFF, put_bits); |
|
404 | 383 |
} |
384 |
+ strip_offsets[i / s->rps] = ptr - pkt->data; |
|
385 |
+ } |
|
386 |
+ if (is_yuv) { |
|
387 |
+ pack_yuv(s, yuv_line, i); |
|
388 |
+ ret = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); |
|
389 |
+ i += s->subsampling[1] - 1; |
|
390 |
+ } else |
|
391 |
+ ret = encode_strip(s, p->data[0] + i * p->linesize[0], |
|
392 |
+ ptr, bytes_per_row, s->compr); |
|
393 |
+ if (ret < 0) { |
|
394 |
+ av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); |
|
395 |
+ goto fail; |
|
396 |
+ } |
|
397 |
+ strip_sizes[i / s->rps] += ret; |
|
398 |
+ ptr += ret; |
|
399 |
+ if (s->compr == TIFF_LZW && |
|
400 |
+ (i == s->height - 1 || i % s->rps == s->rps - 1)) { |
|
401 |
+ ret = ff_lzw_encode_flush(s->lzws, flush_put_bits); |
|
402 |
+ strip_sizes[(i / s->rps)] += ret; |
|
403 |
+ ptr += ret; |
|
405 | 404 |
} |
406 |
- if(s->compr == TIFF_LZW) |
|
407 |
- av_free(s->lzws); |
|
408 | 405 |
} |
406 |
+ if (s->compr == TIFF_LZW) |
|
407 |
+ av_free(s->lzws); |
|
409 | 408 |
|
410 | 409 |
s->num_entries = 0; |
411 | 410 |
|
412 |
- add_entry1(s,TIFF_SUBFILE, TIFF_LONG, 0); |
|
413 |
- add_entry1(s,TIFF_WIDTH, TIFF_LONG, s->width); |
|
414 |
- add_entry1(s,TIFF_HEIGHT, TIFF_LONG, s->height); |
|
411 |
+ add_entry1(s, TIFF_SUBFILE, TIFF_LONG, 0); |
|
412 |
+ add_entry1(s, TIFF_WIDTH, TIFF_LONG, s->width); |
|
413 |
+ add_entry1(s, TIFF_HEIGHT, TIFF_LONG, s->height); |
|
415 | 414 |
|
416 | 415 |
if (s->bpp_tab_size) |
417 |
- add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab); |
|
416 |
+ add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab); |
|
418 | 417 |
|
419 |
- add_entry1(s,TIFF_COMPR, TIFF_SHORT, s->compr); |
|
420 |
- add_entry1(s,TIFF_INVERT, TIFF_SHORT, s->photometric_interpretation); |
|
421 |
- add_entry(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, strip_offsets); |
|
418 |
+ add_entry1(s, TIFF_COMPR, TIFF_SHORT, s->compr); |
|
419 |
+ add_entry1(s, TIFF_INVERT, TIFF_SHORT, s->photometric_interpretation); |
|
420 |
+ add_entry(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, strip_offsets); |
|
422 | 421 |
|
423 | 422 |
if (s->bpp_tab_size) |
424 |
- add_entry1(s,TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size); |
|
423 |
+ add_entry1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size); |
|
425 | 424 |
|
426 |
- add_entry1(s,TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps); |
|
427 |
- add_entry(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, strip_sizes); |
|
428 |
- add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res); |
|
429 |
- add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res); |
|
430 |
- add_entry1(s,TIFF_RES_UNIT, TIFF_SHORT, 2); |
|
425 |
+ add_entry1(s, TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps); |
|
426 |
+ add_entry(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, strip_sizes); |
|
427 |
+ add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res); |
|
428 |
+ add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res); |
|
429 |
+ add_entry1(s, TIFF_RES_UNIT, TIFF_SHORT, 2); |
|
431 | 430 |
|
432 |
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)) |
|
433 |
- add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING, |
|
434 |
- strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT); |
|
431 |
+ if (!(avctx->flags & CODEC_FLAG_BITEXACT)) |
|
432 |
+ add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING, |
|
433 |
+ strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT); |
|
435 | 434 |
|
436 | 435 |
if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { |
437 | 436 |
uint16_t pal[256 * 3]; |
438 | 437 |
for (i = 0; i < 256; i++) { |
439 | 438 |
uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4); |
440 | 439 |
pal[i] = ((rgb >> 16) & 0xff) * 257; |
441 |
- pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257; |
|
442 |
- pal[i + 512] = ( rgb & 0xff) * 257; |
|
440 |
+ pal[i + 256] = ((rgb >> 8) & 0xff) * 257; |
|
441 |
+ pal[i + 512] = (rgb & 0xff) * 257; |
|
443 | 442 |
} |
444 | 443 |
add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal); |
445 | 444 |
} |
446 |
- if (is_yuv){ |
|
445 |
+ if (is_yuv) { |
|
447 | 446 |
/** according to CCIR Recommendation 601.1 */ |
448 |
- uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1}; |
|
447 |
+ uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 }; |
|
449 | 448 |
add_entry(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling); |
450 | 449 |
add_entry(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw); |
451 | 450 |
} |
452 |
- bytestream_put_le32(&offset, ptr - pkt->data); // write offset to dir |
|
451 |
+ // write offset to dir |
|
452 |
+ bytestream_put_le32(&offset, ptr - pkt->data); |
|
453 | 453 |
|
454 | 454 |
if (check_size(s, 6 + s->num_entries * 12)) { |
455 | 455 |
ret = AVERROR(EINVAL); |
... | ... |
@@ -473,12 +473,12 @@ fail: |
473 | 473 |
#define OFFSET(x) offsetof(TiffEncoderContext, x) |
474 | 474 |
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
475 | 475 |
static const AVOption options[] = { |
476 |
- { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, {.i64 = TIFF_PACKBITS}, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" }, |
|
477 |
- { "packbits", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_PACKBITS}, 0, 0, VE, "compression_algo" }, |
|
478 |
- { "raw", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_RAW}, 0, 0, VE, "compression_algo" }, |
|
479 |
- { "lzw", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_LZW}, 0, 0, VE, "compression_algo" }, |
|
476 |
+ { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" }, |
|
477 |
+ { "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, "compression_algo" }, |
|
478 |
+ { "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, "compression_algo" }, |
|
479 |
+ { "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, "compression_algo" }, |
|
480 | 480 |
#if CONFIG_ZLIB |
481 |
- { "deflate", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_DEFLATE}, 0, 0, VE, "compression_algo" }, |
|
481 |
+ { "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, "compression_algo" }, |
|
482 | 482 |
#endif |
483 | 483 |
{ NULL }, |
484 | 484 |
}; |
... | ... |
@@ -492,6 +492,7 @@ static const AVClass tiffenc_class = { |
492 | 492 |
|
493 | 493 |
AVCodec ff_tiff_encoder = { |
494 | 494 |
.name = "tiff", |
495 |
+ .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
|
495 | 496 |
.type = AVMEDIA_TYPE_VIDEO, |
496 | 497 |
.id = AV_CODEC_ID_TIFF, |
497 | 498 |
.priv_data_size = sizeof(TiffEncoderContext), |
... | ... |
@@ -504,6 +505,5 @@ AVCodec ff_tiff_encoder = { |
504 | 504 |
AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, |
505 | 505 |
AV_PIX_FMT_NONE |
506 | 506 |
}, |
507 |
- .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
|
508 | 507 |
.priv_class = &tiffenc_class, |
509 | 508 |
}; |