Reformat code

This commit is contained in:
Zoë Gidiere
2023-11-02 18:47:36 -06:00
parent d696e4fd24
commit 81a96d6b76
224 changed files with 1156 additions and 1075 deletions
@@ -2,7 +2,6 @@ version = version("1.0.1")
dependencies {
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
}
@@ -84,6 +84,6 @@ public class ImageLibraryAddon implements AddonInitializer {
colorSamplerRegistry.register(addon.key("COLOR"), ConstantColorSamplerTemplate::new);
colorSamplerRegistry.register(addon.key("ROTATE"), RotateColorSamplerTemplate::new);
colorSamplerRegistry.register(addon.key("TRANSLATE"), TranslateColorSamplerTemplate::new);
});
});
}
}
@@ -6,6 +6,7 @@ public interface ColorSampler {
/**
* @param x World x coordinate
* @param z World z coordinate
*
* @return Integer representing a web color
*/
int apply(int x, int z);
@@ -10,7 +10,7 @@ public enum Alignment implements ImageTransformation {
public int transformX(Image image, int x) {
return x;
}
@Override
public int transformZ(Image image, int z) {
return z;
@@ -21,7 +21,7 @@ public enum Alignment implements ImageTransformation {
public int transformX(Image image, int x) {
return x + image.getWidth() / 2;
}
@Override
public int transformZ(Image image, int z) {
return z + image.getHeight() / 2;
@@ -3,6 +3,7 @@ package com.dfsek.terra.addons.image.colorsampler.mutate;
import com.dfsek.terra.addons.image.colorsampler.ColorSampler;
import com.dfsek.terra.api.util.MathUtil;
public class RotateColorSampler implements ColorSampler {
private final ColorSampler sampler;
@@ -15,15 +16,15 @@ public class RotateColorSampler implements ColorSampler {
this.sampler = sampler;
double normalizedDegrees = degrees % 360.0;
if (normalizedDegrees < 0) normalizedDegrees += 360.0;
if(normalizedDegrees < 0) normalizedDegrees += 360.0;
if (normalizedDegrees == 0.0)
if(normalizedDegrees == 0.0)
rotationMethod = RotationMethod.DEG_0;
else if (normalizedDegrees == 90.0)
else if(normalizedDegrees == 90.0)
rotationMethod = RotationMethod.DEG_90;
else if (normalizedDegrees == 180.0)
else if(normalizedDegrees == 180.0)
rotationMethod = RotationMethod.DEG_180;
else if (normalizedDegrees == 270.0)
else if(normalizedDegrees == 270.0)
rotationMethod = RotationMethod.DEG_270;
else
rotationMethod = RotationMethod.RAD_ANY;
@@ -28,28 +28,24 @@ public class ColorLoader implements TypeLoader<ColorString> {
this.argb = parse(string);
}
public int getColor() {
return argb;
}
private static int parse(String string) throws IllegalArgumentException {
if (string.length() == 0)
if(string.length() == 0)
throw new IllegalArgumentException("Empty string cannot be parsed as a valid color");
String[] split = string.split(",");
if (split.length == 1)
if(split.length == 1)
return parseHex(string);
else if (split.length == 3)
else if(split.length == 3)
return parseChannels("255", split[0], split[1], split[2]);
else if (split.length == 4)
else if(split.length == 4)
return parseChannels(split[0], split[1], split[2], split[3]);
else
throw new IllegalArgumentException("Invalid channels provided, required format RED,GREEN,BLUE or ALPHA,RED,GREEN,BLUE");
}
private static int parseHex(String hex) throws IllegalArgumentException {
if (hex.startsWith("#"))
if(hex.startsWith("#"))
hex = hex.substring(1);
int alpha = 255;
@@ -71,7 +67,7 @@ public class ColorLoader implements TypeLoader<ColorString> {
blue = Integer.parseInt(hex.substring(4, 6), 16);
return ColorUtil.argbValidated(alpha, red, green, blue);
} catch (NumberFormatException e) {
} catch(NumberFormatException e) {
throw new IllegalArgumentException("Failed to parse hex color", e);
}
}
@@ -84,9 +80,13 @@ public class ColorLoader implements TypeLoader<ColorString> {
int b = Integer.decode(blue);
return ColorUtil.argbValidated(a, r, g, b);
} catch (NumberFormatException e) {
} catch(NumberFormatException e) {
throw new IllegalArgumentException("Invalid channel value", e);
}
}
public int getColor() {
return argb;
}
}
}
@@ -7,6 +7,7 @@ import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.terra.api.properties.Properties;
public class ImageLibraryPackConfigTemplate implements ConfigTemplate, Properties {
// TODO - These would be better as plugin wide config parameters in config.yml
@@ -17,8 +18,10 @@ public class ImageLibraryPackConfigTemplate implements ConfigTemplate, Propertie
@Value("images.cache.timeout")
@Description("How many seconds to keep images loaded in the image cache for. " +
"If set to a number greater than 0, images will be removed from memory if not used after the timeout, otherwise images will stay loaded in memory. " +
"Setting the timeout to greater than 0 will trade decreased memory consumption when not performing any image reads for a period of time for extra processing time required to perform cache lookups.")
"If set to a number greater than 0, images will be removed from memory if not used after the timeout, otherwise images " +
"will stay loaded in memory. " +
"Setting the timeout to greater than 0 will trade decreased memory consumption when not performing any image reads for a" +
" period of time for extra processing time required to perform cache lookups.")
@Default
private int cacheTimeout = 0;
@@ -9,7 +9,7 @@ import com.dfsek.terra.addons.image.colorsampler.image.SingleImageColorSampler;
public class SingleImageColorSamplerTemplate extends ImageColorSamplerTemplate {
@Value("outside-sampler")
private ColorSampler fallback;
@Override
public ColorSampler get() {
return new SingleImageColorSampler(image, fallback, alignment);
@@ -5,7 +5,7 @@ import com.dfsek.terra.addons.image.colorsampler.image.TileImageColorSampler;
public class TileImageColorSamplerTemplate extends ImageColorSamplerTemplate {
@Override
public ColorSampler get() {
return new TileImageColorSampler(image, alignment);
@@ -16,6 +16,6 @@ public class TranslateColorSamplerTemplate extends MutateColorSamplerTemplate {
@Override
public ColorSampler get() {
return new TranslateColorSampler(sampler, translateX, translateZ);
return new TranslateColorSampler(sampler, translateX, translateZ);
}
}
@@ -27,12 +27,12 @@ record ImageCache(LoadingCache<String, Image> cache) implements Properties {
ImageCache images;
if(!pack.getContext().has(ImageCache.class)) {
var cacheBuilder = Caffeine.newBuilder();
if (config.unloadOnTimeout()) cacheBuilder.expireAfterAccess(config.getCacheTimeout(), TimeUnit.SECONDS);
if(config.unloadOnTimeout()) cacheBuilder.expireAfterAccess(config.getCacheTimeout(), TimeUnit.SECONDS);
images = new ImageCache(cacheBuilder.build(s -> loadImage(s, files)));
pack.getContext().put(images);
} else images = pack.getContext().get(ImageCache.class);
if (config.loadOnUse()) {
if(config.loadOnUse()) {
if(config.unloadOnTimeout()) { // Grab directly from cache if images are to unload on timeout
return new SuppliedImage(() -> images.cache.get(path));
} else {
@@ -12,13 +12,11 @@ import com.dfsek.terra.api.config.Loader;
public class ImageTemplate implements ObjectTemplate<Image> {
private final Loader files;
private final ConfigPack pack;
@Value("path")
private String path;
private final Loader files;
private final ConfigPack pack;
public ImageTemplate(Loader files, ConfigPack pack) {
this.files = files;
this.pack = pack;
@@ -15,24 +15,19 @@ import com.dfsek.terra.api.config.Loader;
public class StitchedImageTemplate implements ObjectTemplate<Image>, ValidatedConfigTemplate {
private final Loader files;
private final ConfigPack pack;
@Value("path-format")
private String path;
@Value("rows")
private int rows;
@Value("columns")
private int cols;
@Value("zero-indexed")
@Default
private boolean zeroIndexed = false;
private final Loader files;
private final ConfigPack pack;
public StitchedImageTemplate(Loader files, ConfigPack pack) {
this.files = files;
this.pack = pack;
@@ -54,13 +49,13 @@ public class StitchedImageTemplate implements ObjectTemplate<Image>, ValidatedCo
}
private String getFormattedPath(int row, int column) {
if (!zeroIndexed) {
if(!zeroIndexed) {
row++;
column++;
}
return path.replaceFirst("\\{row}", String.valueOf(row)).replaceFirst("\\{column}", String.valueOf(column));
}
@Override
public boolean validate() throws ValidationException {
if(!path.contains("{row}"))
@@ -69,6 +69,7 @@ public class DistanceTransformNoiseSamplerTemplate implements ObjectTemplate<Noi
@Override
public NoiseSampler get() {
return new DistanceTransform.Noise(new DistanceTransform(image, channel, threshold, clampToEdge, costFunction, invertThreshold), normalization);
return new DistanceTransform.Noise(new DistanceTransform(image, channel, threshold, clampToEdge, costFunction, invertThreshold),
normalization);
}
}
@@ -4,17 +4,18 @@ import java.util.Map;
import com.dfsek.terra.addons.image.util.ColorUtil;
public class ClosestMatchColorConverter<T> implements ColorConverter<T> {
private final Map<Integer, T> map;
private final Integer[] colors;
public ClosestMatchColorConverter(Map<Integer, T> map) {
this.map = map;
this.colors = map.keySet().toArray(new Integer[0]);
}
@Override
public T apply(int color) {
int closest = 0;
@@ -32,7 +33,7 @@ public class ClosestMatchColorConverter<T> implements ColorConverter<T> {
}
return map.get(closest);
}
@Override
public Iterable<T> getEntries() {
return map.values();
@@ -16,7 +16,7 @@ public class ExactColorConverter<T> implements ColorConverter<T> {
private final boolean ignoreAlpha;
public ExactColorConverter(Map<Integer, T> map, T fallback, boolean ignoreAlpha) {
if (ignoreAlpha) {
if(ignoreAlpha) {
map = MapUtil.mapKeys(map, ColorUtil::zeroAlpha);
}
this.map = map;
@@ -26,7 +26,7 @@ public class ExactColorConverter<T> implements ColorConverter<T> {
@Override
public T apply(int color) {
if (ignoreAlpha) {
if(ignoreAlpha) {
color = ColorUtil.zeroAlpha(color);
}
T lookup = map.get(color);
@@ -30,7 +30,8 @@ public class BiomeDefinedColorMapping<T> implements ColorMapping<T> {
if(!output.containsKey(color)) {
output.put(color, biome);
} else {
throw new IllegalArgumentException(String.format("Biome %s has same color as %s: %x", biome.getID(), output.get(color).getID(), color));
throw new IllegalArgumentException(
String.format("Biome %s has same color as %s: %x", biome.getID(), output.get(color).getID(), color));
}
}));
return output.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> converter.apply(e.getValue())));
@@ -40,7 +40,7 @@ public class StitchedImage implements Image {
}
private int getColumn(int x) {
for(int i = columnOffsets.length-1; i > 0; i--) {
for(int i = columnOffsets.length - 1; i > 0; i--) {
if(x >= columnOffsets[i])
return i;
}
@@ -48,7 +48,7 @@ public class StitchedImage implements Image {
}
private int getRow(int y) {
for(int i = rowOffsets.length-1; i > 0; i--) {
for(int i = rowOffsets.length - 1; i > 0; i--) {
if(y >= rowOffsets[i])
return i;
}
@@ -59,7 +59,7 @@ public class StitchedImage implements Image {
public int getRGB(int x, int y) {
int row = getRow(y);
int column = getColumn(x);
return images[row][column].getRGB(x-columnOffsets[column], y-rowOffsets[row]);
return images[row][column].getRGB(x - columnOffsets[column], y - rowOffsets[row]);
}
@Override
@@ -2,6 +2,7 @@ package com.dfsek.terra.addons.image.image;
import java.util.function.Supplier;
public class SuppliedImage implements Image {
private final Supplier<Image> imageSupplier;
@@ -16,21 +16,20 @@ import static com.dfsek.terra.addons.image.util.MathUtil.lerp;
*/
public class DistanceTransform {
private static final double MAX_DISTANCE_CAP = 10_000_000; // Arbitrarily large value, doubtful someone would
private final double[][] distances;
/**
* Size bounds matching the provided image.
*/
private final int width, height;
/**
* Min and max distances of the distance computation. These may change after {@link #normalize(Normalization)} calls.
*/
private double minDistance, maxDistance;
private static final double MAX_DISTANCE_CAP = 10_000_000; // Arbitrarily large value, doubtful someone would
// ever use an image large enough to exceed this.
public DistanceTransform(Image image, Channel channel, int threshold, boolean clampToMaxEdgeDistance, CostFunction costFunction, boolean invertThreshold) {
// ever use an image large enough to exceed this.
public DistanceTransform(Image image, Channel channel, int threshold, boolean clampToMaxEdgeDistance, CostFunction costFunction,
boolean invertThreshold) {
// Construct binary image based on threshold value
boolean[][] binaryImage = new boolean[image.getWidth()][image.getHeight()];
for(int x = 0; x < image.getWidth(); x++) {
@@ -47,17 +46,17 @@ public class DistanceTransform {
binaryImageEdge[x][y] = false;
else
// If cell borders any false cell
binaryImageEdge[x][y] = x > 0 && !binaryImage[x-1][y] ||
y > 0 && !binaryImage[x][y-1] ||
x < image.getWidth ()-1 && !binaryImage[x+1][y] ||
y < image.getHeight()-1 && !binaryImage[x][y+1];
binaryImageEdge[x][y] = x > 0 && !binaryImage[x - 1][y] ||
y > 0 && !binaryImage[x][y - 1] ||
x < image.getWidth() - 1 && !binaryImage[x + 1][y] ||
y < image.getHeight() - 1 && !binaryImage[x][y + 1];
}
}
double[][] function = new double[image.getWidth()][image.getHeight()];
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
function[x][y] = switch (costFunction) {
function[x][y] = switch(costFunction) {
case Channel -> ColorUtil.getChannel(image.getRGB(x, y), channel);
case Threshold -> binaryImage[x][y] ? MAX_DISTANCE_CAP : 0;
case ThresholdEdge, ThresholdEdgeSigned -> binaryImageEdge[x][y] ? 0 : MAX_DISTANCE_CAP;
@@ -80,11 +79,11 @@ public class DistanceTransform {
double max = Double.NEGATIVE_INFINITY;
for(int x = 0; x < image.getWidth(); x++) {
max = Math.max(max, distances[x][0]);
max = Math.max(max, distances[x][image.getHeight()-1]);
max = Math.max(max, distances[x][image.getHeight() - 1]);
}
for(int y = 0; y < image.getHeight(); y++) {
max = Math.max(max, distances[0][y]);
max = Math.max(max, distances[image.getWidth()-1][y]);
max = Math.max(max, distances[image.getWidth() - 1][y]);
}
// Clamp to that largest value
for(int x = 0; x < image.getWidth(); x++) {
@@ -93,7 +92,7 @@ public class DistanceTransform {
}
}
}
this.width = image.getWidth();
this.height = image.getHeight();
@@ -122,28 +121,28 @@ public class DistanceTransform {
private double[] calculateDistance1D(double[] f) {
double[] d = new double[f.length];
int[] v = new int[f.length];
double[] z = new double[f.length+1];
double[] z = new double[f.length + 1];
int k = 0;
v[0] = 0;
z[0] = Integer.MIN_VALUE;
z[1] = Integer.MAX_VALUE;
for(int q = 1; q <= f.length-1; q++) {
double s = ((f[q]+Math.pow(q, 2))-(f[v[k]]+Math.pow(v[k], 2)))/(2*q-2*v[k]);
while (s <= z[k]) {
for(int q = 1; q <= f.length - 1; q++) {
double s = ((f[q] + Math.pow(q, 2)) - (f[v[k]] + Math.pow(v[k], 2))) / (2 * q - 2 * v[k]);
while(s <= z[k]) {
k--;
s = ((f[q]+Math.pow(q, 2))-(f[v[k]]+Math.pow(v[k], 2)))/(2*q-2*v[k]);
s = ((f[q] + Math.pow(q, 2)) - (f[v[k]] + Math.pow(v[k], 2))) / (2 * q - 2 * v[k]);
}
k++;
v[k] = q;
z[k] = s;
z[k+1] = Integer.MAX_VALUE;
z[k + 1] = Integer.MAX_VALUE;
}
k = 0;
for(int q = 0; q <= f.length-1; q++) {
while(z[k+1] < q)
for(int q = 0; q <= f.length - 1; q++) {
while(z[k + 1] < q)
k++;
d[q] = Math.pow(q-v[k], 2) + f[v[k]];
d[q] = Math.pow(q - v[k], 2) + f[v[k]];
}
return d;
}
@@ -164,9 +163,9 @@ public class DistanceTransform {
yield lerp(distances[x][y], minDistance, -1, maxDistance, 1);
} else {
if(d > 0) {
yield Math.pow(d/maxDistance, 2);
yield Math.pow(d / maxDistance, 2);
} else if(d < 0) {
yield -Math.pow(d/minDistance, 2);
yield -Math.pow(d / minDistance, 2);
} else {
yield 0;
}
@@ -198,6 +197,7 @@ public class DistanceTransform {
ThresholdEdgeSigned,
}
public enum Normalization {
/**
* Return the raw calculated distances.
@@ -217,21 +217,22 @@ public class DistanceTransform {
SmoothPreserveZero,
}
public static class Noise implements NoiseSampler {
private final DistanceTransform transform;
public Noise(DistanceTransform transform, Normalization normalization) {
this.transform = transform;
transform.normalize(normalization);
}
@Override
public double noise(long seed, double x, double y) {
if(x<0 || y<0 || x>=transform.width || y>=transform.height) return transform.minDistance;
if(x < 0 || y < 0 || x >= transform.width || y >= transform.height) return transform.minDistance;
return transform.distances[(int) Math.floor(x)][(int) Math.floor(y)];
}
@Override
public double noise(long seed, double x, double y, double z) {
return noise(seed, x, z);
@@ -5,7 +5,7 @@ package com.dfsek.terra.addons.image.util;
*/
public class ColorUtil {
private ColorUtil() {}
private ColorUtil() { }
public static int distance(int a, int b) {
return Math.abs(getRed(a) - getRed(b)) +
@@ -17,6 +17,7 @@ public class ColorUtil {
* Returns the red channel value of a given ARGB color value.
*
* @param argb the ARGB color value to extract the red channel value from
*
* @return the red channel value of the given ARGB color value, in the range 0-255
*/
public static int getRed(int argb) {
@@ -27,6 +28,7 @@ public class ColorUtil {
* Returns the green channel value of a given ARGB color value.
*
* @param argb the ARGB color value to extract the green channel value from
*
* @return the green channel value of the given ARGB color value, in the range 0-255
*/
public static int getGreen(int argb) {
@@ -37,6 +39,7 @@ public class ColorUtil {
* Returns the blue channel value of a given ARGB color value.
*
* @param argb the ARGB color value to extract the blue channel value from
*
* @return the blue channel value of the given ARGB color value, in the range 0-255
*/
public static int getBlue(int argb) {
@@ -47,6 +50,7 @@ public class ColorUtil {
* Returns the alpha channel value of a given ARGB color value.
*
* @param argb the ARGB color value to extract the blue channel value from
*
* @return the alpha channel value of the given ARGB color value, in the range 0-255
*/
public static int getAlpha(int argb) {
@@ -57,6 +61,7 @@ public class ColorUtil {
* Returns the grayscale value of a given ARGB color value.
*
* @param argb the ARGB color value to convert to grayscale
*
* @return the grayscale value of the given ARGB color value, in the range 0-255
*/
public static int getGrayscale(int argb) {
@@ -66,8 +71,9 @@ public class ColorUtil {
/**
* Returns the value of the specified channel for a given ARGB color value.
*
* @param argb the ARGB color value to extract the channel value from
* @param argb the ARGB color value to extract the channel value from
* @param channel the channel to extract the value from
*
* @return the value of the specified channel for the given ARGB color value, in the range 0-255
*/
public static int getChannel(int argb, Channel channel) {
@@ -78,6 +84,7 @@ public class ColorUtil {
* Sets the red channel value of a given ARGB color value to zero.
*
* @param argb the ARGB color value to zero the red channel of
*
* @return the resulting ARGB color value with the red channel set to zero
*/
public static int zeroRed(int argb) {
@@ -88,6 +95,7 @@ public class ColorUtil {
* Sets the green channel value of a given ARGB color value to zero.
*
* @param argb the ARGB color value to zero the green channel of
*
* @return the resulting ARGB color value with the green channel set to zero
*/
public static int zeroGreen(int argb) {
@@ -98,6 +106,7 @@ public class ColorUtil {
* Sets the blue channel value of a given ARGB color value to zero.
*
* @param argb the ARGB color value to zero the blue channel of
*
* @return the resulting ARGB color value with the blue channel set to zero
*/
public static int zeroBlue(int argb) {
@@ -109,6 +118,7 @@ public class ColorUtil {
* This is the same as setting the color to fully transparent.
*
* @param argb the ARGB color value to zero the alpha channel of
*
* @return the resulting ARGB color value with the alpha channel set to zero
*/
public static int zeroAlpha(int argb) {
@@ -120,6 +130,7 @@ public class ColorUtil {
* This is the same as setting the color to black, while preserving the alpha.
*
* @param argb the ARGB color value to zero the color channel of
*
* @return the resulting ARGB color value with the color channels set to zero
*/
public static int zeroGrayscale(int argb) {
@@ -129,8 +140,9 @@ public class ColorUtil {
/**
* Sets the specified channel value of a given ARGB color value to zero.
*
* @param argb the ARGB color value to zero the specified channel of
* @param argb the ARGB color value to zero the specified channel of
* @param channel the channel to zero the value of
*
* @return the resulting ARGB color value with the specified channel value set to zero
*/
public static int zeroChannel(int argb, Channel channel) {
@@ -141,6 +153,7 @@ public class ColorUtil {
* Multiply the RGB channels of a given ARGB color value by its alpha channel value.
*
* @param argb the ARGB color value to premultiply the RGB channels of
*
* @return the resulting premultiplied ARGB color value
*/
public static int premultiply(int argb) {
@@ -155,9 +168,10 @@ public class ColorUtil {
* Returns an ARGB color value with the specified values for alpha, red, green, and blue channels.
*
* @param alpha the alpha value, between 0 and 255, to set in the ARGB color value
* @param red the red value, between 0 and 255, to set in the ARGB color value
* @param red the red value, between 0 and 255, to set in the ARGB color value
* @param green the green value, between 0 and 255, to set in the ARGB color value
* @param blue the blue value, between 0 and 255, to set in the ARGB color value
* @param blue the blue value, between 0 and 255, to set in the ARGB color value
*
* @return the resulting ARGB color value with the specified values for alpha, red, green, and blue channels
*/
public static int argb(int alpha, int red, int green, int blue) {
@@ -169,17 +183,19 @@ public class ColorUtil {
* after validating that each channel value is in the range 0-255.
*
* @param alpha the alpha value, between 0 and 255, to set in the ARGB color value
* @param red the red value, between 0 and 255, to set in the ARGB color value
* @param red the red value, between 0 and 255, to set in the ARGB color value
* @param green the green value, between 0 and 255, to set in the ARGB color value
* @param blue the blue value, between 0 and 255, to set in the ARGB color value
* @param blue the blue value, between 0 and 255, to set in the ARGB color value
*
* @return the resulting ARGB color value with the specified values for alpha, red, green, and blue channels
*
* @throws IllegalArgumentException if any channel value is outside the range 0-255
*/
public static int argbValidated(int alpha, int red, int green, int blue) throws IllegalArgumentException {
if (alpha < 0 || alpha > 255 ||
red < 0 || red > 255 ||
green < 0 || green > 255 ||
blue < 0 || blue > 255
if(alpha < 0 || alpha > 255 ||
red < 0 || red > 255 ||
green < 0 || green > 255 ||
blue < 0 || blue > 255
) throw new IllegalArgumentException("Channel values must be in range 0-255");
return argb(alpha, red, green, blue);
}
@@ -189,6 +205,7 @@ public class ColorUtil {
* for the red, green, and blue channels.
*
* @param alpha the alpha channel value to set in the ARGB color value
*
* @return the resulting ARGB color value
*/
public static int argbAlpha(int alpha) { return alpha << 24; }
@@ -198,6 +215,7 @@ public class ColorUtil {
* for the alpha, green, and blue channels.
*
* @param red the red channel value to set in the ARGB color value
*
* @return the resulting ARGB color value
*/
public static int argbRed(int red) { return red << 16; }
@@ -207,6 +225,7 @@ public class ColorUtil {
* for the alpha, red, and blue channels.
*
* @param green the green channel value to set in the ARGB color value
*
* @return the resulting ARGB color value
*/
public static int argbGreen(int green) { return green << 8; }
@@ -216,6 +235,7 @@ public class ColorUtil {
* for the alpha, red, and green channels.
*
* @param blue the blue channel value to set in the ARGB color value
*
* @return the resulting ARGB color value
*/
public static int argbBlue(int blue) { return blue; }
@@ -224,6 +244,7 @@ public class ColorUtil {
* Returns an ARGB color value with the specified grayscale value for all four channels.
*
* @param value the grayscale value to set in all four channels of the ARGB color value
*
* @return the resulting ARGB color value with the specified grayscale value for all four channels
*/
public static int argbGrayscale(int value) { return argb(value, value, value, value); }
@@ -234,7 +255,7 @@ public class ColorUtil {
public int from(int argb) {
return getRed(argb);
}
@Override
public int zero(int argb) {
return zeroRed(argb);
@@ -250,7 +271,7 @@ public class ColorUtil {
public int from(int argb) {
return getGreen(argb);
}
@Override
public int zero(int argb) {
return zeroGreen(argb);
@@ -266,7 +287,7 @@ public class ColorUtil {
public int from(int argb) {
return getBlue(argb);
}
@Override
public int zero(int argb) {
return zeroBlue(argb);
@@ -282,7 +303,7 @@ public class ColorUtil {
public int from(int argb) {
return getGrayscale(argb);
}
@Override
public int zero(int argb) {
return zeroGrayscale(argb);
@@ -298,7 +319,7 @@ public class ColorUtil {
public int from(int argb) {
return getAlpha(argb);
}
@Override
public int zero(int argb) {
return zeroAlpha(argb);
@@ -7,8 +7,8 @@ import java.util.stream.Collectors;
public class MapUtil {
private MapUtil() {}
private MapUtil() { }
/**
* Utility method for applying transformations on a map's keys.
@@ -20,6 +20,6 @@ public class MapUtil {
.collect(Collectors.toMap(
e -> mappingFunction.apply(e.getKey()),
Entry::getValue
));
));
}
}
@@ -1,9 +1,9 @@
package com.dfsek.terra.addons.image.util;
public class MathUtil {
private MathUtil() {}
private MathUtil() { }
public static double lerp(double x, double x1, double y1, double x2, double y2) {
return (((y1-y2)*(x-x1))/(x1-x2))+y1;
return (((y1 - y2) * (x - x1)) / (x1 - x2)) + y1;
}
}
@@ -1,12 +1,12 @@
schema-version: 1
contributors:
- Terra contributors
- Terra contributors
id: library-image
version: @VERSION@
entrypoints:
- "com.dfsek.terra.addons.image.ImageLibraryAddon"
- "com.dfsek.terra.addons.image.ImageLibraryAddon"
website:
issues: https://github.com/PolyhedralDev/Terra/issues
source: https://github.com/PolyhedralDev/Terra
docs: https://terra.polydev.org
issues: https://github.com/PolyhedralDev/Terra/issues
source: https://github.com/PolyhedralDev/Terra
docs: https://terra.polydev.org
license: MIT License