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 Details

    • 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 BufferedImage image
    • imageReadException

      private ImagingException imageReadException
    • ioException

      private IOException ioException
    • zz

      private final int[] zz
    • blockInt

      private final int[] blockInt
    • block

      private final float[] block
    • useTiffRgb

      private boolean useTiffRgb
  • Constructor Details

    • JpegDecoder

      public JpegDecoder()
      Constructs a new instance with the default, big-endian, byte order.
  • Method Details

    • fastRound

      private static int fastRound(float x)
    • getIntervalStartPositions

      static List<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:
      beginSos in interface JpegUtils.Visitor
    • decode

      public BufferedImage decode(ByteSource byteSource) throws IOException, ImagingException
      Throws:
      IOException
      ImagingException
    • 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
    • rescaleMcu

      private void rescaleMcu(Block[] dataUnits, int hSize, int vSize, Block[] ret)
    • 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, IOException
      Specified by:
      visitSegment in interface JpegUtils.Visitor
      Throws:
      ImagingException
      IOException
    • visitSos

      public void visitSos(int marker, byte[] markerBytes, byte[] imageData)
      Specified by:
      visitSos in interface JpegUtils.Visitor