LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Functions | Variables

Bridge dependency error handling and borrowed JPEG buffers. More...

Collaboration diagram for JPEG dependency interface:

Files

file  tif_jpeg_12.c
 Reuse the JPEG bridge with the twelve-bit dependency ABI.
 

Data Structures

struct  JPEGOtherSettings
 Preserve ABI-independent JPEG options and saved parent hooks. More...
 
struct  JPEGState
 Own the leading libjpeg ABI context managers and TIFF transfer state. More...
 
struct  JPEGFixupTagsSubsamplingData
 Track a bounded first-strile window for JPEG sampling inspection. More...
 

Macros

#define TIFF_JSAMPLE   JSAMPLE
 Select the dependency scalar sample type.
 
#define TIFF_JSAMPARRAY   JSAMPARRAY
 Select the dependency row-array sample type.
 
#define TIFF_JSAMPIMAGE   JSAMPIMAGE
 Select the dependency component-plane sample type.
 
#define TIFF_JSAMPROW   JSAMPROW
 Select the dependency row-pointer sample type.
 
#define SETJMP(jbuf)   setjmp(jbuf)
 Save the calling environment for a later LONGJMP (plain setjmp).
 
#define LONGJMP(jbuf, code)   longjmp(jbuf, code)
 Jump back to the frame saved by SETJMP (plain longjmp); never returns.
 
#define JMP_BUF   jmp_buf
 Select jump-buffer storage for dependency failures.
 
#define JState(tif)   ((JPEGState *)(tif)->tif_data)
 Borrow the handle-owned JPEG state.
 
#define FIELD_JPEGTABLES   (FIELD_CODEC + 0)
 Reserve the codec field bit for JPEGTables.
 
#define CALLJPEG(sp, fail, op)   (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))
 Evaluate a libjpeg call, yielding a failure value if libjpeg raises a fatal error.
 
#define CALLVJPEG(sp, op)   CALLJPEG(sp, 0, ((op), 1))
 Evaluate a void libjpeg call under CALLJPEG, yielding 1 on completion or 0 after a fatal libjpeg error.
 
#define JPEG_MARKER_SOF0   0xC0
 Recognise the JPEG baseline sequential Huffman frame marker.
 
#define JPEG_MARKER_SOF1   0xC1
 Recognise the JPEG extended sequential Huffman frame marker.
 
#define JPEG_MARKER_SOF2   0xC2
 Recognise the JPEG progressive Huffman frame marker.
 
#define JPEG_MARKER_SOF9   0xC9
 Recognise the JPEG extended sequential arithmetic frame marker.
 
#define JPEG_MARKER_SOF10   0xCA
 Recognise the JPEG progressive arithmetic frame marker.
 
#define JPEG_MARKER_DHT   0xC4
 Recognise the JPEG Huffman table marker.
 
#define JPEG_MARKER_SOI   0xD8
 Recognise the JPEG start of image marker.
 
#define JPEG_MARKER_SOS   0xDA
 Recognise the JPEG start of scan marker.
 
#define JPEG_MARKER_DQT   0xDB
 Recognise the JPEG quantisation table marker.
 
#define JPEG_MARKER_DRI   0xDD
 Recognise the JPEG restart interval marker.
 
#define JPEG_MARKER_APP0   0xE0
 Recognise the JPEG first application (APP0) marker.
 
#define JPEG_MARKER_COM   0xFE
 Recognise the JPEG comment marker.
 
#define SIZE_OF_JPEGTABLES   2000
 Size of the zero-filled placeholder JPEGTables buffer.
 
#define TIFF_JPEG_MAX_MEMORY_TO_USE   (10 * 1024 * 1024)
 Preferred libjpeg compressor memory limit.
 

Typedefs

typedef struct jpeg_destination_mgr tiff_jpeg_destination_mgr
 Name the embedded dependency jpeg destination mgr type.
 
typedef struct jpeg_source_mgr tiff_jpeg_source_mgr
 Name the embedded dependency jpeg source mgr type.
 
typedef struct jpeg_error_mgr tiff_jpeg_error_mgr
 Name the embedded dependency jpeg error mgr type.
 

Functions

int TIFFReInitJPEG_12 (TIFF *tif, const JPEGOtherSettings *otherSettings, int scheme, int is_encode)
 Replace JPEG state with the twelve-bit ABI and restore saved options.
 
int TIFFJPEGIsFullStripRequired_12 (TIFF *tif)
 Probe cached twelve-bit JPEG input for whole-strile requirements.
 
static void TIFFjpeg_error_exit (j_common_ptr cinfo)
 Route a fatal JPEG error abort the operation and jump to its wrapper.
 
static void TIFFjpeg_output_message (j_common_ptr cinfo)
 Route a dependency warning through the TIFF handle.
 
static void TIFFjpeg_progress_monitor (j_common_ptr cinfo)
 Abort JPEG decompression when its scan count reaches the configured limit.
 
static int TIFFjpeg_create_compress (JPEGState *sp)
 Create a libjpeg compressor and install TIFF error routing.
 
static int TIFFjpeg_create_decompress (JPEGState *sp)
 Create a libjpeg decompressor and install TIFF error routing.
 
static int TIFFjpeg_set_defaults (JPEGState *sp)
 Apply dependency default compression parameters.
 
static int TIFFjpeg_set_colorspace (JPEGState *sp, J_COLOR_SPACE colorspace)
 Select the dependency compression colour space.
 
static int TIFFjpeg_set_quality (JPEGState *sp, int quality, boolean force_baseline)
 Set dependency quantisation quality and baseline policy.
 
static int TIFFjpeg_suppress_tables (JPEGState *sp, boolean suppress)
 Set dependency table-emission suppression.
 
static int TIFFjpeg_start_compress (JPEGState *sp, boolean write_all_tables)
 Start the dependency compressor for a strile.
 
static int TIFFjpeg_write_scanlines (JPEGState *sp, TIFF_JSAMPARRAY scanlines, int num_lines)
 Encode dependency scanline rows.
 
static int TIFFjpeg_write_raw_data (JPEGState *sp, TIFF_JSAMPIMAGE data, int num_lines)
 Encode dependency downsampled component rows.
 
static int TIFFjpeg_finish_compress (JPEGState *sp)
 Finish dependency compression through the attached destination.
 
static int TIFFjpeg_write_tables (JPEGState *sp)
 Emit a tables-only JPEG stream through the destination.
 
static int TIFFjpeg_read_header (JPEGState *sp, boolean require_image)
 Parse a dependency JPEG header or tables-only stream.
 
static int TIFFjpeg_has_multiple_scans (JPEGState *sp)
 Query whether dependency input uses multiple scans.
 
static int TIFFjpeg_start_decompress (JPEGState *sp)
 Start the dependency decompressor and progress monitor.
 
static int TIFFjpeg_read_scanlines (JPEGState *sp, TIFF_JSAMPARRAY scanlines, int max_lines)
 Decode dependency scanline rows.
 
static int TIFFjpeg_read_raw_data (JPEGState *sp, TIFF_JSAMPIMAGE data, int max_lines)
 Decode dependency downsampled component rows.
 
static tmsize_t JPEGRawBytesPerClumpLine (TIFF *tif, uint32_t width, uint16_t h_sampling, uint16_t v_sampling, int data_precision, const char *module)
 Calculate packed bytes for one horizontally sampled JPEG clump row.
 
static TIFF_JSAMPLE JPEGReadPacked12Sample (const uint8_t *buf, tmsize_t sample_index)
 Read one sample from TIFF packed twelve-bit bytes.
 
static void JPEGWritePacked12Sample (uint8_t *buf, tmsize_t sample_index, TIFF_JSAMPLE sample)
 Write one sample to TIFF packed twelve-bit bytes.
 
static int TIFFjpeg_finish_decompress (JPEGState *sp)
 Finish dependency decompression after output rows.
 
static int TIFFjpeg_abort (JPEGState *sp)
 Abort the current dependency operation and release image-pool storage.
 
static int TIFFjpeg_destroy (JPEGState *sp)
 Destroy dependency resources while retaining outer JPEGState.
 
static JSAMPARRAY TIFFjpeg_alloc_sarray (JPEGState *sp, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows)
 Allocate sample-row storage in a dependency memory pool.
 
static void std_init_destination (j_compress_ptr cinfo)
 Attach libjpeg output to the handle raw buffer.
 
static boolean std_empty_output_buffer (j_compress_ptr cinfo)
 Flush produced JPEG payload and reset the dependency output window.
 
static void std_term_destination (j_compress_ptr cinfo)
 Commit dependency output cursor and pending bytes to the TIFF cache.
 
static void TIFFjpeg_data_dest (JPEGState *sp, TIFF *tif)
 Install raw-buffer JPEG output manager callbacks.
 
static void tables_init_destination (j_compress_ptr cinfo)
 Begin writing JPEG tables into the codec-owned table allocation.
 
static boolean tables_empty_output_buffer (j_compress_ptr cinfo)
 Grow the codec-owned JPEG table allocation by one thousand bytes.
 
static void tables_term_destination (j_compress_ptr cinfo)
 Replace JPEG table capacity with the emitted table-stream length.
 
static int TIFFjpeg_tables_dest (JPEGState *sp, TIFF *tif)
 Replace table storage and install tables-only output callbacks.
 
static void std_init_source (j_decompress_ptr cinfo)
 Attach libjpeg input to cached raw strile bytes.
 
static boolean std_fill_input_buffer (j_decompress_ptr cinfo)
 Supply a synthetic JPEG end marker when cached input is exhausted.
 
static void std_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 Skip cached JPEG input or substitute synthetic end-of-image.
 
static void std_term_source (j_decompress_ptr cinfo)
 Complete JPEG source management without additional work.
 
static void TIFFjpeg_data_src (JPEGState *sp)
 Install cached-strile JPEG source manager callbacks.
 
static void tables_init_source (j_decompress_ptr cinfo)
 Attach libjpeg input to codec-owned JPEG table bytes.
 
static void TIFFjpeg_tables_src (JPEGState *sp)
 Install the JPEG source manager for tables-only input.
 
static int alloc_downsampled_buffers (TIFF *tif, jpeg_component_info *comp_info, int num_components)
 Allocate dependency-owned component rows for raw sampled JPEG transfer.
 
static int JPEGFixupTags (TIFF *tif)
 Attempt JPEG-stream YCbCr subsampling correction before ordinary access.
 
static void JPEGFixupTagsSubsampling (TIFF *tif)
 Probe first-strile markers to recover JPEG sampling factors.
 
static int JPEGFixupTagsSubsamplingSec (struct JPEGFixupTagsSubsamplingData *data)
 Scan marker segments for TIFF-compatible component sampling.
 
static int JPEGFixupTagsSubsamplingReadByte (struct JPEGFixupTagsSubsamplingData *data, uint8_t *result)
 Read one byte through the bounded JPEG marker window.
 
static int JPEGFixupTagsSubsamplingReadWord (struct JPEGFixupTagsSubsamplingData *data, uint16_t *result)
 Read a big-endian sixteen-bit marker value.
 
static void JPEGFixupTagsSubsamplingSkip (struct JPEGFixupTagsSubsamplingData *data, uint16_t skiplength)
 Skip bounded marker bytes without immediately reading them.
 
static int JPEGSetupDecode (TIFF *tif)
 Initialise JPEG decompression tables sampling and source managers.
 
static int JPEGComputeStrileWidthHeightBytesPerLine (TIFF *tif, uint16_t s)
 Cache JPEG strile geometry and decoded row extent.
 
static int JPEGPreDecode (TIFF *tif, uint16_t s)
 Validate one JPEG strile header and start its chosen decoder.
 
