mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 22:30:00 +00:00
Move channels into image lib
This commit is contained in:
@@ -11,6 +11,7 @@ import net.jafama.FastMath;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.addons.image.util.ColorUtil.Channel;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@@ -38,38 +39,4 @@ public class ImageSampler implements NoiseSampler {
|
||||
return noise(seed, x, y);
|
||||
}
|
||||
|
||||
public enum Channel {
|
||||
RED {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 16) & 0xff;
|
||||
}
|
||||
},
|
||||
GREEN {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 8) & 0xff;
|
||||
}
|
||||
},
|
||||
BLUE {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return mashed & 0xff;
|
||||
}
|
||||
},
|
||||
GRAYSCALE {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (RED.getChannel(mashed) + GREEN.getChannel(mashed) + BLUE.getChannel(mashed)) / 3;
|
||||
}
|
||||
},
|
||||
ALPHA {
|
||||
@Override
|
||||
public int getChannel(int mashed) {
|
||||
return (mashed >> 24) & 0xff;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int getChannel(int mashed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.addons.image.util.ColorUtil.Channel;
|
||||
import com.dfsek.terra.addons.noise.config.templates.SamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.image.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
@@ -27,7 +28,7 @@ public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
private @Meta double frequency;
|
||||
|
||||
@Value("channel")
|
||||
private ImageSampler.@Meta Channel channel;
|
||||
private @Meta Channel channel;
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
|
||||
@@ -8,7 +8,9 @@ public class ColorUtil {
|
||||
private ColorUtil() {}
|
||||
|
||||
public static int distance(int a, int b) {
|
||||
return FastMath.abs(getRed(a) - getRed(b)) + FastMath.abs(getGreen(a) - getGreen(b)) + FastMath.abs(getBlue(a) - getBlue(b));
|
||||
return FastMath.abs(getRed(a) - getRed(b)) +
|
||||
FastMath.abs(getGreen(a) - getGreen(b)) +
|
||||
FastMath.abs(getBlue(a) - getBlue(b));
|
||||
}
|
||||
|
||||
public static int getRed(int rgb) {
|
||||
@@ -27,4 +29,42 @@ public class ColorUtil {
|
||||
return rgb >> 24 & 255;
|
||||
}
|
||||
|
||||
public static int getGrayscale(int rgb) {
|
||||
return (getRed(rgb) + getGreen(rgb) + getBlue(rgb)) / 3;
|
||||
}
|
||||
|
||||
public enum Channel {
|
||||
RED {
|
||||
@Override
|
||||
public int getChannel(int rgb) {
|
||||
return getRed(rgb);
|
||||
}
|
||||
},
|
||||
GREEN {
|
||||
@Override
|
||||
public int getChannel(int rgb) {
|
||||
return getGreen(rgb);
|
||||
}
|
||||
},
|
||||
BLUE {
|
||||
@Override
|
||||
public int getChannel(int rgb) {
|
||||
return getBlue(rgb);
|
||||
}
|
||||
},
|
||||
GRAYSCALE {
|
||||
@Override
|
||||
public int getChannel(int rgb) {
|
||||
return getGrayscale(rgb);
|
||||
}
|
||||
},
|
||||
ALPHA {
|
||||
@Override
|
||||
public int getChannel(int rgb) {
|
||||
return getAlpha(rgb);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract int getChannel(int rgb);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user