home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / grfx_snd / tifflib / source / tif_dump.c < prev    next >
C/C++ Source or Header  |  1992-11-08  |  3KB  |  109 lines

  1. #pragma warn -use
  2. static char     *sccsid = "@(#)TIFF/tif_dumpmode.c 1.12, Copyright (c) Sam Leffler, Dieter Linde, "__DATE__;
  3. #pragma warn .use
  4. /*
  5.  * Copyright (c) 1988, 1990 by Sam Leffler, Oct 8 1990
  6.  * All rights reserved.
  7.  *
  8.  * This file is provided for unrestricted use provided that this legend is included on all tape media and as a part of the
  9.  * software program in whole or part.  Users may copy, modify or distribute this file at will.
  10.  *
  11.  * TIFF Library.
  12.  *
  13.  * "Null" Compression Algorithm Support.
  14.  */
  15. #include <stdio.h>
  16. #include <assert.h>
  17. #include "tiffio.h"
  18.  
  19. /****************************************************************************
  20.  * Encode a scanline of pixels.
  21.  */
  22. static int
  23. DumpModeEncode(
  24.            register TIFF    *tif,
  25.         u_char         *buf,
  26.         int         cc
  27.         )
  28. {
  29.         if (tif->tif_rawcc + cc > tif->tif_rawdatasize)
  30.                 if (!TIFFFlushData(tif))
  31.                         return(-1);
  32.         bcopy(buf, tif->tif_rawcp, cc);
  33.         if (tif->tif_flags & TIFF_SWAB) {
  34.                 switch (tif->tif_dir.td_bitspersample) {
  35.                     case 16:
  36.                             assert((cc & 3) == 0);
  37.                             TIFFSwabArrayOfShort((u_short *)tif->tif_rawcp, cc / 2);
  38.                             break;
  39.                     case 32:
  40.                             assert((cc & 15) == 0);
  41.                             TIFFSwabArrayOfLong((u_long *)tif->tif_rawcp, cc / 4);
  42.                             break;
  43.                 }
  44.         }
  45.         tif->tif_rawcp += cc;
  46.         tif->tif_rawcc += cc;
  47.         return(1);
  48. }
  49.  
  50. /****************************************************************************
  51.  * Decode a scanline of pixels.
  52.  */
  53. static int
  54. DumpModeDecode(
  55.         register TIFF     *tif,
  56.         u_char         *buf,
  57.         int         cc
  58.         )
  59. {
  60.         if (tif->tif_rawcc < cc) {
  61.                 TIFFError(tif->tif_name, "DumpModeDecode: Not enough data for scanline %d", tif->tif_row);
  62.                 return(0);
  63.         }
  64.         bcopy(tif->tif_rawcp, buf, cc);
  65.         if (tif->tif_flags & TIFF_SWAB) {
  66.                 switch (tif->tif_dir.td_bitspersample) {
  67.                     case 16:
  68.                             assert((cc & 3) == 0);
  69.                             TIFFSwabArrayOfShort((u_short *)buf, cc / 2);
  70.                             break;
  71.                     case 32:
  72.                             assert((cc & 15) == 0);
  73.                             TIFFSwabArrayOfLong((u_long *)buf, cc / 4);
  74.                             break;
  75.                 }
  76.         }
  77.         tif->tif_rawcp += cc;
  78.         tif->tif_rawcc -= cc;
  79.         return(1);
  80. }
  81.  
  82. /****************************************************************************
  83.  * Seek forwards nrows in the current strip.
  84.  */
  85. static int
  86. DumpModeSeek(
  87.         register TIFF    *tif,
  88.         long         nrows
  89.         )
  90. {
  91.         tif->tif_rawcp += nrows * tif->tif_scanlinesize;
  92.         tif->tif_rawcc -= nrows * tif->tif_scanlinesize;
  93.         return(1);
  94. }
  95.  
  96. /****************************************************************************
  97.  * Initialize dump mode.
  98.  */
  99. int
  100. TIFFInitDumpMode(
  101.     register TIFF    *tif
  102.     )
  103. {
  104.         tif->tif_decoderow = DumpModeDecode;
  105.         tif->tif_encoderow = DumpModeEncode;
  106.         tif->tif_seek = DumpModeSeek;
  107.         return(1);
  108. }
  109.