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

Decode legacy TIFF JPEG by reconstructing a dependency input stream. More...

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

Go to the source code of this file.

Data Structures

struct  OJPEGState
 Own old-style JPEG reconstruction tables buffers and dependency sessions. More...
 

Macros

#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
 Type used to store the libjpeg error jump frame.
 
#define OJPEG_BUFFER   2048
 Capacity in bytes of the embedded input and synthetic marker buffers.
 
#define JPEG_MARKER_SOF0   0xC0
 JPEG SOF0 (baseline DCT start-of-frame) marker code.
 
#define JPEG_MARKER_SOF1   0xC1
 JPEG SOF1 (extended sequential DCT start-of-frame) marker code.
 
#define JPEG_MARKER_SOF3   0xC3
 JPEG SOF3 (lossless start-of-frame) marker code.
 
#define JPEG_MARKER_DHT   0xC4
 JPEG DHT (define Huffman table) marker code.
 
#define JPEG_MARKER_RST0   0XD0
 JPEG RST0 (restart) marker code.
 
#define JPEG_MARKER_SOI   0xD8
 JPEG SOI (start of image) marker code.
 
#define JPEG_MARKER_EOI   0xD9
 JPEG EOI (end of image) marker code.
 
#define JPEG_MARKER_SOS   0xDA
 JPEG SOS (start of scan) marker code.
 
#define JPEG_MARKER_DQT   0xDB
 JPEG DQT (define quantization table) marker code.
 
#define JPEG_MARKER_DRI   0xDD
 JPEG DRI (define restart interval) marker code.
 
#define JPEG_MARKER_APP0   0xE0
 JPEG APP0 marker code; APP0..APP15 are this value plus 0..15.
 
#define JPEG_MARKER_COM   0xFE
 JPEG COM (comment) marker code.
 
#define FIELD_OJPEG_JPEGINTERCHANGEFORMAT   (FIELD_CODEC + 0)
 TIFFField field bit for the codec-private JpegInterchangeFormat tag.
 
#define FIELD_OJPEG_JPEGINTERCHANGEFORMATLENGTH   (FIELD_CODEC + 1)
 TIFFField field bit for the codec-private JpegInterchangeFormatLength tag.
 
#define FIELD_OJPEG_JPEGQTABLES   (FIELD_CODEC + 2)
 TIFFField field bit for the codec-private JpegQTables tag.
 
#define FIELD_OJPEG_JPEGDCTABLES   (FIELD_CODEC + 3)
 TIFFField field bit for the codec-private JpegDcTables tag.
 
#define FIELD_OJPEG_JPEGACTABLES   (FIELD_CODEC + 4)
 TIFFField field bit for the codec-private JpegAcTables tag.
 
#define FIELD_OJPEG_JPEGPROC   (FIELD_CODEC + 5)
 TIFFField field bit for the codec-private JpegProc tag.
 
#define FIELD_OJPEG_JPEGRESTARTINTERVAL   (FIELD_CODEC + 6)
 TIFFField field bit for the codec-private JpegRestartInterval tag.
 

Typedefs

typedef struct jpeg_source_mgr tiff_ojpeg_source_mgr
 Alias for the libjpeg source-manager structure.
 
typedef struct jpeg_error_mgr tiff_ojpeg_error_mgr
 Alias for the libjpeg error-manager structure.
 
typedef struct jpeg_common_struct tiff_ojpeg_common_struct
 Alias for the libjpeg common context structure.
 
typedef struct jpeg_decompress_struct tiff_ojpeg_decompress_struct
 Alias for the libjpeg decompressor context structure.
 

Enumerations

enum  OJPEGStateInBufferSource { osibsNotSetYet , osibsJpegInterchangeFormat , osibsStrile , osibsEof }
 Source of the bytes currently read into the input buffer. More...
 
enum  OJPEGStateOutState {
  ososSoi , ososQTable0 , ososQTable1 , ososQTable2 ,
  ososQTable3 , ososDcTable0 , ososDcTable1 , ososDcTable2 ,
  ososDcTable3 , ososAcTable0 , ososAcTable1 , ososAcTable2 ,
  ososAcTable3 , ososDri , ososSof , ososSos ,
  ososCompressed , ososRst , ososEoi
}
 Next item to emit in the reconstructed JPEG stream. More...
 

Functions

static int OJPEGVGetField (TIFF *tif, uint32_t tag, va_list ap)
 Retrieve old-style JPEG metadata or delegate to the parent getter.
 
