nvTiff Documentation¶
Introduction¶
The nvTIFF library accelerates the decoding and encoding of TIFF images compressed with LZW on NVIDIA GPUs. The library is built on the CUDA ® platform and is supported on Volta+ GPU architectures.
Note
Throughout this document, the terms “CPU” and “Host” are used synonymously. Similarly, the terms “GPU” and “Device” are synonymous.
nvTIFF Decoder / Encoder¶
The library utilizes GPU for TIFF decode and encode using CUDA. The code uses a single GPU to decode uncompressed or LZW-compressed images in a TIFF file, or to LZW-compress raster images in memory and save the results in a TIFF file. The code supports multi-image TIFF files in both regular and BigTIFF format, with the following limitations:
color space must be either Grayscale (PhotometricInterpretation=1) or RGB (=2)
image data compressed with LZW (Compression=5) or uncompressed
pixel components stored in “chunky” format (RGBRGB…, PlanarConfiguration=1) for RGB images
image data must be organized in Strips, not Tiles
pixels of RGB images must be represented with at most 4 components
each component must be represented with exactly 8 bits in case of LZW or 8, 16 or 32 bits for uncompressed ones
all images in the file must have the same properties
Prerequisites¶
CUDA Toolkit version 11.6 and above
CUDA Driver version r475 and above
Platforms Supported¶
Linux versions:
Architecture |
Distribution Information |
||||
---|---|---|---|---|---|
Name |
Version |
Kernel |
GCC |
GLIBC |
|
x86_64 |
Ubuntu |
20.04.1 |
5.8.0 |
9.3.0 |
2.31 |
18.04.5 |
5.3.0 |
7.5.0 |
2.27 |
||
16.04.7 |
4.15.0 |
5.4.0 |
2.23 |
-
Windows versions:
Windows 10 and Windows Server 2019
Quick Start Guide¶
This section will explain how to use decoder and encoder APIs in a few quick steps. The API details will be covered in the next section.
Note
Link to nvTIFF Samples: https://github.com/NVIDIA/CUDALibrarySamples/tree/master/nvTIFF
Please note that since the decoding and encoding of TIFF images are two fundamentally different problems the APIs for decoding and encoding are also different and independent.
nvTIFF Decode¶
The library read file and load the data stream on device.
Open Tiff file and allocate the device memory :
// we want to decode all images in file "fname" from
// subfile no. "frameBeg" to subfile no. "frameEnd"
nvTiffFile_t *tiffData = nvTiffOpen(devId, fname, memType);
if (!tiffData) {
fprintf(stderr, "Error while reading file %s\n", fname);
exit(EXIT_FAILURE);
}
frameBeg = fmax(frameBeg, 0);
frameEnd = fmin(frameEnd, tiffData->nSubFiles-1);
const int nDecode = frameEnd-frameBeg+1;
// allocate device memory for images
unsigned char **imageOut_d = NULL;
// nvTiff requires all the images (subfiles) in the same file to have
// the same properties so we use the values nrow, ncol and bitsPerPixel
// of the first subfile
const size_t imageSize = sizeof(**imageOut_d)*tiffData->subFiles[0].nrow*
tiffData->subFiles[0].ncol*
(tiffData->subFiles[0].bitsPerPixel/8);
imageOut_d = (unsigned char **)Malloc(sizeof(*imageOut_d)*nDecode);
for(unsigned int i = 0; i < nDecode; i++) {
CHECK_CUDA(cudaMalloc(imageOut_d+i, imageSize));
}
Copy the TIFF file data to specific device memory (pinned memory or pageable memory, etc), if the value of the parameter memType passed to nvTiffOpen() is equal to NVTIFF_MEM_PIN. If it is equal to NVTIFF_MEM_REG this call is not necessary.
// overlap H2D copy of file data with something else...
nvTiffH2DAsync(tiffData, stream);
Call nvTiff decode function to decode the data or range of data from files.
if (!decodeRange) {
rv = nvTiffDecode(tiffData, imageOut_d, stream);
} else {
rv = nvTiffDecodeRange(tiffData, frameBeg, nDecode, imageOut_d, stream);
}
This is an optional step as decoded data are available on GPU. For example this copies the i-th decoded image to the CPU to process the raster data.
CHECK_CUDA(cudaMemcpy(imageOut_h, imageOut_d[i], imageSize, cudaMemcpyDeviceToHost));
Go to step 1 to decode another image. Once all images are decoded, release nvTIFF the library resources by calling the corresponding destroy APIs.
nvTIFF Encode¶
Initialize the library handles and encoder parameters listed below:
// unsigned char **images_d is an host array of "nSubFiles" pointers
// to device buffers containing "nSubFiles" uncompressed images; each
// image has the same number of rows (nrow), of columns (ncol)
// and pixel size in bytes (pixelSize)
// for example let's partition the images in strips of four rows each
unsigned int encRowsPerStrip = 4;
unsigned int nStripOut = DIV_UP(nrow, encRowsPerStrip);
unsigned int totStrips = nSubFiles*nStripOut;
// initial estimate on the maximim
// size of compressed strips
unsigned long long encStripAllocSize = rowsPerStrip*ncol*(pixelSize);
// allocate encoding output buffers;
CHECK_CUDA(cudaMalloc(&stripSize_d, sizeof(*stripSize_d)*totStrips));
CHECK_CUDA(cudaMalloc(&stripOffs_d, sizeof(*stripOffs_d)*totStrips));
CHECK_CUDA(cudaMalloc(&stripData_d, sizeof(*stripData_d)*totStrips*encStripAllocSize));
// create encoding context
nvTiffEncodeCtx_t *ctx = nvTiffEncodeCtxCreate(devId, nSubFiles, nStripOut);
Call nvTiffEncode function to encode. Since we cant’t know in advance the size of the compressed strips, we first try to encode in the buffers allocated based on our initial estimate. If one or more strips require more memory than “encStripAllocSize” bytes then we need to restart the encoding process with a parger buffer. In that case, after the encoding fails do to a passed output buffer too small, the minimum size required for the compressed strip data in order to the encoding to succeed is passed from the library to the user in the context field stripSizeMax. In this way the endcoding process can only fail once due to an output buffer too small.
int i = 0;
do {
rv = nvTiffEncode(ctx,
nrow,
ncol,
pixelSize,
encRowsPerStrip,
nSubFiles,
imageOut_d,
encStripAllocSize,
stripSize_d,
stripOffs_d,
stripData_d,
stream);
if (rv != NVTIFF_ENCODE_SUCCESS) {
// ERROR, WHILE ENCODING IMAGES!
}
rv = nvTiffEncodeFinalize(ctx, stream);
if (rv != NVTIFF_ENCODE_SUCCESS) {
if (rv == NVTIFF_ENCODE_COMP_OVERFLOW) {
if (i == 1) {
// UNKNOWN ERROR, nvTiffEncode() SHOULDN'T OVERFLOW TWICE!
}
encStripAllocSize = ctx->stripSizeMax;
nvTiffEncodeCtxDestroy(ctx);
cudaFree(stripData_d);
cudaMalloc(&stripData_d,
sizeof(*stripData_d)*totStrips*encStripAllocSize);
ctx = nvTiffEncodeCtxCreate(dev, ...);
i++;
} else {
// ERROR WHILE FINALIZING COMPRESSED IMAGES
}
}
} while(rv == NVTIFF_ENCODE_COMP_OVERFLOW);
Write the compress image to TIFF file.
// copy compressed data from the device to the host
unsigned long long *stripSize_h = (unsigned long long *)Malloc(sizeof(*stripSize_h)*totStrips);
CHECK_CUDA(cudaMemcpy(stripSize_h,
stripSize_d,
sizeof(*stripSize_h)*totStrips,
cudaMemcpyDeviceToHost));
unsigned long long *stripOffs_h = (unsigned long long *)Malloc(sizeof(*stripOffs_h)*totStrips);
CHECK_CUDA(cudaMemcpy(stripOffs_h,
stripOffs_d,
sizeof(*stripOffs_h)*totStrips,
cudaMemcpyDeviceToHost));
unsigned char *stripData_h = (unsigned char *)Malloc(sizeof(*stripData_h)*ctx->stripSizeTot);
CHECK_CUDA(cudaMemcpy(stripData_h,
stripData_d,
ctx->stripSizeTot,
cudaMemcpyDeviceToHost));
// write output file
nvTiffWriteFile("outFile.tif",
VER_REG_TIFF,
nSubFiles,
nrow,
ncol,
encRowsPerStrip,
samplesPerPixel,
bitsPerSample,
photometricInt,
planarConf,
stripSize_h,
stripOffs_h,
stripData_h);
Tiff Decode / Encode Demo example¶
The binary nvTiff_exmaple provides a complete and detailed usage example for the encoding and decoding capabilities of the nvTIFF library.
Usage: nvTiff_example [options] -f|–file <TIFF_FILE>
General options:
-d DEVICE_ID –device DEVICE_ID
Specifies the GPU to use for images decoding/encoding. Default: device 0 is used.
-v –verbose
Prints some information about the decoded TIFF file.
-h –help
Prints this help
Decoding options:
-f TIFF_FILE –file TIFF_FILE
Specifies the TIFF file to decode. The code supports both single and multi-image tiff files with the following limitations:
color space must be either Grayscale (PhotometricInterp.=1) or RGB (=2)
image data compressed with LZW (Compression=5) or uncompressed
pixel components stored in “chunky” format (RGB…, PlanarConfiguration=1) for RGB images
image data must be organized in Strips, not Tiles
pixels of RGB images must be represented with at most 4 components
each component must be represented exactly with:
8 bits for LZW compressed images
8, 16 or 32 bits for uncompressed images
all images in the file must have the same properties
-b BEG_FRM –frame-beg BEG_FRM
Specifies the image id in the input TIFF file to start decoding from. The image id must be a value between 0 and the total number of images in the file minus 1. Values less than 0 are clamped to 0. Default: 0
-e END_FRM –frame-end END_FRM
Specifies the image id in the input TIFF file to stop decoding at (included). The image id must be a value between 0 and the total number of images in the file minus 1. Values greater than num_images-1 are clamped to num_images-1. Default: num_images-1.
-m –memtype TYPE
Specifies the type of memory used to hold the TIFF file content: pinned or pageable. Pinned memory is used if ‘p’ is specified. Pageable memory is used if ‘r’ is specified. In case of pinned memory, file content is not copied to device memory before the decoding process (with a resulting performance impact) unless the option -c is also specified (see below). Defualt: r (pageable)
-c –copyh2d
Specifies to copy the file data to device memory in case the -m option specifies to use pinned memory. In case of pageable memory this option has no effect. Default: off.
—decode-out NUM_OUT Enables the writing of selected images from the decoded input TIFF file into separate BMP files for inspection. If no argument is passed, only the first image is written to disk, otherwise the first NUM_OUT images are written. Output files are named outImage_0.bmp, outImage_1.bmp… Defualt: disabled.
Encoding options:
-E –encode
This option enables the encoding of the raster images obtained by decoding the input TIFF file. The images are divided into strips, compressed with LZW and, optionally, written into an output TIFF file. Default: disabled.
-r –rowsxstrip
Specifies the number of consecutive rows to use to divide the images into strips. Each image is divided in strips of the same size (except possibly the last strip) and then the strips are compressed as independent byte streams. This option is ignored if -E is not specified. Default: 1.
-s –stripalloc
Specifies the initial estimate of the maximum size of compressed strips. If during compression one or more strips require more space, the compression is aborted and restarted automatically with a safe estimate. This option is ignored if -E is not specified. Default: the size, in bytes, of a strip in the uncompressed images.
—encode-out Enables the writing of the compressed images to an output TIFF file named outFile.tif. This option is ignored if -E is not specified. Defualt: disabled.
Python Tiff Decode example¶
Prerequisites¶
Python packages
cupy
$ pip install cupy
numpy
$ pip install numpy
tifffile
$ pip install tifffile
Install nvTIFF Python Wheel¶
$ pip install nvtiff-0.1.0-cp36-cp36m-linux_x86_64.whl
Usage:¶
$ python3 nvtiff_test.py -h
usage: nvtiff_test.py [-h] [-o OUTPUT_FILE_PREFIX] [-s] [-c] [-p]
[-r SUBFILE_RANGE]
tiff_file
positional arguments:
tiff_file tiff file to decode.
optional arguments:
-h, --help show this help message and exit
-o OUTPUT_FILE_PREFIX, --output_file_prefix OUTPUT_FILE_PREFIX
Output file prefix to save decoded data. Will save one
file per image in tiff file.
-s, --return_single_array
Return single array from nvTiff instead of list of
arrays
-c, --check_output Compare nvTiff output to reference CPU result
-p, --use_pinned_mem Read TIFF data from pinned memory.
-r SUBFILE_RANGE, --subfile_range SUBFILE_RANGE
comma separated list of starting and ending file
indices to decode, inclusive
Python Example¶
$ python3 nvtiff_test.py bali_notiles.tif
Command line arguments:
tiff_file: bali_notiles.tif
return_single_array: False
output_file_prefix: None
check_output: False
use_pinned_mem: False
subfile_range: None
Time for tifffile:
decode: 0.010347366333007812 s
h2d copy: 0.0010058879852294922 s
total: 0.011353254318237305 s
Time for nvTiff:
open: 0.002551555633544922 s
decode: 0.0005545616149902344 s
total: 0.0031061172485351562 s
Type Declarations¶
nvTIFF Decode API Return Status Codes¶
The return codes of the nvTIFF Decode APIs are listed below:
#define NVTIFF_DECODE_SUCCESS (0)
#define NVTIFF_DECODE_INVALID_CTX (1)
#define NVTIFF_DECODE_INVALID_RANGE (2)
Description the Return Codes
Return Code |
Description |
---|---|
NVTIFF_DECODE_SUCCESS (0) |
The API call has finished successfully. Note that many of the calls are asynchronous and some of the errors may be seen only after synchronization. |
NVTIFF_DECODE_INVALID_CTX (1) |
Invalid CTX. |
NVTIFF_DECODE_INVALID_RANGE (2) |
Range of subfiles not valid |
nvTIFF Encode API Return Status Codes¶
The return codes of the nvTIFF Encode APIs are listed below:
#define NVTIFF_ENCODE_SUCCESS (0)
#define NVTIFF_ENCODE_INVALID_CTX (1)
#define NVTIFF_ENCODE_INVALID_STRIP_NUM (2)
#define NVTIFF_ENCODE_COMP_OVERFLOW (3)
#define NVTIFF_ENCODE_COMP_STRIP_TOO_LONG (4)
Description the Return Codes
Return Code |
Description |
---|---|
NVTIFF_ENCODE_SUCCESS (0) |
The API call has finished successfully. Note that many of the calls are asynchronous and some of the errors may be seen only after synchronization. |
NVTIFF_ENCODE_INVALID_CTX (1) |
Invalid CTX. |
NVTIFF_ENCODE_INVALID_STRIP_NUM (2) |
Invalid strip number |
NVTIFF_ENCODE_COMP_OVERFLOW (3) |
overflow during compression |
NVTIFF_ENCODE_COMP_STRIP_TOO_LONG (4) |
Too long strip |
nvTIFF Write API Return Status Codes¶
The return codes of the nvTIFF Write APIs are listed below:
#define NVTIFF_WRITE_SUCCESS (0)
#define NVTIFF_WRITE_UNSUPP_PLANAR_CONF (1)
#define NVTIFF_WRITE_UNSUPP_PHOTOMETRIC_INT (2)
Description the Return Codes
Return Code |
Description |
---|---|
NVTIFF_WRITE_SUCCESS (0) |
The API call has finished successfully. Note that many of the calls are asynchronous and some of the errors may be seen only after synchronization. |
NVTIFF_WRITE_UNSUPP_PLANAR_CONF (1) |
if the value of planarConf parameter is not equal to 1;. |
NVTIFF_WRITE_UNSUPP_PHOTOMETRIC_INT (2) |
if the value of photometricInt parameter is neither 1 nor 2; |
API Reference¶
Decoding API Reference¶
Open a TIFF file and returns a pointer to a nvTiffFile_t object containing the file data.
Signature:
nvTiffFile_t NVTIFFAPI *nvTiffOpen(int dev,
const char *fname,
int hostMemType=NVTIFF_MEM_REG);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
int dev |
Input |
device to use for CUDA calls |
|
const char *fname |
Input |
Host |
path to TIFF file to open. |
int hostMemType=NVTIFF_MEM_REG |
Input |
specifies whether pinned or pageable memory should be used for the buffer allocated to read the content of the TIFF file “fname”. Possible values are NVTIFF_MEM_PIN or NVTIFF_MEM_REG. If pageable memory is used, then the file content is also copied in a device buffer before the function returns. In case of pinned memory instead, no Host2Device copy is performed. |
Closes an opened TIFF file read into a nvTiffFile_t object, freeing all the allocated memory (on both the host and the device).
Signature:
void nvTiffClose(nvTiffFile_t *tiffFile);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffFile_t *tiffFile |
Input |
Closes an opened TIFF file read into a nvTiffFile_t object |
Copies the file data read by nvTiffOpen() from the internal host buffer to the internal device buffer.
This function is fully asynchronous.
This function is useful when nvTiffOpen() is called withhostMemType=NVTIFF_MEM_PIN in order to overlap the copy of the data with something else before calling the decoding functions nvTiffDecode() or nvTiffDecodeRange(). Please note that in case the file buffer is allocated with pinned memory, if this function is not called, then the decode functions will directly read the pinned host buffer via zero-copy.
This function as no effect in case nvTiffOpen() is called with hostMemType=NVTIFF_MEM_REG.
Signature:
void NVTIFFAPI nvTiffH2DAsync(nvTiffFile_t *tiffFile,
cudaStream_t stream=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffFile_t *tiffFile |
Input |
nvtiff file |
Perform the decoding of the image data on the GPU specified in “tiffFile” using a specified stream. Each image in the TIFF file is copied into the respective buffer pointed to by “imageOut_d”. This function is fully asynchronous.
Signature:
int nvTiffDecode(nvTiffFile_t *tiffFile,
unsigned char **imageOut_d,
cudaStream_t stream=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffFile_t *tiffFile |
Input |
The nvTiffFile_t object in which the TIFF file has been read. |
|
unsigned char **imageOut_d |
Output |
Host |
host array (of size tiffData->nSubFiles) of pointers to device buffers. Each device buffer is expected to have size at least: tiffData->subFiles[0].nrow * tiffData->subFiles[0].ncol * (tiffData->subFiles[0].bitsPerPixel/8) |
cudaStream_t stream |
Input |
the stream to use for the kernel launches. |
Returns:
NVTIFF_DECODE_SUCCESS
- on success.
NVTIFF_DECODE_INVALID_CTX
- if tiffFile is invalid.
This function is similar to nvTiffDecode() with the difference that it allows to specify a range of images to be decoded (instead of decoding all images in the file).
Signature:
int nvTiffDecodeRange(nvTiffFile_t *tiffFile,
unsigned int subFileStart,
unsigned int subFileNum,
unsigned char **imageOut_d,
cudaStream_t stream=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffFile_t *tiffFile |
Input |
The nvTiffFile_t object in which the TIFF file has been read. |
|
unsigned int subFileStart |
Input |
index of the first image to decode, in [0, tiffData->nSubFiles). |
|
unsigned int subFileNum |
Input |
number of images to decode starting from “subFileStart”, in (0, tiffData->nSubFiles] |
|
unsigned char **imageOut_d |
Output |
Host |
host array (of size tiffData->nSubFiles) of pointers to device buffers. Each device buffer is expected to have size at least: tiffData->subFiles[0].nrow * tiffData->subFiles[0].ncol * (tiffData->subFiles[0].bitsPerPixel/8) |
cudaStream_t stream |
Input |
the stream to use for the kernel launches. |
Returns:
NVTIFF_DECODE_SUCCESS
- on success.
NVTIFF_DECODE_INVALID_CTX
- if tiffFile is invalid.
NVTIFF_DECODE_INVALID_RANGE
- if (subFileStart, subFileNum) specify and invalid range of images.
Encoding API Reference¶
This function encoding context based on the specified parameters that can be used to perform a parallel LZW compression of images.
Signature:
nvTiffEncodeCtx_t nvTiffEncodeCtxCreate(int dev,
unsigned int imagesMax,
unsigned int stripsPerImageMax,
size_t memLimit=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
int dev |
Input |
Device to use for CUDA calls and kernel launches |
|
unsigned int imagesMax |
Input |
maximum number of images that will be encoded using the returned context |
|
unsigned int stripsPerImageMax |
Input |
maximum number of strips that the images that will be encoded using the returned context will be partitioned into |
|
size_t memLimit |
Input |
maximum amount of device memory that can be used to allocate the internal buffers required by the strip compression kernel |
Returns:
SUCCESS
- on success returns a pointer to nvTiffEncodeCtx_t
NULL
- otherwise.
Destroys context ctx freeing all the allocated memory on both the host and the device.
Signature:
void nvTiffEncodeCtxDestroy(nvTiffEncodeCtx_t *ctx);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffEncodeCtx_t *ctx |
Input |
Destroys context ctx freeing all the allocated memory on both the host and the device. |
Perform the encoding of multiple images using the resources specified by the encoding context. Each image is divided into strips formed by groups of consecutive rows and then each strip is compressed using LZW independently.
This function is fully asynchronous.
Signature:
int NVTIFFAPI nvTiffEncode(nvTiffEncodeCtx_t *ctx,
unsigned int nrow,
unsigned int ncol,
unsigned int pixelSize,
unsigned int rowsPerStrip,
unsigned int nImages,
unsigned char **images_d,
unsigned long long stripAllocSize,
unsigned long long *stripSize_d,
unsigned long long *stripOffs_d,
unsigned char *stripData_d,
cudaStream_t stream=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffEncodeCtx_t *ctx |
Input |
the nvTiffEncodeCtx_t returned by nvTiffEncodeCtxCreate(); |
|
unsigned int nrow |
Input |
number of rows of the images to compress; |
|
unsigned int ncol |
Input |
number of columns of the images to compress; |
|
unsigned int pixelSize |
Input |
pixel size, in bytes, for the images to compress; |
|
unsigned int rowsPerStrip |
Input |
number of rows to be compressed together in a single strip; |
|
unsigned int nImages |
Input |
number of images to compress; |
|
unsigned char **images_d |
Input |
Host |
host array of size nImages of pointers to device buffers |
unsigned long long stripAllocSize |
Input |
the estimated maximum size for compressed strips; |
|
unsigned int *stripSize_d |
Output |
Device |
device array of size at least ceil(nrow/rowsPerStrip)*nImages |
unsigned int *stripOffs_d |
Output |
Device |
device array of size at least ceil(nrow/rowsPerStrip)*nImages |
unsigned long long *stripData_d |
Output |
Device |
device array of size at least ceil(nrow/rowsPerStrip)*nImages*stripAllocSize in which the compressed strips are returned |
stream |
Input |
the stream to use for the kernel launches |
Returns:
NVTIFF_ENCODE_SUCCESS
- on success, the compressed strips can be accessed after the subsequent call to nvTiffEncodeFinalize(), see below;
NVTIFF_ENCODE_INVALID_CTX
- ctx is invalid.
NVTIFF_ENCODE_INVALID_STRIP_NUM
- if the specified nrow, rowsPerStrip and nImages amount to a number of strips to be compressed greater than those specified by the parameters imagesMax and stripsPerImageMax
specified at the creation of the context ctx;
This function completes the compression process initiated by nvTiffEncode(). Since nvTiffEncode() is asynchronous, the state about its runtime operations is checked via this finalization call.
Signature:
int nvTiffEncodeFinalize(nvTiffEncodeCtx_t *ctx,
cudaStream_t stream=0);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
nvTiffEncodeCtx_t *ctx |
Input |
the nvTiffEncodeCtx_t passed to nvTiffEncode(); |
|
stream |
Input |
the stream to use for the kernel launches |
Returns:
NVTIFF_ENCODE_SUCCESS
- on success; the strips sizes, offsets and data can be accessed in the array stripSize_d,
stripOffs_d, stripData_d passed to nvTiffEncode() after all the operations enqueued on stream are concluded;
NVTIFF_ENCODE_INVALID_CTX
- ctx is invalid.
NVTIFF_ENCODE_COMP_STRIP_TOO_LONG
- currently the compression procedure supports strips with a compressed size up to 48KB;
if one strip would be compressed into a larger size then this error is returned
NVTIFF_ENCODE_COMP_OVERFLOW
- this error is returned in case one or more strips compress to a size grater than the value of the
parameter stripAllocSize passed to nvTiffEncode()
This is a convenience function to write compressed images to a single TIFF file. Library users may want to implement their own function to use additional/custom TIFF tags.
Signature:
int nvTiffWriteFile(const char *fname,
int tiffVer,
unsigned int nImages,
unsigned int nrow,
unsigned int ncol,
unsigned int rowsPerStrip,
unsigned short samplesPerPixel,
unsigned short *bitsPerSample,
unsigned int photometricInt,
unsigned int planarConf,
unsigned long long *stripSize,
unsigned long long *stripOffs,
unsigned char *stripData);
Parameters:
Parameter |
Input/Output |
Memory |
Description |
---|---|---|---|
const char *fname |
Input |
Host |
the name of the output TIFF file; |
int tiffVer |
Input |
specifies whether to use regular Tiff or a BigTiff file format; for regular Tiff use VER_REG_TIFF; for BigTiff use VER_BIG_TIFF; |
|
unsigned int nImages |
Input |
number of images to write into the file |
|
unsigned int nrow |
Input |
number of rows of every image |
|
unsigned int ncol |
Input |
number of columns of every image; |
|
unsigned int rowsPerStrip |
Input |
number of rows that form a Tiff strip |
|
unsigned short samplesPerPixel |
Input |
number of components per pixel |
|
unsigned short bitsPerSample |
Input |
array of length samplesPerPixel specifying the number of bits per component; |
|
unsigned int photometricInt |
Input |
color space of the image data; supported values: 1 or 2; |
|
unsigned int planarConf |
Input |
how the components of each pixel are stored; supported values: 1 (chunky format); |
|
unsigned long long *stripSize |
Input |
Host |
host array of size ceil(nrow/rowsPerStrip)*nImages containing the length of the compressed strips; |
unsigned long long *stripOffs |
Input |
Host |
host array of size ceil(nrow/rowsPerStrip)*nImages containing the starting offset of the compressed strips inside the stripData buffer; |
unsigned char *stripData |
Input |
Host |
host array containing the ceil(nrow/rowsPerStrip)*nImages compressed strips; strips are expected to be stored one after the other starting from the first image to the last, from the top to bottom; |
Returns:
NVTIFF_WRITE_SUCCESS
- on success
NVTIFF_WRITE_UNSUPP_PLANAR_CONF
- if the value of planarConf parameter is not equal to 1;.
NVTIFF_WRITE_UNSUPP_PHOTOMETRIC_INT
- if the value of photometricInt parameter is neither 1 nor 2;