annotate common-bioformats/src/main/java/digilib/image/BioFormatsDocuImage.java @ 1132:d47513632da5

additional annotationSafeTokenUrl for https url, used with passwords. we don't always use https for issues with self-signed certs.
author robcast
date Tue, 13 Nov 2012 19:29:23 +0100
parents f34891279a6e
children
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
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
15 import ome.xml.model.primitives.PositiveInteger;
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
16
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
17 import loci.common.services.DependencyException;
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
18 import loci.common.services.ServiceException;
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
19 import loci.common.services.ServiceFactory;
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
20 import loci.formats.FormatException;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
21 import loci.formats.IFormatWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
22 import loci.formats.ImageReader;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
23 import loci.formats.ImageWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
24 import loci.formats.gui.BufferedImageReader;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
25 import loci.formats.gui.BufferedImageWriter;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
26 import loci.formats.meta.DummyMetadata;
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
27 import loci.formats.meta.IMetadata;
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
28 import loci.formats.meta.MetadataRetrieve;
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
29 import loci.formats.meta.MetadataStore;
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
30 import loci.formats.ome.OMEXMLMetadata;
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
31 import loci.formats.services.OMEXMLService;
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
32
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
33 import digilib.io.FileOpException;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
34 import digilib.io.ImageInput;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
35 import digilib.util.ImageSize;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
36
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
37 /**
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
38 * @author casties
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 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
41 public class BioFormatsDocuImage extends DocuImageImpl {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
42
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
43 private BufferedImage img;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
44 private Object imageSize;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
45 private RenderingHints renderHint;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
46 private ImageReader reader;
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
47 private OMEXMLMetadata meta;
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
48
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
49 /*
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
50 * (non-Javadoc)
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
51 *
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
52 * @see digilib.image.DocuImageImpl#identify(digilib.io.ImageInput)
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
53 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
54 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
55 public ImageInput identify(ImageInput ii) throws IOException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
56 ImageReader reader = new ImageReader();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
57 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
58 reader.setId(ii.getFile().getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
59 } catch (FormatException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
60 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
61 e.printStackTrace();
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 int width = reader.getSizeX();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
64 int height = reader.getSizeY();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
65 String fmt = reader.getFormat();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
66
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
67 String mt = "";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
68 if (fmt.equalsIgnoreCase("Tagged Image File Format")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
69 mt = "image/tiff";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
70 } else if (fmt.equalsIgnoreCase("JPEG")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
71 mt = "image/jpeg";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
72 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
73
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
74 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
75 ii.setSize(new ImageSize(width, height));
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
76 ii.setMimetype(mt);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
77 return ii;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
78 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
79
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
80 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
81 public void loadImage(ImageInput ii) throws FileOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
82 logger.debug("loadImage: " + ii);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
83 this.input = ii;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
84 reader = new ImageReader();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
85 try {
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
86 // construct the object that stores OME-XML metadata
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
87 ServiceFactory factory = new ServiceFactory();
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
88 OMEXMLService service = factory.getInstance(OMEXMLService.class);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
89 meta = service.createOMEXMLMetadata();
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
90
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
91 // set up the reader and associate it with the input file
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
92 reader = new ImageReader();
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
93 reader.setMetadataStore(meta);
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
94 reader.setId(ii.getFile().getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
95 BufferedImageReader biReader = BufferedImageReader.makeBufferedImageReader(reader);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
96 img = biReader.openImage(0);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
97 logger.debug("image loaded: " + img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
98 } catch (FormatException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
99 throw new FileOpException("Unable to load image format: " + e);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
100 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
101 throw new FileOpException("Unable to load image file: " + e);
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
102 } catch (ServiceException e) {
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
103 // TODO Auto-generated catch block
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
104 e.printStackTrace();
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
105 } catch (DependencyException e) {
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
106 // TODO Auto-generated catch block
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
107 e.printStackTrace();
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
108 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
109 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
110
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
111 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
112 public void scale(double scaleX, double scaleY) throws ImageOpException {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
113 logger.debug("scale: " + scaleX);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
114 /* 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
115 if ((scaleX <= 0.5) && (quality > 1)) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
116 int bl = (int) Math.floor(1 / scaleX);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
117 // blur(bl);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
118 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
119 /* then scaled */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
120 AffineTransformOp scaleOp = new AffineTransformOp(AffineTransform.getScaleInstance(scaleX, scaleY), renderHint);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
121 img = scaleOp.filter(img, null);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
122 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
123 // invalidate image size
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
124 imageSize = null;
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
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
127 public void setQuality(int qual) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
128 quality = qual;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
129 renderHint = new RenderingHints(null);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
130 // hint.put(RenderingHints.KEY_ANTIALIASING,
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
131 // RenderingHints.VALUE_ANTIALIAS_OFF);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
132 // setup interpolation quality
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
133 if (qual > 0) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
134 logger.debug("quality q1");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
135 renderHint.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
136 } else {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
137 logger.debug("quality q0");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
138 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
139 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
140 }
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 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
143 // setup Crop
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
144 img = img.getSubimage(x_off, y_off, width, height);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
145 logger.debug("CROP:" + img.getWidth() + "x" + img.getHeight());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
146 // invalidate image size
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
147 imageSize = null;
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
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
150 @Override
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
151 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
152 logger.debug("writeImage");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
153 File outFile;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
154 String filext = ".jpg";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
155 if (mt.equals("image/png")) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
156 filext = ".png";
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
157 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
158 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
159 outFile = File.createTempFile("biof_temp", filext);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
160 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
161 throw new FileOpException(e.toString());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
162 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
163 // save image to file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
164 ImageWriter iw = new ImageWriter();
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 * try { //iw.setMetadataRetrieve(new DummyMetadata());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
167 * //iw.setSeries(0); //iw.setId(outFile.getAbsolutePath());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
168 * //logger.debug("writer="+iw); } catch (FormatException e) { throw new
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
169 * FileOpException(e.toString()); } catch (IOException e) { // TODO
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
170 * Auto-generated catch block e.printStackTrace(); } /* if
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
171 * (mt.endsWith("png")) { iw = }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
172 */
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
173 BufferedImageWriter writer = BufferedImageWriter.makeBufferedImageWriter(iw);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
174 try {
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
175 logger.debug("setting metadata "+meta);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
176 iw.setMetadataRetrieve(meta);
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
177 logger.debug("writing to file " + outFile);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
178 writer.setId(outFile.getAbsolutePath());
979
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
179 logger.debug("fixing metadata "+meta);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
180 iw.setInterleaved(reader.isInterleaved());
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
181 iw.setWriteSequentially(true);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
182 meta.setPixelsSizeX(new PositiveInteger(img.getWidth()), 0);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
183 meta.setPixelsSizeY(new PositiveInteger(img.getHeight()), 0);
f34891279a6e bio-formats codec now works sometimes (only mo=q0 and only mo=jpg).
robcast
parents: 973
diff changeset
184 meta.setPixelsSizeC(new PositiveInteger(img.getColorModel().getNumComponents()), 0);
973
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
185 logger.debug("saving image " + img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
186 writer.saveImage(0, img);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
187 logger.debug("closing file");
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
188 writer.close();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
189 } catch (FormatException e1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
190 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
191 e1.printStackTrace();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
192 } catch (IOException e1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
193 // TODO Auto-generated catch block
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
194 e1.printStackTrace();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
195 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
196 // now send file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
197 FileInputStream inFile = null;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
198 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
199 inFile = new FileInputStream(outFile);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
200 byte dataBuffer[] = new byte[4096];
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
201 int len;
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
202 while ((len = inFile.read(dataBuffer)) != -1) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
203 // copy out file
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
204 ostream.write(dataBuffer, 0, len);
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
205 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
206 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
207 throw new FileOpException(e.toString());
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
208 } finally {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
209 try {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
210 if (inFile != null) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
211 inFile.close();
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
212 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
213 } catch (IOException e) {
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
214 // nothing to do
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
215 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
216 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
217
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
218 }
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
219
55572a4bbf68 DocuImage implementation using Bio-Formats library (doesn't work yet).
robcast
parents:
diff changeset
220 }