From ee2a222079f4cf5d61f4a663cc930cab2f89a65c Mon Sep 17 00:00:00 2001 From: Tim Butram Date: Tue, 22 Apr 2014 17:39:47 -0400 Subject: [PATCH] Removed ColorCafe, as it was duplicated functionality of Java Color --- src/libnoiseforjava/NoiseGen.java | 9 +- src/libnoiseforjava/util/ColorCafe.java | 105 ------------------ src/libnoiseforjava/util/GradientColor.java | 18 +-- src/libnoiseforjava/util/GradientPoint.java | 14 ++- src/libnoiseforjava/util/ImageCafe.java | 24 ++-- src/libnoiseforjava/util/MiscUtilities.java | 16 +-- src/libnoiseforjava/util/RendererImage.java | 68 ++++++------ .../util/RendererNormalMap.java | 8 +- 8 files changed, 84 insertions(+), 178 deletions(-) delete mode 100644 src/libnoiseforjava/util/ColorCafe.java diff --git a/src/libnoiseforjava/NoiseGen.java b/src/libnoiseforjava/NoiseGen.java index 4996fde..4031002 100644 --- a/src/libnoiseforjava/NoiseGen.java +++ b/src/libnoiseforjava/NoiseGen.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -60,6 +60,8 @@ public enum NoiseQuality static final int SEED_NOISE_GEN = 1013; static final int SHIFT_NOISE_GEN = 8; + private static final VectorTable vectorTable = new VectorTable(); + public static double GradientCoherentNoise3D (double x, double y, double z, int seed, NoiseQuality noiseQuality) { @@ -121,16 +123,13 @@ public static double GradientCoherentNoise3D (double x, double y, double z, int public static double GradientNoise3D (double fx, double fy, double fz, int ix, int iy, int iz, int seed) { - - VectorTable vectorTable = new VectorTable(); // Randomly generate a gradient vector given the integer coordinates of the // input value. This implementation generates a random number and uses it // as an index into a normalized-vector lookup table. int vectorIndex = (X_NOISE_GEN * ix + Y_NOISE_GEN * iy + Z_NOISE_GEN * iz - + SEED_NOISE_GEN * seed) - & 0xffffffff; + + SEED_NOISE_GEN * seed); vectorIndex ^= (vectorIndex >> SHIFT_NOISE_GEN); vectorIndex &= 0xff; diff --git a/src/libnoiseforjava/util/ColorCafe.java b/src/libnoiseforjava/util/ColorCafe.java deleted file mode 100644 index 08cb4ab..0000000 --- a/src/libnoiseforjava/util/ColorCafe.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) - * - * This file is part of libnoiseforjava. - * - * libnoiseforjava is a Java port of the C++ library libnoise, which may be found at - * http://libnoise.sourceforge.net/. libnoise was developed by Jason Bevins, who may be - * contacted at jlbezigvins@gmzigail.com (for great email, take off every 'zig'). - * Porting to Java was done by Thomas Hodge, who may be contacted at - * libnoisezagforjava@gzagmail.com (remove every 'zag'). - * - * libnoiseforjava 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 3 of the License, or (at your option) any later version. - * - * libnoiseforjava 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 - * libnoiseforjava. If not, see . - * - */ - -package libnoiseforjava.util; - -public class ColorCafe -{ - /// Defines a color. - /// - /// A color object contains four 8-bit channels: red, green, blue, and an - /// alpha (transparency) channel. Channel values range from 0 to 255. - /// - /// The alpha channel defines the transparency of the color. If the alpha - /// channel has a value of 0, the color is completely transparent. If the - /// alpha channel has a value of 255, the color is completely opaque. - - /// Value of the alpha (transparency) channel. - int alpha; - - /// Value of the blue channel. - int blue; - - /// Value of the green channel. - int green; - - /// Value of the red channel. - int red; - - /// Constructor. - /// - /// @param r Value of the red channel. - /// @param g Value of the green channel. - /// @param b Value of the blue channel. - /// @param a Value of the alpha (transparency) channel. - public ColorCafe (int red, int green, int blue, int alpha) - { - this.red = red; - this.blue = blue; - this.green = green; - this.alpha = alpha; - } - - public int getAlpha() - { - return alpha; - } - - public int getBlue() - { - return blue; - } - - public int getGreen() - { - return green; - } - - public int getRed() - { - return red; - } - - public void setAlpha(int alpha) - { - this.alpha = alpha; - } - - public void setBlue(int blue) - { - this.blue = blue; - } - - public void setGreen(int green) - { - this.green = green; - } - - public void setRed(int red) - { - this.red = red; - } - -} diff --git a/src/libnoiseforjava/util/GradientColor.java b/src/libnoiseforjava/util/GradientColor.java index d9f5736..1131a60 100644 --- a/src/libnoiseforjava/util/GradientColor.java +++ b/src/libnoiseforjava/util/GradientColor.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -28,6 +28,8 @@ import libnoiseforjava.Misc; import libnoiseforjava.exception.ExceptionInvalidParam; +import java.awt.*; + public class GradientColor { /// Defines a color gradient. @@ -63,12 +65,12 @@ public class GradientColor GradientPoint [] gradientPoints; int gradientPointCount; - ColorCafe workingColor; + Color workingColor; public GradientColor() { gradientPoints = new GradientPoint[1]; - gradientPoints[0] = new GradientPoint(0.0, new ColorCafe(0, 0, 0, 0)); + gradientPoints[0] = new GradientPoint(0.0, new Color(0, 0, 0, 0)); } /// Adds a gradient point to this gradient object. @@ -81,7 +83,7 @@ public GradientColor() /// @throw noise::ExceptionInvalidParam See the precondition. /// /// It does not matter which order these gradient points are added. - public void addGradientPoint (double gradientPos, ColorCafe gradientColor) throws ExceptionInvalidParam + public void addGradientPoint (double gradientPos, Color gradientColor) throws ExceptionInvalidParam { // Find the insertion point for the new gradient point and insert the new // gradient point at that insertion point. The gradient point array will @@ -137,7 +139,7 @@ public int findInsertionPos (double gradientPos) throws ExceptionInvalidParam /// @param gradientPos The specified position. /// /// @returns The color at that position. - public ColorCafe getColor (double gradientPos) + public Color getColor (double gradientPos) { assert (gradientPointCount >= 2); @@ -172,8 +174,8 @@ public ColorCafe getColor (double gradientPos) double alpha = (gradientPos - input0) / (input1 - input0); // Now perform the linear interpolation given the alpha value. - ColorCafe color0 = gradientPoints[index0].color; - ColorCafe color1 = gradientPoints[index1].color; + Color color0 = gradientPoints[index0].color; + Color color1 = gradientPoints[index1].color; workingColor = MiscUtilities.linearInterpColor (color0, color1, (float)alpha); return workingColor; } @@ -194,7 +196,7 @@ public ColorCafe getColor (double gradientPos) /// must be sorted by the position, the new gradient point should be /// inserted at the position in which the order is still preserved. public void insertAtPos (int insertionPos, double gradientPos, - ColorCafe gradientColor) + Color gradientColor) { // Make room for the new gradient point at the specified insertion position // within the gradient point array. The insertion position is determined by diff --git a/src/libnoiseforjava/util/GradientPoint.java b/src/libnoiseforjava/util/GradientPoint.java index 8711d67..55aa386 100644 --- a/src/libnoiseforjava/util/GradientPoint.java +++ b/src/libnoiseforjava/util/GradientPoint.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -25,6 +25,8 @@ package libnoiseforjava.util; +import java.awt.*; + public class GradientPoint { /// Defines a point used to build a color gradient. @@ -38,15 +40,15 @@ public class GradientPoint /// objects. double position; - ColorCafe color; + Color color; public GradientPoint() { position = 0.0; - color = new ColorCafe(0,0,0,0); + color = new Color(0,0,0,0); } - public GradientPoint(double position, ColorCafe color) + public GradientPoint(double position, Color color) { this.position = position; this.color = color; @@ -57,7 +59,7 @@ public double getPosition() return position; } - public ColorCafe getColor() + public Color getColor() { return color; } @@ -67,7 +69,7 @@ public void setPosition(double position) this.position = position; } - public void setColor(ColorCafe color) + public void setColor(Color color) { this.color = color; } diff --git a/src/libnoiseforjava/util/ImageCafe.java b/src/libnoiseforjava/util/ImageCafe.java index 192e93d..4c1cc05 100644 --- a/src/libnoiseforjava/util/ImageCafe.java +++ b/src/libnoiseforjava/util/ImageCafe.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -27,6 +27,8 @@ import libnoiseforjava.exception.ExceptionInvalidParam; +import java.awt.*; + public class ImageCafe { @@ -34,7 +36,7 @@ public class ImageCafe /// /// An image can be used to store a color texture. /// - /// These color values are of type ColorCafe. + /// These color values are of type Color. /// /// The size (width and height) of the image can be specified during /// object construction. @@ -55,7 +57,7 @@ public class ImageCafe /// /// The Color value used for all positions outside of the image. - ColorCafe borderValue; + Color borderValue; /// The current height of the image. int height; @@ -63,14 +65,14 @@ public class ImageCafe /// The current width of the image. int width; - /// Array of ColorCafes holding the color values - ColorCafe [][] imageCafeColors; + /// Array of Colors holding the color values + Color [][] imageCafeColors; public ImageCafe (int width, int height) throws ExceptionInvalidParam { setSize (width, height); - borderValue = new ColorCafe (0, 0, 0, 0); - imageCafeColors = new ColorCafe[width][height]; + borderValue = new Color (0, 0, 0, 0); + imageCafeColors = new Color[width][height]; } /// Returns a color value from the specified position in the image. @@ -82,7 +84,7 @@ public ImageCafe (int width, int height) throws ExceptionInvalidParam /// /// This method returns the border value if the coordinates exist /// outside of the image. - public ColorCafe getValue (int x, int y) + public Color getValue (int x, int y) { if (x >= 0 && x < width && y >= 0 && y < height) return imageCafeColors[x][y]; @@ -122,7 +124,7 @@ public void setSize (int width, int height) throws ExceptionInvalidParam /// /// This method does nothing if the image is empty or the position is /// outside the bounds of the image. - public void setValue (int x, int y, ColorCafe value) + public void setValue (int x, int y, Color value) { if (x >= 0 && x < width && y >= 0 && y < height) this.imageCafeColors[x][y] = value; @@ -137,7 +139,7 @@ public void setValue (int x, int y, ColorCafe value) /// /// All positions outside of the image are assumed to have a common /// color value known as the border value. - public ColorCafe getBorderValue () + public Color getBorderValue () { return borderValue; } @@ -166,7 +168,7 @@ public int getWidth () /// /// All positions outside of the image are assumed to have a common /// color value known as the border value. - public void setBorderValue (ColorCafe borderValue) + public void setBorderValue (Color borderValue) { this.borderValue = borderValue; } diff --git a/src/libnoiseforjava/util/MiscUtilities.java b/src/libnoiseforjava/util/MiscUtilities.java index 6b0c1c3..8bf2d50 100644 --- a/src/libnoiseforjava/util/MiscUtilities.java +++ b/src/libnoiseforjava/util/MiscUtilities.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -25,6 +25,8 @@ package libnoiseforjava.util; +import java.awt.*; + public class MiscUtilities { @@ -37,14 +39,14 @@ public static short blendChannel (int red, int red2, float alpha) } // Performs linear interpolation between two colors - public static ColorCafe linearInterpColor (ColorCafe color0, ColorCafe color1, + public static Color linearInterpColor (Color color0, Color color1, float alpha) { - ColorCafe color = new ColorCafe( - blendChannel (color0.red, color1.red, alpha), - blendChannel (color0.green, color1.green, alpha), - blendChannel (color0.blue, color1.blue, alpha), - blendChannel (color0.alpha, color1.alpha, alpha) + Color color = new Color( + blendChannel (color0.getRed(), color1.getRed(), alpha), + blendChannel (color0.getGreen(), color1.getGreen(), alpha), + blendChannel (color0.getBlue(), color1.getBlue(), alpha), + blendChannel (color0.getAlpha(), color1.getAlpha(), alpha) ); return color; } diff --git a/src/libnoiseforjava/util/RendererImage.java b/src/libnoiseforjava/util/RendererImage.java index 5940527..d85f17d 100644 --- a/src/libnoiseforjava/util/RendererImage.java +++ b/src/libnoiseforjava/util/RendererImage.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -28,6 +28,8 @@ import libnoiseforjava.Interp; import libnoiseforjava.exception.ExceptionInvalidParam; +import java.awt.*; + public class RendererImage { @@ -153,7 +155,7 @@ public class RendererImage double lightBrightness; /// The color of the light source. - ColorCafe lightColor; + Color lightColor; /// The contrast between areas in light and areas in shadow. double lightContrast; @@ -194,7 +196,7 @@ public RendererImage () throws ExceptionInvalidParam isWrapEnabled = false; lightAzimuth = 45.0; lightBrightness = 1.0; - lightColor = new ColorCafe(255, 255, 255, 255); + lightColor = new Color(255, 255, 255, 255); lightContrast = 1.0; lightElev = 45.0; lightIntensity = 1.0; @@ -228,7 +230,7 @@ public RendererImage () throws ExceptionInvalidParam /// towards the calculated color, and if the alpha value is low, this /// object weighs the blend towards the color from the corresponding /// pixel in the background image. - public void addGradientPoint (double gradientPos, ColorCafe gradientColor) throws ExceptionInvalidParam + public void addGradientPoint (double gradientPos, Color gradientColor) throws ExceptionInvalidParam { gradient.addGradientPoint (gradientPos, gradientColor); } @@ -244,8 +246,8 @@ public void addGradientPoint (double gradientPos, ColorCafe gradientColor) throw public void buildGrayscaleGradient () throws ExceptionInvalidParam { clearGradient (); - gradient.addGradientPoint (-1.0, new ColorCafe ( 0, 0, 0, 255)); - gradient.addGradientPoint ( 1.0, new ColorCafe (255, 255, 255, 255)); + gradient.addGradientPoint (-1.0, new Color ( 0, 0, 0, 255)); + gradient.addGradientPoint ( 1.0, new Color (255, 255, 255, 255)); } /// Builds a color gradient suitable for terrain. @@ -259,15 +261,15 @@ public void buildGrayscaleGradient () throws ExceptionInvalidParam public void buildTerrainGradient () throws ExceptionInvalidParam { clearGradient (); - gradient.addGradientPoint (-1.00, new ColorCafe ( 0, 0, 128, 255)); - gradient.addGradientPoint (-0.20, new ColorCafe ( 32, 64, 128, 255)); - gradient.addGradientPoint (-0.04, new ColorCafe ( 64, 96, 192, 255)); - gradient.addGradientPoint (-0.02, new ColorCafe (192, 192, 128, 255)); - gradient.addGradientPoint ( 0.00, new ColorCafe ( 0, 192, 0, 255)); - gradient.addGradientPoint ( 0.25, new ColorCafe (192, 192, 0, 255)); - gradient.addGradientPoint ( 0.50, new ColorCafe (160, 96, 64, 255)); - gradient.addGradientPoint ( 0.75, new ColorCafe (128, 255, 255, 255)); - gradient.addGradientPoint ( 1.00, new ColorCafe (255, 255, 255, 255)); + gradient.addGradientPoint (-1.00, new Color ( 0, 0, 128, 255)); + gradient.addGradientPoint (-0.20, new Color ( 32, 64, 128, 255)); + gradient.addGradientPoint (-0.04, new Color ( 64, 96, 192, 255)); + gradient.addGradientPoint (-0.02, new Color (192, 192, 128, 255)); + gradient.addGradientPoint ( 0.00, new Color ( 0, 192, 0, 255)); + gradient.addGradientPoint ( 0.25, new Color (192, 192, 0, 255)); + gradient.addGradientPoint ( 0.50, new Color (160, 96, 64, 255)); + gradient.addGradientPoint ( 0.75, new Color (128, 255, 255, 255)); + gradient.addGradientPoint ( 1.00, new Color (255, 255, 255, 255)); } /// Calculates the destination color. @@ -279,16 +281,16 @@ public void buildTerrainGradient () throws ExceptionInvalidParam /// @param lightValue The intensity of the light at that position. /// /// @returns The destination color. - public ColorCafe calcDestColor (ColorCafe sourceColor, ColorCafe backgroundColor, + public Color calcDestColor (Color sourceColor, Color backgroundColor, double lightValue) { - double sourceRed = (double)sourceColor.red / 255.0; - double sourceGreen = (double)sourceColor.green / 255.0; - double sourceBlue = (double)sourceColor.blue / 255.0; - double sourceAlpha = (double)sourceColor.alpha / 255.0; - double backgroundRed = (double)backgroundColor.red / 255.0; - double backgroundGreen = (double)backgroundColor.green / 255.0; - double backgroundBlue = (double)backgroundColor.blue / 255.0; + double sourceRed = (double)sourceColor.getRed() / 255.0; + double sourceGreen = (double)sourceColor.getGreen() / 255.0; + double sourceBlue = (double)sourceColor.getBlue() / 255.0; + double sourceAlpha = (double)sourceColor.getAlpha() / 255.0; + double backgroundRed = (double)backgroundColor.getRed() / 255.0; + double backgroundGreen = (double)backgroundColor.getGreen() / 255.0; + double backgroundBlue = (double)backgroundColor.getBlue() / 255.0; // First, blend the source color to the background color using the alpha // of the source color. @@ -299,9 +301,9 @@ public ColorCafe calcDestColor (ColorCafe sourceColor, ColorCafe backgroundColor if (isLightEnabled) { // Now calculate the light color. - double lightRed = lightValue * (double)lightColor.red / 255.0; - double lightGreen = lightValue * (double)lightColor.green / 255.0; - double lightBlue = lightValue * (double)lightColor.blue / 255.0; + double lightRed = lightValue * (double)lightColor.getRed() / 255.0; + double lightGreen = lightValue * (double)lightColor.getGreen() / 255.0; + double lightBlue = lightValue * (double)lightColor.getBlue() / 255.0; // Apply the light color to the new color. red *= lightRed ; @@ -319,8 +321,8 @@ public ColorCafe calcDestColor (ColorCafe sourceColor, ColorCafe backgroundColor // Rescale the color channels to the noise::uint8 (0..255) range and return // the new color. - ColorCafe newColor = new ColorCafe((int)(red * 255.0) & 0xff,(int)(green * 255.0) & 0xff, - (int)(blue * 255.0) & 0xff, Math.max (sourceColor.alpha, backgroundColor.alpha)); + Color newColor = new Color((int)(red * 255.0) & 0xff,(int)(green * 255.0) & 0xff, + (int)(blue * 255.0) & 0xff, Math.max (sourceColor.getAlpha(), backgroundColor.getAlpha())); return newColor; } @@ -419,13 +421,13 @@ public void render () throws ExceptionInvalidParam for (int y = 0; y < height; y++) { - ColorCafe background = new ColorCafe(255, 255, 255, 255); + Color background = new Color(255, 255, 255, 255); for (int x = 0; x < width; x++) { // Get the color based on the value at the current point in the noise // map. - ColorCafe destColor = gradient.getColor (sourceNoiseMap.getValue(x,y)); + Color destColor = gradient.getColor (sourceNoiseMap.getValue(x,y)); // If lighting is enabled, calculate the light intensity based on the // rate of change at the current point in the noise map. @@ -523,7 +525,7 @@ else if (y == (int)height - 1) } // Get the current background color from the background image. - ColorCafe backgroundColor = new ColorCafe (255, 255, 255, 255); + Color backgroundColor = new Color (255, 255, 255, 255); if (backgroundImage != null) backgroundColor = backgroundImage.getValue(x, y); @@ -590,7 +592,7 @@ public double getLightBrightness () /// Returns the color of the light source. /// /// @returns The color of the light source. - public ColorCafe getLightColor () + public Color getLightColor () { return lightColor; } @@ -731,7 +733,7 @@ public void setLightBrightness (double lightBrightness) /// /// Make sure the light source is enabled via a call to the /// EnableLight() method before calling the Render() method. - public void setLightColor (ColorCafe lightColor) + public void setLightColor (Color lightColor) { this.lightColor = lightColor; } diff --git a/src/libnoiseforjava/util/RendererNormalMap.java b/src/libnoiseforjava/util/RendererNormalMap.java index f9320a5..aadefd8 100644 --- a/src/libnoiseforjava/util/RendererNormalMap.java +++ b/src/libnoiseforjava/util/RendererNormalMap.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2003, 2004 Jason Bevins (original libnoise code) - * Copyright © 2010 Thomas J. Hodge (java port of libnoise) + * Copyright � 2010 Thomas J. Hodge (java port of libnoise) * * This file is part of libnoiseforjava. * @@ -27,6 +27,8 @@ import libnoiseforjava.exception.ExceptionInvalidParam; +import java.awt.*; + public class RendererNormalMap { /// Renders a normal map from a noise map. @@ -105,7 +107,7 @@ public RendererNormalMap (int height, int width) throws ExceptionInvalidParam /// /// The spatial resolution and elevation resolution are determined by /// the application. - public ColorCafe calcNormalColor (double nc, double nr, double nu, + public Color calcNormalColor (double nc, double nr, double nu, double bumpHeight) { // Calculate the surface normal. @@ -129,7 +131,7 @@ public ColorCafe calcNormalColor (double nc, double nr, double nu, // left as example of what was here in case above conversion doesn't work. //zc = (noise::uint8)((noise::uint)((floor)((vzc + 1.0) * 127.5)) & 0xff); - return new ColorCafe (xc, yc, zc, 255); + return new Color (xc, yc, zc, 255); } /// Renders the noise map to the destination image.