Class JpegDecoder
- java.lang.Object
-
- org.apache.commons.imaging.common.BinaryFileParser
-
- org.apache.commons.imaging.formats.jpeg.decoder.JpegDecoder
-
- All Implemented Interfaces:
JpegUtils.Visitor
public class JpegDecoder extends BinaryFileParser implements JpegUtils.Visitor
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]BAND_MASK_ARGBprivate static int[]BAND_MASK_RGBprivate float[]blockprivate int[]blockIntprivate DhtSegment.HuffmanTable[]huffmanACTablesprivate DhtSegment.HuffmanTable[]huffmanDCTablesprivate java.awt.image.BufferedImageimageprivate ImagingExceptionimageReadExceptionprivate java.io.IOExceptionioExceptionprivate DqtSegment.QuantizationTable[]quantizationTablesprivate float[][]scaledQuantizationTablesprivate SofnSegmentsofnSegmentprivate SosSegmentsosSegmentprivate booleanuseTiffRgbprivate int[]zz
-
Constructor Summary
Constructors Constructor Description JpegDecoder()Constructs a new instance with the default, big-endian, byte order.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Block[]allocateMcuMemory()booleanbeginSos()java.awt.image.BufferedImagedecode(ByteSource byteSource)private intdecode(JpegInputStream is, DhtSegment.HuffmanTable huffmanTable)private intextend(int v, int t)private static intfastRound(float x)(package private) static java.util.List<java.lang.Integer>getIntervalStartPositions(int[] scanPayload)Returns the positions of where each interval in the provided array starts.private voidreadMcu(JpegInputStream is, int[] preds, Block[] mcu)private intreceive(int ssss, JpegInputStream is)private voidrescaleMcu(Block[] dataUnits, int hSize, int vSize, Block[] ret)voidsetTiffRgb()Sets the decoder to treat incoming data as using the RGB color model.(package private) static JpegInputStream[]splitByRstMarkers(int[] scanPayload)Returns an array of JpegInputStream where each field contains the JpegInputStream for one interval.booleanvisitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData)voidvisitSos(int marker, byte[] markerBytes, byte[] imageData)-
Methods inherited from class org.apache.commons.imaging.common.BinaryFileParser
debugNumber, debugNumber, getByteOrder, setByteOrder
-
-
-
-
Field Detail
-
BAND_MASK_ARGB
private static final int[] BAND_MASK_ARGB
-
BAND_MASK_RGB
private static final int[] BAND_MASK_RGB
-
quantizationTables
private final DqtSegment.QuantizationTable[] quantizationTables
-
huffmanDCTables
private final DhtSegment.HuffmanTable[] huffmanDCTables
-
huffmanACTables
private final DhtSegment.HuffmanTable[] huffmanACTables
-
sofnSegment
private SofnSegment sofnSegment
-
sosSegment
private SosSegment sosSegment
-
scaledQuantizationTables
private final float[][] scaledQuantizationTables
-
image
private java.awt.image.BufferedImage image
-
imageReadException
private ImagingException imageReadException
-
ioException
private java.io.IOException ioException
-
zz
private final int[] zz
-
blockInt
private final int[] blockInt
-
block
private final float[] block
-
useTiffRgb
private boolean useTiffRgb
-
-
Method Detail
-
fastRound
private static int fastRound(float x)
-
getIntervalStartPositions
static java.util.List<java.lang.Integer> getIntervalStartPositions(int[] scanPayload)
Returns the positions of where each interval in the provided array starts. The number of start positions is also the count of intervals while the number of restart markers found is equal to the number of start positions minus one (because restart markers are between intervals).- Parameters:
scanPayload- array to examine- Returns:
- the start positions
-
splitByRstMarkers
static JpegInputStream[] splitByRstMarkers(int[] scanPayload)
Returns an array of JpegInputStream where each field contains the JpegInputStream for one interval.- Parameters:
scanPayload- array to read intervals from- Returns:
- JpegInputStreams for all intervals, at least one stream is always provided
-
allocateMcuMemory
private Block[] allocateMcuMemory() throws ImagingException
- Throws:
ImagingException
-
beginSos
public boolean beginSos()
- Specified by:
beginSosin interfaceJpegUtils.Visitor
-
decode
public java.awt.image.BufferedImage decode(ByteSource byteSource) throws java.io.IOException, ImagingException
- Throws:
java.io.IOExceptionImagingException
-
decode
private int decode(JpegInputStream is, DhtSegment.HuffmanTable huffmanTable) throws ImagingException
- Throws:
ImagingException
-
extend
private int extend(int v, int t)
-
readMcu
private void readMcu(JpegInputStream is, int[] preds, Block[] mcu) throws ImagingException
- Throws:
ImagingException
-
receive
private int receive(int ssss, JpegInputStream is) throws ImagingException- Throws:
ImagingException
-
setTiffRgb
public void setTiffRgb()
Sets the decoder to treat incoming data as using the RGB color model. This extension to the JPEG specification is intended to support TIFF files that use JPEG compression.
-
visitSegment
public boolean visitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData) throws ImagingException, java.io.IOException- Specified by:
visitSegmentin interfaceJpegUtils.Visitor- Throws:
ImagingExceptionjava.io.IOException
-
visitSos
public void visitSos(int marker, byte[] markerBytes, byte[] imageData)- Specified by:
visitSosin interfaceJpegUtils.Visitor
-
-