Skip to content

Commit c474fb8

Browse files
committed
Merge branch 'read_only' into 'master'
Take into account PACKBITS_READ_ONLY, LZW_READ_ONLY, and LERC_READ_ONLY macros See merge request libtiff/libtiff!683
2 parents 1b9252f + 6885ac0 commit c474fb8

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

libtiff/tif_lerc.c

+31-23
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ typedef struct
9393
#define LERCDecoderState(tif) GetLERCState(tif)
9494
#define LERCEncoderState(tif) GetLERCState(tif)
9595

96-
static int LERCEncode(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s);
9796
static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s);
9897

9998
static int LERCFixupTags(TIFF *tif)
@@ -222,20 +221,20 @@ static int SetupBuffers(TIFF *tif, LERCState *sp, const char *module)
222221
{
223222
TIFFErrorExtR(tif, module, "Too large uncompressed strip/tile");
224223
_TIFFfreeExt(tif, sp->uncompressed_buffer);
225-
sp->uncompressed_buffer = 0;
224+
sp->uncompressed_buffer = NULL;
226225
sp->uncompressed_alloc = 0;
227226
return 0;
228227
}
229228

230229
if (sp->uncompressed_alloc < new_alloc)
231230
{
232231
_TIFFfreeExt(tif, sp->uncompressed_buffer);
233-
sp->uncompressed_buffer = _TIFFmallocExt(tif, new_alloc);
232+
sp->uncompressed_buffer = (uint8_t *)_TIFFmallocExt(tif, new_alloc);
234233
if (!sp->uncompressed_buffer)
235234
{
236235
TIFFErrorExtR(tif, module, "Cannot allocate buffer");
237236
_TIFFfreeExt(tif, sp->uncompressed_buffer);
238-
sp->uncompressed_buffer = 0;
237+
sp->uncompressed_buffer = NULL;
239238
sp->uncompressed_alloc = 0;
240239
return 0;
241240
}
@@ -267,7 +266,7 @@ static int SetupBuffers(TIFF *tif, LERCState *sp, const char *module)
267266
TIFFErrorExtR(tif, module, "Cannot allocate buffer");
268267
sp->mask_size = 0;
269268
_TIFFfreeExt(tif, sp->uncompressed_buffer);
270-
sp->uncompressed_buffer = 0;
269+
sp->uncompressed_buffer = NULL;
271270
sp->uncompressed_alloc = 0;
272271
return 0;
273272
}
@@ -348,7 +347,7 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
348347
return 0;
349348
}
350349
assert(lerc_data_sizet == (unsigned int)lerc_data_sizet);
351-
lerc_data = sp->compressed_buffer;
350+
lerc_data = (uint8_t *)sp->compressed_buffer;
352351
lerc_data_size = (unsigned int)lerc_data_sizet;
353352
#else
354353
z_stream strm;
@@ -369,15 +368,15 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
369368
strm.avail_in = (uInt)tif->tif_rawcc;
370369
strm.next_in = tif->tif_rawcp;
371370
strm.avail_out = sp->compressed_size;
372-
strm.next_out = sp->compressed_buffer;
371+
strm.next_out = (Bytef *)sp->compressed_buffer;
373372
zlib_ret = inflate(&strm, Z_FINISH);
374373
if (zlib_ret != Z_STREAM_END && zlib_ret != Z_OK)
375374
{
376375
TIFFErrorExtR(tif, module, "inflate() failed");
377376
inflateEnd(&strm);
378377
return 0;
379378
}
380-
lerc_data = sp->compressed_buffer;
379+
lerc_data = (uint8_t *)sp->compressed_buffer;
381380
lerc_data_size = sp->compressed_size - strm.avail_out;
382381
inflateEnd(&strm);
383382
#endif
@@ -396,7 +395,7 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
396395
return 0;
397396
}
398397

