public class PixelBuffer extends ImageObject
PixelBuffers are generally used for composing complex images with alpha (transparency) channels. This may be necessary because the normal draw operations done via a Graphics object do not support the writing of alpha channel data. For example, you cannot use fillRect() to fill an area of a drawing surface with a particular color that has an alpha channel.
Any Images created out of the data from the PixelBuffer will be considered to have an alpha (transparency) channel.
Modifier and Type | Field and Description |
---|---|
static int |
PUT_BLEND
This is used with put() - it alpha blends in the incoming data with this PixelBuffer's data.
|
static int |
PUT_NONTRANSPARENT_ONLY
This is used with put() and the PUT_SET option - it overwrites this PixelBuffer's data with in the incoming data so
long as the incoming data is NOT FULLY TRANSPARENT (i.e an alpha value of 0).
|
static int |
PUT_SET
This is used with put() - it overwrites this PixelBuffer's data with in the incoming data.
|
static int |
SCALE_KEEP_ASPECT_RATIO
An option for scale().
|
static int |
TRANSFORM_MIRROR_HORIZONTAL
This is a transformation for the transform() method.
|
static int |
TRANSFORM_MIRROR_VERTICAL
This is a transformation for the transform() method.
|
static int |
TRANSFORM_ROTATE_180
This is a transformation for the transform() method.
|
static int |
TRANSFORM_ROTATE_270
This is a transformation for the transform() method.
|
static int |
TRANSFORM_ROTATE_90
This is a transformation for the transform() method.
|
background, height, width
CREATE_OPTION_DONT_SCALE_UP, CREATE_OPTION_IGNORE_ALPHA, CREATE_OPTION_KEEP_ASPECT_RATIO, CREATE_OPTION_ROUGH_SCALING, SCAN_LINE_BYTE_ARRAY, SCAN_LINE_INT_ARRAY, TYPE_ARGB, TYPE_GRAY_SCALE_16, TYPE_GRAY_SCALE_2, TYPE_GRAY_SCALE_256, TYPE_GRAY_SCALE_4, TYPE_INDEXED_16, TYPE_INDEXED_2, TYPE_INDEXED_256, TYPE_INDEXED_4, TYPE_MASK, TYPE_MONO, TYPE_RGB, TYPE_UNKNOWN
Constructor and Description |
---|
PixelBuffer()
After using this constructor you must call resizeTo() or setTo() before
attempting to access the pixels.
|
PixelBuffer(FormattedDataSource fds) |
PixelBuffer(FormattedDataSource fds,
Rect sourceArea,
Dimension newSize,
int createOptions) |
PixelBuffer(ImageData from) |
PixelBuffer(ImageData from,
Rect area) |
PixelBuffer(ImageData from,
Rect sourceArea,
Dimension newSize,
Object useBuffer) |
PixelBuffer(IntArray buffer,
ImageData src,
Rect area) |
PixelBuffer(IntArray buffer,
int width,
int height)
Create a new PixelBuffer using the IntArray to hold the pixel int array.
|
PixelBuffer(int width,
int height) |
PixelBuffer(int width,
int height,
int[] bufferToUse) |
PixelBuffer(String name) |
Modifier and Type | Method and Description |
---|---|
PixelBuffer |
blend(Drawable d,
int drawX,
int drawY,
Color unusedColor,
double alpha) |
void |
blend(PixelBuffer other,
int x,
int y)
This is the same as put(other,x,y,PUT_BLEND).
|
void |
bufferChanged()
If you modify the pixels in the buffer as provided by getBuffer(), then
call this method to let the buffer know about the changes.
|
void |
cache() |
void |
clear()
Erase the contents but do not resize.
|
void |
createImageFor(ImageDataInfo imageInfo,
Rect interestedArea)
This is called at the start of decoding - to let the ImageMaker know the parameters
of the image to be created.
|
PixelBuffer |
draw(Drawable d,
int drawX,
int drawY,
Color unusedColor,
double alpha,
int put_operation) |
void |
draw(Graphics g,
int x,
int y,
int options) |
void |
free() |
PixelBuffer |
getArea(int x,
int y,
int width,
int height) |
int[] |
getBuffer()
This exposes the internal buffer that contains the pixel data.
|
static PixelBuffer |
getCached() |
Graphics |
getCurrentDrawingBuffer()
Return the last Graphics returned by getDrawingBuffer().
|
Graphics |
getDrawingBuffer(Rect area,
Color transparent,
double alphaValue)
This will create a drawing surface, initially filled with the supplied transparent color.
|
Graphics |
getDrawingBuffer(Rect area,
Color transparent,
double alphaValue,
Color drawingColor)
This will create a drawing surface, initially filled with the supplied transparent color.
|
int |
getHeight() |
void |
getImageScanLines(int startLine,
int numLines,
Object destArray,
int offset,
int destScanLineLength)
Place a set of scan lines into a destination array.
|
static PixelBuffer |
getImageSection(IImage image,
Mask m,
Point p,
double alphaValue)
This gets a section of an Image, starting at a particular point and in a shape represented by Mask.
|
int[] |
getPixels(int[] dest,
int offset,
int x,
int y,
int w,
int h,
int rowStride)
Retrieve the pixels from the Image in encoded ARGB values.
|
static int[] |
getPixelsFor(IImage image,
int[] dest,
int offset,
Rect area,
int options,
Color substituteBackground)
This will attempt to get pixels for an IImage.
|
int |
getWidth() |
boolean |
isWriteableImage()
Returns if you can write data to the ImageData.
|
PixelBuffer |
put(Drawable d,
int drawX,
int drawY,
Color unusedColor,
double alpha) |
void |
put(PixelBuffer other,
int x,
int y,
int operation)
This merges the pixels from the other PixelBuffer with the pixels in this PixelBuffer at the
specified location.
|
void |
put(PixelBuffer other,
int x,
int y,
int operation,
Mask mask)
This merges the pixels from the other PixelBuffer with the pixels in this PixelBuffer at the
specified location.
|
void |
putDrawingBuffer(int operation)
Call this after calling getDrawingBuffer() to update this PixelBuffer with the data you
have drawn.
|
void |
putDrawingBuffer(int operation,
Color fullyOpaque,
Color fullyTransparent)
Call this after calling getDrawingBuffer() to update this PixelBuffer with the data you
have drawn if you want to alter the alpha value of the pixels in the PixelBuffer depending
on the difference in color of the pixels between the fullyOpaque and the fullyTransparent color
(which should be as different as possible).
|
void |
putDrawingBuffer(int operation,
Mask mask)
Call this after calling getDrawingBuffer() to update this PixelBuffer with the data you
have drawn, in the area specified by the mask.
|
int[] |
resizeTo(int width,
int height,
int[] bufferToUse)
Resize the PixelBuffer to the specified size and setting it to use the specified
int array as its pixel buffer.
|
PixelBuffer |
scale(int newWidth,
int newHeight) |
PixelBuffer |
scale(int newWidth,
int newHeight,
Object useBuffer) |
PixelBuffer |
scale(int newWidth,
int newHeight,
Rect sourceArea,
int scaleOptions,
Object useBuffer)
Scale the PixelBuffer to produce a new PixelBuffer - optionally scaling only a portion of
the original PixelBuffer.
|
PixelBuffer |
scaleAlpha(double byHowMuch)
This method will go through the pixel buffer data and scale the alpha value of
each pixel by the specified amount - not allowing any alpha value to go higher than 1.0.
|
PixelBuffer |
setAlpha(Color fullyOpaque,
Color fullyTransparent,
double alpha) |
PixelBuffer |
setAlpha(Color transparent,
double alpha)
This method will go through the pixel buffer data and set the alpha value of each
pixel to the specified value (between 0.0 and 1.0), EXCEPT for any pixels that is equal
to the transparent Color - those pixels will be set to have an alpha value of 0.
|
PixelBuffer |
setAlpha(double alpha)
This method will go through the pixel buffer data and set the alpha value of each
pixel to the specified value (between 0.0 and 1.0).
|
PixelBuffer |
setAlpha(Mask mask,
double alpha)
This method will go through the pixel buffer data and set the alpha value of each
pixel which is included in the mask.
|
void |
setImageScanLines(int startLine,
int numLines,
Object sourceArray,
int offset,
int sourceScanLineLength)
Place a set of scan lines from a source Array into the ImageData.
|
boolean |
setPixels(int[] dest,
int offset,
int x,
int y,
int w,
int h,
int rowStride)
Set the pixels in the IImage in encoded ARGB values.
|
PixelBuffer |
setTo(Drawable d,
int sx,
int sy,
Color unusedColor)
Deprecated.
use one of the draw()/put()/blend() methods instead.
|
PixelBuffer |
setTo(Font f,
String text,
int alignment,
Color color,
double alphaValue)
Set this PixelBuffer to be text with possible blended edges represented
by reduced alpha values.
|
PixelBuffer |
setTo(Font f,
StringList text,
int alignment,
Color color,
double alphaValue,
FormattedTextSpecs fts)
Set this PixelBuffer to be text with possible blended edges represented
by reduced alpha values.
|
void |
setTo(FormattedDataSource fds) |
PixelBuffer |
setTo(ImageData sourceData)
Set the PixelBuffer dimensions to match the source IImage and set the pixels
in the PixelBuffer from the source.
|
PixelBuffer |
setTo(ImageData sourceData,
Rect area)
Set the PixelBuffer dimensions to match an area in a source IImage and set the pixels
in the PixelBuffer from the area in the source.
|
PixelBuffer |
setTo(ImageData sourceData,
Rect area,
Color fullyOpaque,
Color fullyTransparent,
double opaqueAlpha)
Set the PixelBuffer dimensions to match an area in a source IImage and set the pixels
in the PixelBuffer from the area in the source.
|
void |
setTransparentColor(Color c)
Go through the PixelBuffer and set the RGB of any pixel that is completely transparent (alpha value of 0)
to that specified in the Color.
|
Image |
toImage()
This returns a new Image with an alpha channel
from the pixels within this PixelBuffer.
|
Picture |
toPicture()
This returns a new Picture with an alpha channel
from the pixels within this PixelBuffer.
|
static PixelBuffer |
toPixelBuffer(ImageData data,
PixelBuffer reused)
Return an ImageData as a PixelBuffer.
|
PixelBuffer |
transform(int transformation,
Object useBuffer)
This does one of a number of specific transformations on the PixelBuffer.
|
boolean |
usesAlpha()
This always returns true.
|
draw, draw, freeImage, getBackground, getCompatibleImagePoints, getDPI, getImageColorTable, getImageData, getImageHeight, getImageScanLineLength, getImageScanLineType, getImageType, getImageWidth, getNativeDrawable, getPixelsUsingScanLines, getScanLinesUsingPixels, isReadableImage, scanLinesComplete, setPixelsUsingScanLines, setScanLinePixels, setScanLinesUsingPixels
public static final int PUT_BLEND
public static final int PUT_SET
public static final int PUT_NONTRANSPARENT_ONLY
public static final int SCALE_KEEP_ASPECT_RATIO
public static final int TRANSFORM_ROTATE_90
public static final int TRANSFORM_ROTATE_180
public static final int TRANSFORM_ROTATE_270
public static final int TRANSFORM_MIRROR_HORIZONTAL
public static final int TRANSFORM_MIRROR_VERTICAL
public PixelBuffer(IntArray buffer, int width, int height)
buffer
- the buffer to use.width
- the width of the PixelBufferheight
- the height of the PixelBuffer.public PixelBuffer(int width, int height, int[] bufferToUse) throws IllegalArgumentException
IllegalArgumentException
public PixelBuffer(int width, int height) throws IllegalArgumentException
IllegalArgumentException
public PixelBuffer(String name) throws ImageDecodingException
ImageDecodingException
public PixelBuffer(FormattedDataSource fds) throws ImageDecodingException
ImageDecodingException
public PixelBuffer(FormattedDataSource fds, Rect sourceArea, Dimension newSize, int createOptions) throws ImageDecodingException
ImageDecodingException
public PixelBuffer(ImageData from, Rect area) throws IllegalArgumentException
IllegalArgumentException
public PixelBuffer(ImageData from)
public PixelBuffer()
public static PixelBuffer toPixelBuffer(ImageData data, PixelBuffer reused)
data
- an ImageDatareused
- an optional PixelBuffer to re-use.public int[] resizeTo(int width, int height, int[] bufferToUse)
width
- the new width.height
- the new height.bufferToUse
- the buffer to use, if it is null it will continue using
its old buffer.public void clear()
public void createImageFor(ImageDataInfo imageInfo, Rect interestedArea) throws IllegalArgumentException
ImageMaker
createImageFor
in interface ImageMaker
createImageFor
in class ImageObject
imageInfo
- information on the image to be decoded.interestedArea
- when the method is called this is set to be the
full area of the image (0,0,imageWidth,imageHeight). This method
can alter this Rect to be a sub-area within the image. In that case
the object that is providing pixel data will know that it need
not provide pixel data outside that area. However you should not
assume that this will strictly be adhered to. It is possible
that all pixels for the entire image may still be provided to
setScanLinePixels().IllegalArgumentException
- if the ImageMaker decides it cannot create the image.public void setTo(FormattedDataSource fds) throws ImageDecodingException
ImageDecodingException
public PixelBuffer setTo(ImageData sourceData)
source
- a source IImage.public PixelBuffer setTo(ImageData sourceData, Rect area) throws IllegalArgumentException
source
- a source IImagearea
- an area within the IImage.IllegalArgumentException
public PixelBuffer setTo(Drawable d, int sx, int sy, Color unusedColor)
d
- the Drawable to capture.sx
- the start x location in the Drawable to capture from.sy
- the start y location in the Drawable to capture from.unusedColor
- an optional color that is definitely unused by the drawable.public PixelBuffer draw(Drawable d, int drawX, int drawY, Color unusedColor, double alpha, int put_operation)
public PixelBuffer put(Drawable d, int drawX, int drawY, Color unusedColor, double alpha)
public PixelBuffer blend(Drawable d, int drawX, int drawY, Color unusedColor, double alpha)
public int[] getBuffer()
public void bufferChanged()
public int getWidth()
getWidth
in interface Drawable
getWidth
in class ImageObject
public int getHeight()
getHeight
in interface Drawable
getHeight
in class ImageObject
public void free()
free
in interface Drawable
free
in class ImageObject
public void blend(PixelBuffer other, int x, int y)
public void put(PixelBuffer other, int x, int y, int operation)
other
- The other PixelBuffer to merge with this one.x
- The x location where the incoming PixelBuffer should be put.y
- The y location where the incoming PixelBuffer should be put.operation
- This should be either PUT_SET or PUT_BLEND. If PUT_SET is used you can
also specify PUT_NONTRANSPARENT_ONLY which tells it to replace pixels in this PixelBuffer
ONLY if the corresponding incoming pixels are not fully transparent.public void put(PixelBuffer other, int x, int y, int operation, Mask mask)
other
- The other PixelBuffer to merge with this one.x
- The x location where the incoming PixelBuffer should be put.y
- The y location where the incoming PixelBuffer should be put.operation
- This should be either PUT_SET or PUT_BLEND.mask
- A mask specifying which incoming pixels should be merged with the Pixels in
this PixelBuffer.public PixelBuffer setAlpha(double alpha)
alpha
- The alpha value between 0.0 and 1.0public PixelBuffer setAlpha(Color transparent, double alpha)
transparent
- the transparent Color.alpha
- The alpha value between 0.0 and 1.0public PixelBuffer setAlpha(Color fullyOpaque, Color fullyTransparent, double alpha)
public PixelBuffer setAlpha(Mask mask, double alpha)
mask
- The pixel mask.alpha
- The alpha value between 0.0 and 1.0public PixelBuffer scaleAlpha(double byHowMuch)
public boolean usesAlpha()
public boolean isWriteableImage()
ImageData
public Graphics getDrawingBuffer(Rect area, Color transparent, double alphaValue)
area
- An area within the pixbuf to use - will default to the entire area if null.transparent
- The initial color to consider the transparent color when putting
the area back into the PixelBuffer, or Color(80,255,80) if none is supplied.alphaValue
- the alphaValue to set all the non-transparent pixels to (between 0.0 and 1.0).public Graphics getDrawingBuffer(Rect area, Color transparent, double alphaValue, Color drawingColor)
area
- An area within the pixbuf to use - will default to the entire area if null.transparent
- The initial color to consider the transparent color when putting
the area back into the PixelBuffer, or Color(80,255,80) if none is supplied.alphaValue
- the alphaValue to set all the non-transparent pixels to (between 0.0 and 1.0).drawingColor
- the color that is to be considered fully opaque. Colors
between this color and the transparent color will be scaled in alpha between
the alphaValue supplied and a zero alpha color. If this is null then no
scaling of the alpha value is done.public Graphics getCurrentDrawingBuffer()
public void putDrawingBuffer(int operation)
operation
- One of PUT_BLEND or PUT_SETpublic void putDrawingBuffer(int operation, Mask mask)
operation
- One of PUT_BLEND or PUT_SETmask
- A mask specifying which pixels should be put. Any pixels not in this area are unchanged.public void putDrawingBuffer(int operation, Color fullyOpaque, Color fullyTransparent)
The "value" of a pixel bit is determined by averaging the RGB values. Values with an average equal to the fullyOpaque value is set to the full alpha value specified in getDrawingBuffer(). Values with an average equal to the fullyTransparent value is set to a zero alpha value. This will put the data that was drawn onto the Graphics created by getDrawingBuffer(), using one of the PUT_ operations.
operation
- One of PUT_BLEND or PUT_SETfullyOpaque
- pixels with this color will be assigned the greatest alpha value (the value
specified in getDrawingBuffer()).fullyTransparent
- pixels with this color will be assigned an alpha value
of zero.public PixelBuffer setTo(ImageData sourceData, Rect area, Color fullyOpaque, Color fullyTransparent, double opaqueAlpha) throws IllegalArgumentException
source
- a source IImagearea
- an area within the IImage.IllegalArgumentException
public Image toImage()
public Picture toPicture()
public void draw(Graphics g, int x, int y, int options)
public PixelBuffer getArea(int x, int y, int width, int height) throws IllegalArgumentException
IllegalArgumentException
public PixelBuffer scale(int newWidth, int newHeight, Object useBuffer)
public PixelBuffer scale(int newWidth, int newHeight)
public PixelBuffer scale(int newWidth, int newHeight, Rect sourceArea, int scaleOptions, Object useBuffer) throws IllegalArgumentException
newWidth
- The width of the new PixelBuffer.newHeight
- The height of the new PixelBuffer.sourceArea
- An optional rectangle specifying the source area in this PixelBuffer.
If it is null then entire area is used.scaleOptions
- This can be zero or SCALE_KEEP_ASPECT_RATIO.useBuffer
- An optional re-usable buffer to use for the data calculations. It can
be a ByteArray or a byte [] object.IllegalArgumentException
- If there was an error with any of the arguments.public PixelBuffer transform(int transformation, Object useBuffer)
transformation
- One of the TRANSFORM_XXX values.useBuffer
- An optional int [] or IntArray object to use as the buffer for the
newly created PixelBuffer, or a PixelBuffer.public int[] getPixels(int[] dest, int offset, int x, int y, int w, int h, int rowStride) throws IllegalArgumentException
ImageData
dest
- The destination int array. If this is null then a new array should be created.offset
- The offset into the array to start placing pixels.x
- the x co-ordinate within the image.y
- the y co-ordinate within the image.w
- the width of the pixel block to get.h
- the height of the pixel block to get.rowStride
- the number of int values between each row in the destination int array. If this is 0 it
will be assumed to be equal to width.IllegalArgumentException
public PixelBuffer setTo(Font f, String text, int alignment, Color color, double alphaValue)
f
- the Font to use.text
- the text. If it contains '\n' characters it is split into
separate lines.alignment
- either Graphics.LEFT or Graphics.RIGHT or Graphics.CENTER.color
- the color to draw the text in.alphaValue
- the maximum alpha value for the text.fts
- optional FormattedTextSpecs to format the text.public PixelBuffer setTo(Font f, StringList text, int alignment, Color color, double alphaValue, FormattedTextSpecs fts)
f
- the Font to use.text
- the text.alignment
- either Graphics.LEFT or Graphics.RIGHT or Graphics.CENTER.color
- the color to draw the text in.alphaValue
- the maximum alpha value for the text.fts
- optional FormattedTextSpecs to format the text.public boolean setPixels(int[] dest, int offset, int x, int y, int w, int h, int rowStride) throws IllegalArgumentException
ImageData
dest
- The source int array.offset
- The offset into the array to start retrieving pixels.x
- the x co-ordinate within the image.y
- the y co-ordinate within the image.w
- the width of the pixel block to get.h
- the height of the pixel block to get.rowStride
- the number of int values between each row in the source int array. If this is 0 it
will be assumed to be equal to width.IllegalArgumentException
public void setTransparentColor(Color c)
c
- the Color to set all fully transparent pixels to.public static int[] getPixelsFor(IImage image, int[] dest, int offset, Rect area, int options, Color substituteBackground)
public static PixelBuffer getImageSection(IImage image, Mask m, Point p, double alphaValue)
image
- The original image.m
- The mask representing the bits of the Image that should be taken. This Mask can be
smaller than the full image - the p parameter specifies where in the image the section should
be taken from.p
- The point in the Image where the section should be taken from.alphaValue
- An alpha value to be applied to all pixels taken from the Image.public void getImageScanLines(int startLine, int numLines, Object destArray, int offset, int destScanLineLength) throws IllegalStateException
ImageData
IllegalStateException
public void setImageScanLines(int startLine, int numLines, Object sourceArray, int offset, int sourceScanLineLength) throws IllegalStateException
ImageData
IllegalStateException
public static PixelBuffer getCached()
public void cache()