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 * jcprepct.c
shoaib_ahmed 0:791a779d6220 3 *
shoaib_ahmed 0:791a779d6220 4 * Copyright (C) 1994-1996, Thomas G. Lane.
shoaib_ahmed 0:791a779d6220 5 * This file is part of the Independent JPEG Group's software.
shoaib_ahmed 0:791a779d6220 6 * For conditions of distribution and use, see the accompanying README file.
shoaib_ahmed 0:791a779d6220 7 *
shoaib_ahmed 0:791a779d6220 8 * This file contains the compression preprocessing controller.
shoaib_ahmed 0:791a779d6220 9 * This controller manages the color conversion, downsampling,
shoaib_ahmed 0:791a779d6220 10 * and edge expansion steps.
shoaib_ahmed 0:791a779d6220 11 *
shoaib_ahmed 0:791a779d6220 12 * Most of the complexity here is associated with buffering input rows
shoaib_ahmed 0:791a779d6220 13 * as required by the downsampler. See the comments at the head of
shoaib_ahmed 0:791a779d6220 14 * jcsample.c for the downsampler's needs.
shoaib_ahmed 0:791a779d6220 15 */
shoaib_ahmed 0:791a779d6220 16
shoaib_ahmed 0:791a779d6220 17 #define JPEG_INTERNALS
shoaib_ahmed 0:791a779d6220 18 #include "jinclude.h"
shoaib_ahmed 0:791a779d6220 19 #include "jpeglib.h"
shoaib_ahmed 0:791a779d6220 20
shoaib_ahmed 0:791a779d6220 21
shoaib_ahmed 0:791a779d6220 22 /* At present, jcsample.c can request context rows only for smoothing.
shoaib_ahmed 0:791a779d6220 23 * In the future, we might also need context rows for CCIR601 sampling
shoaib_ahmed 0:791a779d6220 24 * or other more-complex downsampling procedures. The code to support
shoaib_ahmed 0:791a779d6220 25 * context rows should be compiled only if needed.
shoaib_ahmed 0:791a779d6220 26 */
shoaib_ahmed 0:791a779d6220 27 #ifdef INPUT_SMOOTHING_SUPPORTED
shoaib_ahmed 0:791a779d6220 28 #define CONTEXT_ROWS_SUPPORTED
shoaib_ahmed 0:791a779d6220 29 #endif
shoaib_ahmed 0:791a779d6220 30
shoaib_ahmed 0:791a779d6220 31
shoaib_ahmed 0:791a779d6220 32 /*
shoaib_ahmed 0:791a779d6220 33 * For the simple (no-context-row) case, we just need to buffer one
shoaib_ahmed 0:791a779d6220 34 * row group's worth of pixels for the downsampling step. At the bottom of
shoaib_ahmed 0:791a779d6220 35 * the image, we pad to a full row group by replicating the last pixel row.
shoaib_ahmed 0:791a779d6220 36 * The downsampler's last output row is then replicated if needed to pad
shoaib_ahmed 0:791a779d6220 37 * out to a full iMCU row.
shoaib_ahmed 0:791a779d6220 38 *
shoaib_ahmed 0:791a779d6220 39 * When providing context rows, we must buffer three row groups' worth of
shoaib_ahmed 0:791a779d6220 40 * pixels. Three row groups are physically allocated, but the row pointer
shoaib_ahmed 0:791a779d6220 41 * arrays are made five row groups high, with the extra pointers above and
shoaib_ahmed 0:791a779d6220 42 * below "wrapping around" to point to the last and first real row groups.
shoaib_ahmed 0:791a779d6220 43 * This allows the downsampler to access the proper context rows.
shoaib_ahmed 0:791a779d6220 44 * At the top and bottom of the image, we create dummy context rows by
shoaib_ahmed 0:791a779d6220 45 * copying the first or last real pixel row. This copying could be avoided
shoaib_ahmed 0:791a779d6220 46 * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
shoaib_ahmed 0:791a779d6220 47 * trouble on the compression side.
shoaib_ahmed 0:791a779d6220 48 */
shoaib_ahmed 0:791a779d6220 49
shoaib_ahmed 0:791a779d6220 50
shoaib_ahmed 0:791a779d6220 51 /* Private buffer controller object */
shoaib_ahmed 0:791a779d6220 52
shoaib_ahmed 0:791a779d6220 53 typedef struct {
shoaib_ahmed 0:791a779d6220 54 struct jpeg_c_prep_controller pub; /* public fields */
shoaib_ahmed 0:791a779d6220 55
shoaib_ahmed 0:791a779d6220 56 /* Downsampling input buffer. This buffer holds color-converted data
shoaib_ahmed 0:791a779d6220 57 * until we have enough to do a downsample step.
shoaib_ahmed 0:791a779d6220 58 */
shoaib_ahmed 0:791a779d6220 59 JSAMPARRAY color_buf[MAX_COMPONENTS];
shoaib_ahmed 0:791a779d6220 60
shoaib_ahmed 0:791a779d6220 61 JDIMENSION rows_to_go; /* counts rows remaining in source image */
shoaib_ahmed 0:791a779d6220 62 int next_buf_row; /* index of next row to store in color_buf */
shoaib_ahmed 0:791a779d6220 63
shoaib_ahmed 0:791a779d6220 64 #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
shoaib_ahmed 0:791a779d6220 65 int this_row_group; /* starting row index of group to process */
shoaib_ahmed 0:791a779d6220 66 int next_buf_stop; /* downsample when we reach this index */
shoaib_ahmed 0:791a779d6220 67 #endif
shoaib_ahmed 0:791a779d6220 68 } my_prep_controller;
shoaib_ahmed 0:791a779d6220 69
shoaib_ahmed 0:791a779d6220 70 typedef my_prep_controller * my_prep_ptr;
shoaib_ahmed 0:791a779d6220 71
shoaib_ahmed 0:791a779d6220 72
shoaib_ahmed 0:791a779d6220 73 /*
shoaib_ahmed 0:791a779d6220 74 * Initialize for a processing pass.
shoaib_ahmed 0:791a779d6220 75 */
shoaib_ahmed 0:791a779d6220 76
shoaib_ahmed 0:791a779d6220 77 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 78 start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
shoaib_ahmed 0:791a779d6220 79 {
shoaib_ahmed 0:791a779d6220 80 my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
shoaib_ahmed 0:791a779d6220 81
shoaib_ahmed 0:791a779d6220 82 if (pass_mode != JBUF_PASS_THRU)
shoaib_ahmed 0:791a779d6220 83 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
shoaib_ahmed 0:791a779d6220 84
shoaib_ahmed 0:791a779d6220 85 /* Initialize total-height counter for detecting bottom of image */
shoaib_ahmed 0:791a779d6220 86 prep->rows_to_go = cinfo->image_height;
shoaib_ahmed 0:791a779d6220 87 /* Mark the conversion buffer empty */
shoaib_ahmed 0:791a779d6220 88 prep->next_buf_row = 0;
shoaib_ahmed 0:791a779d6220 89 #ifdef CONTEXT_ROWS_SUPPORTED
shoaib_ahmed 0:791a779d6220 90 /* Preset additional state variables for context mode.
shoaib_ahmed 0:791a779d6220 91 * These aren't used in non-context mode, so we needn't test which mode.
shoaib_ahmed 0:791a779d6220 92 */
shoaib_ahmed 0:791a779d6220 93 prep->this_row_group = 0;
shoaib_ahmed 0:791a779d6220 94 /* Set next_buf_stop to stop after two row groups have been read in. */
shoaib_ahmed 0:791a779d6220 95 prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
shoaib_ahmed 0:791a779d6220 96 #endif
shoaib_ahmed 0:791a779d6220 97 }
shoaib_ahmed 0:791a779d6220 98
shoaib_ahmed 0:791a779d6220 99
shoaib_ahmed 0:791a779d6220 100 /*
shoaib_ahmed 0:791a779d6220 101 * Expand an image vertically from height input_rows to height output_rows,
shoaib_ahmed 0:791a779d6220 102 * by duplicating the bottom row.
shoaib_ahmed 0:791a779d6220 103 */
shoaib_ahmed 0:791a779d6220 104
shoaib_ahmed 0:791a779d6220 105 LOCAL(void)
shoaib_ahmed 0:791a779d6220 106 expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
shoaib_ahmed 0:791a779d6220 107 int input_rows, int output_rows)
shoaib_ahmed 0:791a779d6220 108 {
shoaib_ahmed 0:791a779d6220 109 register int row;
shoaib_ahmed 0:791a779d6220 110
shoaib_ahmed 0:791a779d6220 111 for (row = input_rows; row < output_rows; row++) {
shoaib_ahmed 0:791a779d6220 112 jcopy_sample_rows(image_data, input_rows-1, image_data, row,
shoaib_ahmed 0:791a779d6220 113 1, num_cols);
shoaib_ahmed 0:791a779d6220 114 }
shoaib_ahmed 0:791a779d6220 115 }
shoaib_ahmed 0:791a779d6220 116
shoaib_ahmed 0:791a779d6220 117
shoaib_ahmed 0:791a779d6220 118 /*
shoaib_ahmed 0:791a779d6220 119 * Process some data in the simple no-context case.
shoaib_ahmed 0:791a779d6220 120 *
shoaib_ahmed 0:791a779d6220 121 * Preprocessor output data is counted in "row groups". A row group
shoaib_ahmed 0:791a779d6220 122 * is defined to be v_samp_factor sample rows of each component.
shoaib_ahmed 0:791a779d6220 123 * Downsampling will produce this much data from each max_v_samp_factor
shoaib_ahmed 0:791a779d6220 124 * input rows.
shoaib_ahmed 0:791a779d6220 125 */
shoaib_ahmed 0:791a779d6220 126
shoaib_ahmed 0:791a779d6220 127 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 128 pre_process_data (j_compress_ptr cinfo,
shoaib_ahmed 0:791a779d6220 129 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
shoaib_ahmed 0:791a779d6220 130 JDIMENSION in_rows_avail,
shoaib_ahmed 0:791a779d6220 131 JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
shoaib_ahmed 0:791a779d6220 132 JDIMENSION out_row_groups_avail)
shoaib_ahmed 0:791a779d6220 133 {
shoaib_ahmed 0:791a779d6220 134 my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
shoaib_ahmed 0:791a779d6220 135 int numrows, ci;
shoaib_ahmed 0:791a779d6220 136 JDIMENSION inrows;
shoaib_ahmed 0:791a779d6220 137 jpeg_component_info * compptr;
shoaib_ahmed 0:791a779d6220 138
shoaib_ahmed 0:791a779d6220 139 while (*in_row_ctr < in_rows_avail &&
shoaib_ahmed 0:791a779d6220 140 *out_row_group_ctr < out_row_groups_avail) {
shoaib_ahmed 0:791a779d6220 141 /* Do color conversion to fill the conversion buffer. */
shoaib_ahmed 0:791a779d6220 142 inrows = in_rows_avail - *in_row_ctr;
shoaib_ahmed 0:791a779d6220 143 numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
shoaib_ahmed 0:791a779d6220 144 numrows = (int) MIN((JDIMENSION) numrows, inrows);
shoaib_ahmed 0:791a779d6220 145 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
shoaib_ahmed 0:791a779d6220 146 prep->color_buf,
shoaib_ahmed 0:791a779d6220 147 (JDIMENSION) prep->next_buf_row,
shoaib_ahmed 0:791a779d6220 148 numrows);
shoaib_ahmed 0:791a779d6220 149 *in_row_ctr += numrows;
shoaib_ahmed 0:791a779d6220 150 prep->next_buf_row += numrows;
shoaib_ahmed 0:791a779d6220 151 prep->rows_to_go -= numrows;
shoaib_ahmed 0:791a779d6220 152 /* If at bottom of image, pad to fill the conversion buffer. */
shoaib_ahmed 0:791a779d6220 153 if (prep->rows_to_go == 0 &&
shoaib_ahmed 0:791a779d6220 154 prep->next_buf_row < cinfo->max_v_samp_factor) {
shoaib_ahmed 0:791a779d6220 155 for (ci = 0; ci < cinfo->num_components; ci++) {
shoaib_ahmed 0:791a779d6220 156 expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
shoaib_ahmed 0:791a779d6220 157 prep->next_buf_row, cinfo->max_v_samp_factor);
shoaib_ahmed 0:791a779d6220 158 }
shoaib_ahmed 0:791a779d6220 159 prep->next_buf_row = cinfo->max_v_samp_factor;
shoaib_ahmed 0:791a779d6220 160 }
shoaib_ahmed 0:791a779d6220 161 /* If we've filled the conversion buffer, empty it. */
shoaib_ahmed 0:791a779d6220 162 if (prep->next_buf_row == cinfo->max_v_samp_factor) {
shoaib_ahmed 0:791a779d6220 163 (*cinfo->downsample->downsample) (cinfo,
shoaib_ahmed 0:791a779d6220 164 prep->color_buf, (JDIMENSION) 0,
shoaib_ahmed 0:791a779d6220 165 output_buf, *out_row_group_ctr);
shoaib_ahmed 0:791a779d6220 166 prep->next_buf_row = 0;
shoaib_ahmed 0:791a779d6220 167 (*out_row_group_ctr)++;
shoaib_ahmed 0:791a779d6220 168 }
shoaib_ahmed 0:791a779d6220 169 /* If at bottom of image, pad the output to a full iMCU height.
shoaib_ahmed 0:791a779d6220 170 * Note we assume the caller is providing a one-iMCU-height output buffer!
shoaib_ahmed 0:791a779d6220 171 */
shoaib_ahmed 0:791a779d6220 172 if (prep->rows_to_go == 0 &&
shoaib_ahmed 0:791a779d6220 173 *out_row_group_ctr < out_row_groups_avail) {
shoaib_ahmed 0:791a779d6220 174 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 175 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 176 numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
shoaib_ahmed 0:791a779d6220 177 cinfo->min_DCT_v_scaled_size;
shoaib_ahmed 0:791a779d6220 178 expand_bottom_edge(output_buf[ci],
shoaib_ahmed 0:791a779d6220 179 compptr->width_in_blocks * compptr->DCT_h_scaled_size,
shoaib_ahmed 0:791a779d6220 180 (int) (*out_row_group_ctr * numrows),
shoaib_ahmed 0:791a779d6220 181 (int) (out_row_groups_avail * numrows));
shoaib_ahmed 0:791a779d6220 182 }
shoaib_ahmed 0:791a779d6220 183 *out_row_group_ctr = out_row_groups_avail;
shoaib_ahmed 0:791a779d6220 184 break; /* can exit outer loop without test */
shoaib_ahmed 0:791a779d6220 185 }
shoaib_ahmed 0:791a779d6220 186 }
shoaib_ahmed 0:791a779d6220 187 }
shoaib_ahmed 0:791a779d6220 188
shoaib_ahmed 0:791a779d6220 189
shoaib_ahmed 0:791a779d6220 190 #ifdef CONTEXT_ROWS_SUPPORTED
shoaib_ahmed 0:791a779d6220 191
shoaib_ahmed 0:791a779d6220 192 /*
shoaib_ahmed 0:791a779d6220 193 * Process some data in the context case.
shoaib_ahmed 0:791a779d6220 194 */
shoaib_ahmed 0:791a779d6220 195
shoaib_ahmed 0:791a779d6220 196 METHODDEF(void)
shoaib_ahmed 0:791a779d6220 197 pre_process_context (j_compress_ptr cinfo,
shoaib_ahmed 0:791a779d6220 198 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
shoaib_ahmed 0:791a779d6220 199 JDIMENSION in_rows_avail,
shoaib_ahmed 0:791a779d6220 200 JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
shoaib_ahmed 0:791a779d6220 201 JDIMENSION out_row_groups_avail)
shoaib_ahmed 0:791a779d6220 202 {
shoaib_ahmed 0:791a779d6220 203 my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
shoaib_ahmed 0:791a779d6220 204 int numrows, ci;
shoaib_ahmed 0:791a779d6220 205 int buf_height = cinfo->max_v_samp_factor * 3;
shoaib_ahmed 0:791a779d6220 206 JDIMENSION inrows;
shoaib_ahmed 0:791a779d6220 207
shoaib_ahmed 0:791a779d6220 208 while (*out_row_group_ctr < out_row_groups_avail) {
shoaib_ahmed 0:791a779d6220 209 if (*in_row_ctr < in_rows_avail) {
shoaib_ahmed 0:791a779d6220 210 /* Do color conversion to fill the conversion buffer. */
shoaib_ahmed 0:791a779d6220 211 inrows = in_rows_avail - *in_row_ctr;
shoaib_ahmed 0:791a779d6220 212 numrows = prep->next_buf_stop - prep->next_buf_row;
shoaib_ahmed 0:791a779d6220 213 numrows = (int) MIN((JDIMENSION) numrows, inrows);
shoaib_ahmed 0:791a779d6220 214 (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
shoaib_ahmed 0:791a779d6220 215 prep->color_buf,
shoaib_ahmed 0:791a779d6220 216 (JDIMENSION) prep->next_buf_row,
shoaib_ahmed 0:791a779d6220 217 numrows);
shoaib_ahmed 0:791a779d6220 218 /* Pad at top of image, if first time through */
shoaib_ahmed 0:791a779d6220 219 if (prep->rows_to_go == cinfo->image_height) {
shoaib_ahmed 0:791a779d6220 220 for (ci = 0; ci < cinfo->num_components; ci++) {
shoaib_ahmed 0:791a779d6220 221 int row;
shoaib_ahmed 0:791a779d6220 222 for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
shoaib_ahmed 0:791a779d6220 223 jcopy_sample_rows(prep->color_buf[ci], 0,
shoaib_ahmed 0:791a779d6220 224 prep->color_buf[ci], -row,
shoaib_ahmed 0:791a779d6220 225 1, cinfo->image_width);
shoaib_ahmed 0:791a779d6220 226 }
shoaib_ahmed 0:791a779d6220 227 }
shoaib_ahmed 0:791a779d6220 228 }
shoaib_ahmed 0:791a779d6220 229 *in_row_ctr += numrows;
shoaib_ahmed 0:791a779d6220 230 prep->next_buf_row += numrows;
shoaib_ahmed 0:791a779d6220 231 prep->rows_to_go -= numrows;
shoaib_ahmed 0:791a779d6220 232 } else {
shoaib_ahmed 0:791a779d6220 233 /* Return for more data, unless we are at the bottom of the image. */
shoaib_ahmed 0:791a779d6220 234 if (prep->rows_to_go != 0)
shoaib_ahmed 0:791a779d6220 235 break;
shoaib_ahmed 0:791a779d6220 236 /* When at bottom of image, pad to fill the conversion buffer. */
shoaib_ahmed 0:791a779d6220 237 if (prep->next_buf_row < prep->next_buf_stop) {
shoaib_ahmed 0:791a779d6220 238 for (ci = 0; ci < cinfo->num_components; ci++) {
shoaib_ahmed 0:791a779d6220 239 expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
shoaib_ahmed 0:791a779d6220 240 prep->next_buf_row, prep->next_buf_stop);
shoaib_ahmed 0:791a779d6220 241 }
shoaib_ahmed 0:791a779d6220 242 prep->next_buf_row = prep->next_buf_stop;
shoaib_ahmed 0:791a779d6220 243 }
shoaib_ahmed 0:791a779d6220 244 }
shoaib_ahmed 0:791a779d6220 245 /* If we've gotten enough data, downsample a row group. */
shoaib_ahmed 0:791a779d6220 246 if (prep->next_buf_row == prep->next_buf_stop) {
shoaib_ahmed 0:791a779d6220 247 (*cinfo->downsample->downsample) (cinfo,
shoaib_ahmed 0:791a779d6220 248 prep->color_buf,
shoaib_ahmed 0:791a779d6220 249 (JDIMENSION) prep->this_row_group,
shoaib_ahmed 0:791a779d6220 250 output_buf, *out_row_group_ctr);
shoaib_ahmed 0:791a779d6220 251 (*out_row_group_ctr)++;
shoaib_ahmed 0:791a779d6220 252 /* Advance pointers with wraparound as necessary. */
shoaib_ahmed 0:791a779d6220 253 prep->this_row_group += cinfo->max_v_samp_factor;
shoaib_ahmed 0:791a779d6220 254 if (prep->this_row_group >= buf_height)
shoaib_ahmed 0:791a779d6220 255 prep->this_row_group = 0;
shoaib_ahmed 0:791a779d6220 256 if (prep->next_buf_row >= buf_height)
shoaib_ahmed 0:791a779d6220 257 prep->next_buf_row = 0;
shoaib_ahmed 0:791a779d6220 258 prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
shoaib_ahmed 0:791a779d6220 259 }
shoaib_ahmed 0:791a779d6220 260 }
shoaib_ahmed 0:791a779d6220 261 }
shoaib_ahmed 0:791a779d6220 262
shoaib_ahmed 0:791a779d6220 263
shoaib_ahmed 0:791a779d6220 264 /*
shoaib_ahmed 0:791a779d6220 265 * Create the wrapped-around downsampling input buffer needed for context mode.
shoaib_ahmed 0:791a779d6220 266 */
shoaib_ahmed 0:791a779d6220 267
shoaib_ahmed 0:791a779d6220 268 LOCAL(void)
shoaib_ahmed 0:791a779d6220 269 create_context_buffer (j_compress_ptr cinfo)
shoaib_ahmed 0:791a779d6220 270 {
shoaib_ahmed 0:791a779d6220 271 my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
shoaib_ahmed 0:791a779d6220 272 int rgroup_height = cinfo->max_v_samp_factor;
shoaib_ahmed 0:791a779d6220 273 int ci, i;
shoaib_ahmed 0:791a779d6220 274 jpeg_component_info * compptr;
shoaib_ahmed 0:791a779d6220 275 JSAMPARRAY true_buffer, fake_buffer;
shoaib_ahmed 0:791a779d6220 276
shoaib_ahmed 0:791a779d6220 277 /* Grab enough space for fake row pointers for all the components;
shoaib_ahmed 0:791a779d6220 278 * we need five row groups' worth of pointers for each component.
shoaib_ahmed 0:791a779d6220 279 */
shoaib_ahmed 0:791a779d6220 280 fake_buffer = (JSAMPARRAY)
shoaib_ahmed 0:791a779d6220 281 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 282 (cinfo->num_components * 5 * rgroup_height) *
shoaib_ahmed 0:791a779d6220 283 SIZEOF(JSAMPROW));
shoaib_ahmed 0:791a779d6220 284
shoaib_ahmed 0:791a779d6220 285 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 286 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 287 /* Allocate the actual buffer space (3 row groups) for this component.
shoaib_ahmed 0:791a779d6220 288 * We make the buffer wide enough to allow the downsampler to edge-expand
shoaib_ahmed 0:791a779d6220 289 * horizontally within the buffer, if it so chooses.
shoaib_ahmed 0:791a779d6220 290 */
shoaib_ahmed 0:791a779d6220 291 true_buffer = (*cinfo->mem->alloc_sarray)
shoaib_ahmed 0:791a779d6220 292 ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 293 (JDIMENSION) (((long) compptr->width_in_blocks *
shoaib_ahmed 0:791a779d6220 294 cinfo->min_DCT_h_scaled_size *
shoaib_ahmed 0:791a779d6220 295 cinfo->max_h_samp_factor) / compptr->h_samp_factor),
shoaib_ahmed 0:791a779d6220 296 (JDIMENSION) (3 * rgroup_height));
shoaib_ahmed 0:791a779d6220 297 /* Copy true buffer row pointers into the middle of the fake row array */
shoaib_ahmed 0:791a779d6220 298 MEMCOPY(fake_buffer + rgroup_height, true_buffer,
shoaib_ahmed 0:791a779d6220 299 3 * rgroup_height * SIZEOF(JSAMPROW));
shoaib_ahmed 0:791a779d6220 300 /* Fill in the above and below wraparound pointers */
shoaib_ahmed 0:791a779d6220 301 for (i = 0; i < rgroup_height; i++) {
shoaib_ahmed 0:791a779d6220 302 fake_buffer[i] = true_buffer[2 * rgroup_height + i];
shoaib_ahmed 0:791a779d6220 303 fake_buffer[4 * rgroup_height + i] = true_buffer[i];
shoaib_ahmed 0:791a779d6220 304 }
shoaib_ahmed 0:791a779d6220 305 prep->color_buf[ci] = fake_buffer + rgroup_height;
shoaib_ahmed 0:791a779d6220 306 fake_buffer += 5 * rgroup_height; /* point to space for next component */
shoaib_ahmed 0:791a779d6220 307 }
shoaib_ahmed 0:791a779d6220 308 }
shoaib_ahmed 0:791a779d6220 309
shoaib_ahmed 0:791a779d6220 310 #endif /* CONTEXT_ROWS_SUPPORTED */
shoaib_ahmed 0:791a779d6220 311
shoaib_ahmed 0:791a779d6220 312
shoaib_ahmed 0:791a779d6220 313 /*
shoaib_ahmed 0:791a779d6220 314 * Initialize preprocessing controller.
shoaib_ahmed 0:791a779d6220 315 */
shoaib_ahmed 0:791a779d6220 316
shoaib_ahmed 0:791a779d6220 317 GLOBAL(void)
shoaib_ahmed 0:791a779d6220 318 jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
shoaib_ahmed 0:791a779d6220 319 {
shoaib_ahmed 0:791a779d6220 320 my_prep_ptr prep;
shoaib_ahmed 0:791a779d6220 321 int ci;
shoaib_ahmed 0:791a779d6220 322 jpeg_component_info * compptr;
shoaib_ahmed 0:791a779d6220 323
shoaib_ahmed 0:791a779d6220 324 if (need_full_buffer) /* safety check */
shoaib_ahmed 0:791a779d6220 325 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
shoaib_ahmed 0:791a779d6220 326
shoaib_ahmed 0:791a779d6220 327 prep = (my_prep_ptr)
shoaib_ahmed 0:791a779d6220 328 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 329 SIZEOF(my_prep_controller));
shoaib_ahmed 0:791a779d6220 330 cinfo->prep = (struct jpeg_c_prep_controller *) prep;
shoaib_ahmed 0:791a779d6220 331 prep->pub.start_pass = start_pass_prep;
shoaib_ahmed 0:791a779d6220 332
shoaib_ahmed 0:791a779d6220 333 /* Allocate the color conversion buffer.
shoaib_ahmed 0:791a779d6220 334 * We make the buffer wide enough to allow the downsampler to edge-expand
shoaib_ahmed 0:791a779d6220 335 * horizontally within the buffer, if it so chooses.
shoaib_ahmed 0:791a779d6220 336 */
shoaib_ahmed 0:791a779d6220 337 if (cinfo->downsample->need_context_rows) {
shoaib_ahmed 0:791a779d6220 338 /* Set up to provide context rows */
shoaib_ahmed 0:791a779d6220 339 #ifdef CONTEXT_ROWS_SUPPORTED
shoaib_ahmed 0:791a779d6220 340 prep->pub.pre_process_data = pre_process_context;
shoaib_ahmed 0:791a779d6220 341 create_context_buffer(cinfo);
shoaib_ahmed 0:791a779d6220 342 #else
shoaib_ahmed 0:791a779d6220 343 ERREXIT(cinfo, JERR_NOT_COMPILED);
shoaib_ahmed 0:791a779d6220 344 #endif
shoaib_ahmed 0:791a779d6220 345 } else {
shoaib_ahmed 0:791a779d6220 346 /* No context, just make it tall enough for one row group */
shoaib_ahmed 0:791a779d6220 347 prep->pub.pre_process_data = pre_process_data;
shoaib_ahmed 0:791a779d6220 348 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
shoaib_ahmed 0:791a779d6220 349 ci++, compptr++) {
shoaib_ahmed 0:791a779d6220 350 prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
shoaib_ahmed 0:791a779d6220 351 ((j_common_ptr) cinfo, JPOOL_IMAGE,
shoaib_ahmed 0:791a779d6220 352 (JDIMENSION) (((long) compptr->width_in_blocks *
shoaib_ahmed 0:791a779d6220 353 cinfo->min_DCT_h_scaled_size *
shoaib_ahmed 0:791a779d6220 354 cinfo->max_h_samp_factor) / compptr->h_samp_factor),
shoaib_ahmed 0:791a779d6220 355 (JDIMENSION) cinfo->max_v_samp_factor);
shoaib_ahmed 0:791a779d6220 356 }
shoaib_ahmed 0:791a779d6220 357 }
shoaib_ahmed 0:791a779d6220 358 }