Update of /cvsroot/jrman/drafts/src/org/jrman/util
In directory sc8-pr-cvs1:/tmp/cvs-serv17576/src/org/jrman/util
Modified Files:
SamplesFilter.java
Log Message:
Implemented correct filtering for mipmap creation.
Index: SamplesFilter.java
===================================================================
RCS file: /cvsroot/jrman/drafts/src/org/jrman/util/SamplesFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SamplesFilter.java 25 Jun 2003 17:14:05 -0000 1.1
--- SamplesFilter.java 3 Jul 2003 17:57:52 -0000 1.2
***************
*** 20,23 ****
--- 20,26 ----
package org.jrman.util;
+ import org.jrman.maps.MipMap;
+ import org.jrman.maps.MipMap.Mode;
+
public abstract class SamplesFilter {
***************
*** 82,85 ****
--- 85,145 ----
dst[dstOffset + (dstRowLength * row + col) * bandCount + band] = sum;
}
+ }
+
+ private int getValue(byte[] src, int s, int t, int size, Mode sMode, Mode tMode, int band) {
+ if (s < 0 || s >= size) {
+ if (sMode == MipMap.Mode.BLACK)
+ return (band == 3 ? 255 : 0);
+ else if (sMode == MipMap.Mode.CLAMP)
+ s = Calc.clamp(s, 0, size - 1);
+ else if (sMode == MipMap.Mode.PERIODIC)
+ s &= (size - 1);
+ }
+ if (t < 0 || t >= size) {
+ if (tMode == MipMap.Mode.BLACK)
+ return (band == 3 ? 255 : 0);
+ else if (tMode == MipMap.Mode.CLAMP)
+ t = Calc.clamp(t, 0, size - 1);
+ else if (tMode == MipMap.Mode.PERIODIC)
+ t &= (size - 1);
+ }
+ return src[(size * t + s) * 4 + band] & 0xff;
+ }
+
+ public void doFilter(
+ byte[] src,
+ int srcSize,
+ byte[] dst,
+ int dstRowLength,
+ int colCount,
+ int rowCount,
+ int horizontalStep,
+ int verticalStep,
+ MipMap.Mode sMode,
+ MipMap.Mode tMode) {
+ for (int row = 0; row < rowCount; row++)
+ for (int col = 0; col < colCount; col++)
+ for (int band = 0; band < 4; band++) {
+ float sum = 0f;
+ for (int sampleRow = 0; sampleRow < height; sampleRow++)
+ for (int sampleCol = 0; sampleCol < width; sampleCol++) {
+ int srcRow = row * verticalStep + sampleRow - height / 2;
+ int srcCol = col * horizontalStep + sampleCol - width / 2;
+ int value = getValue(src, srcCol, srcRow, srcSize, sMode, tMode, band);
+ int amplitudeOffset = sampleRow * width + sampleCol;
+ sum += value * amplitude[amplitudeOffset];
+ }
+ sum /= amplitudeSum;
+ dst[(dstRowLength * row + col) * 4 + band] =
+ (byte) Calc.clamp(sum, 0f, 255f);
+ }
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public int getWidth() {
+ return width;
}
|