static int JPEGDecode (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Decode whole JPEG output rows into caller bytes.
 
static int DecodeRowError (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Reject scanline access to raw downsampled JPEG clumps.
 
static int JPEGDecodeRaw (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Decode a whole JPEG strile into packed sampled clump rows.
 
static void unsuppress_quant_table (JPEGState *sp, int tblno)
 Enable emission of an existing JPEG quant table.
 
static void suppress_quant_table (JPEGState *sp, int tblno)
 Suppress emission of an existing JPEG quant table.
 
static void unsuppress_huff_table (JPEGState *sp, int tblno)
 Enable emission of an existing JPEG huff table.
 
static void suppress_huff_table (JPEGState *sp, int tblno)
 Suppress emission of an existing JPEG huff table.
 
static int prepare_JPEGTables (TIFF *tif)
 Generate selected JPEG quantisation and Huffman tables.
 
static void TIFF_std_huff_tables (j_compress_ptr cinfo)
 Populate missing standard JPEG Huffman tables for relevant dependency versions.
 
static int JPEGSetupEncode (TIFF *tif)
 Initialise JPEG compression parameters tables and output manager.
 
static int JPEGPreEncode (TIFF *tif, uint16_t s)
 Select per-strile JPEG sampling table emission and row encoding.
 
static int JPEGEncode (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Encode complete normal JPEG rows from caller bytes.
 
static int JPEGEncodeRaw (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Gather packed sampled clumps into dependency raw JPEG component rows.
 
static int JPEGPostEncode (TIFF *tif)
 Pad pending raw component rows and finish JPEG compression.
 
static void JPEGCleanup (TIFF *tif)
 Restore JPEG tag hooks and release dependency tables and outer state.
 
static void JPEGResetUpsampled (TIFF *tif)
 Update upsampling flags and cached layout sizes after colour-mode changes.
 
static int JPEGVSetField (TIFF *tif, uint32_t tag, va_list ap)
 Set JPEG tables or pseudo-options and chain related tag changes.
 
static int JPEGVGetField (TIFF *tif, uint32_t tag, va_list ap)
 Retrieve JPEG tables/options or delegate related tag queries.
 
static void JPEGPrintDir (TIFF *tif, FILE *fd, long flags)
 Print JPEG table extent then invoke the saved directory printer.
 
static uint32_t JPEGDefaultStripSize (TIFF *tif, uint32_t s)
 Round the parent strip recommendation to JPEG MCU height.
 
static void JPEGDefaultTileSize (TIFF *tif, uint32_t *tw, uint32_t *th)
 Round parent tile recommendations to JPEG MCU dimensions.
 
static int JPEGInitializeLibJPEG (TIFF *tif, int decompress)
 Create or switch the embedded dependency compressor/decompressor.
 
static uint64_t JPEGGetMaxCompressionRatio (TIFF *tif)
 Estimate JPEG expansion from precision and sampled layout.
 
static void TIFFInitJPEGCommon (TIFF *tif)
 Install common JPEG callbacks defaults and handle backlink.
 
int TIFFInitJPEG (TIFF *tif, int scheme)
 Allocate JPEG-in-TIFF codec state and install method chains.
 
int TIFFJPEGIsFullStripRequired (TIFF *tif)
 Probe whether cached JPEG input needs whole-strile decoding.
 

Variables

static const TIFFField jpegFields []
 Define JPEG table and quality/colour/table-mode tag metadata.
 

Detailed Description

Bridge dependency error handling and borrowed JPEG buffers.

Macro Definition Documentation

◆ CALLJPEG

#define CALLJPEG (   sp,
  fail,
  op 
)    (SETJMP((sp)->exit_jmpbuf) ? (fail) : (op))

Evaluate a libjpeg call, yielding a failure value if libjpeg raises a fatal error.

Saves the environment in (sp)->exit_jmpbuf with SETJMP, then evaluates op and yields its value. If libjpeg raises a fatal error during op, TIFFjpeg_error_exit() or TIFFjpeg_progress_monitor() reports it, calls jpeg_abort() and LONGJMPs back here; the expression then evaluates and yields fail instead. sp is evaluated once by the macro itself (op usually refers to it again); op is evaluated at most once, and fail only after a jump. Non-volatile locals of the enclosing function that op modifies are indeterminate after a jump. The frame is valid only while the enclosing function runs, so each TIFFjpeg_* wrapper returns the expansion directly. setjmp is used as the condition of ?:, which is not one of the contexts ISO C lists for setjmp; this relies on usual compiler behaviour.

Parameters
[in,out]spJPEGState pointer; its exit_jmpbuf is overwritten.
[in]failValue yielded after a fatal libjpeg error.
[in]oplibjpeg call expression evaluated under the saved frame.
Returns
The value of op, or fail after a fatal libjpeg error.

Definition at line 687 of file tif_jpeg.c.

◆ CALLVJPEG

#define CALLVJPEG (   sp,
  op 
)    CALLJPEG(sp, 0, ((op), 1))

Evaluate a void libjpeg call under CALLJPEG, yielding 1 on completion or 0 after a fatal libjpeg error.

Expands to CALLJPEG(sp, 0, ((op), 1)); the jump, evaluation-count and indeterminate-local rules of CALLJPEG apply. Any value of op is discarded.

Parameters
[in,out]spJPEGState pointer; its exit_jmpbuf is overwritten.
[in]oplibjpeg call expression evaluated under the saved frame.
Returns
1 if op completed, 0 if libjpeg raised a fatal error.

Definition at line 701 of file tif_jpeg.c.

◆ FIELD_JPEGTABLES

#define FIELD_JPEGTABLES   (FIELD_CODEC + 0)

Reserve the codec field bit for JPEGTables.

First codec-private field bit (FIELD_CODEC + 0). Set when JPEGTables holds tables and tested before they are written or loaded.

Definition at line 536 of file tif_jpeg.c.

◆ JMP_BUF

#define JMP_BUF   jmp_buf

Select jump-buffer storage for dependency failures.

Type of JPEGState::exit_jmpbuf; a plain jmp_buf used with SETJMP and LONGJMP.

Definition at line 380 of file tif_jpeg.c.

◆ JPEG_MARKER_APP0

#define JPEG_MARKER_APP0   0xE0

Recognise the JPEG first application (APP0) marker.

Marker code (the byte after 0xFF). APP0 to APP15 (0xE0 to 0xEF) segments are skipped by JPEGFixupTagsSubsamplingSec() using their length field.

Definition at line 1901 of file tif_jpeg.c.

◆ JPEG_MARKER_COM

#define JPEG_MARKER_COM   0xFE

Recognise the JPEG comment marker.

Marker code (the byte after 0xFF). The segment is skipped by JPEGFixupTagsSubsamplingSec() using its length field.

Definition at line 1909 of file tif_jpeg.c.

◆ JPEG_MARKER_DHT

#define JPEG_MARKER_DHT   0xC4

Recognise the JPEG Huffman table marker.

Marker code (the byte after 0xFF). The segment is skipped by JPEGFixupTagsSubsamplingSec() using its length field.

Definition at line 1860 of file tif_jpeg.c.

◆ JPEG_MARKER_DQT

#define JPEG_MARKER_DQT   0xDB

Recognise the JPEG quantisation table marker.

Marker code (the byte after 0xFF). The segment is skipped by JPEGFixupTagsSubsamplingSec() using its length field.

Definition at line 1884 of file tif_jpeg.c.

◆ JPEG_MARKER_DRI

#define JPEG_MARKER_DRI   0xDD

Recognise the JPEG restart interval marker.

Marker code (the byte after 0xFF). The segment is skipped by JPEGFixupTagsSubsamplingSec() using its length field.

Definition at line 1892 of file tif_jpeg.c.

◆ JPEG_MARKER_SOF0

#define JPEG_MARKER_SOF0   0xC0

Recognise the JPEG baseline sequential Huffman frame marker.

Marker code (the byte after 0xFF). Its frame header supplies the sampling factors read by JPEGFixupTagsSubsamplingSec().

Definition at line 1820 of file tif_jpeg.c.

◆ JPEG_MARKER_SOF1

#define JPEG_MARKER_SOF1   0xC1

Recognise the JPEG extended sequential Huffman frame marker.

Marker code (the byte after 0xFF). Its frame header supplies the sampling factors read by JPEGFixupTagsSubsamplingSec().

Definition at line 1828 of file tif_jpeg.c.

◆ JPEG_MARKER_SOF10

#define JPEG_MARKER_SOF10   0xCA

Recognise the JPEG progressive arithmetic frame marker.

Marker code (the byte after 0xFF). Its frame header supplies the sampling factors read by JPEGFixupTagsSubsamplingSec().

Definition at line 1852 of file tif_jpeg.c.

◆ JPEG_MARKER_SOF2

#define JPEG_MARKER_SOF2   0xC2

Recognise the JPEG progressive Huffman frame marker.

Marker code (the byte after 0xFF). Its frame header supplies the sampling factors read by JPEGFixupTagsSubsamplingSec().

Definition at line 1836 of file tif_jpeg.c.

◆ JPEG_MARKER_SOF9

#define JPEG_MARKER_SOF9   0xC9

Recognise the JPEG extended sequential arithmetic frame marker.

Marker code (the byte after 0xFF). Its frame header supplies the sampling factors read by JPEGFixupTagsSubsamplingSec().

Definition at line 1844 of file tif_jpeg.c.

◆ JPEG_MARKER_SOI

#define JPEG_MARKER_SOI   0xD8

Recognise the JPEG start of image marker.

Marker code (the byte after 0xFF). Has no payload and is skipped by JPEGFixupTagsSubsamplingSec().

Definition at line 1868 of file tif_jpeg.c.

◆ JPEG_MARKER_SOS

#define JPEG_MARKER_SOS   0xDA

Recognise the JPEG start of scan marker.

Marker code (the byte after 0xFF). The segment is skipped by JPEGFixupTagsSubsamplingSec() using its length field.

Definition at line 1876 of file tif_jpeg.c.

◆ JState

#define JState (   tif)    ((JPEGState *)(tif)->tif_data)

Borrow the handle-owned JPEG state.

Casts tif->tif_data without checking it or the codec; valid only while the JPEG codec state is installed.

Parameters
[in]tifHandle whose tif_data holds the JPEGState; evaluated once.

Definition at line 519 of file tif_jpeg.c.

◆ LONGJMP

#define LONGJMP (   jbuf,
  code 
)    longjmp(jbuf, code)

Jump back to the frame saved by SETJMP (plain longjmp); never returns.

Expands to longjmp(jbuf, code). Called with sp->exit_jmpbuf and code 1 by TIFFjpeg_error_exit() and TIFFjpeg_progress_monitor(), after they have reported the error with TIFFErrorExtR() and called jpeg_abort(). Control resumes in the CALLJPEG expansion that filled jbuf, which then yields its fail value. The behaviour is undefined if the function that saved jbuf has already returned.

Parameters
[in]jbufJMP_BUF filled by a still-active SETJMP.
[in]codeValue SETJMP returns after the jump (0 is turned into 1 by longjmp).

Definition at line 372 of file tif_jpeg.c.

◆ SETJMP

#define SETJMP (   jbuf)    setjmp(jbuf)

Save the calling environment for a later LONGJMP (plain setjmp).

Expands to setjmp(jbuf), evaluating jbuf once. Used only inside CALLJPEG on JPEGState::exit_jmpbuf. The saved frame is valid only until the function that expanded the macro returns.

Parameters
[out]jbufJMP_BUF lvalue that receives the saved environment.
Returns
0 when called directly; the nonzero LONGJMP code (always 1 in this file) when control returns here through LONGJMP.

Definition at line 355 of file tif_jpeg.c.

◆ SIZE_OF_JPEGTABLES

#define SIZE_OF_JPEGTABLES   2000

Size of the zero-filled placeholder JPEGTables buffer.

TIFFInitJPEG() allocates this many zero bytes for JPEGTables when no directory has been written yet (tif_diroff == 0), to reserve space for the real tables written later. Undefined after use.

◆ TIFF_JPEG_MAX_MEMORY_TO_USE

#define TIFF_JPEG_MAX_MEMORY_TO_USE   (10 * 1024 * 1024)

Preferred libjpeg compressor memory limit.

Defaults to 10 MiB unless predefined. JPEGInitializeLibJPEG() raises a compressor's positive max_memory_to_use to this value when JPEGMEM is not set; a limit of zero is left unchanged.

◆ TIFF_JSAMPARRAY

#define TIFF_JSAMPARRAY   JSAMPARRAY

Select the dependency row-array sample type.

Maps to the library's JSAMPARRAY; its sample width is fixed by the libjpeg build.

Definition at line 278 of file tif_jpeg.c.

◆ TIFF_JSAMPIMAGE

#define TIFF_JSAMPIMAGE   JSAMPIMAGE

Select the dependency component-plane sample type.

Maps to the library's JSAMPIMAGE; its sample width is fixed by the libjpeg build.

Definition at line 286 of file tif_jpeg.c.

◆ TIFF_JSAMPLE

#define TIFF_JSAMPLE   JSAMPLE

Select the dependency scalar sample type.

Maps to the library's JSAMPLE; its sample width is fixed by the libjpeg build.

Definition at line 270 of file tif_jpeg.c.

◆ TIFF_JSAMPROW

#define TIFF_JSAMPROW   JSAMPROW

Select the dependency row-pointer sample type.

Maps to the library's JSAMPROW; its sample width is fixed by the libjpeg build.

Definition at line 294 of file tif_jpeg.c.

Typedef Documentation

◆ tiff_jpeg_destination_mgr

typedef struct jpeg_destination_mgr tiff_jpeg_destination_mgr

Name the embedded dependency jpeg destination mgr type.

Layout and callback fields follow the selected libjpeg ABI; owning JPEGState retains the structure.

Definition at line 389 of file tif_jpeg.c.

◆ tiff_jpeg_error_mgr

typedef struct jpeg_error_mgr tiff_jpeg_error_mgr

Name the embedded dependency jpeg error mgr type.

Layout and callback fields follow the selected libjpeg ABI; owning JPEGState retains the structure.

Definition at line 405 of file tif_jpeg.c.

◆ tiff_jpeg_source_mgr

typedef struct jpeg_source_mgr tiff_jpeg_source_mgr

Name the embedded dependency jpeg source mgr type.

Layout and callback fields follow the selected libjpeg ABI; owning JPEGState retains the structure.

Definition at line 397 of file tif_jpeg.c.

Function Documentation

◆ alloc_downsampled_buffers()

static int alloc_downsampled_buffers ( TIFF *  tif,
jpeg_component_info *  comp_info,
int  num_components 
)
static

Allocate dependency-owned component rows for raw sampled JPEG transfer.

Requires parsed/started dependency component geometry, num_components within MAX_COMPONENTS and representable positive dimensions. Allocates JPOOL_IMAGE rows through trapped dependency allocation, stores borrowed row pointers and sums samples per clump. Partial allocations remain pool-owned on failure and expire at image-pool release. No caller ownership transfer or direct client I/O.

Parameters
[in,out]tifLive JPEG handle; its codec state receives the row pointers in ds_buffer and the samples-per-clump total.
[in]comp_infoBorrowed dependency component-info array with num_components valid entries.
[in]num_componentsComponent count from zero through MAX_COMPONENTS, with valid padded geometry.
Returns
One after all component buffers, zero on allocation/dependency failure.

Definition at line 1784 of file tif_jpeg.c.

References JPEGState::ds_buffer, JState, JPEGState::samplesperclump, TIFF_JSAMPARRAY, and TIFFjpeg_alloc_sarray().

Referenced by JPEGPreDecode(), and JPEGPreEncode().

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

◆ DecodeRowError()

static int DecodeRowError ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc,
uint16_t  s 
)
static

Reject scanline access to raw downsampled JPEG clumps.

Diagnoses unsupported access and suggests RGB colour mode. Does not touch output, allocate, perform client I/O or transfer ownership.

Parameters
[in]tifNon-NULL live JPEG handle; used only to report the error.
[in]bufUnused; not written.
[in]ccUnused.
[in]sUnused.
Returns
Zero unconditionally.

Definition at line 3054 of file tif_jpeg.c.

References JPEGFixupTagsSubsamplingData::tif, and TIFFErrorExtR().

Referenced by JPEGPreDecode().

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

◆ JPEGCleanup()

static void JPEGCleanup ( TIFF *  tif)
static

Restore JPEG tag hooks and release dependency tables and outer state.

Destroys initialised libjpeg resources (discarding destroy status), frees owned Ext JPEGTables and outer state, clears tif_data and resets compression methods. Invalidates codec/pool/table views. Does not finish/flush payload or close the handle; no status result. Saved sizing hooks are not explicitly restored before default-method reset.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.

Definition at line 4238 of file tif_jpeg.c.

References _TIFFfreeExt(), _TIFFSetDefaultCompressionState(), JPEGState::cinfo_initialized, JPEGOtherSettings::jpegtables, JState, JPEGState::otherSettings, JPEGOtherSettings::printdir, TIFFTagMethods::printdir, JPEGFixupTagsSubsamplingData::tif, tiff::tif_data, tiff::tif_tagmethods, TIFFjpeg_destroy(), TIFFTagMethods::vgetfield, JPEGOtherSettings::vgetparent, TIFFTagMethods::vsetfield, and JPEGOtherSettings::vsetparent.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGComputeStrileWidthHeightBytesPerLine()

static int JPEGComputeStrileWidthHeightBytesPerLine ( TIFF *  tif,
uint16_t  s 
)
static

Cache JPEG strile geometry and decoded row extent.

Uses tile dimensions or image width/truncated remaining strip height and the layout byte query. Separate chroma planes scale expected width/height by positive sampling factors. Requires coherent current row/geometry and representable ceiling arithmetic. Zero sampling diagnoses after caches may change; does not independently reject every zero byte size. No pixel I/O, result allocation or ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]sSample plane index; with separate planar configuration a nonzero value selects a chroma plane, whose width and height are divided by the cached sampling factors.
Returns
One after geometry selection, zero on rejected separate-plane sampling.

