Blame libtiff/tif_write.c

Packit 7838c8
/* $Id: tif_write.c,v 1.46 2016-12-03 21:57:44 erouault Exp $ */
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Copyright (c) 1988-1997 Sam Leffler
Packit 7838c8
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
Packit 7838c8
 *
Packit 7838c8
 * Permission to use, copy, modify, distribute, and sell this software and
Packit 7838c8
 * its documentation for any purpose is hereby granted without fee, provided
Packit 7838c8
 * that (i) the above copyright notices and this permission notice appear in
Packit 7838c8
 * all copies of the software and related documentation, and (ii) the names of
Packit 7838c8
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
Packit 7838c8
 * publicity relating to the software without the specific, prior written
Packit 7838c8
 * permission of Sam Leffler and Silicon Graphics.
Packit 7838c8
 *
Packit 7838c8
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
Packit 7838c8
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
Packit 7838c8
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Packit 7838c8
 *
Packit 7838c8
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
Packit 7838c8
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
Packit 7838c8
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
Packit 7838c8
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
Packit 7838c8
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
Packit 7838c8
 * OF THIS SOFTWARE.
Packit 7838c8
 */
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * TIFF Library.
Packit 7838c8
 *
Packit 7838c8
 * Scanline-oriented Write Support
Packit 7838c8
 */
Packit 7838c8
#include "tiffiop.h"
Packit 7838c8
#include <stdio.h>
Packit 7838c8
Packit 7838c8
#define STRIPINCR	20		/* expansion factor on strip array */
Packit 7838c8
Packit 7838c8
#define WRITECHECKSTRIPS(tif, module)				\
Packit 7838c8
	(((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),0,module))
Packit 7838c8
#define WRITECHECKTILES(tif, module)				\
Packit 7838c8
	(((tif)->tif_flags&TIFF_BEENWRITING) || TIFFWriteCheck((tif),1,module))
Packit 7838c8
#define BUFFERCHECK(tif)					\
Packit 7838c8
	((((tif)->tif_flags & TIFF_BUFFERSETUP) && tif->tif_rawdata) ||	\
Packit 7838c8
	    TIFFWriteBufferSetup((tif), NULL, (tmsize_t) -1))
Packit 7838c8
Packit 7838c8
static int TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module);
Packit 7838c8
static int TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc);
Packit 7838c8
Packit 7838c8
int
Packit 7838c8
TIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteScanline";
Packit 7838c8
	register TIFFDirectory *td;
Packit 7838c8
	int status, imagegrew = 0;
Packit 7838c8
	uint32 strip;
Packit 7838c8
Packit 7838c8
	if (!WRITECHECKSTRIPS(tif, module))
Packit 7838c8
		return (-1);
Packit 7838c8
	/*
Packit 7838c8
	 * Handle delayed allocation of data buffer.  This
Packit 7838c8
	 * permits it to be sized more intelligently (using
Packit 7838c8
	 * directory information).
Packit 7838c8
	 */
Packit 7838c8
	if (!BUFFERCHECK(tif))
Packit 7838c8
		return (-1);
Packit 7838c8
        tif->tif_flags |= TIFF_BUF4WRITE; /* not strictly sure this is right*/
Packit 7838c8
Packit 7838c8
	td = &tif->tif_dir;
Packit 7838c8
	/*
Packit 7838c8
	 * Extend image length if needed
Packit 7838c8
	 * (but only for PlanarConfig=1).
Packit 7838c8
	 */
Packit 7838c8
	if (row >= td->td_imagelength) {	/* extend image */
Packit 7838c8
		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "Can not change \"ImageLength\" when using separate planes");
Packit 7838c8
			return (-1);
Packit 7838c8
		}
Packit 7838c8
		td->td_imagelength = row+1;
Packit 7838c8
		imagegrew = 1;
Packit 7838c8
	}
Packit 7838c8
	/*
Packit 7838c8
	 * Calculate strip and check for crossings.
Packit 7838c8
	 */
Packit 7838c8
	if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
Packit 7838c8
		if (sample >= td->td_samplesperpixel) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "%lu: Sample out of range, max %lu",
Packit 7838c8
			    (unsigned long) sample, (unsigned long) td->td_samplesperpixel);
Packit 7838c8
			return (-1);
Packit 7838c8
		}
Packit 7838c8
		strip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;
Packit 7838c8
	} else
Packit 7838c8
		strip = row / td->td_rowsperstrip;
Packit 7838c8
	/*
Packit 7838c8
	 * Check strip array to make sure there's space. We don't support
Packit 7838c8
	 * dynamically growing files that have data organized in separate
Packit 7838c8
	 * bitplanes because it's too painful.  In that case we require that
Packit 7838c8
	 * the imagelength be set properly before the first write (so that the
Packit 7838c8
	 * strips array will be fully allocated above).
Packit 7838c8
	 */
Packit 7838c8
	if (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))
Packit 7838c8
		return (-1);
