Open Zipped DCM via OpenURL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Open Zipped DCM via OpenURL

Jason NoSpam
Hi,

I am trying to extend ImageJ so it can open up zipped dicom (.dcm)  files via the URL open command.  We are doing this so we can open a zipped-dicom  using ImageJ api (from our applet) and not by using "File/Open" menu manually".  The OpenURL class can open a zipped TIFF so I thought this wouldn't be too  tricky :) . I was able to figure out how to modify the openURL class to handle  zipped DCM.  But I am confused about how to modify the ij.plugin.DICOM  (http://rsb.info.nih.gov/ij/developer/source/ij/plugin/DICOM.java.html) so it  can handle an input stream as the TiffDecoder  (http://rsb.info.nih.gov/ij/developer/source/ij/io/TiffDecoder.java.html ) does  for opening TIFFs via a URL.

Below is the class for opening a ZIP that I  extended at the end to handle a zip that contains a .dcm file.  Some  advice/pointers greatly appreciated -- thanks in advance for your  help!

/** Opens the ZIP compressed TIFF at the specified URL.  */
ImagePlus openZip(URL url) throws IOException  {
IJ.showProgress(0.01);
URLConnection uc = url.openConnection();
int  fileSize = uc.getContentLength(); // compressed size
fileSize *=2; //  estimate uncompressed size
InputStream in =  uc.getInputStream();
ZipInputStream zin = new  ZipInputStream(in);
ByteArrayOutputStream out = new  ByteArrayOutputStream();
byte[] buf = new byte[4096];
ZipEntry entry =  zin.getNextEntry();
if (entry==null)
return null;
String name =  entry.getName();
//double fileSize = entry.getSize(); //returns  -1

//If zip contains a TIF file
if (name.endsWith(".tif")) {
int  len;
int byteCount = 0;
int progress = 0;
while (true) {
len =  zin.read(buf);
if (len<0) break;
out.write(buf, 0, len);
byteCount  +=  len;
IJ.showProgress((double)(byteCount%fileSize)/fileSize);
}
zin.close();
byte[]  bytes = out.toByteArray();
IJ.showProgress(1.0);
return openTiff(new  ByteArrayInputStream(bytes), name);
}

/*  --------------------------------
Start for Zip contains a dcm  file
---------------------------------- */
else if (name.endsWith(".dcm"))  {
int len;
int byteCount = 0;
int progress = 0;
while (true)  {
len = zin.read(buf);
if (len<0) break;
out.write(buf, 0,  len);
byteCount +=  len;
IJ.showProgress((double)(byteCount%fileSize)/fileSize);
}
zin.close();
byte[]  bytes = out.toByteArray();
IJ.showProgress(1.0);
return  IJ.runPlugIn("ij.plugin.DICOM", name);
}
/*  --------------------------------
End for Zip contains a dcm  file
---------------------------------- */
else
throw new  IOException("This ZIP archive does not appear to contain a TIFF or DCM  file");
}
}
 
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1ยข/min.