0N/A * reserved comment block 0N/A * DO NOT REMOVE OR ALTER! 0N/A * Copyright (C) 1991-1998, Thomas G. Lane. 0N/A * This file is part of the Independent JPEG Group's software. 0N/A * For conditions of distribution and use, see the accompanying README file. 0N/A * This file contains routines to write JPEG datastream markers. 0N/Atypedef enum {
/* JPEG marker codes */ 0N/A * Basic output routines. 0N/A * Note that we do not support suspension while writing a marker. 0N/A * Therefore, an application using suspension must ensure that there is 0N/A * enough buffer space for the initial markers (typ. 600-700 bytes) before 0N/A * calling jpeg_start_compress, and enough space to write the trailing EOI 0N/A * (a few bytes) before calling jpeg_finish_compress. Multipass compression 0N/A * modes are not supported at all with suspension, so those two are the only 0N/A * points where markers will be written. 0N/A/* Emit a marker code */ 0N/A/* Emit a 2-byte integer; these are always MSB first in JPEG files */ 0N/A * Routines to write specific marker types. 0N/A/* Emit a DQT marker */ 0N/A/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */ 0N/A /* The table entries must be emitted in zigzag order. */ 0N/A/* Emit a DHT marker */ 0N/A index +=
0x10;
/* output index has AC bit set */ 0N/A for (i =
1; i <=
16; i++)
0N/A for (i =
1; i <=
16; i++)
0N/A/* Emit a DAC marker */ 0N/A/* Since the useful info is so small, we want to emit all the tables in */ 0N/A/* one DAC marker. Therefore this routine does its own scan of the table. */ 0N/A#
endif /* C_ARITH_CODING_SUPPORTED */ 0N/A/* Emit a DRI marker */ 0N/A/* Emit a SOF marker */ 0N/A /* Make sure image isn't bigger than SOF field can handle */ 0N/A/* Emit a SOS marker */ 0N/A /* Progressive mode: only DC or only AC tables are used in one scan; 0N/A * furthermore, Huffman coding of DC refinement uses no table at all. 0N/A * We emit 0 for unused field(s); this is recommended by the P&M text 0N/A * but does not seem to be specified in the standard. 0N/A td = 0;
/* no DC table either */ 0N/A/* Emit a JFIF-compliant APP0 marker */ 0N/A * Length of APP0 block (2 bytes) 0N/A * Block ID (4 bytes - ASCII "JFIF") 0N/A * Zero byte (1 byte to terminate the ID string) 0N/A * Version Major, Minor (2 bytes - major first) 0N/A * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) 0N/A * Xdpu (2 bytes - dots per unit horizontal) 0N/A * Ydpu (2 bytes - dots per unit vertical) 0N/A * Thumbnail X size (1 byte) 0N/A * Thumbnail Y size (1 byte) 0N/A/* Emit an Adobe APP14 marker */ 0N/A * Length of APP14 block (2 bytes) 0N/A * Block ID (5 bytes - ASCII "Adobe") 0N/A * Version Number (2 bytes - currently 100) 0N/A * Flags0 (2 bytes - currently 0) 0N/A * Flags1 (2 bytes - currently 0) 0N/A * Color transform (1 byte) 0N/A * Although Adobe TN 5116 mentions Version = 101, all the Adobe files 0N/A * now in circulation seem to use Version = 100, so that's what we write. 0N/A * We write the color transform byte as 1 if the JPEG color space is 0N/A * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with 0N/A * whether the encoder performed a transformation, which is pretty useless. 0N/A * These routines allow writing an arbitrary marker with parameters. 0N/A * The only intended use is to emit COM or APPn markers after calling 0N/A * write_file_header and before calling write_frame_header. 0N/A * Other uses are not guaranteed to produce desirable results. 0N/A * Counting the parameter bytes properly is the caller's responsibility. 0N/A/* Emit an arbitrary marker header */ 0N/A if (
datalen > (
unsigned int)
65533)
/* safety check */ 0N/A/* Emit one byte of marker parameters following write_marker_header */ 0N/A * Write datastream header. 0N/A * This consists of an SOI and optional APPn markers. 0N/A * We recommend use of the JFIF marker, but not the Adobe marker, 0N/A * when using YCbCr or grayscale data. The JFIF marker should NOT 0N/A * be used for any other JPEG colorspace. The Adobe marker is helpful 0N/A * to distinguish RGB, CMYK, and YCCK colorspaces. 0N/A * Note that an application can write additional header markers after 0N/A * jpeg_start_compress returns. 0N/A /* SOI is defined to reset restart interval to 0 */ 0N/A * Write frame header. 0N/A * This consists of DQT and SOFn markers. 0N/A * Note that we do not emit the SOF until we have emitted the DQT(s). 0N/A * This avoids compatibility problems with incorrect implementations that 0N/A * try to error-check the quant table numbers as soon as they see the SOF. 0N/A /* Emit DQT for each quantization table. 0N/A * Note that emit_dqt() suppresses any duplicate tables. 0N/A /* now prec is nonzero iff there are any 16-bit quant tables. */ 0N/A /* Check for a non-baseline specification. 0N/A * Note we assume that Huffman table numbers won't be changed later. 0N/A /* If it's baseline except for quantizer size, warn the user */ 0N/A /* Emit the proper SOF marker */ 0N/A * Write scan header. 0N/A * This consists of DHT or DAC markers, optional DRI, and SOS. 0N/A * Compressed data will be written following the SOS. 0N/A /* Emit arith conditioning info. We may have some duplication 0N/A * if the file has multiple scans, but it's so small it's hardly 0N/A * worth worrying about. 0N/A /* Emit Huffman tables. 0N/A * Note that emit_dht() suppresses any duplicate tables. 0N/A /* Progressive mode: only DC or only AC tables are used in one scan */ 0N/A if (
cinfo->
Ah == 0)
/* DC needs no table for refinement scan */ 0N/A /* Sequential mode: need both DC and AC tables */ 0N/A /* Emit DRI if required --- note that DRI value could change for each scan. 0N/A * We avoid wasting space with unnecessary DRIs, however. 0N/A * Write datastream trailer. 0N/A * Write an abbreviated table-specification datastream. 0N/A * This consists of SOI, DQT and DHT tables, and EOI. 0N/A * Any table that is defined and not marked sent_table = TRUE will be 0N/A * emitted. Note that all tables will be marked sent_table = TRUE at exit. 0N/A /* Emit DQT for each quantization table. 0N/A * Only emit those tables that are actually associated with image components, 0N/A * if there are any image components, which will usually not be the case. 0N/A * Note that emit_dqt() suppresses any duplicate tables. 0N/A * Initialize the marker writer module. 0N/A /* Create the subobject */ 0N/A /* Initialize method pointers */ 0N/A /* Initialize private state */