Packit 7838c8
	if (strip != tif->tif_curstrip) {
Packit 7838c8
		/*
Packit 7838c8
		 * Changing strips -- flush any data present.
Packit 7838c8
		 */
Packit 7838c8
		if (!TIFFFlushData(tif))
Packit 7838c8
			return (-1);
Packit 7838c8
		tif->tif_curstrip = strip;
Packit 7838c8
		/*
Packit 7838c8
		 * Watch out for a growing image.  The value of strips/image
Packit 7838c8
		 * will initially be 1 (since it can't be deduced until the
Packit 7838c8
		 * imagelength is known).
Packit 7838c8
		 */
Packit 7838c8
		if (strip >= td->td_stripsperimage && imagegrew)
Packit 7838c8
			td->td_stripsperimage =
Packit 7838c8
			    TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip);
Packit 7838c8
                if (td->td_stripsperimage == 0) {
Packit 7838c8
                        TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");
Packit 7838c8
                        return (-1);
Packit 7838c8
                }
Packit 7838c8
		tif->tif_row =
Packit 7838c8
		    (strip % td->td_stripsperimage) * td->td_rowsperstrip;
Packit 7838c8
		if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
Packit 7838c8
			if (!(*tif->tif_setupencode)(tif))
Packit 7838c8
				return (-1);
Packit 7838c8
			tif->tif_flags |= TIFF_CODERSETUP;
Packit 7838c8
		}
Packit 7838c8
        
Packit 7838c8
		tif->tif_rawcc = 0;
Packit 7838c8
		tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
Packit 7838c8
		if( td->td_stripbytecount[strip] > 0 )
Packit 7838c8
		{
Packit 7838c8
			/* if we are writing over existing tiles, zero length */
Packit 7838c8
			td->td_stripbytecount[strip] = 0;
Packit 7838c8
Packit 7838c8
			/* this forces TIFFAppendToStrip() to do a seek */
Packit 7838c8
			tif->tif_curoff = 0;
Packit 7838c8
		}
Packit 7838c8
Packit 7838c8
		if (!(*tif->tif_preencode)(tif, sample))
Packit 7838c8
			return (-1);
Packit 7838c8
		tif->tif_flags |= TIFF_POSTENCODE;
Packit 7838c8
	}
Packit 7838c8
	/*
Packit 7838c8
	 * Ensure the write is either sequential or at the
Packit 7838c8
	 * beginning of a strip (or that we can randomly
Packit 7838c8
	 * access the data -- i.e. no encoding).
Packit 7838c8
	 */
Packit 7838c8
	if (row != tif->tif_row) {
Packit 7838c8
		if (row < tif->tif_row) {
Packit 7838c8
			/*
Packit 7838c8
			 * Moving backwards within the same strip:
Packit 7838c8
			 * backup to the start and then decode
Packit 7838c8
			 * forward (below).
Packit 7838c8
			 */
Packit 7838c8
			tif->tif_row = (strip % td->td_stripsperimage) *
Packit 7838c8
			    td->td_rowsperstrip;
Packit 7838c8
			tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
		}
Packit 7838c8
		/*
Packit 7838c8
		 * Seek forward to the desired row.
Packit 7838c8
		 */
Packit 7838c8
		if (!(*tif->tif_seek)(tif, row - tif->tif_row))
Packit 7838c8
			return (-1);
Packit 7838c8
		tif->tif_row = row;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	/* swab if needed - note that source buffer will be altered */
Packit 7838c8
	tif->tif_postdecode( tif, (uint8*) buf, tif->tif_scanlinesize );
Packit 7838c8
Packit 7838c8
	status = (*tif->tif_encoderow)(tif, (uint8*) buf,
Packit 7838c8
	    tif->tif_scanlinesize, sample);
Packit 7838c8
Packit 7838c8
        /* we are now poised at the beginning of the next row */
Packit 7838c8
	tif->tif_row = row + 1;
Packit 7838c8
	return (status);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Encode the supplied data and write it to the
Packit 7838c8
 * specified strip.
Packit 7838c8
 *
Packit 7838c8
 * NB: Image length must be setup before writing.
Packit 7838c8
 */
Packit 7838c8
tmsize_t
Packit 7838c8
TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteEncodedStrip";
Packit 7838c8
	TIFFDirectory *td = &tif->tif_dir;
Packit 7838c8
	uint16 sample;
Packit 7838c8
Packit 7838c8
	if (!WRITECHECKSTRIPS(tif, module))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
	/*
Packit 7838c8
	 * Check strip array to make sure there's space.
Packit 7838c8
	 * We don't support dynamically growing files that
Packit 7838c8
	 * have data organized in separate bitplanes because
Packit 7838c8
	 * it's too painful.  In that case we require that
Packit 7838c8
	 * the imagelength be set properly before the first
Packit 7838c8
	 * write (so that the strips array will be fully
Packit 7838c8
	 * allocated above).
Packit 7838c8
	 */
Packit 7838c8
	if (strip >= td->td_nstrips) {
Packit 7838c8
		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "Can not grow image by strips when using separate planes");
Packit 7838c8
			return ((tmsize_t) -1);
Packit 7838c8
		}
Packit 7838c8
		if (!TIFFGrowStrips(tif, 1, module))
