Example #1
0
 /** Removes references to images. */
 void discard() {
   combinedImage = null;
   displayedImage = null;
   displayedProjectedImage = null;
   projectedImage = null;
   renderedImage = null;
   clearList(gridImages);
   clearList(originalGridImages);
   clearTextureMap(gridImagesAsTextures);
   projectedImageAsTexture = null;
   renderedImageAsTexture = null;
   System.gc(); // force garbage collection
 }
Example #2
0
  /** Creates the images composing the grid when the color model is <code>GreyScale</code>. */
  private void createGridImagesForGreyScale() {
    int maxC = parent.getMaxC();
    List l = parent.getActiveChannelsInGrid();
    int n = l.size();
    clearList(gridImages);
    if (combinedImage != null) combinedImage.flush();
    switch (n) {
      case 0:
        for (int i = 0; i < maxC; i++) gridImages.add(null);
        combinedImage = null;
        break;
      case 1:
      case 2:
      case 3:
        if (isImageMappedRGB(l)) {
          BufferedImage image = parent.getCombinedGridImage();
          if (image == null) {
            for (int i = 0; i < maxC; i++) gridImages.add(null);
            break;
          }
          combinedImage = Factory.magnifyImage(gridRatio, image);

          int w = combinedImage.getWidth();
          int h = combinedImage.getHeight();

          DataBuffer buf = combinedImage.getRaster().getDataBuffer();
          List<ChannelData> list = parent.getSortedChannelData();
          Iterator<ChannelData> i = list.iterator();
          int index;
          while (i.hasNext()) {
            index = i.next().getIndex();
            if (l.contains(index)) {
              if (parent.isChannelRed(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.RED_MASK, Factory.RED_MASK, Factory.RED_MASK));
              } else if (parent.isChannelGreen(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.GREEN_MASK, Factory.GREEN_MASK, Factory.GREEN_MASK));
              } else if (parent.isChannelBlue(index)) {
                gridImages.add(
                    Factory.createBandImage(
                        buf, w, h, Factory.BLUE_MASK, Factory.BLUE_MASK, Factory.BLUE_MASK));
              }
            } else {
              gridImages.add(null);
            }
          }
        } else {
          retrieveGridImagesForGreyScale(l);
        }
        break;

      default:
        retrieveGridImagesForGreyScale(l);
    }
  }
Example #3
0
 /** Sets the images composing the grid. */
 void setGridImages() {
   if (gridImages.size() != 0) return;
   clearList(originalGridImages);
   if (gridImagesAsTextures.size() != 0) return;
   try {
     if (ImViewerAgent.hasOpenGLSupport()) createGridImagesAsTextures();
     else createGridImages();
   } catch (Exception e) {
     handleGridImageCreationException(e);
   }
 }
Example #4
0
 /** Creates the images composing the grid. */
 private void createGridImages() {
   // if (combinedImage == null) return;
   if (originalGridImages == null) originalGridImages = new ArrayList<BufferedImage>();
   clearList(gridImages);
   if (ImViewer.GREY_SCALE_MODEL.equals(parent.getColorModel())) {
     createGridImagesForGreyScale();
     return;
   }
   List l = parent.getActiveChannels();
   int maxC = parent.getMaxC();
   switch (l.size()) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       if (isImageMappedRGB(l) && !parent.isCompressed()) {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         int w = combinedImage.getWidth();
         int h = combinedImage.getHeight();
         DataBuffer buf = combinedImage.getRaster().getDataBuffer();
         List<ChannelData> list = parent.getSortedChannelData();
         Iterator<ChannelData> i = list.iterator();
         int index;
         while (i.hasNext()) {
           index = i.next().getIndex();
           if (parent.isChannelActive(index)) {
             if (parent.isChannelRed(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.RED_MASK, Factory.BLANK_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelGreen(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.GREEN_MASK, Factory.BLANK_MASK));
             } else if (parent.isChannelBlue(index)) {
               gridImages.add(
                   Factory.createBandImage(
                       buf, w, h, Factory.BLANK_MASK, Factory.BLANK_MASK, Factory.BLUE_MASK));
             }
           } else {
             gridImages.add(null);
           }
         }
       } else {
         retrieveGridImages();
       }
       break;
     default:
       retrieveGridImages();
   }
 }
Example #5
0
 /**
  * Sets the ratio of the grid image.
  *
  * @param gridRatio The value to set.
  */
 void setGridRatio(double gridRatio) {
   // if (ratio == 1) return; //We don't want to be too small.
   double max = ZoomGridAction.MAX_ZOOM_FACTOR;
   if (gridRatio > max) return;
   this.gridRatio = gridRatio;
   if (ImViewerAgent.hasOpenGLSupport()) return;
   if (CollectionUtils.isEmpty(originalGridImages)) {
     try {
       createGridImages();
     } catch (Exception e) {
       handleGridImageCreationException(e);
     }
     return;
   }
   int n = originalGridImages.size();
   clearList(gridImages);
   int maxC = parent.getMaxC();
   switch (n) {
     case 0:
       for (int i = 0; i < maxC; i++) gridImages.add(null);
       break;
     case 1:
     case 2:
     case 3:
       // TODO: Review that code.
       if (isImageMappedRGB(parent.getActiveChannels())) {
         try {
           createGridImages();
         } catch (Exception e) {
           handleGridImageCreationException(e);
         }
       } else {
         combinedImage = null;
         combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
         Iterator<BufferedImage> i = originalGridImages.iterator();
         while (i.hasNext()) {
           gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
         }
       }
       break;
     default:
       combinedImage = null;
       combinedImage = Factory.magnifyImage(gridRatio, renderedImage);
       Iterator<BufferedImage> i = originalGridImages.iterator();
       while (i.hasNext()) {
         gridImages.add(Factory.magnifyImage(gridRatio, i.next()));
       }
   }
 }
Example #6
0
  /**
   * Sets the rendered image.
   *
   * @param image The image to set.
   */
  void setRenderedImage(BufferedImage image) {
    renderedImage = null;
    displayedImage = null;
    combinedImage = null;
    clearList(gridImages);
    renderedImage = image;

    if (renderedImage != null) {
      if (init) {
        int imageWidth = image.getWidth();
        if (imageWidth < ImViewer.MINIMUM_SIZE) {
          ratio = 1;
          gridRatio = 1;
          setUnitBar(false);
        }
        if (imageWidth * ratio > ImViewer.MAXIMUM_SIZE)
          ratio = (double) ImViewer.MAXIMUM_SIZE / imageWidth;
        init = false;
      }
    }
  }
Example #7
0
 /** Clears the grid images when the color model changes. */
 void clearGridImages() {
   clearList(gridImages);
   if (gridImagesAsTextures != null) gridImagesAsTextures.clear();
   // if (originalGridImages != null) originalGridImages.clear();
 }