C# Class BitMiracle.LibJpeg.Classic.jpeg_source_mgr

Show file Open project: prepare/HTML-Renderer Class Usage Examples

Public Methods

Method Description
GetByte ( int &V ) : bool

Read a byte into variable V. If must suspend, take the specified action (typically "return false").

GetBytes ( byte dest, int amount ) : int

Gets the bytes.

GetTwoBytes ( int &V ) : bool

Reads two bytes interpreted as an unsigned 16-bit integer.

MakeByteAvailable ( ) : bool

Functions for fetching data from the data source module.

At all times, cinfo.src.next_input_byte and .bytes_in_buffer reflect the current restart point; we update them only when we have reached a suitable place to restart if a suspension occurs.

fill_input_buffer ( ) : bool

Fills input buffer

init_source ( ) : void

Initializes this instance.

resync_to_restart ( jpeg_decompress_struct cinfo, int desired ) : bool

This is the default resync_to_restart method for data source managers to use if they don't have any better approach.

That method assumes that no backtracking is possible. Some data source managers may be able to back up, or may have additional knowledge about the data which permits a more intelligent recovery strategy; such managers would presumably supply their own resync method.

read_restart_marker calls resync_to_restart if it finds a marker other than the restart marker it was expecting. (This code is *not* used unless a nonzero restart interval has been declared.) cinfo.unread_marker is the marker code actually found (might be anything, except 0 or FF). The desired restart marker number (0..7) is passed as a parameter.

This routine is supposed to apply whatever error recovery strategy seems appropriate in order to position the input stream to the next data segment. Note that cinfo.unread_marker is treated as a marker appearing before the current data-source input point; usually it should be reset to zero before returning.