Definition at line 2458 of file tif_jpeg.c.

References JPEGState::bytesperline, JPEGState::h_sampling, isTiled, JState, PLANARCONFIG_SEPARATE, JPEGState::strile_height, JPEGState::strile_width, TIFFDirectory::td_imagelength, TIFFDirectory::td_imagewidth, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_tilelength, TIFFDirectory::td_tilewidth, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, TIFFErrorExtR(), TIFFhowmany_32, TIFFScanlineSize(), TIFFTileRowSize(), and JPEGState::v_sampling.

Referenced by JPEGPreDecode(), and JPEGPreEncode().

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

◆ JPEGDecode()

static int JPEGDecode ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc,
uint16_t  s 
)
static

Decode whole JPEG output rows into caller bytes.

Requires successful predecode and nonnegative extent with sufficient row capacity. Refreshes dependency raw input; warns/discards a fractional trailing row, zeroes padding for smaller codestream extents and advances current row after supplied rows. Reads rows directly into buf; no temporary allocation or repacking. A dependency row failure clears the whole cc-byte output; state from earlier rows remains. Normal completion commits raw cursors and may finish decompression. A negative finish result is accepted by the Boolean completion expression, so success is not proof of an error-free finish. No ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[out]bufBorrowed writable cc-byte storage for decoded rows; disjoint from codec buffers.
[in]ccNonnegative byte count; whole rows of bytesperline are decoded and a fractional remainder is warned about and left unread.
[in]sSample plane index; unused.
Returns
Boolean completion, zero on explicit decode rejection/failure; warned truncation or accepted negative finish can still yield one.

Definition at line 2807 of file tif_jpeg.c.

References JPEGState::bytesperline, JPEGState::cinfo, JPEGState::d, JState, JPEGState::src, JPEGState::strile_width, TIFFDirectory::td_row, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_name, tiff::tif_rawcc, tiff::tif_rawcp, TIFFjpeg_finish_decompress(), TIFFjpeg_read_scanlines(), and TIFFWarningExtR().

Referenced by JPEGPreDecode(), and TIFFInitJPEGCommon().

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

◆ JPEGDecodeRaw()

static int JPEGDecodeRaw ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc,
uint16_t  s 
)
static

Decode a whole JPEG strile into packed sampled clump rows.

Requires successful raw predecode, valid component buffers and nonnegative caller extent for all remaining strile rows. Clears the entire output first, computes checked clump/packed byte extents, gathers component rows and repacks ABI-specific samples with optional temporary staging. Clamps the last strip to image rows and rejects insufficient per-clump capacity. Component gathering stores TIFF_JSAMPLE values, so twelve-bit samples are not truncated to eight bits. Frees temporary staging on ordinary exits. Advances row/scancount, but does not generally commit raw cursors as the normal decoder does. Failure leaves partial output/state; a negative dependency finish can be accepted by Boolean completion. No caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[out]bufBorrowed writable cc-byte storage for packed clump rows; zeroed first, then filled; disjoint from codec buffers.
[in]ccNonnegative byte count; must hold the packed clump rows for the rest of the strile.
[in]sSample plane index; unused.
Returns
One on accepted completion, zero on explicit extent/allocation/row failure; accepted negative finish can still produce one.

Definition at line 3104 of file tif_jpeg.c.

References _TIFFCastUInt64ToSSize(), _TIFFCheckMalloc(), _TIFFfreeExt(), _TIFFMultiply64(), JPEGState::cinfo, JPEGState::d, JPEGState::ds_buffer, JPEGState::h_sampling, isTiled, JPEGRawBytesPerClumpLine(), JPEGWritePacked12Sample(), JState, JPEGState::samplesperclump, JPEGState::scancount, JPEGState::strile_width, TIFFDirectory::td_imagelength, TIFFDirectory::td_row, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, TIFF_JSAMPLE, TIFFErrorExtR(), TIFFjpeg_finish_decompress(), TIFFjpeg_read_raw_data(), and JPEGState::v_sampling.

Referenced by JPEGPreDecode().

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

◆ JPEGDefaultStripSize()

static uint32_t JPEGDefaultStripSize ( TIFF *  tif,
uint32_t  s 
)
static

Round the parent strip recommendation to JPEG MCU height.

Calls the saved sizing method and, when the result is below ImageLength, rounds it up to a multiple of the directory YCbCrSubsampling vertical factor (default 2) times DCTSIZE. This rounding is applied for every photometric, not only YCbCr, and does not use the cached sampling in the codec state. Requires positive representable sampling/rounding arithmetic; does not apply the tag or validate the final recommendation. Parent callback effects/diagnostics apply; no ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]sRequested rows per strip (0 lets the parent choose); passed to the saved parent recommender.
Returns
Adjusted recommended rows per strip; no independent error sentinel.

Definition at line 4490 of file tif_jpeg.c.

References JPEGOtherSettings::defsparent, JState, JPEGState::otherSettings, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, and TIFFroundup_32.

Referenced by TIFFInitJPEGCommon().

Here is the caller graph for this function:

◆ JPEGDefaultTileSize()

static void JPEGDefaultTileSize ( TIFF *  tif,
uint32_t *  tw,
uint32_t *  th 
)
static

Round parent tile recommendations to JPEG MCU dimensions.

Calls the saved method and rounds width/height up by the directory YCbCrSubsampling horizontal/vertical factors (default 2) times DCTSIZE, for every photometric. Requires live writable slots and nonzero representable rounding units. Does not set tags, validate recommendations or provide separate status; parent effects apply, no ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in,out]twNon-NULL caller-owned tile-width request/result.
[in,out]thNon-NULL caller-owned tile-height request/result.

Definition at line 4516 of file tif_jpeg.c.

References JPEGOtherSettings::deftparent, JState, JPEGState::otherSettings, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, and TIFFroundup_32.

Referenced by TIFFInitJPEGCommon().

Here is the caller graph for this function:

◆ JPEGEncode()

static int JPEGEncode ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc,
uint16_t  s 
)
static

Encode complete normal JPEG rows from caller bytes.

Requires successful preencode and positive bytesperline. Warns/discards fractional input and clamps the final strip to remaining image rows. Twelve-bit input is unpacked into a temporary short row, including an odd final sample; that allocation is freed on normal completion but not every early dependency-write failure. Caller samples remain unchanged. Dependency output can flush client bytes and leave partial file/cache/row progress on failure; no ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]bufBorrowed readable cc-byte complete input; disjoint from codec buffers.
[in]ccNonnegative byte count; whole rows of bytesperline are encoded and a fractional remainder is warned about and discarded.
[in]sSample plane index; unused.
Returns
One after accepted rows, zero on allocation/dependency row-write failure; warned truncation can still succeed.

Definition at line 3938 of file tif_jpeg.c.

References _TIFFfreeExt(), _TIFFmallocExt(), JPEGState::bytesperline, JPEGState::c, JPEGState::cinfo, isTiled, JPEGReadPacked12Sample(), JState, TIFFDirectory::td_imagelength, TIFFDirectory::td_row, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_name, TIFF_JSAMPLE, TIFF_JSAMPROW, TIFFErrorExtR(), TIFFjpeg_write_scanlines(), and TIFFWarningExtR().

Referenced by JPEGPreEncode(), and TIFFInitJPEGCommon().

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

◆ JPEGEncodeRaw()

static int JPEGEncodeRaw ( TIFF *  tif,
uint8_t *  buf,
tmsize_t  cc,
uint16_t  s 
)
static

Gather packed sampled clumps into dependency raw JPEG component rows.

Requires successful raw preencode, positive sampling/clump geometry and complete nonnegative input clump rows. Computes checked clump extents, validates available input, handles packed twelve-bit odd samples, horizontally pads component rows and writes full MCU groups. Latches encode_raw_error after selected failures to prevent unsafe retry; row/scancount/file state can already change. Caller input remains borrowed/unmodified; no rollback or ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]bufBorrowed readable cc-byte complete input; disjoint from codec buffers.
[in]ccNonnegative byte count; whole packed clump lines are encoded and a fractional remainder is warned about and discarded.
[in]sSample plane index; unused.
Returns
One after accepted groups, zero on latched error, extent/geometry rejection or dependency raw-write failure.

