Example #1
0
  /** Initializes the ImageDisplay. */
  private synchronized void initialize() {
    if (source == null) return;

    componentWidth = source.getWidth();
    componentHeight = source.getHeight();

    setPreferredSize(new Dimension(componentWidth, componentHeight));

    this.sampleModel = source.getSampleModel();

    // First check whether the opimage has already set a suitable ColorModel
    this.colorModel = source.getColorModel();
    if (this.colorModel == null) {
      // If not, then create one.
      this.colorModel = PlanarImage.createColorModel(this.sampleModel);
      if (this.colorModel == null) {
        throw new IllegalArgumentException("no color model");
      }
    }

    minTileX = source.getMinTileX();
    maxTileX = source.getMinTileX() + source.getNumXTiles() - 1;
    minTileY = source.getMinTileY();
    maxTileY = source.getMinTileY() + source.getNumYTiles() - 1;
    tileWidth = source.getTileWidth();
    tileHeight = source.getTileHeight();
    tileGridXOffset = source.getTileGridXOffset();
    tileGridYOffset = source.getTileGridYOffset();
  }
Example #2
0
  private synchronized void computeHistogram(Rectangle visibleRect, PlanarImage image) {
    int channels = image.getSampleModel().getNumBands();

    Histogram hist = new Histogram(256, 256, 512, channels);

    bins = hist.getBins();

    // Raster raster = image.getData(visibleRect);
    Rectangle bounds = visibleRect; // image.getBounds();
    int pixel[] = null;

    int maxPixels = 256;
    int incX = bounds.width >= 2 * maxPixels ? bounds.width / maxPixels : 1;
    int incY = bounds.height >= 2 * maxPixels ? bounds.height / maxPixels : 1;

    double log2 = Math.log(2);

    int minTileX = image.XToTileX(bounds.x);
    int maxTileX = image.XToTileX(bounds.x + bounds.width - 1);
    int minTileY = image.YToTileY(bounds.y);
    int maxTileY = image.YToTileY(bounds.y + bounds.height - 1);

    for (int tx = minTileX; tx <= maxTileX; tx++)
      for (int ty = minTileY; ty <= maxTileY; ty++) {
        Raster raster = image.getTile(tx, ty);

        int minX = Math.max(bounds.x, raster.getMinX());
        int maxX = Math.min(bounds.x + bounds.width, raster.getMinX() + raster.getWidth());
        int minY = Math.max(bounds.y, raster.getMinY());
        int maxY = Math.min(bounds.y + bounds.height, raster.getMinY() + raster.getHeight());

        for (int x = minX; x < maxX; x += incX)
          for (int y = minY; y < maxY; y += incY) {
            pixel = raster.getPixel(x, y, pixel);
            for (int c = 0; c < channels; c++) {
              int v = (int) (511 * logTable[pixel[c]] / (16 * log2));
              if (v > 255) bins[c][v - 256]++;
              else bins[c][0]++;
            }
          }
      }

    bins = hist.getBins();
  }