01: /*
02: * $RCSfile: InterpAverage.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.2 $
09: * $Date: 2005/12/09 01:42:36 $
10: * $State: Exp $
11: */package com.sun.media.jai.util;
12:
13: import javax.media.jai.Interpolation;
14:
15: /**
16: * An <code>Interpolation</code> class which performs simple averaging of
17: * all pixels within a specified neighborhood. It is used by the
18: * "SubsampleAverage" operation implementations.
19: *
20: * @since JAI 1.1.2
21: */
22: public class InterpAverage extends Interpolation {
23: /**
24: * Creates an <code>InterpAverage</code> instance having the supplied
25: * dimensions. The left and top padding are
26: * <code>(blockX - 1)/2</code> and
27: * <code>(blockY - 1)/2</code>, respectively. The
28: * <code>subsampleBitsH</code> and <code>subsampleBitsV</code> instance
29: * variables are set to 32.
30: *
31: * @param blockX The width of the interpolation block.
32: * @param blockY The height of the interpolation block.
33: *
34: * @throws IllegalArgumentException if either parameter is non-positive.
35: */
36: public InterpAverage(int blockX, int blockY) {
37: super (blockX, blockY, (blockX - 1) / 2, blockX - 1
38: - (blockX - 1) / 2, (blockY - 1) / 2, blockY - 1
39: - (blockY - 1) / 2, 32, 32);
40:
41: if (blockX <= 0 || blockY <= 0) {
42: throw new IllegalArgumentException(
43: "blockX <= 0 || blockY <= 0");
44: }
45: }
46:
47: /**
48: * Returns the average of all elements in <code>samples</code>;
49: * <code>xfrac</code> is ignored.
50: */
51: public int interpolateH(int[] samples, int xfrac) {
52: int numSamples = samples.length;
53: double total = 0.0;
54: for (int i = 0; i < numSamples; i++) {
55: total += samples[i] / numSamples;
56: }
57: return (int) (total + 0.5);
58: }
59:
60: /**
61: * Returns the average of all elements in <code>samples</code>;
62: * <code>xfrac</code> is ignored.
63: */
64: public float interpolateH(float[] samples, float xfrac) {
65: int numSamples = samples.length;
66: float total = 0.0F;
67: for (int i = 0; i < numSamples; i++) {
68: total += samples[i] / numSamples;
69: }
70: return total;
71: }
72:
73: /**
74: * Returns the average of all elements in <code>samples</code>;
75: * <code>xfrac</code> is ignored.
76: */
77: public double interpolateH(double[] samples, float xfrac) {
78: int numSamples = samples.length;
79: double total = 0.0;
80: for (int i = 0; i < numSamples; i++) {
81: total += samples[i] / numSamples;
82: }
83: return total;
84: }
85: }
|