Changeset 6949


Ignore:
Timestamp:
09/16/10 13:21:30 (9 years ago)
Author:
melissa
Message:

Ensure that LUTs are properly preserved when using a virtual stack. Closes #557.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/src/loci/plugins/in/ImagePlusReader.java

    r6881 r6949  
    155155    final ImagePlus imp = new ImagePlus(title, stack); 
    156156 
    157     // NB: Save individual planar LUTs as properties, for later access. 
    158     // This step is necessary because ImageStack.addSlice only extracts the 
    159     // pixels from the ImageProcessor, and does not preserve the ColorModel. 
    160     // Later, Colorizer can use the LUTs when wrapping into a CompositeImage. 
    161     for (int i=0; i<luts.size(); i++) { 
    162       final LUT lut = luts.get(i); 
    163       if (lut != null) imp.setProperty(PROP_LUT + i, lut); 
    164     } 
    165  
     157    saveLUTs(imp, luts); 
    166158    return imp; 
    167159  } 
     
    255247    // create image stack 
    256248    final ImageStack stack; 
    257     if (options.isVirtual()) stack = createVirtualStack(process, s); 
     249    if (options.isVirtual()) stack = createVirtualStack(process, s, luts); 
    258250    else stack = readPlanes(process, s, luts); 
    259251 
     
    273265      vip.setReader(reader); 
    274266      imp = vip; 
     267      saveLUTs(imp, luts); 
    275268    } 
    276269    else imp = createImage(title, stack, luts); 
     
    296289  } 
    297290 
    298   private ImageStack createVirtualStack(ImportProcess process, int s) 
    299     throws FormatException, IOException 
     291  private ImageStack createVirtualStack(ImportProcess process, int s, 
     292    List<LUT> luts) throws FormatException, IOException 
    300293  { 
    301294    final ImporterOptions options = process.getOptions(); 
     
    316309      virtualStack.addSlice(label); 
    317310    } 
     311 
     312    if (luts != null) { 
     313      for (int c=0; c<cCount; c++) { 
     314        int index = reader.getIndex(0, c, 0); 
     315        ImageProcessor ip = reader.openProcessors(index)[0]; 
     316        final ColorModel cm = ip.getColorModel(); 
     317        final LUT lut = cm instanceof LUT ? (LUT) cm : null; 
     318        luts.add(lut); 
     319      } 
     320    } 
     321 
    318322    return virtualStack; 
    319323  } 
     
    591595  } 
    592596 
     597  private static void saveLUTs(ImagePlus imp, List<LUT> luts) { 
     598    // NB: Save individual planar LUTs as properties, for later access. 
     599    // This step is necessary because ImageStack.addSlice only extracts the 
     600    // pixels from the ImageProcessor, and does not preserve the ColorModel. 
     601    // Later, Colorizer can use the LUTs when wrapping into a CompositeImage. 
     602    for (int i=0; i<luts.size(); i++) { 
     603      final LUT lut = luts.get(i); 
     604      if (lut != null) { 
     605        imp.setProperty(PROP_LUT + i, lut); 
     606      } 
     607    } 
     608  } 
     609 
    593610} 
Note: See TracChangeset for help on using the changeset viewer.