@Override
    public boolean visitSegment(final int marker, final byte[] markerBytes, final int segmentLength, final byte[] segmentLengthBytes, final byte[] segmentData)
            throws ImagingException, IOException {
        final int[] sofnSegments = { JpegConstants.SOF0_MARKER, JpegConstants.SOF1_MARKER, JpegConstants.SOF2_MARKER, JpegConstants.SOF3_MARKER,
                JpegConstants.SOF5_MARKER, JpegConstants.SOF6_MARKER, JpegConstants.SOF7_MARKER, JpegConstants.SOF9_MARKER, JpegConstants.SOF10_MARKER,
                JpegConstants.SOF11_MARKER, JpegConstants.SOF13_MARKER, JpegConstants.SOF14_MARKER, JpegConstants.SOF15_MARKER, };

        if (Arrays.binarySearch(sofnSegments, marker) >= 0) {
            if (marker != JpegConstants.SOF0_MARKER) {
                throw new ImagingException("Only sequential, baseline JPEGs " + "are supported at the moment");
            }
            sofnSegment = new SofnSegment(marker, segmentData);
        } else if (marker == JpegConstants.DQT_MARKER) {
            final DqtSegment dqtSegment = new DqtSegment(marker, segmentData);
            for (final QuantizationTable table : dqtSegment.quantizationTables) {
                if (0 > table.destinationIdentifier || table.destinationIdentifier >= quantizationTables.length) {
                    throw new ImagingException("Invalid quantization table identifier " + table.destinationIdentifier);
                }
                quantizationTables[table.destinationIdentifier] = table;
                final int mSize = 64;
                final int[] quantizationMatrixInt = Allocator.intArray(mSize);
                ZigZag.zigZagToBlock(table.getElements(), quantizationMatrixInt);
                final float[] quantizationMatrixFloat = Allocator.floatArray(mSize);
                for (int j = 0; j < mSize; j++) {
                    quantizationMatrixFloat[j] = quantizationMatrixInt[j];
                }
                Dct.scaleDequantizationMatrix(quantizationMatrixFloat);
                scaledQuantizationTables[table.destinationIdentifier] = quantizationMatrixFloat;
            }
        } else if (marker == JpegConstants.DHT_MARKER) {
            final DhtSegment dhtSegment = new DhtSegment(marker, segmentData);
            for (final HuffmanTable table : dhtSegment.huffmanTables) {
                final DhtSegment.HuffmanTable[] tables;
                if (table.tableClass == 0) {
                    tables = huffmanDCTables;
                } else if (table.tableClass == 1) {
                    tables = huffmanACTables;
                } else {
                    throw new ImagingException("Invalid huffman table class " + table.tableClass);
                }
                if (0 > table.destinationIdentifier || table.destinationIdentifier >= tables.length) {
                    throw new ImagingException("Invalid huffman table identifier " + table.destinationIdentifier);
                }
                tables[table.destinationIdentifier] = table;
            }
        }
        return true;
    }
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.
src/main/java/org/apache/commons/imaging/formats/jpeg/decoder/JpegDecoder.java