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

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_write.c,v 1.41 92/02/10 19:06:47 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.  * Scanline-oriented Write Support
  33.  */
  34. #include "tiffioP.h"
  35. #include <stdio.h>
  36. #include <assert.h>
  37.  
  38. #define    STRIPINCR    20        /* expansion factor on strip array */
  39.  
  40. #if USE_PROTOTYPES
  41. static    TIFFWriteCheck(TIFF *, int, char []);
  42. static    TIFFBufferSetup(TIFF *, char []);
  43. static    TIFFGrowStrips(TIFF *, int, char []);
  44. static    TIFFAppendToStrip(TIFF *, u_int, u_char *, u_int);
  45. #else
  46. static    TIFFWriteCheck();
  47. static    TIFFBufferSetup();
  48. static    TIFFGrowStrips();
  49. static    TIFFAppendToStrip();
  50. #endif
  51.  
  52. /*VARARGS3*/
  53. TIFFWriteScanline(tif, buf, row, sample)
  54.     register TIFF *tif;
  55.     u_char *buf;
  56.     u_int row, sample;
  57. {
  58.     static char module[] = "TIFFWriteScanline";
  59.     register TIFFDirectory *td;
  60.     int strip, status, imagegrew = 0;
  61.  
  62.     if (!TIFFWriteCheck(tif, 0, module))
  63.         return (-1);
  64.     /*
  65.      * Handle delayed allocation of data buffer.  This
  66.      * permits it to be sized more intelligently (using
  67.      * directory information).
  68.      */
  69.     if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
  70.         if (!TIFFBufferSetup(tif, module))
  71.             return (-1);
  72.         tif->tif_flags |= TIFF_BUFFERSETUP;
  73.     }
  74.     td = &tif->tif_dir;
  75.     /*
  76.      * Extend image length if needed
  77.      * (but only for PlanarConfig=1).
  78.      */
  79.     if (row >= td->td_imagelength) {    /* extend image */
  80.         if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
  81.             TIFFError(tif->tif_name,
  82.         "Can not change \"ImageLength\" when using separate planes");
  83.             return (-1);
  84.         }
  85.         td->td_imagelength = row+1;
  86.         imagegrew = 1;
  87.     }
  88.     /*
  89.      * Calculate strip and check for crossings.
  90.      */
  91.     if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
  92.         if (sample >= td->td_samplesperpixel) {
  93.             TIFFError(tif->tif_name,
  94.                 "%d: Sample out of range, max %d",
  95.                 sample, td->td_samplesperpixel);
  96.             return (-1);
  97.         }
  98.         strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
  99.     } else
  100.         strip = row / td->td_rowsperstrip;
  101.     if (strip != tif->tif_curstrip) {
  102.         /*
  103.          * Changing strips -- flush any data present.
  104.          */
  105.         if (tif->tif_rawcc > 0 && !TIFFFlushData(tif))
  106.             return (-1);
  107.         tif->tif_curstrip = strip;
  108.         /*
  109.          * Watch out for a growing image.  The value of
  110.          * strips/image will initially be 1 (since it
  111.          * can't be deduced until the imagelength is known).
  112.          */
  113.         if (strip >= td->td_stripsperimage && imagegrew)
  114.             td->td_stripsperimage =
  115.                 howmany(td->td_imagelength, td->td_rowsperstrip);
  116.         tif->tif_row =
  117.             (strip % td->td_stripsperimage) * td->td_rowsperstrip;
  118.         if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
  119.             return (-1);
  120.         tif->tif_flags |= TIFF_POSTENCODE;
  121.     }
  122.     /*
  123.      * Check strip array to make sure there's space.
  124.      * We don't support dynamically growing files that
  125.      * have data organized in separate bitplanes because
  126.      * it's too painful.  In that case we require that
  127.      * the imagelength be set properly before the first
  128.      * write (so that the strips array will be fully
  129.      * allocated above).
  130.      */
  131.     if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))
  132.         return (-1);
  133.     /*
  134.      * Ensure the write is either sequential or at the
  135.      * beginning of a strip (or that we can randomly
  136.      * access the data -- i.e. no encoding).
  137.      */
  138.     if (row != tif->tif_row) {
  139.         if (tif->tif_seek) {
  140.             if (row < tif->tif_row) {
  141.                 /*
  142.                  * Moving backwards within the same strip:
  143.                  * backup to the start and then decode
  144.                  * forward (below).
  145.                  */
  146.                 tif->tif_row = (strip % td->td_stripsperimage) *
  147.                     td->td_rowsperstrip;
  148.                 tif->tif_rawcp = tif->tif_rawdata;
  149.             }
  150.             /*
  151.              * Seek forward to the desired row.
  152.              */
  153.             if (!(*tif->tif_seek)(tif, row - tif->tif_row))
  154.                 return (-1);
  155.             tif->tif_row = row;
  156.         } else {
  157.             TIFFError(tif->tif_name,
  158.             "Compression algorithm does not support random access");
  159.             return (-1);
  160.         }
  161.     }
  162.     status = (*tif->tif_encoderow)(tif, buf, tif->tif_scanlinesize, sample);
  163.     tif->tif_row++;
  164.     return (status);
  165. }
  166.  
  167. /*
  168.  * Encode the supplied data and write it to the
  169.  * specified strip.  There must be space for the
  170.  * data; we don't check if strips overlap!
  171.  *
  172.  * NB: Image length must be setup before writing; this
  173.  *     interface does not support automatically growing
  174.  *     the image on each write (as TIFFWriteScanline does).
  175.  */
  176. TIFFWriteEncodedStrip(tif, strip, data, cc)
  177.     TIFF *tif;
  178.     u_int strip;
  179.     u_char *data;
  180.     u_int cc;
  181. {
  182.     static char module[] = "TIFFWriteEncodedStrip";
  183.     TIFFDirectory *td = &tif->tif_dir;
  184.  
  185.     if (!TIFFWriteCheck(tif, 0, module))
  186.         return (-1);
  187.     if (strip >= td->td_nstrips) {
  188.         TIFFError(module, "%s: Strip %d out of range, max %d",
  189.             tif->tif_name, strip, td->td_nstrips);
  190.         return (-1);
  191.     }
  192.     /*
  193.      * Handle delayed allocation of data buffer.  This
  194.      * permits it to be sized according to the directory
  195.      * info.
  196.      */
  197.     if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
  198.         if (!TIFFBufferSetup(tif, module))
  199.             return (-1);
  200.         tif->tif_flags |= TIFF_BUFFERSETUP;
  201.     }
  202.     tif->tif_curstrip = strip;
  203.     tif->tif_flags &= ~TIFF_POSTENCODE;
  204.     if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
  205.         return (-1);
  206.     if (!(*tif->tif_encodestrip)(tif,
  207.         data, cc, strip / td->td_stripsperimage))
  208.         return (0);
  209.     if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
  210.         return (-1);
  211.     if (td->td_fillorder != tif->tif_fillorder &&
  212.         (tif->tif_flags & TIFF_NOBITREV) == 0)
  213.         TIFFReverseBits((u_char *)tif->tif_rawdata, tif->tif_rawcc);
  214.     if (tif->tif_rawcc > 0 &&
  215.         !TIFFAppendToStrip(tif, strip, (u_char *)tif->tif_rawdata, tif->tif_rawcc))
  216.         return (-1);
  217.     tif->tif_rawcc = 0;
  218.     tif->tif_rawcp = tif->tif_rawdata;
  219.     return (cc);
  220. }
  221.  
  222. /*
  223.  * Write the supplied data to the specified strip.
  224.  * There must be space for the data; we don't check
  225.  * if strips overlap!
  226.  *
  227.  * NB: Image length must be setup before writing; this
  228.  *     interface does not support automatically growing
  229.  *     the image on each write (as TIFFWriteScanline does).
  230.  */
  231. TIFFWriteRawStrip(tif, strip, data, cc)
  232.     TIFF *tif;
  233.     u_int strip;
  234.     u_char *data;
  235.     u_int cc;
  236. {
  237.     static char module[] = "TIFFWriteRawStrip";
  238.  
  239.     if (!TIFFWriteCheck(tif, 0, module))
  240.         return (-1);
  241.     if (strip >= tif->tif_dir.td_nstrips) {
  242.         TIFFError(module, "%s: Strip %d out of range, max %d",
  243.             tif->tif_name, strip, tif->tif_dir.td_nstrips);
  244.         return (-1);
  245.     }
  246.     return (TIFFAppendToStrip(tif, strip, data, cc) ? cc : -1);
  247. }
  248.  
  249. /*
  250.  * Write and compress a tile of data.  The
  251.  * tile is selected by the (x,y,z,s) coordinates.
  252.  */
  253. TIFFWriteTile(tif, buf, x, y, z, s)
  254.     TIFF *tif;
  255.     u_char *buf;
  256.     u_long x, y, z;
  257.     u_int s;
  258. {
  259.     if (!TIFFCheckTile(tif, x, y, z, s))
  260.         return (-1);
  261.     /*
  262.      * NB: A tile size of -1 is used instead of tif_tilesize knowing
  263.      *     that TIFFWriteEncodedTile will clamp this to the tile size.
  264.      *     This is done because the tile size may not be defined until
  265.      *     after the output buffer is setup in TIFFBufferSetup.
  266.      */
  267.     return (TIFFWriteEncodedTile(tif,
  268.         TIFFComputeTile(tif, x, y, z, s), buf, (u_int)-1));
  269. }
  270.  
  271. /*
  272.  * Encode the supplied data and write it to the
  273.  * specified tile.  There must be space for the
  274.  * data.  The function clamps individual writes
  275.  * to a tile to the tile size, but does not (and
  276.  * can not) check that multiple writes to the same
  277.  * tile do not write more than tile size data.
  278.  *
  279.  * NB: Image length must be setup before writing; this
  280.  *     interface does not support automatically growing
  281.  *     the image on each write (as TIFFWriteScanline does).
  282.  */
  283. TIFFWriteEncodedTile(tif, tile, data, cc)
  284.     TIFF *tif;
  285.     u_int tile;
  286.     u_char *data;
  287.     u_int cc;
  288. {
  289.     static char module[] = "TIFFWriteEncodedTile";
  290.     TIFFDirectory *td;
  291.  
  292.     if (!TIFFWriteCheck(tif, 1, module))
  293.         return (-1);
  294.     td = &tif->tif_dir;
  295.     if (tile >= td->td_nstrips) {
  296.         TIFFError(module, "%s: Tile %d out of range, max %d",
  297.             tif->tif_name, tile, td->td_nstrips);
  298.         return (-1);
  299.     }
  300.     /*
  301.      * Handle delayed allocation of data buffer.  This
  302.      * permits it to be sized more intelligently (using
  303.      * directory information).
  304.      */
  305.     if ((tif->tif_flags & TIFF_BUFFERSETUP) == 0) {
  306.         if (!TIFFBufferSetup(tif, module))
  307.             return (-1);
  308.         tif->tif_flags |= TIFF_BUFFERSETUP;
  309.     }
  310.     tif->tif_curtile = tile;
  311.     /* 
  312.      * Compute tiles per row & per column to compute
  313.      * current row and column
  314.      */
  315.     tif->tif_row = (tile % howmany(td->td_imagelength, td->td_tilelength))
  316.         * td->td_tilelength;
  317.     tif->tif_col = (tile % howmany(td->td_imagewidth, td->td_tilewidth))
  318.         * td->td_tilewidth;
  319.  
  320.     tif->tif_flags &= ~TIFF_POSTENCODE;
  321.     if (tif->tif_preencode && !(*tif->tif_preencode)(tif))
  322.         return (-1);
  323.     /*
  324.      * Clamp write amount to the tile size.  This is mostly
  325.      * done so that callers can pass in some large number
  326.      * (e.g. -1) and have the tile size used instead.
  327.      */
  328.     if (cc > tif->tif_tilesize)
  329.         cc = tif->tif_tilesize;
  330.     if (!(*tif->tif_encodetile)(tif, data, cc, tile/td->td_stripsperimage))
  331.         return (0);
  332.     if (tif->tif_postencode && !(*tif->tif_postencode)(tif))
  333.         return (-1);
  334.     if (td->td_fillorder != tif->tif_fillorder &&
  335.         (tif->tif_flags & TIFF_NOBITREV) == 0)
  336.         TIFFReverseBits((u_char *)tif->tif_rawdata, tif->tif_rawcc);
  337.     if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,
  338.         (u_char *)tif->tif_rawdata, tif->tif_rawcc))
  339.         return (-1);
  340.     tif->tif_rawcc = 0;
  341.     tif->tif_rawcp = tif->tif_rawdata;
  342.     return (cc);
  343. }
  344.  
  345. /*
  346.  * Write the supplied data to the specified strip.
  347.  * There must be space for the data; we don't check
  348.  * if strips overlap!
  349.  *
  350.  * NB: Image length must be setup before writing; this
  351.  *     interface does not support automatically growing
  352.  *     the image on each write (as TIFFWriteScanline does).
  353.  */
  354. TIFFWriteRawTile(tif, tile, data, cc)
  355.     TIFF *tif;
  356.     u_int tile;
  357.     u_char *data;
  358.     u_int cc;
  359. {
  360.     static char module[] = "TIFFWriteRawTile";
  361.  
  362.     if (!TIFFWriteCheck(tif, 1, module))
  363.         return (-1);
  364.     if (tile >= tif->tif_dir.td_nstrips) {
  365.         TIFFError(module, "%s: Tile %d out of range, max %d",
  366.             tif->tif_name, tile, tif->tif_dir.td_nstrips);
  367.         return (-1);
  368.     }
  369.     return (TIFFAppendToStrip(tif, tile, data, cc) ? cc : -1);
  370. }
  371.  
  372. static
  373. TIFFSetupStrips(tif)
  374.     TIFF *tif;
  375. {
  376. #define    isUnspecified(td, v) \
  377.     (td->v == 0xffffffff || (td)->td_imagelength == 0)
  378.     register TIFFDirectory *td = &tif->tif_dir;
  379.  
  380.     if (!isTiled(tif))
  381.         td->td_stripsperimage = isUnspecified(td, td_rowsperstrip) ?
  382.             1 : howmany(td->td_imagelength, td->td_rowsperstrip);
  383.     else
  384.         td->td_stripsperimage = isUnspecified(td, td_tilelength) ?
  385.             1 : TIFFNumberOfTiles(tif);
  386.     td->td_nstrips = td->td_stripsperimage;
  387.     if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
  388.         td->td_nstrips *= td->td_samplesperpixel;
  389.     td->td_stripoffset = (u_long *)
  390.         malloc(td->td_nstrips * sizeof (u_long));
  391.     td->td_stripbytecount = (u_long *)
  392.         malloc(td->td_nstrips * sizeof (u_long));
  393.     if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
  394.         return (0);
  395.     /*
  396.      * Place data at the end-of-file
  397.      * (by setting offsets to zero).
  398.      */
  399.     bzero((char *)td->td_stripoffset, td->td_nstrips * sizeof (u_long));
  400.     bzero((char *)td->td_stripbytecount, td->td_nstrips * sizeof (u_long));
  401.     TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
  402.     TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
  403.     return (1);
  404. #undef isUnspecified
  405. }
  406.  
  407. /*
  408.  * Verify file is writable and that the directory
  409.  * information is setup properly.  In doing the latter
  410.  * we also "freeze" the state of the directory so
  411.  * that important information is not changed.
  412.  */
  413. static
  414. TIFFWriteCheck(tif, tiles, module)
  415.     register TIFF *tif;
  416.     int tiles;
  417.     char module[];
  418. {
  419.     if (tif->tif_mode == O_RDONLY) {
  420.         TIFFError(module, "%s: File not open for writing",
  421.             tif->tif_name);
  422.         return (0);
  423.     }
  424.     if (tiles ^ isTiled(tif)) {
  425.         TIFFError(tif->tif_name, tiles ?
  426.             "Can not write tiles to a stripped image" :
  427.             "Can not write scanlines to a tiled image");
  428.         return (0);
  429.     }
  430.     /*
  431.      * On the first write verify all the required information
  432.      * has been setup and initialize any data structures that
  433.      * had to wait until directory information was set.
  434.      * Note that a lot of our work is assumed to remain valid
  435.      * because we disallow any of the important parameters
  436.      * from changing after we start writing (i.e. once
  437.      * TIFF_BEENWRITING is set, TIFFSetField will only allow
  438.      * the image's length to be changed).
  439.      */
  440.     if ((tif->tif_flags & TIFF_BEENWRITING) == 0) {
  441.         if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {
  442.             TIFFError(module,
  443.                 "%s: Must set \"ImageWidth\" before writing data",
  444.                 tif->tif_name);
  445.             return (0);
  446.         }
  447.         if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {
  448.             TIFFError(module,
  449.             "%s: Must set \"PlanarConfiguration\" before writing data",
  450.                 tif->tif_name);
  451.             return (0);
  452.         }
  453.         if (tif->tif_dir.td_stripoffset == NULL &&
  454.             !TIFFSetupStrips(tif)) {
  455.             tif->tif_dir.td_nstrips = 0;
  456.             TIFFError(module, "%s: No space for %s arrays",
  457.                 tif->tif_name, isTiled(tif) ? "tile" : "strip");
  458.             return (0);
  459.         }
  460.         tif->tif_flags |= TIFF_BEENWRITING;
  461.     }
  462.     return (1);
  463. }
  464.  
  465. /*
  466.  * Setup the raw data buffer used for encoding.
  467.  */
  468. static
  469. TIFFBufferSetup(tif, module)
  470.     register TIFF *tif;
  471.     char module[];
  472. {
  473.     int size;
  474.  
  475.     if (isTiled(tif))
  476.         tif->tif_tilesize = size = TIFFTileSize(tif);
  477.     else
  478.         tif->tif_scanlinesize = size = TIFFScanlineSize(tif);
  479.     /*
  480.      * Make raw data buffer at least 8K
  481.      */
  482.     if (size < 8*1024)
  483.         size = 8*1024;
  484.     tif->tif_rawdata = malloc(size);
  485.     if (tif->tif_rawdata == NULL) {
  486.         TIFFError(module, "%s: No space for output buffer",
  487.             tif->tif_name);
  488.         return (0);
  489.     }
  490.     tif->tif_rawdatasize = size;
  491.     tif->tif_rawcc = 0;
  492.     tif->tif_rawcp = tif->tif_rawdata;
  493.     return (1);
  494. }
  495.  
  496. /*
  497.  * Grow the strip data structures by delta strips.
  498.  */
  499. static
  500. TIFFGrowStrips(tif, delta, module)
  501.     TIFF *tif;
  502.     int delta;
  503.     char module[];
  504. {
  505.     TIFFDirectory *td = &tif->tif_dir;
  506.  
  507.     assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
  508.     td->td_stripoffset = (u_long *)realloc(td->td_stripoffset,
  509.         (td->td_nstrips + delta) * sizeof (u_long));
  510.     td->td_stripbytecount = (u_long *)realloc(td->td_stripbytecount,
  511.         (td->td_nstrips + delta) * sizeof (u_long));
  512.     if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL) {
  513.         td->td_nstrips = 0;
  514.         TIFFError(module, "%s: No space to expand strip arrays",
  515.             tif->tif_name);
  516.         return (0);
  517.     }
  518.     bzero(td->td_stripoffset+td->td_nstrips, delta*sizeof (u_long));
  519.     bzero(td->td_stripbytecount+td->td_nstrips, delta*sizeof (u_long));
  520.     td->td_nstrips += delta;
  521.     return (1);
  522. }
  523.  
  524. /*
  525.  * Append the data to the specified strip.
  526.  *
  527.  * NB: We don't check that there's space in the
  528.  *     file (i.e. that strips do not overlap).
  529.  */
  530. static
  531. TIFFAppendToStrip(tif, strip, data, cc)
  532.     TIFF *tif;
  533.     u_int strip;
  534.     u_char *data;
  535.     u_int cc;
  536. {
  537.     TIFFDirectory *td = &tif->tif_dir;
  538.     static char module[] = "TIFFAppendToStrip";
  539.  
  540.     if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
  541.         /*
  542.          * No current offset, set the current strip.
  543.          */
  544.         if (td->td_stripoffset[strip] != 0) {
  545.             if (!SeekOK(tif->tif_fd, td->td_stripoffset[strip])) {
  546.                 TIFFError(module,
  547.                     "%s: Seek error at scanline %d",
  548.                     tif->tif_name, tif->tif_row);
  549.                 return (0);
  550.             }
  551.         } else
  552.             td->td_stripoffset[strip] =
  553.                 lseek(tif->tif_fd, 0L, L_XTND);
  554.         tif->tif_curoff = td->td_stripoffset[strip];
  555.     }
  556.     if (!WriteOK(tif->tif_fd, data, cc)) {
  557.         TIFFError(module, "%s: Write error at scanline %d",
  558.             tif->tif_name, tif->tif_row);
  559.         return (0);
  560.     }
  561.     tif->tif_curoff += cc;
  562.     td->td_stripbytecount[strip] += cc;
  563.     return (1);
  564. }
  565.  
  566. /*
  567.  * Internal version of TIFFFlushData that can be
  568.  * called by ``encodestrip routines'' w/o concern
  569.  * for infinite recursion.
  570.  */
  571. TIFFFlushData1(tif)
  572.     register TIFF *tif;
  573. {
  574.     if (tif->tif_rawcc > 0) {
  575.         if (tif->tif_dir.td_fillorder != tif->tif_fillorder &&
  576.             (tif->tif_flags & TIFF_NOBITREV) == 0)
  577.             TIFFReverseBits((u_char *)tif->tif_rawdata,
  578.                 tif->tif_rawcc);
  579.         if (!TIFFAppendToStrip(tif,
  580.             isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,
  581.             (u_char *)tif->tif_rawdata, tif->tif_rawcc))
  582.             return (0);
  583.         tif->tif_rawcc = 0;
  584.         tif->tif_rawcp = tif->tif_rawdata;
  585.     }
  586.     return (1);
  587. }
  588.