Package gov.nih.mipav.model.file
Class FileDicomJPEG
java.lang.Object
gov.nih.mipav.model.file.FileDicomJPEG
Class that reads a lossless compressed JPEG file. These are sometimes encapsulated in DICOM. The lossless decoder
uses a Huffman table to interpret values. For color images this file will have to be modified. Some code for color is
here but it isn't universal. There is a private class within this file that does the bit reading and packing. For
more information see the comments in front of that class. This code was ported from Huang and Smith's Cornell
software.
Copyright (c) 1993 Cornell University, Kongji Huang All rights reserved. Permission to use, copy, modify, and distribute this software and its documentation for research purposes, without fee, and without written agreement is hereby granted, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE CORNELL UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE CORNELL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Copyright (c) 1993 The Regents of the University of California, Brian C. Smith All rights reserved. Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without written agreement is hereby granted, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
IJG Copyright The authors make NO WARRANTY or representation, either express or implied, with respect to this software, its quality, accuracy, merchantability, or fitness for a particular purpose. This software is provided "AS IS", and you, its user, assume the entire risk as to its quality and accuracy. This software is copyright (C) 1991, 1992, Thomas G. Lane. All Rights Reserved except as specified below. Permission is hereby granted to use, copy, modify, and distribute this software (or portions thereof) for any purpose, without fee, subject to these conditions: (1) If any part of the source code for this software is distributed, then this README file must be included, with this copyright and no-warranty notice unaltered; and any additions, deletions, or changes to the original files must be clearly indicated in accompanying documentation. (2) If only executable code is distributed, then the accompanying documentation must state that "this software is based in part on the work of the Independent JPEG Group". (3) Permission for use of this software is granted only if the user accepts full responsibility for any undesirable consequences; the authors accept NO LIABILITY for damages of any kind. Permission is NOT granted for the use of any IJG author's name or company name in advertising or publicity relating to this software or products derived from it. This software may be referred to only as "the Independent JPEG Group's software". We specifically permit and encourage the use of this software as the basis of commercial products, provided that all warranty or liability claims are assumed by the product vendor.
- Version:
- 1.0 May 14, 2002
- Author:
- Neva Cherniavsky
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classThis class reads and packs the bits appropriately for interpreting the huffman codes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int[]Useful bit mask for getting appropriate bits out of number.private final byte[][]Read in DHT header.private final int[]Needed for color images.private final short[]Needed for color images.private intNumber of components in scan; 1 for black and white, 4 for color.private byteData precision.private final intHeight read in from DICOM file; only use if imageHeight isn't defined.private final intWidth read in from DICOM file; only use if imageWidth isn't defined.private static int[]Entry n is (-1 invalid input: '<'invalid input: '<' n) + 1; used to make a number negative.private static int[]Entry n is 2**(n-1); used to test whether we need to make a number negative.private final int[]Horizontal sample factor.private final byte[][]Read in DHT header.private byte[]Image data we're reading.private intImage height.private intImage width.private static final byteRequired marker in this standard.private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteMarker tags in JPEG header.private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private static final byteDOCUMENT ME!private final int[][]mincode[index] = minimum legal code at that index.private final short[][]mincode[index] = minimum legal code at that index.private intNumbers needed for restart.private final int[][]number of bits needed for code at index.private intNumber of components - 1 for black and white, 4 for color.private intShift by this when putting into int buffer.private intNumbers needed for restart.private intRestart interval.private intNumbers needed for restart.private byteByte indicating which location to use as the predictor.private final int[]Table number - always 0 for non-color images.private Vector<byte[]> private Vector<int[]> private final short[][]valptr[index] = pointer to where legal code values start.private final int[][]huffman value for code.private intprivate final int[]Vertical sample factor. -
Constructor Summary
ConstructorsConstructorDescriptionFileDicomJPEG(byte[] imageBuffer, int width, int height) Assigns image buffer and creates the other arrays needed to read in image.FileDicomJPEG(Vector<byte[]> v, Vector<int[]> v2, int width, int height) Assigns image buffer and creates the other arrays needed to read in image. -
Method Summary
Modifier and TypeMethodDescriptionprivate voiddecodeFirstRow(FileDicomJPEG.HuffTable table, short[][] curRowBuf) Decode the first raster line of samples at the start of the scan and at the beginning of each restart interval.private int[]decodeImage(int index) Decode the input stream.int[]Extracts the JPEG image by processing the byte image array.voidprivate voidfixHuffmanTable(int tableNum) Sets up Huffman table based on values read in header.private intgetAPPO(int index) Get APPO part of header.private intgetDHT(int index) Get the Huffman table.private intgetDRI(int index) Get DRI part of header.private intgetSOF(int index) Get the SOF part of header.private intgetSOS(int index) Get the SOS part of header.private intnextMarker(int index) Gets the next marker in the header.private intprocessRestart(int index) Check for a restart marker invalid input: '&' resynchronize decoder.private intprocessTables(int index) Process the header markers.private intskipVariable(int index) Skip this variable.
-
Field Details
-
M_SOF0
private static final byte M_SOF0Marker tags in JPEG header.- See Also:
-
M_SOF1
private static final byte M_SOF1DOCUMENT ME!- See Also:
-
M_SOF2
private static final byte M_SOF2DOCUMENT ME!- See Also:
-
M_SOF3
private static final byte M_SOF3DOCUMENT ME!- See Also:
-
M_SOF5
private static final byte M_SOF5DOCUMENT ME!- See Also:
-
M_SOF6
private static final byte M_SOF6DOCUMENT ME!- See Also:
-
M_SOF7
private static final byte M_SOF7DOCUMENT ME!- See Also:
-
M_JPG
private static final byte M_JPGDOCUMENT ME!- See Also:
-
M_SOF9
private static final byte M_SOF9DOCUMENT ME!- See Also:
-
M_SOF10
private static final byte M_SOF10DOCUMENT ME!- See Also:
-
M_SOF11
private static final byte M_SOF11DOCUMENT ME!- See Also:
-
M_SOF13
private static final byte M_SOF13DOCUMENT ME!- See Also:
-
M_SOF14
private static final byte M_SOF14DOCUMENT ME!- See Also:
-
M_SOF15
private static final byte M_SOF15DOCUMENT ME!- See Also:
-
M_DHT
private static final byte M_DHTDOCUMENT ME!- See Also:
-
M_RST0
private static final byte M_RST0DOCUMENT ME!- See Also:
-
M_RST1
private static final byte M_RST1DOCUMENT ME!- See Also:
-
M_RST2
private static final byte M_RST2DOCUMENT ME!- See Also:
-
M_RST3
private static final byte M_RST3DOCUMENT ME!- See Also:
-
M_RST4
private static final byte M_RST4DOCUMENT ME!- See Also:
-
M_RST5
private static final byte M_RST5DOCUMENT ME!- See Also:
-
M_RST6
private static final byte M_RST6DOCUMENT ME!- See Also:
-
M_RST7
private static final byte M_RST7DOCUMENT ME!- See Also:
-
M_SOI
private static final byte M_SOIDOCUMENT ME!- See Also:
-
M_EOI
private static final byte M_EOIDOCUMENT ME!- See Also:
-
M_SOS
private static final byte M_SOSDOCUMENT ME!- See Also:
-
M_DQT
private static final byte M_DQTDOCUMENT ME!- See Also:
-
M_DRI
private static final byte M_DRIDOCUMENT ME!- See Also:
-
M_APP0
private static final byte M_APP0Required marker in this standard.- See Also:
-
M_TEM
private static final byte M_TEMDOCUMENT ME!- See Also:
-
extendTest
private static int[] extendTestEntry n is 2**(n-1); used to test whether we need to make a number negative. -
extendOffset
private static int[] extendOffsetEntry n is (-1 invalid input: '<'invalid input: '<' n) + 1; used to make a number negative. -
bitMask
private final int[] bitMaskUseful bit mask for getting appropriate bits out of number. -
bits
private final byte[][] bitsRead in DHT header. Number of codes with bitlength of index. Thus, bits[2] = 1 means one code represented by 2 bits. bits[3] = 4 means four codes represented by 3 bits. 2D array necessary in case of color image - component #. -
componentId
private final int[] componentIdNeeded for color images. -
componentIndex
private final short[] componentIndexNeeded for color images. -
compsInScan
private int compsInScanNumber of components in scan; 1 for black and white, 4 for color. -
dataPrecision
private byte dataPrecisionData precision. -
dicomH
private final int dicomHHeight read in from DICOM file; only use if imageHeight isn't defined. -
dicomW
private final int dicomWWidth read in from DICOM file; only use if imageWidth isn't defined. -
hSampFactor
private final int[] hSampFactorHorizontal sample factor. -
huffval
private final byte[][] huffvalRead in DHT header. Huffman code values, used to determine Huffman table (value array). Also directly accessed when numbits > 8, since fast lookup is not possible. -
image
private byte[] imageImage data we're reading. -
imageHeight
private int imageHeightImage height. -
imageWidth
private int imageWidthImage width. -
maxcode
private final int[][] maxcodemincode[index] = minimum legal code at that index. -
mincode
private final short[][] mincodemincode[index] = minimum legal code at that index. -
nextRestartNum
private int nextRestartNumNumbers needed for restart. Hasn't been tested! -
numbits
private final int[][] numbitsnumber of bits needed for code at index. -
numComponents
private int numComponentsNumber of components - 1 for black and white, 4 for color. -
Pt
private int PtShift by this when putting into int buffer. -
restartInRows
private int restartInRowsNumbers needed for restart. Hasn't been tested! -
restartInterval
private int restartIntervalRestart interval. -
restartRowsToGo
private int restartRowsToGoNumbers needed for restart. Hasn't been tested! -
Ss
private byte SsByte indicating which location to use as the predictor. -
tableNo
private final int[] tableNoTable number - always 0 for non-color images. -
valptr
private final short[][] valptrvalptr[index] = pointer to where legal code values start. -
value
private final int[][] valuehuffman value for code. -
vSampFactor
private final int[] vSampFactorVertical sample factor. -
v
-
vIndex
private int vIndex -
v2
-
-
Constructor Details
-
FileDicomJPEG
public FileDicomJPEG(byte[] imageBuffer, int width, int height) Assigns image buffer and creates the other arrays needed to read in image.- Parameters:
imageBuffer- Image buffer.width- DOCUMENT ME!height- DOCUMENT ME!
-
FileDicomJPEG
Assigns image buffer and creates the other arrays needed to read in image.- Parameters:
width- DOCUMENT ME!height- DOCUMENT ME!imageBuffer- Image buffer.
-
-
Method Details
-
extractMultiJPEGImage
- Throws:
IOException
-
extractJPEGImage
Extracts the JPEG image by processing the byte image array.- Returns:
- image buffer - the JPEG image
- Throws:
IOException- DOCUMENT ME!
-
decodeFirstRow
Decode the first raster line of samples at the start of the scan and at the beginning of each restart interval. This includes modifying the component value so the real value, not the difference is returned.- Parameters:
table- Huffman table.curRowBuf- Current row buffer; 2D because if image is color, there are 4 components.
-
decodeImage
private int[] decodeImage(int index) Decode the input stream. This includes modifying the component value so the real value, not the difference is returned.- Parameters:
index- Index where we currently are in the image.- Returns:
- Buffer holding decompressed image.
-
fixHuffmanTable
private void fixHuffmanTable(int tableNum) Sets up Huffman table based on values read in header.- Parameters:
tableNum- Usually 0, haven't tested when it isn't.
-
getAPPO
private int getAPPO(int index) Get APPO part of header.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
getDHT
private int getDHT(int index) Get the Huffman table.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
getDRI
private int getDRI(int index) Get DRI part of header.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
getSOF
private int getSOF(int index) Get the SOF part of header.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
getSOS
private int getSOS(int index) Get the SOS part of header.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
nextMarker
private int nextMarker(int index) Gets the next marker in the header.- Parameters:
index- Index that we're at in the image array.- Returns:
- Last accessed index.
-
processRestart
private int processRestart(int index) Check for a restart marker invalid input: '&' resynchronize decoder. Haven't tested this at all.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
processTables
private int processTables(int index) Process the header markers.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-
skipVariable
private int skipVariable(int index) Skip this variable.- Parameters:
index- Index we're at in the image array.- Returns:
- Last accessed index.
-