fi.faidon.jis
Class JPEGSample

java.lang.Object
  |
  +--fi.faidon.jis.JPEGSample

public class JPEGSample
extends java.lang.Object

This file is more or less a translation of the jcsample.c file of the Independent JPEG Group's software. This file contains downsampling routines. Downsampling input data is counted in "row groups". A row group is defined to be max_v_samp_factor pixel rows of each component, from which the downsampler produces v_samp_factor sample rows. A single row group is processed in each call to the downsampler module. The downsampler is responsible for edge-expansion of its output data to fill an integral number of DCT blocks horizontally. The source buffer may be modified if it is helpful for this purpose (the source buffer is allocated wide enough to correspond to the desired output width). The caller (the prep controller) is responsible for vertical padding. The downsampler may request "context rows" by setting need_context_rows during startup. In this case, the input arrays will contain at least one row group's worth of pixels above and below the passed-in data; the caller will create dummy rows at image top and bottom by replicating the first or last real pixel row. An excellent reference for image resampling is Digital Image Warping, George Wolberg, 1990. Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. The downsampling algorithm used here is a simple average of the source pixels covered by the output pixel. The hi-falutin sampling literature refers to this as a "box filter". In general the characteristics of a box filter are not very good, but for the specific cases we normally use (1:1 and 2:1 ratios) the box is equivalent to a "triangle filter" which is not nearly so bad. If you intend to use other sampling ratios, you'd be well advised to improve this code. A simple input-smoothing capability is provided. This is mainly intended for cleaning up color-dithered GIF input files (if you find it inadequate, we suggest using an external filtering program such as pnmconvol). When enabled, each input pixel P is replaced by a weighted sum of itself and its eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, where SF = (smoothing_factor / 1024). Currently, smoothing is only supported for 2h2v sampling factors.


Field Summary
 boolean needContextRows
           
 
Constructor Summary
JPEGSample(JPEGImageSaver cinfo)
          Module initialization routine for downsampling.
 
Method Summary
 void downsample(JPEGImageSaver cinfo, java.util.Vector inputBuf, int inRowIndex, java.util.Vector outputBuf, int outRowGroupIndex)
          Replaces the downsample function pointer of the original C source.
 void expandRightEdge(int[][] imageData, int inRowOff, int numRows, int inputCols, int outputCols)
          Expand a component horizontally from width input_cols to width output_cols, by duplicating the rightmost samples.
 void intDownsample(JPEGImageSaver cinfo, JPEGComponentInfo comp, int[][] inputData, int inRowOff, int[][] outputData, int outRowOff)
          Downsample pixel values of a single component.
 void sepDownsample(JPEGImageSaver cinfo, java.util.Vector inputBuf, int inRowIndex, java.util.Vector outputBuf, int outRowGroupIndex)
          Do downsampling for a whole row group (all components).
 void startPass(JPEGImageSaver cinfo)
          Replaces the start_pass function pointer of the original C source.
 void startPassDownsample(JPEGImageSaver cinfo)
          Initialize for a downsampling pass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

needContextRows

public boolean needContextRows
Constructor Detail

JPEGSample

public JPEGSample(JPEGImageSaver cinfo)
           throws java.io.IOException
Module initialization routine for downsampling. Note that we must select a routine for each component. See jinit_downsampler in jcsample.c of IJG Jpeg-6a library.

Method Detail

startPass

public void startPass(JPEGImageSaver cinfo)
Replaces the start_pass function pointer of the original C source.


startPassDownsample

public void startPassDownsample(JPEGImageSaver cinfo)
Initialize for a downsampling pass. See start_pass_downsample in jcsample.c of IJG Jpeg-6a library.


expandRightEdge

public void expandRightEdge(int[][] imageData,
                            int inRowOff,
                            int numRows,
                            int inputCols,
                            int outputCols)
Expand a component horizontally from width input_cols to width output_cols, by duplicating the rightmost samples. See expand_right_edge in jcsample.c of IJG Jpeg-6a library.


downsample

public void downsample(JPEGImageSaver cinfo,
                       java.util.Vector inputBuf,
                       int inRowIndex,
                       java.util.Vector outputBuf,
                       int outRowGroupIndex)
Replaces the downsample function pointer of the original C source.


sepDownsample

public void sepDownsample(JPEGImageSaver cinfo,
                          java.util.Vector inputBuf,
                          int inRowIndex,
                          java.util.Vector outputBuf,
                          int outRowGroupIndex)
Do downsampling for a whole row group (all components). In this version we simply downsample each component independently. See sep_downsample in jcsample.c of IJG Jpeg-6a library.


intDownsample

public void intDownsample(JPEGImageSaver cinfo,
                          JPEGComponentInfo comp,
                          int[][] inputData,
                          int inRowOff,
                          int[][] outputData,
                          int outRowOff)
Downsample pixel values of a single component. One row group is processed per call. This version handles arbitrary integral sampling ratios, without smoothing. Note that this version is not actually used for customary sampling ratios. See int_downsample in jcsample.c of IJG Jpeg-6a library.