001: /*
002: * $RCSfile: HistogramOpImage.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:27 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.opimage;
013:
014: import java.awt.Rectangle;
015: import java.awt.image.DataBuffer;
016: import java.awt.image.Raster;
017: import java.awt.image.RenderedImage;
018: import java.util.LinkedList;
019: import java.util.ListIterator;
020: import javax.media.jai.Histogram;
021: import javax.media.jai.PixelAccessor;
022: import javax.media.jai.ROI;
023: import javax.media.jai.StatisticsOpImage;
024: import javax.media.jai.UnpackedImageData;
025:
026: /**
027: * An <code>OpImage</code> implementing the "Histogram" operation as
028: * described in <code>javax.media.jai.operator.HistogramDescriptor</code>.
029: *
030: * @see javax.media.jai.Histogram
031: * @see javax.media.jai.operator.HistogramDescriptor
032: * @see HistogramCRIF
033: */
034: final class HistogramOpImage extends StatisticsOpImage {
035:
036: /** Number of bins per band. */
037: private int[] numBins;
038:
039: /** The low value checked inclusive for each band. */
040: private double[] lowValue;
041:
042: /** The high value checked exclusive for each band. */
043: private double[] highValue;
044:
045: /** The number of bands of the source image. */
046: private int numBands;
047:
048: private final boolean tileIntersectsROI(int tileX, int tileY) {
049: if (roi == null) { // ROI is entire tile
050: return true;
051: } else {
052: return roi.intersects(tileXToX(tileX), tileYToY(tileY),
053: tileWidth, tileHeight);
054: }
055: }
056:
057: /**
058: * Constructs an <code>HistogramOpImage</code>.
059: *
060: * @param source The source image.
061: */
062: public HistogramOpImage(RenderedImage source, ROI roi, int xStart,
063: int yStart, int xPeriod, int yPeriod, int[] numBins,
064: double[] lowValue, double[] highValue) {
065: super (source, roi, xStart, yStart, xPeriod, yPeriod);
066:
067: numBands = source.getSampleModel().getNumBands();
068:
069: this .numBins = new int[numBands];
070: this .lowValue = new double[numBands];
071: this .highValue = new double[numBands];
072:
073: for (int b = 0; b < numBands; b++) {
074: this .numBins[b] = numBins.length == 1 ? numBins[0]
075: : numBins[b];
076: this .lowValue[b] = lowValue.length == 1 ? lowValue[0]
077: : lowValue[b];
078: this .highValue[b] = highValue.length == 1 ? highValue[0]
079: : highValue[b];
080: }
081: }
082:
083: protected String[] getStatisticsNames() {
084: String[] names = new String[1];
085: names[0] = "histogram";
086: return names;
087: }
088:
089: protected Object createStatistics(String name) {
090: if (name.equalsIgnoreCase("histogram")) {
091: return new Histogram(numBins, lowValue, highValue);
092: } else {
093: return java.awt.Image.UndefinedProperty;
094: }
095: }
096:
097: protected void accumulateStatistics(String name, Raster source,
098: Object stats) {
099: Histogram histogram = (Histogram) stats;
100: histogram.countPixels(source, roi, xStart, yStart, xPeriod,
101: yPeriod);
102: }
103: }
|