TinyTIFF
a lightweight C/C++ library for reading and writing TIFF files
Loading...
Searching...
No Matches

Functions

template<class Tin , class Tout >
void TinyTIFFReader_readFrame (TinyTIFFReaderFile *tif, Tout *buffer, uint16_t sample=0)
 template function that internally calls TinyTIFFReader_getSampleData() and copies the data into the specified output buffer
 
template<class Tin , class Tout >
void TinyTIFFReader_readFrame_s (TinyTIFFReaderFile *tif, Tout *buffer, unsigned long buffer_size, uint16_t sample=0)
 template function that internally calls TinyTIFFReader_getSampleData_s() and copies the data into the specified output buffer
 

Detailed Description

All functions in this group are extensions to the basic TinyTIFFReader libarary. They are all header-only (or templates), so no link library other than libTinyTIFF is required.

Function Documentation

◆ TinyTIFFReader_readFrame()

template<class Tin , class Tout >
void TinyTIFFReader_readFrame ( TinyTIFFReaderFile tif,
Tout *  buffer,
uint16_t  sample = 0 
)
inline

template function that internally calls TinyTIFFReader_getSampleData() and copies the data into the specified output buffer

Template Parameters
Tindatatype of the sample in the TIFF file
Toutdatatype of buffer
Parameters
tifthe TIFF file to read from
bufferthe buffer to write into

This function may be used in reader code like this:

bool intReadFrameFloat(float *data) {
if (!tif) return false;
uint32_t wwidth=TinyTIFFReader_getWidth(tif);
uint32_t hheight=TinyTIFFReader_getHeight(tif);
if (!(wwidth>0 && hheight>0)) tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("error in file '%1': frame %2 is too small\n").arg(filename).arg(frame));
else {
uint16_t sformat=TinyTIFFReader_getSampleFormat(tif);
uint16_t bits=TinyTIFFReader_getBitsPerSample(tif);
if (bits==8) TinyTIFFReader_readFrame<uint8_t, float>(tif, data);
else if (bits==16) TinyTIFFReader_readFrame<uint16_t, float>(tif, data);
else if (bits==32) TinyTIFFReader_readFrame<uint32_t, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else if (sformat==TINYTIFF_SAMPLEFORMAT_INT) {
if (bits==8) TinyTIFFReader_readFrame<int8_t, float>(tif, data);
else if (bits==16) TinyTIFFReader_readFrame<int16_t, float>(tif, data);
else if (bits==32) TinyTIFFReader_readFrame<int32_t, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else if (sformat==TINYTIFF_SAMPLEFORMAT_FLOAT) {
if (bits==32) TinyTIFFReader_readFrame<float, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
}
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("error reading frame %1: %2\n").arg(frame).arg(TinyTIFFReader_getLastError(tif)));
return false;
}
return true;
}
uint16_t TinyTIFFReader_getSampleFormat(TinyTIFFReaderFile *tiff)
return the sample format of the current frame
Definition tinytiffreader.c:1055
uint16_t TinyTIFFReader_getBitsPerSample(TinyTIFFReaderFile *tiff, int sample)
return the bits per sample of the current frame
Definition tinytiffreader.c:1062
int TinyTIFFReader_wasError(TinyTIFFReaderFile *tiff)
returns TINYTIFF_TRUE (non-zero) when there was an error in the last function call,...
Definition tinytiffreader.c:332
uint32_t TinyTIFFReader_getWidth(TinyTIFFReaderFile *tiff)
return the width of the current frame
Definition tinytiffreader.c:1033
const char * TinyTIFFReader_getLastError(TinyTIFFReaderFile *tiff)
returns a pointer to the last error message
Definition tinytiffreader.c:327
uint32_t TinyTIFFReader_getHeight(TinyTIFFReaderFile *tiff)
return the height of the current frame
Definition tinytiffreader.c:1040
#define TINYTIFF_SAMPLEFORMAT_UINT
possible return value of TinyTIFFReader_getSampleFormat(), indicating unsigned integer data
Definition tinytiff_defs.h:45
#define TINYTIFF_SAMPLEFORMAT_FLOAT
possible return value of TinyTIFFReader_getSampleFormat(), indicating floating-point data
Definition tinytiff_defs.h:59
#define TINYTIFF_SAMPLEFORMAT_INT
possible return value of TinyTIFFReader_getSampleFormat(), indicating integer data
Definition tinytiff_defs.h:52

◆ TinyTIFFReader_readFrame_s()

template<class Tin , class Tout >
void TinyTIFFReader_readFrame_s ( TinyTIFFReaderFile tif,
Tout *  buffer,
unsigned long  buffer_size,
uint16_t  sample = 0 
)
inline

template function that internally calls TinyTIFFReader_getSampleData_s() and copies the data into the specified output buffer

Template Parameters
Tindatatype of the sample in the TIFF file
Toutdatatype of buffer
Parameters
tifthe TIFF file to read from
bufferthe buffer to write into
buffer_sizesize of buffer (i.e. number of entries)

This function may be used in reader code like this:

bool intReadFrameFloat(float *data) {
if (!tif) return false;
uint32_t wwidth=TinyTIFFReader_getWidth(tif);
uint32_t hheight=TinyTIFFReader_getHeight(tif);
if (!(wwidth>0 && hheight>0)) tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("error in file '%1': frame %2 is too small\n").arg(filename).arg(frame));
else {
uint16_t sformat=TinyTIFFReader_getSampleFormat(tif);
uint16_t bits=TinyTIFFReader_getBitsPerSample(tif);
if (bits==8) TinyTIFFReader_readFrame_s<uint8_t, float>(tif, data);
else if (bits==16) TinyTIFFReader_readFrame_s<uint16_t, float>(tif, data);
else if (bits==32) TinyTIFFReader_readFrame_s<uint32_t, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else if (sformat==TINYTIFF_SAMPLEFORMAT_INT) {
if (bits==8) TinyTIFFReader_readFrame_s<int8_t, float>(tif, data);
else if (bits==16) TinyTIFFReader_readFrame_s<int16_t, float>(tif, data);
else if (bits==32) TinyTIFFReader_readFrame_s<int32_t, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else if (sformat==TINYTIFF_SAMPLEFORMAT_FLOAT) {
if (bits==32) TinyTIFFReader_readFrame_s<float, float>(tif, data);
else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
} else {
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("frame %1 has a datatype not convertible to float (type=%2, bitspersample=%3)\n").arg(frame).arg(sformat).arg(bits));
return false;
}
}
tinyTIFFErrorHandler("QFImageReaderTinyTIFF", QObject::tr("error reading frame %1: %2\n").arg(frame).arg(TinyTIFFReader_getLastError(tif)));
return false;
}
return true;
}