Changeset 6766


Ignore:
Timestamp:
08/04/10 15:18:51 (9 years ago)
Author:
melissa
Message:

Fixed file export from ImageViewer. Closes #525.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/gui/ImageViewer.java

    r6520 r6766  
    7070import loci.formats.IFormatWriter; 
    7171import loci.formats.ImageWriter; 
     72import loci.formats.MetadataTools; 
    7273import loci.formats.meta.MetadataRetrieve; 
    7374import loci.formats.meta.MetadataStore; 
    7475import loci.formats.services.OMEReaderWriterService; 
    7576import loci.formats.services.OMEXMLService; 
     77 
     78import ome.xml.model.enums.DimensionOrder; 
     79import ome.xml.model.enums.EnumerationException; 
     80import ome.xml.model.enums.PixelType; 
     81import ome.xml.model.enums.handlers.DimensionOrderEnumHandler; 
     82import ome.xml.model.enums.handlers.PixelTypeEnumHandler; 
     83import ome.xml.model.primitives.PositiveInteger; 
    7684 
    7785import org.slf4j.Logger; 
     
    407415    wait(true); 
    408416    try { 
     417      if (omeMeta == null) { 
     418        omeMeta = omexmlService.createOMEXMLMetadata(); 
     419        omeMeta.setImageID(MetadataTools.createLSID("Image", 0), 0); 
     420        omeMeta.setPixelsID(MetadataTools.createLSID("Pixels", 0), 0); 
     421        omeMeta.setPixelsBinDataBigEndian(false, 0, 0); 
     422 
     423        String order = "XYCZT"; 
     424        if (in != null) order = in.getDimensionOrder(); 
     425 
     426        omeMeta.setPixelsDimensionOrder((DimensionOrder) 
     427          new DimensionOrderEnumHandler().getEnumeration(order), 0); 
     428        int type = AWTImageTools.getPixelType(images[0]); 
     429        String pixelType = FormatTools.getPixelTypeString(type); 
     430        omeMeta.setPixelsType( 
     431          (PixelType) new PixelTypeEnumHandler().getEnumeration(pixelType), 0); 
     432 
     433        int nBands = images[0].getRaster().getNumBands(); 
     434        int rgbChannelCount = (sizeC * sizeZ * sizeT) / nBands; 
     435        int realChannelCount = sizeC / rgbChannelCount; 
     436 
     437        for (int i=0; i<realChannelCount; i++) { 
     438          omeMeta.setChannelID(MetadataTools.createLSID("Channel", i, 0), i, 0); 
     439          omeMeta.setChannelSamplesPerPixel( 
     440            new PositiveInteger(rgbChannelCount), i, 0); 
     441        } 
     442 
     443        omeMeta.setPixelsSizeX(new PositiveInteger(images[0].getWidth()), 0); 
     444        omeMeta.setPixelsSizeY(new PositiveInteger(images[0].getHeight()), 0); 
     445        omeMeta.setPixelsSizeC(new PositiveInteger(sizeC), 0); 
     446        omeMeta.setPixelsSizeZ(new PositiveInteger(sizeZ), 0); 
     447        omeMeta.setPixelsSizeT(new PositiveInteger(sizeT), 0); 
     448      } 
     449      myWriter.setMetadataRetrieve(omexmlService.asRetrieve(omeMeta)); 
    409450      myWriter.setId(id); 
    410451      boolean stack = myWriter.canDoStacks(); 
     
    416457          progress.setProgress(i); 
    417458          boolean canceled = progress.isCanceled(); 
    418           myWriter.savePlane(i, images[i]); 
     459          myWriter.saveImage(i, images[i]); 
    419460          if (canceled) break; 
    420461        } 
     
    430471    catch (FormatException exc) { LOGGER.info("", exc); } 
    431472    catch (IOException exc) { LOGGER.info("", exc); } 
     473    catch (ServiceException exc) { LOGGER.info("", exc); } 
     474    catch (EnumerationException exc) { LOGGER.info("", exc); } 
    432475    wait(false); 
    433476  } 
Note: See TracChangeset for help on using the changeset viewer.