C# Class BitMiracle.LibJpeg.Classic.Internal.jpeg_d_main_controller

Main buffer control (downsampled-data buffer) In the current system design, the main buffer need never be a full-image buffer; any full-height buffers will be found inside the coefficient or postprocessing controllers. Nonetheless, the main controller is not trivial. Its responsibility is to provide context rows for upsampling/ rescaling, and doing this in an efficient fashion is a bit tricky. Postprocessor input data is counted in "row groups". A row group is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) sample rows of each component. (We require DCT_scaled_size values to be chosen such that these numbers are integers. In practice DCT_scaled_size values will likely be powers of two, so we actually have the stronger condition that DCT_scaled_size / min_DCT_scaled_size is an integer.) Upsampling will typically produce max_v_samp_factor pixel rows from each row group (times any additional scale factor that the upsampler is applying). The coefficient controller will deliver data to us one iMCU row at a time; each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or exactly min_DCT_scaled_size row groups. (This amount of data corresponds to one row of MCUs when the image is fully interleaved.) Note that the number of sample rows varies across components, but the number of row groups does not. Some garbage sample rows may be included in the last iMCU row at the bottom of the image. Depending on the vertical scaling algorithm used, the upsampler may need access to the sample row(s) above and below its current input row group. The upsampler is required to set need_context_rows true at global selection time if so. When need_context_rows is false, this controller can simply obtain one iMCU row at a time from the coefficient controller and dole it out as row groups to the postprocessor. When need_context_rows is true, this controller guarantees that the buffer passed to postprocessing contains at least one row group's worth of samples above and below the row group(s) being processed. Note that the context rows "above" the first passed row group appear at negative row offsets in the passed buffer. At the top and bottom of the image, the required context rows are manufactured by duplicating the first or last real sample row; this avoids having special cases in the upsampling inner loops. The amount of context is fixed at one row group just because that's a convenient number for this controller to work with. The existing upsamplers really only need one sample row of context. An upsampler supporting arbitrary output rescaling might wish for more than one row group of context when shrinking the image; tough, we don't handle that. (This is justified by the assumption that downsizing will be handled mostly by adjusting the DCT_scaled_size values, so that the actual scale factor at the upsample step needn't be much less than one.) To provide the desired context, we have to retain the last two row groups of one iMCU row while reading in the next iMCU row. (The last row group can't be processed until we have another row group for its below-context, and so we have to save the next-to-last group too for its above-context.) We could do this most simply by copying data around in our buffer, but that'd be very slow. We can avoid copying any data by creating a rather strange pointer structure. Here's how it works. We allocate a workspace consisting of M+2 row groups (where M = min_DCT_scaled_size is the number of row groups per iMCU row). We create two sets of redundant pointers to the workspace. Labeling the physical row groups 0 to M+1, the synthesized pointer lists look like this: M+1 M-1 master pointer --> 0 master pointer --> 0 1 1 ... ... M-3 M-3 M-2 M M-1 M+1 M M-2 M+1 M-1 0 0 We read alternate iMCU rows using each master pointer; thus the last two row groups of the previous iMCU row remain un-overwritten in the workspace. The pointer lists are set up so that the required context rows appear to be adjacent to the proper places when we pass the pointer lists to the upsampler. The above pictures describe the normal state of the pointer lists. At top and bottom of the image, we diddle the pointer lists to duplicate the first or last sample row as necessary (this is cheaper than copying sample rows around). This scheme breaks down if M less than 2, ie, min_DCT_scaled_size is 1. In that situation each iMCU row provides only one row group so the buffering logic must be different (eg, we must read two iMCU rows before we can emit the first row group). For now, we simply do not support providing context rows when min_DCT_scaled_size is 1. That combination seems unlikely to be worth providing --- if someone wants a 1/8th-size preview, they probably want it quick and dirty, so a context-free upsampler is sufficient.
Mostrar archivo Open project: prepare/HTML-Renderer

Public Methods

Method Description
jpeg_d_main_controller ( jpeg_decompress_struct cinfo )
process_data ( byte output_buf, int &out_row_ctr, int out_rows_avail ) : void
start_pass ( J_BUF_MODE pass_mode ) : void

Initialize for a processing pass.

Private Methods

Method Description
alloc_funny_pointers ( ) : void

Allocate space for the funny pointer lists. This is done only once, not once per pass.

make_funny_pointers ( ) : void

Create the funny pointer lists discussed in the comments above. The actual workspace is already allocated (in main.buffer), and the space for the pointer lists is allocated too. This routine just fills in the curiously ordered lists. This will be repeated at the beginning of each pass.

process_data_context_main ( byte output_buf, int &out_row_ctr, int out_rows_avail ) : void

Process some data. This handles the case where context rows must be provided.

process_data_crank_post ( byte output_buf, int &out_row_ctr, int out_rows_avail ) : void

Process some data. Final pass of two-pass quantization: just call the postprocessor. Source data will be the postprocessor controller's internal buffer.

process_data_simple_main ( byte output_buf, int &out_row_ctr, int out_rows_avail ) : void

Process some data. This handles the simple case where no context is required.

set_bottom_pointers ( ) : void

Change the pointer lists to duplicate the last sample row at the bottom of the image. m_whichFunny indicates which m_funnyIndices holds the final iMCU row. Also sets rowgroups_avail to indicate number of nondummy row groups in row.

set_wraparound_pointers ( ) : void

Set up the "wraparound" pointers at top and bottom of the pointer lists. This changes the pointer list state from top-of-image to the normal state.

Method Details

jpeg_d_main_controller() public method

public jpeg_d_main_controller ( jpeg_decompress_struct cinfo )
cinfo jpeg_decompress_struct

process_data() public method

public process_data ( byte output_buf, int &out_row_ctr, int out_rows_avail ) : void
output_buf byte
out_row_ctr int
out_rows_avail int
return void

start_pass() public method

Initialize for a processing pass.
public start_pass ( J_BUF_MODE pass_mode ) : void
pass_mode J_BUF_MODE
return void