home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / xloadimg.zip / xloadimage.4.1 / tiff / tif_dumpmode.c < prev    next >
C/C++ Source or Header  |  1993-10-21  |  4KB  |  161 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_dumpmode.c,v 1.23 92/02/10 19:06:35 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. #include <stdio.h>
  36. #include <assert.h>
  37.  
  38. #if USE_PROTOTYPES
  39. static    int DumpModeEncode(TIFF *, u_char *, int, u_int);
  40. static    int DumpModeDecode(TIFF *, u_char *, int, u_int);
  41. static    int DumpModeSeek(TIFF *, int);
  42. #else
  43. static    int DumpModeEncode(), DumpModeDecode(), DumpModeSeek();
  44. #endif
  45.  
  46. /*
  47.  * Initialize dump mode.
  48.  */
  49. TIFFInitDumpMode(tif)
  50.     register TIFF *tif;
  51. {
  52.     tif->tif_decoderow = DumpModeDecode;
  53.     tif->tif_decodestrip = DumpModeDecode;
  54.     tif->tif_decodetile = DumpModeDecode;
  55.     tif->tif_encoderow = DumpModeEncode;
  56.     tif->tif_encodestrip = DumpModeEncode;
  57.     tif->tif_encodetile = DumpModeEncode;
  58.     tif->tif_seek = DumpModeSeek;
  59.     return (1);
  60. }
  61.  
  62. /*
  63.  * Encode a hunk of pixels.
  64.  */
  65. static int
  66. DumpModeEncode(tif, pp, cc, s)
  67.     register TIFF *tif;
  68.     u_char *pp;
  69.     int cc;
  70.     u_int s;
  71. {
  72.     /*
  73.      * This may be overzealous, but avoids having to
  74.      * worry about byte alignment for the (potential)
  75.      * byte-swapping work below.
  76.      */
  77.     if (tif->tif_rawcc + cc > tif->tif_rawdatasize)
  78.         if (!TIFFFlushData1(tif))
  79.             return (-1);
  80.     while (cc > 0) {
  81.         int n;
  82.         if ((n = cc) > tif->tif_rawdatasize)
  83.             n = tif->tif_rawdatasize;
  84.         bcopy(pp, tif->tif_rawcp, n);
  85.         if (tif->tif_flags & TIFF_SWAB) {
  86.             switch (tif->tif_dir.td_bitspersample) {
  87.             case 16:
  88.                 assert((n & 3) == 0);
  89.                 TIFFSwabArrayOfShort((u_short *)tif->tif_rawcp,
  90.                     n/2);
  91.                 break;
  92.             case 32:
  93.                 assert((n & 15) == 0);
  94.                 TIFFSwabArrayOfLong((u_long *)tif->tif_rawcp,
  95.                     n/4);
  96.                 break;
  97.             }
  98.         }
  99.         tif->tif_rawcp += n;
  100.         tif->tif_rawcc += n;
  101.         pp += n;
  102.         cc -= n;
  103.         if (tif->tif_rawcc >= tif->tif_rawdatasize &&
  104.             !TIFFFlushData1(tif))
  105.             return (-1);
  106.     }
  107.     return (1);
  108. }
  109.  
  110. /*
  111.  * Decode a hunk of pixels.
  112.  */
  113. static int
  114. DumpModeDecode(tif, buf, cc, s)
  115.     register TIFF *tif;
  116.     u_char *buf;
  117.     int cc;
  118.     u_int s;
  119. {
  120.     if (tif->tif_rawcc < cc) {
  121.         TIFFError(tif->tif_name,
  122.             "DumpModeDecode: Not enough data for scanline %d",
  123.             tif->tif_row);
  124.         return (0);
  125.     }
  126.     /*
  127.      * Avoid copy if client has setup raw
  128.      * data buffer to avoid extra copy.
  129.      */
  130.     if (tif->tif_rawcp != (char*) buf)
  131.         bcopy(tif->tif_rawcp, buf, cc);
  132.     if (tif->tif_flags & TIFF_SWAB) {
  133.         switch (tif->tif_dir.td_bitspersample) {
  134.         case 16:
  135.             assert((cc & 3) == 0);
  136.             TIFFSwabArrayOfShort((u_short *)buf, cc/2);
  137.             break;
  138.         case 32:
  139.             assert((cc & 15) == 0);
  140.             TIFFSwabArrayOfLong((u_long *)buf, cc/4);
  141.             break;
  142.         }
  143.     }
  144.     tif->tif_rawcp += cc;
  145.     tif->tif_rawcc -= cc;
  146.     return (1);
  147. }
  148.  
  149. /*
  150.  * Seek forwards nrows in the current strip.
  151.  */
  152. static int
  153. DumpModeSeek(tif, nrows)
  154.     register TIFF *tif;
  155.     int nrows;
  156. {
  157.     tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  158.     tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  159.     return (1);
  160. }
  161.