]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/tif_strip.c
   4  * Copyright (c) 1991-1997 Sam Leffler 
   5  * Copyright (c) 1991-1997 Silicon Graphics, Inc. 
   7  * Permission to use, copy, modify, distribute, and sell this software and  
   8  * its documentation for any purpose is hereby granted without fee, provided 
   9  * that (i) the above copyright notices and this permission notice appear in 
  10  * all copies of the software and related documentation, and (ii) the names of 
  11  * Sam Leffler and Silicon Graphics may not be used in any advertising or 
  12  * publicity relating to the software without the specific, prior written 
  13  * permission of Sam Leffler and Silicon Graphics. 
  15  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,  
  16  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY  
  17  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.   
  19  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 
  20  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 
  21  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
  22  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF  
  23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE  
  30  * Strip-organized Image Support Routines. 
  35 summarize(TIFF
* tif
, size_t summand1
, size_t summand2
, const char* where
) 
  37         uint32  bytes 
= summand1 
+ summand2
; 
  39         if (bytes 
- summand1 
!= summand2
) { 
  40                 TIFFError(tif
->tif_name
, "Integer overflow in %s", where
); 
  48 multiply(TIFF
* tif
, size_t nmemb
, size_t elem_size
, const char* where
) 
  50         uint32  bytes 
= nmemb 
* elem_size
; 
  52         if (elem_size 
&& bytes 
/ elem_size 
!= nmemb
) { 
  53                 TIFFError(tif
->tif_name
, "Integer overflow in %s", where
); 
  61  * Compute which strip a (row,sample) value is in. 
  64 TIFFComputeStrip(TIFF
* tif
, uint32 row
, tsample_t sample
) 
  66         TIFFDirectory 
*td 
= &tif
->tif_dir
; 
  69         strip 
= row 
/ td
->td_rowsperstrip
; 
  70         if (td
->td_planarconfig 
== PLANARCONFIG_SEPARATE
) { 
  71                 if (sample 
>= td
->td_samplesperpixel
) { 
  72                         TIFFError(tif
->tif_name
, 
  73                             "%u: Sample out of range, max %u", 
  74                             sample
, td
->td_samplesperpixel
); 
  75                         return ((tstrip_t
) 0); 
  77                 strip 
+= sample
*td
->td_stripsperimage
; 
  83  * Compute how many strips are in an image. 
  86 TIFFNumberOfStrips(TIFF
* tif
) 
  88         TIFFDirectory 
*td 
= &tif
->tif_dir
; 
  91         nstrips 
= (td
->td_rowsperstrip 
== (uint32
) -1 ? 
  92              (td
->td_imagelength 
!= 0 ? 1 : 0) : 
  93              TIFFhowmany(td
->td_imagelength
, td
->td_rowsperstrip
)); 
  94         if (td
->td_planarconfig 
== PLANARCONFIG_SEPARATE
) 
  95                 nstrips 
= multiply(tif
, nstrips
, td
->td_samplesperpixel
, 
  96                                    "TIFFNumberOfStrips"); 
 101  * Compute the # bytes in a variable height, row-aligned strip. 
 104 TIFFVStripSize(TIFF
* tif
, uint32 nrows
) 
 106         TIFFDirectory 
*td 
= &tif
->tif_dir
; 
 108         if (nrows 
== (uint32
) -1) 
 109                 nrows 
= td
->td_imagelength
; 
 111         if (td
->td_planarconfig 
== PLANARCONFIG_CONTIG 
&& 
 112             td
->td_photometric 
== PHOTOMETRIC_YCBCR 
&& 
 115                  * Packed YCbCr data contain one Cb+Cr for every 
 116                  * HorizontalSampling*VerticalSampling Y values. 
 117                  * Must also roundup width and height when calculating 
 118                  * since images that are not a multiple of the 
 119                  * horizontal/vertical subsampling area include 
 120                  * YCbCr data for the extended image. 
 122                 uint16 ycbcrsubsampling
[2]; 
 123                 tsize_t w
, scanline
, samplingarea
; 
 125                 TIFFGetField( tif
, TIFFTAG_YCBCRSUBSAMPLING
,  
 126                               ycbcrsubsampling 
+ 0,  
 127                               ycbcrsubsampling 
+ 1 ); 
 129                 w 
= TIFFroundup(td
->td_imagewidth
, ycbcrsubsampling
[0]); 
 130                 scanline 
= TIFFhowmany8(multiply(tif
, w
, td
->td_bitspersample
, 
 132                 samplingarea 
= ycbcrsubsampling
[0]*ycbcrsubsampling
[1]; 
 133                 nrows 
= TIFFroundup(nrows
, ycbcrsubsampling
[1]); 
 134                 /* NB: don't need TIFFhowmany here 'cuz everything is rounded */ 
 135                 scanline 
= multiply(tif
, nrows
, scanline
, "TIFFVStripSize"); 
 137                     summarize(tif
, scanline
, 
 138                               multiply(tif
, 2, scanline 
/ samplingarea
, 
 139                                        "TIFFVStripSize"), "TIFFVStripSize")); 
 142                 return ((tsize_t
) multiply(tif
, nrows
, TIFFScanlineSize(tif
), 
 148  * Compute the # bytes in a raw strip. 
 151 TIFFRawStripSize(TIFF
* tif
, tstrip_t strip
) 
 153         TIFFDirectory
* td 
= &tif
->tif_dir
; 
 154         tsize_t bytecount 
= td
->td_stripbytecount
[strip
]; 
 156         if (bytecount 
<= 0) { 
 157                 TIFFError(tif
->tif_name
, 
 158                           "%lu: Invalid strip byte count, strip %lu", 
 159                           (u_long
) bytecount
, (u_long
) strip
); 
 160                 bytecount 
= (tsize_t
) -1; 
 167  * Compute the # bytes in a (row-aligned) strip. 
 169  * Note that if RowsPerStrip is larger than the 
 170  * recorded ImageLength, then the strip size is 
 171  * truncated to reflect the actual space required 
 175 TIFFStripSize(TIFF
* tif
) 
 177         TIFFDirectory
* td 
= &tif
->tif_dir
; 
 178         uint32 rps 
= td
->td_rowsperstrip
; 
 179         if (rps 
> td
->td_imagelength
) 
 180                 rps 
= td
->td_imagelength
; 
 181         return (TIFFVStripSize(tif
, rps
)); 
 185  * Compute a default strip size based on the image 
 186  * characteristics and a requested value.  If the 
 187  * request is <1 then we choose a strip size according 
 188  * to certain heuristics. 
 191 TIFFDefaultStripSize(TIFF
* tif
, uint32 request
) 
 193         return (*tif
->tif_defstripsize
)(tif
, request
); 
 197 _TIFFDefaultStripSize(TIFF
* tif
, uint32 s
) 
 201                  * If RowsPerStrip is unspecified, try to break the 
 202                  * image up into strips that are approximately 8Kbytes. 
 204                 tsize_t scanline 
= TIFFScanlineSize(tif
); 
 205                 s 
= (uint32
)(8*1024) / (scanline 
== 0 ? 1 : scanline
); 
 206                 if (s 
== 0)             /* very wide images */ 
 213  * Return the number of bytes to read/write in a call to 
 214  * one of the scanline-oriented i/o routines.  Note that 
 215  * this number may be 1/samples-per-pixel if data is 
 216  * stored as separate planes. 
 219 TIFFScanlineSize(TIFF
* tif
) 
 221         TIFFDirectory 
*td 
= &tif
->tif_dir
; 
 224         scanline 
= multiply (tif
, td
->td_bitspersample
, td
->td_imagewidth
, 
 226         if (td
->td_planarconfig 
== PLANARCONFIG_CONTIG
) 
 227                 scanline 
= multiply (tif
, scanline
, td
->td_samplesperpixel
, 
 229         return ((tsize_t
) TIFFhowmany8(scanline
)); 
 233  * Return the number of bytes required to store a complete 
 234  * decoded and packed raster scanline (as opposed to the 
 235  * I/O size returned by TIFFScanlineSize which may be less 
 236  * if data is store as separate planes). 
 239 TIFFRasterScanlineSize(TIFF
* tif
) 
 241         TIFFDirectory 
*td 
= &tif
->tif_dir
; 
 244         scanline 
= multiply (tif
, td
->td_bitspersample
, td
->td_imagewidth
, 
 245                              "TIFFRasterScanlineSize"); 
 246         if (td
->td_planarconfig 
== PLANARCONFIG_CONTIG
) { 
 247                 scanline 
= multiply (tif
, scanline
, td
->td_samplesperpixel
, 
 248                                      "TIFFRasterScanlineSize"); 
 249                 return ((tsize_t
) TIFFhowmany8(scanline
)); 
 251                 return ((tsize_t
) multiply (tif
, TIFFhowmany8(scanline
), 
 252                                             td
->td_samplesperpixel
, 
 253                                             "TIFFRasterScanlineSize"));