home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / netpbm_src.lzh / NETPBM / LIBTIFF / tif_strip.c < prev    next >
Text File  |  1996-11-18  |  4KB  |  117 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_strip.c,v 1.13 93/08/26 14:27:09 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library.
  31.  *
  32.  * Strip-organized Image Support Routines.
  33.  */
  34. #include "tiffiop.h"
  35.  
  36. /*
  37.  * Compute which strip a (row,sample) value is in.
  38.  */
  39. tstrip_t
  40. TIFFComputeStrip(TIFF* tif, uint32 row, tsample_t sample)
  41. {
  42.     TIFFDirectory *td = &tif->tif_dir;
  43.     tstrip_t strip;
  44.  
  45.     strip = row / td->td_rowsperstrip;
  46.     if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
  47.         if (sample >= td->td_samplesperpixel) {
  48.             TIFFError(tif->tif_name,
  49.                 "%u: Sample out of range, max %u",
  50.                 sample, td->td_samplesperpixel);
  51.             return ((tstrip_t) 0);
  52.         }
  53.         strip += sample*td->td_stripsperimage;
  54.     }
  55.     return (strip);
  56. }
  57.  
  58. /*
  59.  * Compute how many strips are in an image.
  60.  */
  61. tstrip_t
  62. TIFFNumberOfStrips(TIFF* tif)
  63. {
  64.     TIFFDirectory *td = &tif->tif_dir;
  65.     tstrip_t nstrips;
  66.  
  67.     nstrips = (td->td_rowsperstrip == 0xffffffff ?
  68.          (td->td_imagelength != 0 ? 1 : 0) :
  69.          howmany(td->td_imagelength, td->td_rowsperstrip));
  70.     if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
  71.         nstrips *= td->td_samplesperpixel;
  72.     return (nstrips);
  73. }
  74.  
  75. /*
  76.  * Compute the # bytes in a variable height, row-aligned strip.
  77.  */
  78. tsize_t
  79. TIFFVStripSize(TIFF* tif, uint32 nrows)
  80. {
  81.     TIFFDirectory *td = &tif->tif_dir;
  82.  
  83.     if (nrows == (uint32) -1)
  84.         nrows = td->td_imagelength;
  85. #ifdef YCBCR_SUPPORT
  86.     if (td->td_planarconfig == PLANARCONFIG_CONTIG &&
  87.         td->td_photometric == PHOTOMETRIC_YCBCR) {
  88.         /*
  89.          * Packed YCbCr data contain one Cb+Cr for every
  90.          * HorizontalSampling*VerticalSampling Y values.
  91.          * Must also roundup width and height when calculating
  92.          * since images that are not a multiple of the
  93.          * horizontal/vertical subsampling area include
  94.          * YCbCr data for the extended image.
  95.          */
  96.         tsize_t w =
  97.             roundup(td->td_imagewidth, td->td_ycbcrsubsampling[0]);
  98.         tsize_t scanline = howmany(w*td->td_bitspersample, 8);
  99.         tsize_t samplingarea =
  100.             td->td_ycbcrsubsampling[0]*td->td_ycbcrsubsampling[1];
  101.         nrows = roundup(nrows, td->td_ycbcrsubsampling[1]);
  102.         /* NB: don't need howmany here 'cuz everything is rounded */
  103.         return (nrows*scanline + 2*(nrows*scanline / samplingarea));
  104.     } else
  105. #endif
  106.         return (nrows * TIFFScanlineSize(tif));
  107. }
  108.  
  109. /*
  110.  * Compute the # bytes in a (row-aligned) strip.
  111.  */
  112. tsize_t
  113. TIFFStripSize(TIFF* tif)
  114. {
  115.     return (TIFFVStripSize(tif, tif->tif_dir.td_rowsperstrip));
  116. }
  117.