Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shoaib_ahmed 0:791a779d6220 1 /*
shoaib_ahmed 0:791a779d6220 2 * jcmarker.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1991-1998, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * Modified 2003-2013 by Guido Vollbeding.
shoaib_ahmed 0:791a779d6220 6 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 7 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 8 *
shoaib_ahmed 0:791a779d6220 9 * This file contains routines to write JPEG datastream markers.
shoaib_ahmed 0:791a779d6220 10 */
shoaib_ahmed 0:791a779d6220 11
shoaib_ahmed 0:791a779d6220 12 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 13 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 14 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 15
shoaib_ahmed 0:791a779d6220 16
shoaib_ahmed 0:791a779d6220 17 typedef enum { /* JPEG marker codes */
shoaib_ahmed 0:791a779d6220 18 M_SOF0 = 0xc0,
shoaib_ahmed 0:791a779d6220 19 M_SOF1 = 0xc1,
shoaib_ahmed 0:791a779d6220 20 M_SOF2 = 0xc2,
shoaib_ahmed 0:791a779d6220 21 M_SOF3 = 0xc3,
shoaib_ahmed 0:791a779d6220 22
shoaib_ahmed 0:791a779d6220 23 M_SOF5 = 0xc5,
shoaib_ahmed 0:791a779d6220 24 M_SOF6 = 0xc6,
shoaib_ahmed 0:791a779d6220 25 M_SOF7 = 0xc7,
shoaib_ahmed 0:791a779d6220 26
shoaib_ahmed 0:791a779d6220 27 M_JPG = 0xc8,
shoaib_ahmed 0:791a779d6220 28 M_SOF9 = 0xc9,
shoaib_ahmed 0:791a779d6220 29 M_SOF10 = 0xca,
shoaib_ahmed 0:791a779d6220 30 M_SOF11 = 0xcb,
shoaib_ahmed 0:791a779d6220 31
shoaib_ahmed 0:791a779d6220 32 M_SOF13 = 0xcd,
shoaib_ahmed 0:791a779d6220 33 M_SOF14 = 0xce,
shoaib_ahmed 0:791a779d6220 34 M_SOF15 = 0xcf,
shoaib_ahmed 0:791a779d6220 35
shoaib_ahmed 0:791a779d6220 36 M_DHT = 0xc4,
shoaib_ahmed 0:791a779d6220 37
shoaib_ahmed 0:791a779d6220 38 M_DAC = 0xcc,
shoaib_ahmed 0:791a779d6220 39
shoaib_ahmed 0:791a779d6220 40 M_RST0 = 0xd0,
shoaib_ahmed 0:791a779d6220 41 M_RST1 = 0xd1,
shoaib_ahmed 0:791a779d6220 42 M_RST2 = 0xd2,
shoaib_ahmed 0:791a779d6220 43 M_RST3 = 0xd3,
shoaib_ahmed 0:791a779d6220 44 M_RST4 = 0xd4,
shoaib_ahmed 0:791a779d6220 45 M_RST5 = 0xd5,
shoaib_ahmed 0:791a779d6220 46 M_RST6 = 0xd6,
shoaib_ahmed 0:791a779d6220 47 M_RST7 = 0xd7,
shoaib_ahmed 0:791a779d6220 48
shoaib_ahmed 0:791a779d6220 49 M_SOI = 0xd8,
shoaib_ahmed 0:791a779d6220 50 M_EOI = 0xd9,
shoaib_ahmed 0:791a779d6220 51 M_SOS = 0xda,
shoaib_ahmed 0:791a779d6220 52 M_DQT = 0xdb,
shoaib_ahmed 0:791a779d6220 53 M_DNL = 0xdc,
shoaib_ahmed 0:791a779d6220 54 M_DRI = 0xdd,
shoaib_ahmed 0:791a779d6220 55 M_DHP = 0xde,
shoaib_ahmed 0:791a779d6220 56 M_EXP = 0xdf,
shoaib_ahmed 0:791a779d6220 57
shoaib_ahmed 0:791a779d6220 58 M_APP0 = 0xe0,
shoaib_ahmed 0:791a779d6220 59 M_APP1 = 0xe1,
shoaib_ahmed 0:791a779d6220 60 M_APP2 = 0xe2,
shoaib_ahmed 0:791a779d6220 61 M_APP3 = 0xe3,
shoaib_ahmed 0:791a779d6220 62 M_APP4 = 0xe4,
shoaib_ahmed 0:791a779d6220 63 M_APP5 = 0xe5,
shoaib_ahmed 0:791a779d6220 64 M_APP6 = 0xe6,
shoaib_ahmed 0:791a779d6220 65 M_APP7 = 0xe7,
shoaib_ahmed 0:791a779d6220 66 M_APP8 = 0xe8,
shoaib_ahmed 0:791a779d6220 67 M_APP9 = 0xe9,
shoaib_ahmed 0:791a779d6220 68 M_APP10 = 0xea,
shoaib_ahmed 0:791a779d6220 69 M_APP11 = 0xeb,
shoaib_ahmed 0:791a779d6220 70 M_APP12 = 0xec,
shoaib_ahmed 0:791a779d6220 71 M_APP13 = 0xed,
shoaib_ahmed 0:791a779d6220 72 M_APP14 = 0xee,
shoaib_ahmed 0:791a779d6220 73 M_APP15 = 0xef,
shoaib_ahmed 0:791a779d6220 74
shoaib_ahmed 0:791a779d6220 75 M_JPG0 = 0xf0,
shoaib_ahmed 0:791a779d6220 76 M_JPG8 = 0xf8,
shoaib_ahmed 0:791a779d6220 77 M_JPG13 = 0xfd,
shoaib_ahmed 0:791a779d6220 78 M_COM = 0xfe,
shoaib_ahmed 0:791a779d6220 79
shoaib_ahmed 0:791a779d6220 80 M_TEM = 0x01,
shoaib_ahmed 0:791a779d6220 81
shoaib_ahmed 0:791a779d6220 82 M_ERROR = 0x100
shoaib_ahmed 0:791a779d6220 83 } JPEG_MARKER;
shoaib_ahmed 0:791a779d6220 84
shoaib_ahmed 0:791a779d6220 85
shoaib_ahmed 0:791a779d6220 86 /* Private state */
shoaib_ahmed 0:791a779d6220 87
shoaib_ahmed 0:791a779d6220 88 typedef struct {
shoaib_ahmed 0:791a779d6220 89 struct jpeg_marker_writer pub; /* public fields */
shoaib_ahmed 0:791a779d6220 90
shoaib_ahmed 0:791a779d6220 91 unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
shoaib_ahmed 0:791a779d6220 92 } my_marker_writer;
shoaib_ahmed 0:791a779d6220 93
shoaib_ahmed 0:791a779d6220 94 typedef my_marker_writer * my_marker_ptr;
shoaib_ahmed 0:791a779d6220 95
shoaib_ahmed 0:791a779d6220 96
shoaib_ahmed 0:791a779d6220 97 /*
shoaib_ahmed 0:791a779d6220 98 * Basic output routines.
shoaib_ahmed 0:791a779d6220 99 *
shoaib_ahmed 0:791a779d6220 100 * Note that we do not support suspension while writing a marker.
shoaib_ahmed 0:791a779d6220 101 * Therefore, an application using suspension must ensure that there is
shoaib_ahmed 0:791a779d6220 102 * enough buffer space for the initial markers (typ. 600-700 bytes) before
shoaib_ahmed 0:791a779d6220 103 * calling jpeg_start_compress, and enough space to write the trailing EOI
shoaib_ahmed 0:791a779d6220 104 * (a few bytes) before calling jpeg_finish_compress. Multipass compression
shoaib_ahmed 0:791a779d6220 105 * modes are not supported at all with suspension, so those two are the only
shoaib_ahmed 0:791a779d6220 106 * points where markers will be written.
shoaib_ahmed 0:791a779d6220 107 */
shoaib_ahmed 0:791a779d6220 108
shoaib_ahmed 0:791a779d6220 109 LOCAL(void)
shoaib_ahmed 0:791a779d6220 110 emit_byte (j_compress_ptr cinfo, int val)
shoaib_ahmed 0:791a779d6220 111 /* Emit a byte */
shoaib_ahmed 0:791a779d6220 112 {
shoaib_ahmed 0:791a779d6220 113 struct jpeg_destination_mgr * dest = cinfo->dest;
shoaib_ahmed 0:791a779d6220 114
shoaib_ahmed 0:791a779d6220 115 *(dest->next_output_byte)++ = (JOCTET) val;
shoaib_ahmed 0:791a779d6220 116 if (--dest->free_in_buffer == 0) {
shoaib_ahmed 0:791a779d6220 117 if (! (*dest->empty_output_buffer) (cinfo))
shoaib_ahmed 0:791a779d6220 118 ERREXIT(cinfo, JERR_CANT_SUSPEND);
shoaib_ahmed 0:791a779d6220 119 }
shoaib_ahmed 0:791a779d6220 120 }
shoaib_ahmed 0:791a779d6220 121
shoaib_ahmed 0:791a779d6220 122
shoaib_ahmed 0:791a779d6220 123 LOCAL(void)
shoaib_ahmed 0:791a779d6220 124 emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
shoaib_ahmed 0:791a779d6220 125 /* Emit a marker code */
shoaib_ahmed 0:791a779d6220 126 {
shoaib_ahmed 0:791a779d6220 127 emit_byte(cinfo, 0xFF);
shoaib_ahmed 0:791a779d6220 128 emit_byte(cinfo, (int) mark);
shoaib_ahmed 0:791a779d6220 129 }
shoaib_ahmed 0:791a779d6220 130
shoaib_ahmed 0:791a779d6220 131
shoaib_ahmed 0:791a779d6220 132 LOCAL(void)
shoaib_ahmed 0:791a779d6220 133 emit_2bytes (j_compress_ptr cinfo, int value)
shoaib_ahmed 0:791a779d6220 134 /* Emit a 2-byte integer; these are always MSB first in JPEG files */
shoaib_ahmed 0:791a779d6220 135 {
shoaib_ahmed 0:791a779d6220 136 emit_byte(cinfo, (value >> 8) & 0xFF);
shoaib_ahmed 0:791a779d6220 137 emit_byte(cinfo, value & 0xFF);
shoaib_ahmed 0:791a779d6220 138 }
shoaib_ahmed 0:791a779d6220 139
shoaib_ahmed 0:791a779d6220 140
shoaib_ahmed 0:791a779d6220 141 /*
shoaib_ahmed 0:791a779d6220 142 * Routines to write specific marker types.
shoaib_ahmed 0:791a779d6220 143 */
shoaib_ahmed 0:791a779d6220 144
shoaib_ahmed 0:791a779d6220 145 LOCAL(int)
shoaib_ahmed 0:791a779d6220 146 emit_dqt (j_compress_ptr cinfo, int index)
shoaib_ahmed 0:791a779d6220 147 /* Emit a DQT marker */
shoaib_ahmed 0:791a779d6220 148 /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
shoaib_ahmed 0:791a779d6220 149 {
shoaib_ahmed 0:791a779d6220 150 JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
shoaib_ahmed 0:791a779d6220 151 int prec;
shoaib_ahmed 0:791a779d6220 152 int i;
shoaib_ahmed 0:791a779d6220 153
shoaib_ahmed 0:791a779d6220 154 if (qtbl == NULL)
shoaib_ahmed 0:791a779d6220 155 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
shoaib_ahmed 0:791a779d6220 156
shoaib_ahmed 0:791a779d6220 157 prec = 0;
shoaib_ahmed 0:791a779d6220 158 for (i = 0; i <= cinfo->lim_Se; i++) {
shoaib_ahmed 0:791a779d6220 159 if (qtbl->quantval[cinfo->natural_order[i]] > 255)
shoaib_ahmed 0:791a779d6220 160 prec = 1;
shoaib_ahmed 0:791a779d6220 161 }
shoaib_ahmed 0:791a779d6220 162
shoaib_ahmed 0:791a779d6220 163 if (! qtbl->sent_table) {
shoaib_ahmed 0:791a779d6220 164 emit_marker(cinfo, M_DQT);
shoaib_ahmed 0:791a779d6220 165
shoaib_ahmed 0:791a779d6220 166 emit_2bytes(cinfo,
shoaib_ahmed 0:791a779d6220 167 prec ? cinfo->lim_Se * 2 + 2 + 1 + 2 : cinfo->lim_Se + 1 + 1 + 2);
shoaib_ahmed 0:791a779d6220 168
shoaib_ahmed 0:791a779d6220 169 emit_byte(cinfo, index + (prec<<4));
shoaib_ahmed 0:791a779d6220 170
shoaib_ahmed 0:791a779d6220 171 for (i = 0; i <= cinfo->lim_Se; i++) {
shoaib_ahmed 0:791a779d6220 172 /* The table entries must be emitted in zigzag order. */
shoaib_ahmed 0:791a779d6220 173 unsigned int qval = qtbl->quantval[cinfo->natural_order[i]];
shoaib_ahmed 0:791a779d6220 174 if (prec)
shoaib_ahmed 0:791a779d6220 175 emit_byte(cinfo, (int) (qval >> 8));
shoaib_ahmed 0:791a779d6220 176 emit_byte(cinfo, (int) (qval & 0xFF));
shoaib_ahmed 0:791a779d6220 177 }
shoaib_ahmed 0:791a779d6220 178
shoaib_ahmed 0:791a779d6220 179 qtbl->sent_table = TRUE;
shoaib_ahmed 0:791a779d6220 180 }
shoaib_ahmed 0:791a779d6220 181
shoaib_ahmed 0:791a779d6220 182 return prec;
shoaib_ahmed 0:791a779d6220 183 }
shoaib_ahmed 0:791a779d6220 184
shoaib_ahmed 0:791a779d6220 185
shoaib_ahmed 0:791a779d6220 186 LOCAL(void)
shoaib_ahmed 0:791a779d6220 187 emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
shoaib_ahmed 0:791a779d6220 188 /* Emit a DHT marker */
shoaib_ahmed 0:791a779d6220 189 {
shoaib_ahmed 0:791a779d6220 190 JHUFF_TBL * htbl;
shoaib_ahmed 0:791a779d6220 191 int length, i;
shoaib_ahmed 0:791a779d6220 192
shoaib_ahmed 0:791a779d6220 193 if (is_ac) {
shoaib_ahmed 0:791a779d6220 194 htbl = cinfo->ac_huff_tbl_ptrs[index];
shoaib_ahmed 0:791a779d6220 195 index += 0x10; /* output index has AC bit set */
shoaib_ahmed 0:791a779d6220 196 } else {
shoaib_ahmed 0:791a779d6220 197 htbl = cinfo->dc_huff_tbl_ptrs[index];
shoaib_ahmed 0:791a779d6220 198 }
shoaib_ahmed 0:791a779d6220 199
shoaib_ahmed 0:791a779d6220 200 if (htbl == NULL)
shoaib_ahmed 0:791a779d6220 201 ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
shoaib_ahmed 0:791a779d6220 202
shoaib_ahmed 0:791a779d6220 203 if (! htbl->sent_table) {
shoaib_ahmed 0:791a779d6220 204 emit_marker(cinfo, M_DHT);
shoaib_ahmed 0:791a779d6220 205
shoaib_ahmed 0:791a779d6220 206 length = 0;
shoaib_ahmed 0:791a779d6220 207 for (i = 1; i <= 16; i++)
shoaib_ahmed 0:791a779d6220 208 length += htbl->bits[i];
shoaib_ahmed 0:791a779d6220 209
shoaib_ahmed 0:791a779d6220 210 emit_2bytes(cinfo, length + 2 + 1 + 16);
shoaib_ahmed 0:791a779d6220 211 emit_byte(cinfo, index);
shoaib_ahmed 0:791a779d6220 212
shoaib_ahmed 0:791a779d6220 213 for (i = 1; i <= 16; i++)
shoaib_ahmed 0:791a779d6220 214 emit_byte(cinfo, htbl->bits[i]);
shoaib_ahmed 0:791a779d6220 215
shoaib_ahmed 0:791a779d6220 216 for (i = 0; i < length; i++)
shoaib_ahmed 0:791a779d6220 217 emit_byte(cinfo, htbl->huffval[i]);
shoaib_ahmed 0:791a779d6220 218
shoaib_ahmed 0:791a779d6220 219 htbl->sent_table = TRUE;
shoaib_ahmed 0:791a779d6220 220 }
shoaib_ahmed 0:791a779d6220 221 }
shoaib_ahmed 0:791a779d6220 222
shoaib_ahmed 0:791a779d6220 223
shoaib_ahmed 0:791a779d6220 224 LOCAL(void)
shoaib_ahmed 0:791a779d6220 225 emit_dac (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 226 /* Emit a DAC marker */
shoaib_ahmed 0:791a779d6220 227 /* Since the useful info is so small, we want to emit all the tables in */
shoaib_ahmed 0:791a779d6220 228 /* one DAC marker. Therefore this routine does its own scan of the table. */
shoaib_ahmed 0:791a779d6220 229 {
shoaib_ahmed 0:791a779d6220 230 #ifdef C_ARITH_CODING_SUPPORTED
shoaib_ahmed 0:791a779d6220 231 char dc_in_use[NUM_ARITH_TBLS];
shoaib_ahmed 0:791a779d6220 232 char ac_in_use[NUM_ARITH_TBLS];
shoaib_ahmed 0:791a779d6220 233 int length, i;
shoaib_ahmed 0:791a779d6220 234 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 235
shoaib_ahmed 0:791a779d6220 236 for (i = 0; i < NUM_ARITH_TBLS; i++)
shoaib_ahmed 0:791a779d6220 237 dc_in_use[i] = ac_in_use[i] = 0;
shoaib_ahmed 0:791a779d6220 238
shoaib_ahmed 0:791a779d6220 239 for (i = 0; i < cinfo->comps_in_scan; i++) {
shoaib_ahmed 0:791a779d6220 240 compptr = cinfo->cur_comp_info[i];
shoaib_ahmed 0:791a779d6220 241 /* DC needs no table for refinement scan */
shoaib_ahmed 0:791a779d6220 242 if (cinfo->Ss == 0 && cinfo->Ah == 0)
shoaib_ahmed 0:791a779d6220 243 dc_in_use[compptr->dc_tbl_no] = 1;
shoaib_ahmed 0:791a779d6220 244 /* AC needs no table when not present */
shoaib_ahmed 0:791a779d6220 245 if (cinfo->Se)
shoaib_ahmed 0:791a779d6220 246 ac_in_use[compptr->ac_tbl_no] = 1;
shoaib_ahmed 0:791a779d6220 247 }
shoaib_ahmed 0:791a779d6220 248
shoaib_ahmed 0:791a779d6220 249 length = 0;
shoaib_ahmed 0:791a779d6220 250 for (i = 0; i < NUM_ARITH_TBLS; i++)
shoaib_ahmed 0:791a779d6220 251 length += dc_in_use[i] + ac_in_use[i];
shoaib_ahmed 0:791a779d6220 252
shoaib_ahmed 0:791a779d6220 253 if (length) {
shoaib_ahmed 0:791a779d6220 254 emit_marker(cinfo, M_DAC);
shoaib_ahmed 0:791a779d6220 255
shoaib_ahmed 0:791a779d6220 256 emit_2bytes(cinfo, length*2 + 2);
shoaib_ahmed 0:791a779d6220 257
shoaib_ahmed 0:791a779d6220 258 for (i = 0; i < NUM_ARITH_TBLS; i++) {
shoaib_ahmed 0:791a779d6220 259 if (dc_in_use[i]) {
shoaib_ahmed 0:791a779d6220 260 emit_byte(cinfo, i);
shoaib_ahmed 0:791a779d6220 261 emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
shoaib_ahmed 0:791a779d6220 262 }
shoaib_ahmed 0:791a779d6220 263 if (ac_in_use[i]) {
shoaib_ahmed 0:791a779d6220 264 emit_byte(cinfo, i + 0x10);
shoaib_ahmed 0:791a779d6220 265 emit_byte(cinfo, cinfo->arith_ac_K[i]);
shoaib_ahmed 0:791a779d6220 266 }
shoaib_ahmed 0:791a779d6220 267 }
shoaib_ahmed 0:791a779d6220 268 }
shoaib_ahmed 0:791a779d6220 269 #endif /* C_ARITH_CODING_SUPPORTED */
shoaib_ahmed 0:791a779d6220 270 }
shoaib_ahmed 0:791a779d6220 271
shoaib_ahmed 0:791a779d6220 272
shoaib_ahmed 0:791a779d6220 273 LOCAL(void)
shoaib_ahmed 0:791a779d6220 274 emit_dri (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 275 /* Emit a DRI marker */
shoaib_ahmed 0:791a779d6220 276 {
shoaib_ahmed 0:791a779d6220 277 emit_marker(cinfo, M_DRI);
shoaib_ahmed 0:791a779d6220 278
shoaib_ahmed 0:791a779d6220 279 emit_2bytes(cinfo, 4); /* fixed length */
shoaib_ahmed 0:791a779d6220 280
shoaib_ahmed 0:791a779d6220 281 emit_2bytes(cinfo, (int) cinfo->restart_interval);
shoaib_ahmed 0:791a779d6220 282 }
shoaib_ahmed 0:791a779d6220 283
shoaib_ahmed 0:791a779d6220 284
shoaib_ahmed 0:791a779d6220 285 LOCAL(void)
shoaib_ahmed 0:791a779d6220 286 emit_lse_ict (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 287 /* Emit an LSE inverse color transform specification marker */
shoaib_ahmed 0:791a779d6220 288 {
shoaib_ahmed 0:791a779d6220 289 /* Support only 1 transform */
shoaib_ahmed 0:791a779d6220 290 if (cinfo->color_transform != JCT_SUBTRACT_GREEN ||
shoaib_ahmed 0:791a779d6220 291 cinfo->num_components < 3)
shoaib_ahmed 0:791a779d6220 292 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
shoaib_ahmed 0:791a779d6220 293
shoaib_ahmed 0:791a779d6220 294 emit_marker(cinfo, M_JPG8);
shoaib_ahmed 0:791a779d6220 295
shoaib_ahmed 0:791a779d6220 296 emit_2bytes(cinfo, 24); /* fixed length */
shoaib_ahmed 0:791a779d6220 297
shoaib_ahmed 0:791a779d6220 298 emit_byte(cinfo, 0x0D); /* ID inverse transform specification */
shoaib_ahmed 0:791a779d6220 299 emit_2bytes(cinfo, MAXJSAMPLE); /* MAXTRANS */
shoaib_ahmed 0:791a779d6220 300 emit_byte(cinfo, 3); /* Nt=3 */
shoaib_ahmed 0:791a779d6220 301 emit_byte(cinfo, cinfo->comp_info[1].component_id);
shoaib_ahmed 0:791a779d6220 302 emit_byte(cinfo, cinfo->comp_info[0].component_id);
shoaib_ahmed 0:791a779d6220 303 emit_byte(cinfo, cinfo->comp_info[2].component_id);
shoaib_ahmed 0:791a779d6220 304 emit_byte(cinfo, 0x80); /* F1: CENTER1=1, NORM1=0 */
shoaib_ahmed 0:791a779d6220 305 emit_2bytes(cinfo, 0); /* A(1,1)=0 */
shoaib_ahmed 0:791a779d6220 306 emit_2bytes(cinfo, 0); /* A(1,2)=0 */
shoaib_ahmed 0:791a779d6220 307 emit_byte(cinfo, 0); /* F2: CENTER2=0, NORM2=0 */
shoaib_ahmed 0:791a779d6220 308 emit_2bytes(cinfo, 1); /* A(2,1)=1 */
shoaib_ahmed 0:791a779d6220 309 emit_2bytes(cinfo, 0); /* A(2,2)=0 */
shoaib_ahmed 0:791a779d6220 310 emit_byte(cinfo, 0); /* F3: CENTER3=0, NORM3=0 */
shoaib_ahmed 0:791a779d6220 311 emit_2bytes(cinfo, 1); /* A(3,1)=1 */
shoaib_ahmed 0:791a779d6220 312 emit_2bytes(cinfo, 0); /* A(3,2)=0 */
shoaib_ahmed 0:791a779d6220 313 }
shoaib_ahmed 0:791a779d6220 314
shoaib_ahmed 0:791a779d6220 315
shoaib_ahmed 0:791a779d6220 316 LOCAL(void)
shoaib_ahmed 0:791a779d6220 317 emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
shoaib_ahmed 0:791a779d6220 318 /* Emit a SOF marker */
shoaib_ahmed 0:791a779d6220 319 {
shoaib_ahmed 0:791a779d6220 320 int ci;
shoaib_ahmed 0:791a779d6220 321 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 322
shoaib_ahmed 0:791a779d6220 323 emit_marker(cinfo, code);
shoaib_ahmed 0:791a779d6220 324
shoaib_ahmed 0:791a779d6220 325 emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
shoaib_ahmed 0:791a779d6220 326
shoaib_ahmed 0:791a779d6220 327 /* Make sure image isn't bigger than SOF field can handle */
shoaib_ahmed 0:791a779d6220 328 if ((long) cinfo->jpeg_height > 65535L ||
shoaib_ahmed 0:791a779d6220 329 (long) cinfo->jpeg_width > 65535L)
shoaib_ahmed 0:791a779d6220 330 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
shoaib_ahmed 0:791a779d6220 331
shoaib_ahmed 0:791a779d6220 332 emit_byte(cinfo, cinfo->data_precision);
shoaib_ahmed 0:791a779d6220 333 emit_2bytes(cinfo, (int) cinfo->jpeg_height);
shoaib_ahmed 0:791a779d6220 334 emit_2bytes(cinfo, (int) cinfo->jpeg_width);
shoaib_ahmed 0:791a779d6220 335
shoaib_ahmed 0:791a779d6220 336 emit_byte(cinfo, cinfo->num_components);
shoaib_ahmed 0:791a779d6220 337
shoaib_ahmed 0:791a779d6220 338 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 339 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 340 emit_byte(cinfo, compptr->component_id);
shoaib_ahmed 0:791a779d6220 341 emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
shoaib_ahmed 0:791a779d6220 342 emit_byte(cinfo, compptr->quant_tbl_no);
shoaib_ahmed 0:791a779d6220 343 }
shoaib_ahmed 0:791a779d6220 344 }
shoaib_ahmed 0:791a779d6220 345
shoaib_ahmed 0:791a779d6220 346
shoaib_ahmed 0:791a779d6220 347 LOCAL(void)
shoaib_ahmed 0:791a779d6220 348 emit_sos (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 349 /* Emit a SOS marker */
shoaib_ahmed 0:791a779d6220 350 {
shoaib_ahmed 0:791a779d6220 351 int i, td, ta;
shoaib_ahmed 0:791a779d6220 352 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 353
shoaib_ahmed 0:791a779d6220 354 emit_marker(cinfo, M_SOS);
shoaib_ahmed 0:791a779d6220 355
shoaib_ahmed 0:791a779d6220 356 emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
shoaib_ahmed 0:791a779d6220 357
shoaib_ahmed 0:791a779d6220 358 emit_byte(cinfo, cinfo->comps_in_scan);
shoaib_ahmed 0:791a779d6220 359
shoaib_ahmed 0:791a779d6220 360 for (i = 0; i < cinfo->comps_in_scan; i++) {
shoaib_ahmed 0:791a779d6220 361 compptr = cinfo->cur_comp_info[i];
shoaib_ahmed 0:791a779d6220 362 emit_byte(cinfo, compptr->component_id);
shoaib_ahmed 0:791a779d6220 363
shoaib_ahmed 0:791a779d6220 364 /* We emit 0 for unused field(s); this is recommended by the P&M text
shoaib_ahmed 0:791a779d6220 365 * but does not seem to be specified in the standard.
shoaib_ahmed 0:791a779d6220 366 */
shoaib_ahmed 0:791a779d6220 367
shoaib_ahmed 0:791a779d6220 368 /* DC needs no table for refinement scan */
shoaib_ahmed 0:791a779d6220 369 td = cinfo->Ss == 0 && cinfo->Ah == 0 ? compptr->dc_tbl_no : 0;
shoaib_ahmed 0:791a779d6220 370 /* AC needs no table when not present */
shoaib_ahmed 0:791a779d6220 371 ta = cinfo->Se ? compptr->ac_tbl_no : 0;
shoaib_ahmed 0:791a779d6220 372
shoaib_ahmed 0:791a779d6220 373 emit_byte(cinfo, (td << 4) + ta);
shoaib_ahmed 0:791a779d6220 374 }
shoaib_ahmed 0:791a779d6220 375
shoaib_ahmed 0:791a779d6220 376 emit_byte(cinfo, cinfo->Ss);
shoaib_ahmed 0:791a779d6220 377 emit_byte(cinfo, cinfo->Se);
shoaib_ahmed 0:791a779d6220 378 emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
shoaib_ahmed 0:791a779d6220 379 }
shoaib_ahmed 0:791a779d6220 380
shoaib_ahmed 0:791a779d6220 381
shoaib_ahmed 0:791a779d6220 382 LOCAL(void)
shoaib_ahmed 0:791a779d6220 383 emit_pseudo_sos (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 384 /* Emit a pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 385 {
shoaib_ahmed 0:791a779d6220 386 emit_marker(cinfo, M_SOS);
shoaib_ahmed 0:791a779d6220 387
shoaib_ahmed 0:791a779d6220 388 emit_2bytes(cinfo, 2 + 1 + 3); /* length */
shoaib_ahmed 0:791a779d6220 389
shoaib_ahmed 0:791a779d6220 390 emit_byte(cinfo, 0); /* Ns */
shoaib_ahmed 0:791a779d6220 391
shoaib_ahmed 0:791a779d6220 392 emit_byte(cinfo, 0); /* Ss */
shoaib_ahmed 0:791a779d6220 393 emit_byte(cinfo, cinfo->block_size * cinfo->block_size - 1); /* Se */
shoaib_ahmed 0:791a779d6220 394 emit_byte(cinfo, 0); /* Ah/Al */
shoaib_ahmed 0:791a779d6220 395 }
shoaib_ahmed 0:791a779d6220 396
shoaib_ahmed 0:791a779d6220 397
shoaib_ahmed 0:791a779d6220 398 LOCAL(void)
shoaib_ahmed 0:791a779d6220 399 emit_jfif_app0 (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 400 /* Emit a JFIF-compliant APP0 marker */
shoaib_ahmed 0:791a779d6220 401 {
shoaib_ahmed 0:791a779d6220 402 /*
shoaib_ahmed 0:791a779d6220 403 * Length of APP0 block (2 bytes)
shoaib_ahmed 0:791a779d6220 404 * Block ID (4 bytes - ASCII "JFIF")
shoaib_ahmed 0:791a779d6220 405 * Zero byte (1 byte to terminate the ID string)
shoaib_ahmed 0:791a779d6220 406 * Version Major, Minor (2 bytes - major first)
shoaib_ahmed 0:791a779d6220 407 * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
shoaib_ahmed 0:791a779d6220 408 * Xdpu (2 bytes - dots per unit horizontal)
shoaib_ahmed 0:791a779d6220 409 * Ydpu (2 bytes - dots per unit vertical)
shoaib_ahmed 0:791a779d6220 410 * Thumbnail X size (1 byte)
shoaib_ahmed 0:791a779d6220 411 * Thumbnail Y size (1 byte)
shoaib_ahmed 0:791a779d6220 412 */
shoaib_ahmed 0:791a779d6220 413
shoaib_ahmed 0:791a779d6220 414 emit_marker(cinfo, M_APP0);
shoaib_ahmed 0:791a779d6220 415
shoaib_ahmed 0:791a779d6220 416 emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
shoaib_ahmed 0:791a779d6220 417
shoaib_ahmed 0:791a779d6220 418 emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
shoaib_ahmed 0:791a779d6220 419 emit_byte(cinfo, 0x46);
shoaib_ahmed 0:791a779d6220 420 emit_byte(cinfo, 0x49);
shoaib_ahmed 0:791a779d6220 421 emit_byte(cinfo, 0x46);
shoaib_ahmed 0:791a779d6220 422 emit_byte(cinfo, 0);
shoaib_ahmed 0:791a779d6220 423 emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
shoaib_ahmed 0:791a779d6220 424 emit_byte(cinfo, cinfo->JFIF_minor_version);
shoaib_ahmed 0:791a779d6220 425 emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
shoaib_ahmed 0:791a779d6220 426 emit_2bytes(cinfo, (int) cinfo->X_density);
shoaib_ahmed 0:791a779d6220 427 emit_2bytes(cinfo, (int) cinfo->Y_density);
shoaib_ahmed 0:791a779d6220 428 emit_byte(cinfo, 0); /* No thumbnail image */
shoaib_ahmed 0:791a779d6220 429 emit_byte(cinfo, 0);
shoaib_ahmed 0:791a779d6220 430 }
shoaib_ahmed 0:791a779d6220 431
shoaib_ahmed 0:791a779d6220 432
shoaib_ahmed 0:791a779d6220 433 LOCAL(void)
shoaib_ahmed 0:791a779d6220 434 emit_adobe_app14 (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 435 /* Emit an Adobe APP14 marker */
shoaib_ahmed 0:791a779d6220 436 {
shoaib_ahmed 0:791a779d6220 437 /*
shoaib_ahmed 0:791a779d6220 438 * Length of APP14 block (2 bytes)
shoaib_ahmed 0:791a779d6220 439 * Block ID (5 bytes - ASCII "Adobe")
shoaib_ahmed 0:791a779d6220 440 * Version Number (2 bytes - currently 100)
shoaib_ahmed 0:791a779d6220 441 * Flags0 (2 bytes - currently 0)
shoaib_ahmed 0:791a779d6220 442 * Flags1 (2 bytes - currently 0)
shoaib_ahmed 0:791a779d6220 443 * Color transform (1 byte)
shoaib_ahmed 0:791a779d6220 444 *
shoaib_ahmed 0:791a779d6220 445 * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
shoaib_ahmed 0:791a779d6220 446 * now in circulation seem to use Version = 100, so that's what we write.
shoaib_ahmed 0:791a779d6220 447 *
shoaib_ahmed 0:791a779d6220 448 * We write the color transform byte as 1 if the JPEG color space is
shoaib_ahmed 0:791a779d6220 449 * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
shoaib_ahmed 0:791a779d6220 450 * whether the encoder performed a transformation, which is pretty useless.
shoaib_ahmed 0:791a779d6220 451 */
shoaib_ahmed 0:791a779d6220 452
shoaib_ahmed 0:791a779d6220 453 emit_marker(cinfo, M_APP14);
shoaib_ahmed 0:791a779d6220 454
shoaib_ahmed 0:791a779d6220 455 emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
shoaib_ahmed 0:791a779d6220 456
shoaib_ahmed 0:791a779d6220 457 emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
shoaib_ahmed 0:791a779d6220 458 emit_byte(cinfo, 0x64);
shoaib_ahmed 0:791a779d6220 459 emit_byte(cinfo, 0x6F);
shoaib_ahmed 0:791a779d6220 460 emit_byte(cinfo, 0x62);
shoaib_ahmed 0:791a779d6220 461 emit_byte(cinfo, 0x65);
shoaib_ahmed 0:791a779d6220 462 emit_2bytes(cinfo, 100); /* Version */
shoaib_ahmed 0:791a779d6220 463 emit_2bytes(cinfo, 0); /* Flags0 */
shoaib_ahmed 0:791a779d6220 464 emit_2bytes(cinfo, 0); /* Flags1 */
shoaib_ahmed 0:791a779d6220 465 switch (cinfo->jpeg_color_space) {
shoaib_ahmed 0:791a779d6220 466 case JCS_YCbCr:
shoaib_ahmed 0:791a779d6220 467 emit_byte(cinfo, 1); /* Color transform = 1 */
shoaib_ahmed 0:791a779d6220 468 break;
shoaib_ahmed 0:791a779d6220 469 case JCS_YCCK:
shoaib_ahmed 0:791a779d6220 470 emit_byte(cinfo, 2); /* Color transform = 2 */
shoaib_ahmed 0:791a779d6220 471 break;
shoaib_ahmed 0:791a779d6220 472 default:
shoaib_ahmed 0:791a779d6220 473 emit_byte(cinfo, 0); /* Color transform = 0 */
shoaib_ahmed 0:791a779d6220 474 break;
shoaib_ahmed 0:791a779d6220 475 }
shoaib_ahmed 0:791a779d6220 476 }
shoaib_ahmed 0:791a779d6220 477
shoaib_ahmed 0:791a779d6220 478
shoaib_ahmed 0:791a779d6220 479 /*
shoaib_ahmed 0:791a779d6220 480 * These routines allow writing an arbitrary marker with parameters.
shoaib_ahmed 0:791a779d6220 481 * The only intended use is to emit COM or APPn markers after calling
shoaib_ahmed 0:791a779d6220 482 * write_file_header and before calling write_frame_header.
shoaib_ahmed 0:791a779d6220 483 * Other uses are not guaranteed to produce desirable results.
shoaib_ahmed 0:791a779d6220 484 * Counting the parameter bytes properly is the caller's responsibility.
shoaib_ahmed 0:791a779d6220 485 */
shoaib_ahmed 0:791a779d6220 486
shoaib_ahmed 0:791a779d6220 487 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 488 write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
shoaib_ahmed 0:791a779d6220 489 /* Emit an arbitrary marker header */
shoaib_ahmed 0:791a779d6220 490 {
shoaib_ahmed 0:791a779d6220 491 if (datalen > (unsigned int) 65533) /* safety check */
shoaib_ahmed 0:791a779d6220 492 ERREXIT(cinfo, JERR_BAD_LENGTH);
shoaib_ahmed 0:791a779d6220 493
shoaib_ahmed 0:791a779d6220 494 emit_marker(cinfo, (JPEG_MARKER) marker);
shoaib_ahmed 0:791a779d6220 495
shoaib_ahmed 0:791a779d6220 496 emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
shoaib_ahmed 0:791a779d6220 497 }
shoaib_ahmed 0:791a779d6220 498
shoaib_ahmed 0:791a779d6220 499 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 500 write_marker_byte (j_compress_ptr cinfo, int val)
shoaib_ahmed 0:791a779d6220 501 /* Emit one byte of marker parameters following write_marker_header */
shoaib_ahmed 0:791a779d6220 502 {
shoaib_ahmed 0:791a779d6220 503 emit_byte(cinfo, val);
shoaib_ahmed 0:791a779d6220 504 }
shoaib_ahmed 0:791a779d6220 505
shoaib_ahmed 0:791a779d6220 506
shoaib_ahmed 0:791a779d6220 507 /*
shoaib_ahmed 0:791a779d6220 508 * Write datastream header.
shoaib_ahmed 0:791a779d6220 509 * This consists of an SOI and optional APPn markers.
shoaib_ahmed 0:791a779d6220 510 * We recommend use of the JFIF marker, but not the Adobe marker,
shoaib_ahmed 0:791a779d6220 511 * when using YCbCr or grayscale data. The JFIF marker is also used
shoaib_ahmed 0:791a779d6220 512 * for other standard JPEG colorspaces. The Adobe marker is helpful
shoaib_ahmed 0:791a779d6220 513 * to distinguish RGB, CMYK, and YCCK colorspaces.
shoaib_ahmed 0:791a779d6220 514 * Note that an application can write additional header markers after
shoaib_ahmed 0:791a779d6220 515 * jpeg_start_compress returns.
shoaib_ahmed 0:791a779d6220 516 */
shoaib_ahmed 0:791a779d6220 517
shoaib_ahmed 0:791a779d6220 518 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 519 write_file_header (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 520 {
shoaib_ahmed 0:791a779d6220 521 my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
shoaib_ahmed 0:791a779d6220 522
shoaib_ahmed 0:791a779d6220 523 emit_marker(cinfo, M_SOI); /* first the SOI */
shoaib_ahmed 0:791a779d6220 524
shoaib_ahmed 0:791a779d6220 525 /* SOI is defined to reset restart interval to 0 */
shoaib_ahmed 0:791a779d6220 526 marker->last_restart_interval = 0;
shoaib_ahmed 0:791a779d6220 527
shoaib_ahmed 0:791a779d6220 528 if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
shoaib_ahmed 0:791a779d6220 529 emit_jfif_app0(cinfo);
shoaib_ahmed 0:791a779d6220 530 if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
shoaib_ahmed 0:791a779d6220 531 emit_adobe_app14(cinfo);
shoaib_ahmed 0:791a779d6220 532 }
shoaib_ahmed 0:791a779d6220 533
shoaib_ahmed 0:791a779d6220 534
shoaib_ahmed 0:791a779d6220 535 /*
shoaib_ahmed 0:791a779d6220 536 * Write frame header.
shoaib_ahmed 0:791a779d6220 537 * This consists of DQT and SOFn markers,
shoaib_ahmed 0:791a779d6220 538 * a conditional LSE marker and a conditional pseudo SOS marker.
shoaib_ahmed 0:791a779d6220 539 * Note that we do not emit the SOF until we have emitted the DQT(s).
shoaib_ahmed 0:791a779d6220 540 * This avoids compatibility problems with incorrect implementations that
shoaib_ahmed 0:791a779d6220 541 * try to error-check the quant table numbers as soon as they see the SOF.
shoaib_ahmed 0:791a779d6220 542 */
shoaib_ahmed 0:791a779d6220 543
shoaib_ahmed 0:791a779d6220 544 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 545 write_frame_header (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 546 {
shoaib_ahmed 0:791a779d6220 547 int ci, prec;
shoaib_ahmed 0:791a779d6220 548 boolean is_baseline;
shoaib_ahmed 0:791a779d6220 549 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 550
shoaib_ahmed 0:791a779d6220 551 /* Emit DQT for each quantization table.
shoaib_ahmed 0:791a779d6220 552 * Note that emit_dqt() suppresses any duplicate tables.
shoaib_ahmed 0:791a779d6220 553 */
shoaib_ahmed 0:791a779d6220 554 prec = 0;
shoaib_ahmed 0:791a779d6220 555 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 556 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 557 prec += emit_dqt(cinfo, compptr->quant_tbl_no);
shoaib_ahmed 0:791a779d6220 558 }
shoaib_ahmed 0:791a779d6220 559 /* now prec is nonzero iff there are any 16-bit quant tables. */
shoaib_ahmed 0:791a779d6220 560
shoaib_ahmed 0:791a779d6220 561 /* Check for a non-baseline specification.
shoaib_ahmed 0:791a779d6220 562 * Note we assume that Huffman table numbers won't be changed later.
shoaib_ahmed 0:791a779d6220 563 */
shoaib_ahmed 0:791a779d6220 564 if (cinfo->arith_code || cinfo->progressive_mode ||
shoaib_ahmed 0:791a779d6220 565 cinfo->data_precision != 8 || cinfo->block_size != DCTSIZE) {
shoaib_ahmed 0:791a779d6220 566 is_baseline = FALSE;
shoaib_ahmed 0:791a779d6220 567 } else {
shoaib_ahmed 0:791a779d6220 568 is_baseline = TRUE;
shoaib_ahmed 0:791a779d6220 569 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 570 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 571 if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
shoaib_ahmed 0:791a779d6220 572 is_baseline = FALSE;
shoaib_ahmed 0:791a779d6220 573 }
shoaib_ahmed 0:791a779d6220 574 if (prec && is_baseline) {
shoaib_ahmed 0:791a779d6220 575 is_baseline = FALSE;
shoaib_ahmed 0:791a779d6220 576 /* If it's baseline except for quantizer size, warn the user */
shoaib_ahmed 0:791a779d6220 577 TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
shoaib_ahmed 0:791a779d6220 578 }
shoaib_ahmed 0:791a779d6220 579 }
shoaib_ahmed 0:791a779d6220 580
shoaib_ahmed 0:791a779d6220 581 /* Emit the proper SOF marker */
shoaib_ahmed 0:791a779d6220 582 if (cinfo->arith_code) {
shoaib_ahmed 0:791a779d6220 583 if (cinfo->progressive_mode)
shoaib_ahmed 0:791a779d6220 584 emit_sof(cinfo, M_SOF10); /* SOF code for progressive arithmetic */
shoaib_ahmed 0:791a779d6220 585 else
shoaib_ahmed 0:791a779d6220 586 emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */
shoaib_ahmed 0:791a779d6220 587 } else {
shoaib_ahmed 0:791a779d6220 588 if (cinfo->progressive_mode)
shoaib_ahmed 0:791a779d6220 589 emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
shoaib_ahmed 0:791a779d6220 590 else if (is_baseline)
shoaib_ahmed 0:791a779d6220 591 emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
shoaib_ahmed 0:791a779d6220 592 else
shoaib_ahmed 0:791a779d6220 593 emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
shoaib_ahmed 0:791a779d6220 594 }
shoaib_ahmed 0:791a779d6220 595
shoaib_ahmed 0:791a779d6220 596 /* Check to emit LSE inverse color transform specification marker */
shoaib_ahmed 0:791a779d6220 597 if (cinfo->color_transform)
shoaib_ahmed 0:791a779d6220 598 emit_lse_ict(cinfo);
shoaib_ahmed 0:791a779d6220 599
shoaib_ahmed 0:791a779d6220 600 /* Check to emit pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 601 if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
shoaib_ahmed 0:791a779d6220 602 emit_pseudo_sos(cinfo);
shoaib_ahmed 0:791a779d6220 603 }
shoaib_ahmed 0:791a779d6220 604
shoaib_ahmed 0:791a779d6220 605
shoaib_ahmed 0:791a779d6220 606 /*
shoaib_ahmed 0:791a779d6220 607 * Write scan header.
shoaib_ahmed 0:791a779d6220 608 * This consists of DHT or DAC markers, optional DRI, and SOS.
shoaib_ahmed 0:791a779d6220 609 * Compressed data will be written following the SOS.
shoaib_ahmed 0:791a779d6220 610 */
shoaib_ahmed 0:791a779d6220 611
shoaib_ahmed 0:791a779d6220 612 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 613 write_scan_header (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 614 {
shoaib_ahmed 0:791a779d6220 615 my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
shoaib_ahmed 0:791a779d6220 616 int i;
shoaib_ahmed 0:791a779d6220 617 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 618
shoaib_ahmed 0:791a779d6220 619 if (cinfo->arith_code) {
shoaib_ahmed 0:791a779d6220 620 /* Emit arith conditioning info. We may have some duplication
shoaib_ahmed 0:791a779d6220 621 * if the file has multiple scans, but it's so small it's hardly
shoaib_ahmed 0:791a779d6220 622 * worth worrying about.
shoaib_ahmed 0:791a779d6220 623 */
shoaib_ahmed 0:791a779d6220 624 emit_dac(cinfo);
shoaib_ahmed 0:791a779d6220 625 } else {
shoaib_ahmed 0:791a779d6220 626 /* Emit Huffman tables.
shoaib_ahmed 0:791a779d6220 627 * Note that emit_dht() suppresses any duplicate tables.
shoaib_ahmed 0:791a779d6220 628 */
shoaib_ahmed 0:791a779d6220 629 for (i = 0; i < cinfo->comps_in_scan; i++) {
shoaib_ahmed 0:791a779d6220 630 compptr = cinfo->cur_comp_info[i];
shoaib_ahmed 0:791a779d6220 631 /* DC needs no table for refinement scan */
shoaib_ahmed 0:791a779d6220 632 if (cinfo->Ss == 0 && cinfo->Ah == 0)
shoaib_ahmed 0:791a779d6220 633 emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
shoaib_ahmed 0:791a779d6220 634 /* AC needs no table when not present */
shoaib_ahmed 0:791a779d6220 635 if (cinfo->Se)
shoaib_ahmed 0:791a779d6220 636 emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
shoaib_ahmed 0:791a779d6220 637 }
shoaib_ahmed 0:791a779d6220 638 }
shoaib_ahmed 0:791a779d6220 639
shoaib_ahmed 0:791a779d6220 640 /* Emit DRI if required --- note that DRI value could change for each scan.
shoaib_ahmed 0:791a779d6220 641 * We avoid wasting space with unnecessary DRIs, however.
shoaib_ahmed 0:791a779d6220 642 */
shoaib_ahmed 0:791a779d6220 643 if (cinfo->restart_interval != marker->last_restart_interval) {
shoaib_ahmed 0:791a779d6220 644 emit_dri(cinfo);
shoaib_ahmed 0:791a779d6220 645 marker->last_restart_interval = cinfo->restart_interval;
shoaib_ahmed 0:791a779d6220 646 }
shoaib_ahmed 0:791a779d6220 647
shoaib_ahmed 0:791a779d6220 648 emit_sos(cinfo);
shoaib_ahmed 0:791a779d6220 649 }
shoaib_ahmed 0:791a779d6220 650
shoaib_ahmed 0:791a779d6220 651
shoaib_ahmed 0:791a779d6220 652 /*
shoaib_ahmed 0:791a779d6220 653 * Write datastream trailer.
shoaib_ahmed 0:791a779d6220 654 */
shoaib_ahmed 0:791a779d6220 655
shoaib_ahmed 0:791a779d6220 656 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 657 write_file_trailer (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 658 {
shoaib_ahmed 0:791a779d6220 659 emit_marker(cinfo, M_EOI);
shoaib_ahmed 0:791a779d6220 660 }
shoaib_ahmed 0:791a779d6220 661
shoaib_ahmed 0:791a779d6220 662
shoaib_ahmed 0:791a779d6220 663 /*
shoaib_ahmed 0:791a779d6220 664 * Write an abbreviated table-specification datastream.
shoaib_ahmed 0:791a779d6220 665 * This consists of SOI, DQT and DHT tables, and EOI.
shoaib_ahmed 0:791a779d6220 666 * Any table that is defined and not marked sent_table = TRUE will be
shoaib_ahmed 0:791a779d6220 667 * emitted. Note that all tables will be marked sent_table = TRUE at exit.
shoaib_ahmed 0:791a779d6220 668 */
shoaib_ahmed 0:791a779d6220 669
shoaib_ahmed 0:791a779d6220 670 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 671 write_tables_only (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 672 {
shoaib_ahmed 0:791a779d6220 673 int i;
shoaib_ahmed 0:791a779d6220 674
shoaib_ahmed 0:791a779d6220 675 emit_marker(cinfo, M_SOI);
shoaib_ahmed 0:791a779d6220 676
shoaib_ahmed 0:791a779d6220 677 for (i = 0; i < NUM_QUANT_TBLS; i++) {
shoaib_ahmed 0:791a779d6220 678 if (cinfo->quant_tbl_ptrs[i] != NULL)
shoaib_ahmed 0:791a779d6220 679 (void) emit_dqt(cinfo, i);
shoaib_ahmed 0:791a779d6220 680 }
shoaib_ahmed 0:791a779d6220 681
shoaib_ahmed 0:791a779d6220 682 if (! cinfo->arith_code) {
shoaib_ahmed 0:791a779d6220 683 for (i = 0; i < NUM_HUFF_TBLS; i++) {
shoaib_ahmed 0:791a779d6220 684 if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
shoaib_ahmed 0:791a779d6220 685 emit_dht(cinfo, i, FALSE);
shoaib_ahmed 0:791a779d6220 686 if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
shoaib_ahmed 0:791a779d6220 687 emit_dht(cinfo, i, TRUE);
shoaib_ahmed 0:791a779d6220 688 }
shoaib_ahmed 0:791a779d6220 689 }
shoaib_ahmed 0:791a779d6220 690
shoaib_ahmed 0:791a779d6220 691 emit_marker(cinfo, M_EOI);
shoaib_ahmed 0:791a779d6220 692 }
shoaib_ahmed 0:791a779d6220 693
shoaib_ahmed 0:791a779d6220 694
shoaib_ahmed 0:791a779d6220 695 /*
shoaib_ahmed 0:791a779d6220 696 * Initialize the marker writer module.
shoaib_ahmed 0:791a779d6220 697 */
shoaib_ahmed 0:791a779d6220 698
shoaib_ahmed 0:791a779d6220 699 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 700 jinit_marker_writer (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 701 {
shoaib_ahmed 0:791a779d6220 702 my_marker_ptr marker;
shoaib_ahmed 0:791a779d6220 703
shoaib_ahmed 0:791a779d6220 704 /* Create the subobject */
shoaib_ahmed 0:791a779d6220 705 marker = (my_marker_ptr)
shoaib_ahmed 0:791a779d6220 706 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 707 SIZEOF(my_marker_writer));
shoaib_ahmed 0:791a779d6220 708 cinfo->marker = &marker->pub;
shoaib_ahmed 0:791a779d6220 709 /* Initialize method pointers */
shoaib_ahmed 0:791a779d6220 710 marker->pub.write_file_header = write_file_header;
shoaib_ahmed 0:791a779d6220 711 marker->pub.write_frame_header = write_frame_header;
shoaib_ahmed 0:791a779d6220 712 marker->pub.write_scan_header = write_scan_header;
shoaib_ahmed 0:791a779d6220 713 marker->pub.write_file_trailer = write_file_trailer;
shoaib_ahmed 0:791a779d6220 714 marker->pub.write_tables_only = write_tables_only;
shoaib_ahmed 0:791a779d6220 715 marker->pub.write_marker_header = write_marker_header;
shoaib_ahmed 0:791a779d6220 716 marker->pub.write_marker_byte = write_marker_byte;
shoaib_ahmed 0:791a779d6220 717 /* Initialize private state */
shoaib_ahmed 0:791a779d6220 718 marker->last_restart_interval = 0;
shoaib_ahmed 0:791a779d6220 719 }