GLOBAL(void)
jpeg_calc_output_dimensions(j_decompress_ptr cinfo) /* Do computations that are needed before master selection phase */
{ #ifdef IDCT_SCALING_SUPPORTED int ci;
jpeg_component_info *compptr; #endif
/* Prevent application from calling me at wrong times */ if (cinfo->global_state != DSTATE_READY)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (!cinfo->master->lossless) { /* In selecting the actual DCT scaling for each component, we try to *scaleupthechromacomponentsviaIDCTscalingratherthanupsampling. *Thissavestimeiftheupsamplergetstouse1:1scaling. *Notethiscodeadaptssubsamplingratioswhicharepowersof2.
*/ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { int ssize = cinfo->_min_DCT_scaled_size; while (ssize < DCTSIZE &&
((cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->h_samp_factor * ssize * 2) == 0) &&
((cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size) %
(compptr->v_samp_factor * ssize * 2) == 0)) {
ssize = ssize * 2;
} #if JPEG_LIB_VERSION >= 70
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; #else
compptr->DCT_scaled_size = ssize; #endif
}
/* Recompute downsampled dimensions of components; *applicationneedstoknowtheseifusingrawdownsampleddata.
*/ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { /* Size in samples, after IDCT scaling */
compptr->downsampled_width = (JDIMENSION)
jdiv_round_up((long)cinfo->image_width *
(long)(compptr->h_samp_factor *
compptr->_DCT_scaled_size),
(long)(cinfo->max_h_samp_factor * DCTSIZE));
compptr->downsampled_height = (JDIMENSION)
jdiv_round_up((long)cinfo->image_height *
(long)(compptr->v_samp_factor *
compptr->_DCT_scaled_size),
(long)(cinfo->max_v_samp_factor * DCTSIZE));
}
} else #endif/* IDCT_SCALING_SUPPORTED */
{ /* Hardwire it to "no scaling" */
cinfo->output_width = cinfo->image_width;
cinfo->output_height = cinfo->image_height; /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE, *andhascomputedunscaleddownsampled_widthanddownsampled_height.
*/
}
/* Report number of components in selected colorspace. */ /* Probably this should be in the color conversion module... */ switch (cinfo->out_color_space) { case JCS_GRAYSCALE:
cinfo->out_color_components = 1; break; case JCS_RGB: case JCS_EXT_RGB: case JCS_EXT_RGBX: case JCS_EXT_BGR: case JCS_EXT_BGRX: case JCS_EXT_XBGR: case JCS_EXT_XRGB: case JCS_EXT_RGBA: case JCS_EXT_BGRA: case JCS_EXT_ABGR: case JCS_EXT_ARGB:
cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space]; break; case JCS_YCbCr: case JCS_RGB565:
cinfo->out_color_components = 3; break; case JCS_CMYK: case JCS_YCCK:
cinfo->out_color_components = 4; break; default: /* else must be same colorspace as in file */
cinfo->out_color_components = cinfo->num_components; break;
}
cinfo->output_components = (cinfo->quantize_colors ? 1 :
cinfo->out_color_components);
/* See if upsampler will want to emit more than one row at a time */ if (use_merged_upsample(cinfo))
cinfo->rec_outbuf_height = cinfo->max_v_samp_factor; else
cinfo->rec_outbuf_height = 1;
}
LOCAL(void)
prepare_range_limit_table(j_decompress_ptr cinfo) /* Allocate and fill in the sample_range_limit table */
{
JSAMPLE *table;
J12SAMPLE *table12; #ifdef D_LOSSLESS_SUPPORTED
J16SAMPLE *table16; #endif int i;
if (cinfo->data_precision <= 8) {
table = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE));
table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */
cinfo->sample_range_limit = table; /* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE)); /* Main part of "simple" table: limit[x] = x */ for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE)i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ /* End of simple table, rest of first half of post-IDCT table */ for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++)
table[i] = MAXJSAMPLE; /* Second half of post-IDCT table */
memset(table + (2 * (MAXJSAMPLE + 1)), 0,
(2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE));
memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE),
cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE));
} elseif (cinfo->data_precision <= 12) {
table12 = (J12SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple
table */
cinfo->sample_range_limit = (JSAMPLE *)table12; /* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table12 - (MAXJ12SAMPLE + 1), 0,
(MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE)); /* Main part of "simple" table: limit[x] = x */ for (i = 0; i <= MAXJ12SAMPLE; i++)
table12[i] = (J12SAMPLE)i;
table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */ /* End of simple table, rest of first half of post-IDCT table */ for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++)
table12[i] = MAXJ12SAMPLE; /* Second half of post-IDCT table */
memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0,
(2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE));
memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE),
cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE));
} else { #ifdef D_LOSSLESS_SUPPORTED
table16 = (J16SAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
(5 * (MAXJ16SAMPLE + 1) + CENTERJ16SAMPLE) * sizeof(J16SAMPLE));
table16 += (MAXJ16SAMPLE + 1); /* allow negative subscripts of simple
table */
cinfo->sample_range_limit = (JSAMPLE *)table16; /* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset(table16 - (MAXJ16SAMPLE + 1), 0,
(MAXJ16SAMPLE + 1) * sizeof(J16SAMPLE)); /* Main part of "simple" table: limit[x] = x */ for (i = 0; i <= MAXJ16SAMPLE; i++)
table16[i] = (J16SAMPLE)i;
table16 += CENTERJ16SAMPLE; /* Point to where post-IDCT table starts */ /* End of simple table, rest of first half of post-IDCT table */ for (i = CENTERJ16SAMPLE; i < 2 * (MAXJ16SAMPLE + 1); i++)
table16[i] = MAXJ16SAMPLE; /* Second half of post-IDCT table */
memset(table16 + (2 * (MAXJ16SAMPLE + 1)), 0,
(2 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE) * sizeof(J16SAMPLE));
memcpy(table16 + (4 * (MAXJ16SAMPLE + 1) - CENTERJ16SAMPLE),
cinfo->sample_range_limit, CENTERJ16SAMPLE * sizeof(J16SAMPLE)); #else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif
}
}
/* Disable IDCT scaling and raw (downsampled) data output in lossless mode. *IDCTscalingisnotusefulinlosslessmode,anditmustbedisabledin *ordertoproperlycalculatetheoutputdimensions.Rawdataoutputisn't *particularlyusefulwithoutsubsamplingandhasnotbeentestedin *losslessmode.
*/ #ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless) {
cinfo->raw_data_out = FALSE;
cinfo->scale_num = cinfo->scale_denom = 1;
} #endif
/* Initialize dimensions and other stuff */
jpeg_calc_output_dimensions(cinfo);
prepare_range_limit_table(cinfo);
/* Width of an output scanline must be representable as JDIMENSION. */
samplesperrow = (long)cinfo->output_width *
(long)cinfo->out_color_components;
jd_samplesperrow = (JDIMENSION)samplesperrow; if ((long)jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* Initialize my private state */
master->pass_number = 0;
master->using_merged_upsample = use_merged_upsample(cinfo);
/* Color quantizer selection */
master->quantizer_1pass = NULL;
master->quantizer_2pass = NULL; /* No mode changes if not using buffered-image mode. */ if (!cinfo->quantize_colors || !cinfo->buffered_image) {
cinfo->enable_1pass_quant = FALSE;
cinfo->enable_external_quant = FALSE;
cinfo->enable_2pass_quant = FALSE;
} if (cinfo->quantize_colors) { if (cinfo->raw_data_out)
ERREXIT(cinfo, JERR_NOTIMPL); /* 2-pass quantizer only works in 3-component color space. */ if (cinfo->out_color_components != 3 ||
cinfo->out_color_space == JCS_RGB565) {
cinfo->enable_1pass_quant = TRUE;
cinfo->enable_external_quant = FALSE;
cinfo->enable_2pass_quant = FALSE;
cinfo->colormap = NULL;
} elseif (cinfo->colormap != NULL) {
cinfo->enable_external_quant = TRUE;
} elseif (cinfo->two_pass_quantize) {
cinfo->enable_2pass_quant = TRUE;
} else {
cinfo->enable_1pass_quant = TRUE;
}
/* We use the 2-pass code to map to external colormaps. */ if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { #ifdef QUANT_2PASS_SUPPORTED if (cinfo->data_precision == 8)
jinit_2pass_quantizer(cinfo); elseif (cinfo->data_precision == 12)
j12init_2pass_quantizer(cinfo); else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
master->quantizer_2pass = cinfo->cquantize; #else
ERREXIT(cinfo, JERR_NOT_COMPILED); #endif
} /* If both quantizers are initialized, the 2-pass one is left active; *thisisnecessaryforstartingwithquantizationtoanexternalmap.
*/
}
/* Post-processing: in particular, color conversion first */ if (!cinfo->raw_data_out) { if (master->using_merged_upsample) { #ifdef UPSAMPLE_MERGING_SUPPORTED if (cinfo->data_precision == 8)
jinit_merged_upsampler(cinfo); /* does color conversion too */ elseif (cinfo->data_precision == 12)
j12init_merged_upsampler(cinfo); /* does color conversion too */ else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #else
ERREXIT(cinfo, JERR_NOT_COMPILED); #endif
} else { if (cinfo->data_precision <= 8) {
jinit_color_deconverter(cinfo);
jinit_upsampler(cinfo);
} elseif (cinfo->data_precision <= 12) {
j12init_color_deconverter(cinfo);
j12init_upsampler(cinfo);
} else { #ifdef D_LOSSLESS_SUPPORTED
j16init_color_deconverter(cinfo);
j16init_upsampler(cinfo); #else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif
}
} if (cinfo->data_precision <= 8)
jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); elseif (cinfo->data_precision <= 12)
j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant); else #ifdef D_LOSSLESS_SUPPORTED
j16init_d_post_controller(cinfo, cinfo->enable_2pass_quant); #else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif
}
if (cinfo->master->lossless) { #ifdef D_LOSSLESS_SUPPORTED /* Prediction, sample undifferencing, point transform, and sample size *scaling
*/ if (cinfo->data_precision <= 8)
jinit_lossless_decompressor(cinfo); elseif (cinfo->data_precision <= 12)
j12init_lossless_decompressor(cinfo); else
j16init_lossless_decompressor(cinfo); /* Entropy decoding: either Huffman or arithmetic coding. */ if (cinfo->arith_code) {
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
} else {
jinit_lhuff_decoder(cinfo);
}
if (!cinfo->raw_data_out) { if (cinfo->data_precision <= 8)
jinit_d_main_controller(cinfo, FALSE/* never need full buffer here */); elseif (cinfo->data_precision <= 12)
j12init_d_main_controller(cinfo, FALSE/* never need full buffer here */); else #ifdef D_LOSSLESS_SUPPORTED
j16init_d_main_controller(cinfo, FALSE/* never need full buffer here */); #else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif
}
/* We can now tell the memory manager to allocate virtual arrays. */
(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
/* Initialize input side of decompressor to consume first scan. */
(*cinfo->inputctl->start_input_pass) (cinfo);
/* Set the first and last iMCU columns to decompress from single-scan images. *Bydefault,decompressalloftheiMCUcolumns.
*/
cinfo->master->first_iMCU_col = 0;
cinfo->master->last_iMCU_col = cinfo->MCUs_per_row - 1;
cinfo->master->last_good_iMCU_row = 0;
#ifdef D_MULTISCAN_FILES_SUPPORTED /* If jpeg_start_decompress will read the whole file, initialize *progressmonitoringappropriately.Theinputstepiscounted *asonepass.
*/ if (cinfo->progress != NULL && !cinfo->buffered_image &&
cinfo->inputctl->has_multiple_scans) { int nscans; /* Estimate number of scans to set pass_limit. */ if (cinfo->progressive_mode) { /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
nscans = 2 + 3 * cinfo->num_components;
} else { /* For a nonprogressive multiscan file, estimate 1 scan per component. */
nscans = cinfo->num_components;
}
cinfo->progress->pass_counter = 0L;
cinfo->progress->pass_limit = (long)cinfo->total_iMCU_rows * nscans;
cinfo->progress->completed_passes = 0;
cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2); /* Count the input pass as done */
master->pass_number++;
} #endif/* D_MULTISCAN_FILES_SUPPORTED */
}
/* Set up progress monitor's pass info if present */ if (cinfo->progress != NULL) {
cinfo->progress->completed_passes = master->pass_number;
cinfo->progress->total_passes = master->pass_number +
(master->pub.is_dummy_pass ? 2 : 1); /* In buffered-image mode, we assume one more output pass if EOI not *yetreached,butnomorepassesifEOIhasbeenreached.
*/ if (cinfo->buffered_image && !cinfo->inputctl->eoi_reached) {
cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
}
}
}
/* Prevent application from calling me at wrong times */ if (cinfo->global_state != DSTATE_BUFIMAGE)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (cinfo->quantize_colors && cinfo->enable_external_quant &&
cinfo->colormap != NULL) { /* Select 2-pass quantizer for external colormap use */
cinfo->cquantize = master->quantizer_2pass; /* Notify quantizer of colormap change */
(*cinfo->cquantize->new_color_map) (cinfo);
master->pub.is_dummy_pass = FALSE; /* just in case */
} else
ERREXIT(cinfo, JERR_MODE_CHANGE);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.