Definition at line 4043 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, JPEGState::ds_buffer, JPEGState::encode_raw_error, JPEGState::h_sampling, JPEGRawBytesPerClumpLine(), JPEGReadPacked12Sample(), JState, JPEGState::samplesperclump, JPEGState::scancount, TIFFDirectory::td_row, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_name, TIFF_JSAMPLE, TIFFErrorExtR(), TIFFjpeg_write_raw_data(), TIFFWarningExtR(), TRUE, and JPEGState::v_sampling.

Referenced by JPEGPreEncode().

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

◆ JPEGFixupTags()

static int JPEGFixupTags ( TIFF *  tif)
static

Attempt JPEG-stream YCbCr subsampling correction before ordinary access.

For enabled subsampling checks and eligible contiguous three-sample YCbCr input, probes the first strile unless sampling was already supplied/fetched. Helper failures can warn while this routine still succeeds. Can allocate, seek/read client data and update cached sampling; file position is not restored. No caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One unconditionally.

Definition at line 1967 of file tif_jpeg.c.

References JPEGFixupTagsSubsampling(), JState, JPEGState::otherSettings, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_samplesperpixel, tiff::tif_dir, and JPEGOtherSettings::ycbcrsampling_fetched.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGFixupTagsSubsampling()

static void JPEGFixupTagsSubsampling ( TIFF *  tif)
static

Probe first-strile markers to recover JPEG sampling factors.

Returns silently when the first offset is zero; otherwise allocates a temporary 2048-byte Ext read window, scans the bounded first strile and frees the window on ordinary exit. Allocation/parse failure warns without separate status. Can seek/read and update directory sampling; does not restore file position or roll back corrections. No retained caller storage.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.

Definition at line 1997 of file tif_jpeg.c.

References _TIFFfreeExt(), _TIFFmallocExt(), JPEGFixupTagsSubsamplingData::buffer, JPEGFixupTagsSubsamplingData::bufferbytesleft, JPEGFixupTagsSubsamplingData::buffercurrentbyte, JPEGFixupTagsSubsamplingData::buffersize, JPEGFixupTagsSubsamplingData::filebytesleft, JPEGFixupTagsSubsamplingData::fileoffset, JPEGFixupTagsSubsamplingData::filepositioned, JPEGFixupTagsSubsamplingSec(), JPEGFixupTagsSubsamplingData::tif, TIFFGetStrileByteCount(), TIFFGetStrileOffset(), and TIFFWarningExtR().

Referenced by JPEGFixupTags().

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

◆ JPEGFixupTagsSubsamplingReadByte()

static int JPEGFixupTagsSubsamplingReadByte ( struct JPEGFixupTagsSubsamplingData *  data,
uint8_t *  result 
)
static

Read one byte through the bounded JPEG marker window.

Refills from remaining strile extent, seeking when not positioned, then advances buffer/file cursors. Requires valid positive buffer capacity below 2^31 and representable offsets. Short/failed I/O returns zero without a local diagnostic; client callback effects and partial file position remain. No allocation or ownership transfer.

Parameters
[in,out]dataBorrowed marker-window state with bounded first-strile input and live temporary buffer/handle.
[out]resultNon-NULL caller-owned byte, assigned only on success.
Returns
One after assigning result, zero on extent/seek/read failure; result unchanged on rejection.

Definition at line 2222 of file tif_jpeg.c.

References JPEGFixupTagsSubsamplingData::buffer, JPEGFixupTagsSubsamplingData::bufferbytesleft, JPEGFixupTagsSubsamplingData::buffercurrentbyte, JPEGFixupTagsSubsamplingData::buffersize, JPEGFixupTagsSubsamplingData::filebytesleft, JPEGFixupTagsSubsamplingData::fileoffset, JPEGFixupTagsSubsamplingData::filepositioned, JPEGFixupTagsSubsamplingData::tif, TIFFReadFile, and TIFFSeekFile.

Referenced by JPEGFixupTagsSubsamplingReadWord(), and JPEGFixupTagsSubsamplingSec().

Here is the caller graph for this function:

◆ JPEGFixupTagsSubsamplingReadWord()

static int JPEGFixupTagsSubsamplingReadWord ( struct JPEGFixupTagsSubsamplingData *  data,
uint16_t *  result 
)
static

Read a big-endian sixteen-bit marker value.

Reads two bytes through the marker window and assigns result only after both succeed. First-byte consumption can remain after a second-byte failure. Client I/O/cursor effects follow the byte reader; no allocation or ownership transfer.

Parameters
[in,out]dataBorrowed marker-window state with bounded first-strile input and live temporary buffer/handle.
[out]resultNon-NULL caller-owned sixteen-bit value, assigned only after both bytes are read.
Returns
One on assignment, zero on byte-reader failure.

Definition at line 2272 of file tif_jpeg.c.

References JPEGFixupTagsSubsamplingReadByte().

Referenced by JPEGFixupTagsSubsamplingSec().

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

◆ JPEGFixupTagsSubsamplingSec()

static int JPEGFixupTagsSubsamplingSec ( struct JPEGFixupTagsSubsamplingData *  data)
static

Scan marker segments for TIFF-compatible component sampling.

Consumes a bounded buffered client stream until a supported SOF marker. Skips irrelevant length-delimited segments, validates segment layout and compares three-component sampling. Compatible factors can update cached directory subsampling with a warning; unrepresentable factors warn and return one without correction. No result allocation or ownership transfer; file/cursor changes remain on failure.

Parameters
[in,out]dataBorrowed marker-window state with bounded first-strile input and live temporary buffer/handle.
Returns
One after a handled SOF, including warned unsupported sampling; zero on unhandled marker/truncated or invalid layout.

Definition at line 2071 of file tif_jpeg.c.

References JPEG_MARKER_APP0, JPEG_MARKER_COM, JPEG_MARKER_DHT, JPEG_MARKER_DQT, JPEG_MARKER_DRI, JPEG_MARKER_SOF0, JPEG_MARKER_SOF1, JPEG_MARKER_SOF10, JPEG_MARKER_SOF2, JPEG_MARKER_SOF9, JPEG_MARKER_SOI, JPEG_MARKER_SOS, JPEGFixupTagsSubsamplingReadByte(), JPEGFixupTagsSubsamplingReadWord(), JPEGFixupTagsSubsamplingSkip(), TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, and TIFFWarningExtR().

Referenced by JPEGFixupTagsSubsampling().

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

◆ JPEGFixupTagsSubsamplingSkip()

static void JPEGFixupTagsSubsamplingSkip ( struct JPEGFixupTagsSubsamplingData *  data,
uint16_t  skiplength 
)
static

Skip bounded marker bytes without immediately reading them.

Advances buffered cursor when possible; otherwise consumes buffered remainder, advances the file-offset window and marks repositioning required. A skip beyond remaining data exhausts the window silently. No allocation, immediate client I/O, diagnostics, status result or ownership transfer.

Parameters
[in,out]dataBorrowed marker-window state with bounded first-strile input and live temporary buffer/handle.
[in]skiplengthMarker payload bytes to skip within the bounded window.

Definition at line 2301 of file tif_jpeg.c.

References JPEGFixupTagsSubsamplingData::bufferbytesleft, JPEGFixupTagsSubsamplingData::buffercurrentbyte, JPEGFixupTagsSubsamplingData::filebytesleft, JPEGFixupTagsSubsamplingData::fileoffset, and JPEGFixupTagsSubsamplingData::filepositioned.

Referenced by JPEGFixupTagsSubsamplingSec().

Here is the caller graph for this function:

◆ JPEGGetMaxCompressionRatio()

static uint64_t JPEGGetMaxCompressionRatio ( TIFF *  tif)
static

Estimate JPEG expansion from precision and sampled layout.

Reads handle/state without allocation, I/O, diagnostics or ownership transfer. Contiguous three-sample YCbCr reports a known estimate only for 2x2 sampling; other layouts use precision-specific estimates. This is an allocation heuristic, not a content/precision guarantee.

Parameters
[in]tifNon-NULL live JPEG handle; directory and codec state are only read.
Returns
512 or 768 for eight/twelve-bit 2x2 YCbCr; zero for other YCbCr sampling; otherwise 256 or 384.

Definition at line 4638 of file tif_jpeg.c.

References JPEGState::h_sampling, JState, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, TIFFDirectory::td_bitspersample, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_samplesperpixel, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, and JPEGState::v_sampling.

Referenced by TIFFInitJPEGCommon().

Here is the caller graph for this function:

◆ JPEGInitializeLibJPEG()

static int JPEGInitializeLibJPEG ( TIFF *  tif,
int  decompress 
)
static

Create or switch the embedded dependency compressor/decompressor.

Reuses an already matching mode; otherwise attempts destroy (ignoring its result), clears creation flag and creates the new mode. For compressor memory limits, raises an existing positive limit toward TIFF_JPEG_MAX_MEMORY_TO_USE unless JPEGMEM is set; does not impose a new positive limit where dependency uses zero. Dependency allocation/error routing can invalidate old views and leave partial state. No caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]decompressNonzero selects decompression, zero compression.
Returns
One for ready matching/created mode, zero on trapped creation failure.

Definition at line 4566 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, JPEGState::cinfo_initialized, JPEGState::comm, JState, JPEGFixupTagsSubsamplingData::tif, TIFF_JPEG_MAX_MEMORY_TO_USE, TIFFjpeg_create_compress(), TIFFjpeg_create_decompress(), TIFFjpeg_destroy(), and TRUE.

Referenced by JPEGSetupDecode(), and JPEGSetupEncode().

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

◆ JPEGPostEncode()

static int JPEGPostEncode ( TIFF *  tif)
static

Pad pending raw component rows and finish JPEG compression.

When raw rows are pending, repeats the last component row to complete the MCU group, emits it and then invokes the compression finish wrapper. Each repeated row copies width_in_blocks * DCTSIZE * sizeof(TIFF_JSAMPLE) bytes, so whole rows are copied for both eight- and twelve-bit samples. Dependency callbacks can flush client output; failure leaves partial state/file data. Does not persist IFD or promise durability; no ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One when the finish call returns normally, zero on component-write or trapped finish failure.

Definition at line 4192 of file tif_jpeg.c.

References _TIFFmemcpy(), JPEGState::c, JPEGState::cinfo, JPEGState::ds_buffer, JState, JPEGState::scancount, JPEGFixupTagsSubsamplingData::tif, TIFF_JSAMPLE, TIFFjpeg_finish_compress(), and TIFFjpeg_write_raw_data().

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGPreDecode()

static int JPEGPreDecode ( TIFF *  tif,
uint16_t  s 
)
static

Validate one JPEG strile header and start its chosen decoder.

If the dependency context is not in decompression mode, first invokes tif_setupdecode without checking its result (which may reallocate the codec state for a twelve-bit ABI switch). Aborts prior dependency image state, parses the new header and commits raw header consumption. Validates precision, component count, expected dimensions and sampling; smaller images warn, and an oversized-height last strip is tolerated under the specific truncated-strip recovery case. Progressive input warns once and checks estimated coefficient memory against the dependency limit unless the environment override is present. Selects RGB conversion or raw downsampled transfer; raw mode disables scanline access and allocates image-pool component rows. Setup/validation/longjmp failures can leave changed state, caches and borrowed dependency views invalidated. No caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]sSample plane index, passed to JPEGComputeStrileWidthHeightBytesPerLine() to size a separate chroma plane.
Returns
One after decompression start/buffer setup, zero on detected validation/dependency/allocation failure.

Definition at line 2532 of file tif_jpeg.c.

References alloc_downsampled_buffers(), JPEGState::cinfo, JPEGState::comm, JPEGState::d, DecodeRowError(), FALSE, JPEGState::h_sampling, JPEGOtherSettings::has_warned_about_progressive_mode, isTiled, JPEGOtherSettings::jpegcolormode, JPEGCOLORMODE_RGB, JPEGComputeStrileWidthHeightBytesPerLine(), JPEGDecode(), JPEGDecodeRaw(), JState, JPEGState::otherSettings, JPEGState::photometric, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, JPEGState::scancount, JPEGState::src, JPEGState::strile_height, JPEGState::strile_width, TIFFDirectory::td_bitspersample, TIFFDirectory::td_imagelength, TIFFDirectory::td_planarconfig, TIFFDirectory::td_row, TIFFDirectory::td_samplesperpixel, JPEGFixupTagsSubsamplingData::tif, tiff::tif_decoderow, tiff::tif_decodestrip, tiff::tif_decodetile, tiff::tif_dir, tiff::tif_rawcc, tiff::tif_rawcp, tiff::tif_setupdecode, TIFFErrorExtR(), TIFFjpeg_abort(), TIFFjpeg_has_multiple_scans(), TIFFjpeg_read_header(), TIFFjpeg_start_decompress(), TIFFWarningExtR(), TRUE, and JPEGState::v_sampling.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGPreEncode()

