0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * jcmarker.c
0N/A *
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 *
0N/A * This file contains routines to write JPEG datastream markers.
0N/A */
0N/A
0N/A#define JPEG_INTERNALS
0N/A#include "jinclude.h"
0N/A#include "jpeglib.h"
0N/A
0N/A
0N/Atypedef enum { /* JPEG marker codes */
0N/A M_SOF0 = 0xc0,
0N/A M_SOF1 = 0xc1,
0N/A M_SOF2 = 0xc2,
0N/A M_SOF3 = 0xc3,
0N/A
0N/A M_SOF5 = 0xc5,
0N/A M_SOF6 = 0xc6,
0N/A M_SOF7 = 0xc7,
0N/A
0N/A M_JPG = 0xc8,
0N/A M_SOF9 = 0xc9,
0N/A M_SOF10 = 0xca,
0N/A M_SOF11 = 0xcb,
0N/A
0N/A M_SOF13 = 0xcd,
0N/A M_SOF14 = 0xce,
0N/A M_SOF15 = 0xcf,
0N/A
0N/A M_DHT = 0xc4,
0N/A
0N/A M_DAC = 0xcc,
0N/A
0N/A M_RST0 = 0xd0,
0N/A M_RST1 = 0xd1,
0N/A M_RST2 = 0xd2,
0N/A M_RST3 = 0xd3,
0N/A M_RST4 = 0xd4,
0N/A M_RST5 = 0xd5,
0N/A M_RST6 = 0xd6,
0N/A M_RST7 = 0xd7,
0N/A
0N/A M_SOI = 0xd8,
0N/A M_EOI = 0xd9,
0N/A M_SOS = 0xda,
0N/A M_DQT = 0xdb,
0N/A M_DNL = 0xdc,
0N/A M_DRI = 0xdd,
0N/A M_DHP = 0xde,
0N/A M_EXP = 0xdf,
0N/A
0N/A M_APP0 = 0xe0,
0N/A M_APP1 = 0xe1,
0N/A M_APP2 = 0xe2,
0N/A M_APP3 = 0xe3,
0N/A M_APP4 = 0xe4,
0N/A M_APP5 = 0xe5,
0N/A M_APP6 = 0xe6,
0N/A M_APP7 = 0xe7,
0N/A M_APP8 = 0xe8,
0N/A M_APP9 = 0xe9,
0N/A M_APP10 = 0xea,
0N/A M_APP11 = 0xeb,
0N/A M_APP12 = 0xec,
0N/A M_APP13 = 0xed,
0N/A M_APP14 = 0xee,
0N/A M_APP15 = 0xef,
0N/A
0N/A M_JPG0 = 0xf0,
0N/A M_JPG13 = 0xfd,
0N/A M_COM = 0xfe,
0N/A
0N/A M_TEM = 0x01,
0N/A
0N/A M_ERROR = 0x100
0N/A} JPEG_MARKER;
0N/A
0N/A
0N/A/* Private state */
0N/A
0N/Atypedef struct {
0N/A struct jpeg_marker_writer pub; /* public fields */
0N/A
0N/A unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
0N/A} my_marker_writer;
0N/A
0N/Atypedef my_marker_writer * my_marker_ptr;
0N/A
0N/A
0N/A/*
0N/A * Basic output routines.
0N/A *
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 */
0N/A
0N/ALOCAL(void)
0N/Aemit_byte (j_compress_ptr cinfo, int val)
0N/A/* Emit a byte */
0N/A{
0N/A struct jpeg_destination_mgr * dest = cinfo->dest;
0N/A
0N/A *(dest->next_output_byte)++ = (JOCTET) val;
0N/A if (--dest->free_in_buffer == 0) {
0N/A if (! (*dest->empty_output_buffer) (cinfo))
0N/A ERREXIT(cinfo, JERR_CANT_SUSPEND);
0N/A }
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
0N/A/* Emit a marker code */
0N/A{
0N/A emit_byte(cinfo, 0xFF);
0N/A emit_byte(cinfo, (int) mark);
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_2bytes (j_compress_ptr cinfo, int value)
0N/A/* Emit a 2-byte integer; these are always MSB first in JPEG files */
0N/A{
0N/A emit_byte(cinfo, (value >> 8) & 0xFF);
0N/A emit_byte(cinfo, value & 0xFF);
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Routines to write specific marker types.
0N/A */
0N/A
0N/ALOCAL(int)
0N/Aemit_dqt (j_compress_ptr cinfo, int index)
0N/A/* Emit a DQT marker */
0N/A/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
0N/A{
0N/A JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
0N/A int prec;
0N/A int i;
0N/A
0N/A if (qtbl == NULL)
0N/A ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
0N/A
0N/A prec = 0;
0N/A for (i = 0; i < DCTSIZE2; i++) {
0N/A if (qtbl->quantval[i] > 255)
0N/A prec = 1;
0N/A }
0N/A
0N/A if (! qtbl->sent_table) {
0N/A emit_marker(cinfo, M_DQT);
0N/A
0N/A emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
0N/A
0N/A emit_byte(cinfo, index + (prec<<4));
0N/A
0N/A for (i = 0; i < DCTSIZE2; i++) {
0N/A /* The table entries must be emitted in zigzag order. */
0N/A unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
0N/A if (prec)
0N/A emit_byte(cinfo, (int) (qval >> 8));
0N/A emit_byte(cinfo, (int) (qval & 0xFF));
0N/A }
0N/A
0N/A qtbl->sent_table = TRUE;
0N/A }
0N/A
0N/A return prec;
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
0N/A/* Emit a DHT marker */
0N/A{
0N/A JHUFF_TBL * htbl;
0N/A int length, i;
0N/A
0N/A if (is_ac) {
0N/A htbl = cinfo->ac_huff_tbl_ptrs[index];
0N/A index += 0x10; /* output index has AC bit set */
0N/A } else {
0N/A htbl = cinfo->dc_huff_tbl_ptrs[index];
0N/A }
0N/A
0N/A if (htbl == NULL)
0N/A ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
0N/A
0N/A if (! htbl->sent_table) {
0N/A emit_marker(cinfo, M_DHT);
0N/A
0N/A length = 0;
0N/A for (i = 1; i <= 16; i++)
0N/A length += htbl->bits[i];
0N/A
0N/A emit_2bytes(cinfo, length + 2 + 1 + 16);
0N/A emit_byte(cinfo, index);
0N/A
0N/A for (i = 1; i <= 16; i++)
0N/A emit_byte(cinfo, htbl->bits[i]);
0N/A
0N/A for (i = 0; i < length; i++)
0N/A emit_byte(cinfo, htbl->huffval[i]);
0N/A
0N/A htbl->sent_table = TRUE;
0N/A }
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_dac (j_compress_ptr cinfo)
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{
0N/A#ifdef C_ARITH_CODING_SUPPORTED
0N/A char dc_in_use[NUM_ARITH_TBLS];
0N/A char ac_in_use[NUM_ARITH_TBLS];
0N/A int length, i;
0N/A jpeg_component_info *compptr;
0N/A
0N/A for (i = 0; i < NUM_ARITH_TBLS; i++)
0N/A dc_in_use[i] = ac_in_use[i] = 0;
0N/A
0N/A for (i = 0; i < cinfo->comps_in_scan; i++) {
0N/A compptr = cinfo->cur_comp_info[i];
0N/A dc_in_use[compptr->dc_tbl_no] = 1;
0N/A ac_in_use[compptr->ac_tbl_no] = 1;
0N/A }
0N/A
0N/A length = 0;
0N/A for (i = 0; i < NUM_ARITH_TBLS; i++)
0N/A length += dc_in_use[i] + ac_in_use[i];
0N/A
0N/A emit_marker(cinfo, M_DAC);
0N/A
0N/A emit_2bytes(cinfo, length*2 + 2);
0N/A
0N/A for (i = 0; i < NUM_ARITH_TBLS; i++) {
0N/A if (dc_in_use[i]) {
0N/A emit_byte(cinfo, i);
0N/A emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
0N/A }
0N/A if (ac_in_use[i]) {
0N/A emit_byte(cinfo, i + 0x10);
0N/A emit_byte(cinfo, cinfo->arith_ac_K[i]);
0N/A }
0N/A }
0N/A#endif /* C_ARITH_CODING_SUPPORTED */
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_dri (j_compress_ptr cinfo)
0N/A/* Emit a DRI marker */
0N/A{
0N/A emit_marker(cinfo, M_DRI);
0N/A
0N/A emit_2bytes(cinfo, 4); /* fixed length */
0N/A
0N/A emit_2bytes(cinfo, (int) cinfo->restart_interval);
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
0N/A/* Emit a SOF marker */
0N/A{
0N/A int ci;
0N/A jpeg_component_info *compptr;
0N/A
0N/A emit_marker(cinfo, code);
0N/A
0N/A emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
0N/A
0N/A /* Make sure image isn't bigger than SOF field can handle */
0N/A if ((long) cinfo->image_height > 65535L ||
0N/A (long) cinfo->image_width > 65535L)
0N/A ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
0N/A
0N/A emit_byte(cinfo, cinfo->data_precision);
0N/A emit_2bytes(cinfo, (int) cinfo->image_height);
0N/A emit_2bytes(cinfo, (int) cinfo->image_width);
0N/A
0N/A emit_byte(cinfo, cinfo->num_components);
0N/A
0N/A for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
0N/A ci++, compptr++) {
0N/A emit_byte(cinfo, compptr->component_id);
0N/A emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
0N/A emit_byte(cinfo, compptr->quant_tbl_no);
0N/A }
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_sos (j_compress_ptr cinfo)
0N/A/* Emit a SOS marker */
0N/A{
0N/A int i, td, ta;
0N/A jpeg_component_info *compptr;
0N/A
0N/A emit_marker(cinfo, M_SOS);
0N/A
0N/A emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
0N/A
0N/A emit_byte(cinfo, cinfo->comps_in_scan);
0N/A
0N/A for (i = 0; i < cinfo->comps_in_scan; i++) {
0N/A compptr = cinfo->cur_comp_info[i];
0N/A emit_byte(cinfo, compptr->component_id);
0N/A td = compptr->dc_tbl_no;
0N/A ta = compptr->ac_tbl_no;
0N/A if (cinfo->progressive_mode) {
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 */
0N/A if (cinfo->Ss == 0) {
0N/A ta = 0; /* DC scan */
0N/A if (cinfo->Ah != 0 && !cinfo->arith_code)
0N/A td = 0; /* no DC table either */
0N/A } else {
0N/A td = 0; /* AC scan */
0N/A }
0N/A }
0N/A emit_byte(cinfo, (td << 4) + ta);
0N/A }
0N/A
0N/A emit_byte(cinfo, cinfo->Ss);
0N/A emit_byte(cinfo, cinfo->Se);
0N/A emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_jfif_app0 (j_compress_ptr cinfo)
0N/A/* Emit a JFIF-compliant APP0 marker */
0N/A{
0N/A /*
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 */
0N/A
0N/A emit_marker(cinfo, M_APP0);
0N/A
0N/A emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
0N/A
0N/A emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
0N/A emit_byte(cinfo, 0x46);
0N/A emit_byte(cinfo, 0x49);
0N/A emit_byte(cinfo, 0x46);
0N/A emit_byte(cinfo, 0);
0N/A emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
0N/A emit_byte(cinfo, cinfo->JFIF_minor_version);
0N/A emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
0N/A emit_2bytes(cinfo, (int) cinfo->X_density);
0N/A emit_2bytes(cinfo, (int) cinfo->Y_density);
0N/A emit_byte(cinfo, 0); /* No thumbnail image */
0N/A emit_byte(cinfo, 0);
0N/A}
0N/A
0N/A
0N/ALOCAL(void)
0N/Aemit_adobe_app14 (j_compress_ptr cinfo)
0N/A/* Emit an Adobe APP14 marker */
0N/A{
0N/A /*
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 *
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 *
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 */
0N/A
0N/A emit_marker(cinfo, M_APP14);
0N/A
0N/A emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
0N/A
0N/A emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
0N/A emit_byte(cinfo, 0x64);
0N/A emit_byte(cinfo, 0x6F);
0N/A emit_byte(cinfo, 0x62);
0N/A emit_byte(cinfo, 0x65);
0N/A emit_2bytes(cinfo, 100); /* Version */
0N/A emit_2bytes(cinfo, 0); /* Flags0 */
0N/A emit_2bytes(cinfo, 0); /* Flags1 */
0N/A switch (cinfo->jpeg_color_space) {
0N/A case JCS_YCbCr:
0N/A emit_byte(cinfo, 1); /* Color transform = 1 */
0N/A break;
0N/A case JCS_YCCK:
0N/A emit_byte(cinfo, 2); /* Color transform = 2 */
0N/A break;
0N/A default:
0N/A emit_byte(cinfo, 0); /* Color transform = 0 */
0N/A break;
0N/A }
0N/A}
0N/A
0N/A
0N/A/*
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 */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
0N/A/* Emit an arbitrary marker header */
0N/A{
0N/A if (datalen > (unsigned int) 65533) /* safety check */
0N/A ERREXIT(cinfo, JERR_BAD_LENGTH);
0N/A
0N/A emit_marker(cinfo, (JPEG_MARKER) marker);
0N/A
0N/A emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
0N/A}
0N/A
0N/AMETHODDEF(void)
0N/Awrite_marker_byte (j_compress_ptr cinfo, int val)
0N/A/* Emit one byte of marker parameters following write_marker_header */
0N/A{
0N/A emit_byte(cinfo, val);
0N/A}
0N/A
0N/A
0N/A/*
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 */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_file_header (j_compress_ptr cinfo)
0N/A{
0N/A my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
0N/A
0N/A emit_marker(cinfo, M_SOI); /* first the SOI */
0N/A
0N/A /* SOI is defined to reset restart interval to 0 */
0N/A marker->last_restart_interval = 0;
0N/A
0N/A if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
0N/A emit_jfif_app0(cinfo);
0N/A if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
0N/A emit_adobe_app14(cinfo);
0N/A}
0N/A
0N/A
0N/A/*
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 */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_frame_header (j_compress_ptr cinfo)
0N/A{
0N/A int ci, prec;
0N/A boolean is_baseline;
0N/A jpeg_component_info *compptr;
0N/A
0N/A /* Emit DQT for each quantization table.
0N/A * Note that emit_dqt() suppresses any duplicate tables.
0N/A */
0N/A prec = 0;
0N/A for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
0N/A ci++, compptr++) {
0N/A prec += emit_dqt(cinfo, compptr->quant_tbl_no);
0N/A }
0N/A /* now prec is nonzero iff there are any 16-bit quant tables. */
0N/A
0N/A /* Check for a non-baseline specification.
0N/A * Note we assume that Huffman table numbers won't be changed later.
0N/A */
0N/A if (cinfo->arith_code || cinfo->progressive_mode ||
0N/A cinfo->data_precision != 8) {
0N/A is_baseline = FALSE;
0N/A } else {
0N/A is_baseline = TRUE;
0N/A for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
0N/A ci++, compptr++) {
0N/A if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
0N/A is_baseline = FALSE;
0N/A }
0N/A if (prec && is_baseline) {
0N/A is_baseline = FALSE;
0N/A /* If it's baseline except for quantizer size, warn the user */
0N/A TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
0N/A }
0N/A }
0N/A
0N/A /* Emit the proper SOF marker */
0N/A if (cinfo->arith_code) {
0N/A emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
0N/A } else {
0N/A if (cinfo->progressive_mode)
0N/A emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
0N/A else if (is_baseline)
0N/A emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
0N/A else
0N/A emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
0N/A }
0N/A}
0N/A
0N/A
0N/A/*
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 */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_scan_header (j_compress_ptr cinfo)
0N/A{
0N/A my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
0N/A int i;
0N/A jpeg_component_info *compptr;
0N/A
0N/A if (cinfo->arith_code) {
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 */
0N/A emit_dac(cinfo);
0N/A } else {
0N/A /* Emit Huffman tables.
0N/A * Note that emit_dht() suppresses any duplicate tables.
0N/A */
0N/A for (i = 0; i < cinfo->comps_in_scan; i++) {
0N/A compptr = cinfo->cur_comp_info[i];
0N/A if (cinfo->progressive_mode) {
0N/A /* Progressive mode: only DC or only AC tables are used in one scan */
0N/A if (cinfo->Ss == 0) {
0N/A if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
0N/A emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
0N/A } else {
0N/A emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
0N/A }
0N/A } else {
0N/A /* Sequential mode: need both DC and AC tables */
0N/A emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
0N/A emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
0N/A }
0N/A }
0N/A }
0N/A
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 */
0N/A if (cinfo->restart_interval != marker->last_restart_interval) {
0N/A emit_dri(cinfo);
0N/A marker->last_restart_interval = cinfo->restart_interval;
0N/A }
0N/A
0N/A emit_sos(cinfo);
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Write datastream trailer.
0N/A */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_file_trailer (j_compress_ptr cinfo)
0N/A{
0N/A emit_marker(cinfo, M_EOI);
0N/A}
0N/A
0N/A
0N/A/*
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 */
0N/A
0N/AMETHODDEF(void)
0N/Awrite_tables_only (j_compress_ptr cinfo)
0N/A{
0N/A int i;
0N/A
0N/A emit_marker(cinfo, M_SOI);
0N/A
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 */
0N/A if (cinfo->num_components > 0) {
0N/A int ci;
0N/A jpeg_component_info *compptr;
0N/A for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
0N/A ci++, compptr++) {
0N/A (void) emit_dqt(cinfo, compptr->quant_tbl_no);
0N/A }
0N/A } else {
0N/A for (i = 0; i < NUM_QUANT_TBLS; i++) {
0N/A if (cinfo->quant_tbl_ptrs[i] != NULL)
0N/A (void) emit_dqt(cinfo, i);
0N/A }
0N/A }
0N/A
0N/A if (! cinfo->arith_code) {
0N/A for (i = 0; i < NUM_HUFF_TBLS; i++) {
0N/A if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
0N/A emit_dht(cinfo, i, FALSE);
0N/A if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
0N/A emit_dht(cinfo, i, TRUE);
0N/A }
0N/A }
0N/A
0N/A emit_marker(cinfo, M_EOI);
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Initialize the marker writer module.
0N/A */
0N/A
0N/AGLOBAL(void)
0N/Ajinit_marker_writer (j_compress_ptr cinfo)
0N/A{
0N/A my_marker_ptr marker;
0N/A
0N/A /* Create the subobject */
0N/A marker = (my_marker_ptr)
0N/A (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
0N/A SIZEOF(my_marker_writer));
0N/A cinfo->marker = (struct jpeg_marker_writer *) marker;
0N/A /* Initialize method pointers */
0N/A marker->pub.write_file_header = write_file_header;
0N/A marker->pub.write_frame_header = write_frame_header;
0N/A marker->pub.write_scan_header = write_scan_header;
0N/A marker->pub.write_file_trailer = write_file_trailer;
0N/A marker->pub.write_tables_only = write_tables_only;
0N/A marker->pub.write_marker_header = write_marker_header;
0N/A marker->pub.write_marker_byte = write_marker_byte;
0N/A /* Initialize private state */
0N/A marker->last_restart_interval = 0;
0N/A}