LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Functions
Pixel writing

Encode scanlines and striles or append stored payload bytes. More...

Collaboration diagram for Pixel writing:

Functions

int TIFFWriteScanline (TIFF *tif, void *buf, uint32_t row, uint16_t sample)
 Encode and buffer one image scanline.
 
tmsize_t TIFFWriteTile (TIFF *tif, void *buf, uint32_t x, uint32_t y, uint32_t z, uint16_t s)
 Encode the tile containing image coordinates.
 
tmsize_t TIFFWriteEncodedStrip (TIFF *tif, uint32_t strip, void *data, tmsize_t cc)
 Write encoded samples to one strip.
 
tmsize_t TIFFWriteRawStrip (TIFF *tif, uint32_t strip, void *data, tmsize_t cc)
 Write raw stored bytes to one strip.
 
tmsize_t TIFFWriteEncodedTile (TIFF *tif, uint32_t tile, void *data, tmsize_t cc)
 Write encoded samples to one tile.
 
tmsize_t TIFFWriteRawTile (TIFF *tif, uint32_t tile, void *data, tmsize_t cc)
 Write raw stored bytes to one tile.
 
void TIFFSetWriteOffset (TIFF *tif, toff_t off)
 Change the cached next payload write offset.
 

Detailed Description

Encode scanlines and striles or append stored payload bytes.

Function Documentation

◆ TIFFSetWriteOffset()

void TIFFSetWriteOffset ( TIFF *  tif,
toff_t  off 
)
extern

Change the cached next payload write offset.

Assigns the cached continuation offset (tif_curoff) and clears the saved reusable-extent boundary without seeking, validating file layout, writing, allocating, or diagnosing. The offset only matters when further data is appended to a strile that already has an offset: it is then taken as the current write position for size and boundary bookkeeping, but no seek to it is performed. It does not choose the location of a new strile: for a strile with no offset, or after the offset is reset to zero, the next append reuses the strile's existing on-disk slot when the new data fits and otherwise appends at EOF, ignoring any nonzero value. TIFFWriteEncodedStrip() and TIFFWriteEncodedTile() reset the offset to zero on entry, and TIFFWriteScanline() and TIFFWriteRawStrip() reset it when the strip changes. Does not set IFD metadata offsets, prevent overlap, flush buffers, or transfer ownership.

Parameters
[in,out]tifNon-NULL live handle; serialise access externally.
[in]offContinuation offset in file bytes for the strile being written; zero lets the next append choose the strile location.

Definition at line 1244 of file tif_write.c.

References tiff::tif_curoff, and tiff::tif_lastvalidoff.

Referenced by TIFFCheckpointDirectory().

Here is the caller graph for this function:

◆ TIFFWriteEncodedStrip()

tmsize_t TIFFWriteEncodedStrip ( TIFF *  tif,
uint32_t  strip,
void *  data,
tmsize_t  cc 
)
extern

Write encoded samples to one strip.

Encodes supplied host-order samples. The source is writable because postdecode swapping runs in place before encoding; uncompressed paths can additionally reverse its bits. Mutation is not undone on failure. Compressed output may be buffered/appended through codec hooks. cc must be a nonnegative representable input extent; encoded strips do not interpret minus one as a full-strip sentinel. Strip writers can grow contiguous strile arrays only at the immediately following index; separate-plane arrays cannot grow this way. Establish ImageLength before strile writes; array growth is not a general image-height update. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek and write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

Codec encode callbacks are tested for nonzero here; negative callback errors, such as the fallback encoder used for unknown schemes, can therefore be accepted as success. A positive public status can accompany error diagnostics with no data stored.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripZero-based strip index including separate sample planes.
[in,out]dataCaller-owned input of cc bytes; may be byte-swapped or bit-reversed in place before encoding.
[in]ccNonnegative input byte count.
Returns
cc on success (the input byte count, not the compressed byte count), or minus one on detected failure.

Definition at line 331 of file tif_write.c.

References _TIFFCheckPostDecodeLength(), _TIFFReserveLargeEnoughWriteBuffer(), BUFFERCHECK, COMPRESSION_NONE, isFillOrder, PLANARCONFIG_SEPARATE, TIFFDirectory::td_curstrip, TIFFDirectory::td_row, tiff::tif_curoff, tiff::tif_dir, tiff::tif_encodestrip, tiff::tif_flags, tiff::tif_postdecode, tiff::tif_postencode, tiff::tif_preencode, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_setupencode, TIFF_BUF4WRITE, TIFF_CODERSETUP, TIFF_NOBITREV, TIFFAppendToStrip(), TIFFErrorExtR(), TIFFGrowStrips(), TIFFhowmany_32, TIFFReverseBits(), TIFFSafeModMul32, and WRITECHECKSTRIPS.

