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 float[]blockprivate int[]blockIntprivate DhtSegment.HuffmanTable[]huffmanACTablesprivate DhtSegment.HuffmanTable[]huffmanDCTablesprivate java.awt.image.BufferedImageimageprivate ImageReadExceptionimageReadExceptionprivate java.io.IOExceptionioExceptionprivate DqtSegment.QuantizationTable[]quantizationTablesprivate float[][]scaledQuantizationTablesprivate SofnSegmentsofnSegmentprivate SosSegmentsosSegmentprivate int[]zz
-
Constructor Summary
Constructors Constructor Description JpegDecoder()
-
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)(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
-
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 ImageReadException imageReadException
-
ioException
private java.io.IOException ioException
-
zz
private final int[] zz
-
blockInt
private final int[] blockInt
-
block
private final float[] block
-
-
Method Detail
-
beginSOS
public boolean beginSOS()
- Specified by:
beginSOSin interfaceJpegUtils.Visitor
-
visitSOS
public void visitSOS(int marker, byte[] markerBytes, byte[] imageData)- Specified by:
visitSOSin interfaceJpegUtils.Visitor
-
visitSegment
public boolean visitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData) throws ImageReadException, java.io.IOException- Specified by:
visitSegmentin interfaceJpegUtils.Visitor- Throws:
ImageReadExceptionjava.io.IOException
-
allocateMCUMemory
private Block[] allocateMCUMemory() throws ImageReadException
- Throws:
ImageReadException
-
readMCU
private void readMCU(JpegInputStream is, int[] preds, Block[] mcu) throws java.io.IOException, ImageReadException
- Throws:
java.io.IOExceptionImageReadException
-
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
-
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
-
fastRound
private static int fastRound(float x)
-
extend
private int extend(int v, int t)
-
receive
private int receive(int ssss, JpegInputStream is) throws java.io.IOException, ImageReadException- Throws:
java.io.IOExceptionImageReadException
-
decode
private int decode(JpegInputStream is, DhtSegment.HuffmanTable huffmanTable) throws java.io.IOException, ImageReadException
- Throws:
java.io.IOExceptionImageReadException
-
decode
public java.awt.image.BufferedImage decode(ByteSource byteSource) throws java.io.IOException, ImageReadException
- Throws:
java.io.IOExceptionImageReadException
-
-