Changeset 6324
- Timestamp:
- 05/17/10 00:40:34 (10 years ago)
- Location:
- trunk/components/loci-plugins/src/loci/plugins
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/loci-plugins/src/loci/plugins/colorize/Colorizer.java
r6322 r6324 326 326 327 327 private static byte[][] promptForColor(int channel, int series) { 328 /* 328 329 CustomColorChooser chooser = new CustomColorChooser( 329 330 "Color Chooser - Channel " + channel, null, series, channel); 330 331 331 332 Color color = chooser.getColor(); 333 */ 334 Color color = null; // CTR TEMP 332 335 if (color == null) return null; 333 336 double redIncrement = ((double) color.getRed()) / 255; -
trunk/components/loci-plugins/src/loci/plugins/in/ColorDialog.java
r6271 r6324 1 1 // 2 // C ustomColorChooser.java2 // ColorDialog.java 3 3 // 4 4 … … 24 24 */ 25 25 26 package loci.plugins. colorize;26 package loci.plugins.in; 27 27 28 28 import ij.gui.GenericDialog; … … 37 37 import java.awt.event.TextEvent; 38 38 import java.awt.event.TextListener; 39 import java.util.ArrayList; 39 40 import java.util.List; 40 41 42 import loci.plugins.util.ImageProcessorReader; 41 43 import loci.plugins.util.WindowTools; 42 44 43 45 /** 44 * Adapted from {@link ij.gui.ColorChooser}. 46 * Bio-Formats Importer custom color chooser dialog box. 47 * 48 * Heavily adapted from {@link ij.gui.ColorChooser}. 45 49 * ColorChooser is not used because there is no way to change the slider 46 50 * labels—this means that we can't record macros in which custom colors … … 48 52 * 49 53 * <dl><dt><b>Source code:</b></dt> 50 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/src/loci/plugins/C ustomColorChooser.java">Trac</a>,51 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/loci-plugins/src/loci/plugins/C ustomColorChooser.java">SVN</a></dd></dl>54 * <dd><a href="https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/src/loci/plugins/ColorDialog.java">Trac</a>, 55 * <a href="https://skyking.microscopy.wisc.edu/svn/java/trunk/components/loci-plugins/src/loci/plugins/ColorDialog.java">SVN</a></dd></dl> 52 56 * 53 57 * @author Melissa Linkert linkert at wisc.edu 58 * @author Curtis Rueden ctrueden at wisc.edu 54 59 */ 55 public class CustomColorChooser implements TextListener { 56 List<TextField> colors; 57 Panel panel; 58 Color initialColor; 59 int red, green, blue; 60 String title; 60 public class ColorDialog extends ImporterDialog { 61 61 62 private int series, channel;62 // -- Constants -- 63 63 64 public CustomColorChooser(String title, Color initialColor, int series, 65 int channel) 66 { 67 this.title = title; 68 if (initialColor == null) initialColor = Color.BLACK; 69 this.initialColor = initialColor; 70 red = initialColor.getRed(); 71 green = initialColor.getGreen(); 72 blue = initialColor.getBlue(); 73 this.series = series; 74 this.channel = channel; 64 /** Default custom colors for each channel. */ 65 private static final Color[] DEFAULT_COLORS = { 66 Color.red, 67 Color.green, 68 Color.blue, 69 Color.white, 70 Color.cyan, 71 Color.magenta, 72 Color.yellow 73 }; 74 private static final Dimension SWATCH_SIZE = new Dimension(100, 50); 75 76 // -- Fields -- 77 78 private List<TextField> colors; 79 80 // -- Constructor -- 81 82 public ColorDialog(ImportProcess process) { 83 super(process); 75 84 } 76 85 77 // -- ColorChooser APImethods --86 // -- ImporterDialog methods -- 78 87 79 /** 80 * Displays a color selection dialog and returns the color 81 * selected by the user. 82 */ 83 public Color getColor() { 84 GenericDialog gd = new GenericDialog(title); 85 gd.addSlider(makeLabel("Red:"), 0, 255, red); 86 gd.addSlider(makeLabel("Green:"), 0, 255, green); 87 gd.addSlider(makeLabel("Blue:"), 0, 255, blue); 88 89 panel = new Panel(); 90 Dimension prefSize = new Dimension(100, 50); 91 panel.setPreferredSize(prefSize); 92 panel.setMinimumSize(prefSize); 93 panel.setBackground(initialColor); 94 gd.addPanel(panel, GridBagConstraints.CENTER, new Insets(10, 0, 0, 0)); 95 96 colors = WindowTools.getNumericFields(gd); 97 for (int i=0; i<colors.size(); i++) { 98 colors.get(i).addTextListener(this); 99 } 100 gd.showDialog(); 101 if (gd.wasCanceled()) return null; 102 int red = (int) gd.getNextNumber(); 103 int green = (int) gd.getNextNumber(); 104 int blue = (int) gd.getNextNumber(); 105 return new Color(red, green, blue); 88 @Override 89 protected boolean needPrompt() { 90 return !process.isWindowless() && options.isColorModeCustom(); 106 91 } 107 92 108 public void textValueChanged(TextEvent e) { 109 int red = getColorValue(0); 110 int green = getColorValue(1); 111 int blue = getColorValue(2); 112 panel.setBackground(new Color(red, green, blue)); 113 panel.repaint(); 93 @Override 94 protected GenericDialog constructDialog() { 95 GenericDialog gd = new GenericDialog("Bio-Formats Custom Colorization"); 96 97 // CTR TODO - avoid problem with MAX_SLIDERS in GenericDialog 98 final ImageProcessorReader reader = process.getReader(); 99 final List<Panel> swatches = new ArrayList<Panel>(); 100 for (int s=0; s<process.getSeriesCount(); s++) { 101 if (!options.isSeriesOn(s)) continue; 102 reader.setSeries(s); 103 for (int c=0; c<reader.getSizeC(); c++) { 104 Color color = options.getCustomColor(s, c); 105 if (color == null) color = DEFAULT_COLORS[c % DEFAULT_COLORS.length]; 106 gd.addSlider(makeLabel("Red:", s, c), 0, 255, color.getRed()); 107 gd.addSlider(makeLabel("Green:", s, c), 0, 255, color.getGreen()); 108 gd.addSlider(makeLabel("Blue:", s, c), 0, 255, color.getBlue()); 109 110 Panel swatch = createSwatch(color); 111 gd.addPanel(swatch, GridBagConstraints.CENTER, new Insets(5, 0, 5, 0)); 112 swatches.add(swatch); 113 } 114 } 115 116 // change swatch colors when sliders move 117 List<TextField> colorFields = gd.getNumericFields(); 118 attachListeners(colorFields, swatches); 119 120 WindowTools.addScrollBars(gd); 121 122 return gd; 123 } 124 125 @Override 126 protected boolean harvestResults(GenericDialog gd) { 127 final ImageProcessorReader reader = process.getReader(); 128 for (int s=0; s<process.getSeriesCount(); s++) { 129 if (!options.isSeriesOn(s)) continue; 130 reader.setSeries(s); 131 for (int c=0; c<reader.getSizeC(); c++) { 132 int red = (int) gd.getNextNumber(); 133 int green = (int) gd.getNextNumber(); 134 int blue = (int) gd.getNextNumber(); 135 Color color = new Color(red, green, blue); 136 options.setCustomColor(s, c, color); 137 } 138 } 139 return true; 114 140 } 115 141 116 142 // -- Helper methods -- 117 143 118 private int getColorValue(int index) { 119 int color = (int) Tools.parseDouble(colors.get(index).getText()); 144 private String makeLabel(String baseLabel, int s, int c) { 145 return "Series_" + s + "_Channel_" + c + "_" + baseLabel; 146 } 147 148 private Panel createSwatch(Color color) { 149 Panel swatch = new Panel(); 150 swatch.setPreferredSize(SWATCH_SIZE); 151 swatch.setMinimumSize(SWATCH_SIZE); 152 swatch.setMaximumSize(SWATCH_SIZE); 153 swatch.setBackground(color); 154 return swatch; 155 } 156 157 private void attachListeners(List<TextField> colors, List<Panel> swatches) { 158 int colorIndex = 0, swatchIndex = 0; 159 while (colorIndex < colors.size()) { 160 final TextField redField = colors.get(colorIndex++); 161 final TextField greenField = colors.get(colorIndex++); 162 final TextField blueField = colors.get(colorIndex++); 163 final Panel swatch = swatches.get(swatchIndex++); 164 TextListener textListener = new TextListener() { 165 public void textValueChanged(TextEvent e) { 166 int red = getColorValue(redField); 167 int green = getColorValue(greenField); 168 int blue = getColorValue(blueField); 169 swatch.setBackground(new Color(red, green, blue)); 170 swatch.repaint(); 171 } 172 }; 173 redField.addTextListener(textListener); 174 greenField.addTextListener(textListener); 175 blueField.addTextListener(textListener); 176 } 177 } 178 179 private int getColorValue(TextField colorField) { 180 int color = 0; 181 try { 182 color = Integer.parseInt(colorField.getText()); 183 } 184 catch (NumberFormatException exc) { } 120 185 if (color < 0) color = 0; 121 186 if (color > 255) color = 255; … … 123 188 } 124 189 125 private String makeLabel(String baseLabel) {126 return "Series_" + series + "_Channel_" + channel + "_" + baseLabel;127 }128 129 190 } -
trunk/components/loci-plugins/src/loci/plugins/in/ImagePlusReader.java
r6322 r6324 131 131 132 132 // beginning timing 133 long startTime = System.currentTimeMillis(); 134 long time = startTime; 133 startTiming(); 135 134 136 135 ImageProcessorReader reader = process.getReader(); … … 147 146 for (int s=0; s<reader.getSeriesCount(); s++) { 148 147 if (!options.isSeriesOn(s)) continue; 149 reader.setSeries(s); 150 151 boolean[] load = new boolean[reader.getImageCount()]; 152 int cBegin = process.getCBegin(s); 153 int cEnd = process.getCEnd(s); 154 int cStep = process.getCStep(s); 155 int zBegin = process.getZBegin(s); 156 int zEnd = process.getZEnd(s); 157 int zStep = process.getZStep(s); 158 int tBegin = process.getTBegin(s); 159 int tEnd = process.getTEnd(s); 160 int tStep = process.getTStep(s); 161 for (int c=cBegin; c<=cEnd; c+=cStep) { 162 for (int z=zBegin; z<=zEnd; z+=zStep) { 163 for (int t=tBegin; t<=tEnd; t+=tStep) { 164 //int index = r.isOrderCertain() ? r.getIndex(z, c, t) : c; 165 int index = reader.getIndex(z, c, t); 166 load[index] = true; 167 } 168 } 169 } 170 int total = 0; 171 for (int j=0; j<reader.getImageCount(); j++) if (load[j]) total++; 172 173 FileInfo fi = new FileInfo(); 174 175 // populate other common FileInfo fields 176 String idDir = process.getIdLocation() == null ? 177 null : process.getIdLocation().getParent(); 178 if (idDir != null && !idDir.endsWith(File.separator)) { 179 idDir += File.separator; 180 } 181 fi.fileName = process.getIdName(); 182 fi.directory = idDir; 183 184 ImageStack stackB = null; // for byte images (8-bit) 185 ImageStack stackS = null; // for short images (16-bit) 186 ImageStack stackF = null; // for floating point images (32-bit) 187 ImageStack stackO = null; // for all other images (24-bit RGB) 188 189 Region region = process.getCropRegion(s); 190 int sizeX = reader.getSizeX(), sizeY = reader.getSizeY(); 191 if (options.doCrop()) { 192 // bounds checking for cropped region 193 if (region.x < 0) region.x = 0; 194 if (region.y < 0) region.y = 0; 195 if (region.width <= 0 || region.x + region.width > sizeX) { 196 region.width = sizeX - region.x; 197 } 198 if (region.height <= 0 || region.y + region.height > sizeY) { 199 region.height = sizeX - region.y; 200 } 201 } 202 else { 203 // obtain entire image plane 204 region.x = region.y = 0; 205 region.width = sizeX; 206 region.height = sizeY; 207 } 208 209 int q = 0; 210 211 // dump OME-XML to ImageJ's description field, if available 212 try { 213 ServiceFactory factory = new ServiceFactory(); 214 OMEXMLService service = factory.getInstance(OMEXMLService.class); 215 fi.description = service.getOMEXML(process.getOMEMetadata()); 216 } 217 catch (DependencyException de) { } 218 catch (ServiceException se) { } 219 220 if (options.isVirtual()) { 221 boolean doMerge = false; //options.isMergeChannels(); 222 boolean doColorize = false; //options.isColorize(); 223 224 reader.setSeries(s); 225 // NB: ImageJ 1.39+ is required for VirtualStack 226 BFVirtualStack virtualStackB = new BFVirtualStack(options.getId(), 227 reader, doColorize, doMerge, options.isRecord()); 228 stackB = virtualStackB; 229 if (doMerge) { 230 for (int j=0; j<reader.getImageCount(); j++) { 231 int[] zct = reader.getZCTCoords(j); 232 if (zct[1] > 0) continue; 233 ChannelMerger channelMerger = new ChannelMerger(reader); 234 int index = channelMerger.getIndex(zct[0], zct[1], zct[2]); 235 String label = constructSliceLabel(index, 236 channelMerger, process.getOMEMetadata(), s, 237 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 238 virtualStackB.addSlice(label); 239 } 240 } 241 else { 242 for (int j=0; j<reader.getImageCount(); j++) { 243 String label = constructSliceLabel(j, 244 reader, process.getOMEMetadata(), s, 245 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 246 virtualStackB.addSlice(label); 247 } 248 } 249 } 250 else { 251 // CTR CHECK 252 //if (r.isIndexed()) colorModels = new IndexColorModel[r.getSizeC()]; 253 254 for (int i=0; i<reader.getImageCount(); i++) { 255 if (!load[i]) continue; 256 257 // limit message update rate 258 long clock = System.currentTimeMillis(); 259 if (clock - time >= 100) { 260 String sLabel = reader.getSeriesCount() > 1 ? 261 ("series " + (s + 1) + ", ") : ""; 262 String pLabel = "plane " + (i + 1) + "/" + total; 263 notifyListeners(new StatusEvent("Reading " + sLabel + pLabel)); 264 time = clock; 265 } 266 notifyListeners(new StatusEvent(q++, total, null)); 267 268 String label = constructSliceLabel(i, 269 reader, process.getOMEMetadata(), s, 270 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 271 272 // get image processor for ith plane 273 ImageProcessor[] p; 274 p = reader.openProcessors(i, region.x, region.y, 275 region.width, region.height); 276 ImageProcessor ip = p[0]; 277 if (p.length > 1) { 278 ip = ImagePlusTools.makeRGB(p).getProcessor(); 279 } 280 if (ip == null) { 281 throw new FormatException("Cannot read ImageProcessor #" + i); 282 } 283 284 // CTR CHECK 285 //int channel = r.getZCTCoords(i)[1]; 286 //if (colorModels != null && p.length == 1) { 287 // colorModels[channel] = (IndexColorModel) ip.getColorModel(); 288 //} 289 290 // add plane to image stack 291 int w = region.width, h = region.height; 292 if (ip instanceof ByteProcessor) { 293 if (stackB == null) stackB = new ImageStack(w, h); 294 stackB.addSlice(label, ip); 295 } 296 else if (ip instanceof ShortProcessor) { 297 if (stackS == null) stackS = new ImageStack(w, h); 298 stackS.addSlice(label, ip); 299 } 300 else if (ip instanceof FloatProcessor) { 301 // merge image plane into existing stack if possible 302 if (stackB != null) { 303 ip = ip.convertToByte(true); 304 stackB.addSlice(label, ip); 305 } 306 else if (stackS != null) { 307 ip = ip.convertToShort(true); 308 stackS.addSlice(label, ip); 309 } 310 else { 311 if (stackF == null) stackF = new ImageStack(w, h); 312 stackF.addSlice(label, ip); 313 } 314 } 315 else if (ip instanceof ColorProcessor) { 316 if (stackO == null) stackO = new ImageStack(w, h); 317 stackO.addSlice(label, ip); 318 } 319 } 320 } 321 322 notifyListeners(new StatusEvent(1, 1, "Creating image")); 323 324 ImagePlus impB = createImage(stackB, s, fi); 325 ImagePlus impS = createImage(stackS, s, fi); 326 ImagePlus impF = createImage(stackF, s, fi); 327 ImagePlus impO = createImage(stackO, s, fi); 328 if (impB != null) imps.add(impB); 329 if (impS != null) imps.add(impS); 330 if (impF != null) imps.add(impF); 331 if (impO != null) imps.add(impO); 148 readSeries(s, imps); 332 149 } 333 150 … … 365 182 366 183 return imps; 184 } 185 186 private long startTime, time; 187 private void startTiming() { 188 startTime = time = System.currentTimeMillis(); 189 } 190 private void updateTiming(int s, int i, int current, int total) { 191 ImageProcessorReader reader = process.getReader(); 192 long clock = System.currentTimeMillis(); 193 if (clock - time >= 100) { 194 String sLabel = reader.getSeriesCount() > 1 ? 195 ("series " + (s + 1) + ", ") : ""; 196 String pLabel = "plane " + (i + 1) + "/" + total; 197 notifyListeners(new StatusEvent("Reading " + sLabel + pLabel)); 198 time = clock; 199 } 200 notifyListeners(new StatusEvent(current, total, null)); 201 } 202 203 private FileInfo createFileInfo() { 204 FileInfo fi = new FileInfo(); 205 206 // populate common FileInfo fields 207 String idDir = process.getIdLocation() == null ? 208 null : process.getIdLocation().getParent(); 209 if (idDir != null && !idDir.endsWith(File.separator)) { 210 idDir += File.separator; 211 } 212 fi.fileName = process.getIdName(); 213 fi.directory = idDir; 214 215 // dump OME-XML to ImageJ's description field, if available 216 try { 217 ServiceFactory factory = new ServiceFactory(); 218 OMEXMLService service = factory.getInstance(OMEXMLService.class); 219 fi.description = service.getOMEXML(process.getOMEMetadata()); 220 } 221 catch (DependencyException de) { } 222 catch (ServiceException se) { } 223 224 return fi; 225 } 226 227 private void readSeries(int s, List<ImagePlus> imps) 228 throws FormatException, IOException 229 { 230 ImageProcessorReader reader = process.getReader(); 231 ImporterOptions options = process.getOptions(); 232 reader.setSeries(s); 233 234 boolean[] load = getPlanesToLoad(s); 235 int current = 0, total = 0; 236 for (int j=0; j<reader.getImageCount(); j++) if (load[j]) total++; 237 238 FileInfo fi = createFileInfo(); 239 240 ImageStack stackB = null; // for byte images (8-bit) 241 ImageStack stackS = null; // for short images (16-bit) 242 ImageStack stackF = null; // for floating point images (32-bit) 243 ImageStack stackO = null; // for all other images (24-bit RGB) 244 245 Region region = process.getCropRegion(s); 246 247 if (options.isVirtual()) { 248 boolean doMerge = false; //options.isMergeChannels(); 249 boolean doColorize = false; //options.isColorize(); 250 251 reader.setSeries(s); 252 // NB: ImageJ 1.39+ is required for VirtualStack 253 BFVirtualStack virtualStackB = new BFVirtualStack(options.getId(), 254 reader, doColorize, doMerge, options.isRecord()); 255 stackB = virtualStackB; 256 if (doMerge) { 257 for (int j=0; j<reader.getImageCount(); j++) { 258 int[] zct = reader.getZCTCoords(j); 259 if (zct[1] > 0) continue; 260 ChannelMerger channelMerger = new ChannelMerger(reader); 261 int index = channelMerger.getIndex(zct[0], zct[1], zct[2]); 262 String label = constructSliceLabel(index, 263 channelMerger, process.getOMEMetadata(), s, 264 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 265 virtualStackB.addSlice(label); 266 } 267 } 268 else { 269 for (int j=0; j<reader.getImageCount(); j++) { 270 String label = constructSliceLabel(j, 271 reader, process.getOMEMetadata(), s, 272 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 273 virtualStackB.addSlice(label); 274 } 275 } 276 } 277 else { 278 // CTR CHECK 279 //if (r.isIndexed()) colorModels = new IndexColorModel[r.getSizeC()]; 280 281 for (int i=0; i<reader.getImageCount(); i++) { 282 if (!load[i]) continue; 283 284 // limit message update rate 285 updateTiming(s, i, current++, total); 286 287 String label = constructSliceLabel(i, 288 reader, process.getOMEMetadata(), s, 289 process.getZCount(s), process.getCCount(s), process.getTCount(s)); 290 291 // get image processor for ith plane 292 ImageProcessor[] p; 293 p = reader.openProcessors(i, region.x, region.y, 294 region.width, region.height); 295 ImageProcessor ip = p[0]; 296 if (p.length > 1) { 297 ip = ImagePlusTools.makeRGB(p).getProcessor(); 298 } 299 if (ip == null) { 300 throw new FormatException("Cannot read ImageProcessor #" + i); 301 } 302 303 // CTR CHECK 304 //int channel = r.getZCTCoords(i)[1]; 305 //if (colorModels != null && p.length == 1) { 306 // colorModels[channel] = (IndexColorModel) ip.getColorModel(); 307 //} 308 309 // add plane to image stack 310 int w = region.width, h = region.height; 311 if (ip instanceof ByteProcessor) { 312 if (stackB == null) stackB = new ImageStack(w, h); 313 stackB.addSlice(label, ip); 314 } 315 else if (ip instanceof ShortProcessor) { 316 if (stackS == null) stackS = new ImageStack(w, h); 317 stackS.addSlice(label, ip); 318 } 319 else if (ip instanceof FloatProcessor) { 320 // merge image plane into existing stack if possible 321 if (stackB != null) { 322 ip = ip.convertToByte(true); 323 stackB.addSlice(label, ip); 324 } 325 else if (stackS != null) { 326 ip = ip.convertToShort(true); 327 stackS.addSlice(label, ip); 328 } 329 else { 330 if (stackF == null) stackF = new ImageStack(w, h); 331 stackF.addSlice(label, ip); 332 } 333 } 334 else if (ip instanceof ColorProcessor) { 335 if (stackO == null) stackO = new ImageStack(w, h); 336 stackO.addSlice(label, ip); 337 } 338 } 339 } 340 341 notifyListeners(new StatusEvent(1, 1, "Creating image")); 342 343 ImagePlus impB = createImage(stackB, s, fi); 344 ImagePlus impS = createImage(stackS, s, fi); 345 ImagePlus impF = createImage(stackF, s, fi); 346 ImagePlus impO = createImage(stackO, s, fi); 347 if (impB != null) imps.add(impB); 348 if (impS != null) imps.add(impS); 349 if (impF != null) imps.add(impF); 350 if (impO != null) imps.add(impO); 351 } 352 353 private boolean[] getPlanesToLoad(int s) { 354 ImageProcessorReader reader = process.getReader(); 355 boolean[] load = new boolean[reader.getImageCount()]; 356 int cBegin = process.getCBegin(s); 357 int cEnd = process.getCEnd(s); 358 int cStep = process.getCStep(s); 359 int zBegin = process.getZBegin(s); 360 int zEnd = process.getZEnd(s); 361 int zStep = process.getZStep(s); 362 int tBegin = process.getTBegin(s); 363 int tEnd = process.getTEnd(s); 364 int tStep = process.getTStep(s); 365 for (int c=cBegin; c<=cEnd; c+=cStep) { 366 for (int z=zBegin; z<=zEnd; z+=zStep) { 367 for (int t=tBegin; t<=tEnd; t+=tStep) { 368 //int index = r.isOrderCertain() ? r.getIndex(z, c, t) : c; 369 int index = reader.getIndex(z, c, t); 370 load[index] = true; 371 } 372 } 373 } 374 return load; 367 375 } 368 376 … … 453 461 // stackOrder, lut, r.getSeries(), null, hyper); 454 462 // } 455 //456 // // CTR FIXME457 // if (splitC || splitZ || splitT) {458 // imp = Slicer.reslice(imp, splitC, splitZ, splitT, hyper, stackOrder);459 // }460 463 // } 461 464 … … 493 496 } 494 497 495 /** Constructs slice label. */496 498 private String constructSliceLabel(int ndx, IFormatReader r, 497 499 IMetadata meta, int series, int zCount, int cCount, int tCount) -
trunk/components/loci-plugins/src/loci/plugins/in/ImportProcess.java
r6322 r6324 154 154 initializeCrop(); 155 155 156 step(ImportStep.COLORS); 157 if (cancel) return false; 158 initializeColors(); 159 156 160 step(ImportStep.METADATA); 157 161 if (cancel) return false; … … 305 309 public Region getCropRegion(int s) { 306 310 assertStep(ImportStep.STACK); 307 Region region = options.getCropRegion(s); 308 if (region != null) return region; 311 Region region = options.doCrop() ? options.getCropRegion(s) : null; 309 312 ImageProcessorReader r = getReader(); 310 return new Region(0, 0, r.getSizeX(), r.getSizeY()); 313 int sizeX = r.getSizeX(), sizeY = r.getSizeY(); 314 if (region == null) { 315 // entire image plane is the default region 316 region = new Region(0, 0, sizeX, sizeY); 317 } 318 else { 319 // bounds checking for cropped region 320 if (region.x < 0) region.x = 0; 321 if (region.y < 0) region.y = 0; 322 if (region.width <= 0 || region.x + region.width > sizeX) { 323 region.width = sizeX - region.x; 324 } 325 if (region.height <= 0 || region.y + region.height > sizeY) { 326 region.height = sizeX - region.y; 327 } 328 } 329 return region; 311 330 } 312 331 … … 457 476 /** Performed following ImportStep.CROP notification. */ 458 477 private void initializeCrop() { } 478 479 /** Performed following ImportStep.COLORS notification. */ 480 private void initializeColors() { } 459 481 460 482 /** Performed following ImportStep.METADATA notification. */ -
trunk/components/loci-plugins/src/loci/plugins/in/ImportStep.java
r6322 r6324 46 46 RANGE (5, "Confirming planar ranges"), 47 47 CROP (6, "Confirming crop region"), 48 METADATA (7, "Initializing metadata"), 49 COMPLETE (8, "Import preparations complete"); 48 COLORS (7, "Confirming colorization"), 49 METADATA (8, "Initializing metadata"), 50 COMPLETE (9, "Import preparations complete"); 50 51 51 52 // -- Static fields -- -
trunk/components/loci-plugins/src/loci/plugins/in/ImporterOptions.java
r6322 r6324 26 26 package loci.plugins.in; 27 27 28 import java.awt.Color; 28 29 import java.io.IOException; 29 30 import java.util.ArrayList; … … 132 133 private List<Region> cropRegion = new ArrayList<Region>(); 133 134 135 // color mode options 136 private List<List<Color>> customColors = new ArrayList<List<Color>>(); 137 134 138 // -- Constructor -- 135 139 … … 396 400 public void setCropRegion(int s, Region r) { set(cropRegion, s, r, null); } 397 401 402 // color mode options 403 public Color getCustomColor(int s, int c) { 404 List<Color> list = get(customColors, s, null); 405 if (list == null) return null; 406 return get(list, c, null); 407 } 408 public void setCustomColor(int s, int c, Color color) { 409 List<Color> list = get(customColors, s, null); 410 if (list == null) { 411 list = new ArrayList<Color>(); 412 set(customColors, s, list, null); 413 } 414 set(list, c, color, null); 415 } 416 398 417 // -- Helper methods - miscellaneous -- 399 418 -
trunk/components/loci-plugins/src/loci/plugins/in/ImporterPrompter.java
r6278 r6324 94 94 if (!promptCrop()) process.cancel(); 95 95 break; 96 case COLORS: 97 if (!promptColors()) process.cancel(); 98 break; 96 99 case METADATA: 97 100 break; … … 153 156 return dialog.showDialog() == OptionsDialog.STATUS_OK; 154 157 } 155 158 159 /** Prompts for color details, if necessary. */ 160 private boolean promptColors() { 161 ColorDialog dialog = new ColorDialog(process); 162 return dialog.showDialog() == OptionsDialog.STATUS_OK; 163 } 156 164 }
Note: See TracChangeset
for help on using the changeset viewer.