Here is the call graph for this function:

◆ TIFFWriteEncodedTile()

tmsize_t TIFFWriteEncodedTile ( TIFF *  tif,
uint32_t  tile,
void *  data,
tmsize_t  cc 
)
extern

Write encoded samples to one tile.

Encodes supplied host-order samples. The source is writable because postdecode swapping runs in place before encoding; uncompressed paths can additionally reverse its bits. Mutation is not undone on failure. Compressed output may be buffered/appended through codec hooks. Encoded tiles clamp cc<1 or cc above the cached decoded tile size to a full tile, including minus one. The caller must therefore supply the full extent even for a zero/negative request. Requires an existing in-range tile and established image/tile geometry; cannot grow the image. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek and write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

Codec encode callbacks are tested for nonzero here; negative callback errors, such as the fallback encoder used for unknown schemes, can therefore be accepted as success. A positive public status can accompany error diagnostics with no data stored.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]tileZero-based tile index including separate sample planes.
[in,out]dataCaller-owned input of the effective cc bytes; may be byte-swapped or bit-reversed in place before encoding.
[in]ccInput byte count; values below one or above the decoded tile size select the full tile.
Returns
Effective input byte count after clamping (not the compressed byte count), or minus one on detected failure.

Definition at line 565 of file tif_write.c.

References _TIFFCheckPostDecodeLength(), _TIFFReserveLargeEnoughWriteBuffer(), BUFFERCHECK, COMPRESSION_NONE, isFillOrder, TIFFDirectory::td_col, TIFFDirectory::td_curtile, TIFFDirectory::td_row, TIFFDirectory::td_tilesize, tiff::tif_curoff, tiff::tif_dir, tiff::tif_encodetile, tiff::tif_flags, tiff::tif_postdecode, tiff::tif_postencode, tiff::tif_preencode, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_setupencode, TIFF_BUF4WRITE, TIFF_CODERSETUP, TIFF_NOBITREV, TIFFAppendToStrip(), TIFFErrorExtR(), TIFFhowmany_32, TIFFReverseBits(), TIFFSafeModMul32, and WRITECHECKTILES.

Referenced by TIFFWriteTile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TIFFWriteRawStrip()

tmsize_t TIFFWriteRawStrip ( TIFF *  tif,
uint32_t  strip,
void *  data,
tmsize_t  cc 
)
extern

Write raw stored bytes to one strip.

Appends already encoded/file-order bytes without sample conversion or compression; supply the representation expected by the selected codec/directory. Does not inspect payload correctness or generally prevent overlapping file regions. cc must be a nonnegative representable input extent; a negative cc, including minus one, is diagnosed and rejected rather than treated as a full-strip sentinel. Strip writers can grow contiguous strile arrays only at the immediately following index; separate-plane arrays cannot grow this way. Establish ImageLength before strile writes; array growth is not a general image-height update. May allocate handle-owned strile arrays, load deferred metadata, seek and write client I/O, and invoke tag/diagnostic callbacks; no codec callbacks run. No handle or caller-buffer ownership transfers. Failure is not transactional: strile arrays, flags, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]stripZero-based strip index including separate sample planes.
[in]dataReadable caller-owned stored bytes of cc bytes; not modified by this call.
[in]ccNonnegative count of stored bytes to append.
Returns
cc on success, or minus one on detected failure.

Definition at line 458 of file tif_write.c.

References PLANARCONFIG_SEPARATE, TIFFDirectory::td_curstrip, TIFFDirectory::td_row, tiff::tif_curoff, tiff::tif_dir, TIFF_SSIZE_FORMAT, TIFFAppendToStrip(), TIFFErrorExtR(), TIFFGrowStrips(), TIFFhowmany_32, TIFFSafeModMul32, and WRITECHECKSTRIPS.

Here is the call graph for this function:

◆ TIFFWriteRawTile()

tmsize_t TIFFWriteRawTile ( TIFF *  tif,
uint32_t  tile,
void *  data,
tmsize_t  cc 
)
extern

Write raw stored bytes to one tile.

Appends already encoded/file-order bytes without sample conversion or compression; supply the representation expected by the selected codec/directory. Does not inspect payload correctness or generally prevent overlapping file regions. cc must be a nonnegative representable input extent; unlike TIFFWriteEncodedTile(), a negative cc, including minus one, is diagnosed and rejected rather than treated as a full tile. Requires an existing in-range tile and established image/tile geometry; cannot grow the image. May allocate handle-owned strile arrays, load deferred metadata, seek and write client I/O, and invoke tag/diagnostic callbacks; no codec callbacks run. No handle or caller-buffer ownership transfers. Failure is not transactional: strile arrays, flags, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in]tileZero-based tile index including separate sample planes.
[in]dataReadable caller-owned stored bytes of cc bytes; not modified by this call.
[in]ccNonnegative count of stored bytes to append.
Returns
cc on success, or minus one on detected failure.