This implementation is substantially constrained by wanting to treat the input as a data stream; this means we can't back up. Therefore, we have only the following actions to work with:
1. Simply discard the marker and let the entropy decoder resume at next byte of file.
2. Read forward until we find another marker, discarding intervening data. (In theory we could look ahead within the current bufferload, without having to discard data if we don't find the desired marker. This idea is not implemented here, in part because it makes behavior dependent on buffer size and chance buffer-boundary positions.)
3. Leave the marker unread (by failing to zero cinfo.unread_marker). This will cause the entropy decoder to process an empty data segment, inserting dummy zeroes, and then we will reprocess the marker.
#2 is appropriate if we think the desired marker lies ahead, while #3 is appropriate if the found marker is a future restart marker (indicating that we have missed the desired restart marker, probably because it got corrupted).
We apply #2 or #3 if the found marker is a restart marker no more than two counts behind or ahead of the expected one. We also apply #2 if the found marker is not a legal JPEG marker code (it's certainly bogus data). If the found marker is a restart marker more than 2 counts away, we do #1 (too much risk that the marker is erroneous; with luck we will be able to resync at some future point).
For any valid non-restart JPEG marker, we apply #3. This keeps us from overrunning the end of a scan. An implementation limited to single-scan files might find it better to apply #2 for markers other than EOI, since any other marker would have to be bogus data in that case.

skip_input_data ( int num_bytes ) : void

Skip data - used to skip over a potentially large amount of uninteresting data (such as an APPn marker).

Writers of suspendable-input applications must note that skip_input_data is not granted the right to give a suspension return. If the skip extends beyond the data currently in the buffer, the buffer can be marked empty so that the next read will cause a fill_input_buffer call that can suspend. Arranging for additional bytes to be discarded before reloading the input buffer is the application writer's problem.

term_source ( ) : void

Terminate source - called by jpeg_finish_decompress after all data has been read. Often a no-op.

NB: not called by jpeg_abort or jpeg_destroy; surrounding application must deal with any cleanup that should happen even for error exit.

Protected Methods

Method Description
initInternalBuffer ( byte buffer, int size ) : void

Initializes the internal buffer.

Method Details

GetByte() public method

Read a byte into variable V. If must suspend, take the specified action (typically "return false").
public GetByte ( int &V ) : bool
V int The result.
return bool

GetBytes() public method

Gets the bytes.
public GetBytes ( byte dest, int amount ) : int
dest byte The destination.
amount int The amount.
return int

GetTwoBytes() public method

Reads two bytes interpreted as an unsigned 16-bit integer.
public GetTwoBytes ( int &V ) : bool
V int The result.
return bool

MakeByteAvailable() public method

Functions for fetching data from the data source module.
At all times, cinfo.src.next_input_byte and .bytes_in_buffer reflect the current restart point; we update them only when we have reached a suitable place to restart if a suspension occurs.
public MakeByteAvailable ( ) : bool
return bool

fill_input_buffer() public abstract method

Fills input buffer
public abstract fill_input_buffer ( ) : bool
return bool

initInternalBuffer() protected method

Initializes the internal buffer.
protected initInternalBuffer ( byte buffer, int size ) : void
buffer byte The buffer.
size int The size.
return void

init_source() public abstract method

Initializes this instance.
public abstract init_source ( ) : void
return void

resync_to_restart() public method

This is the default resync_to_restart method for data source managers to use if they don't have any better approach.
That method assumes that no backtracking is possible. Some data source managers may be able to back up, or may have additional knowledge about the data which permits a more intelligent recovery strategy; such managers would presumably supply their own resync method.

read_restart_marker calls resync_to_restart if it finds a marker other than the restart marker it was expecting. (This code is *not* used unless a nonzero restart interval has been declared.) cinfo.unread_marker is the marker code actually found (might be anything, except 0 or FF). The desired restart marker number (0..7) is passed as a parameter.

This routine is supposed to apply whatever error recovery strategy seems appropriate in order to position the input stream to the next data segment. Note that cinfo.unread_marker is treated as a marker appearing before the current data-source input point; usually it should be reset to zero before returning.

This implementation is substantially constrained by wanting to treat the input as a data stream; this means we can't back up. Therefore, we have only the following actions to work with:
1. Simply discard the marker and let the entropy decoder resume at next byte of file.
2. Read forward until we find another marker, discarding intervening data. (In theory we could look ahead within the current bufferload, without having to discard data if we don't find the desired marker. This idea is not implemented here, in part because it makes behavior dependent on buffer size and chance buffer-boundary positions.)
3. Leave the marker unread (by failing to zero cinfo.unread_marker). This will cause the entropy decoder to process an empty data segment, inserting dummy zeroes, and then we will reprocess the marker.
#2 is appropriate if we think the desired marker lies ahead, while #3 is appropriate if the found marker is a future restart marker (indicating that we have missed the desired restart marker, probably because it got corrupted).
We apply #2 or #3 if the found marker is a restart marker no more than two counts behind or ahead of the expected one. We also apply #2 if the found marker is not a legal JPEG marker code (it's certainly bogus data). If the found marker is a restart marker more than 2 counts away, we do #1 (too much risk that the marker is erroneous; with luck we will be able to resync at some future point).
For any valid non-restart JPEG marker, we apply #3. This keeps us from overrunning the end of a scan. An implementation limited to single-scan files might find it better to apply #2 for markers other than EOI, since any other marker would have to be bogus data in that case.
public resync_to_restart ( jpeg_decompress_struct cinfo, int desired ) : bool
cinfo jpeg_decompress_struct An instance of
desired int The desired
return bool

skip_input_data() public method

Skip data - used to skip over a potentially large amount of uninteresting data (such as an APPn marker).
Writers of suspendable-input applications must note that skip_input_data is not granted the right to give a suspension return. If the skip extends beyond the data currently in the buffer, the buffer can be marked empty so that the next read will cause a fill_input_buffer call that can suspend. Arranging for additional bytes to be discarded before reloading the input buffer is the application writer's problem.
public skip_input_data ( int num_bytes ) : void
num_bytes int The number of bytes to skip.
return void

term_source() public method

Terminate source - called by jpeg_finish_decompress after all data has been read. Often a no-op.
NB: not called by jpeg_abort or jpeg_destroy; surrounding application must deal with any cleanup that should happen even for error exit.
public term_source ( ) : void
return void