Class CommonUtil

java.lang.Object
org.boxutil.util.CommonUtil

public final class CommonUtil extends Object
  • Method Details

    • getKelvinColor

      public static Color getKelvinColor(float temperature)
      Not accurate numbers.

      The value at [1000, 40000], unit is K(Kelvin).

    • RGBToHSVArray

      public static float[] RGBToHSVArray(float r, float g, float b)
    • RGBToHSV

      public static org.lwjgl.util.vector.Vector3f RGBToHSV(org.lwjgl.util.vector.Vector3f color, org.lwjgl.util.vector.Vector3f out)
    • RGBToHSV

      public static org.lwjgl.util.vector.Vector3f RGBToHSV(Color color, org.lwjgl.util.vector.Vector3f out)
    • HSVToRGBArray

      public static float[] HSVToRGBArray(float h, float s, float v)
    • HSVToRGB

      public static org.lwjgl.util.vector.Vector3f HSVToRGB(org.lwjgl.util.vector.Vector3f color, org.lwjgl.util.vector.Vector3f out)
    • HSVToRGB

      public static Color HSVToRGB(org.lwjgl.util.vector.Vector3f color)
    • HSVToRGB

      public static Color HSVToRGB(org.lwjgl.util.vector.Vector3f color, float alpha)
    • toCommonColor

      public static Color toCommonColor(@NotNull org.lwjgl.util.vector.Vector3f color)
    • clampColor3f

      public static org.lwjgl.util.vector.Vector3f clampColor3f(@NotNull org.lwjgl.util.vector.Vector3f color, org.lwjgl.util.vector.Vector3f out)
    • toCommonColor

      public static Color toCommonColor(@NotNull org.lwjgl.util.vector.Vector4f color)
    • clampColor4f

      public static org.lwjgl.util.vector.Vector4f clampColor4f(@NotNull org.lwjgl.util.vector.Vector4f color, org.lwjgl.util.vector.Vector4f out)
    • colorNormalization3f

      public static org.lwjgl.util.vector.Vector3f colorNormalization3f(@NotNull Color color, org.lwjgl.util.vector.Vector3f out)
    • colorNormalization4f

      public static org.lwjgl.util.vector.Vector4f colorNormalization4f(@NotNull Color color, org.lwjgl.util.vector.Vector4f out)
    • colorNormalization3fArray

      public static float[] colorNormalization3fArray(@NotNull Color color, float[] out)
    • colorNormalization4fArray

      public static float[] colorNormalization4fArray(@NotNull Color color, float[] out)
    • colorToByteArray

      public static byte[] colorToByteArray(Color color)
    • color4fToByteArray

      public static byte[] color4fToByteArray(org.lwjgl.util.vector.Vector4f color)
    • byteArrayToColor

      public static Color byteArrayToColor(byte... color)
      Parameters:
      color - length is 4
    • byteArrayToColor4f

      public static org.lwjgl.util.vector.Vector4f byteArrayToColor4f(byte... color)
      Parameters:
      color - length is 4
    • colorNormalization4f

      public static org.lwjgl.util.vector.Vector4f colorNormalization4f(@NotNull Color color, float alpha)
    • isZeroVector3f

      public static boolean isZeroVector3f(@NotNull org.lwjgl.util.vector.Vector3f check)
    • isZeroVector4f

      public static boolean isZeroVector4f(@NotNull org.lwjgl.util.vector.Vector4f check)
    • getVector2fArray

      public static float[] getVector2fArray(@NotNull org.lwjgl.util.vector.Vector2f vector)
    • getVector3fArray

      public static float[] getVector3fArray(@NotNull org.lwjgl.util.vector.Vector3f vector)
    • getVector4fArray

      public static float[] getVector4fArray(@NotNull org.lwjgl.util.vector.Vector4f vector)
    • getMatrix2fArray

      public static float[] getMatrix2fArray(@NotNull org.lwjgl.util.vector.Matrix2f matrix)
    • getMatrix3fArray

      public static float[] getMatrix3fArray(@NotNull org.lwjgl.util.vector.Matrix3f matrix)
    • getMatrix4fArray

      public static float[] getMatrix4fArray(@NotNull org.lwjgl.util.vector.Matrix4f matrix)
    • toMatrix2f

      public static org.lwjgl.util.vector.Matrix2f toMatrix2f(float[] array)
    • toMatrix3f

      public static org.lwjgl.util.vector.Matrix3f toMatrix3f(float[] array)
    • toMatrix4f

      public static org.lwjgl.util.vector.Matrix4f toMatrix4f(float[] array)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector2f vector)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector2f... vectors)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector3f vector)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector3f... vectors)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector4f vector)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Vector4f... vectors)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix2f matrix)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix2f... matrices)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix3f matrix)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix3f... matrices)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix4f matrix)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(org.lwjgl.util.vector.Matrix4f... matrices)
    • createPointerBuffer

      public static org.lwjgl.PointerBuffer createPointerBuffer(long... array)
    • createFloatBuffer

      public static DoubleBuffer createFloatBuffer(double... array)
    • createFloatBuffer

      public static FloatBuffer createFloatBuffer(float... array)
    • createLongBuffer

      public static LongBuffer createLongBuffer(long... array)
    • createIntBuffer

      public static IntBuffer createIntBuffer(int... array)
    • createShortBuffer

      public static ShortBuffer createShortBuffer(short... array)
    • createShortBuffer

      public static CharBuffer createShortBuffer(char... array)
    • createByteBuffer

      public static ByteBuffer createByteBuffer(byte... array)
    • createIdentityMatrix2x2f

      public static FloatBuffer createIdentityMatrix2x2f()
      Returns:
      2x2 identity matrix in buffer with 4 capacity.
    • fillIdentityMatrix2x2f

      public static FloatBuffer fillIdentityMatrix2x2f(int writePosition, @NotNull FloatBuffer target)
    • createIdentityMatrix3x3f

      public static FloatBuffer createIdentityMatrix3x3f()
      Returns:
      3x3 identity matrix in buffer with 9 capacity.
    • fillIdentityMatrix3x3f

      public static FloatBuffer fillIdentityMatrix3x3f(int writePosition, @NotNull FloatBuffer target)
    • createIdentityMatrix4x4f

      public static FloatBuffer createIdentityMatrix4x4f()
      Returns:
      4x4 identity matrix in buffer with 16 capacity.
    • fillIdentityMatrix4x4f

      public static FloatBuffer fillIdentityMatrix4x4f(int writePosition, @NotNull FloatBuffer target)
    • float16BitsToFloat

      public static float float16BitsToFloat(short src)
      Just for fast, ignore special values.
    • float16ToShort

      public static short float16ToShort(float src)
      Just for fast, ignore special values.
    • jFloat16ToFloat

      public static float jFloat16ToFloat(short floatBinary16)
      Move from java 21
    • jFloatToFloat16

      public static short jFloatToFloat16(float f)
      Move from java 21
    • float16ToShort

      public static short[] float16ToShort(float... array)
      Just for fast, ignore special values.
    • putFloat16

      public static ShortBuffer putFloat16(@NotNull ShortBuffer buffer, float src)
      Just for fast, ignore special values.
    • putFloat16

      public static ShortBuffer putFloat16(@NotNull ShortBuffer buffer, float... array)
      Just for fast, ignore special values.
    • packingBytesToShort

      public static short packingBytesToShort(byte i1, byte i0)
    • packingBytesToShort

      public static short[] packingBytesToShort(byte[] i1, byte[] i0)
    • putPackingBytes

      public static ShortBuffer putPackingBytes(@NotNull ShortBuffer buffer, int index, byte i1, byte i0)
    • putPackingBytes

      public static ShortBuffer putPackingBytes(@NotNull ShortBuffer buffer, byte i1, byte i0)
    • putPackingBytes

      public static ShortBuffer putPackingBytes(@NotNull ShortBuffer buffer, byte[] i1, byte[] i0)
    • packingBytesToInt

      public static int packingBytesToInt(byte i3, byte i2, byte i1, byte i0)
    • packingBytesToInt

      public static int[] packingBytesToInt(byte[] i3, byte[] i2, byte[] i1, byte[] i0)
    • putPackingBytes

      public static IntBuffer putPackingBytes(@NotNull IntBuffer buffer, int index, byte i3, byte i2, byte i1, byte i0)
    • putPackingBytes

      public static IntBuffer putPackingBytes(@NotNull IntBuffer buffer, byte i3, byte i2, byte i1, byte i0)
    • putPackingBytes

      public static IntBuffer putPackingBytes(@NotNull IntBuffer buffer, byte[] i3, byte[] i2, byte[] i1, byte[] i0)
    • packingBytesToFloat

      public static float packingBytesToFloat(byte i3, byte i2, byte i1, byte i0)
    • packingBytesToFloat

      public static float[] packingBytesToFloat(byte[] i3, byte[] i2, byte[] i1, byte[] i0)
    • putPackingBytes

      public static FloatBuffer putPackingBytes(FloatBuffer buffer, int index, byte i3, byte i2, byte i1, byte i0)
    • putPackingBytes

      public static FloatBuffer putPackingBytes(@NotNull FloatBuffer buffer, byte i3, byte i2, byte i1, byte i0)
    • putPackingBytes

      public static FloatBuffer putPackingBytes(@NotNull FloatBuffer buffer, byte[] i3, byte[] i2, byte[] i1, byte[] i0)
    • normalizedFloatToByte

      public static byte normalizedFloatToByte(float src)
    • normalizedFloatToByte

      public static byte[] normalizedFloatToByte(float... array)
    • putNormalizedByte

      public static ByteBuffer putNormalizedByte(@NotNull ByteBuffer buffer, float src)
    • putNormalizedByte

      public static ByteBuffer putNormalizedByte(@NotNull ByteBuffer buffer, float... array)
    • normalizedFloatToUnsignedByte

      public static byte normalizedFloatToUnsignedByte(float src)
    • normalizedFloatToUnsignedByte

      public static byte[] normalizedFloatToUnsignedByte(float... array)
    • putNormalizedUnsignedByte

      public static ByteBuffer putNormalizedUnsignedByte(@NotNull ByteBuffer buffer, float src)
    • putNormalizedUnsignedByte

      public static ByteBuffer putNormalizedUnsignedByte(@NotNull ByteBuffer buffer, float... array)
    • reverseArray

      public static Object[] reverseArray(Object[] array)
    • getRawPixels

      public static com.fs.starfarer.api.util.Pair<int[],ByteBuffer> getRawPixels(String file, int channelNum, boolean alignForward)
      Parameters:
      alignForward - true rotate the image from facing upward to facing right, i.e. rotate it in -90 angle, that force it point to positive x-axis rather than positive y-axis.
      Returns:
      int[] = {sizeX, sizeY, channelNum, pixelPreImage, ivec3(averageColor), ivec3(averageBrightColor)};

      ByteBuffer = pixels value;

    • getRawPixels

      public static com.fs.starfarer.api.util.Pair<int[],ByteBuffer> getRawPixels(String file, int channelNum)
    • getGLTexture

      public static com.fs.starfarer.api.util.Pair<int[],ByteBuffer> getGLTexture(int target, int texture, byte channelNum)
      Get the level 0 texture object bytes data.
      Parameters:
      target - GL11.GL_TEXTURE_1D and GL11.GL_TEXTURE_2D only.
      texture - only support the 8bit per channel ubyte texture, and format must be GL11.GL_RED, GL30.GL_RG, GL11.GL_RGB, GL11.GL_RGBA.
      channelNum - the channel of OpenGL texture object.
      Returns:
      int[] = {width, height, internalFormat};

      ByteBuffer = pixels value, null if format not support or failed;

      internalFormat returns 0 if failed or format not support or failed.

    • saveBytesImage

      public static boolean saveBytesImage(@Nullable String path, @Nullable String saveFileName, ByteBuffer buffer, int width, int height, byte bufferChannel)
      General method for save OpenGL texture object to local ARGB png format image.

      Root path is in 'gameRootDirectory'\ for default.

      Parameters:
      path - unneeded add a \ at the start; set to null that save to 'gameRootDirectory'\saves\images\.
      saveFileName - the name without format, length less than or equal 100; set to null that save to "SavedTexture_'System.currentTimeMillis()'.png".
      buffer - default OpenGL order, LB = positionZero, TR = positionMax.
      width - the texture width.
      height - the texture height.
      bufferChannel - the OpenGL texture object channel num: 1, 2, 3, 4. if less than 4, will set alpha channel to 255.
      Returns:
      true if success, false if failed.
    • saveGLTexture

      public static boolean saveGLTexture(@Nullable String path, @Nullable String saveFileName, int target, int texture, byte channelNum)
      Requires OpenGL 3.0 or higher and Framebuffer support.

      Save OpenGL texture object to local ARGB png format image.

      Root path is in 'gameRootDirectory'\ for default.

      Parameters:
      path - unneeded add a \ at the start; set to null that save to 'gameRootDirectory'\saves\images\.
      saveFileName - the name without format, length less than or equal 100; set to null that save to "SavedTexture_'System.currentTimeMillis()'.png".
      target - GL11.GL_TEXTURE_1D and GL11.GL_TEXTURE_2D only.
      texture - only support the 8bit per channel unsigned byte texture, and format must be GL11.GL_RED, GL30.GL_RG, GL11.GL_RGB, GL11.GL_RGBA.
      Returns:
      true if success, false if failed.
    • glDebug

      public static void glDebug(String tags, Object info) throws org.lwjgl.opengl.OpenGLException
      Throws:
      org.lwjgl.opengl.OpenGLException
    • printThrowable

      public static void printThrowable(org.apache.log4j.Logger logger, org.apache.log4j.Level level, String tips, @NotNull Throwable e)
    • printThrowable

      public static void printThrowable(org.apache.log4j.Logger logger, String tips, @NotNull Throwable e)
    • printThrowable

      public static void printThrowable(Class clazz, String tips, @NotNull Throwable e)