Packit 7838c8
			return ((tmsize_t) -1);
Packit 7838c8
		td->td_stripsperimage =
Packit 7838c8
		    TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);  
Packit 7838c8
	}
Packit 7838c8
	/*
Packit 7838c8
	 * Handle delayed allocation of data buffer.  This
Packit 7838c8
	 * permits it to be sized according to the directory
Packit 7838c8
	 * info.
Packit 7838c8
	 */
Packit 7838c8
	if (!BUFFERCHECK(tif))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
Packit 7838c8
        tif->tif_flags |= TIFF_BUF4WRITE;
Packit 7838c8
	tif->tif_curstrip = strip;
Packit 7838c8
Packit 7838c8
        if (td->td_stripsperimage == 0) {
Packit 7838c8
                TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");
Packit 7838c8
                return ((tmsize_t) -1);
Packit 7838c8
        }
Packit 7838c8
Packit 7838c8
	tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
Packit 7838c8
	if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
Packit 7838c8
		if (!(*tif->tif_setupencode)(tif))
Packit 7838c8
			return ((tmsize_t) -1);
Packit 7838c8
		tif->tif_flags |= TIFF_CODERSETUP;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	if( td->td_stripbytecount[strip] > 0 )
Packit 7838c8
        {
Packit 7838c8
            /* Make sure that at the first attempt of rewriting the tile, we will have */
Packit 7838c8
            /* more bytes available in the output buffer than the previous byte count, */
Packit 7838c8
            /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */
Packit 7838c8
            /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */
Packit 7838c8
            if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )
Packit 7838c8
            {
Packit 7838c8
                if( !(TIFFWriteBufferSetup(tif, NULL,
Packit 7838c8
                    (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )
Packit 7838c8
                    return ((tmsize_t)(-1));
Packit 7838c8
            }
Packit 7838c8
Packit 7838c8
	    /* Force TIFFAppendToStrip() to consider placing data at end
Packit 7838c8
               of file. */
Packit 7838c8
            tif->tif_curoff = 0;
Packit 7838c8
        }
Packit 7838c8
Packit 7838c8
    tif->tif_rawcc = 0;
Packit 7838c8
    tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
Packit 7838c8
	tif->tif_flags &= ~TIFF_POSTENCODE;
Packit 7838c8
Packit 7838c8
    /* shortcut to avoid an extra memcpy() */
Packit 7838c8
    if( td->td_compression == COMPRESSION_NONE )
Packit 7838c8
    {
Packit 7838c8
        /* swab if needed - note that source buffer will be altered */
Packit 7838c8
        tif->tif_postdecode( tif, (uint8*) data, cc );
Packit 7838c8
Packit 7838c8
        if (!isFillOrder(tif, td->td_fillorder) &&
Packit 7838c8
            (tif->tif_flags & TIFF_NOBITREV) == 0)
Packit 7838c8
            TIFFReverseBits((uint8*) data, cc);
Packit 7838c8
Packit 7838c8
        if (cc > 0 &&
Packit 7838c8
            !TIFFAppendToStrip(tif, strip, (uint8*) data, cc))
Packit 7838c8
            return ((tmsize_t) -1);
Packit 7838c8
        return (cc);
Packit 7838c8
    }
Packit 7838c8
Packit 7838c8
	sample = (uint16)(strip / td->td_stripsperimage);
Packit 7838c8
	if (!(*tif->tif_preencode)(tif, sample))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
Packit 7838c8
        /* swab if needed - note that source buffer will be altered */
Packit 7838c8
	tif->tif_postdecode( tif, (uint8*) data, cc );
Packit 7838c8
Packit 7838c8
	if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
	if (!(*tif->tif_postencode)(tif))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
	if (!isFillOrder(tif, td->td_fillorder) &&
Packit 7838c8
	    (tif->tif_flags & TIFF_NOBITREV) == 0)
Packit 7838c8
		TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
Packit 7838c8
	if (tif->tif_rawcc > 0 &&
Packit 7838c8
	    !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
	tif->tif_rawcc = 0;
Packit 7838c8
	tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
	return (cc);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Write the supplied data to the specified strip.
Packit 7838c8
 *
Packit 7838c8
 * NB: Image length must be setup before writing.
Packit 7838c8
 */
Packit 7838c8
tmsize_t
Packit 7838c8
TIFFWriteRawStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteRawStrip";
Packit 7838c8
	TIFFDirectory *td = &tif->tif_dir;
Packit 7838c8
Packit 7838c8
	if (!WRITECHECKSTRIPS(tif, module))
Packit 7838c8
		return ((tmsize_t) -1);
Packit 7838c8
	/*
Packit 7838c8
	 * Check strip array to make sure there's space.
Packit 7838c8
	 * We don't support dynamically growing files that
Packit 7838c8
	 * have data organized in separate bitplanes because
Packit 7838c8
	 * it's too painful.  In that case we require that
Packit 7838c8
	 * the imagelength be set properly before the first
Packit 7838c8
	 * write (so that the strips array will be fully
Packit 7838c8
	 * allocated above).
Packit 7838c8
	 */
Packit 7838c8
	if (strip >= td->td_nstrips) {
Packit 7838c8
		if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "Can not grow image by strips when using separate planes");
Packit 7838c8
			return ((tmsize_t) -1);
Packit 7838c8
		}
Packit 7838c8
		/*
Packit 7838c8
		 * Watch out for a growing image.  The value of
Packit 7838c8
		 * strips/image will initially be 1 (since it
Packit 7838c8
		 * can't be deduced until the imagelength is known).
Packit 7838c8
		 */
Packit 7838c8
		if (strip >= td->td_stripsperimage)
Packit 7838c8
			td->td_stripsperimage =
Packit 7838c8
			    TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip);
Packit 7838c8
		if (!TIFFGrowStrips(tif, 1, module))
Packit 7838c8
			return ((tmsize_t) -1);
Packit 7838c8
	}
