1ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/* $Id: tif_strip.c,v 1.36 2015-06-07 22:35:40 bfriesen Exp $ */
2ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
3ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
4ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Copyright (c) 1991-1997 Sam Leffler
5ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Copyright (c) 1991-1997 Silicon Graphics, Inc.
6ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann *
7ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Permission to use, copy, modify, distribute, and sell this software and
8ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * its documentation for any purpose is hereby granted without fee, provided
9ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * that (i) the above copyright notices and this permission notice appear in
10ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * all copies of the software and related documentation, and (ii) the names of
11ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Sam Leffler and Silicon Graphics may not be used in any advertising or
12ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * publicity relating to the software without the specific, prior written
13ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * permission of Sam Leffler and Silicon Graphics.
14ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann *
15ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann *
19ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * OF THIS SOFTWARE.
25ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
26ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
27ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
28ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * TIFF Library.
29ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann *
30ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Strip-organized Image Support Routines.
31ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
32ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#include "tiffiop.h"
33ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
34ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
35ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute which strip a (row,sample) value is in.
36ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
37ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint32
38ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFComputeStrip(TIFF* tif, uint32 row, uint16 sample)
39ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
40ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFComputeStrip";
41ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory *td = &tif->tif_dir;
42ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint32 strip;
43ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
44ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	strip = row / td->td_rowsperstrip;
45ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
46ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if (sample >= td->td_samplesperpixel) {
47ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			TIFFErrorExt(tif->tif_clientdata, module,
48ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			    "%lu: Sample out of range, max %lu",
49ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			    (unsigned long) sample, (unsigned long) td->td_samplesperpixel);
50ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			return (0);
51ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
52ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		strip += (uint32)sample*td->td_stripsperimage;
53ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
54ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return (strip);
55ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
56ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
57ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
58ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute how many strips are in an image.
59ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
60ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint32
61ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFNumberOfStrips(TIFF* tif)
62ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
63ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory *td = &tif->tif_dir;
64ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint32 nstrips;
65ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
66ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
67ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	     TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
68ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
69ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		nstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,
70ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    "TIFFNumberOfStrips");
71ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return (nstrips);
72ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
73ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
74ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
75ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute the # bytes in a variable height, row-aligned strip.
76ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
77ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint64
78ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFVStripSize64(TIFF* tif, uint32 nrows)
79ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
80ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFVStripSize64";
81ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory *td = &tif->tif_dir;
82ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (nrows==(uint32)(-1))
83ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		nrows=td->td_imagelength;
84ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&
85ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	    (td->td_photometric == PHOTOMETRIC_YCBCR)&&
86ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	    (!isUpSampled(tif)))
87ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
88ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		/*
89ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * Packed YCbCr data contain one Cb+Cr for every
90ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * HorizontalSampling*VerticalSampling Y values.
91ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * Must also roundup width and height when calculating
92ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * since images that are not a multiple of the
93ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * horizontal/vertical subsampling area include
94ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * YCbCr data for the extended image.
95ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 */
96ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint16 ycbcrsubsampling[2];
97ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint16 samplingblock_samples;
98ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint32 samplingblocks_hor;
99ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint32 samplingblocks_ver;
100ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint64 samplingrow_samples;
101ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint64 samplingrow_size;
102ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if(td->td_samplesperpixel!=3)
103ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		{
104ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			TIFFErrorExt(tif->tif_clientdata,module,
105ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			    "Invalid td_samplesperpixel value");
106ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			return 0;
107ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
108ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,
109ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    ycbcrsubsampling+1);
110ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if ((ycbcrsubsampling[0] != 1 && ycbcrsubsampling[0] != 2 && ycbcrsubsampling[0] != 4)
111ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    ||(ycbcrsubsampling[1] != 1 && ycbcrsubsampling[1] != 2 && ycbcrsubsampling[1] != 4))
112ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		{
113ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			TIFFErrorExt(tif->tif_clientdata,module,
114ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann				     "Invalid YCbCr subsampling (%dx%d)",
115ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann				     ycbcrsubsampling[0],
116ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann				     ycbcrsubsampling[1] );
117ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			return 0;
118ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
119ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		samplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;
120ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		samplingblocks_hor=TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]);
121ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		samplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);
122ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		samplingrow_samples=_TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module);
123ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		samplingrow_size=TIFFhowmany8_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module));
124ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		return(_TIFFMultiply64(tif,samplingrow_size,samplingblocks_ver,module));
125ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
126ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	else
127ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		return(_TIFFMultiply64(tif,nrows,TIFFScanlineSize64(tif),module));
128ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
129ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmanntmsize_t
130ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFVStripSize(TIFF* tif, uint32 nrows)
131ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
132ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFVStripSize";
133ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 m;
134ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	tmsize_t n;
135ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	m=TIFFVStripSize64(tif,nrows);
136ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	n=(tmsize_t)m;
137ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((uint64)n!=m)
138ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
139ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
140ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=0;
141ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
142ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(n);
143ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
144ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
145ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
146ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute the # bytes in a raw strip.
147ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
148ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint64
149ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFRawStripSize64(TIFF* tif, uint32 strip)
150ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
151ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFRawStripSize64";
152ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory* td = &tif->tif_dir;
153ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 bytecount = td->td_stripbytecount[strip];
154ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
155ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (bytecount == 0)
156ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
157ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
158ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata, module,
159ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     "%I64u: Invalid strip byte count, strip %lu",
160ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     (unsigned __int64) bytecount,
161ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     (unsigned long) strip);
162ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#else
163ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata, module,
164ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     "%llu: Invalid strip byte count, strip %lu",
165ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     (unsigned long long) bytecount,
166ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			     (unsigned long) strip);
167ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann#endif
168ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		bytecount = (uint64) -1;
169ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
170ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
171ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return bytecount;
172ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
173ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmanntmsize_t
174ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFRawStripSize(TIFF* tif, uint32 strip)
175ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
176ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFRawStripSize";
177ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 m;
178ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	tmsize_t n;
179ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	m=TIFFRawStripSize64(tif,strip);
180ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (m==(uint64)(-1))
181ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=(tmsize_t)(-1);
182ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	else
183ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
184ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=(tmsize_t)m;
185ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if ((uint64)n!=m)
186ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		{
187ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
188ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			n=0;
189ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
190ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
191ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(n);
192ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
193ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
194ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
195ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute the # bytes in a (row-aligned) strip.
196ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann *
197ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Note that if RowsPerStrip is larger than the
198ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * recorded ImageLength, then the strip size is
199ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * truncated to reflect the actual space required
200ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * to hold the strip.
201ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
202ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint64
203ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFStripSize64(TIFF* tif)
204ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
205ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory* td = &tif->tif_dir;
206ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint32 rps = td->td_rowsperstrip;
207ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (rps > td->td_imagelength)
208ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		rps = td->td_imagelength;
209ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return (TIFFVStripSize64(tif, rps));
210ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
211ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmanntmsize_t
212ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFStripSize(TIFF* tif)
213ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
214ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFStripSize";
215ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 m;
216ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	tmsize_t n;
217ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	m=TIFFStripSize64(tif);
218ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	n=(tmsize_t)m;
219ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((uint64)n!=m)
220ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
221ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");
222ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=0;
223ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
224ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(n);
225ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
226ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
227ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
228ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Compute a default strip size based on the image
229ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * characteristics and a requested value.  If the
230ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * request is <1 then we choose a strip size according
231ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * to certain heuristics.
232ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
233ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint32
234ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFDefaultStripSize(TIFF* tif, uint32 request)
235ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
236ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return (*tif->tif_defstripsize)(tif, request);
237ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
238ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
239ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint32
240ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann_TIFFDefaultStripSize(TIFF* tif, uint32 s)
241ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
242ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((int32) s < 1) {
243ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		/*
244ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * If RowsPerStrip is unspecified, try to break the
245ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * image up into strips that are approximately
246ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 * STRIP_SIZE_DEFAULT bytes long.
247ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		 */
248ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint64 scanlinesize;
249ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		uint64 rows;
250ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		scanlinesize=TIFFScanlineSize64(tif);
251ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if (scanlinesize==0)
252ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			scanlinesize=1;
253ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		rows=(uint64)STRIP_SIZE_DEFAULT/scanlinesize;
254ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if (rows==0)
255ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			rows=1;
256ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		else if (rows>0xFFFFFFFF)
257ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			rows=0xFFFFFFFF;
258ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		s=(uint32)rows;
259ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
260ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return (s);
261ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
262ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
263ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
264ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Return the number of bytes to read/write in a call to
265ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * one of the scanline-oriented i/o routines.  Note that
266ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * this number may be 1/samples-per-pixel if data is
267ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * stored as separate planes.
268ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * The ScanlineSize in case of YCbCrSubsampling is defined as the
269ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * strip size divided by the strip height, i.e. the size of a pack of vertical
270ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * subsampling lines divided by vertical subsampling. It should thus make
271ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * sense when multiplied by a multiple of vertical subsampling.
272ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
273ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint64
274ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFScanlineSize64(TIFF* tif)
275ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
276ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFScanlineSize64";
277ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory *td = &tif->tif_dir;
278ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 scanline_size;
279ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (td->td_planarconfig==PLANARCONFIG_CONTIG)
280ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
281ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		if ((td->td_photometric==PHOTOMETRIC_YCBCR)&&
282ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    (td->td_samplesperpixel==3)&&
283ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    (!isUpSampled(tif)))
284ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		{
285ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint16 ycbcrsubsampling[2];
286ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint16 samplingblock_samples;
287ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint32 samplingblocks_hor;
288ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint64 samplingrow_samples;
289ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint64 samplingrow_size;
290ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			if(td->td_samplesperpixel!=3)
291ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			{
292ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                            TIFFErrorExt(tif->tif_clientdata,module,
293ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                                         "Invalid td_samplesperpixel value");
294ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                            return 0;
295ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			}
296ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			TIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,
297ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                                              ycbcrsubsampling+0,
298ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                                              ycbcrsubsampling+1);
299ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			if (((ycbcrsubsampling[0]!=1)&&(ycbcrsubsampling[0]!=2)&&(ycbcrsubsampling[0]!=4)) ||
300ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			    ((ycbcrsubsampling[1]!=1)&&(ycbcrsubsampling[1]!=2)&&(ycbcrsubsampling[1]!=4)))
301ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			{
302ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                            TIFFErrorExt(tif->tif_clientdata,module,
303ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                                         "Invalid YCbCr subsampling");
304ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                            return 0;
305ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			}
306ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			samplingblock_samples = ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;
307ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			samplingblocks_hor = TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]);
308ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			samplingrow_samples = _TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module);
309ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			samplingrow_size = TIFFhowmany_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module),8);
310ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			scanline_size = (samplingrow_size/ycbcrsubsampling[1]);
311ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
312ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		else
313ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		{
314ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			uint64 scanline_samples;
315ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			scanline_samples=_TIFFMultiply64(tif,td->td_imagewidth,td->td_samplesperpixel,module);
316ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann			scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,scanline_samples,td->td_bitspersample,module),8);
317ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		}
318ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
319ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	else
320ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann        {
321ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		scanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,td->td_imagewidth,td->td_bitspersample,module),8);
322ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann        }
323ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann        if (scanline_size == 0)
324ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann        {
325ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                TIFFErrorExt(tif->tif_clientdata,module,"Computed scanline size is zero");
326ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann                return 0;
327ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann        }
328ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(scanline_size);
329ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
330ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmanntmsize_t
331ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFScanlineSize(TIFF* tif)
332ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
333ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFScanlineSize";
334ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 m;
335ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	tmsize_t n;
336ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	m=TIFFScanlineSize64(tif);
337ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	n=(tmsize_t)m;
338ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((uint64)n!=m) {
339ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");
340ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=0;
341ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
342ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(n);
343ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
344ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
345ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
346ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Return the number of bytes required to store a complete
347ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * decoded and packed raster scanline (as opposed to the
348ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * I/O size returned by TIFFScanlineSize which may be less
349ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * if data is store as separate planes).
350ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
351ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmannuint64
352ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFRasterScanlineSize64(TIFF* tif)
353ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
354ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFRasterScanlineSize64";
355ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	TIFFDirectory *td = &tif->tif_dir;
356ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 scanline;
357ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
358ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	scanline = _TIFFMultiply64(tif, td->td_bitspersample, td->td_imagewidth, module);
359ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if (td->td_planarconfig == PLANARCONFIG_CONTIG) {
360ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		scanline = _TIFFMultiply64(tif, scanline, td->td_samplesperpixel, module);
361ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		return (TIFFhowmany8_64(scanline));
362ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	} else
363ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		return (_TIFFMultiply64(tif, TIFFhowmany8_64(scanline),
364ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		    td->td_samplesperpixel, module));
365ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
366ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmanntmsize_t
367ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. MoltmannTIFFRasterScanlineSize(TIFF* tif)
368ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann{
369ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	static const char module[] = "TIFFRasterScanlineSize";
370ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	uint64 m;
371ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	tmsize_t n;
372ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	m=TIFFRasterScanlineSize64(tif);
373ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	n=(tmsize_t)m;
374ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	if ((uint64)n!=m)
375ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	{
376ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");
377ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann		n=0;
378ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	}
379ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann	return(n);
380ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann}
381ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann
382ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/* vim: set ts=8 sts=8 sw=8 noet: */
383ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann/*
384ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * Local Variables:
385ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * mode: c
386ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * c-basic-offset: 8
387ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * fill-column: 78
388ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann * End:
389ac3d58cff7c80b0ef56bf55130d91da17cbaa3c4Philip P. Moltmann */
390