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[]
block
private int[]
blockInt
private DhtSegment.HuffmanTable[]
huffmanACTables
private DhtSegment.HuffmanTable[]
huffmanDCTables
private java.awt.image.BufferedImage
image
private ImageReadException
imageReadException
private java.io.IOException
ioException
private DqtSegment.QuantizationTable[]
quantizationTables
private float[][]
scaledQuantizationTables
private SofnSegment
sofnSegment
private SosSegment
sosSegment
private 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()
boolean
beginSOS()
java.awt.image.BufferedImage
decode(ByteSource byteSource)
private int
decode(JpegInputStream is, DhtSegment.HuffmanTable huffmanTable)
private int
extend(int v, int t)
private static int
fastRound(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 void
readMCU(JpegInputStream is, int[] preds, Block[] mcu)
private int
receive(int ssss, JpegInputStream is)
private void
rescaleMCU(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.boolean
visitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData)
void
visitSOS(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:
beginSOS
in interfaceJpegUtils.Visitor
-
visitSOS
public void visitSOS(int marker, byte[] markerBytes, byte[] imageData)
- Specified by:
visitSOS
in interfaceJpegUtils.Visitor
-
visitSegment
public boolean visitSegment(int marker, byte[] markerBytes, int segmentLength, byte[] segmentLengthBytes, byte[] segmentData) throws ImageReadException, java.io.IOException
- Specified by:
visitSegment
in interfaceJpegUtils.Visitor
- Throws:
ImageReadException
java.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.IOException
ImageReadException
-
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.IOException
ImageReadException
-
decode
private int decode(JpegInputStream is, DhtSegment.HuffmanTable huffmanTable) throws java.io.IOException, ImageReadException
- Throws:
java.io.IOException
ImageReadException
-
decode
public java.awt.image.BufferedImage decode(ByteSource byteSource) throws java.io.IOException, ImageReadException
- Throws:
java.io.IOException
ImageReadException
-
-