Definition at line 692 of file tif_write.c.

References TIFFDirectory::td_nstrips, tiff::tif_dir, TIFF_SSIZE_FORMAT, TIFFAppendToStrip(), TIFFErrorExtR(), and WRITECHECKTILES.

Here is the call graph for this function:

◆ TIFFWriteScanline()

int TIFFWriteScanline ( TIFF *  tif,
void *  buf,
uint32_t  row,
uint16_t  sample 
)
extern

Encode and buffer one image scanline.

Requires strip organisation and a writable handle. Can extend ImageLength for contiguous storage, not separate planes; skipped/backward rows depend on codec seek support. Performs in-place postdecode byte swapping on the input before encoding and does not restore it. Rejects a byte count that is not a multiple of the effective swap width before swapping or encoding. Does not by itself persist the IFD or guarantee all compressed data has reached the file. Row advances to row+1 after encoder dispatch even when it fails. C++ defaults sample to zero. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek and write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in,out]bufCaller-owned scanline of at least TIFFScanlineSize() bytes; may be byte-swapped in place before encoding.
[in]rowZero-based row; for contiguous storage a row at or beyond ImageLength extends it to row+1.
[in]sampleSeparate sample plane; ordinary contiguous access uses zero.
Returns
Encoder callback status (normally one/zero), or minus one for setup, seek, or postdecode-length rejection; zero is also failure.

Definition at line 99 of file tif_write.c.

References _TIFFAdd64(), _TIFFCastUInt64ToUInt32(), _TIFFCheckPostDecodeLength(), _TIFFMultiply64(), BUFFERCHECK, PLANARCONFIG_SEPARATE, TIFFDirectory::td_curstrip, TIFFDirectory::td_row, TIFFDirectory::td_scanlinesize, tiff::tif_curoff, tiff::tif_dir, tiff::tif_encoderow, tiff::tif_flags, tiff::tif_postdecode, tiff::tif_preencode, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_rawdata, tiff::tif_seek, tiff::tif_setupencode, TIFF_BUF4WRITE, TIFF_CODERSETUP, TIFF_POSTENCODE, TIFFErrorExtR(), TIFFFlushData(), TIFFGrowStrips(), TIFFhowmany_32, TIFFSafeModMul32, and WRITECHECKSTRIPS.

Here is the call graph for this function:

◆ TIFFWriteTile()

tmsize_t TIFFWriteTile ( TIFF *  tif,
void *  buf,
uint32_t  x,
uint32_t  y,
uint32_t  z,
uint16_t  s 
)
extern

Encode the tile containing image coordinates.

Checks coordinate bounds, computes the tile index, then delegates to TIFFWriteEncodedTile() with the full-tile sentinel. Fails if the tile index overflows 32 bits. The buffer must cover the full decoded tile including edge padding, not just visible pixels. Input can be changed by swapping/bit reversal. May allocate or replace handle-owned raw/strile buffers, load deferred metadata, seek and write client I/O, and invoke codec/tag/diagnostic callbacks. No handle or caller-buffer ownership transfers. Failure is not transactional: buffers, codec progress, indices, flags, metadata, file position, or file bytes can already have changed, and data already written is not removed. No errno, rollback, or durability guarantee. See Image transfers and buffers.

The delegated TIFFWriteEncodedTile() tests encode callbacks for nonzero; negative callback errors, such as the fallback encoder used for unknown schemes, can therefore be accepted as success. A positive public status can accompany error diagnostics with no data stored.

Parameters
[in,out]tifNon-NULL live handle with matching current geometry and codec methods; serialise access externally.
[in,out]bufCaller-owned full decoded tile of TIFFTileSize() bytes; may be byte-swapped or bit-reversed in place before encoding.
[in]xPixel column inside the image.
[in]yPixel row inside the image.
[in]zDepth slice inside the image.
[in]sSeparate sample plane, zero for ordinary contiguous use.
Returns
Full effective decoded/input tile byte count on success, minus one on detected coordinate/tile-index/setup/codec/I/O failure.

Definition at line 532 of file tif_write.c.

References _TIFFComputeTileExt(), TIFFCheckTile(), and TIFFWriteEncodedTile().

Here is the call graph for this function: