tiff_common.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * @file
  23. * TIFF Common Routines
  24. * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
  25. */
  26. #ifndef AVCODEC_TIFF_COMMON_H
  27. #define AVCODEC_TIFF_COMMON_H
  28. #include "avcodec.h"
  29. #include "tiff.h"
  30. #include "bytestream.h"
  31. #include "libavutil/bprint.h"
  32. /** data type identifiers for TIFF tags */
  33. enum TiffTypes {
  34. TIFF_BYTE = 1,
  35. TIFF_STRING,
  36. TIFF_SHORT,
  37. TIFF_LONG,
  38. TIFF_RATIONAL,
  39. TIFF_SBYTE,
  40. TIFF_UNDEFINED,
  41. TIFF_SSHORT,
  42. TIFF_SLONG,
  43. TIFF_SRATIONAL,
  44. TIFF_FLOAT,
  45. TIFF_DOUBLE,
  46. TIFF_IFD
  47. };
  48. /** sizes of various TIFF field types (string size = 100)*/
  49. static const uint8_t type_sizes[14] = {
  50. 0, 1, 100, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
  51. };
  52. static const uint16_t ifd_tags[] = {
  53. 0x8769, // EXIF IFD
  54. 0x8825, // GPS IFD
  55. 0xA005 // Interoperability IFD
  56. };
  57. /** Returns a value > 0 if the tag is a known IFD-tag.
  58. * The return value is the array index + 1 within ifd_tags[].
  59. */
  60. int ff_tis_ifd(unsigned tag);
  61. /** Reads a short from the bytestream using given endianness. */
  62. unsigned ff_tget_short(GetByteContext *gb, int le);
  63. /** Reads a long from the bytestream using given endianness. */
  64. unsigned ff_tget_long(GetByteContext *gb, int le);
  65. /** Reads a double from the bytestream using given endianness. */
  66. double ff_tget_double(GetByteContext *gb, int le);
  67. /** Reads a byte from the bytestream using given endianness. */
  68. unsigned ff_tget(GetByteContext *gb, int type, int le);
  69. /** Returns an allocated string containing count
  70. * rational values using the given separator.
  71. */
  72. char *ff_trationals2str(int *rp, int count, const char *sep);
  73. /** Returns an allocated string containing count
  74. * long values using the given separator.
  75. */
  76. char *ff_tlongs2str(int32_t *lp, int count, const char *sep);
  77. /** Returns an allocated string containing count
  78. * double values using the given separator.
  79. */
  80. char *ff_tdoubles2str(double *dp, int count, const char *sep);
  81. /** Returns an allocated string containing count
  82. * short values using the given separator.
  83. */
  84. char *ff_tshorts2str(int16_t *sp, int count, const char *sep);
  85. /** Adds count rationals converted to a string
  86. * into the metadata dictionary.
  87. */
  88. int ff_tadd_rational_metadata(int count, const char *name, const char *sep,
  89. GetByteContext *gb, int le, AVDictionary **metadata);
  90. /** Adds count longs converted to a string
  91. * into the metadata dictionary.
  92. */
  93. int ff_tadd_long_metadata(int count, const char *name, const char *sep,
  94. GetByteContext *gb, int le, AVDictionary **metadata);
  95. /** Adds count doubles converted to a string
  96. * into the metadata dictionary.
  97. */
  98. int ff_tadd_doubles_metadata(int count, const char *name, const char *sep,
  99. GetByteContext *gb, int le, AVDictionary **metadata);
  100. /** Adds count shorts converted to a string
  101. * into the metadata dictionary.
  102. */
  103. int ff_tadd_shorts_metadata(int count, const char *name, const char *sep,
  104. GetByteContext *gb, int le, int is_signed, AVDictionary **metadata);
  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. /** Adds a string of count characters
  111. * into the metadata dictionary.
  112. */
  113. int ff_tadd_string_metadata(int count, const char *name,
  114. GetByteContext *gb, int le, AVDictionary **metadata);
  115. /** Decodes a TIFF header from the input bytestream
  116. * and sets the endianness in *le and the offset to
  117. * the first IFD in *ifd_offset accordingly.
  118. */
  119. int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset);
  120. /** Reads the first 3 fields of a TIFF tag, which are
  121. * the tag id, the tag type and the count of values for that tag.
  122. * Afterwards the bytestream is located at the first value to read and
  123. * *next holds the bytestream offset of the following tag.
  124. */
  125. int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type,
  126. unsigned *count, int *next);
  127. #endif /* AVCODEC_TIFF_COMMON_H */