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

  1. #pragma warn -use
  2. static char     *sccsid = "@(#)TIFF/tif_fax4.c 1.05, 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.  * CCITT Group 4 Facsimile-compatible Compression Scheme Support.
  14.  */
  15. #include "tiffio.h"
  16. #include "tif_fax3.h"
  17.  
  18. /****************************************************************************
  19.  * Decode the requested amount of data.
  20.  */
  21. static int
  22. Fax4Decode(
  23.         TIFF     *tif,
  24.         u_char     *buf,
  25.         int     occ
  26.         )
  27. {
  28.         int         scanline = tif->tif_scanlinesize;
  29.         int         imagewidth = tif->tif_dir.td_imagewidth;
  30.         Fax3BaseState     *sp = (Fax3BaseState *)tif->tif_data;
  31.  
  32.         bzero(buf, occ);                   /* decoding only sets non-zero bits */
  33.         while (occ > 0) {
  34.                 if (!Fax3Decode2DRow(tif, (u_char *)buf, imagewidth))
  35.                         return(0);
  36.                 bcopy(buf, sp->refline, scanline);
  37.                 buf += scanline;
  38.                 occ -= scanline;
  39.         }
  40.         return(1);
  41. }
  42.  
  43. /****************************************************************************
  44.  * Encode the requested amount of data.
  45.  */
  46. static int
  47. Fax4Encode(
  48.         TIFF     *tif,
  49.         u_char    *buf,
  50.         int     cc
  51.         )
  52. {
  53.         u_char     *refline = ((Fax3BaseState *)tif->tif_data)->refline;
  54.         int     scanline = tif->tif_scanlinesize;
  55.         int     imagewidth = tif->tif_dir.td_imagewidth;
  56.  
  57.         while (cc > 0) {
  58.                 if (!Fax3Encode2DRow(tif, (u_char *)buf, refline, imagewidth))
  59.                         return(0);
  60.                 bcopy(buf, refline, scanline);
  61.                 buf += scanline;
  62.                 cc -= scanline;
  63.         }
  64.         return(1);
  65. }
  66.  
  67. /****************************************************************************
  68.  *
  69.  */
  70. static void
  71. Fax4Close(
  72.         TIFF     *tif
  73.         )
  74. {
  75.         if (tif->tif_data) {               /* append EOFB */
  76.                 Fax3PutEOL(tif);
  77.                 Fax3PutEOL(tif);
  78.                 (*tif->tif_encodestrip)(tif);
  79.         }
  80. }
  81.  
  82. /****************************************************************************
  83.  *
  84.  */
  85. int
  86. TIFFInitCCITTFax4(
  87.         TIFF    *tif
  88.         )
  89. {
  90.         TIFFInitCCITTFax3(tif);            /* reuse G3 compression */
  91.         tif->tif_decoderow = Fax4Decode;
  92.         tif->tif_encoderow = Fax4Encode;
  93.         tif->tif_close = Fax4Close;
  94.  
  95.         /*
  96.          * This magic causes the regular G3 decompression code to not skip to the EOL mark at the end of
  97.          * a row (during normal decoding).
  98.          */
  99.         tif->tif_options |= TIFF_OPT1;
  100.         return(1);
  101. }
  102.