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

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_fax4.c,v 1.14 92/03/11 15:45:17 sam Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 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.  * CCITT Group 4 Facsimile-compatible
  33.  * Compression Scheme Support.
  34.  */
  35. #include "tiffioP.h"
  36. #include "tif_fax3.h"
  37.  
  38. #if USE_PROTOTYPES
  39. static    int Fax4Decode(TIFF*, u_char *, int, u_int);
  40. static    int Fax4Encode(TIFF*, u_char *, int, u_int);
  41. static    int Fax4PostEncode(TIFF*);
  42. #else
  43. static    int Fax4Decode();
  44. static    int Fax4Encode();
  45. static    int Fax4PostEncode();
  46. #endif
  47.  
  48. TIFFInitCCITTFax4(tif)
  49.     TIFF *tif;
  50. {
  51.     TIFFInitCCITTFax3(tif);        /* reuse G3 compression */
  52.     tif->tif_decoderow = Fax4Decode;
  53.     tif->tif_decodestrip = Fax4Decode;
  54.     tif->tif_decodetile = Fax4Decode;
  55.     tif->tif_encoderow = Fax4Encode;
  56.     tif->tif_encodestrip = Fax4Encode;
  57.     tif->tif_encodetile = Fax4Encode;
  58.     tif->tif_postencode = Fax4PostEncode;
  59.     /*
  60.      * FAX3_NOEOL causes the regular G3 decompression
  61.      * code to not skip to the EOL mark at the end of
  62.      * a row (during normal decoding).  FAX3_CLASSF
  63.      * suppresses RTC generation at the end of an image.
  64.      */
  65.     tif->tif_options = FAX3_NOEOL|FAX3_CLASSF;
  66.     return (1);
  67. }
  68.  
  69. /*
  70.  * Decode the requested amount of data.
  71.  */
  72. static int
  73. Fax4Decode(tif, buf, occ, s)
  74.     TIFF *tif;
  75.     u_char *buf;
  76.     int occ;
  77.     u_int s;
  78. {
  79.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  80.  
  81.     bzero(buf, occ);        /* decoding only sets non-zero bits */
  82.     while (occ > 0) {
  83.         if (!Fax3Decode2DRow(tif, buf, sp->rowpixels))
  84.             return (0);
  85.         bcopy(buf, sp->refline, sp->rowbytes);
  86.         buf += sp->rowbytes;
  87.         occ -= sp->rowbytes;
  88.     }
  89.     return (1);
  90. }
  91.  
  92. /*
  93.  * Encode the requested amount of data.
  94.  */
  95. static int
  96. Fax4Encode(tif, bp, cc, s)
  97.     TIFF *tif;
  98.     u_char *bp;
  99.     int cc;
  100.     u_int s;
  101. {
  102.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  103.  
  104.     while (cc > 0) {
  105.         if (!Fax3Encode2DRow(tif, bp, sp->refline, sp->rowpixels))
  106.             return (0);
  107.         bcopy(bp, sp->refline, sp->rowbytes);
  108.         bp += sp->rowbytes;
  109.         cc -= sp->rowbytes;
  110.     }
  111.     return (1);
  112. }
  113.  
  114. static
  115. Fax4PostEncode(tif)
  116.     TIFF *tif;
  117. {
  118.     Fax3BaseState *sp = (Fax3BaseState *)tif->tif_data;
  119.  
  120.     /* terminate strip w/ EOFB */
  121.     Fax3PutEOL(tif);
  122.     Fax3PutEOL(tif);
  123.     if (sp->bit != 8)
  124.         Fax3FlushBits(tif, sp);
  125.     return (1);
  126. }
  127.