Packit 7838c8
	tif->tif_curstrip = strip;
Packit 7838c8
        if (td->td_stripsperimage == 0) {
Packit 7838c8
                TIFFErrorExt(tif->tif_clientdata, module,"Zero strips per image");
Packit 7838c8
                return ((tmsize_t) -1);
Packit 7838c8
        }
Packit 7838c8
	tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
Packit 7838c8
	return (TIFFAppendToStrip(tif, strip, (uint8*) data, cc) ?
Packit 7838c8
	    cc : (tmsize_t) -1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Write and compress a tile of data.  The
Packit 7838c8
 * tile is selected by the (x,y,z,s) coordinates.
Packit 7838c8
 */
Packit 7838c8
tmsize_t
Packit 7838c8
TIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)
Packit 7838c8
{
Packit 7838c8
	if (!TIFFCheckTile(tif, x, y, z, s))
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
	/*
Packit 7838c8
	 * NB: A tile size of -1 is used instead of tif_tilesize knowing
Packit 7838c8
	 *     that TIFFWriteEncodedTile will clamp this to the tile size.
Packit 7838c8
	 *     This is done because the tile size may not be defined until
Packit 7838c8
	 *     after the output buffer is setup in TIFFWriteBufferSetup.
Packit 7838c8
	 */
Packit 7838c8
	return (TIFFWriteEncodedTile(tif,
Packit 7838c8
	    TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Encode the supplied data and write it to the
Packit 7838c8
 * specified tile.  There must be space for the
Packit 7838c8
 * data.  The function clamps individual writes
Packit 7838c8
 * to a tile to the tile size, but does not (and
Packit 7838c8
 * can not) check that multiple writes to the same
Packit 7838c8
 * tile do not write more than tile size data.
Packit 7838c8
 *
Packit 7838c8
 * NB: Image length must be setup before writing; this
Packit 7838c8
 *     interface does not support automatically growing
Packit 7838c8
 *     the image on each write (as TIFFWriteScanline does).
Packit 7838c8
 */
Packit 7838c8
tmsize_t
Packit 7838c8
TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteEncodedTile";
Packit 7838c8
	TIFFDirectory *td;
Packit 7838c8
	uint16 sample;
Packit 7838c8
        uint32 howmany32;
Packit 7838c8
Packit 7838c8
	if (!WRITECHECKTILES(tif, module))
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
	td = &tif->tif_dir;
Packit 7838c8
	if (tile >= td->td_nstrips) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu",
Packit 7838c8
		    (unsigned long) tile, (unsigned long) td->td_nstrips);
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
	}
Packit 7838c8
	/*
Packit 7838c8
	 * Handle delayed allocation of data buffer.  This
Packit 7838c8
	 * permits it to be sized more intelligently (using
Packit 7838c8
	 * directory information).
Packit 7838c8
	 */
Packit 7838c8
	if (!BUFFERCHECK(tif))
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
Packit 7838c8
        tif->tif_flags |= TIFF_BUF4WRITE;
Packit 7838c8
	tif->tif_curtile = tile;
Packit 7838c8
Packit 7838c8
	if( td->td_stripbytecount[tile] > 0 )
Packit 7838c8
        {
Packit 7838c8
            /* Make sure that at the first attempt of rewriting the tile, we will have */
Packit 7838c8
            /* more bytes available in the output buffer than the previous byte count, */
Packit 7838c8
            /* so that TIFFAppendToStrip() will detect the overflow when it is called the first */
Packit 7838c8
            /* time if the new compressed tile is bigger than the older one. (GDAL #4771) */
Packit 7838c8
            if( tif->tif_rawdatasize <= (tmsize_t) td->td_stripbytecount[tile] )
Packit 7838c8
            {
Packit 7838c8
                if( !(TIFFWriteBufferSetup(tif, NULL,
Packit 7838c8
                    (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[tile] + 1), 1024))) )
Packit 7838c8
                    return ((tmsize_t)(-1));
Packit 7838c8
            }
Packit 7838c8
Packit 7838c8
	    /* Force TIFFAppendToStrip() to consider placing data at end
Packit 7838c8
               of file. */
Packit 7838c8
            tif->tif_curoff = 0;
Packit 7838c8
        }
Packit 7838c8
Packit 7838c8
	tif->tif_rawcc = 0;
