annotate common-bioformats/src/main/java/digilib/image/BioFormatsDocuImage.java @ 973:55572a4bbf68

DocuImage implementation using Bio-Formats library (doesn't work yet).
author robcast
date Thu, 26 Jan 2012 15:02:29 +0100
parents
children f34891279a6e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
1 /**
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
2 *
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
3 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
4 package digilib.image;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
5
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
6 import java.awt.RenderingHints;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
7 import java.awt.geom.AffineTransform;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
8 import java.awt.image.AffineTransformOp;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
9 import java.awt.image.BufferedImage;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
10 import java.io.File;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
11 import java.io.FileInputStream;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
12 import java.io.IOException;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
13 import java.io.OutputStream;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
14
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
15 import loci.formats.FormatException;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
16 import loci.formats.IFormatWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
17 import loci.formats.ImageReader;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
18 import loci.formats.ImageWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
19 import loci.formats.gui.BufferedImageReader;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
20 import loci.formats.gui.BufferedImageWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
21 import loci.formats.meta.DummyMetadata;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
22 import loci.formats.meta.MetadataRetrieve;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
23
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
24 import digilib.io.FileOpException;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
25 import digilib.io.ImageInput;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
26 import digilib.util.ImageSize;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
27
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
28 /**
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
29 * @author casties
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
30 *
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
31 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
32 public class BioFormatsDocuImage extends DocuImageImpl {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
33
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
34 private BufferedImage img;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
35 private Object imageSize;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
36 private RenderingHints renderHint;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
37 private ImageReader reader;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
38
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
39 /*
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
40 * (non-Javadoc)
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
41 *
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
42 * @see digilib.image.DocuImageImpl#identify(digilib.io.ImageInput)
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
43 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
44 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
45 public ImageInput identify(ImageInput ii) throws IOException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
46 ImageReader reader = new ImageReader();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
47 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
48 reader.setId(ii.getFile().getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
49 } catch (FormatException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
50 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
51 e.printStackTrace();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
52 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
53 int width = reader.getSizeX();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
54 int height = reader.getSizeY();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
55 String fmt = reader.getFormat();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
56
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
57 String mt = "";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
58 if (fmt.equalsIgnoreCase("Tagged Image File Format")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
59 mt = "image/tiff";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
60 } else if (fmt.equalsIgnoreCase("JPEG")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
61 mt = "image/jpeg";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
62 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
63
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
64 logger.debug("BioFormats identify: width=" + width + " height=" + height + " format=" + fmt + " mimetype=" + mt);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
65 ii.setSize(new ImageSize(width, height));
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
66 ii.setMimetype(mt);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
67 return ii;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
68 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
69
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
70 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
71 public void loadImage(ImageInput ii) throws FileOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
72 logger.debug("loadImage: " + ii);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
73 this.input = ii;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
74 reader = new ImageReader();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
75 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
76 reader.setId(ii.getFile().getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
77 BufferedImageReader biReader = BufferedImageReader.makeBufferedImageReader(reader);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
78 img = biReader.openImage(0);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
79 logger.debug("image loaded: " + img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
80 } catch (FormatException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
81 throw new FileOpException("Unable to load image format: " + e);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
82 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
83 throw new FileOpException("Unable to load image file: " + e);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
84 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
85 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
86
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
87 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
88 public void scale(double scaleX, double scaleY) throws ImageOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
89 logger.debug("scale: " + scaleX);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
90 /* for downscaling in high quality the image is blurred first */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
91 if ((scaleX <= 0.5) && (quality > 1)) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
92 int bl = (int) Math.floor(1 / scaleX);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
93 // blur(bl);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
94 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
95 /* then scaled */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
96 AffineTransformOp scaleOp = new AffineTransformOp(AffineTransform.getScaleInstance(scaleX, scaleY), renderHint);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
97 img = scaleOp.filter(img, null);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
98 logger.debug("scaled to " + img.getWidth() + "x" + img.getHeight() + " img=" + img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
99 // invalidate image size
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
100 imageSize = null;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
101 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
102
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
103 public void setQuality(int qual) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
104 quality = qual;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
105 renderHint = new RenderingHints(null);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
106 // hint.put(RenderingHints.KEY_ANTIALIASING,
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
107 // RenderingHints.VALUE_ANTIALIAS_OFF);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
108 // setup interpolation quality
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
109 if (qual > 0) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
110 logger.debug("quality q1");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
111 renderHint.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
112 } else {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
113 logger.debug("quality q0");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
114 renderHint.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
115 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
116 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
117
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
118 public void crop(int x_off, int y_off, int width, int height) throws ImageOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
119 // setup Crop
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
120 img = img.getSubimage(x_off, y_off, width, height);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
121 logger.debug("CROP:" + img.getWidth() + "x" + img.getHeight());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
122 // invalidate image size
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
123 imageSize = null;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
124 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
125
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
126 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
127 public void writeImage(String mt, OutputStream ostream) throws ImageOpException, FileOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
128 logger.debug("writeImage");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
129 File outFile;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
130 String filext = ".jpg";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
131 if (mt.equals("image/png")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
132 filext = ".png";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
133 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
134 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
135 outFile = File.createTempFile("biof_temp", filext);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
136 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
137 throw new FileOpException(e.toString());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
138 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
139 // save image to file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
140 ImageWriter iw = new ImageWriter();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
141 /*
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
142 * try { //iw.setMetadataRetrieve(new DummyMetadata());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
143 * //iw.setSeries(0); //iw.setId(outFile.getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
144 * //logger.debug("writer="+iw); } catch (FormatException e) { throw new
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
145 * FileOpException(e.toString()); } catch (IOException e) { // TODO
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
146 * Auto-generated catch block e.printStackTrace(); } /* if
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
147 * (mt.endsWith("png")) { iw = }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
148 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
149 BufferedImageWriter writer = BufferedImageWriter.makeBufferedImageWriter(iw);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
150 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
151 logger.debug("setting metadata");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
152 iw.setMetadataRetrieve((MetadataRetrieve) reader.getMetadataStore());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
153 logger.debug("writing to file " + outFile);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
154 writer.setId(outFile.getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
155 logger.debug("saving image " + img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
156 writer.saveImage(0, img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
157 logger.debug("closing file");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
158 writer.close();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
159 } catch (FormatException e1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
160 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
161 e1.printStackTrace();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
162 } catch (IOException e1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
163 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
164 e1.printStackTrace();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
165 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
166 // now send file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
167 FileInputStream inFile = null;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
168 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
169 inFile = new FileInputStream(outFile);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
170 byte dataBuffer[] = new byte[4096];
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
171 int len;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
172 while ((len = inFile.read(dataBuffer)) != -1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
173 // copy out file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
174 ostream.write(dataBuffer, 0, len);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
175 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
176 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
177 throw new FileOpException(e.toString());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
178 } finally {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
179 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
180 if (inFile != null) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
181 inFile.close();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
182 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
183 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
184 // nothing to do
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
185 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
186 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
187
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
188 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
189
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
190 }