FileDocCategorySizeDatePackage
JPEGQTable.javaAPI DocJava SE 5 API5012Fri Aug 26 14:54:42 BST 2005com.sun.image.codec.jpeg

JPEGQTable

public class JPEGQTable extends Object
Class to encapsulate the JPEG quantization tables.

Note that the classes in the com.sun.image.codec.jpeg package are not part of the core Java APIs. They are a part of Sun's JDK and JRE distributions. Although other licensees may choose to distribute these classes, developers cannot depend on their availability in non-Sun implementations. We expect that equivalent functionality will eventually be available in a core API or standard extension.

Fields Summary
private int[]
quantval
Quantization step for each coefficient in zig-zag order
private static final byte
QTABLESIZE
The number of coefficients in a DCT block
public static final JPEGQTable
StdLuminance
This is the sample luminance quantization table given in the JPEG spec section K.1, expressed in zigzag order. The spec says that the values given produce "good" quality, and when divided by 2, "very good" quality.
public static final JPEGQTable
StdChrominance
This is the sample luminance quantization table given in the JPEG spec section K.1, expressed in zigzag order. The spec says that the values given produce "good" quality, and when divided by 2, "very good" quality.
Constructors Summary
private JPEGQTable()
Constructs an empty quantization table. This is used to create the Std Q-Tables.

	 
		int [] chromVals = {
			17,  18,  18,  24,  21,  24,  47,  26,
			26,  47,  99,  66,  56,  66,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99,
			99,  99,  99,  99,  99,  99,  99,  99
		};
		StdChrominance.quantval = chromVals;
	
		quantval = new int[QTABLESIZE];
	
public JPEGQTable(int[] table)
Constructs an quantization table from the array that was passed. The coefficents must be in zig-zag order. The array must be of length 64.

param
table the quantization table (this is copied).

		if ( table.length != QTABLESIZE ) {
			throw new IllegalArgumentException
				("Quantization table is the wrong size.");
		} else {
			quantval = new int[QTABLESIZE];
			System.arraycopy( table, 0, quantval, 0, QTABLESIZE );
		}
	
Methods Summary
public com.sun.image.codec.jpeg.JPEGQTablegetScaledInstance(float scaleFactor, boolean forceBaseline)
Returns a new Quantization table where the values are multiplied by scaleFactor and then clamped to the range 1..32767 (or to 1..255 if forceBaseline is 'true').

Values less than one tend to improve the quality level of the table, and values greater than one degrade the quality level of the table.

param
scaleFactor the multiplication factor for the table
param
forceBaseline if true the values will be clamped to the range [1 .. 255]
return
A new Q-Table that is a linear multiple of this Q-Table

		long  max    = (forceBaseline)?255L:32767L;
		int []ret    = new int[QTABLESIZE];

		for (int i=0; i<QTABLESIZE; i++ ) {
			long holder = (long)((quantval[i] * scaleFactor) + 0.5);

			// limit to valid range
			if (holder <= 0L) holder = 1L;

			// Max quantizer for 12 bits
			if (holder > max ) holder = max; 
			
			ret[i] = (int)holder;
		}
		return new JPEGQTable(ret);
	
public int[]getTable()
Returns the current quantization table as an array of ints in zig zag order.

return
A copy of the contained quantization table.

 
		int[] table = new int[QTABLESIZE];
		System.arraycopy( quantval, 0, table, 0, QTABLESIZE );
		return table;