Mercurial > libavcodec.hg
annotate tiffenc.c @ 12504:036603a63c51 libavcodec
ARM: disable movw/movt for relocated values on Apple platforms
Apparently Apple platforms do not handle movw/movt relocations
properly, leading to runtime crashes in code using them.
author | mru |
---|---|
date | Mon, 20 Sep 2010 21:50:46 +0000 |
parents | 7dd2a45249a9 |
children |
rev | line source |
---|---|
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
1 /* |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
2 * TIFF image encoder |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
3 * Copyright (c) 2007 Bartlomiej Wolowiec |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
4 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
5 * This file is part of FFmpeg. |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
6 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
11 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
16 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
20 */ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
21 |
4782
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 encoder |
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 Bartlomiej Wolowiec |
bca8924ed36c
Add some Doxygen comments, by Kamil Nowosad, k.nowosad students.mimuw.edu pl.
diego
parents:
4774
diff
changeset
|
26 */ |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
27 #include "avcodec.h" |
8590 | 28 #if CONFIG_ZLIB |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
29 #include <zlib.h> |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
30 #endif |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
31 #include "bytestream.h" |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
32 #include "tiff.h" |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
33 #include "rle.h" |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
34 #include "lzw.h" |
10634 | 35 #include "put_bits.h" |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
36 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
37 #define TIFF_MAX_ENTRY 32 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
38 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
39 /** sizes of various TIFF field types (string size = 1)*/ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
40 static const uint8_t type_sizes2[6] = { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
41 0, 1, 1, 2, 4, 8 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
42 }; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
43 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
44 typedef struct TiffEncoderContext { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
45 AVCodecContext *avctx; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
46 AVFrame picture; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
47 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
48 int width; ///< picture width |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
49 int height; ///< picture height |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
50 unsigned int bpp; ///< bits per pixel |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
51 int compr; ///< compression level |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
52 int bpp_tab_size; ///< bpp_tab size |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
53 int photometric_interpretation; ///< photometric interpretation |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
54 int strips; ///< number of strips |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
55 int rps; ///< row per strip |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
56 uint8_t entries[TIFF_MAX_ENTRY*12]; ///< entires in header |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
57 int num_entries; ///< number of entires |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
58 uint8_t **buf; ///< actual position in buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
59 uint8_t *buf_start; ///< pointer to first byte in buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
60 int buf_size; ///< buffer size |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
61 uint16_t subsampling[2]; ///< YUV subsampling factors |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
62 struct LZWEncodeState *lzws; ///< LZW Encode state |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
63 } TiffEncoderContext; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
64 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
65 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
66 /** |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
67 * Check free space in buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
68 * @param s Tiff context |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
69 * @param need Needed bytes |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
70 * @return 0 - ok, 1 - no free space |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
71 */ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
72 inline static int check_size(TiffEncoderContext * s, uint64_t need) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
73 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
74 if (s->buf_size < *s->buf - s->buf_start + need) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
75 *s->buf = s->buf_start + s->buf_size + 1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
76 av_log(s->avctx, AV_LOG_ERROR, "Buffer is too small\n"); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
77 return 1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
78 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
79 return 0; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
80 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
81 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
82 /** |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
83 * Put n values to buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
84 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
85 * @param p Pointer to pointer to output buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
86 * @param n Number of values |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
87 * @param val Pointer to values |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
88 * @param type Type of values |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
89 * @param flip =0 - normal copy, >0 - flip |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
90 */ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
91 static void tnput(uint8_t ** p, int n, const uint8_t * val, enum TiffTypes type, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
92 int flip) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
93 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
94 int i; |
9985 | 95 #if HAVE_BIGENDIAN |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
96 flip ^= ((int[]) {0, 0, 0, 1, 3, 3})[type]; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
97 #endif |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
98 for (i = 0; i < n * type_sizes2[type]; i++) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
99 *(*p)++ = val[i ^ flip]; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
100 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
101 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
102 /** |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
103 * Add entry to directory in tiff header. |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
104 * @param s Tiff context |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
105 * @param tag Tag that identifies the entry |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
106 * @param type Entry type |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
107 * @param count The number of values |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
108 * @param ptr_val Pointer to values |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
109 */ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
110 static void add_entry(TiffEncoderContext * s, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
111 enum TiffTags tag, enum TiffTypes type, int count, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
112 const void *ptr_val) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
113 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
114 uint8_t *entries_ptr = s->entries + 12 * s->num_entries; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
115 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
116 assert(s->num_entries < TIFF_MAX_ENTRY); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
117 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
118 bytestream_put_le16(&entries_ptr, tag); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
119 bytestream_put_le16(&entries_ptr, type); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
120 bytestream_put_le32(&entries_ptr, count); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
121 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
122 if (type_sizes[type] * count <= 4) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
123 tnput(&entries_ptr, count, ptr_val, type, 0); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
124 } else { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
125 bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
126 check_size(s, count * type_sizes2[type]); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
127 tnput(s->buf, count, ptr_val, type, 0); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
128 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
129 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
130 s->num_entries++; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
131 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
132 |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
133 static void add_entry1(TiffEncoderContext * s, |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
134 enum TiffTags tag, enum TiffTypes type, int val){ |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
135 uint16_t w = val; |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
136 uint32_t dw= val; |
6313 | 137 add_entry(s, tag, type, 1, type == TIFF_SHORT ? (void *)&w : (void *)&dw); |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
138 } |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
139 |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
140 /** |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
141 * Encode one strip in tiff file |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
142 * |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
143 * @param s Tiff context |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
144 * @param src Input buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
145 * @param dst Output buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
146 * @param n Size of input buffer |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
147 * @param compr Compression method |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
148 * @return Number of output bytes. If an output error is encountered, -1 returned |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
149 */ |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
150 static int encode_strip(TiffEncoderContext * s, const int8_t * src, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
151 uint8_t * dst, int n, int compr) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
152 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
153 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
154 switch (compr) { |
8590 | 155 #if CONFIG_ZLIB |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
156 case TIFF_DEFLATE: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
157 case TIFF_ADOBE_DEFLATE: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
158 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
159 unsigned long zlen = s->buf_size - (*s->buf - s->buf_start); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
160 if (compress(dst, &zlen, src, n) != Z_OK) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
161 av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n"); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
162 return -1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
163 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
164 return zlen; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
165 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
166 #endif |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
167 case TIFF_RAW: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
168 if (check_size(s, n)) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
169 return -1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
170 memcpy(dst, src, n); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
171 return n; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
172 case TIFF_PACKBITS: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
173 return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), src, 1, n, 2, 0xff, -1, 0); |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
174 case TIFF_LZW: |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
175 return ff_lzw_encode(s->lzws, src, n); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
176 default: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
177 return -1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
178 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
179 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
180 |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
181 static void pack_yuv(TiffEncoderContext * s, uint8_t * dst, int lnum) |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
182 { |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
183 AVFrame *p = &s->picture; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
184 int i, j, k; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
185 int w = (s->width - 1) / s->subsampling[0] + 1; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
186 uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
187 uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]]; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
188 for (i = 0; i < w; i++){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
189 for (j = 0; j < s->subsampling[1]; j++) |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
190 for (k = 0; k < s->subsampling[0]; k++) |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
191 *dst++ = p->data[0][(lnum + j) * p->linesize[0] + |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
192 i * s->subsampling[0] + k]; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
193 *dst++ = *pu++; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
194 *dst++ = *pv++; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
195 } |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
196 } |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
197 |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
198 static int encode_frame(AVCodecContext * avctx, unsigned char *buf, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
199 int buf_size, void *data) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
200 { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
201 TiffEncoderContext *s = avctx->priv_data; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
202 AVFrame *pict = data; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
203 AVFrame *const p = (AVFrame *) & s->picture; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
204 int i; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
205 int n; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
206 uint8_t *ptr = buf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
207 uint8_t *offset; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
208 uint32_t strips; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
209 uint32_t *strip_sizes = NULL; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
210 uint32_t *strip_offsets = NULL; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
211 int bytes_per_row; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
212 uint32_t res[2] = { 72, 1 }; // image resolution (72/1) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
213 static const uint16_t bpp_tab[] = { 8, 8, 8, 8 }; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
214 int ret = -1; |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
215 int is_yuv = 0; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
216 uint8_t *yuv_line = NULL; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
217 int shift_h, shift_v; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
218 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
219 s->buf_start = buf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
220 s->buf = &ptr; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
221 s->buf_size = buf_size; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
222 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
223 *p = *pict; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
224 p->pict_type = FF_I_TYPE; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
225 p->key_frame = 1; |
6919 | 226 avctx->coded_frame= &s->picture; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
227 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
228 s->compr = TIFF_PACKBITS; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
229 if (avctx->compression_level == 0) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
230 s->compr = TIFF_RAW; |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
231 } else if(avctx->compression_level == 2) { |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
232 s->compr = TIFF_LZW; |
8590 | 233 #if CONFIG_ZLIB |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
234 } else if ((avctx->compression_level >= 3)) { |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
235 s->compr = TIFF_DEFLATE; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
236 #endif |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
237 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
238 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
239 s->width = avctx->width; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
240 s->height = avctx->height; |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
241 s->subsampling[0] = 1; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
242 s->subsampling[1] = 1; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
243 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
244 switch (avctx->pix_fmt) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
245 case PIX_FMT_RGB24: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
246 s->bpp = 24; |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
247 s->photometric_interpretation = 2; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
248 break; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
249 case PIX_FMT_GRAY8: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
250 s->bpp = 8; |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
251 s->photometric_interpretation = 1; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
252 break; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
253 case PIX_FMT_PAL8: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
254 s->bpp = 8; |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
255 s->photometric_interpretation = 3; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
256 break; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
257 case PIX_FMT_MONOBLACK: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
258 s->bpp = 1; |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
259 s->photometric_interpretation = 1; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
260 break; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
261 case PIX_FMT_MONOWHITE: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
262 s->bpp = 1; |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
263 s->photometric_interpretation = 0; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
264 break; |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
265 case PIX_FMT_YUV420P: |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
266 case PIX_FMT_YUV422P: |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
267 case PIX_FMT_YUV444P: |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
268 case PIX_FMT_YUV410P: |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
269 case PIX_FMT_YUV411P: |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
270 s->photometric_interpretation = 6; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
271 avcodec_get_chroma_sub_sample(avctx->pix_fmt, |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
272 &shift_h, &shift_v); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
273 s->bpp = 8 + (16 >> (shift_h + shift_v)); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
274 s->subsampling[0] = 1 << shift_h; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
275 s->subsampling[1] = 1 << shift_v; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
276 s->bpp_tab_size = 3; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
277 is_yuv = 1; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
278 break; |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
279 default: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
280 av_log(s->avctx, AV_LOG_ERROR, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
281 "This colors format is not supported\n"); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
282 return -1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
283 } |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
284 if (!is_yuv) |
4839 | 285 s->bpp_tab_size = (s->bpp >> 3); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
286 |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
287 if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
288 //best choose for DEFLATE |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
289 s->rps = s->height; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
290 else |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
291 s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); // suggest size of strip |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
292 s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // round rps up |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
293 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
294 strips = (s->height - 1) / s->rps + 1; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
295 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
296 if (check_size(s, 8)) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
297 goto fail; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
298 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
299 // write header |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
300 bytestream_put_le16(&ptr, 0x4949); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
301 bytestream_put_le16(&ptr, 42); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
302 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
303 offset = ptr; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
304 bytestream_put_le32(&ptr, 0); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
305 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
306 strip_sizes = av_mallocz(sizeof(*strip_sizes) * strips); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
307 strip_offsets = av_mallocz(sizeof(*strip_offsets) * strips); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
308 |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
309 bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
310 * s->subsampling[0] * s->subsampling[1] + 7) >> 3; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
311 if (is_yuv){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
312 yuv_line = av_malloc(bytes_per_row); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
313 if (yuv_line == NULL){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
314 av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n"); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
315 goto fail; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
316 } |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
317 } |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
318 |
8590 | 319 #if CONFIG_ZLIB |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
320 if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
321 uint8_t *zbuf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
322 int zlen, zn; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
323 int j; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
324 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
325 zlen = bytes_per_row * s->rps; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
326 zbuf = av_malloc(zlen); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
327 strip_offsets[0] = ptr - buf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
328 zn = 0; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
329 for (j = 0; j < s->rps; j++) { |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
330 if (is_yuv){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
331 pack_yuv(s, yuv_line, j); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
332 memcpy(zbuf + zn, yuv_line, bytes_per_row); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
333 j += s->subsampling[1] - 1; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
334 } |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
335 else |
4847 | 336 memcpy(zbuf + j * bytes_per_row, |
337 p->data[0] + j * p->linesize[0], bytes_per_row); | |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
338 zn += bytes_per_row; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
339 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
340 n = encode_strip(s, zbuf, ptr, zn, s->compr); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
341 av_free(zbuf); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
342 if (n<0) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
343 av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
344 goto fail; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
345 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
346 ptr += n; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
347 strip_sizes[0] = ptr - buf - strip_offsets[0]; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
348 } else |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
349 #endif |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
350 { |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
351 if(s->compr == TIFF_LZW) |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
352 s->lzws = av_malloc(ff_lzw_encode_state_size); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
353 for (i = 0; i < s->height; i++) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
354 if (strip_sizes[i / s->rps] == 0) { |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
355 if(s->compr == TIFF_LZW){ |
10634 | 356 ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), |
357 12, FF_LZW_TIFF, put_bits); | |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
358 } |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
359 strip_offsets[i / s->rps] = ptr - buf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
360 } |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
361 if (is_yuv){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
362 pack_yuv(s, yuv_line, i); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
363 n = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
364 i += s->subsampling[1] - 1; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
365 } |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
366 else |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
367 n = encode_strip(s, p->data[0] + i * p->linesize[0], |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
368 ptr, bytes_per_row, s->compr); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
369 if (n < 0) { |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
370 av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
371 goto fail; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
372 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
373 strip_sizes[i / s->rps] += n; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
374 ptr += n; |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
375 if(s->compr == TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){ |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
376 int ret; |
10634 | 377 ret = ff_lzw_encode_flush(s->lzws, flush_put_bits); |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
378 strip_sizes[(i / s->rps )] += ret ; |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
379 ptr += ret; |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
380 } |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
381 } |
4799
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
382 if(s->compr == TIFF_LZW) |
812f759a7c59
TIFF-LZW encoding support by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
4792
diff
changeset
|
383 av_free(s->lzws); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
384 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
385 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
386 s->num_entries = 0; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
387 |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
388 add_entry1(s,TIFF_SUBFILE, TIFF_LONG, 0); |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
389 add_entry1(s,TIFF_WIDTH, TIFF_LONG, s->width); |
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
390 add_entry1(s,TIFF_HEIGHT, TIFF_LONG, s->height); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
391 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
392 if (s->bpp_tab_size) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
393 add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
394 |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
395 add_entry1(s,TIFF_COMPR, TIFF_SHORT, s->compr); |
4791
caafad01dec0
s/invert/photometric_interpretation/ patch by Kamil Nowosad k.nowosad students mimuw edu pl
michael
parents:
4786
diff
changeset
|
396 add_entry1(s,TIFF_INVERT, TIFF_SHORT, s->photometric_interpretation); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
397 add_entry(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, strip_offsets); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
398 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
399 if (s->bpp_tab_size) |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
400 add_entry1(s,TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
401 |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
402 add_entry1(s,TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
403 add_entry(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, strip_sizes); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
404 add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
405 add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res); |
4786
95f58f0b70fc
remove compound literals gcc 2.95 doesnt support taking an address of a compound literal
michael
parents:
4782
diff
changeset
|
406 add_entry1(s,TIFF_RES_UNIT, TIFF_SHORT, 2); |
4850
9e471439d2e8
fix tiff regression test (bitexact flag was ignoredwhich caused the
michael
parents:
4847
diff
changeset
|
407 |
9e471439d2e8
fix tiff regression test (bitexact flag was ignoredwhich caused the
michael
parents:
4847
diff
changeset
|
408 if(!(avctx->flags & CODEC_FLAG_BITEXACT)) |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
409 add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
410 strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
411 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
412 if (avctx->pix_fmt == PIX_FMT_PAL8) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
413 uint16_t pal[256 * 3]; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
414 for (i = 0; i < 256; i++) { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
415 uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
416 pal[i] = ((rgb >> 16) & 0xff) * 257; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
417 pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
418 pal[i + 512] = ( rgb & 0xff) * 257; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
419 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
420 add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
421 } |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
422 if (is_yuv){ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
423 /** according to CCIR Recommendation 601.1 */ |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
424 uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1}; |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
425 add_entry(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
426 add_entry(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw); |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
427 } |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
428 bytestream_put_le32(&offset, ptr - buf); // write offset to dir |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
429 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
430 if (check_size(s, 6 + s->num_entries * 12)) |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
431 goto fail; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
432 bytestream_put_le16(&ptr, s->num_entries); // write tag count |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
433 bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
434 bytestream_put_le32(&ptr, 0); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
435 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
436 ret = ptr - buf; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
437 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
438 fail: |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
439 av_free(strip_sizes); |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
440 av_free(strip_offsets); |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
441 av_free(yuv_line); |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
442 return ret; |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
443 } |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
444 |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
445 AVCodec tiff_encoder = { |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
446 "tiff", |
11560
8a4984c5cacc
Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents:
10634
diff
changeset
|
447 AVMEDIA_TYPE_VIDEO, |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
448 CODEC_ID_TIFF, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
449 sizeof(TiffEncoderContext), |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
450 NULL, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
451 encode_frame, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
452 NULL, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
453 NULL, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
454 0, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
455 NULL, |
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
456 .pix_fmts = |
10146
38cfe222e1a4
Mark all pix_fmts and supported_framerates compound literals as const.
reimar
parents:
9985
diff
changeset
|
457 (const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8, |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
458 PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE, |
4792
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
459 PIX_FMT_YUV420P, PIX_FMT_YUV422P, |
d8b17a09a114
YUV support patch by (Kamil Nowosad k.nowosad students mimuw edu pl)
michael
parents:
4791
diff
changeset
|
460 PIX_FMT_YUV444P, PIX_FMT_YUV410P, |
6570 | 461 PIX_FMT_YUV411P, |
6788 | 462 PIX_FMT_NONE}, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6919
diff
changeset
|
463 .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), |
4774
0860efc2f02b
tiff encoder by (Bartlomiej Wolowiec b.wolowiec students mimuw edu pl)
michael
parents:
diff
changeset
|
464 }; |