FileDocCategorySizeDatePackage
JPEGQTable.javaAPI DocJava SE 6 API7370Tue Jun 10 00:26:08 BST 2008javax.imageio.plugins.jpeg

JPEGQTable

public class JPEGQTable extends Object
A class encapsulating a single JPEG quantization table. The elements appear in natural order (as opposed to zig-zag order). Static variables are provided for the "standard" tables taken from Annex K of the JPEG spec, as well as the default tables conventionally used for visually lossless encoding.

For more information about the operation of the built-in JPEG plug-ins, see the JPEG metadata format specification and usage notes.

version
0.5

Fields Summary
private int[]
table
Table
private static final byte
QTABLESIZE
The number of coefficients in a quantization table.
public static final JPEGQTable
K1Luminance
The sample luminance quantization table given in the JPEG specification, table K.1. According to the specification, these values produce "good" quality output.
public static final JPEGQTable
K1Div2Luminance
The sample luminance quantization table given in the JPEG specification, table K.1, with all elements divided by 2. According to the specification, these values produce "very good" quality output. This is the table usually used for "visually lossless" encoding, and is the default luminance table used if the default tables and quality settings are used.
public static final JPEGQTable
K2Chrominance
The sample chrominance quantization table given in the JPEG specification, table K.2. According to the specification, these values produce "good" quality output.
public static final JPEGQTable
K2Div2Chrominance
The sample chrominance quantization table given in the JPEG specification, table K.2, with all elements divided by 2. According to the specification, these values produce "very good" quality output. This is the table usually used for "visually lossless" encoding, and is the default chrominance table used if the default tables and quality settings are used.
Constructors Summary
private JPEGQTable()
Constructs an empty quantization table. This is used to create the standard tables.

    
                       
      
public JPEGQTable(int[] table)
Constructs a quantization table from the argument, which must contain 64 elements in natural order (not zig-zag order). A copy is made of the the input array.

param
table the quantization table, as an int array.
exception
IllegalArgumentException if table is null or table.length is not equal to 64.

        if (table == null) {
            throw new IllegalArgumentException("table == null!");
        }
        if (table.length != QTABLESIZE) {
            throw new IllegalArgumentException
                ("Quantization table is the wrong size.");
        }

        this.table = (int[])table.clone();
    
Methods Summary
public javax.imageio.plugins.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 of scaleFactorless than 1 tend to improve the quality level of the table, and values greater than 1.0 degrade the quality level of the table.

param
scaleFactor the multiplicative factor for the table.
param
forceBaseline if true, the values will be clamped to the range 1..255.
return
a new quantization table that is a linear multiple of the current table.

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

        for (int i = 0; i < QTABLESIZE; i++) {
            float scaledValue = (float)Math.round(table[i]*scaleFactor);
            int holder;
            
            // limit to valid range
            if (scaledValue <= 1.0F) {
                holder = 1;
            } else if (scaledValue >= max) {
                holder = max;
            } else {
                holder = (int)scaledValue;
            }
            ret[i] = holder;
        }

        return new JPEGQTable(ret);
    
public int[]getTable()
Returns a copy of the current quantization table as an array of ints in natural (not zig-zag) order.

return
A copy of the current quantization table.

 
        return (int[])table.clone();
    
public java.lang.StringtoString()

        StringBuffer sb = new StringBuffer();
        sb.append("JPEGQTable:\n");
        for (int i = 0; i< 8; i++) {
            sb.append('\t");
            for (int j = 0; j < 8; j++) {
                sb.append(table[(i*8)+j]).append(" ");
            }
            sb.append('\n");
        }
        return sb.toString();