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 * jdinput.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1991-1997, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * Modified 2002-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 input control logic for the JPEG decompressor.
shoaib_ahmed 0:791a779d6220 10 * These routines are concerned with controlling the decompressor's input
shoaib_ahmed 0:791a779d6220 11 * processing (marker reading and coefficient decoding). The actual input
shoaib_ahmed 0:791a779d6220 12 * reading is done in jdmarker.c, jdhuff.c, and jdarith.c.
shoaib_ahmed 0:791a779d6220 13 */
shoaib_ahmed 0:791a779d6220 14
shoaib_ahmed 0:791a779d6220 15 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 16 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 17 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 18
shoaib_ahmed 0:791a779d6220 19
shoaib_ahmed 0:791a779d6220 20 /* Private state */
shoaib_ahmed 0:791a779d6220 21
shoaib_ahmed 0:791a779d6220 22 typedef struct {
shoaib_ahmed 0:791a779d6220 23 struct jpeg_input_controller pub; /* public fields */
shoaib_ahmed 0:791a779d6220 24
shoaib_ahmed 0:791a779d6220 25 int inheaders; /* Nonzero until first SOS is reached */
shoaib_ahmed 0:791a779d6220 26 } my_input_controller;
shoaib_ahmed 0:791a779d6220 27
shoaib_ahmed 0:791a779d6220 28 typedef my_input_controller * my_inputctl_ptr;
shoaib_ahmed 0:791a779d6220 29
shoaib_ahmed 0:791a779d6220 30
shoaib_ahmed 0:791a779d6220 31 /* Forward declarations */
shoaib_ahmed 0:791a779d6220 32 METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
shoaib_ahmed 0:791a779d6220 33
shoaib_ahmed 0:791a779d6220 34
shoaib_ahmed 0:791a779d6220 35 /*
shoaib_ahmed 0:791a779d6220 36 * Routines to calculate various quantities related to the size of the image.
shoaib_ahmed 0:791a779d6220 37 */
shoaib_ahmed 0:791a779d6220 38
shoaib_ahmed 0:791a779d6220 39
shoaib_ahmed 0:791a779d6220 40 /*
shoaib_ahmed 0:791a779d6220 41 * Compute output image dimensions and related values.
shoaib_ahmed 0:791a779d6220 42 * NOTE: this is exported for possible use by application.
shoaib_ahmed 0:791a779d6220 43 * Hence it mustn't do anything that can't be done twice.
shoaib_ahmed 0:791a779d6220 44 */
shoaib_ahmed 0:791a779d6220 45
shoaib_ahmed 0:791a779d6220 46 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 47 jpeg_core_output_dimensions (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 48 /* Do computations that are needed before master selection phase.
shoaib_ahmed 0:791a779d6220 49 * This function is used for transcoding and full decompression.
shoaib_ahmed 0:791a779d6220 50 */
shoaib_ahmed 0:791a779d6220 51 {
shoaib_ahmed 0:791a779d6220 52 #ifdef IDCT_SCALING_SUPPORTED
shoaib_ahmed 0:791a779d6220 53 int ci;
shoaib_ahmed 0:791a779d6220 54 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 55
shoaib_ahmed 0:791a779d6220 56 /* Compute actual output image dimensions and DCT scaling choices. */
shoaib_ahmed 0:791a779d6220 57 if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) {
shoaib_ahmed 0:791a779d6220 58 /* Provide 1/block_size scaling */
shoaib_ahmed 0:791a779d6220 59 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 60 jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 61 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 62 jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 63 cinfo->min_DCT_h_scaled_size = 1;
shoaib_ahmed 0:791a779d6220 64 cinfo->min_DCT_v_scaled_size = 1;
shoaib_ahmed 0:791a779d6220 65 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) {
shoaib_ahmed 0:791a779d6220 66 /* Provide 2/block_size scaling */
shoaib_ahmed 0:791a779d6220 67 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 68 jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 69 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 70 jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 71 cinfo->min_DCT_h_scaled_size = 2;
shoaib_ahmed 0:791a779d6220 72 cinfo->min_DCT_v_scaled_size = 2;
shoaib_ahmed 0:791a779d6220 73 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 3) {
shoaib_ahmed 0:791a779d6220 74 /* Provide 3/block_size scaling */
shoaib_ahmed 0:791a779d6220 75 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 76 jdiv_round_up((long) cinfo->image_width * 3L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 77 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 78 jdiv_round_up((long) cinfo->image_height * 3L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 79 cinfo->min_DCT_h_scaled_size = 3;
shoaib_ahmed 0:791a779d6220 80 cinfo->min_DCT_v_scaled_size = 3;
shoaib_ahmed 0:791a779d6220 81 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) {
shoaib_ahmed 0:791a779d6220 82 /* Provide 4/block_size scaling */
shoaib_ahmed 0:791a779d6220 83 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 84 jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 85 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 86 jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 87 cinfo->min_DCT_h_scaled_size = 4;
shoaib_ahmed 0:791a779d6220 88 cinfo->min_DCT_v_scaled_size = 4;
shoaib_ahmed 0:791a779d6220 89 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 5) {
shoaib_ahmed 0:791a779d6220 90 /* Provide 5/block_size scaling */
shoaib_ahmed 0:791a779d6220 91 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 92 jdiv_round_up((long) cinfo->image_width * 5L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 93 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 94 jdiv_round_up((long) cinfo->image_height * 5L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 95 cinfo->min_DCT_h_scaled_size = 5;
shoaib_ahmed 0:791a779d6220 96 cinfo->min_DCT_v_scaled_size = 5;
shoaib_ahmed 0:791a779d6220 97 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 6) {
shoaib_ahmed 0:791a779d6220 98 /* Provide 6/block_size scaling */
shoaib_ahmed 0:791a779d6220 99 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 100 jdiv_round_up((long) cinfo->image_width * 6L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 101 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 102 jdiv_round_up((long) cinfo->image_height * 6L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 103 cinfo->min_DCT_h_scaled_size = 6;
shoaib_ahmed 0:791a779d6220 104 cinfo->min_DCT_v_scaled_size = 6;
shoaib_ahmed 0:791a779d6220 105 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 7) {
shoaib_ahmed 0:791a779d6220 106 /* Provide 7/block_size scaling */
shoaib_ahmed 0:791a779d6220 107 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 108 jdiv_round_up((long) cinfo->image_width * 7L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 109 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 110 jdiv_round_up((long) cinfo->image_height * 7L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 111 cinfo->min_DCT_h_scaled_size = 7;
shoaib_ahmed 0:791a779d6220 112 cinfo->min_DCT_v_scaled_size = 7;
shoaib_ahmed 0:791a779d6220 113 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) {
shoaib_ahmed 0:791a779d6220 114 /* Provide 8/block_size scaling */
shoaib_ahmed 0:791a779d6220 115 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 116 jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 117 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 118 jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 119 cinfo->min_DCT_h_scaled_size = 8;
shoaib_ahmed 0:791a779d6220 120 cinfo->min_DCT_v_scaled_size = 8;
shoaib_ahmed 0:791a779d6220 121 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 9) {
shoaib_ahmed 0:791a779d6220 122 /* Provide 9/block_size scaling */
shoaib_ahmed 0:791a779d6220 123 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 124 jdiv_round_up((long) cinfo->image_width * 9L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 125 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 126 jdiv_round_up((long) cinfo->image_height * 9L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 127 cinfo->min_DCT_h_scaled_size = 9;
shoaib_ahmed 0:791a779d6220 128 cinfo->min_DCT_v_scaled_size = 9;
shoaib_ahmed 0:791a779d6220 129 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 10) {
shoaib_ahmed 0:791a779d6220 130 /* Provide 10/block_size scaling */
shoaib_ahmed 0:791a779d6220 131 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 132 jdiv_round_up((long) cinfo->image_width * 10L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 133 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 134 jdiv_round_up((long) cinfo->image_height * 10L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 135 cinfo->min_DCT_h_scaled_size = 10;
shoaib_ahmed 0:791a779d6220 136 cinfo->min_DCT_v_scaled_size = 10;
shoaib_ahmed 0:791a779d6220 137 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 11) {
shoaib_ahmed 0:791a779d6220 138 /* Provide 11/block_size scaling */
shoaib_ahmed 0:791a779d6220 139 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 140 jdiv_round_up((long) cinfo->image_width * 11L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 141 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 142 jdiv_round_up((long) cinfo->image_height * 11L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 143 cinfo->min_DCT_h_scaled_size = 11;
shoaib_ahmed 0:791a779d6220 144 cinfo->min_DCT_v_scaled_size = 11;
shoaib_ahmed 0:791a779d6220 145 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 12) {
shoaib_ahmed 0:791a779d6220 146 /* Provide 12/block_size scaling */
shoaib_ahmed 0:791a779d6220 147 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 148 jdiv_round_up((long) cinfo->image_width * 12L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 149 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 150 jdiv_round_up((long) cinfo->image_height * 12L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 151 cinfo->min_DCT_h_scaled_size = 12;
shoaib_ahmed 0:791a779d6220 152 cinfo->min_DCT_v_scaled_size = 12;
shoaib_ahmed 0:791a779d6220 153 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 13) {
shoaib_ahmed 0:791a779d6220 154 /* Provide 13/block_size scaling */
shoaib_ahmed 0:791a779d6220 155 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 156 jdiv_round_up((long) cinfo->image_width * 13L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 157 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 158 jdiv_round_up((long) cinfo->image_height * 13L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 159 cinfo->min_DCT_h_scaled_size = 13;
shoaib_ahmed 0:791a779d6220 160 cinfo->min_DCT_v_scaled_size = 13;
shoaib_ahmed 0:791a779d6220 161 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 14) {
shoaib_ahmed 0:791a779d6220 162 /* Provide 14/block_size scaling */
shoaib_ahmed 0:791a779d6220 163 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 164 jdiv_round_up((long) cinfo->image_width * 14L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 165 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 166 jdiv_round_up((long) cinfo->image_height * 14L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 167 cinfo->min_DCT_h_scaled_size = 14;
shoaib_ahmed 0:791a779d6220 168 cinfo->min_DCT_v_scaled_size = 14;
shoaib_ahmed 0:791a779d6220 169 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 15) {
shoaib_ahmed 0:791a779d6220 170 /* Provide 15/block_size scaling */
shoaib_ahmed 0:791a779d6220 171 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 172 jdiv_round_up((long) cinfo->image_width * 15L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 173 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 174 jdiv_round_up((long) cinfo->image_height * 15L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 175 cinfo->min_DCT_h_scaled_size = 15;
shoaib_ahmed 0:791a779d6220 176 cinfo->min_DCT_v_scaled_size = 15;
shoaib_ahmed 0:791a779d6220 177 } else {
shoaib_ahmed 0:791a779d6220 178 /* Provide 16/block_size scaling */
shoaib_ahmed 0:791a779d6220 179 cinfo->output_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 180 jdiv_round_up((long) cinfo->image_width * 16L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 181 cinfo->output_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 182 jdiv_round_up((long) cinfo->image_height * 16L, (long) cinfo->block_size);
shoaib_ahmed 0:791a779d6220 183 cinfo->min_DCT_h_scaled_size = 16;
shoaib_ahmed 0:791a779d6220 184 cinfo->min_DCT_v_scaled_size = 16;
shoaib_ahmed 0:791a779d6220 185 }
shoaib_ahmed 0:791a779d6220 186
shoaib_ahmed 0:791a779d6220 187 /* Recompute dimensions of components */
shoaib_ahmed 0:791a779d6220 188 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 189 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 190 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size;
shoaib_ahmed 0:791a779d6220 191 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size;
shoaib_ahmed 0:791a779d6220 192 }
shoaib_ahmed 0:791a779d6220 193
shoaib_ahmed 0:791a779d6220 194 #else /* !IDCT_SCALING_SUPPORTED */
shoaib_ahmed 0:791a779d6220 195
shoaib_ahmed 0:791a779d6220 196 /* Hardwire it to "no scaling" */
shoaib_ahmed 0:791a779d6220 197 cinfo->output_width = cinfo->image_width;
shoaib_ahmed 0:791a779d6220 198 cinfo->output_height = cinfo->image_height;
shoaib_ahmed 0:791a779d6220 199 /* initial_setup has already initialized DCT_scaled_size,
shoaib_ahmed 0:791a779d6220 200 * and has computed unscaled downsampled_width and downsampled_height.
shoaib_ahmed 0:791a779d6220 201 */
shoaib_ahmed 0:791a779d6220 202
shoaib_ahmed 0:791a779d6220 203 #endif /* IDCT_SCALING_SUPPORTED */
shoaib_ahmed 0:791a779d6220 204 }
shoaib_ahmed 0:791a779d6220 205
shoaib_ahmed 0:791a779d6220 206
shoaib_ahmed 0:791a779d6220 207 LOCAL(void)
shoaib_ahmed 0:791a779d6220 208 initial_setup (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 209 /* Called once, when first SOS marker is reached */
shoaib_ahmed 0:791a779d6220 210 {
shoaib_ahmed 0:791a779d6220 211 int ci;
shoaib_ahmed 0:791a779d6220 212 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 213
shoaib_ahmed 0:791a779d6220 214 /* Make sure image isn't bigger than I can handle */
shoaib_ahmed 0:791a779d6220 215 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
shoaib_ahmed 0:791a779d6220 216 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
shoaib_ahmed 0:791a779d6220 217 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
shoaib_ahmed 0:791a779d6220 218
shoaib_ahmed 0:791a779d6220 219 /* Only 8 to 12 bits data precision are supported for DCT based JPEG */
shoaib_ahmed 0:791a779d6220 220 if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
shoaib_ahmed 0:791a779d6220 221 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
shoaib_ahmed 0:791a779d6220 222
shoaib_ahmed 0:791a779d6220 223 /* Check that number of components won't exceed internal array sizes */
shoaib_ahmed 0:791a779d6220 224 if (cinfo->num_components > MAX_COMPONENTS)
shoaib_ahmed 0:791a779d6220 225 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
shoaib_ahmed 0:791a779d6220 226 MAX_COMPONENTS);
shoaib_ahmed 0:791a779d6220 227
shoaib_ahmed 0:791a779d6220 228 /* Compute maximum sampling factors; check factor validity */
shoaib_ahmed 0:791a779d6220 229 cinfo->max_h_samp_factor = 1;
shoaib_ahmed 0:791a779d6220 230 cinfo->max_v_samp_factor = 1;
shoaib_ahmed 0:791a779d6220 231 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 232 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 233 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
shoaib_ahmed 0:791a779d6220 234 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
shoaib_ahmed 0:791a779d6220 235 ERREXIT(cinfo, JERR_BAD_SAMPLING);
shoaib_ahmed 0:791a779d6220 236 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
shoaib_ahmed 0:791a779d6220 237 compptr->h_samp_factor);
shoaib_ahmed 0:791a779d6220 238 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
shoaib_ahmed 0:791a779d6220 239 compptr->v_samp_factor);
shoaib_ahmed 0:791a779d6220 240 }
shoaib_ahmed 0:791a779d6220 241
shoaib_ahmed 0:791a779d6220 242 /* Derive block_size, natural_order, and lim_Se */
shoaib_ahmed 0:791a779d6220 243 if (cinfo->is_baseline || (cinfo->progressive_mode &&
shoaib_ahmed 0:791a779d6220 244 cinfo->comps_in_scan)) { /* no pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 245 cinfo->block_size = DCTSIZE;
shoaib_ahmed 0:791a779d6220 246 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 247 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 248 } else
shoaib_ahmed 0:791a779d6220 249 switch (cinfo->Se) {
shoaib_ahmed 0:791a779d6220 250 case (1*1-1):
shoaib_ahmed 0:791a779d6220 251 cinfo->block_size = 1;
shoaib_ahmed 0:791a779d6220 252 cinfo->natural_order = jpeg_natural_order; /* not needed */
shoaib_ahmed 0:791a779d6220 253 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 254 break;
shoaib_ahmed 0:791a779d6220 255 case (2*2-1):
shoaib_ahmed 0:791a779d6220 256 cinfo->block_size = 2;
shoaib_ahmed 0:791a779d6220 257 cinfo->natural_order = jpeg_natural_order2;
shoaib_ahmed 0:791a779d6220 258 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 259 break;
shoaib_ahmed 0:791a779d6220 260 case (3*3-1):
shoaib_ahmed 0:791a779d6220 261 cinfo->block_size = 3;
shoaib_ahmed 0:791a779d6220 262 cinfo->natural_order = jpeg_natural_order3;
shoaib_ahmed 0:791a779d6220 263 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 264 break;
shoaib_ahmed 0:791a779d6220 265 case (4*4-1):
shoaib_ahmed 0:791a779d6220 266 cinfo->block_size = 4;
shoaib_ahmed 0:791a779d6220 267 cinfo->natural_order = jpeg_natural_order4;
shoaib_ahmed 0:791a779d6220 268 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 269 break;
shoaib_ahmed 0:791a779d6220 270 case (5*5-1):
shoaib_ahmed 0:791a779d6220 271 cinfo->block_size = 5;
shoaib_ahmed 0:791a779d6220 272 cinfo->natural_order = jpeg_natural_order5;
shoaib_ahmed 0:791a779d6220 273 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 274 break;
shoaib_ahmed 0:791a779d6220 275 case (6*6-1):
shoaib_ahmed 0:791a779d6220 276 cinfo->block_size = 6;
shoaib_ahmed 0:791a779d6220 277 cinfo->natural_order = jpeg_natural_order6;
shoaib_ahmed 0:791a779d6220 278 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 279 break;
shoaib_ahmed 0:791a779d6220 280 case (7*7-1):
shoaib_ahmed 0:791a779d6220 281 cinfo->block_size = 7;
shoaib_ahmed 0:791a779d6220 282 cinfo->natural_order = jpeg_natural_order7;
shoaib_ahmed 0:791a779d6220 283 cinfo->lim_Se = cinfo->Se;
shoaib_ahmed 0:791a779d6220 284 break;
shoaib_ahmed 0:791a779d6220 285 case (8*8-1):
shoaib_ahmed 0:791a779d6220 286 cinfo->block_size = 8;
shoaib_ahmed 0:791a779d6220 287 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 288 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 289 break;
shoaib_ahmed 0:791a779d6220 290 case (9*9-1):
shoaib_ahmed 0:791a779d6220 291 cinfo->block_size = 9;
shoaib_ahmed 0:791a779d6220 292 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 293 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 294 break;
shoaib_ahmed 0:791a779d6220 295 case (10*10-1):
shoaib_ahmed 0:791a779d6220 296 cinfo->block_size = 10;
shoaib_ahmed 0:791a779d6220 297 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 298 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 299 break;
shoaib_ahmed 0:791a779d6220 300 case (11*11-1):
shoaib_ahmed 0:791a779d6220 301 cinfo->block_size = 11;
shoaib_ahmed 0:791a779d6220 302 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 303 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 304 break;
shoaib_ahmed 0:791a779d6220 305 case (12*12-1):
shoaib_ahmed 0:791a779d6220 306 cinfo->block_size = 12;
shoaib_ahmed 0:791a779d6220 307 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 308 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 309 break;
shoaib_ahmed 0:791a779d6220 310 case (13*13-1):
shoaib_ahmed 0:791a779d6220 311 cinfo->block_size = 13;
shoaib_ahmed 0:791a779d6220 312 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 313 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 314 break;
shoaib_ahmed 0:791a779d6220 315 case (14*14-1):
shoaib_ahmed 0:791a779d6220 316 cinfo->block_size = 14;
shoaib_ahmed 0:791a779d6220 317 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 318 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 319 break;
shoaib_ahmed 0:791a779d6220 320 case (15*15-1):
shoaib_ahmed 0:791a779d6220 321 cinfo->block_size = 15;
shoaib_ahmed 0:791a779d6220 322 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 323 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 324 break;
shoaib_ahmed 0:791a779d6220 325 case (16*16-1):
shoaib_ahmed 0:791a779d6220 326 cinfo->block_size = 16;
shoaib_ahmed 0:791a779d6220 327 cinfo->natural_order = jpeg_natural_order;
shoaib_ahmed 0:791a779d6220 328 cinfo->lim_Se = DCTSIZE2-1;
shoaib_ahmed 0:791a779d6220 329 break;
shoaib_ahmed 0:791a779d6220 330 default:
shoaib_ahmed 0:791a779d6220 331 ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
shoaib_ahmed 0:791a779d6220 332 cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
shoaib_ahmed 0:791a779d6220 333 break;
shoaib_ahmed 0:791a779d6220 334 }
shoaib_ahmed 0:791a779d6220 335
shoaib_ahmed 0:791a779d6220 336 /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
shoaib_ahmed 0:791a779d6220 337 * In the full decompressor,
shoaib_ahmed 0:791a779d6220 338 * this will be overridden by jpeg_calc_output_dimensions in jdmaster.c;
shoaib_ahmed 0:791a779d6220 339 * but in the transcoder,
shoaib_ahmed 0:791a779d6220 340 * jpeg_calc_output_dimensions is not used, so we must do it here.
shoaib_ahmed 0:791a779d6220 341 */
shoaib_ahmed 0:791a779d6220 342 cinfo->min_DCT_h_scaled_size = cinfo->block_size;
shoaib_ahmed 0:791a779d6220 343 cinfo->min_DCT_v_scaled_size = cinfo->block_size;
shoaib_ahmed 0:791a779d6220 344
shoaib_ahmed 0:791a779d6220 345 /* Compute dimensions of components */
shoaib_ahmed 0:791a779d6220 346 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 347 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 348 compptr->DCT_h_scaled_size = cinfo->block_size;
shoaib_ahmed 0:791a779d6220 349 compptr->DCT_v_scaled_size = cinfo->block_size;
shoaib_ahmed 0:791a779d6220 350 /* Size in DCT blocks */
shoaib_ahmed 0:791a779d6220 351 compptr->width_in_blocks = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 352 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
shoaib_ahmed 0:791a779d6220 353 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
shoaib_ahmed 0:791a779d6220 354 compptr->height_in_blocks = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 355 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
shoaib_ahmed 0:791a779d6220 356 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
shoaib_ahmed 0:791a779d6220 357 /* downsampled_width and downsampled_height will also be overridden by
shoaib_ahmed 0:791a779d6220 358 * jdmaster.c if we are doing full decompression. The transcoder library
shoaib_ahmed 0:791a779d6220 359 * doesn't use these values, but the calling application might.
shoaib_ahmed 0:791a779d6220 360 */
shoaib_ahmed 0:791a779d6220 361 /* Size in samples */
shoaib_ahmed 0:791a779d6220 362 compptr->downsampled_width = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 363 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
shoaib_ahmed 0:791a779d6220 364 (long) cinfo->max_h_samp_factor);
shoaib_ahmed 0:791a779d6220 365 compptr->downsampled_height = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 366 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
shoaib_ahmed 0:791a779d6220 367 (long) cinfo->max_v_samp_factor);
shoaib_ahmed 0:791a779d6220 368 /* Mark component needed, until color conversion says otherwise */
shoaib_ahmed 0:791a779d6220 369 compptr->component_needed = TRUE;
shoaib_ahmed 0:791a779d6220 370 /* Mark no quantization table yet saved for component */
shoaib_ahmed 0:791a779d6220 371 compptr->quant_table = NULL;
shoaib_ahmed 0:791a779d6220 372 }
shoaib_ahmed 0:791a779d6220 373
shoaib_ahmed 0:791a779d6220 374 /* Compute number of fully interleaved MCU rows. */
shoaib_ahmed 0:791a779d6220 375 cinfo->total_iMCU_rows = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 376 jdiv_round_up((long) cinfo->image_height,
shoaib_ahmed 0:791a779d6220 377 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
shoaib_ahmed 0:791a779d6220 378
shoaib_ahmed 0:791a779d6220 379 /* Decide whether file contains multiple scans */
shoaib_ahmed 0:791a779d6220 380 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
shoaib_ahmed 0:791a779d6220 381 cinfo->inputctl->has_multiple_scans = TRUE;
shoaib_ahmed 0:791a779d6220 382 else
shoaib_ahmed 0:791a779d6220 383 cinfo->inputctl->has_multiple_scans = FALSE;
shoaib_ahmed 0:791a779d6220 384 }
shoaib_ahmed 0:791a779d6220 385
shoaib_ahmed 0:791a779d6220 386
shoaib_ahmed 0:791a779d6220 387 LOCAL(void)
shoaib_ahmed 0:791a779d6220 388 per_scan_setup (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 389 /* Do computations that are needed before processing a JPEG scan */
shoaib_ahmed 0:791a779d6220 390 /* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
shoaib_ahmed 0:791a779d6220 391 {
shoaib_ahmed 0:791a779d6220 392 int ci, mcublks, tmp;
shoaib_ahmed 0:791a779d6220 393 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 394
shoaib_ahmed 0:791a779d6220 395 if (cinfo->comps_in_scan == 1) {
shoaib_ahmed 0:791a779d6220 396
shoaib_ahmed 0:791a779d6220 397 /* Noninterleaved (single-component) scan */
shoaib_ahmed 0:791a779d6220 398 compptr = cinfo->cur_comp_info[0];
shoaib_ahmed 0:791a779d6220 399
shoaib_ahmed 0:791a779d6220 400 /* Overall image size in MCUs */
shoaib_ahmed 0:791a779d6220 401 cinfo->MCUs_per_row = compptr->width_in_blocks;
shoaib_ahmed 0:791a779d6220 402 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
shoaib_ahmed 0:791a779d6220 403
shoaib_ahmed 0:791a779d6220 404 /* For noninterleaved scan, always one block per MCU */
shoaib_ahmed 0:791a779d6220 405 compptr->MCU_width = 1;
shoaib_ahmed 0:791a779d6220 406 compptr->MCU_height = 1;
shoaib_ahmed 0:791a779d6220 407 compptr->MCU_blocks = 1;
shoaib_ahmed 0:791a779d6220 408 compptr->MCU_sample_width = compptr->DCT_h_scaled_size;
shoaib_ahmed 0:791a779d6220 409 compptr->last_col_width = 1;
shoaib_ahmed 0:791a779d6220 410 /* For noninterleaved scans, it is convenient to define last_row_height
shoaib_ahmed 0:791a779d6220 411 * as the number of block rows present in the last iMCU row.
shoaib_ahmed 0:791a779d6220 412 */
shoaib_ahmed 0:791a779d6220 413 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
shoaib_ahmed 0:791a779d6220 414 if (tmp == 0) tmp = compptr->v_samp_factor;
shoaib_ahmed 0:791a779d6220 415 compptr->last_row_height = tmp;
shoaib_ahmed 0:791a779d6220 416
shoaib_ahmed 0:791a779d6220 417 /* Prepare array describing MCU composition */
shoaib_ahmed 0:791a779d6220 418 cinfo->blocks_in_MCU = 1;
shoaib_ahmed 0:791a779d6220 419 cinfo->MCU_membership[0] = 0;
shoaib_ahmed 0:791a779d6220 420
shoaib_ahmed 0:791a779d6220 421 } else {
shoaib_ahmed 0:791a779d6220 422
shoaib_ahmed 0:791a779d6220 423 /* Interleaved (multi-component) scan */
shoaib_ahmed 0:791a779d6220 424 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
shoaib_ahmed 0:791a779d6220 425 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
shoaib_ahmed 0:791a779d6220 426 MAX_COMPS_IN_SCAN);
shoaib_ahmed 0:791a779d6220 427
shoaib_ahmed 0:791a779d6220 428 /* Overall image size in MCUs */
shoaib_ahmed 0:791a779d6220 429 cinfo->MCUs_per_row = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 430 jdiv_round_up((long) cinfo->image_width,
shoaib_ahmed 0:791a779d6220 431 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
shoaib_ahmed 0:791a779d6220 432 cinfo->MCU_rows_in_scan = (JDIMENSION)
shoaib_ahmed 0:791a779d6220 433 jdiv_round_up((long) cinfo->image_height,
shoaib_ahmed 0:791a779d6220 434 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
shoaib_ahmed 0:791a779d6220 435
shoaib_ahmed 0:791a779d6220 436 cinfo->blocks_in_MCU = 0;
shoaib_ahmed 0:791a779d6220 437
shoaib_ahmed 0:791a779d6220 438 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
shoaib_ahmed 0:791a779d6220 439 compptr = cinfo->cur_comp_info[ci];
shoaib_ahmed 0:791a779d6220 440 /* Sampling factors give # of blocks of component in each MCU */
shoaib_ahmed 0:791a779d6220 441 compptr->MCU_width = compptr->h_samp_factor;
shoaib_ahmed 0:791a779d6220 442 compptr->MCU_height = compptr->v_samp_factor;
shoaib_ahmed 0:791a779d6220 443 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
shoaib_ahmed 0:791a779d6220 444 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;
shoaib_ahmed 0:791a779d6220 445 /* Figure number of non-dummy blocks in last MCU column & row */
shoaib_ahmed 0:791a779d6220 446 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
shoaib_ahmed 0:791a779d6220 447 if (tmp == 0) tmp = compptr->MCU_width;
shoaib_ahmed 0:791a779d6220 448 compptr->last_col_width = tmp;
shoaib_ahmed 0:791a779d6220 449 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
shoaib_ahmed 0:791a779d6220 450 if (tmp == 0) tmp = compptr->MCU_height;
shoaib_ahmed 0:791a779d6220 451 compptr->last_row_height = tmp;
shoaib_ahmed 0:791a779d6220 452 /* Prepare array describing MCU composition */
shoaib_ahmed 0:791a779d6220 453 mcublks = compptr->MCU_blocks;
shoaib_ahmed 0:791a779d6220 454 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
shoaib_ahmed 0:791a779d6220 455 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
shoaib_ahmed 0:791a779d6220 456 while (mcublks-- > 0) {
shoaib_ahmed 0:791a779d6220 457 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
shoaib_ahmed 0:791a779d6220 458 }
shoaib_ahmed 0:791a779d6220 459 }
shoaib_ahmed 0:791a779d6220 460
shoaib_ahmed 0:791a779d6220 461 }
shoaib_ahmed 0:791a779d6220 462 }
shoaib_ahmed 0:791a779d6220 463
shoaib_ahmed 0:791a779d6220 464
shoaib_ahmed 0:791a779d6220 465 /*
shoaib_ahmed 0:791a779d6220 466 * Save away a copy of the Q-table referenced by each component present
shoaib_ahmed 0:791a779d6220 467 * in the current scan, unless already saved during a prior scan.
shoaib_ahmed 0:791a779d6220 468 *
shoaib_ahmed 0:791a779d6220 469 * In a multiple-scan JPEG file, the encoder could assign different components
shoaib_ahmed 0:791a779d6220 470 * the same Q-table slot number, but change table definitions between scans
shoaib_ahmed 0:791a779d6220 471 * so that each component uses a different Q-table. (The IJG encoder is not
shoaib_ahmed 0:791a779d6220 472 * currently capable of doing this, but other encoders might.) Since we want
shoaib_ahmed 0:791a779d6220 473 * to be able to dequantize all the components at the end of the file, this
shoaib_ahmed 0:791a779d6220 474 * means that we have to save away the table actually used for each component.
shoaib_ahmed 0:791a779d6220 475 * We do this by copying the table at the start of the first scan containing
shoaib_ahmed 0:791a779d6220 476 * the component.
shoaib_ahmed 0:791a779d6220 477 * The JPEG spec prohibits the encoder from changing the contents of a Q-table
shoaib_ahmed 0:791a779d6220 478 * slot between scans of a component using that slot. If the encoder does so
shoaib_ahmed 0:791a779d6220 479 * anyway, this decoder will simply use the Q-table values that were current
shoaib_ahmed 0:791a779d6220 480 * at the start of the first scan for the component.
shoaib_ahmed 0:791a779d6220 481 *
shoaib_ahmed 0:791a779d6220 482 * The decompressor output side looks only at the saved quant tables,
shoaib_ahmed 0:791a779d6220 483 * not at the current Q-table slots.
shoaib_ahmed 0:791a779d6220 484 */
shoaib_ahmed 0:791a779d6220 485
shoaib_ahmed 0:791a779d6220 486 LOCAL(void)
shoaib_ahmed 0:791a779d6220 487 latch_quant_tables (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 488 {
shoaib_ahmed 0:791a779d6220 489 int ci, qtblno;
shoaib_ahmed 0:791a779d6220 490 jpeg_component_info *compptr;
shoaib_ahmed 0:791a779d6220 491 JQUANT_TBL * qtbl;
shoaib_ahmed 0:791a779d6220 492
shoaib_ahmed 0:791a779d6220 493 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
shoaib_ahmed 0:791a779d6220 494 compptr = cinfo->cur_comp_info[ci];
shoaib_ahmed 0:791a779d6220 495 /* No work if we already saved Q-table for this component */
shoaib_ahmed 0:791a779d6220 496 if (compptr->quant_table != NULL)
shoaib_ahmed 0:791a779d6220 497 continue;
shoaib_ahmed 0:791a779d6220 498 /* Make sure specified quantization table is present */
shoaib_ahmed 0:791a779d6220 499 qtblno = compptr->quant_tbl_no;
shoaib_ahmed 0:791a779d6220 500 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
shoaib_ahmed 0:791a779d6220 501 cinfo->quant_tbl_ptrs[qtblno] == NULL)
shoaib_ahmed 0:791a779d6220 502 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
shoaib_ahmed 0:791a779d6220 503 /* OK, save away the quantization table */
shoaib_ahmed 0:791a779d6220 504 qtbl = (JQUANT_TBL *)
shoaib_ahmed 0:791a779d6220 505 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 506 SIZEOF(JQUANT_TBL));
shoaib_ahmed 0:791a779d6220 507 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
shoaib_ahmed 0:791a779d6220 508 compptr->quant_table = qtbl;
shoaib_ahmed 0:791a779d6220 509 }
shoaib_ahmed 0:791a779d6220 510 }
shoaib_ahmed 0:791a779d6220 511
shoaib_ahmed 0:791a779d6220 512
shoaib_ahmed 0:791a779d6220 513 /*
shoaib_ahmed 0:791a779d6220 514 * Initialize the input modules to read a scan of compressed data.
shoaib_ahmed 0:791a779d6220 515 * The first call to this is done by jdmaster.c after initializing
shoaib_ahmed 0:791a779d6220 516 * the entire decompressor (during jpeg_start_decompress).
shoaib_ahmed 0:791a779d6220 517 * Subsequent calls come from consume_markers, below.
shoaib_ahmed 0:791a779d6220 518 */
shoaib_ahmed 0:791a779d6220 519
shoaib_ahmed 0:791a779d6220 520 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 521 start_input_pass (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 522 {
shoaib_ahmed 0:791a779d6220 523 per_scan_setup(cinfo);
shoaib_ahmed 0:791a779d6220 524 latch_quant_tables(cinfo);
shoaib_ahmed 0:791a779d6220 525 (*cinfo->entropy->start_pass) (cinfo);
shoaib_ahmed 0:791a779d6220 526 (*cinfo->coef->start_input_pass) (cinfo);
shoaib_ahmed 0:791a779d6220 527 cinfo->inputctl->consume_input = cinfo->coef->consume_data;
shoaib_ahmed 0:791a779d6220 528 }
shoaib_ahmed 0:791a779d6220 529
shoaib_ahmed 0:791a779d6220 530
shoaib_ahmed 0:791a779d6220 531 /*
shoaib_ahmed 0:791a779d6220 532 * Finish up after inputting a compressed-data scan.
shoaib_ahmed 0:791a779d6220 533 * This is called by the coefficient controller after it's read all
shoaib_ahmed 0:791a779d6220 534 * the expected data of the scan.
shoaib_ahmed 0:791a779d6220 535 */
shoaib_ahmed 0:791a779d6220 536
shoaib_ahmed 0:791a779d6220 537 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 538 finish_input_pass (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 539 {
shoaib_ahmed 0:791a779d6220 540 (*cinfo->entropy->finish_pass) (cinfo);
shoaib_ahmed 0:791a779d6220 541 cinfo->inputctl->consume_input = consume_markers;
shoaib_ahmed 0:791a779d6220 542 }
shoaib_ahmed 0:791a779d6220 543
shoaib_ahmed 0:791a779d6220 544
shoaib_ahmed 0:791a779d6220 545 /*
shoaib_ahmed 0:791a779d6220 546 * Read JPEG markers before, between, or after compressed-data scans.
shoaib_ahmed 0:791a779d6220 547 * Change state as necessary when a new scan is reached.
shoaib_ahmed 0:791a779d6220 548 * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
shoaib_ahmed 0:791a779d6220 549 *
shoaib_ahmed 0:791a779d6220 550 * The consume_input method pointer points either here or to the
shoaib_ahmed 0:791a779d6220 551 * coefficient controller's consume_data routine, depending on whether
shoaib_ahmed 0:791a779d6220 552 * we are reading a compressed data segment or inter-segment markers.
shoaib_ahmed 0:791a779d6220 553 *
shoaib_ahmed 0:791a779d6220 554 * Note: This function should NOT return a pseudo SOS marker (with zero
shoaib_ahmed 0:791a779d6220 555 * component number) to the caller. A pseudo marker received by
shoaib_ahmed 0:791a779d6220 556 * read_markers is processed and then skipped for other markers.
shoaib_ahmed 0:791a779d6220 557 */
shoaib_ahmed 0:791a779d6220 558
shoaib_ahmed 0:791a779d6220 559 METHODDEF(int)
shoaib_ahmed 0:791a779d6220 560 consume_markers (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 561 {
shoaib_ahmed 0:791a779d6220 562 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
shoaib_ahmed 0:791a779d6220 563 int val;
shoaib_ahmed 0:791a779d6220 564
shoaib_ahmed 0:791a779d6220 565 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
shoaib_ahmed 0:791a779d6220 566 return JPEG_REACHED_EOI;
shoaib_ahmed 0:791a779d6220 567
shoaib_ahmed 0:791a779d6220 568 for (;;) { /* Loop to pass pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 569 val = (*cinfo->marker->read_markers) (cinfo);
shoaib_ahmed 0:791a779d6220 570
shoaib_ahmed 0:791a779d6220 571 switch (val) {
shoaib_ahmed 0:791a779d6220 572 case JPEG_REACHED_SOS: /* Found SOS */
shoaib_ahmed 0:791a779d6220 573 if (inputctl->inheaders) { /* 1st SOS */
shoaib_ahmed 0:791a779d6220 574 if (inputctl->inheaders == 1)
shoaib_ahmed 0:791a779d6220 575 initial_setup(cinfo);
shoaib_ahmed 0:791a779d6220 576 if (cinfo->comps_in_scan == 0) { /* pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 577 inputctl->inheaders = 2;
shoaib_ahmed 0:791a779d6220 578 break;
shoaib_ahmed 0:791a779d6220 579 }
shoaib_ahmed 0:791a779d6220 580 inputctl->inheaders = 0;
shoaib_ahmed 0:791a779d6220 581 /* Note: start_input_pass must be called by jdmaster.c
shoaib_ahmed 0:791a779d6220 582 * before any more input can be consumed. jdapimin.c is
shoaib_ahmed 0:791a779d6220 583 * responsible for enforcing this sequencing.
shoaib_ahmed 0:791a779d6220 584 */
shoaib_ahmed 0:791a779d6220 585 } else { /* 2nd or later SOS marker */
shoaib_ahmed 0:791a779d6220 586 if (! inputctl->pub.has_multiple_scans)
shoaib_ahmed 0:791a779d6220 587 ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
shoaib_ahmed 0:791a779d6220 588 if (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */
shoaib_ahmed 0:791a779d6220 589 break;
shoaib_ahmed 0:791a779d6220 590 start_input_pass(cinfo);
shoaib_ahmed 0:791a779d6220 591 }
shoaib_ahmed 0:791a779d6220 592 return val;
shoaib_ahmed 0:791a779d6220 593 case JPEG_REACHED_EOI: /* Found EOI */
shoaib_ahmed 0:791a779d6220 594 inputctl->pub.eoi_reached = TRUE;
shoaib_ahmed 0:791a779d6220 595 if (inputctl->inheaders) { /* Tables-only datastream, apparently */
shoaib_ahmed 0:791a779d6220 596 if (cinfo->marker->saw_SOF)
shoaib_ahmed 0:791a779d6220 597 ERREXIT(cinfo, JERR_SOF_NO_SOS);
shoaib_ahmed 0:791a779d6220 598 } else {
shoaib_ahmed 0:791a779d6220 599 /* Prevent infinite loop in coef ctlr's decompress_data routine
shoaib_ahmed 0:791a779d6220 600 * if user set output_scan_number larger than number of scans.
shoaib_ahmed 0:791a779d6220 601 */
shoaib_ahmed 0:791a779d6220 602 if (cinfo->output_scan_number > cinfo->input_scan_number)
shoaib_ahmed 0:791a779d6220 603 cinfo->output_scan_number = cinfo->input_scan_number;
shoaib_ahmed 0:791a779d6220 604 }
shoaib_ahmed 0:791a779d6220 605 return val;
shoaib_ahmed 0:791a779d6220 606 case JPEG_SUSPENDED:
shoaib_ahmed 0:791a779d6220 607 return val;
shoaib_ahmed 0:791a779d6220 608 default:
shoaib_ahmed 0:791a779d6220 609 return val;
shoaib_ahmed 0:791a779d6220 610 }
shoaib_ahmed 0:791a779d6220 611 }
shoaib_ahmed 0:791a779d6220 612 }
shoaib_ahmed 0:791a779d6220 613
shoaib_ahmed 0:791a779d6220 614
shoaib_ahmed 0:791a779d6220 615 /*
shoaib_ahmed 0:791a779d6220 616 * Reset state to begin a fresh datastream.
shoaib_ahmed 0:791a779d6220 617 */
shoaib_ahmed 0:791a779d6220 618
shoaib_ahmed 0:791a779d6220 619 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 620 reset_input_controller (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 621 {
shoaib_ahmed 0:791a779d6220 622 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
shoaib_ahmed 0:791a779d6220 623
shoaib_ahmed 0:791a779d6220 624 inputctl->pub.consume_input = consume_markers;
shoaib_ahmed 0:791a779d6220 625 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
shoaib_ahmed 0:791a779d6220 626 inputctl->pub.eoi_reached = FALSE;
shoaib_ahmed 0:791a779d6220 627 inputctl->inheaders = 1;
shoaib_ahmed 0:791a779d6220 628 /* Reset other modules */
shoaib_ahmed 0:791a779d6220 629 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
shoaib_ahmed 0:791a779d6220 630 (*cinfo->marker->reset_marker_reader) (cinfo);
shoaib_ahmed 0:791a779d6220 631 /* Reset progression state -- would be cleaner if entropy decoder did this */
shoaib_ahmed 0:791a779d6220 632 cinfo->coef_bits = NULL;
shoaib_ahmed 0:791a779d6220 633 }
shoaib_ahmed 0:791a779d6220 634
shoaib_ahmed 0:791a779d6220 635
shoaib_ahmed 0:791a779d6220 636 /*
shoaib_ahmed 0:791a779d6220 637 * Initialize the input controller module.
shoaib_ahmed 0:791a779d6220 638 * This is called only once, when the decompression object is created.
shoaib_ahmed 0:791a779d6220 639 */
shoaib_ahmed 0:791a779d6220 640
shoaib_ahmed 0:791a779d6220 641 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 642 jinit_input_controller (j_decompress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 643 {
shoaib_ahmed 0:791a779d6220 644 my_inputctl_ptr inputctl;
shoaib_ahmed 0:791a779d6220 645
shoaib_ahmed 0:791a779d6220 646 /* Create subobject in permanent pool */
shoaib_ahmed 0:791a779d6220 647 inputctl = (my_inputctl_ptr)
shoaib_ahmed 0:791a779d6220 648 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
shoaib_ahmed 0:791a779d6220 649 SIZEOF(my_input_controller));
shoaib_ahmed 0:791a779d6220 650 cinfo->inputctl = &inputctl->pub;
shoaib_ahmed 0:791a779d6220 651 /* Initialize method pointers */
shoaib_ahmed 0:791a779d6220 652 inputctl->pub.consume_input = consume_markers;
shoaib_ahmed 0:791a779d6220 653 inputctl->pub.reset_input_controller = reset_input_controller;
shoaib_ahmed 0:791a779d6220 654 inputctl->pub.start_input_pass = start_input_pass;
shoaib_ahmed 0:791a779d6220 655 inputctl->pub.finish_input_pass = finish_input_pass;
shoaib_ahmed 0:791a779d6220 656 /* Initialize state: can't use reset_input_controller since we don't
shoaib_ahmed 0:791a779d6220 657 * want to try to reset other modules yet.
shoaib_ahmed 0:791a779d6220 658 */
shoaib_ahmed 0:791a779d6220 659 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
shoaib_ahmed 0:791a779d6220 660 inputctl->pub.eoi_reached = FALSE;
shoaib_ahmed 0:791a779d6220 661 inputctl->inheaders = 1;
shoaib_ahmed 0:791a779d6220 662 }