java.lang.Object
dev.lukebemish.dynamicassetgenerator.api.client.image.ImageUtils

public final class ImageUtils extends Object
A series of utilities for working with images and colors.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> void
    applyParallelScaledOperation(PointwiseOperation<T> pointwiseOperation, ImageUtils.OperationResultConsumer<T> consumer, List<com.mojang.blaze3d.platform.NativeImage> images)
    Applies a pointwise operation to a list of images, scaled so that their widths are all equal, and feeds the results and their positions to a consumer.
    static <T> void
    applyScaledOperation(PointwiseOperation<T> pointwiseOperation, ImageUtils.OperationResultConsumer<T> consumer, List<com.mojang.blaze3d.platform.NativeImage> images)
    Applies a pointwise operation to a list of images, scaled so that their widths are all equal, and feeds the results and their positions to a consumer.
    static com.mojang.datafixers.util.Pair<Integer,Integer>
    calculateScaledSize(List<com.mojang.blaze3d.platform.NativeImage> images)
    Calculates the dimensions of an image that can contain all the supplied images, scaled so that their widths are all equal.
    static com.mojang.blaze3d.platform.NativeImage
    generateScaledImage(PointwiseOperation<Integer> pointwiseOperation, List<com.mojang.blaze3d.platform.NativeImage> images)
    Generates an image by applying a pointwise operation to a list of images, scaled so that their widths are all equal.
    static Palette
    getPalette(com.mojang.blaze3d.platform.NativeImage image)
     
    static Palette
    getPalette(com.mojang.blaze3d.platform.NativeImage image, double cutoff)
     
    static int
    safeGetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y)
     
    static int
    safeGetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int def)
     
    static int
    safeGetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y)
     
    static int
    safeGetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int def)
     
    static boolean
    safeSetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int color)
    Sets the color at a given position in an image, if the position is in bounds.
    static boolean
    safeSetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int color)
    Sets the color at a given position in an image, if the position is in bounds.

    Methods inherited from class java.lang.Object

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

    • getPalette

      public static Palette getPalette(com.mojang.blaze3d.platform.NativeImage image, double cutoff)
      Returns:
      a palette with a given cutoff of colors from an image
    • getPalette

      public static Palette getPalette(com.mojang.blaze3d.platform.NativeImage image)
    • safeGetPixelABGR

      public static int safeGetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int def)
      Returns:
      the color at a given position in an image, or a default value if the position is out of bounds
    • safeGetPixelABGR

      public static int safeGetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y)
      Returns:
      the color at a given position in an image, or 0x00000000 if the position is out of bounds
    • safeSetPixelABGR

      public static boolean safeSetPixelABGR(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int color)
      Sets the color at a given position in an image, if the position is in bounds.
      Returns:
      whether the position was in bounds
    • safeGetPixelARGB

      public static int safeGetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int def)
      Returns:
      the color at a given position in an image, or a default value if the position is out of bounds, in ARGB32 encoding
    • safeGetPixelARGB

      public static int safeGetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y)
      Returns:
      the color at a given position in an image, or 0x00000000 if the position is out of bounds, in ARGB32 encoding
    • safeSetPixelARGB

      public static boolean safeSetPixelARGB(com.mojang.blaze3d.platform.NativeImage image, int x, int y, int color)
      Sets the color at a given position in an image, if the position is in bounds.
      Returns:
      whether the position was in bounds, in ARGB32 encoding
    • calculateScaledSize

      public static com.mojang.datafixers.util.Pair<Integer,Integer> calculateScaledSize(List<com.mojang.blaze3d.platform.NativeImage> images)
      Calculates the dimensions of an image that can contain all the supplied images, scaled so that their widths are all equal.
    • applyScaledOperation

      public static <T> void applyScaledOperation(PointwiseOperation<T> pointwiseOperation, ImageUtils.OperationResultConsumer<T> consumer, List<com.mojang.blaze3d.platform.NativeImage> images)
      Applies a pointwise operation to a list of images, scaled so that their widths are all equal, and feeds the results and their positions to a consumer.
      Type Parameters:
      T - the type of data generated by the operation
      Parameters:
      pointwiseOperation - the operation to apply
      consumer - the consumer to feed the results to - accepts the x and y coordinates of the pixel, and the data generated by the operation
      images - the images to apply the operation to. The number of images must match the number expected by the operation, or the operation must expect any number of images
    • applyParallelScaledOperation

      public static <T> void applyParallelScaledOperation(PointwiseOperation<T> pointwiseOperation, ImageUtils.OperationResultConsumer<T> consumer, List<com.mojang.blaze3d.platform.NativeImage> images)
      Applies a pointwise operation to a list of images, scaled so that their widths are all equal, and feeds the results and their positions to a consumer. The operation is applied in parallel, and the provided operation and consumer must be thread-safe.
      Type Parameters:
      T - the type of data generated by the operation
      Parameters:
      pointwiseOperation - the operation to apply
      consumer - the consumer to feed the results to - accepts the x and y coordinates of the pixel, and the data generated by the operation
      images - the images to apply the operation to. The number of images must match the number expected by the operation, or the operation must expect any number of images
    • generateScaledImage

      public static com.mojang.blaze3d.platform.NativeImage generateScaledImage(PointwiseOperation<Integer> pointwiseOperation, List<com.mojang.blaze3d.platform.NativeImage> images)
      Generates an image by applying a pointwise operation to a list of images, scaled so that their widths are all equal.
      Parameters:
      pointwiseOperation - the operation to apply. Is applied in parallel and must be threadsafe
      images - the images to apply the operation to. The number of images must match the number expected by the operation, or the operation must expect any number of images
      Returns:
      the generated image