Update of /cvsroot/jrman/drafts/src/org/jrman/util
In directory sc8-pr-cvs1:/tmp/cvs-serv6208/src/org/jrman/util
Added Files:
GaussianSamplesFilter.java SamplesFilter.java
Log Message:
Implemented pixel filter support.
--- NEW FILE: GaussianSamplesFilter.java ---
/*
GaussianSamplesFilter.java
Copyright (C) 2003 Gerardo Horvilleur Martinez
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.jrman.util;
public class GaussianSamplesFilter extends SamplesFilter {
protected float filterFunc(float x, float y, float xWidth, float yWidth) {
x *= 2f / xWidth;
y *= 2f / yWidth;
return (float) Math.exp(-2f * (x * x + y * y));
}
}
--- NEW FILE: SamplesFilter.java ---
/*
SamplesFilter.java
Copyright (C) 2003 Gerardo Horvilleur Martinez
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.jrman.util;
public abstract class SamplesFilter {
protected int width;
protected int height;
protected float[] amplitude;
protected float amplitudeSum;
protected abstract float filterFunc(float x, float y, float xWidth, float yWidth);
public void init(int width, int height, float xWidth, float yWidth) {
this.width = width;
this.height = height;
amplitude = new float[width * height];
float xInc = xWidth / width;
float yInc = yWidth / height;
float y = -yWidth / 2f + yInc / 2f;
for (int row = 0; row < height; row++) {
float x = -xWidth / 2f + xInc / 2f;
for (int column = 0; column < width; column++) {
float a = filterFunc(x, y, xWidth, yWidth);
amplitude[row * width + column] = a;
amplitudeSum += a;
x += xInc;
}
y += yInc;
}
}
public void doFilter(
float[] src,
int srcOffset,
int srcRowLength,
float[] dst,
int dstOffset,
int dstRowLength,
int colCount,
int rowCount,
int horizontalStep,
int verticalStep,
int bandCount) {
for (int row = 0; row < rowCount; row++)
for (int col = 0; col < colCount; col++)
for (int band = 0; band < bandCount; band++) {
float sum = 0f;
for (int sampleRow = 0; sampleRow < height; sampleRow++)
for (int sampleCol = 0; sampleCol < width; sampleCol++) {
int offset =
srcOffset
+ (srcRowLength * (row * verticalStep + sampleRow)
+ col * horizontalStep
+ sampleCol)
* bandCount
+ band;
int amplitudeOffset = sampleRow * width + sampleCol;
sum += src[offset] * amplitude[amplitudeOffset];
}
sum /= amplitudeSum;
dst[dstOffset + (dstRowLength * row + col) * bandCount + band] = sum;
}
}
}
|