GLOBAL(boolean)
jpeg_start_decompress(j_decompress_ptr cinfo)
{ if (cinfo->global_state == DSTATE_READY) { /* First call: initialize master control, select active modules */
jinit_master_decompress(cinfo); if (cinfo->buffered_image) { /* No more work here; expecting jpeg_start_output next */
cinfo->global_state = DSTATE_BUFIMAGE; return TRUE;
}
cinfo->global_state = DSTATE_PRELOAD;
} if (cinfo->global_state == DSTATE_PRELOAD) { /* If file has multiple scans, absorb them all into the coef buffer */ if (cinfo->inputctl->has_multiple_scans) { #ifdef D_MULTISCAN_FILES_SUPPORTED for (;;) { int retcode; /* Call progress monitor hook if present */ if (cinfo->progress != NULL)
(*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); /* Absorb some more input */
retcode = (*cinfo->inputctl->consume_input) (cinfo); if (retcode == JPEG_SUSPENDED) returnFALSE; if (retcode == JPEG_REACHED_EOI) break; /* Advance progress counter if appropriate */ if (cinfo->progress != NULL &&
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { /* jdmaster underestimated number of scans; ratchet up one scan */
cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
}
}
} #else
ERREXIT(cinfo, JERR_NOT_COMPILED); #endif/* D_MULTISCAN_FILES_SUPPORTED */
}
cinfo->output_scan_number = cinfo->input_scan_number;
} elseif (cinfo->global_state != DSTATE_PRESCAN)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Perform any dummy output passes, and set up for the final pass */ return output_pass_setup(cinfo);
}
if (!xoffset || !width)
ERREXIT(cinfo, JERR_BAD_CROP_SPEC);
/* xoffset and width must fall within the output image dimensions. */ if (*width == 0 ||
(unsignedlonglong)(*xoffset) + *width > cinfo->output_width)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* No need to do anything if the caller wants the entire width. */ if (*width == cinfo->output_width) return;
/* Ensuring the proper alignment of xoffset is tricky. At minimum, it *mustalignwithanMCUboundary,because: * *(1)TheIDCTisperformedinblocks,anditisnotfeasibletomodify *thealgorithmsothatitcantransformpartialblocks. *(2)BecauseoftheSIMDextensions,anyinputbufferpassedtothe *upsamplingandcolorconversionroutinesmustbealignedtothe *SIMDwordsize(forinstance,128-bitinthecaseofSSE2.)The *easiestwaytoaccomplishthiswithoutcopyingdataistoensure *thatupsamplingandcolorconversionbeginatthestartofthe *firstMCUcolumnthatwillbeinversetransformed. * *Inpractice,weactuallyimposeastricteralignmentrequirement.We *requirethatxoffsetbeamultipleofthemaximumMCUcolumnwidthofall *ofthecomponents(the"iMCUcolumnwidth.")Thisistosimplifythe *single-passdecompressioncase,allowingustousethesameMCUcolumn *widthforallofthecomponents.
*/ if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
align = cinfo->_min_DCT_scaled_size; else
align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor;
/* Adjust xoffset to the nearest iMCU boundary <= the requested value */
input_xoffset = *xoffset;
*xoffset = (input_xoffset / align) * align;
/* Adjust the width so that the right edge of the output image is as *requested(onlytheleftedgeisaltered.)Itisimportantthatcalling *programscheckthisvalueafterthisfunctionreturns,sothattheycan *allocateanoutputbufferwiththeappropriatesize.
*/
*width = *width + input_xoffset - *xoffset;
cinfo->output_width = *width; #ifdef UPSAMPLE_MERGING_SUPPORTED if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
upsample->out_row_width =
cinfo->output_width * cinfo->out_color_components;
} #endif
/* Set the first and last iMCU columns that we must decompress. These values *willbeusedinsingle-scandecompressions.
*/
cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
cinfo->master->last_iMCU_col =
(JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
(long)align) - 1;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ? 1 : compptr->h_samp_factor;
/* Set downsampled_width to the new output width. */
orig_downsampled_width = compptr->downsampled_width;
compptr->downsampled_width =
(JDIMENSION)jdiv_round_up((long)cinfo->output_width *
(long)(compptr->h_samp_factor *
compptr->_DCT_scaled_size),
(long)(cinfo->max_h_samp_factor *
cinfo->_min_DCT_scaled_size)); if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2)
reinit_upsampler = TRUE;
/* Set the first and last iMCU columns that we must decompress. These *valueswillbeusedinmulti-scandecompressions.
*/
cinfo->master->first_MCU_col[ci] =
(JDIMENSION)(long)(*xoffset * hsf) / (long)align;
cinfo->master->last_MCU_col[ci] =
(JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
(long)align) - 1;
}
/* Process some data */
row_ctr = 0; if (cinfo->main->_process_data == NULL)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
cinfo->output_scanline += row_ctr; return row_ctr; #else
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); return0; #endif
}
#if BITS_IN_JSAMPLE != 16
/* Dummy color convert function used by _jpeg_skip_scanlines() */
LOCAL(void)
noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
{
}
/* Dummy quantize function used by _jpeg_skip_scanlines() */
LOCAL(void)
noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows)
{
}
if (cinfo->cconvert && #ifdef UPSAMPLE_MERGING_SUPPORTED
!master->using_merged_upsample && #endif
cinfo->cconvert->_color_convert) {
color_convert = cinfo->cconvert->_color_convert;
cinfo->cconvert->_color_convert = noop_convert; /* This just prevents UBSan from complaining about adding 0 to a NULL *pointer.Thepointerisn'tactuallyused.
*/
scanlines = &dummy_row;
}
/* Increment the counter to the next row group after the skipped rows. */
main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
/* Partially skipping a row group would involve modifying the internal state *oftheupsampler,soreadtheremainingrowsintoadummybufferinstead.
*/
rows_left = rows % cinfo->max_v_samp_factor;
cinfo->output_scanline += rows - rows_left;
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (cinfo->master->lossless)
ERREXIT(cinfo, JERR_NOTIMPL);
/* Two-pass color quantization is not supported. */ if (cinfo->quantize_colors && cinfo->two_pass_quantize)
ERREXIT(cinfo, JERR_NOTIMPL);
if (cinfo->global_state != DSTATE_SCANNING)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Do not skip past the bottom of the image. */ if ((unsignedlonglong)cinfo->output_scanline + num_lines >=
cinfo->output_height) {
num_lines = cinfo->output_height - cinfo->output_scanline;
cinfo->output_scanline = cinfo->output_height;
(*cinfo->inputctl->finish_input_pass) (cinfo);
cinfo->inputctl->eoi_reached = TRUE; return num_lines;
}
/* Skip the lines remaining in the current iMCU row. When upsampling *requirescontextrows,weneedthepreviousandnextrowsinordertoread *thecurrentrow.Thisaddssomecomplexity.
*/ if (cinfo->upsample->need_context_rows) { /* If the skipped lines would not move us past the current iMCU row, we *readthelinesandignorethem.Theremightbeafasterwayofdoing *this,butwearefacingincreasingcomplexityfordiminishingreturns. *Theincreasingcomplexitywouldbeaby-productofmeddlingwiththe *statemachineusedtoskipcontextrows.NeartheendofaniMCUrow, *thenextiMCUrowmayhavealreadybeenentropy-decoded.Inthisunique *case,wewillreadthenextiMCUrowifwecannotskippastitaswell.
*/ if ((num_lines < lines_left_in_iMCU_row + 1) ||
(lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
read_and_discard_scanlines(cinfo, num_lines); return num_lines;
}
/* If the next iMCU row has already been entropy-decoded, make sure that *wedonotskiptoofar.
*/ if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
lines_after_iMCU_row -= lines_per_iMCU_row;
} else {
cinfo->output_scanline += lines_left_in_iMCU_row;
}
/* If we have just completed the first block, adjust the buffer pointers */ if (main_ptr->iMCU_row_ctr == 0 ||
(main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
set_wraparound_pointers(cinfo);
main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0;
main_ptr->context_state = CTX_PREPARE_FOR_IMCU; if (!master->using_merged_upsample) {
upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
}
/* Skipping is much simpler when context rows are not required. */ else { if (num_lines < lines_left_in_iMCU_row) {
increment_simple_rowgroup_ctr(cinfo, num_lines); return num_lines;
} else {
cinfo->output_scanline += lines_left_in_iMCU_row;
main_ptr->buffer_full = FALSE;
main_ptr->rowgroup_ctr = 0; if (!master->using_merged_upsample) {
upsample->next_row_out = cinfo->max_v_samp_factor;
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
}
}
}
/* Calculate how many full iMCU rows we can skip. */ if (cinfo->upsample->need_context_rows)
lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
lines_per_iMCU_row; else
lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
lines_per_iMCU_row; /* Calculate the number of lines that remain to be skipped after skipping all *ofthefulliMCUrowsthatwecan.Wewillnotreadtheselinesunlesswe *haveto.
*/
lines_to_read = lines_after_iMCU_row - lines_to_skip;
/* For images requiring multiple scans (progressive, non-interleaved, etc.), *alloftheentropydecodingoccursinjpeg_start_decompress(),assuming *thattheinputdatasourceisnon-suspending.Thismakesskippingeasy.
*/ if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) { if (cinfo->upsample->need_context_rows) {
cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; /* It is complex to properly move to the middle of a context block, so *readtheremaininglinesinsteadofskippingthem.
*/
read_and_discard_scanlines(cinfo, lines_to_read);
} else {
cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
increment_simple_rowgroup_ctr(cinfo, lines_to_read);
} if (!master->using_merged_upsample)
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; return num_lines;
}
/* Skip the iMCU rows that we can safely skip. */ for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) { for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) { for (x = 0; x < cinfo->MCUs_per_row; x++) { /* Calling decode_mcu() with a NULL pointer causes it to discard the *decodedcoefficients.Thisis~5%fasterforlargesubsets,but *it'stoughtotelladifferenceforsmallerimages.
*/ if (!cinfo->entropy->insufficient_data)
cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
(*cinfo->entropy->decode_mcu) (cinfo, NULL);
}
}
cinfo->input_iMCU_row++;
cinfo->output_iMCU_row++; if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
start_iMCU_row(cinfo); else
(*cinfo->inputctl->finish_input_pass) (cinfo);
}
cinfo->output_scanline += lines_to_skip;
if (cinfo->upsample->need_context_rows) { /* Context-based upsampling keeps track of iMCU rows. */
main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
/* It is complex to properly move to the middle of a context block, so *readtheremaininglinesinsteadofskippingthem.
*/
read_and_discard_scanlines(cinfo, lines_to_read);
} else {
increment_simple_rowgroup_ctr(cinfo, lines_to_read);
}
/* Since skipping lines involves skipping the upsampling step, the value of *"rows_to_go"willbecomeinvalidunlesswesetithere.NOTE:Thisisa *bitodd,since"rows_to_go"seemstoberedundantlykeepingtrackof *output_scanline.
*/ if (!master->using_merged_upsample)
upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
/* Always skip the requested number of lines. */ return num_lines;
}
/* Verify that at least one iMCU row can be returned. */
lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size; if (max_lines < lines_per_iMCU_row)
ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Decompress directly into user's buffer. */ if (cinfo->coef->_decompress_data == NULL)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); if (!(*cinfo->coef->_decompress_data) (cinfo, data)) return0; /* suspension forced, can do nothing more */
/* OK, we processed one iMCU row. */
cinfo->output_scanline += lines_per_iMCU_row; return lines_per_iMCU_row;
}
#endif/* BITS_IN_JSAMPLE != 16 */
#if BITS_IN_JSAMPLE == 8
/* Additional entry points for buffered-image mode. */
GLOBAL(boolean)
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
{ if (cinfo->global_state != DSTATE_BUFIMAGE &&
cinfo->global_state != DSTATE_PRESCAN)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Limit scan number to valid range */ if (scan_number <= 0)
scan_number = 1; if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
scan_number = cinfo->input_scan_number;
cinfo->output_scan_number = scan_number; /* Perform any dummy output passes, and set up for the real pass */ return output_pass_setup(cinfo);
}
GLOBAL(boolean)
jpeg_finish_output(j_decompress_ptr cinfo)
{ if ((cinfo->global_state == DSTATE_SCANNING ||
cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { /* Terminate this pass. */ /* We do not require the whole pass to have been completed. */
(*cinfo->master->finish_output_pass) (cinfo);
cinfo->global_state = DSTATE_BUFPOST;
} elseif (cinfo->global_state != DSTATE_BUFPOST) { /* BUFPOST = repeat call after a suspension, anything else is error */
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
} /* Read markers looking for SOS or EOI */ while (cinfo->input_scan_number <= cinfo->output_scan_number &&
!cinfo->inputctl->eoi_reached) { if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) returnFALSE; /* Suspend, come back later */
}
cinfo->global_state = DSTATE_BUFIMAGE; return TRUE;
}
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.