com.meltingice.caman.util
Class CamanUtil

java.lang.Object
  extended by com.meltingice.caman.util.CamanUtil

public class CamanUtil
extends java.lang.Object

Utility class of static methods

Version:
1.0
Author:
Ryan LeFevre

Constructor Summary
CamanUtil()
           
 
Method Summary
static int[][] buildKernel(Image image, int kernelSize, int x, int y)
          Generates a convolution kernel from the given image and location.
static int[] channelsToIntArray(java.lang.String chans)
          Converts a string of channel characters (r, g, or b) to their appropriate index in the standard rgb array.
static int[] clampRGB(double[] drgb)
          Clamps an array of doubles and returns an array of integers.
static int clampRGB(int val)
          Clamps an integer value between 0 and 255
static int[] clampRGB(int[] rgb)
          Clamps an array of integers between 0 and 255.
static java.lang.String getClassName(java.lang.String input)
          Given an input string, format it to produce the class name for a filter.
static double randomRange(double min, double max)
          Returns a pseudorandom double within the given range.
static int randomRange(int min, int max)
          Returns a pseudorandom int within the given range.
static
<T> T[]
reverseArray(T[] arr)
          Utility function to reverse an array of any type.
static double[] toDouble(int[] rgb)
          Converts an integer array to a double array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CamanUtil

public CamanUtil()
Method Detail

clampRGB

public static int clampRGB(int val)
Clamps an integer value between 0 and 255

Parameters:
val - The value to clamp
Returns:
The clamped integer

clampRGB

public static int[] clampRGB(int[] rgb)
Clamps an array of integers between 0 and 255. Useful when returning an integer array from CamanFilter.process(int[])

Parameters:
rgb - The array of integers to clamp
Returns:
The array of clamped integers

clampRGB

public static int[] clampRGB(double[] drgb)
Clamps an array of doubles and returns an array of integers. The reason it doesn't return an array of doubles is because this is designed to be returned from CamanFilter.process(int[]), and the return must be an int array. Doubles are converted to ints by simple casting, so the decimal portion of the double is dropped without rounding.

Parameters:
drgb - The array of doubles to clamp
Returns:
The array of clamped integers

toDouble

public static double[] toDouble(int[] rgb)
Converts an integer array to a double array.

Parameters:
rgb - The integer array to convert
Returns:
The array of doubles

getClassName

public static java.lang.String getClassName(java.lang.String input)
Given an input string, format it to produce the class name for a filter. All it does is capitalize the first letter of the name.

Parameters:
input - The filter name
Returns:
The formatted filter name

randomRange

public static double randomRange(double min,
                                 double max)
Returns a pseudorandom double within the given range.

Parameters:
min - The minimum inclusive value
max - The maximum inclusive value
Returns:
The pseudorandom value

randomRange

public static int randomRange(int min,
                              int max)
Returns a pseudorandom int within the given range.

Parameters:
min - The minimum inclusive value
max - The maximum inclusive value
Returns:
The pseudorandom value

channelsToIntArray

public static int[] channelsToIntArray(java.lang.String chans)
Converts a string of channel characters (r, g, or b) to their appropriate index in the standard rgb array. In other words, r => 0, g => 1, b => 2

Parameters:
chans - A string of color channels
Returns:
An array of ints representing the color channels given

reverseArray

public static <T> T[] reverseArray(T[] arr)
Utility function to reverse an array of any type.

Type Parameters:
T - Will be automatically determined from the type of object array given
Parameters:
arr - The object array to reverse
Returns:
The reversed object array

buildKernel

public static int[][] buildKernel(Image image,
                                  int kernelSize,
                                  int x,
                                  int y)
Generates a convolution kernel from the given image and location.

Parameters:
image - The image to retrieve the pixel color values from.
kernelSize - The size of the kernel to produce.
x - The x coordinate of the kernel.
y - The y coordinate of the kernel.
Returns:
The convolution kernel.