static int JPEGPreEncode ( TIFF *  tif,
uint16_t  s 
)
static

Select per-strile JPEG sampling table emission and row encoding.

Computes strile geometry, validates JPEG_MAX_DIMENSION, sets colour/sample tables and suppresses extraneous JFIF/Adobe markers. Selects normal or raw sampled input, starts compression, allocates downsampled image-pool buffers where needed and resets row/error state. A mode-switch setup call is not directly checked before subsequent assertions/use. Dependency or allocation failure can leave partial state/output; caller retains input ownership.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]sSample plane index; sizes a separate chroma plane and, for separate planes, becomes the component id (nonzero YCbCr planes use the chroma tables).
Returns
One after start/buffer selection, zero on detected geometry/dependency/allocation failure.

Definition at line 3770 of file tif_jpeg.c.

References alloc_downsampled_buffers(), JPEGState::c, JPEGState::cinfo, JPEGState::comm, JPEGState::encode_raw_error, FALSE, JPEGState::h_sampling, JPEGOtherSettings::jpegcolormode, JPEGCOLORMODE_RGB, JPEGComputeStrileWidthHeightBytesPerLine(), JPEGEncode(), JPEGEncodeRaw(), JPEGOtherSettings::jpegquality, JPEGOtherSettings::jpegtablesmode, JPEGTABLESMODE_HUFF, JPEGTABLESMODE_QUANT, JState, JPEGState::otherSettings, JPEGState::photometric, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, JPEGState::scancount, JPEGState::strile_height, JPEGState::strile_width, suppress_huff_table(), suppress_quant_table(), TIFFDirectory::td_planarconfig, TIFFDirectory::td_samplesperpixel, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_encoderow, tiff::tif_encodestrip, tiff::tif_encodetile, tiff::tif_setupencode, TIFFErrorExtR(), TIFFjpeg_set_colorspace(), TIFFjpeg_set_quality(), TIFFjpeg_start_compress(), TRUE, unsuppress_quant_table(), and JPEGState::v_sampling.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGPrintDir()

static void JPEGPrintDir ( TIFF *  tif,
FILE *  fd,
long  flags 
)
static

Print JPEG table extent then invoke the saved directory printer.

Prints present table length to borrowed FILE and chains the optional parent with flags. Does not check stdio failures or close the stream. No ownership transfer or separate error status; parent callback effects apply.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in,out]fdBorrowed writable FILE; remains caller-owned.
[in]flagsPrint flags forwarded to the parent printer.

Definition at line 4453 of file tif_jpeg.c.

References FIELD_JPEGTABLES, JPEGOtherSettings::jpegtables_length, JState, JPEGState::otherSettings, JPEGOtherSettings::printdir, JPEGFixupTagsSubsamplingData::tif, and TIFFFieldSet.

Referenced by TIFFInitJPEGCommon().

Here is the caller graph for this function:

◆ JPEGRawBytesPerClumpLine()

static tmsize_t JPEGRawBytesPerClumpLine ( TIFF *  tif,
uint32_t  width,
uint16_t  h_sampling,
uint16_t  v_sampling,
int  data_precision,
const char *  module 
)
static

Calculate packed bytes for one horizontally sampled JPEG clump row.

Requires nonzero horizontal/vertical sampling and positive precision. Uses ceil(width/h), (h*v+2) samples per clump, checked sixty-four-bit products/addition and signed-size conversion. Rounds the complete bit row once to bytes. Diagnoses invalid sampling/overflow; conservative ceiling guards can reject silently and final rounding is not a general independent overflow proof. No allocation, payload I/O or ownership transfer.

Parameters
[in]tifHandle used only for diagnostics and the checked arithmetic helpers; no state is changed.
[in]widthPixel width for the complete packed clump row.
[in]h_samplingPositive horizontal luminance sampling factor.
[in]v_samplingPositive vertical luminance sampling factor.
[in]data_precisionPositive bits per sample.
[in]moduleBorrowed diagnostic label.
Returns
Positive packed row extent in bytes, or zero for empty/rejected/overflowed calculation.

Definition at line 1152 of file tif_jpeg.c.

References _TIFFAdd64(), _TIFFCastUInt64ToSSize(), _TIFFMultiply64(), TIFFErrorExtR(), TIFFhowmany8_64, and TIFFhowmany_64.

Referenced by JPEGDecodeRaw(), and JPEGEncodeRaw().

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

◆ JPEGReadPacked12Sample()

static TIFF_JSAMPLE JPEGReadPacked12Sample ( const uint8_t *  buf,
tmsize_t  sample_index 
)
static

Read one sample from TIFF packed twelve-bit bytes.

Requires nonnegative index and enough live input for its pair layout. Even samples use byte0 plus high nibble of byte1; odd samples use low nibble of byte1 plus byte2. No host-endian typed load, fill-order conversion, allocation, I/O, diagnostics or ownership effects.

Parameters
[in]bufBorrowed packed twelve-bit bytes; only read, and must hold the indexed sample pair.
[in]sample_indexNonnegative sample index with representable paired-byte offset.
Returns
Decoded twelve-bit sample under the selected sample type.

Definition at line 1206 of file tif_jpeg.c.

References TIFF_JSAMPLE.

Referenced by JPEGEncode(), and JPEGEncodeRaw().

Here is the caller graph for this function:

◆ JPEGResetUpsampled()

static void JPEGResetUpsampled ( TIFF *  tif)
static

Update upsampling flags and cached layout sizes after colour-mode changes.

Sets UPSAMPLED for contiguous YCbCr with RGB mode, clears it otherwise, and recomputes positive cached tile/scanline sizes. Getters/layout arithmetic can diagnose; no pixel conversion, payload I/O or ownership transfer. Failed prior tag changes do not prevent these cache updates.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.

Definition at line 4270 of file tif_jpeg.c.

References isTiled, JPEGOtherSettings::jpegcolormode, JPEGCOLORMODE_RGB, JState, JPEGState::otherSettings, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_scanlinesize, TIFFDirectory::td_tilesize, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_flags, TIFF_UPSAMPLED, TIFFScanlineSize(), and TIFFTileSize().

Referenced by JPEGVSetField().

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

◆ JPEGSetupDecode()

static int JPEGSetupDecode ( TIFF *  tif)
static

Initialise JPEG decompression tables sampling and source managers.

For enabled twelve-bit dispatch can replace outer state through TIFFReInitJPEG_12. Otherwise creates/switches dependency mode, parses JPEGTables as a tables-only stream when present, caches photometric/sampling, installs raw input manager and disables ordinary postdecode swapping. Dependency allocations/diagnostics and changed methods/state can remain after failure; tables/state retain codec ownership. No direct pixel decoding.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One after setup, zero on dependency/table/ABI setup failure.

Definition at line 2346 of file tif_jpeg.c.

References _TIFFNoPostDecode(), JPEGState::cinfo, JPEGState::comm, COMPRESSION_JPEG, FALSE, FIELD_JPEGTABLES, JPEGState::h_sampling, JPEGInitializeLibJPEG(), JState, JPEGState::otherSettings, JPEGState::photometric, PHOTOMETRIC_YCBCR, TIFFDirectory::td_bitspersample, TIFFDirectory::td_photometric, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_postdecode, TIFFErrorExtR(), TIFFFieldSet, TIFFjpeg_data_src(), TIFFjpeg_read_header(), TIFFjpeg_tables_src(), TIFFReInitJPEG_12(), TRUE, and JPEGState::v_sampling.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGSetupEncode()

static int JPEGSetupEncode ( TIFF *  tif)
static

Initialise JPEG compression parameters tables and output manager.

Can switch twelve-bit ABI through reinitialisation. Creates compression mode, establishes colour defaults, disables progressive output, handles dependency-specific Huffman policy, validates photometric/precision/sampling and MCU-aligned strip/tile dimensions. May supply ReferenceBlackWhite via a nested setter whose status is ignored. Table generation can replace owned storage and mark directory metadata dirty; placeholder detection reads eight bytes, so existing table storage must cover that prefix. Failure can leave changed tags/methods/dependency allocations. No caller ownership transfer or pixel transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One after setup, zero on detected validation/dependency/table allocation failure.

Definition at line 3508 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, JPEGState::comm, COMPRESSION_JPEG, FALSE, FIELD_JPEGTABLES, JPEGState::h_sampling, isTiled, JPEGOtherSettings::jpegcolormode, JPEGCOLORMODE_RGB, JPEGInitializeLibJPEG(), JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtablesmode, JPEGTABLESMODE_HUFF, JPEGTABLESMODE_QUANT, JState, JPEGState::otherSettings, JPEGState::photometric, PHOTOMETRIC_MASK, PHOTOMETRIC_MINISBLACK, PHOTOMETRIC_MINISWHITE, PHOTOMETRIC_PALETTE, PHOTOMETRIC_RGB, PHOTOMETRIC_SEPARATED, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, prepare_JPEGTables(), TIFFDirectory::td_bitspersample, TIFFDirectory::td_imagelength, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_tilelength, TIFFDirectory::td_tilewidth, TIFFDirectory::td_ycbcrsubsampling, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, tiff::tif_flags, TIFF_DIRTYDIRECT, TIFF_std_huff_tables(), TIFFClrFieldBit, TIFFErrorExtR(), TIFFGetField(), TIFFjpeg_data_dest(), TIFFjpeg_set_defaults(), TIFFReInitJPEG_12(), TIFFSetField(), TIFFSetFieldBit, TIFFTAG_REFERENCEBLACKWHITE, TIFFWarningExtR(), and JPEGState::v_sampling.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGVGetField()

static int JPEGVGetField ( TIFF *  tif,
uint32_t  tag,
va_list  ap 
)
static

Retrieve JPEG tables/options or delegate related tag queries.

JPEGTABLES consumes non-NULL uint32_t* length and const void** pointer outputs returning borrowed codec-owned storage, invalidated by replacement/build/cleanup. QUALITY, COLORMODE and TABLESMODE consume int*. Other tags, including YCbCrSubsampling, are delegated unchanged to the saved parent getter. This hook itself performs no allocation or client I/O; the parent getter's effects apply to delegated tags.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]tagJPEG/related tag identifier or parent-delegated tag.
[in,out]apLive tag-specific va_list cursor consumed synchronously; not retained.
Returns
One for codec retrieval, otherwise parent getter status.

Definition at line 4412 of file tif_jpeg.c.

References JPEGOtherSettings::jpegcolormode, JPEGOtherSettings::jpegquality, JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGOtherSettings::jpegtablesmode, JState, JPEGState::otherSettings, JPEGFixupTagsSubsamplingData::tif, TIFFTAG_JPEGCOLORMODE, TIFFTAG_JPEGQUALITY, TIFFTAG_JPEGTABLES, TIFFTAG_JPEGTABLESMODE, and JPEGOtherSettings::vgetparent.

Referenced by TIFFInitJPEGCommon().

Here is the caller graph for this function:

◆ JPEGVSetField()

static int JPEGVSetField ( TIFF *  tif,
uint32_t  tag,
va_list  ap 
)
static

Set JPEG tables or pseudo-options and chain related tag changes.

JPEGTABLES consumes uint32_t byte count then void*; zero rejects. The old table is freed before the copy; if the allocation fails (or the pointer is NULL) the table pointer is left NULL while the length, the field-present bit and TIFF_DIRTYDIRECT are still set and the function returns one, so callers cannot detect the failure. Supply a valid JPEG tables stream with sufficient setup prefix storage, not merely a positive length. QUALITY, COLORMODE and TABLESMODE consume int without comprehensive validation; colour mode updates upsampling caches. PHOTOMETRIC delegates then updates caches even on rejection; YCBCRSUBSAMPLING marks fetched before parent status. Other tags follow parent variadic contracts. Input table bytes are copied synchronously; old borrowed views can expire on failure.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
[in]tagJPEG/related tag identifier or parent-delegated tag.
[in,out]apLive tag-specific va_list cursor consumed synchronously; not retained.
Returns
One for handled pseudo-tags/table state, zero for explicit count/field rejection, or parent status; allocation failure need not be reflected.

