tif_codec.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 1988-1997 Sam Leffler
  3. * Copyright (c) 1991-1997 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the names of
  9. * Sam Leffler and Silicon Graphics may not be used in any advertising or
  10. * publicity relating to the software without the specific, prior written
  11. * permission of Sam Leffler and Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. /*
  25. * TIFF Library
  26. *
  27. * Builtin Compression Scheme Configuration Support.
  28. */
  29. #include "tiffiop.h"
  30. static int NotConfigured(TIFF *, int);
  31. #ifndef LZW_SUPPORT
  32. #define TIFFInitLZW NotConfigured
  33. #endif
  34. #ifndef PACKBITS_SUPPORT
  35. #define TIFFInitPackBits NotConfigured
  36. #endif
  37. #ifndef THUNDER_SUPPORT
  38. #define TIFFInitThunderScan NotConfigured
  39. #endif
  40. #ifndef NEXT_SUPPORT
  41. #define TIFFInitNeXT NotConfigured
  42. #endif
  43. #ifndef JPEG_SUPPORT
  44. #define TIFFInitJPEG NotConfigured
  45. #endif
  46. #ifndef OJPEG_SUPPORT
  47. #define TIFFInitOJPEG NotConfigured
  48. #endif
  49. #ifndef CCITT_SUPPORT
  50. #define TIFFInitCCITTRLE NotConfigured
  51. #define TIFFInitCCITTRLEW NotConfigured
  52. #define TIFFInitCCITTFax3 NotConfigured
  53. #define TIFFInitCCITTFax4 NotConfigured
  54. #endif
  55. #ifndef JBIG_SUPPORT
  56. #define TIFFInitJBIG NotConfigured
  57. #endif
  58. #ifndef ZIP_SUPPORT
  59. #define TIFFInitZIP NotConfigured
  60. #endif
  61. #ifndef PIXARLOG_SUPPORT
  62. #define TIFFInitPixarLog NotConfigured
  63. #endif
  64. #ifndef LOGLUV_SUPPORT
  65. #define TIFFInitSGILog NotConfigured
  66. #endif
  67. #ifndef LERC_SUPPORT
  68. #define TIFFInitLERC NotConfigured
  69. #endif
  70. #ifndef LZMA_SUPPORT
  71. #define TIFFInitLZMA NotConfigured
  72. #endif
  73. #ifndef ZSTD_SUPPORT
  74. #define TIFFInitZSTD NotConfigured
  75. #endif
  76. #ifndef WEBP_SUPPORT
  77. #define TIFFInitWebP NotConfigured
  78. #endif
  79. /*
  80. * Compression schemes statically built into the library.
  81. */
  82. const TIFFCodec _TIFFBuiltinCODECS[] = {
  83. {"None", COMPRESSION_NONE, TIFFInitDumpMode},
  84. {"LZW", COMPRESSION_LZW, TIFFInitLZW},
  85. {"PackBits", COMPRESSION_PACKBITS, TIFFInitPackBits},
  86. {"ThunderScan", COMPRESSION_THUNDERSCAN, TIFFInitThunderScan},
  87. {"NeXT", COMPRESSION_NEXT, TIFFInitNeXT},
  88. {"JPEG", COMPRESSION_JPEG, TIFFInitJPEG},
  89. {"Old-style JPEG", COMPRESSION_OJPEG, TIFFInitOJPEG},
  90. {"CCITT RLE", COMPRESSION_CCITTRLE, TIFFInitCCITTRLE},
  91. {"CCITT RLE/W", COMPRESSION_CCITTRLEW, TIFFInitCCITTRLEW},
  92. {"CCITT Group 3", COMPRESSION_CCITTFAX3, TIFFInitCCITTFax3},
  93. {"CCITT Group 4", COMPRESSION_CCITTFAX4, TIFFInitCCITTFax4},
  94. {"ISO JBIG", COMPRESSION_JBIG, TIFFInitJBIG},
  95. {"Deflate", COMPRESSION_DEFLATE, TIFFInitZIP},
  96. {"AdobeDeflate", COMPRESSION_ADOBE_DEFLATE, TIFFInitZIP},
  97. {"PixarLog", COMPRESSION_PIXARLOG, TIFFInitPixarLog},
  98. {"SGILog", COMPRESSION_SGILOG, TIFFInitSGILog},
  99. {"SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog},
  100. {"LZMA", COMPRESSION_LZMA, TIFFInitLZMA},
  101. {"ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD},
  102. {"WEBP", COMPRESSION_WEBP, TIFFInitWebP},
  103. {"LERC", COMPRESSION_LERC, TIFFInitLERC},
  104. {NULL, 0, NULL}};
  105. static int _notConfigured(TIFF *tif)
  106. {
  107. const TIFFCodec *c = TIFFFindCODEC(tif->tif_dir.td_compression);
  108. char compression_code[20];
  109. snprintf(compression_code, sizeof(compression_code), "%" PRIu16,
  110. tif->tif_dir.td_compression);
  111. TIFFErrorExtR(tif, tif->tif_name,
  112. "%s compression support is not configured",
  113. c ? c->name : compression_code);
  114. return (0);
  115. }
  116. static int NotConfigured(TIFF *tif, int scheme)
  117. {
  118. (void)scheme;
  119. tif->tif_fixuptags = _notConfigured;
  120. tif->tif_decodestatus = FALSE;
  121. tif->tif_setupdecode = _notConfigured;
  122. tif->tif_encodestatus = FALSE;
  123. tif->tif_setupencode = _notConfigured;
  124. return (1);
  125. }
  126. /************************************************************************/
  127. /* TIFFIsCODECConfigured() */
  128. /************************************************************************/
  129. /**
  130. * Check whether we have working codec for the specific coding scheme.
  131. *
  132. * @return returns 1 if the codec is configured and working. Otherwise
  133. * 0 will be returned.
  134. */
  135. int TIFFIsCODECConfigured(uint16_t scheme)
  136. {
  137. const TIFFCodec *codec = TIFFFindCODEC(scheme);
  138. if (codec == NULL)
  139. {
  140. return 0;
  141. }
  142. if (codec->init == NULL)
  143. {
  144. return 0;
  145. }
  146. if (codec->init != NotConfigured)
  147. {
  148. return 1;
  149. }
  150. return 0;
  151. }