Class BitmapTransform

java.lang.Object
net.paulhertz.pixelaudio.BitmapTransform

public class BitmapTransform extends Object

Provides static methods for rotating and reflecting 2D integer arrays using index remapping. For methods that accept an int[] array and width and height parameters, the arrays may be bitmap pixel arrays, but not necessarily--they could represent index values over a large bitmap or integer data of any sort, such as the LUTs generated by PixelMapGen subclasses. Methods that take a PImage as an argument will use the PImage.pixels array, and resize the image when necessary. Map methods that accept width and height parameters return arrays of transformed pixel indices.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[]
    coordTransform(int x, int y, int width, int height, AffineTransformType type)
    Performs a geometric transform (rotation, reflection) of a single pixel location.
    static int[]
    flipX(int[] pixels, int width, int height)
    Reflects an array of integers on vertical axis, as determined by width and height arguments, flipping x-coordinates.
    static processing.core.PImage
    flipX(processing.core.PImage img)
    Reflects a PImage on the vertical axis, flipping the x-coordinates.
    static int[]
    flipX270(int[] pixels, int width, int height)
    Reflects an array of integers on the secondary diagonal, as determined by width and height arguments.
    static processing.core.PImage
    flipX270(processing.core.PImage img)
    Reflects a PImage on the secondary diagonal, running from lower left to upper right.
    static int[]
    flipX270Coord(int x, int y, int w, int h)
    Reflect x and y on secondary diagonal.
    static int[]
    flipX270Map(int width, int height)
    Generates a map to reflect pixels on secondary diagonal.
    static int[]
    flipX90(int[] pixels, int width, int height)
    Reflects an array of integers on the primary diagonal, as determined by width and height arguments.
    static processing.core.PImage
    flipX90(processing.core.PImage img)
    Reflects a PImage on the primary diagonal, running from upper left to lower right.
    static int[]
    flipX90Coord(int x, int y, int w, int h)
    Reflect x and y on primary diagonal.
    static int[]
    flipX90Map(int width, int height)
    Generates a map to reflect pixels on primary diagonal.
    static int[]
    flipXCoord(int x, int y, int w, int h)
     
    static int[]
    flipXMap(int width, int height)
    Generates a map to reflect pixels on the vertical axis, flipping x-coordinates.
    static int[]
    flipY(int[] pixels, int width, int height)
    Reflects an array of integers on the horizontal axis, as determined by width and height arguments, flipping y-coordinates.
    static processing.core.PImage
    flipY(processing.core.PImage img)
    Reflects a PImage on the horizontal axis, flipping the y-coordinates.
    static int[]
    flipYCoord(int x, int y, int w, int h)
     
    static int[]
    flipYMap(int width, int height)
    Generates a map to reflect pixels on the horizontal axis, flipping y-coordinates.
    static int[]
    getIndexMap(int w, int h, AffineTransformType type)
     
    static processing.core.PImage
    imageTransform(processing.core.PImage img, AffineTransformType type)
     
    static int[]
    nadaCoord(int x, int y, int w, int h)
    Don't do nothing, no, no, no, just return an array with x and y.
    static int[]
    nadaMap(int width, int height)
    Generates a map to leave a pixel array unchanged: the don't do nothing map, oh no, nada, nothing map.
    static int[]
    pixelsTransform(int[] pixels, int width, int height, AffineTransformType type)
    Performs a geometric transform (rotation, reflection) of an array of pixels.
    static int[]
    rotate180(int[] pixels, int width, int height)
    Rotates an array of integers 180 degrees, as determined by width and height arguments.
    static processing.core.PImage
    rotate180(processing.core.PImage img)
    Rotates a PImage 180 degrees.
    static int[]
    rotate180Coord(int x, int y, int w, int h)
     
    static int[]
    rotate180Map(int width, int height)
    Generates a map to rotate pixels 180 degrees.
    static int[]
    rotate270(int[] pixels, int width, int height)
    Rotates an array of integers 90 degrees clockwise, as determined by width and height arguments.
    static processing.core.PImage
    rotate270(processing.core.PImage img)
    Rotates a PImage 90 degrees clockwise.
    static int[]
    rotate270Coord(int x, int y, int w, int h)
     
    static int[]
    rotate270Map(int width, int height)
    Generates a map to rotate pixels 90 degrees CW.
    static int[]
    rotate90(int[] pixels, int width, int height)
    Rotates an array of integers 90 degrees counter-clockwise, as determined by width and height arguments.
    static processing.core.PImage
    rotate90(processing.core.PImage img)
    Rotates a PImage 90 degrees counter-clockwise.
    static int[]
    rotate90Coord(int x, int y, int w, int h)
     
    static int[]
    rotate90Map(int width, int height)
    Generates a map to rotate pixels 90 degrees CCW.

    Methods inherited from class java.lang.Object

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

    • BitmapTransform

      public BitmapTransform()
  • Method Details

    • imageTransform

      public static processing.core.PImage imageTransform(processing.core.PImage img, AffineTransformType type)
      Parameters:
      img - a PImage to transform
      type - a geometric transform (rotation, reflection) to perform on img
      Returns:
      transformed image
    • pixelsTransform

      public static int[] pixelsTransform(int[] pixels, int width, int height, AffineTransformType type)
      Performs a geometric transform (rotation, reflection) of an array of pixels.
      Parameters:
      pixels - an array of integers, possibly RGB or ARGB colors or array indices
      width - width of bitmap for pixel
      height - height of bitmap for pixel
      type - type of geometric transform for the bitmap
      Returns:
      transformed coordinate pair, as determined by width, height, and transform type
    • coordTransform

      public static int[] coordTransform(int x, int y, int width, int height, AffineTransformType type)
      Performs a geometric transform (rotation, reflection) of a single pixel location.
      Parameters:
      x - x-coordinate of a pixel
      y - y-coordinate of a pixel
      width - width of bitmap for pixel
      height - height of bitmap for pixel
      type - type of geometric transform for the bitmap
      Returns:
      transformed coordinate pair, as determined by width, height, and transform type
    • getIndexMap

      public static int[] getIndexMap(int w, int h, AffineTransformType type)
      Parameters:
      w - bitmap width
      h - bitmap height
      type - type of affine transform
      Returns:
      array of bitmap indices reordered in accordance with the desired transform
    • rotate270

      public static int[] rotate270(int[] pixels, int width, int height)
      Rotates an array of integers 90 degrees clockwise, as determined by width and height arguments. In computer graphics standards, rotation counterclockwise, so this is rotate270 in CG parlance.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • rotate90

      public static int[] rotate90(int[] pixels, int width, int height)
      Rotates an array of integers 90 degrees counter-clockwise, as determined by width and height arguments. In computer graphices, this is a standard 90 degree rotation.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • rotate180

      public static int[] rotate180(int[] pixels, int width, int height)
      Rotates an array of integers 180 degrees, as determined by width and height arguments.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • flipX

      public static int[] flipX(int[] pixels, int width, int height)
      Reflects an array of integers on vertical axis, as determined by width and height arguments, flipping x-coordinates.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • flipY

      public static int[] flipY(int[] pixels, int width, int height)
      Reflects an array of integers on the horizontal axis, as determined by width and height arguments, flipping y-coordinates.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • flipX90

      public static int[] flipX90(int[] pixels, int width, int height)
      Reflects an array of integers on the primary diagonal, as determined by width and height arguments.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • flipX270

      public static int[] flipX270(int[] pixels, int width, int height)
      Reflects an array of integers on the secondary diagonal, as determined by width and height arguments.
      Parameters:
      pixels - an array of integer values, possibly RGB or ARGB colors or array indices
      width - width of the bitmap for the pixels array
      height - height of the bitmap for the pixels array
      Returns:
      a transformed copy of the pixels array
    • rotate270

      public static processing.core.PImage rotate270(processing.core.PImage img)
      Rotates a PImage 90 degrees clockwise.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • rotate90

      public static processing.core.PImage rotate90(processing.core.PImage img)
      Rotates a PImage 90 degrees counter-clockwise.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • rotate180

      public static processing.core.PImage rotate180(processing.core.PImage img)
      Rotates a PImage 180 degrees.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • flipX

      public static processing.core.PImage flipX(processing.core.PImage img)
      Reflects a PImage on the vertical axis, flipping the x-coordinates.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • flipY

      public static processing.core.PImage flipY(processing.core.PImage img)
      Reflects a PImage on the horizontal axis, flipping the y-coordinates.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • flipX90

      public static processing.core.PImage flipX90(processing.core.PImage img)
      Reflects a PImage on the primary diagonal, running from upper left to lower right.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • flipX270

      public static processing.core.PImage flipX270(processing.core.PImage img)
      Reflects a PImage on the secondary diagonal, running from lower left to upper right.
      Parameters:
      img - a PImage
      Returns:
      transformed image
    • rotate270Coord

      public static int[] rotate270Coord(int x, int y, int w, int h)
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • rotate90Coord

      public static int[] rotate90Coord(int x, int y, int w, int h)
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • rotate180Coord

      public static int[] rotate180Coord(int x, int y, int w, int h)
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • flipXCoord

      public static int[] flipXCoord(int x, int y, int w, int h)
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • flipYCoord

      public static int[] flipYCoord(int x, int y, int w, int h)
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • flipX90Coord

      public static int[] flipX90Coord(int x, int y, int w, int h)
      Reflect x and y on primary diagonal.
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • flipX270Coord

      public static int[] flipX270Coord(int x, int y, int w, int h)
      Reflect x and y on secondary diagonal.
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      transformed coordinates {x, y}
    • nadaCoord

      public static int[] nadaCoord(int x, int y, int w, int h)
      Don't do nothing, no, no, no, just return an array with x and y.
      Parameters:
      x - x-coordinate of pixel
      y - y-coordinate of pixel
      w - width of bitmap
      h - height of bitmap
      Returns:
      untransformed coordinates {x, y}
    • rotate270Map

      public static int[] rotate270Map(int width, int height)
      Generates a map to rotate pixels 90 degrees CW.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform of 90 degrees CW
    • rotate90Map

      public static int[] rotate90Map(int width, int height)
      Generates a map to rotate pixels 90 degrees CCW.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform of 90 degrees CCW
    • rotate180Map

      public static int[] rotate180Map(int width, int height)
      Generates a map to rotate pixels 180 degrees.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform rotates 180 degrees
    • flipXMap

      public static int[] flipXMap(int width, int height)
      Generates a map to reflect pixels on the vertical axis, flipping x-coordinates.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform that reflects on Y-axis
    • flipYMap

      public static int[] flipYMap(int width, int height)
      Generates a map to reflect pixels on the horizontal axis, flipping y-coordinates.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform that reflects on X-axis
    • flipX90Map

      public static int[] flipX90Map(int width, int height)
      Generates a map to reflect pixels on primary diagonal.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform that reflects on primary diagonal
    • flipX270Map

      public static int[] flipX270Map(int width, int height)
      Generates a map to reflect pixels on secondary diagonal.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform that reflects on secondary diagonal
    • nadaMap

      public static int[] nadaMap(int width, int height)
      Generates a map to leave a pixel array unchanged: the don't do nothing map, oh no, nada, nothing map.
      Parameters:
      width - width of transformation map
      height - height of transformation map
      Returns:
      look up table for a geometric transform that does nothing