Definition at line 4334 of file tif_jpeg.c.

References _TIFFsetByteArrayExt(), _TIFFField::field_bit, FIELD_JPEGTABLES, JPEGOtherSettings::jpegcolormode, JPEGOtherSettings::jpegquality, JPEGResetUpsampled(), JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGOtherSettings::jpegtablesmode, JState, JPEGState::otherSettings, JPEGFixupTagsSubsamplingData::tif, tiff::tif_flags, TIFF_DIRTYDIRECT, TIFFFieldWithTag(), TIFFSetFieldBit, TIFFTAG_JPEGCOLORMODE, TIFFTAG_JPEGQUALITY, TIFFTAG_JPEGTABLES, TIFFTAG_JPEGTABLESMODE, TIFFTAG_PHOTOMETRIC, TIFFTAG_YCBCRSUBSAMPLING, JPEGOtherSettings::vsetparent, and JPEGOtherSettings::ycbcrsampling_fetched.

Referenced by TIFFInitJPEGCommon().

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

◆ JPEGWritePacked12Sample()

static void JPEGWritePacked12Sample ( uint8_t *  buf,
tmsize_t  sample_index,
TIFF_JSAMPLE  sample 
)
static

Write one sample to TIFF packed twelve-bit bytes.

Requires nonnegative index and enough writable paired-byte storage. Masks to twelve bits. An even write assigns the shared byte and clears its low nibble; the following odd write preserves the high nibble. Write pairs in even-then-odd order when retaining both samples. No allocation, I/O, diagnostics, retained pointer or ownership transfer.

Parameters
[in,out]bufBorrowed packed twelve-bit byte storage with capacity for the indexed sample pair.
[in]sample_indexNonnegative sample index with representable paired-byte offset.
[in]sampleSample value; low twelve bits are stored.

Definition at line 1232 of file tif_jpeg.c.

Referenced by JPEGDecodeRaw().

Here is the caller graph for this function:

◆ prepare_JPEGTables()

static int prepare_JPEGTables ( TIFF *  tif)
static

Generate selected JPEG quantisation and Huffman tables.

Applies quality, suppresses all tables then selectively enables requested luma/chroma entries. Replaces owned table storage with a tables-only destination and emits the stream. Failures can invalidate old table views and retain partial new tables/dependency state; wrapper diagnostics apply. No client payload I/O or caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One after emission, zero on dependency/table-buffer failure.

Definition at line 3413 of file tif_jpeg.c.

References FALSE, JPEGOtherSettings::jpegquality, JPEGOtherSettings::jpegtablesmode, JPEGTABLESMODE_HUFF, JPEGTABLESMODE_QUANT, JState, JPEGState::otherSettings, JPEGState::photometric, PHOTOMETRIC_YCBCR, JPEGFixupTagsSubsamplingData::tif, TIFFjpeg_set_quality(), TIFFjpeg_suppress_tables(), TIFFjpeg_tables_dest(), TIFFjpeg_write_tables(), TRUE, unsuppress_huff_table(), and unsuppress_quant_table().

Referenced by JPEGSetupEncode().

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

◆ std_empty_output_buffer()

static boolean std_empty_output_buffer ( j_compress_ptr  cinfo)
static

Flush produced JPEG payload and reset the dependency output window.

Sets rawcc from the produced extent (with IPP-specific adjustment when compiled), invokes TIFFFlushData1 then reattaches raw storage. I/O/diagnostics and partial file/cache changes can survive failure; no allocation owned by caller or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.
Returns
TRUE after flush/reset, FALSE on flush failure.

Definition at line 1378 of file tif_jpeg.c.

References JPEGState::dest, FALSE, JPEGState::tif, tiff::tif_rawcc, tiff::tif_rawdata, tiff::tif_rawdatasize, TIFFFlushData1(), and TRUE.

Referenced by TIFFjpeg_data_dest().

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

◆ std_fill_input_buffer()

static boolean std_fill_input_buffer ( j_decompress_ptr  cinfo)
static

Supply a synthetic JPEG end marker when cached input is exhausted.

Normally warns through dependency routing then points the source manager at immutable two-byte EOI storage. Optional IPP behavior retains nonempty input instead. Does not refill client I/O or prove valid/truly complete input; truncated input can therefore recover. No allocation or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.
Returns
TRUE unconditionally.

Definition at line 1608 of file tif_jpeg.c.

References JPEGState::src, and TRUE.

Referenced by std_skip_input_data(), and TIFFjpeg_data_src().

Here is the caller graph for this function:

◆ std_init_destination()

static void std_init_destination ( j_compress_ptr  cinfo)
static

Attach libjpeg output to the handle raw buffer.

Borrows positive-capacity raw storage and resets the dependency output pointer/count. Does not flush, allocate or transfer ownership; caller must keep raw storage live throughout compression.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1356 of file tif_jpeg.c.

References JPEGState::dest, JPEGState::tif, tiff::tif_rawdata, and tiff::tif_rawdatasize.

Referenced by TIFFjpeg_data_dest().

Here is the caller graph for this function:

◆ std_init_source()

static void std_init_source ( j_decompress_ptr  cinfo)
static

Attach libjpeg input to cached raw strile bytes.

Borrows rawdata and nonnegative rawcc; does not read client bytes or advance TIFF raw cursors directly. Keep storage live until dependency consumption completes. No allocation, diagnostics or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1585 of file tif_jpeg.c.

References JPEGState::src, JPEGState::tif, tiff::tif_rawcc, and tiff::tif_rawdata.

Referenced by TIFFjpeg_data_src().

Here is the caller graph for this function:

◆ std_skip_input_data()

static void std_skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)
static

Skip cached JPEG input or substitute synthetic end-of-image.

Nonpositive counts do nothing. A count within cached bytes advances source cursor; a larger count invokes the fake-EOI fill without seeking the underlying stream or consuming the original requested count. Can warn, no allocation or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.
[in]num_bytesRequested cached input skip in bytes; nonpositive means no change.

Definition at line 1658 of file tif_jpeg.c.

References JPEGState::src, and std_fill_input_buffer().

Referenced by TIFFjpeg_data_src().

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

◆ std_term_destination()

static void std_term_destination ( j_compress_ptr  cinfo)
static

Commit dependency output cursor and pending bytes to the TIFF cache.

Sets rawcp/rawcc from dependency state without flushing the final buffer. No allocation, diagnostics, direct client I/O or ownership transfer; buffered bytes remain handle-owned.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1418 of file tif_jpeg.c.

References JPEGState::dest, JPEGState::tif, tiff::tif_rawcc, tiff::tif_rawcp, and tiff::tif_rawdatasize.

Referenced by TIFFjpeg_data_dest().

Here is the caller graph for this function:

◆ std_term_source()

static void std_term_source ( j_decompress_ptr  cinfo)
static

Complete JPEG source management without additional work.

Ignores the context; does not free borrowed input, allocate, do I/O, diagnose or transfer ownership.

Parameters
[in]cinfoUnused.

Definition at line 1686 of file tif_jpeg.c.

Referenced by TIFFjpeg_data_src().

Here is the caller graph for this function:

◆ suppress_huff_table()

static void suppress_huff_table ( JPEGState *  sp,
int  tblno 
)
static

Suppress emission of an existing JPEG huff table.

Requires a valid table index in dependency bounds. If present, sets its sent_table flag to TRUE. Applies to both DC and AC Huffman entries. No allocation, client I/O, diagnostics, ownership transfer or status result.

Parameters
[in,out]spBorrowed live JPEG state and dependency-owned table views.
[in]tblnoHuffman table index, 0 to NUM_HUFF_TBLS-1; selects both the DC and the AC table.

Definition at line 3389 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, and TRUE.

Referenced by JPEGPreEncode().

Here is the caller graph for this function:

◆ suppress_quant_table()

static void suppress_quant_table ( JPEGState *  sp,
int  tblno 
)
static

Suppress emission of an existing JPEG quant table.

Requires a valid table index in dependency bounds. If present, sets its sent_table flag to TRUE. No allocation, client I/O, diagnostics, ownership transfer or status result.

Parameters
[in,out]spBorrowed live JPEG state and dependency-owned table views.
[in]tblnoQuantisation table index, 0 to NUM_QUANT_TBLS-1.

Definition at line 3345 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, and TRUE.

Referenced by JPEGPreEncode().

Here is the caller graph for this function:

◆ tables_empty_output_buffer()

static boolean tables_empty_output_buffer ( j_compress_ptr  cinfo)
static

Grow the codec-owned JPEG table allocation by one thousand bytes.

Requires representable capacity growth and active CALLJPEG frame. Ext realloc can invalidate old table/output views; updates pointer/capacity and returns TRUE after growth. Failure raises a fatal dependency out-of-memory error and longjmps through the installed handler. No client I/O or caller ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.
Returns
TRUE on growth; allocation failure normally exits through the error handler.

Definition at line 1490 of file tif_jpeg.c.

References _TIFFreallocExt(), JPEGState::dest, JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGState::otherSettings, JPEGState::tif, and TRUE.

Referenced by TIFFjpeg_tables_dest().

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

◆ tables_init_destination()

static void tables_init_destination ( j_compress_ptr  cinfo)
static

Begin writing JPEG tables into the codec-owned table allocation.

Borrows jpegtables and its current capacity and resets dependency output pointers. Requires valid live positive storage; no allocation, I/O, diagnostics or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1465 of file tif_jpeg.c.

References JPEGState::dest, JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, and JPEGState::otherSettings.

Referenced by TIFFjpeg_tables_dest().

Here is the caller graph for this function:

◆ tables_init_source()

static void tables_init_source ( j_decompress_ptr  cinfo)
static

Attach libjpeg input to codec-owned JPEG table bytes.

Borrows jpegtables/length and resets source cursor. Keep table storage live throughout parsing; no allocation, client I/O, diagnostics or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1731 of file tif_jpeg.c.

References JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGState::otherSettings, and JPEGState::src.

Referenced by TIFFjpeg_tables_src().

Here is the caller graph for this function:

◆ tables_term_destination()

static void tables_term_destination ( j_compress_ptr  cinfo)
static

Replace JPEG table capacity with the emitted table-stream length.

Subtracts unused destination bytes from jpegtables_length. Requires coherent capacity/count arithmetic. No allocation, I/O, diagnostics or ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 1520 of file tif_jpeg.c.

References JPEGState::dest, JPEGOtherSettings::jpegtables_length, and JPEGState::otherSettings.

Referenced by TIFFjpeg_tables_dest().

Here is the caller graph for this function:

◆ TIFF_std_huff_tables()

static void TIFF_std_huff_tables ( j_compress_ptr  cinfo)
static

Populate missing standard JPEG Huffman tables for relevant dependency versions.

Copies built-in standard bit-count/value arrays into dependency-owned table objects, allocating absent entries directly through libjpeg. Requires a live compressor and valid installed error context; this helper establishes no new local setjmp frame. Dependency allocation/fatal-handler effects apply. No client payload I/O, retained caller pointer or ownership transfer; no status result.

Parameters
[in,out]cinfoBorrowed live dependency compressor context with installed fatal-error routing.

Definition at line 3467 of file tif_jpeg.c.

References FALSE, and TRUE.

Referenced by JPEGSetupEncode().

Here is the caller graph for this function:

◆ TIFFInitJPEG()

int TIFFInitJPEG ( TIFF *  tif,
int  scheme 
)
extern

Allocate JPEG-in-TIFF codec state and install method chains.

Requires COMPRESSION_JPEG and cleaned-up previous state. Merges fields, allocates zeroed Ext state, saves tag/print/sizing hooks and installs common callbacks. For a not-yet-written directory allocates a zero-filled 2000-byte JPEGTables placeholder without marking its field present; later setup builds real tables. Failures diagnose and can retain installed state for lifecycle cleanup. Dependency context is created lazily; no pixel I/O or caller ownership transfer.

Parameters
[in,out]tifNon-NULL handle whose previous codec state has been cleaned up; receives the new codec state. Serialise operations.
[in]schemeCOMPRESSION_JPEG, asserted in debug builds.
Returns
One after installation/placeholder setup, zero on field or allocation failure.

Definition at line 4724 of file tif_jpeg.c.