399-
lerc_data = sp->compressed_buffer;
398+
lerc_data = (uint8_t *)sp->compressed_buffer;
400399
lerc_data_size = (unsigned int)zstd_ret;
401400
#else
402401
TIFFErrorExtR(tif, module, "ZSTD support missing");
@@ -568,7 +567,7 @@ static int LERCPreDecode(TIFF *tif, uint16_t s)
568567
{
569568
_TIFFfreeExt(tif, sp->uncompressed_buffer_multiband);
570569
sp->uncompressed_buffer_multiband =
571-
_TIFFmallocExt(tif, num_bytes_needed);
570+
(uint8_t *)_TIFFmallocExt(tif, num_bytes_needed);
572571
if (!sp->uncompressed_buffer_multiband)
573572
{
574573
sp->uncompressed_buffer_multiband_alloc = 0;
@@ -752,7 +751,7 @@ static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
752751
assert(sp != NULL);
753752
assert(sp->state == LSTATE_INIT_DECODE);
754753

755-
if (sp->uncompressed_buffer == 0)
754+
if (sp->uncompressed_buffer == NULL)
756755
{
757756
memset(op, 0, (size_t)occ);
758757
TIFFErrorExtR(tif, module, "Uncompressed buffer not allocated");
@@ -773,6 +772,8 @@ static int LERCDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
773772
return 1;
774773
}
775774

775+
#ifndef LERC_READ_ONLY
776+
776777
static int LERCSetupEncode(TIFF *tif)
777778
{
778779
LERCState *sp = LERCEncoderState(tif);
@@ -1005,7 +1006,7 @@ static int LERCPostEncode(TIFF *tif)
10051006
{
10061007
_TIFFfreeExt(tif, sp->uncompressed_buffer_multiband);
10071008
sp->uncompressed_buffer_multiband =
1008-
_TIFFmallocExt(tif, num_bytes_needed);
1009+
(uint8_t *)_TIFFmallocExt(tif, num_bytes_needed);
10091010
if (!sp->uncompressed_buffer_multiband)
10101011
{
10111012
sp->uncompressed_buffer_multiband_alloc = 0;
@@ -1126,7 +1127,8 @@ static int LERCPostEncode(TIFF *tif)
11261127
sp->uncompressed_buffer_multiband, sp->lerc_version,
11271128
GetLercDataType(tif), 1, sp->segment_width, sp->segment_height,
11281129
dst_nbands, dst_nbands, sp->mask_buffer, sp->maxzerror,
1129-
sp->compressed_buffer, sp->compressed_size, &numBytesWritten);
1130+
(unsigned char *)sp->compressed_buffer, sp->compressed_size,
1131+
&numBytesWritten);
11301132
}
11311133
else
11321134
#endif
@@ -1139,7 +1141,8 @@ static int LERCPostEncode(TIFF *tif)
11391141
use_mask ? 1 : 0,
11401142
#endif
11411143
use_mask ? sp->mask_buffer : NULL, sp->maxzerror,
1142-
sp->compressed_buffer, sp->compressed_size, &numBytesWritten);
1144+
(unsigned char *)sp->compressed_buffer, sp->compressed_size,
1145+
&numBytesWritten);
11431146
}
11441147
if (lerc_ret != 0)
11451148
{
@@ -1271,7 +1274,7 @@ static int LERCPostEncode(TIFF *tif)
12711274
{
12721275
int ret;
12731276
uint8_t *tif_rawdata_backup = tif->tif_rawdata;
1274-
tif->tif_rawdata = sp->compressed_buffer;
1277+
tif->tif_rawdata = (uint8_t *)sp->compressed_buffer;
12751278
tif->tif_rawcc = numBytesWritten;
12761279
ret = TIFFFlushData1(tif);
12771280
tif->tif_rawdata = tif_rawdata_backup;
@@ -1282,11 +1285,13 @@ static int LERCPostEncode(TIFF *tif)
12821285
return 1;
12831286
}
12841287

1288+
#endif /* LERC_READ_ONLY */
1289+
12851290
static void LERCCleanup(TIFF *tif)
12861291
{
12871292
LERCState *sp = GetLERCState(tif);
12881293

1289-
assert(sp != 0);
1294+
assert(sp != NULL);
12901295

12911296
tif->tif_tagmethods.vgetfield = sp->vgetparent;
12921297
tif->tif_tagmethods.vsetfield = sp->vsetparent;
@@ -1312,20 +1317,21 @@ static void LERCCleanup(TIFF *tif)
13121317
static const TIFFField LERCFields[] = {
13131318
{TIFFTAG_LERC_PARAMETERS, TIFF_VARIABLE2, TIFF_VARIABLE2, TIFF_LONG, 0,
13141319
TIFF_SETGET_C32_UINT32, TIFF_SETGET_UNDEFINED, FIELD_CUSTOM, FALSE, TRUE,
1315-
"LercParameters", NULL},
1320+
(char *)"LercParameters", NULL},
13161321
{TIFFTAG_LERC_MAXZERROR, 0, 0, TIFF_ANY, 0, TIFF_SETGET_DOUBLE,
1317-
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "LercMaximumError",
1318-
NULL},
1322+
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE,
1323+
(char *)"LercMaximumError", NULL},
13191324
{TIFFTAG_LERC_VERSION, 0, 0, TIFF_ANY, 0, TIFF_SETGET_UINT32,
1320-
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, "LercVersion", NULL},
1325+
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE, (char *)"LercVersion",
1326+
NULL},
13211327
{TIFFTAG_LERC_ADD_COMPRESSION, 0, 0, TIFF_ANY, 0, TIFF_SETGET_UINT32,
13221328
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, FALSE, FALSE,
1323-
"LercAdditionalCompression", NULL},
1329+
(char *)"LercAdditionalCompression", NULL},
13241330
{TIFFTAG_ZSTD_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
13251331
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE,
1326-
"ZSTD zstd_compress_level", NULL},
1332+
(char *)"ZSTD zstd_compress_level", NULL},
13271333
{TIFFTAG_ZIPQUALITY, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
1328-
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, "", NULL},
1334+
TIFF_SETGET_UNDEFINED, FIELD_PSEUDO, TRUE, FALSE, (char *)"", NULL},
13291335
};
13301336

