FFmpeg
tiff_common.h
Go to the documentation of this file.
1 /*
2  * TIFF Common Routines
3  * Copyright (c) 2013 Thilo Borgmann <thilo.borgmann _at_ mail.de>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * TIFF Common Routines
25  * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
26  */
27 
28 #ifndef AVCODEC_TIFF_COMMON_H
29 #define AVCODEC_TIFF_COMMON_H
30 
31 #include <stdint.h>
32 #include "libavutil/dict.h"
33 #include "bytestream.h"
34 
35 /** data type identifiers for TIFF tags */
36 enum TiffTypes {
37  TIFF_BYTE = 1,
50 };
51 
52 /** sizes of various TIFF field types (string size = 100)*/
53 static const uint8_t type_sizes[14] = {
54  0, 1, 100, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
55 };
56 
57 static const uint16_t ifd_tags[] = {
58  0x8769, // EXIF IFD
59  0x8825, // GPS IFD
60  0xA005 // Interoperability IFD
61 };
62 
63 
64 /** Returns a value > 0 if the tag is a known IFD-tag.
65  * The return value is the array index + 1 within ifd_tags[].
66  */
67 int ff_tis_ifd(unsigned tag);
68 
69 /** Reads a short from the bytestream using given endianness. */
70 unsigned ff_tget_short(GetByteContext *gb, int le);
71 
72 /** Reads a long from the bytestream using given endianness. */
73 unsigned ff_tget_long(GetByteContext *gb, int le);
74 
75 /** Reads a double from the bytestream using given endianness. */
76 double ff_tget_double(GetByteContext *gb, int le);
77 
78 /** Reads a byte from the bytestream using given endianness. */
79 unsigned ff_tget(GetByteContext *gb, int type, int le);
80 
81 /** Adds count rationals converted to a string
82  * into the metadata dictionary.
83  */
84 int ff_tadd_rational_metadata(int count, const char *name, const char *sep,
85  GetByteContext *gb, int le, AVDictionary **metadata);
86 
87 /** Adds count longs converted to a string
88  * into the metadata dictionary.
89  */
90 int ff_tadd_long_metadata(int count, const char *name, const char *sep,
91  GetByteContext *gb, int le, AVDictionary **metadata);
92 
93 /** Adds count doubles converted to a string
94  * into the metadata dictionary.
95  */
96 int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
97  GetByteContext *gb, int le, AVDictionary **metadata);
98 
99 /** Adds count shorts converted to a string
100  * into the metadata dictionary.
101  */
102 int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
103  GetByteContext *gb, int le, int is_signed, AVDictionary **metadata);
104 
105 /** Adds count bytes converted to a string
106  * into the metadata dictionary.
107  */
108 int ff_tadd_bytes_metadata(int count, const char *name, const char *sep,
109  GetByteContext *gb, int le, int is_signed, AVDictionary **metadata);
110 
111 /** Adds a string of count characters
112  * into the metadata dictionary.
113  */
114 int ff_tadd_string_metadata(int count, const char *name,
115  GetByteContext *gb, int le, AVDictionary **metadata);
116 
117 /** Decodes a TIFF header from the input bytestream
118  * and sets the endianness in *le and the offset to
119  * the first IFD in *ifd_offset accordingly.
120  */
121 int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset);
122 
123 /** Reads the first 3 fields of a TIFF tag, which are
124  * the tag id, the tag type and the count of values for that tag.
125  * Afterwards the bytestream is located at the first value to read and
126  * *next holds the bytestream offset of the following tag.
127  */
128 int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type,
129  unsigned *count, int *next);
130 
131 #endif /* AVCODEC_TIFF_COMMON_H */
TiffTypes
TiffTypes
data type identifiers for TIFF tags
Definition: tiff_common.h:36
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
ff_tadd_bytes_metadata
int ff_tadd_bytes_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
Adds count bytes converted to a string into the metadata dictionary.
Definition: tiff_common.c:187
GetByteContext
Definition: bytestream.h:33
TIFF_LONG
@ TIFF_LONG
Definition: tiff_common.h:40
ff_tadd_string_metadata
int ff_tadd_string_metadata(int count, const char *name, GetByteContext *gb, int le, AVDictionary **metadata)
Adds a string of count characters into the metadata dictionary.
Definition: tiff_common.c:208
TIFF_SLONG
@ TIFF_SLONG
Definition: tiff_common.h:45
AVDictionary
Definition: dict.c:34
ff_tis_ifd
int ff_tis_ifd(unsigned tag)
Returns a value > 0 if the tag is a known IFD-tag.
Definition: tiff_common.c:32
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
TIFF_SBYTE
@ TIFF_SBYTE
Definition: tiff_common.h:42
TIFF_SHORT
@ TIFF_SHORT
Definition: tiff_common.h:39
ff_tget_short
unsigned ff_tget_short(GetByteContext *gb, int le)
Reads a short from the bytestream using given endianness.
Definition: tiff_common.c:44
ff_tadd_rational_metadata
int ff_tadd_rational_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata)
Adds count rationals converted to a string into the metadata dictionary.
Definition: tiff_common.c:99
TIFF_STRING
@ TIFF_STRING
Definition: tiff_common.h:38
TIFF_IFD
@ TIFF_IFD
Definition: tiff_common.h:49
ff_tdecode_header
int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset)
Decodes a TIFF header from the input bytestream and sets the endianness in *le and the offset to the ...
Definition: tiff_common.c:228
TIFF_FLOAT
@ TIFF_FLOAT
Definition: tiff_common.h:47
ff_tget_long
unsigned ff_tget_long(GetByteContext *gb, int le)
Reads a long from the bytestream using given endianness.
Definition: tiff_common.c:50
ff_tadd_long_metadata
int ff_tadd_long_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata)
Adds count longs converted to a string into the metadata dictionary.
Definition: tiff_common.c:123
ff_tadd_doubles_metadata
int ff_tadd_doubles_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata)
Adds count doubles converted to a string into the metadata dictionary.
Definition: tiff_common.c:144
TIFF_BYTE
@ TIFF_BYTE
Definition: tiff_common.h:37
TIFF_SRATIONAL
@ TIFF_SRATIONAL
Definition: tiff_common.h:46
TIFF_DOUBLE
@ TIFF_DOUBLE
Definition: tiff_common.h:48
ff_tadd_shorts_metadata
int ff_tadd_shorts_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
Adds count shorts converted to a string into the metadata dictionary.
Definition: tiff_common.c:165
ff_tread_tag
int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type, unsigned *count, int *next)
Reads the first 3 fields of a TIFF tag, which are the tag id, the tag type and the count of values fo...
Definition: tiff_common.c:253
TIFF_UNDEFINED
@ TIFF_UNDEFINED
Definition: tiff_common.h:43
ff_tget_double
double ff_tget_double(GetByteContext *gb, int le)
Reads a double from the bytestream using given endianness.
Definition: tiff_common.c:56
tag
uint32_t tag
Definition: movenc.c:1791
dict.h
TIFF_RATIONAL
@ TIFF_RATIONAL
Definition: tiff_common.h:41
TIFF_SSHORT
@ TIFF_SSHORT
Definition: tiff_common.h:44
ifd_tags
static const uint16_t ifd_tags[]
Definition: tiff_common.h:57
bytestream.h
ff_tget
unsigned ff_tget(GetByteContext *gb, int type, int le)
Reads a byte from the bytestream using given endianness.
Definition: tiff_common.c:63
type_sizes
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
Definition: tiff_common.h:53