From 11d145831617456525736825e717a5de8e24ef7a Mon Sep 17 00:00:00 2001
From: Andrew Murray <radarhere@users.noreply.github.com>
Date: Sat, 1 May 2021 00:51:39 +1000
Subject: [PATCH] Replaced uint16 and uint32 with uint16_t and uint32_t to
 resolve TIFF deprecations

---
 src/decode.c                |  2 +-
 src/libImaging/TiffDecode.c | 22 +++++++++++-----------
 src/libImaging/TiffDecode.h | 10 +++++-----
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/decode.c b/src/decode.c
index 99e9cdc67..ee1c5685f 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -499,7 +499,7 @@ PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) {
     char *rawmode;
     char *compname;
     int fp;
-    uint32 ifdoffset;
+    uint32_t ifdoffset;
 
     if (!PyArg_ParseTuple(args, "sssiI", &mode, &rawmode, &compname, &fp, &ifdoffset)) {
         return NULL;
diff --git a/src/libImaging/TiffDecode.c b/src/libImaging/TiffDecode.c
index bae3afff4..0f0927e7a 100644
--- a/src/libImaging/TiffDecode.c
+++ b/src/libImaging/TiffDecode.c
@@ -181,7 +181,7 @@ _tiffUnmapProc(thandle_t hdata, tdata_t base, toff_t size) {
 }
 
 int
-ImagingLibTiffInit(ImagingCodecState state, int fp, uint32 offset) {
+ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset) {
     TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
 
     TRACE(("initing libtiff\n"));
@@ -213,10 +213,10 @@ ImagingLibTiffInit(ImagingCodecState state, int fp, uint32 offset) {
 }
 
 int
-_pickUnpackers(Imaging im, ImagingCodecState state, TIFF *tiff, uint16 planarconfig, ImagingShuffler *unpackers) {
+_pickUnpackers(Imaging im, ImagingCodecState state, TIFF *tiff, uint16_t planarconfig, ImagingShuffler *unpackers) {
     // if number of bands is 1, there is no difference with contig case
     if (planarconfig == PLANARCONFIG_SEPARATE && im->bands > 1) {
-        uint16 bits_per_sample = 8;
+        uint16_t bits_per_sample = 8;
 
         TIFFGetFieldDefaulted(tiff, TIFFTAG_BITSPERSAMPLE, &bits_per_sample);
         if (bits_per_sample != 8 && bits_per_sample != 16) {
@@ -545,10 +545,10 @@ ImagingLibTiffDecode(
     char *filename = "tempfile.tif";
     char *mode = "r";
     TIFF *tiff;
-    uint16 photometric = 0;  // init to not PHOTOMETRIC_YCBCR
-    uint16 compression;
+    uint16_t photometric = 0;  // init to not PHOTOMETRIC_YCBCR
+    uint16_t compression;
     int readAsRGBA = 0;
-    uint16 planarconfig = 0;
+    uint16_t planarconfig = 0;
     int planes = 1;
     ImagingShuffler unpackers[4];
     UINT32 img_width, img_height;
@@ -639,7 +639,7 @@ ImagingLibTiffDecode(
 
     if (clientstate->ifd) {
         int rv;
-        uint32 ifdoffset = clientstate->ifd;
+        uint32_t ifdoffset = clientstate->ifd;
         TRACE(("reading tiff ifd %u\n", ifdoffset));
         rv = TIFFSetSubDirectory(tiff, ifdoffset);
         if (!rv) {
@@ -697,8 +697,8 @@ ImagingLibTiffDecode(
             // Check if raw mode was RGBa and it was stored on separate planes
             // so we have to convert it to RGBA
             if (planes > 3 && strcmp(im->mode, "RGBA") == 0) {
-                uint16 extrasamples;
-                uint16* sampleinfo;
+                uint16_t extrasamples;
+                uint16_t* sampleinfo;
                 ImagingShuffler shuffle;
                 INT32 y;
 
@@ -810,7 +810,7 @@ ImagingLibTiffMergeFieldInfo(
     ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length) {
     // Refer to libtiff docs (http://www.simplesystems.org/libtiff/addingtags.html)
     TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
-    uint32 n;
+    uint32_t n;
     int status = 0;
 
     // custom fields added with ImagingLibTiffMergeFieldInfo are only used for
@@ -933,7 +933,7 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
                 state->xsize);
 
             if (TIFFWriteScanline(
-                    tiff, (tdata_t)(state->buffer), (uint32)state->y, 0) == -1) {
+                    tiff, (tdata_t)(state->buffer), (uint32_t)state->y, 0) == -1) {
                 TRACE(("Encode Error, row %d\n", state->y));
                 state->errcode = IMAGING_CODEC_BROKEN;
                 TIFFClose(tiff);
diff --git a/src/libImaging/TiffDecode.h b/src/libImaging/TiffDecode.h
index 2c3d88caa..c7c7d48ed 100644
--- a/src/libImaging/TiffDecode.h
+++ b/src/libImaging/TiffDecode.h
@@ -32,17 +32,17 @@ typedef struct {
     toff_t loc;   /* toff_t == uint32 */
     tsize_t size; /* tsize_t == int32 */
     int fp;
-    uint32 ifd; /* offset of the ifd, used for multipage
-                 * Should be uint32 for libtiff 3.9.x
-                 * uint64 for libtiff 4.0.x
-                 */
+    uint32_t ifd; /* offset of the ifd, used for multipage
+                   * Should be uint32 for libtiff 3.9.x
+                   * uint64 for libtiff 4.0.x
+                   */
     TIFF *tiff; /* Used in write */
     toff_t eof;
     int flrealloc; /* may we realloc */
 } TIFFSTATE;
 
 extern int
-ImagingLibTiffInit(ImagingCodecState state, int fp, uint32 offset);
+ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset);
 extern int
 ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp);
 extern int