Packit 7838c8
	tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
Packit 7838c8
	/* 
Packit 7838c8
	 * Compute tiles per row & per column to compute
Packit 7838c8
	 * current row and column
Packit 7838c8
	 */
Packit 7838c8
        howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
Packit 7838c8
        if (howmany32 == 0) {
Packit 7838c8
                 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
Packit 7838c8
                return ((tmsize_t)(-1));
Packit 7838c8
        }
Packit 7838c8
	tif->tif_row = (tile % howmany32) * td->td_tilelength;
Packit 7838c8
        howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);
Packit 7838c8
        if (howmany32 == 0) {
Packit 7838c8
                 TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
Packit 7838c8
                return ((tmsize_t)(-1));
Packit 7838c8
        }
Packit 7838c8
	tif->tif_col = (tile % howmany32) * td->td_tilewidth;
Packit 7838c8
Packit 7838c8
	if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
Packit 7838c8
		if (!(*tif->tif_setupencode)(tif))
Packit 7838c8
			return ((tmsize_t)(-1));
Packit 7838c8
		tif->tif_flags |= TIFF_CODERSETUP;
Packit 7838c8
	}
Packit 7838c8
	tif->tif_flags &= ~TIFF_POSTENCODE;
Packit 7838c8
Packit 7838c8
	/*
Packit 7838c8
	 * Clamp write amount to the tile size.  This is mostly
Packit 7838c8
	 * done so that callers can pass in some large number
Packit 7838c8
	 * (e.g. -1) and have the tile size used instead.
Packit 7838c8
	 */
Packit 7838c8
	if ( cc < 1 || cc > tif->tif_tilesize)
Packit 7838c8
		cc = tif->tif_tilesize;
Packit 7838c8
Packit 7838c8
    /* shortcut to avoid an extra memcpy() */
Packit 7838c8
    if( td->td_compression == COMPRESSION_NONE )
Packit 7838c8
    {
Packit 7838c8
        /* swab if needed - note that source buffer will be altered */
Packit 7838c8
        tif->tif_postdecode( tif, (uint8*) data, cc );
Packit 7838c8
Packit 7838c8
        if (!isFillOrder(tif, td->td_fillorder) &&
Packit 7838c8
            (tif->tif_flags & TIFF_NOBITREV) == 0)
Packit 7838c8
            TIFFReverseBits((uint8*) data, cc);
Packit 7838c8
Packit 7838c8
        if (cc > 0 &&
Packit 7838c8
            !TIFFAppendToStrip(tif, tile, (uint8*) data, cc))
Packit 7838c8
            return ((tmsize_t) -1);
Packit 7838c8
        return (cc);
Packit 7838c8
    }
Packit 7838c8
Packit 7838c8
    sample = (uint16)(tile/td->td_stripsperimage);
Packit 7838c8
    if (!(*tif->tif_preencode)(tif, sample))
Packit 7838c8
        return ((tmsize_t)(-1));
Packit 7838c8
    /* swab if needed - note that source buffer will be altered */
Packit 7838c8
    tif->tif_postdecode( tif, (uint8*) data, cc );
Packit 7838c8
Packit 7838c8
    if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample))
Packit 7838c8
            return ((tmsize_t) -1);
Packit 7838c8
    if (!(*tif->tif_postencode)(tif))
Packit 7838c8
            return ((tmsize_t)(-1));
Packit 7838c8
    if (!isFillOrder(tif, td->td_fillorder) &&
Packit 7838c8
        (tif->tif_flags & TIFF_NOBITREV) == 0)
Packit 7838c8
            TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc);
Packit 7838c8
    if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,
Packit 7838c8
        tif->tif_rawdata, tif->tif_rawcc))
Packit 7838c8
            return ((tmsize_t)(-1));
Packit 7838c8
    tif->tif_rawcc = 0;
Packit 7838c8
    tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
    return (cc);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Write the supplied data to the specified strip.
Packit 7838c8
 * There must be space for the data; we don't check
Packit 7838c8
 * if strips overlap!
Packit 7838c8
 *
Packit 7838c8
 * NB: Image length must be setup before writing; this
Packit 7838c8
 *     interface does not support automatically growing
Packit 7838c8
 *     the image on each write (as TIFFWriteScanline does).
Packit 7838c8
 */
Packit 7838c8
tmsize_t
Packit 7838c8
TIFFWriteRawTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteRawTile";
Packit 7838c8
Packit 7838c8
	if (!WRITECHECKTILES(tif, module))
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
	if (tile >= tif->tif_dir.td_nstrips) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu",
Packit 7838c8
		    (unsigned long) tile,
Packit 7838c8
		    (unsigned long) tif->tif_dir.td_nstrips);
Packit 7838c8
		return ((tmsize_t)(-1));
Packit 7838c8
	}
Packit 7838c8
	return (TIFFAppendToStrip(tif, tile, (uint8*) data, cc) ?
Packit 7838c8
	    cc : (tmsize_t)(-1));
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
#define	isUnspecified(tif, f) \
Packit 7838c8
    (TIFFFieldSet(tif,f) && (tif)->tif_dir.td_imagelength == 0)