References _TIFFmallocExt(), _TIFFmemset(), _TIFFMergeFields(), COMPRESSION_JPEG, JPEGOtherSettings::defsparent, JPEGOtherSettings::deftparent, jpegFields, JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JState, JPEGState::otherSettings, JPEGOtherSettings::printdir, TIFFTagMethods::printdir, SIZE_OF_JPEGTABLES, JPEGFixupTagsSubsamplingData::tif, tiff::tif_data, tiff::tif_defstripsize, tiff::tif_deftilesize, tiff::tif_diroff, tiff::tif_tagmethods, TIFFArrayCount, TIFFErrorExtR(), TIFFInitJPEGCommon(), TIFFTagMethods::vgetfield, JPEGOtherSettings::vgetparent, TIFFTagMethods::vsetfield, and JPEGOtherSettings::vsetparent.

Here is the call graph for this function:

◆ TIFFInitJPEGCommon()

static void TIFFInitJPEGCommon ( TIFF *  tif)
static

Install common JPEG callbacks defaults and handle backlink.

Requires a fresh/zeroed ABI-appropriate state with parent hooks preserved separately. Resets table pointer/length and codec defaults, installs tag/setup/transfer/sizing methods, sets NOBITREV and clears dependency-created flag. Does not release any old tables/dependency objects or allocate/read/write pixels. Twelve-bit reinitialisation restores preserved otherSettings afterward; no caller ownership transfer.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.

Definition at line 4680 of file tif_jpeg.c.

References JPEGState::cinfo_initialized, FALSE, JPEGCleanup(), JPEGOtherSettings::jpegcolormode, JPEGCOLORMODE_RAW, JPEGDecode(), JPEGDefaultStripSize(), JPEGDefaultTileSize(), JPEGEncode(), JPEGFixupTags(), JPEGGetMaxCompressionRatio(), JPEGPostEncode(), JPEGPreDecode(), JPEGPreEncode(), JPEGPrintDir(), JPEGOtherSettings::jpegquality, JPEGSetupDecode(), JPEGSetupEncode(), JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGOtherSettings::jpegtablesmode, JPEGTABLESMODE_HUFF, JPEGTABLESMODE_QUANT, JPEGVGetField(), JPEGVSetField(), JState, JPEGState::otherSettings, TIFFTagMethods::printdir, JPEGState::tif, JPEGFixupTagsSubsamplingData::tif, tiff::tif_cleanup, tiff::tif_decoderow, tiff::tif_decodestrip, tiff::tif_decodetile, tiff::tif_defstripsize, tiff::tif_deftilesize, tiff::tif_encoderow, tiff::tif_encodestrip, tiff::tif_encodetile, tiff::tif_fixuptags, tiff::tif_flags, tiff::tif_getmaxcompressionratio, tiff::tif_postencode, tiff::tif_predecode, tiff::tif_preencode, tiff::tif_setupdecode, tiff::tif_setupencode, tiff::tif_tagmethods, TIFF_NOBITREV, TIFFTagMethods::vgetfield, TIFFTagMethods::vsetfield, and JPEGOtherSettings::ycbcrsampling_fetched.

Referenced by TIFFInitJPEG().

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

◆ TIFFjpeg_abort()

static int TIFFjpeg_abort ( JPEGState *  sp)
static

Abort the current dependency operation and release image-pool storage.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 1283 of file tif_jpeg.c.

References CALLVJPEG, JPEGState::cinfo, and JPEGState::comm.

Referenced by JPEGPreDecode().

Here is the caller graph for this function:

◆ TIFFjpeg_alloc_sarray()

static JSAMPARRAY TIFFjpeg_alloc_sarray ( JPEGState *  sp,
int  pool_id,
JDIMENSION  samplesperrow,
JDIMENSION  numrows 
)
static

Allocate sample-row storage in a dependency memory pool.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Requires a valid pool and representable row dimensions/capacity under the dependency ABI. Returned rows belong to that pool: image-pool rows expire on abort/finish/destroy, permanent-pool rows on destroy. Do not free individual rows or retain views past pool release.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]pool_idValid dependency memory pool identifier.
[in]samplesperrowSamples per allocated row under the dependency allocation ABI; products must fit.
[in]numrowsNumber of allocated rows; products must fit.
Returns
Borrowed dependency-owned sample-row array, or NULL on trapped allocation/dependency error.

Definition at line 1330 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::comm.

Referenced by alloc_downsampled_buffers().

Here is the caller graph for this function:

◆ TIFFjpeg_create_compress()

static int TIFFjpeg_create_compress ( JPEGState *  sp)
static

Create a libjpeg compressor and install TIFF error routing.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Requires an uncreated/destroyed dependency object; installs error manager and clears client_data before creation.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 720 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, JPEGState::cinfo, JPEGState::err, TIFFjpeg_error_exit(), and TIFFjpeg_output_message().

Referenced by JPEGInitializeLibJPEG().

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

◆ TIFFjpeg_create_decompress()

static int TIFFjpeg_create_decompress ( JPEGState *  sp)
static

Create a libjpeg decompressor and install TIFF error routing.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Requires an uncreated/destroyed dependency object; installs error manager and clears client_data before creation.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 750 of file tif_jpeg.c.

References CALLVJPEG, JPEGState::cinfo, JPEGState::d, JPEGState::err, TIFFjpeg_error_exit(), and TIFFjpeg_output_message().

Referenced by JPEGInitializeLibJPEG(), and TIFFJPEGIsFullStripRequired().

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

◆ TIFFjpeg_data_dest()

static void TIFFjpeg_data_dest ( JPEGState *  sp,
TIFF *  tif 
)
static

Install raw-buffer JPEG output manager callbacks.

Attaches the embedded destination manager to compressor state and assigns init/flush/term functions. Requires live state/handle context and raw buffers when later invoked. No immediate allocation, I/O or ownership transfer.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]tifUnused.

Definition at line 1441 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, JPEGState::dest, std_empty_output_buffer(), std_init_destination(), and std_term_destination().

Referenced by JPEGSetupEncode().

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

◆ TIFFjpeg_data_src()

static void TIFFjpeg_data_src ( JPEGState *  sp)
static

Install cached-strile JPEG source manager callbacks.

Attaches embedded source manager, sets init/fill/skip/term and dependency restart resynchronisation methods, and clears input pointer/count for safety. No immediate allocation, I/O, diagnostics or ownership transfer.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.

Definition at line 1703 of file tif_jpeg.c.

References JPEGState::cinfo, JPEGState::d, JPEGState::src, std_fill_input_buffer(), std_init_source(), std_skip_input_data(), and std_term_source().

Referenced by JPEGSetupDecode(), TIFFjpeg_tables_src(), and TIFFJPEGIsFullStripRequired().

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

◆ TIFFjpeg_destroy()

static int TIFFjpeg_destroy ( JPEGState *  sp)
static

Destroy dependency resources while retaining outer JPEGState.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 1303 of file tif_jpeg.c.

References CALLVJPEG, JPEGState::cinfo, and JPEGState::comm.

Referenced by JPEGCleanup(), JPEGInitializeLibJPEG(), and TIFFJPEGIsFullStripRequired().

Here is the caller graph for this function:

◆ TIFFjpeg_error_exit()

static void TIFFjpeg_error_exit ( j_common_ptr  cinfo)
static

Route a fatal JPEG error abort the operation and jump to its wrapper.

Requires cinfo first within live JPEGState and an active CALLJPEG setjmp frame. Formats into stack text, dispatches handle error, calls jpeg_abort and longjmps. Does not normally return; dependency image storage/views can be invalidated. Application diagnostic callbacks must not close/reconfigure the active handle. No caller ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 582 of file tif_jpeg.c.

References JPEGState::exit_jmpbuf, LONGJMP, JPEGState::tif, and TIFFErrorExtR().

Referenced by TIFFjpeg_create_compress(), and TIFFjpeg_create_decompress().

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

◆ TIFFjpeg_finish_compress()

static int TIFFjpeg_finish_compress ( JPEGState *  sp)
static

Finish dependency compression through the attached destination.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 958 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by JPEGPostEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_finish_decompress()

static int TIFFjpeg_finish_decompress ( JPEGState *  sp)
static

Finish dependency decompression after output rows.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
Dependency Boolean result, or minus one on trapped fatal error; suspension/false is zero.

Definition at line 1263 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::d.

Referenced by JPEGDecode(), and JPEGDecodeRaw().

Here is the caller graph for this function:

◆ TIFFjpeg_has_multiple_scans()

static int TIFFjpeg_has_multiple_scans ( JPEGState *  sp)
static

Query whether dependency input uses multiple scans.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Requires a parsed decompression header.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
Dependency Boolean result, or zero on trapped fatal error; zero does not distinguish single-scan from failure.

Definition at line 1020 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::d.

Referenced by JPEGPreDecode(), and TIFFJPEGIsFullStripRequired().

Here is the caller graph for this function:

◆ TIFFjpeg_output_message()

static void TIFFjpeg_output_message ( j_common_ptr  cinfo)
static

Route a dependency warning through the TIFF handle.

Requires cinfo first in live JPEGState. Formats borrowed error state into stack text and invokes handle warning callbacks synchronously. No output allocation, payload I/O, pointer retention or ownership transfer.

Parameters
[in]cinfoBorrowed dependency context at the beginning of a live JPEGState; only read to format the message.

Definition at line 610 of file tif_jpeg.c.

References TIFFWarningExtR().

Referenced by TIFFjpeg_create_compress(), and TIFFjpeg_create_decompress().

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

◆ TIFFjpeg_progress_monitor()

static void TIFFjpeg_progress_monitor ( j_common_ptr  cinfo)
static

Abort JPEG decompression when its scan count reaches the configured limit.

Reads dependency scan progress and cached limit; on threshold dispatches an error, aborts dependency image state and longjmps to an active wrapper. Otherwise returns without mutation. Requires an active wrapper frame and live state; no caller ownership transfer.

Parameters
[in,out]cinfoBorrowed dependency context at the beginning of a live JPEGState; callbacks are synchronous under its wrapper frame.

Definition at line 636 of file tif_jpeg.c.

References JPEGState::exit_jmpbuf, LONGJMP, JPEGOtherSettings::max_allowed_scan_number, JPEGState::otherSettings, and TIFFErrorExtR().

Referenced by TIFFjpeg_start_decompress().

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

◆ TIFFjpeg_read_header()

static int TIFFjpeg_read_header ( JPEGState *  sp,
boolean  require_image 
)
static

Parse a dependency JPEG header or tables-only stream.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Source manager state can advance even on a rejected header.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]require_imageDependency Boolean requiring a complete image header rather than tables only.
Returns
Dependency JPEG_HEADER result (including suspension), or minus one on trapped fatal error.

Definition at line 1000 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::d.

Referenced by JPEGPreDecode(), JPEGSetupDecode(), and TIFFJPEGIsFullStripRequired().

Here is the caller graph for this function:

◆ TIFFjpeg_read_raw_data()

static int TIFFjpeg_read_raw_data ( JPEGState *  sp,
TIFF_JSAMPIMAGE  data,
int  max_lines 
)
static

Decode dependency downsampled component rows.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Uses the twelve-bit dependency entry point in the enabled dual-mode twelve-bit translation. Buffers must match that compile-time sample ABI and requested row capacities.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in,out]dataBorrowed component sample planes (pointer arrays read) whose padded rows receive the decoded samples.
[in]max_linesNonnegative maximum row count fitting JDIMENSION and the supplied buffers.
Returns
Nonnegative row count returned by the dependency (possibly zero), or minus one on trapped fatal error.

Definition at line 1116 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::d.

Referenced by JPEGDecodeRaw().

Here is the caller graph for this function:

◆ TIFFjpeg_read_scanlines()

static int TIFFjpeg_read_scanlines ( JPEGState *  sp,
TIFF_JSAMPARRAY  scanlines,
int  max_lines 
)
static

Decode dependency scanline rows.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Uses the twelve-bit dependency entry point in the enabled dual-mode twelve-bit translation. Buffers must match that compile-time sample ABI and requested row capacities.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in,out]scanlinesBorrowed row-pointer array (read) whose rows receive up to max_lines decoded rows of compile-time-ABI samples.
[in]max_linesNonnegative maximum row count fitting JDIMENSION and the supplied buffers.
Returns
Nonnegative row count returned by the dependency (possibly zero), or minus one on trapped fatal error.

Definition at line 1081 of file tif_jpeg.c.

References CALLJPEG, JPEGState::cinfo, and JPEGState::d.

Referenced by JPEGDecode().

Here is the caller graph for this function:

◆ TIFFjpeg_set_colorspace()

static int TIFFjpeg_set_colorspace ( JPEGState *  sp,
J_COLOR_SPACE  colorspace 
)
static

Select the dependency compression colour space.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]colorspaceDependency colour-space value for compression.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 799 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by JPEGPreEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_set_defaults()

static int TIFFjpeg_set_defaults ( JPEGState *  sp)
static

