LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Modules | Functions
Byte, bit, and colour conversion

Convert sample representations and colour components. More...

Collaboration diagram for Byte, bit, and colour conversion:

Modules

 LogL and LogLuv representations
 Convert logarithmic luminance chromaticity and XYZ representations.
 

Functions

void TIFFSwabShort (uint16_t *wp)
 Reverse the byte order of one value.
 
void TIFFSwabLong (uint32_t *lp)
 Reverse the byte order of one value.
 
void TIFFSwabLong8 (uint64_t *lp)
 Reverse the byte order of one value.
 
void TIFFSwabFloat (float *fp)
 Reverse the byte order of one value.
 
void TIFFSwabDouble (double *dp)
 Reverse the byte order of one value.
 
void TIFFSwabArrayOfShort (uint16_t *wp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFSwabArrayOfTriples (uint8_t *tp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFSwabArrayOfLong (uint32_t *lp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFSwabArrayOfLong8 (uint64_t *lp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFSwabArrayOfFloat (float *fp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFSwabArrayOfDouble (double *dp, tmsize_t n)
 Reverse the byte order of each array element.
 
void TIFFReverseBits (uint8_t *cp, tmsize_t n)
 Reverse the bit order within each byte of a buffer.
 
const unsigned char * TIFFGetBitRevTable (int reversed)
 Select the immutable byte reversal or identity lookup table.
 
int TIFFCIELabToRGBInit (TIFFCIELabToRGB *cielab, const TIFFDisplay *display, float *refWhite)
 Initialise caller-owned CIE Lab conversion tables and reference white.
 
void TIFFCIELabToXYZ (TIFFCIELabToRGB *cielab, uint32_t l, int32_t a, int32_t b, float *X, float *Y, float *Z)
 Convert 8-bit TIFF CIE L*a*b* samples to XYZ.
 
void TIFFXYZToRGB (TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *r, uint32_t *g, uint32_t *b)
 Convert XYZ tristimulus values to display RGB channels.
 
int TIFFYCbCrToRGBInit (TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite)
 Initialise caller-allocated 8-bit YCbCr conversion tables.
 
void TIFFYCbCrtoRGB (TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *r, uint32_t *g, uint32_t *b)
 Convert an 8-bit YCbCr sample triplet to clipped RGB.
 

Detailed Description

Convert sample representations and colour components.

Function Documentation

◆ TIFFCIELabToRGBInit()

int TIFFCIELabToRGBInit ( TIFFCIELabToRGB *  cielab,
const TIFFDisplay *  display,
float *  refWhite 
)
extern

Initialise caller-owned CIE Lab conversion tables and reference white.

Copies display and white-point values into the supplied complete structure and fills embedded gamma tables. Allocates no storage and retains no input pointers. Requires finite, physically usable coefficients, positive gammas and nonzero usable table steps; inputs are not validated. Current implementation computes all three table steps from the red-channel luminance endpoints. No I/O or diagnostics; caller owns and releases the state.

Parameters
[out]cielabNon-NULL writable full conversion structure, disjoint from inputs.
[in]displayNon-NULL borrowed display description copied during the call.
[in]refWhiteBorrowed three-float XYZ reference-white array; positive Y.
Returns
Zero unconditionally; not a validation status.

Definition at line 162 of file tif_color.c.

References _TIFFmemcpy(), TIFFCIELabToRGB::bstep, CIELABTORGB_TABLE_RANGE, TIFFDisplay::d_gammaB, TIFFDisplay::d_gammaG, TIFFDisplay::d_gammaR, TIFFDisplay::d_Vrwb, TIFFDisplay::d_Vrwg, TIFFDisplay::d_Vrwr, TIFFDisplay::d_Y0R, TIFFDisplay::d_YCR, TIFFCIELabToRGB::display, TIFFCIELabToRGB::gstep, TIFFCIELabToRGB::range, TIFFCIELabToRGB::rstep, TIFFCIELabToRGB::X0, TIFFCIELabToRGB::Y0, TIFFCIELabToRGB::Yb2b, TIFFCIELabToRGB::Yg2g, TIFFCIELabToRGB::Yr2r, and TIFFCIELabToRGB::Z0.

Referenced by initCIELabConversion().

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

◆ TIFFCIELabToXYZ()

void TIFFCIELabToXYZ ( TIFFCIELabToRGB *  cielab,
uint32_t  l,
int32_t  a,
int32_t  b,
float *  X,
float *  Y,
float *  Z 
)
extern

Convert 8-bit TIFF CIE L*a*b* samples to XYZ.

Uses the stored reference white and the piecewise Lab inverse transform. Delegates to TIFFCIELab16ToXYZ() after unsigned luminance scaling by 257 and signed chrominance scaling by 256; out-of-range inputs are not checked and can overflow signed arithmetic. Writes outputs without allocation, I/O, diagnostics, or ownership transfer. Supply finite valid conversion state; this void interface has no error status.

Parameters
[in]cielabNon-NULL caller-owned state initialised by TIFFCIELabToRGBInit(); retained by caller.
[in]lUnsigned luminance in 0..255.
[in]aSigned chrominance in -128..127.
[in]bSigned chrominance with the same scale/range as a.
[out]XNon-NULL caller-owned output slot; must not alias the conversion state.
[out]YNon-NULL caller-owned output slot; must not alias the conversion state.
[out]ZNon-NULL caller-owned output slot; must not alias the conversion state.

Definition at line 50 of file tif_color.c.

References TIFFCIELab16ToXYZ().

Referenced by putcontig8bitCIELab8().

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

◆ TIFFGetBitRevTable()

const unsigned char * TIFFGetBitRevTable ( int  reversed)
extern

Select the immutable byte reversal or identity lookup table.

Returns static library storage with 256 byte-indexed entries. Keep it read-only and do not free it; valid while the library is loaded. No allocation, mutation, I/O, diagnostics, or failure path.

Parameters
[in]reversedNonzero selects reversed bits; zero selects identity.
Returns
Borrowed non-NULL pointer to the selected 256-entry table.

Definition at line 325 of file tif_swab.c.

References TIFFBitRevTable, and TIFFNoBitRevTable.

◆ TIFFReverseBits()

void TIFFReverseBits ( uint8_t *  cp,
tmsize_t  n 
)
extern

Reverse the bit order within each byte of a buffer.

Byte order is unchanged. Applies the immutable reversal table in place. No allocation, I/O, diagnostics, bounds checking, or ownership transfer; zero length performs no accesses.

Parameters
[in,out]cpBorrowed writable storage for n bytes.
[in]nNonnegative byte count.

Definition at line 330 of file tif_swab.c.

References TIFFBitRevTable.

Referenced by JBIGDecode(), JBIGOutputBie(), TIFFFillStrip(), TIFFFillStripPartial(), TIFFFillTile(), TIFFFlushData1(), TIFFReadEncodedStrip(), TIFFReadEncodedTile(), TIFFReadFromUserBuffer(), TIFFWriteEncodedStrip(), and TIFFWriteEncodedTile().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfDouble()

void TIFFSwabArrayOfDouble ( double *  dp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]dpBorrowed writable array of n elements with the declared type alignment; each element spans 8 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 228 of file tif_swab.c.

Referenced by _TIFFSwab64BitData(), and TIFFWriteDirectoryTagCheckedDoubleArray().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfFloat()

void TIFFSwabArrayOfFloat ( float *  fp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]fpBorrowed writable array of n elements with the declared type alignment; each element spans 4 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 186 of file tif_swab.c.

Referenced by TIFFWriteDirectoryTagCheckedFloatArray().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfLong()

void TIFFSwabArrayOfLong ( uint32_t *  lp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]lpBorrowed writable array of n elements with the declared type alignment; each element spans 4 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 123 of file tif_swab.c.

Referenced by _TIFFReadDirEntryCheckedRational(), _TIFFRewriteField(), _TIFFSwab32BitData(), swabHorDiff32(), TIFFFetchNormalTag(), TIFFFetchSubjectDistance(), TIFFReadDirEntryCheckedSrational(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySlongArray(), TIFFWriteDirectoryTagCheckedIfdArray(), TIFFWriteDirectoryTagCheckedLongArray(), TIFFWriteDirectoryTagCheckedRationalArray(), TIFFWriteDirectoryTagCheckedRationalDoubleArray(), TIFFWriteDirectoryTagCheckedSlongArray(), TIFFWriteDirectoryTagCheckedSrationalArray(), and TIFFWriteDirectoryTagCheckedSrationalDoubleArray().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfLong8()

void TIFFSwabArrayOfLong8 ( uint64_t *  lp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]lpBorrowed writable array of n elements with the declared type alignment; each element spans 8 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 144 of file tif_swab.c.

Referenced by _TIFFRewriteField(), swabHorDiff64(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntrySlong8Array(), TIFFWriteDirectoryTagCheckedIfd8Array(), TIFFWriteDirectoryTagCheckedLong8Array(), and TIFFWriteDirectoryTagCheckedSlong8Array().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfShort()

void TIFFSwabArrayOfShort ( uint16_t *  wp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]wpBorrowed writable array of n elements with the declared type alignment; each element spans 2 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 87 of file tif_swab.c.

Referenced by _TIFFRewriteField(), _TIFFSwab16BitData(), PixarLogDecode(), swabHorDiff16(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySshortArray(), TIFFWriteDirectoryTagCheckedShortArray(), and TIFFWriteDirectoryTagCheckedSshortArray().

Here is the caller graph for this function:

◆ TIFFSwabArrayOfTriples()

void TIFFSwabArrayOfTriples ( uint8_t *  tp,
tmsize_t  n 
)
extern

Reverse the byte order of each array element.

Swaps bytes in place without interpreting numeric values. For triples, exchanges the first and third bytes of each three-byte group. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]tpBorrowed writable array of n elements with the declared type alignment; each element spans 3 bytes.
[in]nNonnegative element count, not a byte count; storage must cover every element.

Definition at line 105 of file tif_swab.c.

Referenced by _TIFFSwab24BitData().

Here is the caller graph for this function:

◆ TIFFSwabDouble()

void TIFFSwabDouble ( double *  dp)
extern

Reverse the byte order of one value.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]dpBorrowed writable single value with the declared type alignment; each element spans 8 bytes.

Definition at line 207 of file tif_swab.c.

◆ TIFFSwabFloat()

void TIFFSwabFloat ( float *  fp)
extern

Reverse the byte order of one value.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]fpBorrowed writable single value with the declared type alignment; each element spans 4 bytes.

Definition at line 171 of file tif_swab.c.

◆ TIFFSwabLong()

void TIFFSwabLong ( uint32_t *  lp)
extern

Reverse the byte order of one value.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]lpBorrowed writable single value with the declared type alignment; each element spans 4 bytes.

Definition at line 51 of file tif_swab.c.

Referenced by _TIFFPartialReadStripArray(), _TIFFReadDirEntryCheckedRational(), _TIFFRewriteField(), EvaluateIFDdatasizeReading(), TIFFAdvanceDirectory(), TIFFClientOpenExt(), TIFFFetchDirectory(), TIFFFetchSubjectDistance(), TIFFLinkDirectory(), TIFFReadDirEntryArrayWithLimit(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryCheckedDouble(), TIFFReadDirEntryCheckedFloat(), TIFFReadDirEntryCheckedLong(), TIFFReadDirEntryCheckedLong8(), TIFFReadDirEntryCheckedSlong(), TIFFReadDirEntryCheckedSlong8(), TIFFReadDirEntryCheckedSrational(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRewriteDirectorySec(), TIFFUnlinkDirectory(), TIFFWriteDirectorySec(), TIFFWriteDirectoryTagCheckedLong(), TIFFWriteDirectoryTagCheckedRational(), and TIFFWriteDirectoryTagData().

Here is the caller graph for this function:

◆ TIFFSwabLong8()

void TIFFSwabLong8 ( uint64_t *  lp)
extern

Reverse the byte order of one value.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]lpBorrowed writable single value with the declared type alignment; each element spans 8 bytes.

Definition at line 66 of file tif_swab.c.

Referenced by _TIFFPartialReadStripArray(), _TIFFRewriteField(), EvaluateIFDdatasizeReading(), TIFFAdvanceDirectory(), TIFFClientOpenExt(), TIFFFetchDirectory(), TIFFLinkDirectory(), TIFFReadDirEntryArrayWithLimit(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryCheckedDouble(), TIFFReadDirEntryCheckedLong8(), TIFFReadDirEntryCheckedSlong8(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRewriteDirectorySec(), TIFFUnlinkDirectory(), TIFFWriteDirectorySec(), and TIFFWriteDirectoryTagData().

Here is the caller graph for this function:

◆ TIFFSwabShort()

void TIFFSwabShort ( uint16_t *  wp)
extern

Reverse the byte order of one value.

Swaps bytes in place without interpreting numeric values. No allocation, I/O, diagnostics, bounds checks, or ownership transfer occurs. Caller retains storage; overlapping concurrent access requires external synchronisation. Zero array counts perform no accesses.

Parameters
[in,out]wpBorrowed writable single value with the declared type alignment; each element spans 2 bytes.

Definition at line 39 of file tif_swab.c.

Referenced by _TIFFPartialReadStripArray(), _TIFFRewriteField(), TIFFAdvanceDirectory(), TIFFClientOpenExt(), TIFFFetchDirectory(), TIFFLinkDirectory(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryCheckedShort(), TIFFReadDirEntryCheckedSshort(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRewriteDirectorySec(), TIFFWriteDirectorySec(), and TIFFWriteDirectoryTagCheckedShort().

Here is the caller graph for this function:

◆ TIFFXYZToRGB()

void TIFFXYZToRGB ( TIFFCIELabToRGB *  cielab,
float  X,
float  Y,
float  Z,
uint32_t *  r,
uint32_t *  g,
uint32_t *  b 
)
extern

Convert XYZ tristimulus values to display RGB channels.

Multiplies the display matrix, clips luminosities, indexes gamma tables, rounds, and caps channels at configured display white values. Requires finite inputs and valid positive table steps; malformed state/NaNs are not generally rejected. No allocation, I/O, diagnostics, or ownership transfer; output slots remain caller-owned and must not alias state.

Parameters
[in]cielabNon-NULL caller-owned state initialised by TIFFCIELabToRGBInit(); retained by caller.
[in]XFinite tristimulus component in the configured reference-white scale.
[in]YFinite tristimulus component in the configured reference-white scale.
[in]ZFinite tristimulus component in the configured reference-white scale.
[out]rNon-NULL writable display-channel result.
[out]gNon-NULL writable display-channel result.
[out]bNon-NULL writable display-channel result.

Definition at line 112 of file tif_color.c.

References TIFFCIELabToRGB::bstep, TIFFDisplay::d_mat, TIFFDisplay::d_Vrwb, TIFFDisplay::d_Vrwg, TIFFDisplay::d_Vrwr, TIFFDisplay::d_Y0B, TIFFDisplay::d_Y0G, TIFFDisplay::d_Y0R, TIFFDisplay::d_YCB, TIFFDisplay::d_YCG, TIFFDisplay::d_YCR, TIFFCIELabToRGB::display, TIFFCIELabToRGB::gstep, TIFFCIELabToRGB::range, RINT, TIFFCIELabToRGB::rstep, TIFFmax, TIFFmin, TIFFCIELabToRGB::Yb2b, TIFFCIELabToRGB::Yg2g, and TIFFCIELabToRGB::Yr2r.

Referenced by putcontig8bitCIELab16(), and putcontig8bitCIELab8().

Here is the caller graph for this function:

◆ TIFFYCbCrtoRGB()

void TIFFYCbCrtoRGB ( TIFFYCbCrToRGB *  ycbcr,
uint32_t  Y,
int32_t  Cb,
int32_t  Cr,
uint32_t *  r,
uint32_t *  g,
uint32_t *  b 
)
extern

Convert an 8-bit YCbCr sample triplet to clipped RGB.

Clamps inputs to 0..255, combines initialised fixed-point contribution tables, and clips all outputs to 0..255. No allocation, I/O, diagnostics, state mutation, or ownership transfer. Output slots must not alias the conversion state; state and tables must remain live throughout.

Parameters
[in]ycbcrNon-NULL caller-owned state and trailing tables initialised by TIFFYCbCrToRGBInit().
[in]YUnsigned luminance, capped at 255.
[in]CbBlue chroma code, clamped to 0..255.
[in]CrRed chroma code, clamped to 0..255.
[out]rNon-NULL caller-owned channel result in 0..255.
[out]gNon-NULL caller-owned channel result in 0..255.
[out]bNon-NULL caller-owned channel result in 0..255.

Definition at line 289 of file tif_color.c.

References TIFFYCbCrToRGB::Cb_b_tab, TIFFYCbCrToRGB::Cb_g_tab, CLAMP, TIFFYCbCrToRGB::Cr_g_tab, TIFFYCbCrToRGB::Cr_r_tab, HICLAMP, SHIFT, and TIFFYCbCrToRGB::Y_tab.

Referenced by putseparate8bitYCbCr11tile().

Here is the caller graph for this function:

◆ TIFFYCbCrToRGBInit()

int TIFFYCbCrToRGBInit ( TIFFYCbCrToRGB *  ycbcr,
float *  luma,
float *  refBlackWhite 
)
extern

Initialise caller-allocated 8-bit YCbCr conversion tables.

Lays out biased clamp and contribution tables after the structure in the same allocation. See TIFFYCbCrToRGB for the required extra capacity and alignment; sizeof the structure alone is insufficient. Copies coefficients into computed tables without retaining input pointers. Requires finite usable coefficients/reference endpoints; clamps contribution ranges but does not provide comprehensive validation. No allocation, I/O, diagnostics, or ownership transfer. Do not free individual table pointers.

Parameters
[out]ycbcrNon-NULL suitably aligned writable structure plus all trailing table storage, disjoint from inputs.
[in]lumaBorrowed three-float red/green/blue luma weights; green must support finite division.
[in]refBlackWhiteBorrowed six-float Y/Cb/Cr black-white endpoint pairs.
Returns
Zero unconditionally; not a validation status.

Definition at line 354 of file tif_color.c.

References _TIFFmemset(), TIFFYCbCrToRGB::Cb_b_tab, TIFFYCbCrToRGB::Cb_g_tab, CLAMP, TIFFYCbCrToRGB::clamptab, CLAMPw(), Code2V, TIFFYCbCrToRGB::Cr_g_tab, TIFFYCbCrToRGB::Cr_r_tab, FIX, LumaBlue, LumaGreen, LumaRed, ONE_HALF, SHIFT, TIFFroundup_32, and TIFFYCbCrToRGB::Y_tab.

Referenced by initYCbCrConversion().

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