Packit 7838c8
Packit 7838c8
int
Packit 7838c8
TIFFSetupStrips(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	TIFFDirectory* td = &tif->tif_dir;
Packit 7838c8
Packit 7838c8
	if (isTiled(tif))
Packit 7838c8
		td->td_stripsperimage =
Packit 7838c8
		    isUnspecified(tif, FIELD_TILEDIMENSIONS) ?
Packit 7838c8
			td->td_samplesperpixel : TIFFNumberOfTiles(tif);
Packit 7838c8
	else
Packit 7838c8
		td->td_stripsperimage =
Packit 7838c8
		    isUnspecified(tif, FIELD_ROWSPERSTRIP) ?
Packit 7838c8
			td->td_samplesperpixel : TIFFNumberOfStrips(tif);
Packit 7838c8
	td->td_nstrips = td->td_stripsperimage;
Packit 7838c8
	if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
Packit 7838c8
		td->td_stripsperimage /= td->td_samplesperpixel;
Packit 7838c8
	td->td_stripoffset = (uint64 *)
Packit 7838c8
	    _TIFFmalloc(td->td_nstrips * sizeof (uint64));
Packit 7838c8
	td->td_stripbytecount = (uint64 *)
Packit 7838c8
	    _TIFFmalloc(td->td_nstrips * sizeof (uint64));
Packit 7838c8
	if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
Packit 7838c8
		return (0);
Packit 7838c8
	/*
Packit 7838c8
	 * Place data at the end-of-file
Packit 7838c8
	 * (by setting offsets to zero).
Packit 7838c8
	 */
Packit 7838c8
	_TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64));
Packit 7838c8
	_TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64));
Packit 7838c8
	TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);
Packit 7838c8
	TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
#undef isUnspecified
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Verify file is writable and that the directory
Packit 7838c8
 * information is setup properly.  In doing the latter
Packit 7838c8
 * we also "freeze" the state of the directory so
Packit 7838c8
 * that important information is not changed.
Packit 7838c8
 */
Packit 7838c8
int
Packit 7838c8
TIFFWriteCheck(TIFF* tif, int tiles, const char* module)
Packit 7838c8
{
Packit 7838c8
	if (tif->tif_mode == O_RDONLY) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "File not open for writing");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	if (tiles ^ isTiled(tif)) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, tiles ?
Packit 7838c8
		    "Can not write tiles to a stripped image" :
Packit 7838c8
		    "Can not write scanlines to a tiled image");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
        _TIFFFillStriles( tif );
Packit 7838c8
        
Packit 7838c8
	/*
Packit 7838c8
	 * On the first write verify all the required information
Packit 7838c8
	 * has been setup and initialize any data structures that
Packit 7838c8
	 * had to wait until directory information was set.
Packit 7838c8
	 * Note that a lot of our work is assumed to remain valid
Packit 7838c8
	 * because we disallow any of the important parameters
Packit 7838c8
	 * from changing after we start writing (i.e. once
Packit 7838c8
	 * TIFF_BEENWRITING is set, TIFFSetField will only allow
Packit 7838c8
	 * the image's length to be changed).
Packit 7838c8
	 */
Packit 7838c8
	if (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
		    "Must set \"ImageWidth\" before writing data");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	if (tif->tif_dir.td_samplesperpixel == 1) {
Packit 7838c8
		/* 
Packit 7838c8
		 * Planarconfiguration is irrelevant in case of single band
Packit 7838c8
		 * images and need not be included. We will set it anyway,
Packit 7838c8
		 * because this field is used in other parts of library even
Packit 7838c8
		 * in the single band case.
Packit 7838c8
		 */
Packit 7838c8
		if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG))
Packit 7838c8
                    tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;
Packit 7838c8
	} else {
Packit 7838c8
		if (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
			    "Must set \"PlanarConfiguration\" before writing data");
Packit 7838c8
			return (0);
Packit 7838c8
		}
Packit 7838c8
	}
