43 static const char module[] = "TIFFComputeStrip";
47 if (td->td_rowsperstrip == 0)
50 "Cannot compute strip: RowsPerStrip is zero");
53 strip = row / td->td_rowsperstrip;
56 uint64_t sample_offset;
58 if (sample >= td->td_samplesperpixel)
60 TIFFErrorExtR(tif, module,
"%lu: Sample out of range, max %lu",
61 (
unsigned long)sample,
62 (
unsigned long)td->td_samplesperpixel);
67 if (sample_offset == 0 && sample != 0 && td->td_stripsperimage != 0)
69 strip64 =
_TIFFAdd64(tif, sample_offset, strip,
"TIFFComputeStrip");
70 if (strip64 == 0 && (sample_offset != 0 || strip != 0))
73 if (strip == 0 && strip64 != 0)
98 "TIFFNumberOfStrips");
108 static const char module[] = "_TIFFStrileSize64";
112 if (nrows == (uint32_t)(-1))
117 if (td->td_tilelength == 0 || td->td_tilewidth == 0 ||
118 td->td_tiledepth == 0)
132 uint16_t ycbcrsubsampling[2];
133 uint16_t samplingblock_samples;
134 uint32_t samplingblocks_hor;
135 uint32_t samplingblocks_ver;
136 uint64_t samplingrow_samples;
137 uint64_t samplingrow_size;
138 if (td->td_samplesperpixel != 3)
140 TIFFErrorExtR(tif, module,
"Invalid td_samplesperpixel value");
144 ycbcrsubsampling + 0, ycbcrsubsampling + 1);
145 if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 &&
146 ycbcrsubsampling[0] != 4) ||
147 (ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 &&
148 ycbcrsubsampling[1] != 4) ||
149 (ycbcrsubsampling[0] == 0 || ycbcrsubsampling[1] == 0))
151 TIFFErrorExtR(tif, module,
"Invalid YCbCr subsampling (%dx%d)",
152 ycbcrsubsampling[0], ycbcrsubsampling[1]);
155 samplingblock_samples =
156 (uint16_t)(ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2);
157 const uint32_t width = isStrip ? td->td_imagewidth : td->td_tilewidth;
161 samplingblock_samples, module);
163 tif, samplingrow_samples, td->td_bitspersample, module));
184 static const char module[] = "TIFFVStripSize";
195 static const char module[] = "TIFFRawStripSize64";
201 "%" PRIu64
": Invalid strip byte count, strip %lu",
202 (uint64_t)bytecount, (
unsigned long)strip);
203 bytecount = (uint64_t)-1;
210 static const char module[] = "TIFFRawStripSize";
214 if (m == (uint64_t)(-1))
219 if ((uint64_t)n != m)
246 static const char module[] = "TIFFStripSize";
272 uint64_t scanlinesize;
275 if (scanlinesize == 0)
280 else if (rows > 0xFFFFFFFF)
299 static const char module[] = "TIFFScanlineSize64";
301 uint64_t scanline_size;
305 (td->td_samplesperpixel == 3) && (!
isUpSampled(tif)))
307 uint16_t ycbcrsubsampling[2];
308 uint16_t samplingblock_samples;
309 uint32_t samplingblocks_hor;
310 uint64_t samplingrow_samples;
311 uint64_t samplingrow_size;
312 if (td->td_samplesperpixel != 3)
314 TIFFErrorExtR(tif, module,
"Invalid td_samplesperpixel value");
318 ycbcrsubsampling + 0, ycbcrsubsampling + 1);
319 if (((ycbcrsubsampling[0] != 1) && (ycbcrsubsampling[0] != 2) &&
320 (ycbcrsubsampling[0] != 4)) ||
321 ((ycbcrsubsampling[1] != 1) && (ycbcrsubsampling[1] != 2) &&
322 (ycbcrsubsampling[1] != 4)) ||
323 ((ycbcrsubsampling[0] == 0) || (ycbcrsubsampling[1] == 0)))
328 samplingblock_samples =
329 (uint16_t)(ycbcrsubsampling[0] * ycbcrsubsampling[1] + 2);
333 tif, samplingblocks_hor, samplingblock_samples, module);
336 td->td_bitspersample, module),
338 scanline_size = (samplingrow_size / ycbcrsubsampling[1]);
342 uint64_t scanline_samples;
343 uint32_t scanline_width = td->td_imagewidth;
351 uint16_t subsampling_hor;
354 &subsampling_hor, &ignored);
355 if (subsampling_hor > 1)
362 td->td_samplesperpixel, module);
365 td->td_bitspersample, module),
373 td->td_bitspersample, module),
376 if (scanline_size == 0)
378 TIFFErrorExtR(tif, module,
"Computed scanline size is zero");
381 return (scanline_size);
385 static const char module[] = "TIFFScanlineSize";
399 static const char module[] = "TIFFRasterScanlineSize64";
413 td->td_samplesperpixel, module));
417 static const char module[] = "TIFFRasterScanlineSize";
uint32_t _TIFFCastUInt64ToUInt32(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
uint64_t _TIFFAdd64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Check and add two unsigned operands.
uint32_t _TIFFMultiply32(TIFF *tif, uint32_t first, uint32_t second, const char *where)
Multiply two unsigned values with an overflow check.
tmsize_t _TIFFCastUInt64ToSSize(TIFF *tif, uint64_t val, const char *module)
Convert an unsigned 64-bit value after checking the destination range.
uint64_t _TIFFMultiply64(TIFF *tif, uint64_t first, uint64_t second, const char *where)
Multiply two unsigned values with an overflow check.
#define STRIP_SIZE_DEFAULT
Define the default target strip size in bytes.
uint64_t _TIFFStrileSize64(TIFF *tif, uint32_t nrows, int isStrip)
Compute row-aligned decoded storage for a strip or tile-height request.
uint32_t _TIFFDefaultStripSize(TIFF *tif, uint32_t s)
Choose a default strip height near STRIP_SIZE_DEFAULT bytes.
#define TIFFhowmany_64(x, y)
Compute a 64-bit ceiling quotient using an unchecked addition.
#define isUpSampled(tif)
Test whether the codec reports upsampled output.
#define TIFFroundup_32(x, y)
Round a 32-bit value up to a multiple using the guarded quotient.
#define TRUE
Represent the legacy internal true value.
#define TIFFhowmany_32(x, y)
Compute a guarded 32-bit ceiling quotient.
#define TIFFhowmany8_64(x)
Compute the byte count needed to hold a 64-bit bit count.
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
tmsize_t TIFFStripSize(TIFF *tif)
Compute the decoded-size estimate for a nominal strip.
uint64_t TIFFRawStripSize64(TIFF *tif, uint32_t strip)
Query the stored byte count for one raw strip.
tmsize_t TIFFScanlineSize(TIFF *tif)
Compute the current scanline I/O byte estimate.
tmsize_t TIFFVStripSize(TIFF *tif, uint32_t nrows)
Compute the decoded-size estimate for a requested strip height.
uint64_t TIFFScanlineSize64(TIFF *tif)
Compute the current scanline I/O byte estimate.
uint32_t TIFFNumberOfStrips(TIFF *tif)
Compute the strip count from current image geometry.
uint32_t TIFFComputeStrip(TIFF *tif, uint32_t row, uint16_t sample)
Compute a strip index from a row and optional sample plane.
uint64_t TIFFVStripSize64(TIFF *tif, uint32_t nrows)
Compute the decoded-size estimate for a requested strip height.
tmsize_t TIFFRawStripSize(TIFF *tif, uint32_t strip)
Convert one raw-strip byte count to the legacy signed-size result.
uint64_t TIFFStripSize64(TIFF *tif)
Compute the decoded-size estimate for a nominal strip.
uint32_t TIFFDefaultStripSize(TIFF *tif, uint32_t request)
Ask the installed sizing method for a RowsPerStrip recommendation.
uint64_t TIFFRasterScanlineSize64(TIFF *tif)
Compute the packed full-raster row byte count.
uint64_t TIFFTileRowSize64(TIFF *tif)
Compute the packed byte count of one tile row.
tmsize_t TIFFRasterScanlineSize(TIFF *tif)
Compute the packed full-raster row byte count.
int TIFFGetFieldDefaulted(TIFF *tif, uint32_t tag,...)
Query a present tag or a supported default.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
Store the current directory values and image traversal state.
uint32_t td_rowsperstrip
Rows per strip; UINT32_MAX represents one whole-image strip.
uint16_t td_planarconfig
PLANARCONFIG_* sample-plane arrangement.
uint16_t td_samplesperpixel
Samples per pixel, including extra samples.
uint32_t td_imagelength
Image length in rows.
Hold private state for one open TIFF library instance.
TIFFStripMethod tif_defstripsize
Codec callback computing or constraining a default strip size.
TIFFDirectory tif_dir
Inline representation of the current image directory.
Declare private library state, callbacks, and implementation helpers.