privatestaticfinallongbadAttributeLimit=10;// pretty arbitrary, but avoids very long wait on large non-DICOM files, and still permits the occasional bad ones
...
...
@@ -225,8 +225,6 @@ public class AttributeList extends TreeMap<AttributeTag,Attribute> {
// otherwise can be as large as it needs to be
}
privatestaticbooleanhaveScannedForCodecs;
protectedbooleandecompressPixelData=true;// NOT static ... must be explicitly set to false for each instance constructed !
||vl==0x3030){// handle reserved bytes incorrectly set to ASCII zero characters, not zero :) ! (000872)
vl=i.readUnsigned32();
byteOffset+=4;
}
...
...
@@ -659,6 +658,8 @@ System.err.println("AttributeList.read(): "+tag+" encountered incorrect short Va
byteOffset+=vl;
}
elseif(vl==0xffffffffl&&tag.equals(TagFromName.PixelData)/* && i.getTransferSyntaxInUse().isEncapsulated()*/){// assume encapsulated in case TS is not recognized
//boolean unencapsulatePixelData = ???; // incomplete experiments with deferring not just decompression, but also unencapsulation
//if (unencapsulatePixelData) {
intwordsPerFrame=rows*columns*samplesPerPixel;
//System.err.println("Undefined length encapsulated Pixel Data: words per frame "+wordsPerFrame);
TransferSyntaxts=i.getTransferSyntaxInUse();
...
...
@@ -669,7 +670,7 @@ System.err.println("AttributeList.read(): "+tag+" encountered incorrect short Va
// when constructing EncapsulatedInputStream, take care whether or not to enable JPEG EOI detection to allow fragment spanning, and if not, whether to use one fragment per frame or all fragments in one frame
@@ -889,72 +890,11 @@ System.err.println("AttributeList.read(): "+tag+" encountered incorrect short Va
}
}
else{
if(!haveScannedForCodecs){
//System.err.println("AttributeList.read(): Scanning for ImageIO plugin codecs");
ImageIO.scanForPlugins();
haveScannedForCodecs=true;
}
CompressedFrameDecoder.scanForCodecs();
pixelDataWasActuallyDecompressed=true;
System.err.println("Based on Transfer Syntax, colorSpaceWillBeConvertedToRGBDuringDecompression = "+colorSpaceWillBeConvertedToRGBDuringDecompression);
if(readerWanted!=null){
ImageReaderreader=null;
ImageReaderSpireaderSpi=null;
StringreaderDescription=null;
StringreaderVendorName=null;
StringreaderVersion=null;
// Do NOT assume that first reader found is the best one ... check them all and make explicit choices ...
// prefer any other reader to the standard one, since the standard one is limited, and any other is most likely JAI JIIO
reader=otherReader;
readerSpi=otherReaderSpi;
readerDescription=otherReaderDescription;
readerVendorName=otherReaderVendorName;
readerVersion=otherReaderVersion;
//System.err.println("Choosing reader from "+readerDescription+" "+readerVendorName+" "+readerVersion+" over Standard JPEG Image Reader");
}
}
}
if(reader!=null){
// The JAI JIIO JPEG reader is OK since it handles both 8 and 12 bit JPEGExtended, but the "standard" reader that comes with the JRE only supports 8 bit
// Arguably 8 bits in JPEGExtended is not valid (PS3.5 10.2) but since it is sometimes encountered, deal with it if we can, else throw specific exception ...
thrownewDicomException("Reader "+readerDescription+" "+readerVendorName+" "+readerVersion+" does not support extended lossy JPEG Transfer Syntax "+tsuid+" other than for 8 bit data");
}
System.err.println("Using reader from "+readerDescription+" "+readerVendorName+" "+readerVersion);
//OurIIOReadProgressListener progressListener = new OurIIOReadProgressListener();
//reader.reset(); // NB. will also remove listeners, which we aren't using ... not strictly necessary if following setInput() actually removes anything cached, as it is supposed to
&&e.toString().equals("javax.imageio.IIOException: Inconsistent metadata read from stream")){
thrownewDicomException("Reader "+readerDescription+" "+readerVendorName+" "+readerVersion+" does not support JPEG images with components numbered from 0");
thrownewDicomException("Reader "+reader.getOriginatingProvider().getDescription(Locale.US)+" "+reader.getOriginatingProvider().getVendorName()+" "+reader.getOriginatingProvider().getVersion()+" does not support JPEG images with components numbered from 0");
}
}
//System.err.println("Back from frame reader.readAll()");
//System.err.println("AttributeList.read(): read of compressed bytes into buffers done in "+(System.currentTimeMillis()-startReadCompressedBytesTime)+" ms");
// // follows pattern of EncapsulatedInputStream.readItemTag() but updates local byteOffset
// AttributeTag itemTag = readAttributeTag(i);
// byteOffset+=4;
// long itemLength = i.readUnsigned32(); // always implicit VR form for items and delimiters
// byteOffset+=4;
// if (itemTag.equals(TagFromName.SequenceDelimitationItem)) {
// sequenceDelimiterEncountered = true;
// }
// else if (!itemTag.equals(TagFromName.Item)) {
// throw new IOException("Unexpected DICOM tag "+itemTag+" (vl="+itemLength+") in encapsulated data whilst expecting Item or SequenceDelimitationItem");
// }
// else {
// i.skipInsistently(itemLength);
// byteOffset+=itemLength;
// }
// }
//System.err.println("AttributeList.read(): skip of encapsulated bytes done in "+(System.currentTimeMillis()-startSkipEncapsulatedBytesTime)+" ms");
// a = new OtherByteAttributeOnDisk(TagFromName.PixelData,byteOffset-startOffset+1,i,startOffset); // this will not work if data is actually read - haven't written necessary class to hold encapsulated data yet :(
// allocating and reading all bytes into byte[] runs into int length limit four times as early (as well as transiently requiring ludicrous amount of memory)
// compromise by reading in blocks ... this actually turns out to be yet faster than reading entire byte array
byte[]byteBuffer=newbyte[BYTE_BUFFER_SIZE];
intshortsRemaining=len;
longbytesRemaining=((long)len)*4;
while(shortsRemaining>0){
intbytesToRead=byteBuffer.length;
if(bytesRemaining<bytesToRead){
bytesToRead=(int)bytesRemaining;
}
readInsistently(byteBuffer,0,bytesToRead);
{
intbcount=0;
if(bigEndian){
while(bcount<bytesToRead){
w[offset++]=((byteBuffer[bcount++]<<24)&0xff000000)+((byteBuffer[bcount++]<<16)&0x00ff0000)+((byteBuffer[bcount++]<<8)&0x0000ff00)+(byteBuffer[bcount++]&0xff);// assumes left to right evaluation
}
}
else{
while(bcount<bytesToRead){
w[offset++]=(byteBuffer[bcount++]&0xff)+((byteBuffer[bcount++]<<8)&0x0000ff00)+((byteBuffer[bcount++]<<16)&0x00ff0000)+((byteBuffer[bcount++]<<24)&0xff000000);// assumes left to right evaluation