Packit 7838c8
	if (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {
Packit 7838c8
		tif->tif_dir.td_nstrips = 0;
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",
Packit 7838c8
		    isTiled(tif) ? "tile" : "strip");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	if (isTiled(tif))
Packit 7838c8
	{
Packit 7838c8
		tif->tif_tilesize = TIFFTileSize(tif);
Packit 7838c8
		if (tif->tif_tilesize == 0)
Packit 7838c8
			return (0);
Packit 7838c8
	}
Packit 7838c8
	else
Packit 7838c8
		tif->tif_tilesize = (tmsize_t)(-1);
Packit 7838c8
	tif->tif_scanlinesize = TIFFScanlineSize(tif);
Packit 7838c8
	if (tif->tif_scanlinesize == 0)
Packit 7838c8
		return (0);
Packit 7838c8
	tif->tif_flags |= TIFF_BEENWRITING;
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Setup the raw data buffer used for encoding.
Packit 7838c8
 */
Packit 7838c8
int
Packit 7838c8
TIFFWriteBufferSetup(TIFF* tif, void* bp, tmsize_t size)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFWriteBufferSetup";
Packit 7838c8
Packit 7838c8
	if (tif->tif_rawdata) {
Packit 7838c8
		if (tif->tif_flags & TIFF_MYBUFFER) {
Packit 7838c8
			_TIFFfree(tif->tif_rawdata);
Packit 7838c8
			tif->tif_flags &= ~TIFF_MYBUFFER;
Packit 7838c8
		}
Packit 7838c8
		tif->tif_rawdata = NULL;
Packit 7838c8
	}
Packit 7838c8
	if (size == (tmsize_t)(-1)) {
Packit 7838c8
		size = (isTiled(tif) ?
Packit 7838c8
		    tif->tif_tilesize : TIFFStripSize(tif));
Packit 7838c8
		/*
Packit 7838c8
		 * Make raw data buffer at least 8K
Packit 7838c8
		 */
Packit 7838c8
		if (size < 8*1024)
Packit 7838c8
			size = 8*1024;
Packit 7838c8
		bp = NULL;			/* NB: force malloc */
Packit 7838c8
	}
Packit 7838c8
	if (bp == NULL) {
Packit 7838c8
		bp = _TIFFmalloc(size);
Packit 7838c8
		if (bp == NULL) {
Packit 7838c8
			TIFFErrorExt(tif->tif_clientdata, module, "No space for output buffer");
Packit 7838c8
			return (0);
Packit 7838c8
		}
Packit 7838c8
		tif->tif_flags |= TIFF_MYBUFFER;
Packit 7838c8
	} else
Packit 7838c8
		tif->tif_flags &= ~TIFF_MYBUFFER;
Packit 7838c8
	tif->tif_rawdata = (uint8*) bp;
Packit 7838c8
	tif->tif_rawdatasize = size;
Packit 7838c8
	tif->tif_rawcc = 0;
Packit 7838c8
	tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
	tif->tif_flags |= TIFF_BUFFERSETUP;
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Grow the strip data structures by delta strips.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
TIFFGrowStrips(TIFF* tif, uint32 delta, const char* module)
Packit 7838c8
{
Packit 7838c8
	TIFFDirectory *td = &tif->tif_dir;
Packit 7838c8
	uint64* new_stripoffset;
Packit 7838c8
	uint64* new_stripbytecount;
Packit 7838c8
Packit 7838c8
	assert(td->td_planarconfig == PLANARCONFIG_CONTIG);
Packit 7838c8
	new_stripoffset = (uint64*)_TIFFrealloc(td->td_stripoffset,
Packit 7838c8
		(td->td_nstrips + delta) * sizeof (uint64));
Packit 7838c8
	new_stripbytecount = (uint64*)_TIFFrealloc(td->td_stripbytecount,
Packit 7838c8
		(td->td_nstrips + delta) * sizeof (uint64));
Packit 7838c8
	if (new_stripoffset == NULL || new_stripbytecount == NULL) {
Packit 7838c8
		if (new_stripoffset)
Packit 7838c8
			_TIFFfree(new_stripoffset);
Packit 7838c8
		if (new_stripbytecount)
Packit 7838c8
			_TIFFfree(new_stripbytecount);
Packit 7838c8
		td->td_nstrips = 0;
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "No space to expand strip arrays");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	td->td_stripoffset = new_stripoffset;
Packit 7838c8
	td->td_stripbytecount = new_stripbytecount;
Packit 7838c8
	_TIFFmemset(td->td_stripoffset + td->td_nstrips,
Packit 7838c8
		    0, delta*sizeof (uint64));
Packit 7838c8
	_TIFFmemset(td->td_stripbytecount + td->td_nstrips,
Packit 7838c8
		    0, delta*sizeof (uint64));
Packit 7838c8
	td->td_nstrips += delta;
Packit 7838c8
        tif->tif_flags |= TIFF_DIRTYDIRECT;
Packit 7838c8
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Append the data to the specified strip.
Packit 7838c8
 */
Packit 7838c8
static int
Packit 7838c8
TIFFAppendToStrip(TIFF* tif, uint32 strip, uint8* data, tmsize_t cc)
Packit 7838c8
{
Packit 7838c8
	static const char module[] = "TIFFAppendToStrip";
Packit 7838c8
	TIFFDirectory *td = &tif->tif_dir;
Packit 7838c8
	uint64 m;
Packit 7838c8
        int64 old_byte_count = -1;
Packit 7838c8
Packit 7838c8
	if (td->td_stripoffset[strip] == 0 || tif->tif_curoff == 0) {
Packit 7838c8
            assert(td->td_nstrips > 0);
Packit 7838c8
Packit 7838c8
            if( td->td_stripbytecount[strip] != 0 
Packit 7838c8
                && td->td_stripoffset[strip] != 0 
Packit 7838c8
                && td->td_stripbytecount[strip] >= (uint64) cc )
Packit 7838c8
            {
Packit 7838c8
                /* 
Packit 7838c8
                 * There is already tile data on disk, and the new tile
Packit 7838c8
                 * data we have will fit in the same space.  The only 
Packit 7838c8
                 * aspect of this that is risky is that there could be
Packit 7838c8
                 * more data to append to this strip before we are done
Packit 7838c8
                 * depending on how we are getting called.
Packit 7838c8
                 */
Packit 7838c8
                if (!SeekOK(tif, td->td_stripoffset[strip])) {
Packit 7838c8
                    TIFFErrorExt(tif->tif_clientdata, module,
Packit 7838c8
                                 "Seek error at scanline %lu",
Packit 7838c8
                                 (unsigned long)tif->tif_row);
Packit 7838c8
                    return (0);
Packit 7838c8
                }
Packit 7838c8
            }
Packit 7838c8
            else
Packit 7838c8
            {
Packit 7838c8
                /* 
Packit 7838c8
                 * Seek to end of file, and set that as our location to 
Packit 7838c8
                 * write this strip.
Packit 7838c8
                 */
Packit 7838c8
                td->td_stripoffset[strip] = TIFFSeekFile(tif, 0, SEEK_END);
Packit 7838c8
                tif->tif_flags |= TIFF_DIRTYSTRIP;
Packit 7838c8
            }
Packit 7838c8
Packit 7838c8
            tif->tif_curoff = td->td_stripoffset[strip];
Packit 7838c8
Packit 7838c8
            /*
Packit 7838c8
             * We are starting a fresh strip/tile, so set the size to zero.
Packit 7838c8
             */
Packit 7838c8
            old_byte_count = td->td_stripbytecount[strip];
Packit 7838c8
            td->td_stripbytecount[strip] = 0;
Packit 7838c8
	}
Packit 7838c8
Packit 7838c8
	m = tif->tif_curoff+cc;
Packit 7838c8
	if (!(tif->tif_flags&TIFF_BIGTIFF))
Packit 7838c8
		m = (uint32)m;
Packit 7838c8
	if ((m<tif->tif_curoff)||(m<(uint64)cc))
Packit 7838c8
	{
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "Maximum TIFF file size exceeded");
Packit 7838c8
		return (0);
Packit 7838c8
	}
Packit 7838c8
	if (!WriteOK(tif, data, cc)) {
Packit 7838c8
		TIFFErrorExt(tif->tif_clientdata, module, "Write error at scanline %lu",
Packit 7838c8
		    (unsigned long) tif->tif_row);
Packit 7838c8
		    return (0);
Packit 7838c8
	}
Packit 7838c8
	tif->tif_curoff = m;
Packit 7838c8
	td->td_stripbytecount[strip] += cc;
Packit 7838c8
Packit 7838c8
        if( (int64) td->td_stripbytecount[strip] != old_byte_count )
Packit 7838c8
            tif->tif_flags |= TIFF_DIRTYSTRIP;
Packit 7838c8
            
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Internal version of TIFFFlushData that can be
Packit 7838c8
 * called by ``encodestrip routines'' w/o concern
Packit 7838c8
 * for infinite recursion.
Packit 7838c8
 */
Packit 7838c8
int
Packit 7838c8
TIFFFlushData1(TIFF* tif)
Packit 7838c8
{
Packit 7838c8
	if (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) {
Packit 7838c8
		if (!isFillOrder(tif, tif->tif_dir.td_fillorder) &&
Packit 7838c8
		    (tif->tif_flags & TIFF_NOBITREV) == 0)
Packit 7838c8
			TIFFReverseBits((uint8*)tif->tif_rawdata,
Packit 7838c8
			    tif->tif_rawcc);
Packit 7838c8
		if (!TIFFAppendToStrip(tif,
Packit 7838c8
		    isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,
Packit 7838c8
		    tif->tif_rawdata, tif->tif_rawcc))
Packit 7838c8
        {
Packit 7838c8
            /* We update those variables even in case of error since there's */
Packit 7838c8
            /* code that doesn't really check the return code of this */
Packit 7838c8
            /* function */
Packit 7838c8
            tif->tif_rawcc = 0;
Packit 7838c8
            tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
			return (0);
Packit 7838c8
        }
Packit 7838c8
		tif->tif_rawcc = 0;
Packit 7838c8
		tif->tif_rawcp = tif->tif_rawdata;
Packit 7838c8
	}
Packit 7838c8
	return (1);
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/*
Packit 7838c8
 * Set the current write offset.  This should only be
Packit 7838c8
 * used to set the offset to a known previous location
Packit 7838c8
 * (very carefully), or to 0 so that the next write gets
Packit 7838c8
 * appended to the end of the file.
Packit 7838c8
 */
Packit 7838c8
void
Packit 7838c8
TIFFSetWriteOffset(TIFF* tif, toff_t off)
Packit 7838c8
{
Packit 7838c8
	tif->tif_curoff = off;
Packit 7838c8
}
Packit 7838c8
Packit 7838c8
/* vim: set ts=8 sts=8 sw=8 noet: */
Packit 7838c8
/*
Packit 7838c8
 * Local Variables:
Packit 7838c8
 * mode: c
Packit 7838c8
 * c-basic-offset: 8
Packit 7838c8
 * fill-column: 78
Packit 7838c8
 * End:
Packit 7838c8
 */