32
static int TIFFNoEncode(TIFF *tif, const char *method)
34
const TIFFCodec *c = TIFFFindCODEC(tif->tif_dir.td_compression);
38
TIFFErrorExtR(tif, tif->tif_name, "%s %s encoding is not implemented",
43
TIFFErrorExtR(tif, tif->tif_name,
44
"Compression scheme %" PRIu16
45
" %s encoding is not implemented",
46
tif->tif_dir.td_compression, method);
51
int _TIFFNoRowEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
56
return (TIFFNoEncode(tif, "scanline"));
59
int _TIFFNoStripEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
64
return (TIFFNoEncode(tif, "strip"));
67
int _TIFFNoTileEncode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
72
return (TIFFNoEncode(tif, "tile"));
75
static int TIFFNoDecode(TIFF *tif, const char *method)
77
const TIFFCodec *c = TIFFFindCODEC(tif->tif_dir.td_compression);
80
TIFFErrorExtR(tif, tif->tif_name, "%s %s decoding is not implemented",
83
TIFFErrorExtR(tif, tif->tif_name,
84
"Compression scheme %" PRIu16
85
" %s decoding is not implemented",
86
tif->tif_dir.td_compression, method);
90
static int _TIFFNoFixupTags(TIFF *tif)
96
int _TIFFNoRowDecode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
101
return (TIFFNoDecode(tif, "scanline"));
104
int _TIFFNoStripDecode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
109
return (TIFFNoDecode(tif, "strip"));
112
int _TIFFNoTileDecode(TIFF *tif, uint8_t *pp, tmsize_t cc, uint16_t s)
117
return (TIFFNoDecode(tif, "tile"));
120
int _TIFFNoSeek(TIFF *tif, uint32_t off)
123
TIFFErrorExtR(tif, tif->tif_name,
124
"Compression algorithm does not support random access");
128
int _TIFFNoPreCode(TIFF *tif, uint16_t s)
135
static int _TIFFtrue(TIFF *tif)
140
static void _TIFFvoid(TIFF *tif) { (void)tif; }
142
void _TIFFSetDefaultCompressionState(TIFF *tif)
144
tif->tif_fixuptags = _TIFFNoFixupTags;
145
tif->tif_decodestatus = TRUE;
146
tif->tif_setupdecode = _TIFFtrue;
147
tif->tif_predecode = _TIFFNoPreCode;
148
tif->tif_decoderow = _TIFFNoRowDecode;
149
tif->tif_decodestrip = _TIFFNoStripDecode;
150
tif->tif_decodetile = _TIFFNoTileDecode;
151
tif->tif_encodestatus = TRUE;
152
tif->tif_setupencode = _TIFFtrue;
153
tif->tif_preencode = _TIFFNoPreCode;
154
tif->tif_postencode = _TIFFtrue;
155
tif->tif_encoderow = _TIFFNoRowEncode;
156
tif->tif_encodestrip = _TIFFNoStripEncode;
157
tif->tif_encodetile = _TIFFNoTileEncode;
158
tif->tif_close = _TIFFvoid;
159
tif->tif_seek = _TIFFNoSeek;
160
tif->tif_cleanup = _TIFFvoid;
161
tif->tif_defstripsize = _TIFFDefaultStripSize;
162
tif->tif_deftilesize = _TIFFDefaultTileSize;
163
tif->tif_flags &= ~(TIFF_NOBITREV | TIFF_NOREADRAW);
166
int TIFFSetCompressionScheme(TIFF *tif, int scheme)
168
const TIFFCodec *c = TIFFFindCODEC((uint16_t)scheme);
170
_TIFFSetDefaultCompressionState(tif);
177
return (c ? (*c->init)(tif, scheme) : 1);
190
static codec_t *registeredCODECS = NULL;
192
const TIFFCodec *TIFFFindCODEC(uint16_t scheme)
197
for (cd = registeredCODECS; cd; cd = cd->next)
198
if (cd->info->scheme == scheme)
199
return ((const TIFFCodec *)cd->info);
200
for (c = _TIFFBuiltinCODECS; c->name; c++)
201
if (c->scheme == scheme)
203
return ((const TIFFCodec *)0);
206
TIFFCodec *TIFFRegisterCODEC(uint16_t scheme, const char *name,
209
codec_t *cd = (codec_t *)_TIFFmallocExt(
211
(tmsize_t)(sizeof(codec_t) + sizeof(TIFFCodec) + strlen(name) + 1));
215
cd->info = (TIFFCodec *)((uint8_t *)cd + sizeof(codec_t));
216
cd->info->name = (char *)((uint8_t *)cd->info + sizeof(TIFFCodec));
217
strcpy(cd->info->name, name);
218
cd->info->scheme = scheme;
219
cd->info->init = init;
220
cd->next = registeredCODECS;
221
registeredCODECS = cd;
225
TIFFErrorExt(0, "TIFFRegisterCODEC",
226
"No space to register compression scheme %s", name);
232
void TIFFUnRegisterCODEC(TIFFCodec *c)
237
for (pcd = ®isteredCODECS; (cd = *pcd) != NULL; pcd = &cd->next)
241
_TIFFfreeExt(NULL, cd);
244
TIFFErrorExt(0, "TIFFUnRegisterCODEC",
245
"Cannot remove compression scheme %s; not registered",
261
TIFFCodec *TIFFGetConfiguredCODECs()
266
TIFFCodec *codecs = NULL;
267
TIFFCodec *new_codecs;
269
for (cd = registeredCODECS; cd; cd = cd->next)
272
(TIFFCodec *)_TIFFreallocExt(NULL, codecs, i * sizeof(TIFFCodec));
275
_TIFFfreeExt(NULL, codecs);
279
_TIFFmemcpy(codecs + i - 1, cd->info, sizeof(TIFFCodec));
282
for (c = _TIFFBuiltinCODECS; c->name; c++)
284
if (TIFFIsCODECConfigured(c->scheme))
286
new_codecs = (TIFFCodec *)_TIFFreallocExt(NULL, codecs,
287
i * sizeof(TIFFCodec));
290
_TIFFfreeExt(NULL, codecs);
294
_TIFFmemcpy(codecs + i - 1, (const void *)c, sizeof(TIFFCodec));
300
(TIFFCodec *)_TIFFreallocExt(NULL, codecs, i * sizeof(TIFFCodec));
303
_TIFFfreeExt(NULL, codecs);
307
_TIFFmemset(codecs + i - 1, 0, sizeof(TIFFCodec));