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

Bridge libjpeg error frames managers and JPEG-in-TIFF transfers. More...

#include "tiffiop.h"
#include <stdlib.h>
#include <setjmp.h>
#include "jerror.h"
#include "jpeglib.h"
Include dependency graph for tif_jpeg.c:

Go to the source code of this file.

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 TIFF_JPEG_MAX_MEMORY_TO_USE   (10 * 1024 * 1024)
 Preferred libjpeg compressor memory limit.
 
#define SIZE_OF_JPEGTABLES   2000
 Size of the zero-filled placeholder JPEGTables buffer.
 

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 TIFFFillStrip (TIFF *tif, uint32_t strip)
 Load raw strip bytes and initialise codec decoding.
 
int TIFFFillTile (TIFF *tif, uint32_t tile)
 Load raw tile bytes and initialise codec decoding.
 
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 int JPEGDecode (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Decode whole JPEG output rows into caller bytes.
 
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 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 JPEGInitializeLibJPEG (TIFF *tif, int decompress)
 Create or switch the embedded dependency compressor/decompressor.
 
static int DecodeRowError (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Reject scanline access to raw downsampled JPEG clumps.
 
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 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 JPEGFixupTags (TIFF *tif)
 Attempt JPEG-stream YCbCr subsampling correction before ordinary access.
 
static int JPEGSetupDecode (TIFF *tif)
 Initialise JPEG decompression tables sampling and source managers.
 
int TIFFJPEGIsFullStripRequired (TIFF *tif)
 Probe whether cached JPEG input needs whole-strile decoding.
 
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 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 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 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.
 

Variables

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

Detailed Description

Bridge libjpeg error frames managers and JPEG-in-TIFF transfers.

Definition in file tif_jpeg.c.