fi.helsinki.cs.ohtu.mpeg2.video
Class ChromaSubsampler

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.video.ChromaSubsampler

public class ChromaSubsampler
extends java.lang.Object

Performs chromacity subsampling on byte values. Subsampling is performed either in only in the horizontal direction (usable for eg. Y'CbCr 4:2:2) or in both directions (usable for eg. Y'CbCr 4:2:0).


Field Summary
private  boolean vertical
           
 
Constructor Summary
ChromaSubsampler(boolean vertical)
          Class constructor.
 
Method Summary
private  void copyArray(int[][] from, int[][] to)
           
 boolean getSubsampleVertical()
          Determines whether or not vertical subsampling is enabled or not.
 void setSubsampleVertical(boolean subsampleVertical)
          Sets whether subsampling should be performed in the vertical direction or not.
 int[][] subsample(int[][] values)
          Subsamples image data, given as a two-dimensional array.
 int[][] subsample(int[] values, int height, int width)
          Subsamples image data, given as an one-dimensional array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vertical

private boolean vertical
Constructor Detail

ChromaSubsampler

public ChromaSubsampler(boolean vertical)
Class constructor.

Parameters:
vertical - Whether vertical subsampling should be performed or not, as by a call ot setSubsampleVertical().
Method Detail

getSubsampleVertical

public boolean getSubsampleVertical()
Determines whether or not vertical subsampling is enabled or not.

Returns:
Whether vertical subsampling is enabled or not.

setSubsampleVertical

public void setSubsampleVertical(boolean subsampleVertical)
Sets whether subsampling should be performed in the vertical direction or not. Subsampling is always performed in the horizontal direction. This method can be used to toggle whether additionally vertical subsampling should be performed.

Parameters:
subsampleVertical - Whether vertical subsampling should be enabled or not.

subsample

public int[][] subsample(int[] values,
                         int height,
                         int width)
Subsamples image data, given as an one-dimensional array. The subsampling is performed according to the set vertical subsampling flag, as returned by getSubsampleVertical().

Parameters:
values - The input data. Must be height * width in length, and in a row-major arrangement.
height - The height of the input data in rows.
width - The width of the input data, in columns.
Returns:
The subsampled data. Will have (width / 2), rounded up, columns and either height or (height / 2), rounded up, rows, depending on whether vertical subsampling is enabled or not.

subsample

public int[][] subsample(int[][] values)
Subsamples image data, given as a two-dimensional array. The subsampling is performed according to the set vertical subsampling flag, as returned by getSubsampleVertical().

Parameters:
values - The input data. Must be in a row-major arrangement. Every sub-array (corresponding to the rows) must be of the same length. The width and height are extracted from the array's dimensions.
Returns:
The subsampled data. Will have (width / 2), rounded up, columns and either height or (height / 2), rounded up, rows, depending on whether vertical subsampling is enabled or not.

copyArray

private void copyArray(int[][] from,
                       int[][] to)