ewe.fx
Class Mask

java.lang.Object
  extended byewe.fx.Mask

public class Mask
extends Object

A Mask is used to include/exclude pixels of an Image. It is represented simply as an array of bytes, where each bit maps simply to a pixel of the Image (see the "bits" variable).


Field Summary
protected  byte[] bits
          This is the inclusion bitmap for the mask.
protected  int height
          The height of the mask.
protected  int width
          The width of the mask.
 
Constructor Summary
Mask(Image imageMask)
          Create a new Mask from an Image.
Mask(Image image, Color transparent)
          Create a new Mask from an Image.
Mask(int width, int height)
          Create a Mask with the specified width and height.
Mask(int width, int height, byte[] bits)
          Create a Mask with the specified width and height and using the specified bits.
 
Method Summary
static void blend(Image dest, Image src, int destX, int destY, int width, int height, int srcX, int srcY)
           
static void blend(int[] dest, int[] src)
           
 boolean fromIImage(IImage image)
          Get the bits for this mask from the alpha channel of the image.
 boolean fromImage(Image image)
          Get the bits for this mask from the alpha channel or transparent color in the image.
 boolean fromImageColor(Image image, Color transparentColor)
          Get the bits for this mask from the transparent color in the image.
 boolean fromImageColor(int[] pixels, Color transparentColor)
          Set this Masks bits based on the provided monochrome image in the form of the pixel colors of the image.
 void fromImageMask(Image imageMask)
          Set this Masks bits based on the provided monochrome (B/W) imageMask image.
 void fromImageMask(int[] pixels)
          Set this Masks bits based on the provided monochrome (B/W) imageMask image in the form of the pixel colors of the image.
 byte[] getBitmap()
           
 Mask getCopy()
          Return a copy of this mask, with its own new bit map.
 int getHeight()
           
 int getWidth()
           
static boolean hasTrueAlpha(Image im)
           
 void intersection(Mask other)
          This leaves included only bits which are included in both this Mask and the other Mask.
 void invert()
          This inverts the bitmap for the mask.
 void invert(Mask other)
          This inverts all the bits in this Mask which correspond to set bits in the other Mask.
 Image toImageMask()
          This converts this bitmap to an Image based Mask for use with mImages and Graphics.drawImage() methods.
 mImage toMImage(IImage image)
           
 mImage toMImage(IImage image, int srcX, int srcY)
          This converts the supplied image (which must be the same size as the mask) into an mImage which consists of an Image and Image mask.
 void union(Mask other)
          This unions two masks together.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

width

protected int width
The width of the mask.


height

protected int height
The height of the mask.


bits

protected byte[] bits
This is the inclusion bitmap for the mask. The bits are stored with one bit per pixel. A 1 indicates an pixel to include and a 0 indicates a pixel to ignore. Each scan line is byte aligned and the number of bytes will be height*((width+7)/8)

Constructor Detail

Mask

public Mask(int width,
            int height,
            byte[] bits)
Create a Mask with the specified width and height and using the specified bits. The bits provided are actually used by the Mask and no new byte array is created.

Parameters:
width - The width of the mask.
height - The height of the mask.
bits - The bits for the mask. This must be the correct size otherwise an exception will be thrown.

Mask

public Mask(int width,
            int height)
Create a Mask with the specified width and height. A new array will be created for the bits. The created mask will be all zeros and so be fully exclusive.

Parameters:
width - The width of the mask.
height - The height of the mask.

Mask

public Mask(Image imageMask)
Create a new Mask from an Image.

Parameters:
imageMask - The Image mask where White pixel represent excluded bits and Black pixels represent included bits.

Mask

public Mask(Image image,
            Color transparent)
Create a new Mask from an Image.

Parameters:
image - The image.
transparent - A transparent color. All bits in the image that are of this color are considered excluded from the mask, and all other bits are considered included.
Method Detail

getCopy

public Mask getCopy()
Return a copy of this mask, with its own new bit map.


getWidth

public int getWidth()

getHeight

public int getHeight()

getBitmap

public byte[] getBitmap()

invert

public void invert()
This inverts the bitmap for the mask.


union

public void union(Mask other)
This unions two masks together. All bits which are set in the other mask will also be set in this Mask.

Parameters:
other - The other Mask, which must be the same dimensions as this Mask.

intersection

public void intersection(Mask other)
This leaves included only bits which are included in both this Mask and the other Mask.

Parameters:
other - The other Mask, which must be the same dimensions as this Mask.

invert

public void invert(Mask other)
This inverts all the bits in this Mask which correspond to set bits in the other Mask.

Parameters:
other - The other Mask, which must be the same dimensions as this Mask.

toImageMask

public Image toImageMask()
This converts this bitmap to an Image based Mask for use with mImages and Graphics.drawImage() methods. It effectively creates a new black and white Image where included bits are black and excluded bits are white.


fromImageMask

public void fromImageMask(Image imageMask)
Set this Masks bits based on the provided monochrome (B/W) imageMask image. All white pixels in the image are considered to be transparent, non-white are considered to be opaque.


fromImageMask

public void fromImageMask(int[] pixels)
Set this Masks bits based on the provided monochrome (B/W) imageMask image in the form of the pixel colors of the image. All white pixels in the image are considered to be transparent, non-white are considered to be opaque.


fromImageColor

public boolean fromImageColor(int[] pixels,
                              Color transparentColor)
Set this Masks bits based on the provided monochrome image in the form of the pixel colors of the image.


fromImageColor

public boolean fromImageColor(Image image,
                              Color transparentColor)
Get the bits for this mask from the transparent color in the image.

Parameters:
image - The image to create a mask for.
Returns:
true if there are transparent areas.

fromImage

public boolean fromImage(Image image)
Get the bits for this mask from the alpha channel or transparent color in the image.

Parameters:
image - The image to create a mask for.
Returns:
true if there are transparent areas.

fromIImage

public boolean fromIImage(IImage image)
Get the bits for this mask from the alpha channel of the image.

Parameters:
image - The image to create a mask for.
Returns:
true if there are transparent areas.

toMImage

public mImage toMImage(IImage image,
                       int srcX,
                       int srcY)
This converts the supplied image (which must be the same size as the mask) into an mImage which consists of an Image and Image mask.


toMImage

public mImage toMImage(IImage image)

hasTrueAlpha

public static boolean hasTrueAlpha(Image im)

blend

public static void blend(Image dest,
                         Image src,
                         int destX,
                         int destY,
                         int width,
                         int height,
                         int srcX,
                         int srcY)
                  throws IllegalArgumentException
Throws:
IllegalArgumentException

blend

public static void blend(int[] dest,
                         int[] src)
                  throws IllegalArgumentException
Throws:
IllegalArgumentException