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_dumpmode.c < prev    next >
Text File  |  1996-11-18  |  3KB  |  114 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_dumpmode.c,v 1.33 93/08/26 14:24:23 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 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.  * "Null" Compression Algorithm Support.
  33.  */
  34. #include "tiffiop.h"
  35.  
  36. /*
  37.  * Encode a hunk of pixels.
  38.  */
  39. static int
  40. DumpModeEncode(TIFF* tif, tidata_t pp, tsize_t cc, tsample_t s)
  41. {
  42.     while (cc > 0) {
  43.         tsize_t n;
  44.  
  45.         n = cc;
  46.         if (tif->tif_rawcc + n > tif->tif_rawdatasize)
  47.             n = tif->tif_rawdatasize - tif->tif_rawcc;
  48.         /*
  49.          * Avoid copy if client has setup raw
  50.          * data buffer to avoid extra copy.
  51.          */
  52.         if (tif->tif_rawcp != pp)
  53.             memcpy(tif->tif_rawcp, pp, n);
  54.         tif->tif_rawcp += n;
  55.         tif->tif_rawcc += n;
  56.         pp += n;
  57.         cc -= n;
  58.         if (tif->tif_rawcc >= tif->tif_rawdatasize &&
  59.             !TIFFFlushData1(tif))
  60.             return (-1);
  61.     }
  62.     return (1);
  63. }
  64.  
  65. /*
  66.  * Decode a hunk of pixels.
  67.  */
  68. static int
  69. DumpModeDecode(TIFF* tif, tidata_t buf, tsize_t cc, tsample_t s)
  70. {
  71.     if (tif->tif_rawcc < cc) {
  72.         TIFFError(tif->tif_name,
  73.             "DumpModeDecode: Not enough data for scanline %d",
  74.             tif->tif_row);
  75.         return (0);
  76.     }
  77.     /*
  78.      * Avoid copy if client has setup raw
  79.      * data buffer to avoid extra copy.
  80.      */
  81.     if (tif->tif_rawcp != buf)
  82.         memcpy(buf, tif->tif_rawcp, cc);
  83.     tif->tif_rawcp += cc;
  84.     tif->tif_rawcc -= cc;
  85.     return (1);
  86. }
  87.  
  88. /*
  89.  * Seek forwards nrows in the current strip.
  90.  */
  91. static int
  92. DumpModeSeek(TIFF* tif, uint32 nrows)
  93. {
  94.     tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  95.     tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  96.     return (1);
  97. }
  98.  
  99. /*
  100.  * Initialize dump mode.
  101.  */
  102. int
  103. TIFFInitDumpMode(TIFF* tif)
  104. {
  105.     tif->tif_decoderow = DumpModeDecode;
  106.     tif->tif_decodestrip = DumpModeDecode;
  107.     tif->tif_decodetile = DumpModeDecode;
  108.     tif->tif_encoderow = DumpModeEncode;
  109.     tif->tif_encodestrip = DumpModeEncode;
  110.     tif->tif_encodetile = DumpModeEncode;
  111.     tif->tif_seek = DumpModeSeek;
  112.     return (1);
  113. }
  114.