Skip to content

Commit

Permalink
COMP: Use C99 int types over libtiff's
Browse files Browse the repository at this point in the history
The libtiff int types are depricated in 4.3.0 and produce a warning.
  • Loading branch information
blowekamp authored and N-Dekker committed May 20, 2021
1 parent faccaa9 commit f98f6a8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
10 changes: 5 additions & 5 deletions Modules/IO/LSM/src/itkLSMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ LSMImageIO::Write(const void * buffer)
return;
}

uint32 w = width;
uint32 h = height;
uint32_t w = width;
uint32_t h = height;

TIFFSetTagExtender(TagExtender);
if (m_NumberOfDimensions == 3)
Expand Down Expand Up @@ -302,8 +302,8 @@ LSMImageIO::Write(const void * buffer)
{
// if number of scalar components is greater than 3, that means we assume
// there is alpha.
uint16 extra_samples = scomponents - 3;
auto * sample_info = new uint16[scomponents - 3];
uint16_t extra_samples = scomponents - 3;
auto * sample_info = new uint16_t[scomponents - 3];
sample_info[0] = EXTRASAMPLE_ASSOCALPHA;
int cc;
for (cc = 1; cc < scomponents - 3; ++cc)
Expand Down Expand Up @@ -343,7 +343,7 @@ LSMImageIO::Write(const void * buffer)

TIFFSetField(tif, TIFFTAG_COMPRESSION, compression); // Fix for compression

uint16 photometric = (scomponents == 1) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB;
uint16_t photometric = (scomponents == 1) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB;

if (compression == COMPRESSION_JPEG)
{
Expand Down
68 changes: 34 additions & 34 deletions Modules/IO/TIFF/src/itkTIFFImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ TIFFImageIO::ReadVolume(void * buffer)
const size_t width{ m_InternalImage->m_Width };
const size_t height{ m_InternalImage->m_Height };

for (uint16 page = 0; page < m_InternalImage->m_NumberOfPages; ++page)
for (uint16_t page = 0; page < m_InternalImage->m_NumberOfPages; ++page)
{
if (m_InternalImage->m_IgnoredSubFiles > 0)
{
int32 subfiletype = 6;
int32_t subfiletype = 6;
if (TIFFGetField(m_InternalImage->m_Image, TIFFTAG_SUBFILETYPE, &subfiletype))
{
if (subfiletype & FILETYPE_REDUCEDIMAGE || subfiletype & FILETYPE_MASK)
Expand Down Expand Up @@ -565,21 +565,21 @@ TIFFImageIO::InternalWrite(const void * buffer)
{
const auto * outPtr = static_cast<const char *>(buffer);

uint16 page, pages = 1;
uint16_t page, pages = 1;

const SizeValueType width = m_Dimensions[0];
const SizeValueType height = m_Dimensions[1];
if (m_NumberOfDimensions == 3)
{
pages = static_cast<uint16>(m_Dimensions[2]);
pages = static_cast<uint16_t>(m_Dimensions[2]);
}

auto scomponents = static_cast<uint16>(this->GetNumberOfComponents());
auto scomponents = static_cast<uint16_t>(this->GetNumberOfComponents());
double resolution_x{ m_Spacing[0] != 0.0 ? 25.4 / m_Spacing[0] : 0.0 };
double resolution_y{ m_Spacing[1] != 0.0 ? 25.4 / m_Spacing[1] : 0.0 };
// rowsperstrip is set to a default value but modified based on the tif scanlinesize before
// passing it into the TIFFSetField (see below).
auto rowsperstrip = uint32{ 0 };
auto rowsperstrip = uint32_t{ 0 };
uint16_t bps;

switch (this->GetComponentType())
Expand Down Expand Up @@ -640,8 +640,8 @@ TIFFImageIO::InternalWrite(const void * buffer)
TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
}

auto w = static_cast<uint32>(width);
auto h = static_cast<uint32>(height);
auto w = static_cast<uint32_t>(width);
auto h = static_cast<uint32_t>(height);

if (m_NumberOfDimensions == 3)
{
Expand Down Expand Up @@ -670,18 +670,18 @@ TIFFImageIO::InternalWrite(const void * buffer)
{
// if number of scalar components is greater than 3, that means we assume
// there is alpha.
uint16 extra_samples = scomponents - 3;
auto * sample_info = new uint16[scomponents - 3];
uint16_t extra_samples = scomponents - 3;
auto * sample_info = new uint16_t[scomponents - 3];
sample_info[0] = EXTRASAMPLE_ASSOCALPHA;
for (uint16 cc = 1; cc < scomponents - 3; ++cc)
for (uint16_t cc = 1; cc < scomponents - 3; ++cc)
{
sample_info[cc] = EXTRASAMPLE_UNSPECIFIED;
}
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, extra_samples, sample_info);
delete[] sample_info;
}

uint16 compression;
uint16_t compression;

if (m_UseCompression)
{
Expand Down Expand Up @@ -757,7 +757,7 @@ TIFFImageIO::InternalWrite(const void * buffer)
// achieved when the STRIP_SIZE_DEFAULT is increased to 1 MB.
// This results in an increase in memory usage but no increase in writing time when writing
// locally and significant writing time improvement when writing over sshfs.
// For example, writing a 2048x2048 uint16 image with 8 kB per strip leads to 2 rows per strip
// For example, writing a 2048x2048 uint16_t image with 8 kB per strip leads to 2 rows per strip
// and takes about 120 seconds writing over sshfs.
// Using 1 MB per strip leads to 256 rows per strip, which takes only 4 seconds to write over sshfs.
// Rather than change that value in the third party libtiff library, we instead compute the
Expand Down Expand Up @@ -819,7 +819,7 @@ TIFFImageIO::InternalWrite(const void * buffer)
rowLength *= this->GetNumberOfComponents();
rowLength *= width;

uint32 row = 0;
uint32_t row = 0;
for (unsigned int idx2 = 0; idx2 < height; ++idx2)
{
if (TIFFWriteScanline(tif, const_cast<char *>(outPtr), row, 0) < 0)
Expand Down Expand Up @@ -866,11 +866,11 @@ typedef enum
} ITK_TIFF_MOC_TIFFSetGetFieldType;
struct _TIFFField
{
uint32 field_tag; /* field's tag */
uint32_t field_tag; /* field's tag */
short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
short field_writecount; /* write count/TIFF_VARIABLE */
TIFFDataType field_type; /* type of associated data */
uint32 reserved; /* reserved for future extension */
uint32_t reserved; /* reserved for future extension */
ITK_TIFF_MOC_TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */
ITK_TIFF_MOC_TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */
unsigned short field_bit; /* bit in fieldsset bit vector */
Expand Down Expand Up @@ -982,7 +982,7 @@ TIFFImageIO::ReadRawByteFromTag(unsigned int t, unsigned int & value_count)
}
else if (itkTIFFFieldReadCount(fld) == TIFF_VARIABLE)
{
uint16 cnt;
uint16_t cnt;
ret = TIFFGetField(m_InternalImage->m_Image, tag, &cnt, &raw_data);
value_count = cnt;
}
Expand Down Expand Up @@ -1036,21 +1036,21 @@ TIFFImageIO::AllocateTiffPalette(uint16_t bps)
m_ColorBlue = nullptr;

// bpp is 16 at maximum for palette image
tmsize_t array_size = tmsize_t{ 1 } << bps * sizeof(uint16);
m_ColorRed = static_cast<uint16 *>(_TIFFmalloc(array_size));
tmsize_t array_size = tmsize_t{ 1 } << bps * sizeof(uint16_t);
m_ColorRed = static_cast<uint16_t *>(_TIFFmalloc(array_size));
if (!m_ColorRed)
{
_TIFFfree(m_ColorRed);
itkExceptionMacro("Can't allocate space for Red channel of component tables.");
}
m_ColorGreen = static_cast<uint16 *>(_TIFFmalloc(array_size));
m_ColorGreen = static_cast<uint16_t *>(_TIFFmalloc(array_size));
if (!m_ColorGreen)
{
_TIFFfree(m_ColorRed);
_TIFFfree(m_ColorGreen);
itkExceptionMacro("Can't allocate space for Green channel of component tables.");
}
m_ColorBlue = static_cast<uint16 *>(_TIFFmalloc(array_size));
m_ColorBlue = static_cast<uint16_t *>(_TIFFmalloc(array_size));
if (!m_ColorBlue)
{
_TIFFfree(m_ColorRed);
Expand All @@ -1059,7 +1059,7 @@ TIFFImageIO::AllocateTiffPalette(uint16_t bps)
itkExceptionMacro("Can't allocate space for Blue channel of component tables.");
}
// TIFF palette length is fixed for a given bpp
uint64 TIFFPaletteLength = uint64{ 1 } << bps;
uint64_t TIFFPaletteLength = uint64{ 1 } << bps;
for (size_t i = 0; i < TIFFPaletteLength; ++i)
{
if (i < m_ColorPalette.size())
Expand Down Expand Up @@ -1108,7 +1108,7 @@ TIFFImageIO::ReadTIFFTags()
}
raw_data = nullptr;

uint32 tag = TIFFGetTagListEntry(m_InternalImage->m_Image, i);
uint32_t tag = TIFFGetTagListEntry(m_InternalImage->m_Image, i);

const itkTIFFField * field = TIFFFieldWithTag(m_InternalImage->m_Image, tag);

Expand Down Expand Up @@ -1138,7 +1138,7 @@ TIFFImageIO::ReadTIFFTags()
}
else if (read_count == TIFF_VARIABLE)
{
uint16 cnt;
uint16_t cnt;
if (TIFFGetField(m_InternalImage->m_Image, tag, &cnt, &raw_data) != 1)
{
continue;
Expand Down Expand Up @@ -1227,19 +1227,19 @@ TIFFImageIO::ReadTIFFTags()
dict, field_name, Array<char>(static_cast<const char *>(raw_data), static_cast<size_t>(value_count)));
break;
case TIFF_SHORT:
itkEncapsulate(unsigned short, uint16);
itkEncapsulate(unsigned short, uint16_t);
break;
case TIFF_LONG:
EncapsulateMetaData<unsigned int>(dict, field_name, (static_cast<const uint32 *>(raw_data))[0]);
EncapsulateMetaData<unsigned int>(dict, field_name, (static_cast<const uint32_t *>(raw_data))[0]);
break;
case TIFF_SBYTE:
EncapsulateMetaData<signed char>(dict, field_name, (static_cast<const int8 *>(raw_data))[0]);
EncapsulateMetaData<signed char>(dict, field_name, (static_cast<const int8_t *>(raw_data))[0]);
break;
case TIFF_SSHORT:
EncapsulateMetaData<short>(dict, field_name, (static_cast<const int16 *>(raw_data))[0]);
EncapsulateMetaData<short>(dict, field_name, (static_cast<const int16_t *>(raw_data))[0]);
break;
case TIFF_SLONG:
itkEncapsulate(int, int32);
itkEncapsulate(int, int32_t);
break;
case TIFF_FLOAT:
itkEncapsulate(float, float);
Expand Down Expand Up @@ -1282,17 +1282,17 @@ TIFFImageIO::ReadTIFFTags()
void
TIFFImageIO::ReadCurrentPage(void * buffer, size_t pixelOffset)
{
const uint32 width = m_InternalImage->m_Width;
const uint32 height = m_InternalImage->m_Height;
const uint32_t width = m_InternalImage->m_Width;
const uint32_t height = m_InternalImage->m_Height;


if (!m_InternalImage->CanRead())
{
uint32 * tempImage = nullptr;
uint32_t * tempImage = nullptr;

if (this->GetNumberOfComponents() == 4 && m_ComponentType == IOComponentEnum::UCHAR)
{
tempImage = static_cast<uint32 *>(buffer) + (pixelOffset / 4);
tempImage = static_cast<uint32_t *>(buffer) + (pixelOffset / 4);
}
else
{
Expand Down Expand Up @@ -1402,7 +1402,7 @@ TIFFImageIO::ReadGenericImage(void * _out, unsigned int width, unsigned int heig
break;
}

for (uint32 row = 0; row < height; ++row)
for (uint32_t row = 0; row < height; ++row)
{
if (TIFFReadScanline(m_InternalImage->m_Image, buf, row, 0) <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TIFF/src/itkTIFFReaderInternal.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TIFFReaderInternal::Initialize()

for (unsigned int page = 0; page < this->m_NumberOfPages; ++page)
{
int32 subfiletype = 6;
int32_t subfiletype = 6;
if (TIFFGetField(this->m_Image, TIFFTAG_SUBFILETYPE, &subfiletype))
{
if (subfiletype == 0)
Expand Down

0 comments on commit f98f6a8

Please sign in to comment.