static int OJPEGVSetField (TIFF *tif, uint32_t tag, va_list ap)
 Cache old-style JPEG tag values or delegate to the parent setter.
 
static void OJPEGPrintDir (TIFF *tif, FILE *fd, long flags)
 Print cached old-style JPEG fields before the optional parent printer.
 
static int OJPEGFixupTags (TIFF *tif)
 Accept the old-style JPEG directory without eager fixups.
 
static int OJPEGSetupDecode (TIFF *tif)
 Warn that old-style JPEG compression is deprecated.
 
static int OJPEGPreDecode (TIFF *tif, uint16_t s)
 Position a reconstructed JPEG session at the requested strile and plane.
 
static int OJPEGPreDecodeSkipRaw (TIFF *tif)
 Decode and discard one strile in raw mode.
 
static int OJPEGPreDecodeSkipScanlines (TIFF *tif)
 Decode and discard one strile in scanlines mode.
 
static int OJPEGDecode (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Decode complete output rows from the active old-style JPEG session.
 
static int OJPEGDecodeRaw (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Decode complete subsampled clump rows.
 
static int OJPEGDecodeScanlines (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Decode complete ordinary sample rows.
 
static void OJPEGPostDecode (TIFF *tif, uint8_t *buf, tmsize_t cc)
 Advance the cached strile count and end a completed plane session.
 
static int OJPEGSetupEncode (TIFF *tif)
 Reject unsupported old-style JPEG encoding.
 
static int OJPEGPreEncode (TIFF *tif, uint16_t s)
 Reject unsupported old-style JPEG encoding.
 
static int OJPEGEncode (TIFF *tif, uint8_t *buf, tmsize_t cc, uint16_t s)
 Reject unsupported old-style JPEG encoding.
 
static int OJPEGPostEncode (TIFF *tif)
 Reject unsupported old-style JPEG encoding.
 
static void OJPEGCleanup (TIFF *tif)
 Release old-style JPEG state and restore parent methods.
 
static void OJPEGSubsamplingCorrect (TIFF *tif)
 Probe and reconcile old-style JPEG subsampling once.
 
static int OJPEGReadHeaderInfo (TIFF *tif)
 Validate geometry and cache the first old-style JPEG scan position.
 
static int OJPEGReadSecondarySos (TIFF *tif, uint16_t s)
 Locate and cache a later separate-plane scan header.
 
static int OJPEGWriteHeaderInfo (TIFF *tif)
 Start libjpeg with a synthesized old-style JPEG input header.
 
static void OJPEGLibjpegSessionAbort (TIFF *tif)
 Destroy the active old-style JPEG dependency session.
 
static int OJPEGReadHeaderInfoSec (TIFF *tif)
 Parse a bounded interchange/strile JPEG header or synthesize it from tags.
 
static int OJPEGReadHeaderInfoSecStreamDri (TIFF *tif)
 Parse and cache a JPEG restart interval.
 
static int OJPEGReadHeaderInfoSecStreamDqt (TIFF *tif)
 Capture eight-bit JPEG quantisation table markers.
 
static int OJPEGReadHeaderInfoSecStreamDht (TIFF *tif)
 Capture a JPEG Huffman marker in its selected table slot.
 
static int OJPEGReadHeaderInfoSecStreamSof (TIFF *tif, uint8_t marker_id)
 Validate a JPEG frame and cache its component selectors.
 
static int OJPEGReadHeaderInfoSecStreamSos (TIFF *tif)
 Validate and cache a JPEG scan component header.
 
static int OJPEGReadHeaderInfoSecTablesQTable (TIFF *tif)
 Build quantisation markers from TIFF table-offset tags.
 
static int OJPEGReadHeaderInfoSecTablesDcTable (TIFF *tif)
 Build DC Huffman markers from TIFF table-offset tags.
 
static int OJPEGReadHeaderInfoSecTablesAcTable (TIFF *tif)
 Build AC Huffman markers from TIFF table-offset tags.
 
static int OJPEGReadBufferFill (OJPEGState *sp)
 Refill the old-style JPEG input window across interchange and strile extents.
 
static int OJPEGReadByte (OJPEGState *sp, uint8_t *byte)
 Consume one buffered byte.
 
static int OJPEGReadBytePeek (OJPEGState *sp, uint8_t *byte)
 Peek at the next buffered byte.
 
static void OJPEGReadByteAdvance (OJPEGState *sp)
 Consume one already buffered byte.
 
static int OJPEGReadWord (OJPEGState *sp, uint16_t *word)
 Consume a big-endian sixteen-bit word.
 
static int OJPEGReadBlock (OJPEGState *sp, uint16_t len, void *mem)
 Copy a positive byte block from the input stream.
 
static void OJPEGReadSkip (OJPEGState *sp, uint16_t len)
 Skip up to a bounded input extent without fetching skipped bytes.
 
static int OJPEGWriteStream (TIFF *tif, void **mem, uint32_t *len)
 Produce the next borrowed chunk of reconstructed decoder input.
 
static void OJPEGWriteStreamSoi (TIFF *tif, void **mem, uint32_t *len)
 Produce a Soi reconstruction chunk.
 
static void OJPEGWriteStreamQTable (TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
 Produce a QTable reconstruction chunk.
 
static void OJPEGWriteStreamDcTable (TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
 Produce a DcTable reconstruction chunk.
 
static void OJPEGWriteStreamAcTable (TIFF *tif, uint8_t table_index, void **mem, uint32_t *len)
 Produce a AcTable reconstruction chunk.
 
static void OJPEGWriteStreamDri (TIFF *tif, void **mem, uint32_t *len)
 Produce a Dri reconstruction chunk.
 
static void OJPEGWriteStreamSof (TIFF *tif, void **mem, uint32_t *len)
 Produce a Sof reconstruction chunk.
 
static void OJPEGWriteStreamSos (TIFF *tif, void **mem, uint32_t *len)
 Produce a Sos reconstruction chunk.
 
static int OJPEGWriteStreamCompressed (TIFF *tif, void **mem, uint32_t *len)
 Produce a Compressed reconstruction chunk.
 
static void OJPEGWriteStreamRst (TIFF *tif, void **mem, uint32_t *len)
 Produce a Rst reconstruction chunk.
 
static void OJPEGWriteStreamEoi (TIFF *tif, void **mem, uint32_t *len)
 Produce a Eoi reconstruction chunk.
 
static int jpeg_create_decompress_encap (OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo)
 Trap dependency fatal errors while attempting to create a decompressor.
 
static int jpeg_read_header_encap (OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, uint8_t require_image)
 Trap dependency fatal errors while attempting to read a JPEG header.
 
static int jpeg_start_decompress_encap (OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo)
 Trap dependency fatal errors while attempting to start decompression.
 
static int jpeg_read_scanlines_encap (OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, void *scanlines, uint32_t max_lines)
 Trap dependency fatal errors while attempting to read scanlines.
 
static int jpeg_read_raw_data_encap (OJPEGState *sp, tiff_ojpeg_decompress_struct *cinfo, void *data, uint32_t max_lines)
 Trap dependency fatal errors while attempting to read component planes.
 
static void jpeg_encap_unwind (TIFF *tif)
 Jump to the active old-style JPEG dependency wrapper.
 
static void OJPEGLibjpegJpegErrorMgrOutputMessage (tiff_ojpeg_common_struct *cinfo)
 Route a dependency message through the handle warning handler.
 
static void OJPEGLibjpegJpegErrorMgrErrorExit (tiff_ojpeg_common_struct *cinfo)
 Report a fatal dependency error and unwind the active wrapper.
 
static void OJPEGLibjpegJpegSourceMgrInitSource (tiff_ojpeg_decompress_struct *cinfo)
 Accept the dependency source initialization.
 
static boolean OJPEGLibjpegJpegSourceMgrFillInputBuffer (tiff_ojpeg_decompress_struct *cinfo)
 Supply the next reconstructed JPEG chunk to libjpeg.
 
static void OJPEGLibjpegJpegSourceMgrSkipInputData (tiff_ojpeg_decompress_struct *cinfo, long num_bytes)
 Reject an unexpected dependency skip request.
 
static boolean OJPEGLibjpegJpegSourceMgrResyncToRestart (tiff_ojpeg_decompress_struct *cinfo, int desired)
 Reject an unexpected dependency restart resynchronization request.
 
static void OJPEGLibjpegJpegSourceMgrTermSource (tiff_ojpeg_decompress_struct *cinfo)
 Accept the dependency source termination.
 
int TIFFInitOJPEG (TIFF *tif, int scheme)
 Install the decode-only old-style JPEG codec.
 

Variables

static const TIFFField ojpegFields []
 Describe legacy JPEG tags merged into the handle.
 

Detailed Description

Decode legacy TIFF JPEG by reconstructing a dependency input stream.

Definition in file tif_ojpeg.c.