cz.cuni.jagrlib.piece
Class JPEGQuantizer

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.DefaultBlockQuantizer
              extended by cz.cuni.jagrlib.piece.JPEGQuantizer
All Implemented Interfaces:
Breakable, BlockQuantizer, PersistentParamsBinary, Property, Template

public class JPEGQuantizer
extends DefaultBlockQuantizer

JPEG-like block quantizer.

Since:
0.25
See Also:
JPEGQuantizer.java

Field Summary
protected static int[][] CB50
          JPEG recommendation for Cb, Cr channels and 50% quality (annex K.2).
protected static int MAX_QUANT
          Upper bound for q-value - in strict Baseline JPEG system (8-bit quantizer).
static int MAX_TABLES
          Maximum number of quantization tables.
protected static int OUTSIDE_CB
           
protected static int OUTSIDE_Y
           
protected  int[][][] q
          Quantization tables.
static RegPiece reg
          Static registration instance for this class.
static java.lang.String STRICT_JPEG
           
protected  boolean strictBaselineJPEG
          Obey strict Baseline JPEG rules (8-bit quantizer)?
protected static int[][] Y50
          JPEG recommendation for Y channel and 50% quality (annex K.1).
 
Fields inherited from class cz.cuni.jagrlib.DefaultBlockQuantizer
CATEGORY, TEMPLATE_NAME, tmpD, tmpI, variant
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
JPEGQuantizer()
           
 
Method Summary
 int dequantize(int[] quant, double[] coef)
          Dequantization = reconstruction (floating-point form).
protected  int fiftyPercentCbCr(int x, int y)
           
protected static int fiftyPercentY(int x, int y)
           
 java.lang.Object get(java.lang.String key)
          Gets the given property.
 boolean loadData(byte[] data)
          Loads instance parameters from (previously stored) binary data.
 int quantize(double[] coef, int[] quant)
          Quantization (floating-point form).
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 void setBlockSize(int width, int height)
          Sets actual block size.
 void setData(int[] qtable)
          Sets quantization table for the current variant.
 void setQuality(float quality)
          Sets actual quality coefficient.
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 int setVariant(int variant)
          Set actual quantizer variant (context).
 byte[] storeData()
          Pack instance parameters into binary format.
 
Methods inherited from class cz.cuni.jagrlib.DefaultBlockQuantizer
dequantize, quantize
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

MAX_TABLES

public static final int MAX_TABLES
Maximum number of quantization tables.

See Also:
Constant Field Values

q

protected int[][][] q
Quantization tables.


strictBaselineJPEG

protected boolean strictBaselineJPEG
Obey strict Baseline JPEG rules (8-bit quantizer)?


MAX_QUANT

protected static final int MAX_QUANT
Upper bound for q-value - in strict Baseline JPEG system (8-bit quantizer).

See Also:
Constant Field Values

OUTSIDE_Y

protected static final int OUTSIDE_Y
See Also:
Constant Field Values

Y50

protected static final int[][] Y50
JPEG recommendation for Y channel and 50% quality (annex K.1).


OUTSIDE_CB

protected static final int OUTSIDE_CB
See Also:
Constant Field Values

CB50

protected static final int[][] CB50
JPEG recommendation for Cb, Cr channels and 50% quality (annex K.2).


STRICT_JPEG

public static final java.lang.String STRICT_JPEG
See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

JPEGQuantizer

public JPEGQuantizer()
Method Detail

fiftyPercentY

protected static final int fiftyPercentY(int x,
                                         int y)

fiftyPercentCbCr

protected final int fiftyPercentCbCr(int x,
                                     int y)

setVariant

public int setVariant(int variant)
Set actual quantizer variant (context).

Specified by:
setVariant in interface BlockQuantizer
Overrides:
setVariant in class DefaultBlockQuantizer
Parameters:
variant - Variant number (from 0).
Returns:
Old variant number.
See Also:
setBlockSize(int, int), setQuality(float), setData(int[])

setBlockSize

public void setBlockSize(int width,
                         int height)
Sets actual block size. Can be used both for 1D and 2D quantization.

Specified by:
setBlockSize in interface BlockQuantizer
Overrides:
setBlockSize in class DefaultBlockQuantizer
Parameters:
width - Horizontal block size (1D block size).
height - Vertical block size (1 for 1D).
See Also:
setVariant(int), setQuality(float), setData(int[])

setQuality

public void setQuality(float quality)
Sets actual quality coefficient. Value range for the quality: 0.0f to 1.0f.

Specified by:
setQuality in interface BlockQuantizer
Overrides:
setQuality in class DefaultBlockQuantizer
Parameters:
quality - New quality coefficient.
See Also:
setVariant(int), setBlockSize(int, int), setData(int[])

setData

public void setData(int[] qtable)
Sets quantization table for the current variant.

Specified by:
setData in interface BlockQuantizer
Overrides:
setData in class DefaultBlockQuantizer
Parameters:
qtable - New quantization table. Should have the correct size and layout (scanline top-first, left-first).
See Also:
setVariant(int), setQuality(float), setBlockSize(int, int)

quantize

public int quantize(double[] coef,
                    int[] quant)
Quantization (floating-point form).

Specified by:
quantize in interface BlockQuantizer
Overrides:
quantize in class DefaultBlockQuantizer
Parameters:
coef - Source data (coefficients). Size = array size. Should have the correct size and layout (scanline top-first, left-first).
quant - Pre-allocated result array or null if it's size needs to be determined.
Returns:
Result array size (even if the quantization was not performed).
See Also:
DefaultBlockQuantizer.quantize(int[],int[]), dequantize(int[],double[])

dequantize

public int dequantize(int[] quant,
                      double[] coef)
Dequantization = reconstruction (floating-point form).

Specified by:
dequantize in interface BlockQuantizer
Overrides:
dequantize in class DefaultBlockQuantizer
Parameters:
quant - Source data (quantized coefficients). Size = array size. Should have the correct size and layout (scanline top-first, left-first).
coef - Pre-allocated coefficient array or null if it's size needs to be determined.
Returns:
Coefficient array size (even if the dequantization was not performed).
See Also:
DefaultBlockQuantizer.dequantize(int[],int[]), quantize(double[],int[])

storeData

public byte[] storeData()
Pack instance parameters into binary format.

Specified by:
storeData in interface PersistentParamsBinary
Overrides:
storeData in class DefaultBlockQuantizer
Returns:
Data array to be stored into binary stream. Can be null. The array can be shared by all method calls.
See Also:
loadData(byte[])

loadData

public boolean loadData(byte[] data)
Loads instance parameters from (previously stored) binary data.

Specified by:
loadData in interface PersistentParamsBinary
Overrides:
loadData in class DefaultBlockQuantizer
Parameters:
data - Binary data to be interpreted. Can be null.
Returns:
true if successful.
See Also:
storeData()

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.