13311337
static int LERCVSetFieldBase(TIFF *tif, uint32_t tag, ...)
@@ -1517,12 +1523,14 @@ int TIFFInitLERC(TIFF *tif, int scheme)
15171523
tif->tif_decoderow = LERCDecode;
15181524
tif->tif_decodestrip = LERCDecode;
15191525
tif->tif_decodetile = LERCDecode;
1526+
#ifndef LERC_READ_ONLY
15201527
tif->tif_setupencode = LERCSetupEncode;
15211528
tif->tif_preencode = LERCPreEncode;
15221529
tif->tif_postencode = LERCPostEncode;
15231530
tif->tif_encoderow = LERCEncode;
15241531
tif->tif_encodestrip = LERCEncode;
15251532
tif->tif_encodetile = LERCEncode;
1533+
#endif
15261534
tif->tif_cleanup = LERCCleanup;
15271535

15281536
/* Default values for codec-specific fields */

libtiff/tif_lzw.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ static int LZWDecode(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s);
168168
#ifdef LZW_COMPAT
169169
static int LZWDecodeCompat(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s);
170170
#endif
171-
static void cl_hash(LZWCodecState *);
172171

173172
/*
174173
* LZW Decoder.
@@ -1017,6 +1016,10 @@ static int LZWDecodeCompat(TIFF *tif, uint8_t *op0, tmsize_t occ0, uint16_t s)
10171016
}
10181017
#endif /* LZW_COMPAT */
10191018

1019+
#ifndef LZW_READ_ONLY
1020+
1021+
static void cl_hash(LZWCodecState *);
1022+
10201023
/*
10211024
* LZW Encoding.
10221025
*/
@@ -1373,6 +1376,8 @@ static void cl_hash(LZWCodecState *sp)
13731376
hp->hash = -1;
13741377
}
13751378

1379+
#endif
1380+
13761381
static void LZWCleanup(TIFF *tif)
13771382
{
13781383
(void)TIFFPredictorCleanup(tif);
@@ -1416,12 +1421,14 @@ int TIFFInitLZW(TIFF *tif, int scheme)
14161421
tif->tif_decoderow = LZWDecode;
14171422
tif->tif_decodestrip = LZWDecode;
14181423
tif->tif_decodetile = LZWDecode;
1424+
#ifndef LZW_READ_ONLY
14191425
tif->tif_setupencode = LZWSetupEncode;
14201426
tif->tif_preencode = LZWPreEncode;
14211427
tif->tif_postencode = LZWPostEncode;
14221428
tif->tif_encoderow = LZWEncode;
14231429
tif->tif_encodestrip = LZWEncode;
14241430
tif->tif_encodetile = LZWEncode;
1431+
#endif
14251432
tif->tif_cleanup = LZWCleanup;
14261433
/*
14271434
* Setup predictor setup.

libtiff/tif_packbits.c

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
#include <stdio.h>
3333

34+
#ifndef PACKBITS_READ_ONLY
35+
3436
static int PackBitsPreEncode(TIFF *tif, uint16_t s)
3537
{
3638
(void)s;
@@ -231,6 +233,8 @@ static int PackBitsEncodeChunk(TIFF *tif, uint8_t *bp, tmsize_t cc, uint16_t s)
231233
return (1);
232234
}
233235

236+
#endif
237+
234238
static int PackBitsDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
235239
{
236240
static const char module[] = "PackBitsDecode";
@@ -314,11 +318,13 @@ int TIFFInitPackBits(TIFF *tif, int scheme)
314318
tif->tif_decoderow = PackBitsDecode;
315319
tif->tif_decodestrip = PackBitsDecode;
316320
tif->tif_decodetile = PackBitsDecode;
321+
#ifndef PACKBITS_READ_ONLY
317322
tif->tif_preencode = PackBitsPreEncode;
318323
tif->tif_postencode = PackBitsPostEncode;
319324
tif->tif_encoderow = PackBitsEncode;
320325
tif->tif_encodestrip = PackBitsEncodeChunk;
321326
tif->tif_encodetile = PackBitsEncodeChunk;
327+
#endif
322328
return (1);
323329
}
324330
#endif /* PACKBITS_SUPPORT */

0 commit comments

Comments
 (0)