Class ImageUtil

java.lang.Object
dev.jensderuiter.minecraft_imagery.image.ImageUtil

public class ImageUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Color
    applyDye(Color color, double[] dye)
    Applies a dye to a color by multiplying each color plane with their dye counterparts.
    static double[]
    applyToDye(double[] currentDye, double[] dyeToApply, float factor)
    Subtracts a dye to another dye.
    static Color
    colorFromType(org.bukkit.block.Block block, double[] dye)
    Gets the color for a block and applies a dye to it.
    static double
    difference(double val1, double val2)
    Returns the difference between two numbers regardless of one or the other being negative.
    static Color
    Calculates the average color from an image.
    static boolean
    isWithinBlockIgnoreY(org.bukkit.Location loc1, org.bukkit.Location loc2)
    Checks if the two locations are inside the same block, ignoring the Y-axis.
    static float
    positiveYaw(float rawYaw)
    Returns a yaw that is always a positive number.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ImageUtil

      public ImageUtil()
  • Method Details

    • applyToDye

      public static double[] applyToDye(double[] currentDye, double[] dyeToApply, float factor)
      Subtracts a dye to another dye. It does this by subtracting the multiplied value of the other color planes from a plane.
      Parameters:
      currentDye - The dye to subtract the dyeToApply from. (3-element array with 0-1 values).
      dyeToApply - The dye that will be subtracted from currentDye (3-element array 0-1 values).
      factor - A float which will be multiplied by each color plane's end result. Used to apply intensity on an individual basis.
      Returns:
      The resulting dye (3-element double array).
    • applyDye

      public static Color applyDye(Color color, double[] dye)
      Applies a dye to a color by multiplying each color plane with their dye counterparts.
      Parameters:
      color - The color to apply the dye to.
      dye - The dye that will be multiplied with the color (3-element array).
      Returns:
      The resulting color.
    • getColorFromImage

      public static Color getColorFromImage(BufferedImage bi)
      Calculates the average color from an image. Inspired by: https://stackoverflow.com/questions/28162488/get-average-color-on-bufferedimage-and-bufferedimage-portion-as-fast-as-possible.
      Parameters:
      bi - The image that the color will be sampled from.
      Returns:
      The average color of the image.
    • colorFromType

      public static Color colorFromType(org.bukkit.block.Block block, double[] dye)
      Gets the color for a block and applies a dye to it.
      Parameters:
      block - The block to get the color for.
      dye - The dye to apply to the color for the block (3-element array).
      Returns:
      The ready-to-use color from the block with the dye applied.
    • isWithinBlockIgnoreY

      public static boolean isWithinBlockIgnoreY(org.bukkit.Location loc1, org.bukkit.Location loc2)
      Checks if the two locations are inside the same block, ignoring the Y-axis.
      Parameters:
      loc1 - The location to check against loc2.
      loc2 - The location to check against loc1.
      Returns:
      A boolean that only is true when the locations are both in the same X and Z value.
    • positiveYaw

      public static float positiveYaw(float rawYaw)
      Returns a yaw that is always a positive number. The returned value will resemble a 360-degree output.
      Parameters:
      rawYaw - The yaw gotten from spigot (-180 to 180)
      Returns:
      The transformed yaw (0 to 360).
    • difference

      public static double difference(double val1, double val2)
      Returns the difference between two numbers regardless of one or the other being negative.
      Parameters:
      val1 - The first value.
      val2 - The second value.
      Returns:
      The difference between the two values.