Apply dependency default compression parameters.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 778 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by JPEGSetupEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_set_quality()

static int TIFFjpeg_set_quality ( JPEGState *  sp,
int  quality,
boolean  force_baseline 
)
static

Set dependency quantisation quality and baseline policy.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]qualityDependency quality setting; dependency policy determines clipping/validation.
[in]force_baselineDependency Boolean restricting generated quantisation for baseline compatibility.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 823 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by JPEGPreEncode(), and prepare_JPEGTables().

Here is the caller graph for this function:

◆ TIFFjpeg_start_compress()

static int TIFFjpeg_start_compress ( JPEGState *  sp,
boolean  write_all_tables 
)
static

Start the dependency compressor for a strile.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]write_all_tablesDependency Boolean controlling complete table emission.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 868 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by JPEGPreEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_start_decompress()

static int TIFFjpeg_start_decompress ( JPEGState *  sp)
static

Start the dependency decompressor and progress monitor.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Installs a scan-count progress guard defaulting to 100, overridden by a decimal LIBTIFF_JPEG_MAX_ALLOWED_SCAN_NUMBER of at most INT_MAX; a malformed or out-of-range value keeps the default. TIFFjpeg_progress_monitor() also reports an error and longjmps here once the scan limit is reached.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 1045 of file tif_jpeg.c.

References _TIFFParseUInt32(), CALLVJPEG, JPEGState::cinfo, JPEGState::d, JPEGOtherSettings::max_allowed_scan_number, JPEGState::otherSettings, JPEGState::progress, and TIFFjpeg_progress_monitor().

Referenced by JPEGPreDecode().

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

◆ TIFFjpeg_suppress_tables()

static int TIFFjpeg_suppress_tables ( JPEGState *  sp,
boolean  suppress 
)
static

Set dependency table-emission suppression.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]suppressDependency Boolean table-suppression policy.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 846 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by prepare_JPEGTables().

Here is the caller graph for this function:

◆ TIFFjpeg_tables_dest()

static int TIFFjpeg_tables_dest ( JPEGState *  sp,
TIFF *  tif 
)
static

Replace table storage and install tables-only output callbacks.

Frees previous table storage, allocates one thousand Ext bytes and installs the embedded destination manager. Failure clears length and diagnoses after old views are invalidated. Codec owns the allocation until replacement/cleanup; no client I/O or caller ownership transfer.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]tifLive handle whose memory accounting is used for the table allocation; must be the handle that owns sp.
Returns
One after allocation/installation, zero on allocation failure.

Definition at line 1543 of file tif_jpeg.c.

References _TIFFfreeExt(), _TIFFmallocExt(), JPEGState::c, JPEGState::cinfo, JPEGState::dest, JPEGOtherSettings::jpegtables, JPEGOtherSettings::jpegtables_length, JPEGState::otherSettings, tables_empty_output_buffer(), tables_init_destination(), tables_term_destination(), JPEGState::tif, and TIFFErrorExtR().

Referenced by prepare_JPEGTables().

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

◆ TIFFjpeg_tables_src()

static void TIFFjpeg_tables_src ( JPEGState *  sp)
static

Install the JPEG source manager for tables-only input.

Installs normal source callbacks then substitutes the table init callback. No immediate allocation, I/O, diagnostics or ownership transfer; table bytes remain codec-owned.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.

Definition at line 1750 of file tif_jpeg.c.

References JPEGState::src, tables_init_source(), and TIFFjpeg_data_src().

Referenced by JPEGSetupDecode().

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

◆ TIFFjpeg_write_raw_data()

static int TIFFjpeg_write_raw_data ( JPEGState *  sp,
TIFF_JSAMPIMAGE  data,
int  num_lines 
)
static

Encode dependency downsampled component rows.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Uses the twelve-bit dependency entry point in the enabled dual-mode twelve-bit translation. Buffers must match that compile-time sample ABI and requested row capacities.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]dataBorrowed component sample planes, read by the encoder; each must hold the dependency-required padded rows.
[in]num_linesNonnegative row count fitting JDIMENSION and the supplied buffers.
Returns
Nonnegative row count returned by the dependency (possibly zero), or minus one on trapped fatal error.

Definition at line 929 of file tif_jpeg.c.

References JPEGState::c, CALLJPEG, and JPEGState::cinfo.

Referenced by JPEGEncodeRaw(), and JPEGPostEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_write_scanlines()

static int TIFFjpeg_write_scanlines ( JPEGState *  sp,
TIFF_JSAMPARRAY  scanlines,
int  num_lines 
)
static

Encode dependency scanline rows.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back. Uses the twelve-bit dependency entry point in the enabled dual-mode twelve-bit translation. Buffers must match that compile-time sample ABI and requested row capacities.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
[in]scanlinesBorrowed row-pointer array whose num_lines rows of compile-time-ABI samples are read and encoded.
[in]num_linesNonnegative row count fitting JDIMENSION and the supplied buffers.
Returns
Nonnegative row count returned by the dependency (possibly zero), or minus one on trapped fatal error.

Definition at line 894 of file tif_jpeg.c.

References JPEGState::c, CALLJPEG, and JPEGState::cinfo.

Referenced by JPEGEncode().

Here is the caller graph for this function:

◆ TIFFjpeg_write_tables()

static int TIFFjpeg_write_tables ( JPEGState *  sp)
static

Emit a tables-only JPEG stream through the destination.

Runs the libjpeg call under CALLJPEG()/CALLVJPEG(), which set a jump point on sp->exit_jmpbuf. A fatal libjpeg error is reported by TIFFjpeg_error_exit(), which aborts the libjpeg object and longjmps back here; work done before the error (allocations, buffer and manager state, I/O) is not rolled back.

Parameters
[in,out]spBorrowed live JPEGState with cinfo at offset zero, valid dependency mode and saved handle context.
Returns
One if the dependency call returns without a fatal longjmp, zero on trapped failure; any Boolean return from the dependency operation is discarded by this void-style wrapper.

Definition at line 978 of file tif_jpeg.c.

References JPEGState::c, CALLVJPEG, and JPEGState::cinfo.

Referenced by prepare_JPEGTables().

Here is the caller graph for this function:

◆ TIFFJPEGIsFullStripRequired()

int TIFFJPEGIsFullStripRequired ( TIFF *  tif)
extern

Probe whether cached JPEG input needs whole-strile decoding.

Independently creates a temporary dependency decompressor over rawdata/rawcc, reads a header, queries multiple scans and destroys dependency state. Enabled twelve-bit input delegates to the twelve-bit probe. Requires valid readable raw bytes and sample depth; does not require usual codec setup. Some create/destroy statuses are ignored. Diagnostics and synthetic-EOI recovery can occur; no caller storage ownership transfer or client reads.

Parameters
[in,out]tifNon-NULL live JPEG handle with compatible current directory/state; serialise operations.
Returns
One for multiple scans, zero for single-scan input or trapped/header failure; zero does not distinguish failure.

Definition at line 2410 of file tif_jpeg.c.

References TIFFDirectory::td_bitspersample, JPEGState::tif, JPEGFixupTagsSubsamplingData::tif, tiff::tif_dir, TIFFjpeg_create_decompress(), TIFFjpeg_data_src(), TIFFjpeg_destroy(), TIFFjpeg_has_multiple_scans(), TIFFjpeg_read_header(), TIFFJPEGIsFullStripRequired_12(), and TRUE.

Referenced by TIFFFillStripPartial().

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

◆ TIFFJPEGIsFullStripRequired_12()

int TIFFJPEGIsFullStripRequired_12 ( TIFF *  tif)

Probe cached twelve-bit JPEG input for whole-strile requirements.

Twelve-bit ABI counterpart of TIFFJPEGIsFullStripRequired(); same borrowed input, temporary dependency lifetime, diagnostic and ambiguous-zero status contract.

Parameters
[in,out]tifNon-NULL live handle with compatible twelve-bit raw input.
Returns
One for multiple scans, zero for single-scan or trapped/header failure.

Referenced by TIFFJPEGIsFullStripRequired().

Here is the caller graph for this function:

◆ TIFFReInitJPEG_12()

int TIFFReInitJPEG_12 ( TIFF *  tif,
const JPEGOtherSettings *  otherSettings,
int  scheme,
int  is_encode 
)

Replace JPEG state with the twelve-bit ABI and restore saved options.

Reallocates outer Ext storage, zeroes it, installs common methods, shallow-copies saved options/table ownership, then calls encode/decode setup. otherSettings must be a live disjoint copy outside the allocation being reallocated/cleared. Caller must account for previous dependency resources before replacement; this function does not destroy them itself. Realloc failure leaves the old block allocated; later failure can leave replaced state/methods for cleanup. No pixel I/O or caller storage ownership transfer.

Parameters
[in,out]tifNon-NULL handle whose old JPEG allocation may be replaced.
[in]otherSettingsBorrowed disjoint ABI-independent snapshot, including live parent hooks/table ownership.
[in]schemeCOMPRESSION_JPEG, asserted in debug builds.
[in]is_encodeNonzero invokes encoder setup, zero decoder setup.
Returns
Setup status after replacement, or zero on outer realloc failure.

Referenced by JPEGSetupDecode(), and JPEGSetupEncode().

Here is the caller graph for this function:

◆ unsuppress_huff_table()

static void unsuppress_huff_table ( JPEGState *  sp,
int  tblno 
)
static

Enable emission of an existing JPEG huff table.

Requires a valid table index in dependency bounds. If present, sets its sent_table flag to FALSE. Applies to both DC and AC Huffman entries. No allocation, client I/O, diagnostics, ownership transfer or status result.

Parameters
[in,out]spBorrowed live JPEG state and dependency-owned table views.
[in]tblnoHuffman table index, 0 to NUM_HUFF_TBLS-1; selects both the DC and the AC table.

Definition at line 3366 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, and FALSE.

Referenced by prepare_JPEGTables().

Here is the caller graph for this function:

◆ unsuppress_quant_table()

static void unsuppress_quant_table ( JPEGState *  sp,
int  tblno 
)
static

Enable emission of an existing JPEG quant table.

Requires a valid table index in dependency bounds. If present, sets its sent_table flag to FALSE. No allocation, client I/O, diagnostics, ownership transfer or status result.

Parameters
[in,out]spBorrowed live JPEG state and dependency-owned table views.
[in]tblnoQuantisation table index, 0 to NUM_QUANT_TBLS-1.

Definition at line 3325 of file tif_jpeg.c.

References JPEGState::c, JPEGState::cinfo, and FALSE.

Referenced by JPEGPreEncode(), and prepare_JPEGTables().

Here is the caller graph for this function:

Variable Documentation

◆ jpegFields

const TIFFField jpegFields[]
static
Initial value:
= {
FIELD_JPEGTABLES, FALSE, TRUE, "JPEGTables", NULL},
TRUE, FALSE, "", NULL},
FALSE, FALSE, "", NULL},
FALSE, FALSE, "", NULL}}
#define FIELD_PSEUDO
Share bit zero with FIELD_IGNORE for pseudo-tags.
Definition tif_dir.h:620
@ TIFF_SETGET_INT
Promoted int scalar representation.
Definition tif_dir.h:762
@ TIFF_SETGET_C32_UINT8
Unsigned 8-bit array with 32-bit explicit count.
Definition tif_dir.h:816
#define FIELD_JPEGTABLES
Reserve the codec field bit for JPEGTables.
Definition tif_jpeg.c:536
#define TRUE
Represent the legacy internal true value.
Definition tiffiop.h:131
#define FALSE
Represent the legacy internal false value.
Definition tiffiop.h:136
#define TIFF_ANY
Match any data type when searching for a field descriptor.
Definition tiffio.h:1289
#define TIFFTAG_JPEGTABLESMODE
Pseudo-tag: What to put in JPEGTables.
Definition tiff.h:1553
#define TIFFTAG_JPEGQUALITY
Pseudo-tag: Compression quality level.
Definition tiff.h:1544
#define TIFFTAG_JPEGCOLORMODE
Pseudo-tag: Auto RGB<=>YCbCr convert?
Definition tiff.h:1547
#define TIFFTAG_JPEGTABLES
TIFF tag: JPEG table stream (introduced after TIFF 6.0).
Definition tiff.h:645
@ TIFF_UNDEFINED
Untyped 8-bit data.
Definition tiff.h:245

Define JPEG table and quality/colour/table-mode tag metadata.

Immutable library-lifetime metadata merged into a handle; no caller ownership transfer.

Definition at line 545 of file tif_jpeg.c.

Referenced by TIFFInitJPEG().