public class Layer
extends java.lang.Object
Layer
class provides a simplified usage pattern for doing
graphics rendering. As such the Layer
class forms the basis of
Graphics Engine. The implementation is closely based on the
BufferedImage
class of the Java2D API. For this reason the
drawing idiom closely represents the Java2D API in which you first define the
line style and paint mode of the object to be drawn in the second step.
Classification of methods
Coordinate system
Layer
coordinates are specified using the origin (0,0) in the
top left corner, horizontally spanning to the right and vertically spanning
down. This is the same usage as in the Java 2D API which is used to implement
the Layer
class.
The Java2D API support floating point coordinates, for this reason all the
Layer
methods support floating point coordinates, too. This
fact is of essential use in case of affine transformation applied to the
drawing.
Colors
For each method that takes a numeric value as a color value - such as
setPixel(int, int, long)
- or returns a numeric color value - such as
getPixel(int, int)
- this number is a 32bit unsigned integer number, which
encodes 8bits per color value and the alpha channel value. The colors are all
defined to be RGB colors in the standard sRGB color space.
Example: the value 0xff60c0f0 defines the alpha channel to 0xff, the red channel to 0x60, the green channel to 0xc0 and the blue channel to 0xf0.
The methods taking a Paint
object as a parameter you may pass
a Color
object which you define - amongst others - with the
constructor taking the 32bit integer value encoded as noted above ;
Paint col = new Color( 0xff6cc0f0, true );
Properties of Layer
objects
x, y, width, height | The top, left corner of the layer as well as the width and height of the layer. The top, left corner coordinate is only used when merging or blitting layers, to support relative positioning of the layers. Also when writing the layer in GIF format, the top, left corner values are used. | |
bgcolor | The background color of the layer. The layer is filled with this color when being allocated. This is also the default color to flatten against. | |
transparency | The color in the image which is considered to be the transparent color. This value is only of use for GIF images, as JPG and PNG correctly account for the alpha channel values per pixel and create partially transparent pixels. | |
opacity | The opacity is used during layer merging to merge layers in partially transparent manner. | |
mimeType | This is the default MIME type of the layer. This is set from the image
file if the layer is loaded from an image or defaults to
"image/gif ". This is used to write the image, if the
image type parameter is missing.
| |
quality | Will define some quality values in the future. This is not used yet. |
Notes on J2SE 1.3
The Graphics Engine uses the new ImageIO API to read and write image files. Unfortunately this API is only avaiable with J2SE 1.4 though for some time an early access version called EA2 has been available for J2SE 1.3. The Graphics Engine library contains this EA2 ImageIO implementation which is only used if running in J2SE 1.3.
J2SE 1.3 contains a bug which prevents graphical applications from running correctly on Unix systems if no XServer is available. This is known as 'headless' operation mode and reported to Sun in Sun bug #4281163, support "headless" Java. The workaround is to have the PJA toolkit installed and starting the JVM with the following additional parameters :
-Xbootclasspath/a:<lib>\pja.jar -Dawt.toolkit=com.eteks.awt.PJAToolkit \ -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment \ -Djava2d.font.usePlatformFont=false
Modifier and Type | Class and Description |
---|---|
static class |
Layer.LuminanceSystem
The
LuminanceSystem class encapsulates luminance factor
values for greyscaling operations. |
Modifier and Type | Field and Description |
---|---|
static int |
ALPHA_CHANNEL_ID
Channel number to identify the alpha channel for diverse methods
involving color channels, i.e.
|
static int |
BLUE_CHANNEL_ID
Channel number to identify the blue color channel for diverse methods
involving color channels, i.e.
|
static java.lang.String |
DEFAULT_MIME_TYPE
Default MIME type for writing the image.
|
static Layer.LuminanceSystem |
GAMMA22
Luminance factors for RGB in a Gamma 2.2 color space.
|
static int |
GREEN_CHANNEL_ID
Channel number to identify the green color channel for diverse methods
involving color channels, i.e.
|
static Layer.LuminanceSystem |
LINEAR
Luminance factors for RGB in a linear color space.
|
static Layer.LuminanceSystem |
REC709
Luminance factors for RGB in a color space for contemporary CRT phosphors
according to Rec.
|
static int |
RED_CHANNEL_ID
Channel number to identify the red color channel for diverse methods
involving color channels, i.e.
|
Constructor and Description |
---|
Layer(java.awt.image.BufferedImage image)
Creates a new
Layer by wrapping the
BufferedImage with the Layer properties. |
Layer(java.io.InputStream input)
Creates a new
Layer instance by loading an image from the
InputStream . |
Layer(java.io.InputStream input,
java.awt.Dimension max)
Creates a new
Layer instance by loading an image from the
InputStream . |
Layer(java.io.InputStream input,
int idx)
Creates a new
Layer instance by loading the indexed image
from the InputStream . |
Layer(java.io.InputStream input,
int idx,
java.awt.Dimension max)
Creates a new
Layer instance by loading the indexed image
from the InputStream . |
Layer(java.io.InputStream input,
int idx,
java.awt.Dimension max,
javax.imageio.ImageReadParam params)
Creates a new
Layer instance by loading the indexed image
from the InputStream . |
Layer(int width,
int height,
java.awt.Paint bground)
Creates a
Layer with the indicated dimensions and
background paint. |
Layer(Layer src)
Creates a new
Layer by copying the image of the source
layer and setting all properties to the exact same value they are set in
the source layer. |
Modifier and Type | Method and Description |
---|---|
void |
adjust(int brightness,
float contrast)
Adjust brightness and contrast of the image using the adjustments
indicated :
The brightness operand is a number in the range -255 ..
|
void |
blit(Layer src,
int dw,
int dh)
Copy a subimage from the given source layer to this layer.
|
void |
blit(Layer src,
int dx,
int dy,
int dw,
int dh,
int sx,
int sy)
Copy a subimage from the given source layer to this layer.
|
void |
blur(double radius,
double scale,
int flags,
double gran,
double maxdata)
Blurs the picture in the layer using the values given.
|
void |
colorize(java.awt.Color darkcolor,
java.awt.Color brightcolor)
Colorizes the layer, i.e.
|
void |
colorMask(Layer src,
java.awt.Color col)
Colorizes the identical pixel of the source and destination layer with
the indicated color.
|
void |
copyChannel(Layer src,
int fromChannel,
int toChannel)
Copy the color or alpha channel from the source the same or another color
or alpha channel in this layer.
|
void |
crop(java.awt.geom.Rectangle2D rect)
Get the subimage indicated by the rectangle from the layer.
|
void |
dispose()
Releases as much resources as possible.
|
void |
draw(java.awt.Graphics g)
Draws the layer into another graphics element, for example another image
or a canvas.
|
void |
draw(java.awt.Shape shape)
Draws (the outline of) the given shape.
|
void |
drawEllipse(float cx,
float cy,
float a,
float b)
Draws an ellipse around the given center with the indicated horizontal
and vertical radii.
|
void |
drawImage(java.awt.image.BufferedImage img,
java.awt.image.BufferedImageOp op,
int x,
int y)
Draws the image onto the layers image at the indicated position doing the
image operation before drawing.
|
void |
drawLine(float x1,
float y1,
float x2,
float y2)
Draws a straight line between the points (x1/y1) and (x2/y2) in the
current stroke and paint mode applying the current composite.
|
void |
drawPolyLine(float[][] points)
Draws a connected lines of multiple points given in the
points array. |
void |
drawRect(java.awt.geom.Rectangle2D rect)
Draws the outline of the given rectangle with the preset color and stroke
obeying the current composite setting.
|
void |
drawSector(float cx,
float cy,
float a,
float b,
double from,
double extent)
Draws an arc of the given ellipse with which is closed by drawing
additional lines from the center point to the starting and ending points
of the arc.
|
void |
drawSegment(float cx,
float cy,
float a,
float b,
double from,
double extent)
Draws an arc of the given ellipse.
|
int |
drawText(int x,
int y,
int width,
int height,
java.lang.String text,
AbstractFont font,
int align,
double cs,
int ls)
Render the given text string in the given font to the
Layer
using the attributes given. |
void |
emboss(Layer bump,
int azimut,
int elevation,
int filtersize)
Embosses the layer using the bump (if specified) and the light direction
specified by aizmut and elevation.
|
void |
fill(java.awt.Shape shape)
Fills (the area of) the given shape.
|
void |
fillEllipse(float cx,
float cy,
float a,
float b)
Fills an ellipse around the given center with the indicated horizontal
and vertical radii.
|
void |
fillRect(Layer src,
java.awt.geom.Rectangle2D rect)
Fill the given rectangle with the layer defined as the temporary paint
object.
|
void |
fillRect(java.awt.geom.Rectangle2D rect)
According to the current paint and composite setting, the given rectangle
is drawn onto the layer.
|
void |
fillSector(float cx,
float cy,
float a,
float b,
double from,
double extent)
Filles a sector of the given ellipse with which is closed by drawing
additional lines from the center point to the starting and ending points
of the arc.
|
void |
flatten(java.awt.Color color)
Adapt the alpha channel of the image so that each color value has its
value multiplied with the alpha value.
|
void |
flipHorizontally()
Flips the layer horizontally.
|
void |
flipVertically()
Flips the layer vertically.
|
void |
floodFill(java.awt.Color fillColor,
int blur)
Floods the background with the new fill color.
|
void |
floodFill(java.awt.Color fillColor,
int blur,
java.awt.Color bgColor)
Starting from the four edges of the image towards the center, the method
replaces background color by the fill color.
|
java.awt.Paint |
getBackground()
Returns the background of the layer.
|
java.awt.Color |
getBackgroundColor()
Gets the background color of the image.
|
java.awt.geom.Rectangle2D |
getBoundingBox()
Gets the bounding box of the image, that is the size of the rectangle
spanning all pixels, that do not have the same color as the background
color.
|
java.awt.geom.Rectangle2D |
getBoundingBox(java.awt.Color bgcolor)
Gets the bounding box of the image, that is the size of the rectangle
spanning all pixels, that do not have the same color as the given color
which is supposed to be the background color.
|
java.awt.Rectangle |
getBounds()
Returns the rectangle spanned by the image.
|
java.awt.Composite |
getComposite()
Returns the current Composite in the Graphics2D context.
|
java.awt.Graphics2D |
getG2()
Returns the
Graphics2D object used to draw into this
layer. |
int |
getHeight()
Returns the height of the layer.
|
java.awt.image.BufferedImage |
getImage()
Returns the image on which this layer is based.
|
int |
getImageIndex()
Returns the index of image of this layer within the multi-image file from
which this layer has been loaded.
|
java.awt.Composite |
getLayerComposite()
Returns the current
Composite of this layer. |
java.lang.String |
getMimeType()
Returns the MIME type of the image from which the layer has been loaded.
|
int |
getNumImages()
Returns the number of images in the source from where this layer has been
loaded or -1 if the number of images is not known or the lay has not been
loaded from an image file.
|
float |
getOpacity()
Gets the opacity of the layer.
|
java.awt.Paint |
getPaint() |
int |
getPixel(int x,
int y)
After checking whether the desired coordinate lies within the layer it
gets the ARGB value out of storage and returns that value
|
java.lang.Object |
getRenderingHint(java.awt.RenderingHints.Key hintKey)
Returns the value of a single preference for the rendering algorithms.
|
java.awt.Stroke |
getStroke() |
java.awt.Color |
getTransparency()
Returns the
Color value of transparent pixels. |
int |
getWidth()
Returns the width of the layer.
|
int |
getX()
Returns the left edge of the layer.
|
int |
getY()
Returns the top edge of the layer.
|
void |
grayscale()
Converts the color image into a grayscale image
|
void |
merge(Layer layer)
Merges a layer onto the current layer whereby obeying the layer's opacity
level.
|
void |
merge(Layer[] layers)
Merges a number of layers onto the current layer whereby obeying each
layers opacity level.
|
void |
monotone(java.awt.Color color)
Monotonize the image with a base color other than black.
|
void |
multitone(java.awt.Color[] colors)
Multitone an image.
|
void |
multitone(ColorCurve[] colorCurves)
Colorize the image according to the color curves.
|
void |
reduceColors(int numColors)
Reduces the number of colors of the image to the indicated number, doing
easy 'nearest' color replacement based on a weighting algorithm.
|
void |
replaceColor(long color1,
long color2,
boolean ignoreAlpha)
Sets all pixels having color1 to color2.
|
void |
resize(int width,
int height)
Resize the image scaling it by the scaling factor indicated by the new
width and height parameters.
|
void |
resize(int width,
int height,
boolean fast)
Resize the image scaling it by the scaling factor indicated by the new
width and height parameters.
|
void |
rotate(double degrees)
Rotates the layer by the given angle in degrees in clockwise direction.
|
void |
setBackground(java.awt.Paint bground)
Sets the background of the layer.
|
void |
setBackgroundColor(java.awt.Color bgColor)
Set the background color to the indicated value.
|
void |
setComposite(java.awt.Composite composite)
Sets the drawing composite for drawing and filling operations to the
composite given.
|
void |
setLayerComposite(java.awt.Composite layerComposite)
Sets the
AlphaComposite used for merging this layer onto
other layers. |
void |
setLineStyle(LineStyle lineStyle)
Sets both the paint and the stroke for the next draw and fill operations.
|
void |
setLuminanceSystem(Layer.LuminanceSystem system)
Define the set of color weights to use in luminance definition
|
void |
setMimeType(java.lang.String mimeType)
Sets the MIME type of the image, which is used when writing the image
with no explicite MIME type setting.
|
void |
setOpacity(float opacity)
Sets the opacity of the layer.
|
void |
setPaint(java.awt.Paint paint)
Sets the paint for subsequent draw and fill operations.
|
void |
setPixel(int x,
int y,
long color)
After checking whether the pixel lies within the layer, its color is set
to the desired value.
|
void |
setRenderingHint(java.awt.RenderingHints.Key hintKey,
java.lang.Object hintValue)
Sets the value of a single preference for the rendering algorithms.
|
void |
setStroke(java.awt.Stroke stroke)
Sets the line stroke to use for the subsequent draw operation.
|
void |
setTransform(java.awt.geom.AffineTransform transfrom)
Sets the affine transformation applied to all of the drawing and filling
operations.
|
void |
setTransparency(java.awt.Color transparency)
Sets the
Color value of pixels to be regarded transparent. |
void |
setX(int x)
Sets the left edge of the layer.
|
void |
setY(int y)
Sets the top edge of the layer.
|
void |
sharpen(float amount,
float radius)
Sharpens the image by applying a convolution operation which involves
ehancing the center of a kernel.
|
java.lang.String |
toString()
Convert the Layer to some string representation for intelligent display.
|
boolean |
write(java.lang.String mimeType,
double quality,
java.io.OutputStream outStream)
Write the image to the given
OutputStream using the
desired MIME type. |
void |
xForm(int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4,
boolean crop)
Distorts the layer along a 4-edged shape.
|
void |
xFormColors(double[][] matrix,
double[] vector,
boolean crop)
Recombines the channels of the layer.
|
public static final Layer.LuminanceSystem GAMMA22
public static final Layer.LuminanceSystem LINEAR
public static final Layer.LuminanceSystem REC709
public static final java.lang.String DEFAULT_MIME_TYPE
write
methods.public static final int RED_CHANNEL_ID
copyChannel(Layer, int, int)
public static final int GREEN_CHANNEL_ID
copyChannel(Layer, int, int)
public static final int BLUE_CHANNEL_ID
copyChannel(Layer, int, int)
public static final int ALPHA_CHANNEL_ID
copyChannel(Layer, int, int)
public Layer(int width, int height, java.awt.Paint bground)
Layer
with the indicated dimensions and
background paint. The background paint may be any valid
Paint
implementation but will usually be a simple
Color
instance.
The remaining properties of the layer are set to their default value. The origin is set to zero, the image type is GIF and the transparency color is not set.
Note, that the background Paint
is painted into the newly
created layer. If you later set the background Paint
to
something else and resize the layer or merge it with other layer(s) some
part of the layer will still have the old background color.
width
- Width of the new layer. The minimum width of a layer is 1.height
- Height of the new layer. The minimum height of a layer is
1.bground
- The background paint of the new layer. This may be
null
in which case the background is assumed to
be in transparent white.java.lang.IllegalArgumentException
- if either the width or the height are
specified lower than 1.public Layer(java.io.InputStream input) throws java.io.IOException, javax.imageio.IIOException
Layer
instance by loading an image from the
InputStream
.
The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.
This constructor is equivalent to calling the
Layer(InputStream, int)
constructor with an index value or zero.
input
- The InputStream to read the image data fromjava.lang.NullPointerException
- if the InputStream
is
null
.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image failspublic Layer(java.io.InputStream input, java.awt.Dimension max) throws java.io.IOException, javax.imageio.IIOException
Layer
instance by loading an image from the
InputStream
.
The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.
if max
is given, the loaded image
will not be bigger than the given dimensions. eg: if the image is
1000x400 and the constraints are 500x500, the resulting layer will be
500x200.
This constructor is equivalent to calling the
Layer(InputStream, int, Dimension)
constructor with an index value or zero.
input
- The InputStream to read the image data frommax
- optional constraint for the maximal dimensions.java.lang.NullPointerException
- if the InputStream
is
null
.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image failspublic Layer(java.io.InputStream input, int idx) throws java.io.IOException, javax.imageio.IIOException
Layer
instance by loading the indexed image
from the InputStream
.
The width and height are set to the values of the image, while the other values are set to their respective default values as defined in the class comment above.
input
- The InputStream to read the image data fromidx
- The zero-based index of the image in the image data stream.
The first image has index zero. This must not be a negative
number.java.lang.NullPointerException
- if the InputStream
is
null
.java.lang.IndexOutOfBoundsException
- If idx
is higher than
the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image failspublic Layer(java.io.InputStream input, int idx, java.awt.Dimension max) throws java.io.IOException, javax.imageio.IIOException
Layer
instance by loading the indexed image
from the InputStream
.
The width and height are set to the values of the image, while the other
values are set to their respective default values as defined in the class
comment above. if max
is given, the loaded image
will not be bigger than the given dimensions. eg: if the image is
1000x400 and the constraints are 500x500, the resulting layer will be
500x200.
input
- The InputStream to read the image data fromidx
- The zero-based index of the image in the image data stream.
The first image has index zero. This must not be a negative
number.max
- optional constraints for the maximal dimensions.java.lang.NullPointerException
- if the InputStream
is
null
.java.lang.IndexOutOfBoundsException
- If idx
is higher than
the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image failspublic Layer(java.io.InputStream input, int idx, java.awt.Dimension max, javax.imageio.ImageReadParam params) throws java.io.IOException, javax.imageio.IIOException
Layer
instance by loading the indexed image
from the InputStream
.
The width and height are set to the values of the image, while the other
values are set to their respective default values as defined in the class
comment above. if max
is given, the loaded image
will not be bigger than the given dimensions. eg: if the image is
1000x400 and the constraints are 500x500, the resulting layer will be
500x200.
input
- The InputStream to read the image data fromidx
- The zero-based index of the image in the image data stream.
The first image has index zero. This must not be a negative
number.max
- optional constraints for the maximal dimensions.params
- an instance of ImageReadParam
.java.lang.NullPointerException
- if the InputStream
is
null
.java.lang.IndexOutOfBoundsException
- If idx
is higher than
the index of the last image in the image file.java.io.IOException
- if reading from the stream throws such an exception.javax.imageio.IIOException
- if decoding the image failspublic Layer(Layer src)
Layer
by copying the image of the source
layer and setting all properties to the exact same value they are set in
the source layer.src
- The layer to copyjava.lang.NullPointerException
- if the source layer is null
.public Layer(java.awt.image.BufferedImage image)
Layer
by wrapping the
BufferedImage
with the Layer
properties.
Note that this really is a wrapping constructor and not a copy
constructor. That is if you keep drawing into the original image, you get
a mixed result.image
- The BufferedImage
to wrap as a
Layer
.java.lang.NullPointerException
- if the image is null
.public boolean write(java.lang.String mimeType, double quality, java.io.OutputStream outStream) throws javax.imageio.IIOException, java.io.IOException
OutputStream
using the
desired MIME type. If the MIME type is empty or null, we use the MIME
type of the layer.
The quality parameter is used to define the compression level of JPEG image creation, if JPEG output is desired as per the MIME type. The quality value must be in the range 0.0 .. 1.0 inclusive. Any value outside this range results in the default compression factor 0.82 being used.
For GIF images the colors will be reduced according to the quality argument. If the argument is missing, at most 256 colors will be in the image or as much as need be.
Note that specifying the MIME type for the image type is simply used to decide on the output format to use for writing. Especially the method is not able set any Content-Type headers whatsoever.
The OutputStream is neither flushed nor closed at the end. It is the sole responsibilty of the client of this method to do so.
mimeType
- MIME type to use for writing. If empty or null the MIME
type of the image will be used. As a last fall back the
default MIME type as per DEFAULT_MIME_TYPE
is used.quality
- Defines the JPEG compression quality (0.0 .. 1.0) or the
numbers of colors to use for the GIF image.outStream
- OutputStream
to use to write the layer.java.lang.IllegalArgumentException
- if a mimeType is specified either as a
parameter or as the layer's image type, which is not
supported for writing by the ImageIO system.java.lang.NullPointerException
- if the OutputStream
is
null
.javax.imageio.IIOException
- we get from the ImageIO Library we use.java.io.IOException
- we get from writing to the OutputStream
.public void dispose()
Note that using the layer object again after calling this method results
in unexpected behaviour and at least throwing of
NullPointerException
s.
public void merge(Layer layer)
layer
- the Layer
s to merge onto this one. If
null
this layer is not changed.public void merge(Layer[] layers)
Each layer is painted over the already painted layers according to the
opacity
and composite
set
on the layer to be painted. If the getLayerComposite()
is not a
AlphaComposite
, the opacity
is
ignored.
This method is conservative in that it is a null operation if the layers
is null
or empty.
layers
- the list of Layer
s to merge onto this one.public void blit(Layer src, int dw, int dh)
Layer
.src
- the source Layer
to copy fromdw
- the width of reactangle to copydh
- the height of the rectangle to copy.blit(Layer, int, int, int, int, int, int)
public void blit(Layer src, int dx, int dy, int dw, int dh, int sx, int sy)
src
- the source Layer
to copy fromdx
- the left edge of the destination area in this layerdy
- the top edge of the destination area in this layerdw
- the width of reactangle to copydh
- the height of the rectangle to copy.sx
- the left edge of the source area in the source layersy
- the top edge of the source area in the source layerpublic void copyChannel(Layer src, int fromChannel, int toChannel)
l.copyChannel(null, c, c)
will
do nothing.src
- the source layer for the channel copy, if null
this is used as the src
.fromChannel
- channel to copy from the the source layer. If
negative, the alpha channel will be copiedtoChannel
- channel in this layer to copy the fromChannel into. If
negative the same channel as fromChannel will be used.java.lang.IndexOutOfBoundsException
- if the channel number is higher than
number of available channels in either the source or this
layer.public void colorMask(Layer src, java.awt.Color col)
src
- the source layer for the masking operation or
null
this.col
- the color to set for identical pixels. If null
opaque black is used.public void flatten(java.awt.Color color)
The DST_OVER composite paints the background only as much as the alpha channel of the layer pixels allows also respecting the alpha value of the background color !!
color
- The color to use for unlit pixels. Set to a negative value
to use the background color of the layer.public void rotate(double degrees)
degrees
- the angle to rotate the layer by. Usually this angle
should be in the range 0-360 .public void flipHorizontally()
public void flipVertically()
public void resize(int width, int height)
width
- the new width of the layer. Set to 0 or a negative value to
keep the current width.height
- the new height of the layer. Set to 0 or a negative value
to keep the current height.public void resize(int width, int height, boolean fast)
width
- the new width of the layer. Set to 0 or a negative value to
keep the current width.height
- the new height of the layer. Set to 0 or a negative value
to keep the current height.fast
- if set to true
a faster resizing algorithm is
used but with poorer detail.public void crop(java.awt.geom.Rectangle2D rect)
rect
- the rectangle definiing the part of the image to cut outpublic void emboss(Layer bump, int azimut, int elevation, int filtersize)
NOTE: This implementation is a copy of the existing rgbaLayer routine. It may therefore not be very fast. But it works the same as the corresponding ECMA routine ;-)
bump
- the bump layer to emboss this layer with. If null this layer
itself will also be used as the bump.azimut
- the light direction azimut. Specify a negative value to get
the default value of 30.elevation
- the light direction elevation. Specify a negative value
to get the default value of 30.filtersize
- the filtersize for the embossing. Specify a negative
value to get the default value of 3.public void xForm(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, boolean crop)
crop
parameter, the size of the layer is adapted to the
new size or not. If crop==true
, the layer's size is
either enlarged or made smaller depending on the bounding box of the
transformed layer.
This method internally uses the DistortOp
class to calculate the
transformed layer. Therefore the same warning about memory usage applies
to this method as does to the DistortOp
class.
x1
- x-coordinate of top left corner of transformed rectangley1
- y-coordinate of top left corner of transformed rectanglex2
- x-coordinate of top right corner of transformed rectangley2
- y-coordinate of top right corner of transformed rectanglex3
- x-coordinate of bottom left corner of transformed rectangley3
- y-coordinate of bottom left corner of transformed rectanglex4
- x-coordinate of bottom right corner of transformed rectangley4
- y-coordinate of bottom right corner of transformed rectanglecrop
- true
of the layer should be adapted to the
bounding of the transformed rectangle.public void grayscale()
public void colorize(java.awt.Color darkcolor, java.awt.Color brightcolor)
darkcolor
- the dark start color for the colorization. If negative
0xff000000 (black) will be used.brightcolor
- the bright end color for the colorization. If negative
0xffffffff (white) will be used.public void monotone(java.awt.Color color)
multitone(new Color[]{ color })
.color
- Color to use as the base for the monotonized imagejava.lang.NullPointerException
- if the color value is null
.public void multitone(java.awt.Color[] colors)
Note that monotone(Color)
is the single color special case of
multitone.
This method does not yet work as expected
colors
- The colors to apply.java.lang.NullPointerException
- if the colors array or any of the elements
in the array is null
.java.lang.IllegalArgumentException
- if the colors array is emptypublic void multitone(ColorCurve[] colorCurves)
colorCurves
- The color curves to use in the MultitoneOp
filter.MultitoneOp
,
ColorCurve
public void blur(double radius, double scale, int flags, double gran, double maxdata)
ConvolveOp
class of the Java 2D API. Maybe we
should specify the matrix better ?radius
- (default:1)scale
- (default:1)flags
- (default:all channels) - not used at the momentgran
- (default:1)maxdata
- (default:255)public void sharpen(float amount, float radius)
amount
- Center enhancement in percent in the range 0 .. 1.0radius
- Size of the convolution matrix. The size is rounded to and
integral matrix edge according to
edge = int(2 * (radius + 1))
. That is the
minimum matrix size is guaranteed to be 1, which has no effect
whatsoever. Allowed range for this value is 0.5 .. 10.0public void xFormColors(double[][] matrix, double[] vector, boolean crop)
matrix
- 4x4 matrix to multiply to the vector of channel values of
each pixelvector
- array of 4 elements to add to each resulting value got from
the multiplication.crop
- default truepublic void replaceColor(long color1, long color2, boolean ignoreAlpha)
color1
- Color identifying pixels to be modifiedcolor2
- New color of those pixelsignoreAlpha
- Set to true to not touch the alpha channel of the
pixels.public void adjust(int brightness, float contrast)
destination = ( source * contrast ) + brightnessThe result is clipped to the range 0..255.
brightness
- The brightness operand in the range -255 .. 255contrast
- The contrast factor in the rang 0.0f .. infinitypublic void reduceColors(int numColors)
numColors
- The number of colors to reduce the current image to.public void setPaint(java.awt.Paint paint)
Paint
implementations such as GradientPaint
.
The paint setting remains active until changed by the next setLineStyle() or setPaint() call.
public java.awt.Paint getPaint()
public void setStroke(java.awt.Stroke stroke)
The stroke setting remains active until changed by the next setLineStyle() or setStroke() call.
public java.awt.Stroke getStroke()
public void setLineStyle(LineStyle lineStyle)
The paint and stroke settings remain active until changed by the next setLineStyle() or setPaint() or setStroke() call.
public void setComposite(java.awt.Composite composite)
AlphaComposite
implementations.composite
- The composite to set for the drawing operations.java.lang.NullPointerException
- if composite is null
.public java.awt.Composite getComposite()
public void setTransform(java.awt.geom.AffineTransform transfrom)
transfrom
- The affine transformation to apply to all drawing and
filling operations when operating on the layer.public void setLuminanceSystem(Layer.LuminanceSystem system)
public void setRenderingHint(java.awt.RenderingHints.Key hintKey, java.lang.Object hintValue)
hintKey
- the key of the hint to be set.hintValue
- the value indicating preferences for the specified hint
category.public java.lang.Object getRenderingHint(java.awt.RenderingHints.Key hintKey)
hintKey
- the key corresponding to the hint to gepublic int drawText(int x, int y, int width, int height, java.lang.String text, AbstractFont font, int align, double cs, int ls)
Layer
using the attributes given. Use the default values given for unspecified
values.
If the width of the text box is set to some value other than zero, the text is broken to fit lines of the given length. The line breaking algorithm breaking algorithm breaks on whitespace (blank, tab), carriage return and linefeed (CR/LF) in any combination as well as on other characters such as hyphens.
If the text contains carriage return and/or linefeed characters, the text is broken into several lines, regardless of whether the text would be broken because of the text box width setting.
The layer may be enlarged to accomodate for the space needed for the text to be drawn. This is not the same behaviour as standard Java2D text drawing, where the text is clipped at the edges of the image.
x
- left edge of the text box relative to the layer.y
- top edge of the text box relative to the layer.width
- maximum width of the textbox. If 0 (or negative) the width
of the bounding box is dependent of the rendering attributesheight
- maximum height of the textbox. If 0 (or negative) the width
of the bounding box is dependent of the rendering attributestext
- the text string to drawfont
- the font to render the text stringalign
- alignment, rotation and TrueType attributes for the text.
Use AbstractFont.ALIGN_LEFT
as default value.cs
- extra intercharacter spacing. Use 0 as default value to not add
additional space.ls
- extra line spacing. Use 0 as default value to not add
additional space.java.lang.NullPointerException
- if either the text or the font argument is
null
.java.lang.IllegalArgumentException
- if either x or y are negative.Font.drawText(com.day.image.Layer, int, int, int, int, java.lang.String, java.awt.Paint, java.awt.Stroke, int, double, int)
public void fillRect(java.awt.geom.Rectangle2D rect)
null
,
the entire layer is filled with the paint.
The edges of the rectangle drawn are defined as in Java2D, that is the left edge is x, the right edge is x+width-1, the top edge is y and the bottom edge is y+width-1.
rect
- the rectangle to paint onto the layer. If set to null, the
entire layer will be filled with that color.public void fillRect(Layer src, java.awt.geom.Rectangle2D rect)
src
- the source Layer
to use. If this is the same as
src
, nothin happens.rect
- the rectangle to paint onto the layer. If set to null, the
entire layer will be filled with that color.java.lang.NullPointerException
- if src
is null
.public void drawRect(java.awt.geom.Rectangle2D rect)
null
,
this draws the outline on the edges of the layer.
The edges of the rectangle drawn are defined as in Java2D, that is the left edge is x, the right edge is x+width, the top edge is y and the bottom edge is y+width.
rect
- the rectangle to draw onto the layer. If set to null, the
entire layer will be surrounded with a border line.public void drawLine(float x1, float y1, float x2, float y2)
x1
- The x coordinate of the starting pointy1
- The y coordinate of the starting pointx2
- The x coordinate of the ending pointy2
- The y coordinate of the ending pointpublic void drawPolyLine(float[][] points)
points
array. Each entry in the array contains of a x/y
coordinate pair denoting one point in the line.points
- Array of x/y coordinate pairs. The array must consist of at
least two entries, each entry containing at least two elements
where the first element is interpreted as the x- and the
second element is interpreted as the y-coordinate of that
entry's point.public void drawEllipse(float cx, float cy, float a, float b)
cx
- The x coordinate of the ellipse centercy
- The y coordinate of the ellipse centera
- The horizontal radius of the ellipseb
- The vertical radius of the ellipsepublic void fillEllipse(float cx, float cy, float a, float b)
cx
- The x coordinate of the ellipse centercy
- The y coordinate of the ellipse centera
- The horizontal radius of the ellipseb
- The vertical radius of the ellipsepublic void drawSegment(float cx, float cy, float a, float b, double from, double extent)
drawEllipse(float, float, float, float)
, while only a segment
of this ellipse is drawn. The segement is defined by the from and to
angle denoting the starting and ending angle specified in degrees. The
angle are defined such, that 0 degrees is the axis from the center to the
right edge and positive angles turn counter clockwise.cx
- The x coordinate of the base ellipse centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- The angle the arc spans as defined abovepublic void drawSector(float cx, float cy, float a, float b, double from, double extent)
cx
- The x coordinate of the base ellipse centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- The angle the arc spans as defined abovepublic void fillSector(float cx, float cy, float a, float b, double from, double extent)
drawEllipse(float, float, float, float)
, while only a segment
of this ellipse is drawn. The segement is defined by the from and to
angle denoting the starting and ending angle specified in degrees. The
angle are defined such, that 0 degrees is the axis from the center to the
right edge and positive angles turn counter clockwise.cx
- The x coordinate of the base ellipse centercy
- The y coordinate of the base ellipse centera
- The horizontal radius of the base ellipseb
- The vertical radius of the base ellipsefrom
- The starting angle as defined aboveextent
- The angle the arc spans as defined abovepublic void draw(java.awt.Shape shape)
Shape
.
The Shape
interface forms the basis for all geometrical
figures such as circles, rectangles, lines but also text and even
constructive area geometry.
shape
- The Shape
implementation object to drawpublic void fill(java.awt.Shape shape)
Shape
.
The Shape
interface forms the basis for all geometrical
figures such as circles, rectangles, lines but also text and even
constructive area geometry.
shape
- The Shape
implementation object to drawpublic int getPixel(int x, int y)
x
- horizontal coordinate (0 at the left) of the pixely
- vertical coordinate (0 at the top) of the pixelpublic void setPixel(int x, int y, long color)
x
- horizontal coordinate (0 at the left) of the pixely
- vertical coordinate (0 at the top) of the pixelcolor
- ARGB value for the pixelpublic java.awt.geom.Rectangle2D getBoundingBox()
getBackgroundColor()
method.getBoundingBox(Color)
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.Color bgcolor)
The algorithm scans starting on each edge of the image rectangle and aborts the scan as soon as a non-background pixel is encountered.
bgcolor
- The color value not being considered image color, ie
background color.java.lang.NullPointerException
- if bgcolor is null
.public void floodFill(java.awt.Color fillColor, int blur)
getBackgroundColor()
method.fillColor
- The color to replace the background pixelsblur
- The maximal color distance to apply to a pixel to treat it as
a background color pixel.floodFill(Color, int, Color)
public void floodFill(java.awt.Color fillColor, int blur, java.awt.Color bgColor)
blur < sqrt( dr^2 + dg^2 + db^2 )
where dr,
dg and db are the difference of the red, blue and green component of the
pixel and the background color, resp.
As a side effect the transparency color is set to the fill color if the transparency was set to the backrgound color just replaced.
fillColor
- The color teplace for the background color.blur
- The maximum color distance as defined above.bgColor
- The background color to be replaced.java.lang.NullPointerException
- if either fillColor or bgColor is
null
.public void drawImage(java.awt.image.BufferedImage img, java.awt.image.BufferedImageOp op, int x, int y)
img
- The image to drawop
- The BufferedImageOp
to execute on the image
before drawing, if null
the image is drawn
unaltered.x
- The left position to draw the image toy
- The top position to draw the image topublic void draw(java.awt.Graphics g)
g
- The graphics element to draw intopublic int getX()
public void setX(int x)
x
- left edge of the layer.public int getY()
public void setY(int y)
y
- top edge of the layer.public int getWidth()
public int getHeight()
public java.awt.Rectangle getBounds()
getBoundingBox()
returns the smallest
area of the image not only covered by the background color.public int getImageIndex()
Layer(InputStream, int)
constructor with a non-zero index.public int getNumImages()
public java.awt.Paint getBackground()
public void setBackground(java.awt.Paint bground)
Color
the background color (getBackgroundColor()
)
is also set.bground
- The new background.public void setBackgroundColor(java.awt.Color bgColor)
setBackground(Paint)
and potentially also by
getBackgroundColor()
.
You may set the background color to null
, if you want to
recalculate the background color based on the image data the next time
you call getBackgroundColor()
.
bgColor
- The Color
to set for the background or
null
to force recalculation by the next
getBackgroundColor()
call.public java.awt.Color getBackgroundColor()
setBackgroundColor(Color)
, the background color is
taken to be the background (getBackground()
if the background
is a color, else the color is calculated to be the color most often
occuring on the edges of the layer. This may not be 100% correct but gets
acceptable results.public java.awt.Color getTransparency()
Color
value of transparent pixels. This is
prominently used by the GIF image format, which does not know about alpha
values. For GIF images, a color may be specified to identify pixels which
should be show transparent.Color
value of transparent pixelspublic void setTransparency(java.awt.Color transparency)
Color
value of pixels to be regarded transparent.
This is prominently used by the GIF image format, which does not know
about alpha values. For GIF images, a color may be specified to identify
pixels which should be show transparent.transparency
- The transparency color.public void setMimeType(java.lang.String mimeType)
mimeType
- The MIME type to set on the layer. If null
or empty, the currently set MIME type is not changed.public java.lang.String getMimeType()
image/gif
.public float getOpacity()
setOpacity(float)
public void setOpacity(float opacity)
opacity
- the layer's opacity. If less than zero, zero is set; if
higher than 1.0, 1.0 is set; if not a number (Float.NaN
)
the opacity is not changed.getOpacity()
public java.awt.Composite getLayerComposite()
Composite
of this layer. The default
composite set is AlphaComposite.SrcOver
.
This method returns the Composite
which is set on this
layer and which is used for layer merging. This is different from the
Composite
returned from the getComposite()
method,
which returns the Composite
used for drawing operations
until reset.
Composite
.setLayerComposite(java.awt.Composite)
public void setLayerComposite(java.awt.Composite layerComposite)
AlphaComposite
used for merging this layer onto
other layers.
This method sets the Composite
on this layer which is used
for layer merging. This is different from the Composite
set through setComposite(java.awt.Composite)
, which sets the Composite
used for drawing operations until reset.
layerComposite
- The Composite
to set on this layer.
If null
the current Composite
is
not changed.getLayerComposite()
public java.awt.image.BufferedImage getImage()
public java.awt.Graphics2D getG2()
Graphics2D
object used to draw into this
layer.Graphics2D
object used to draw into this
layer.public java.lang.String toString()
toString
in class java.lang.Object
String
representation of the
Layer
.Copyright © 2010 - 2020 Adobe. All Rights Reserved