|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.Convert
com.ccg.awt.ImageGen
public class ImageGen
Implementation of a image generator
This class is a full implementation of a ImageGenerator. It can interpret a series of "at commands" (things
like "@fill(100,200,blue)" to produce and manipulate RGB bitmaps
and produce a standard Java Image object.
This class provides several basic "at commands" which can be used directly. It is recommended to look at the ImageGenerator Class Overview which provides both a working interpreter (to allow you to try out some "at commands" as well as additional information on using and extending this class.
You use this class to build/modify bitmaps by passing a series of commands in as a String. The following code fragment demonstrates a primative way one could use this code (though this is not the normal/recommended way - it is suitable for documentation purposes):
public static java.awt.Image redNoise() {
ImageGen ig = new ImageGen();
return ig.interpret(null,new ImageHolder(),
"@fill(200,100,red) @noise(70,130)");
}
The following quick reference lists the "at commands" built into this class:
@fill(width,height,color)@load(NAME[,x,y,w,h])ImageHolder associated with the interpreter. You can
optionally specify a rectangular region to load it only with a
portion of a existing region (clip out a section of a bitmap).@round(width[,strength[,smooth])@brightness(percent)@contrast(a,p[,ga,gp,ba,bp])@gray()@noise([minper[,maxper]])@hline(color,vofs[,sofs[,eofs]])@vline(color,hofs[,sofs[,eofs]])
| Constructor Summary | |
|---|---|
ImageGen()
Initializes object making it ready for use. |
|
| Method Summary | |
|---|---|
void |
brightness()
Adjust the brightness of the bitmap (lighten/darken) This method provides support for the "@brightness(percent)" macro. |
protected void |
checkArgCount(int required)
Verifies a specific number of arguments were passed to the command. |
protected Color |
checkColor(String val,
boolean allowDefault,
Color defValue)
Check that user specified a color value or allow a default. |
protected int |
checkInt(String val,
boolean allowDefault,
int defValue)
Check that user specified a integer parameter or allow a default. |
int |
checkIntOrPercent(String val,
int size,
boolean allowDefault,
int defValue)
Handy method to convert a string to a bitmap position. |
RGBPixels |
checkRGBPixels()
Fetch the working bitmap or error if one doesn't exist. |
void |
contrast()
Adjust the contrast of the bitmap This method provides support for the "@contrast(percent)" macro. |
void |
fill()
Create a new bitmap of a specific width, height and color This method provides support for the "@fill(width,height,color)" macro. |
protected String |
getArg(int idx)
Get get one of the arguments which was passed to the @command. |
protected int |
getArgCount()
Get the number of arguments passed to the command. |
ImageHolder |
getImageHolder()
Get the ImageHolder to use as a repository for bitmap information |
int |
getLoadDelayMillis()
Get how long to sleep after grabbing pixels (used by @load macro). |
RGBPixels |
getRGBPixels()
Get the current RGBPixels object which we are modifying
This method may return 'null' if the bitmap hasn't been created
yet. |
void |
gray()
Convert a color bitmap to black and white. |
void |
hline()
Draw a horizontal line across the current bitmap. |
Image |
interpret(Object modify,
ImageHolder ih,
String commands)
Interpret a set of commands to create/modify a image. |
void |
load()
Load the working bitmap with a Image from the
ImageHolder. |
void |
noise()
Randomly adjust the brightness of the bitmap to give it a texture. |
void |
round()
Create the affect of "rounding" the edges of the bitmap This method provides support for the "@round(width[,strength[,smooth])" macro. |
void |
setImageHolder(ImageHolder val)
Set the ImageHolder to use as a repository for bitmap information |
void |
setLoadDelayMillis(int val)
Set how long to sleep after grabbing pixels (used by @load macro). |
void |
setRGBPixels(RGBPixels val)
Set the current RGBPixels object which we are modifying |
void |
vline()
Draw a vertical line across the current bitmap. |
| Methods inherited from class com.ccg.util.Convert |
|---|
choiceValue, getDateFormat, getNumberFormat, setDateFormat, setNumberFormat, toBoolean, toColor, toDate, toFont, toInputStream, toLocale, toNumber, toOutputStream, toString, toTimeSpan |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ImageGen()
interpret(java.lang.Object, com.ccg.awt.ImageHolder, java.lang.String)| Method Detail |
|---|
public Image interpret(Object modify,
ImageHolder ih,
String commands)
throws Exception
The string containing the set of commands to interpret must follow the rules specified in the ImageGenerator Class Overview document.
interpret in interface ImageGeneratormodify - This parameter can be any type of Java object, it will
typically be 'null', a RGBPixels object, or
some sort of Image object.ih - This parameter serves as a way to provide a "library" of
bitmap images to the interpreter. It should never be null, but
its OK to pass a empty ImageHolder
object. The interpreter is free to use this object to lookup
additional bitmap resources as it builds its image.commands - This is a set of commands which the interpreter understands to
create/modify images.
Image
object. It should never null - it throws an exception on
failure.
Exception
public void fill()
throws Exception
interpret command
when it runs across a "@fill()" macro in the string it is
parsing.
The macro has the following form:
@fill(width,height,color)
The following parameters are ALL required
toColor method.
Exception - If the arguments specified to the macro are not valid.interpret(java.lang.Object, com.ccg.awt.ImageHolder, java.lang.String)
public void load()
throws Exception
Image from the
ImageHolder.
This method provides support for the "@load(name)" macro. It is
invoked by the interpret command when it runs
across a "@macro()" macro in the string it is parsing. This
command is similar to the "@fill()" macro in that it "creates" a
full working bitmap to manipulate (it doesn't modify anything -
just replaces/creates). This means that the command should only
used once at the start of the set of macros to process.
The macro can be invoked with either one or five arguments and has the following form:
@load(name)
@load(name,x,y,w,h)
Image object
which to initialize our working pixel buffer with. The Image will be retrieved from the ImageHolder associated with the interpretor. If the image isn't
found or fully loaded, a exception will be thrown.
Here are some examples:
The following would take load the image data whose top left corner was 10% in from left, and 10% down from the top. The size of the loaded image will be one half the width and height of the original:
@load(megan,.1,.1,.5,.5)
The following would take load the image data whose top left corner was 30% in from left, and 10% up from the bottom. The size of the loaded image will be 10 pixels wide and 10 pixels tall:
@load(megan,.3,-.1,10,10)
The following would load the image data whose top left corner was 100 pixels in from right, and 100 pixels up from the bottom. The size of the loaded image will be 100 pixels wide and 100 pixels tall:
@load(megan,-100,-100,100,100)
Exception - If the arguments specified to the macro are not valid, the
associate ImageHolder doesn't contain the
requested Image or the Image isn't
fully loaded, or you tried to clip out a invalid region.fill()
public void round()
throws Exception
interpret command when it runs across a
"@round()" macro in the string it is parsing. This macro behaves
in a fashion similar to the RGBPixels.button3D(int, int) method,
however, it also provides for the "smoothing" of the edges.
The macro has the following form:
@round(width[,strength[,smooth])
The following parameters are recognized:
Exception - If there isn't a bitmap loaded to convert or if the arguments
specified to the macro are not valid.RGBPixels.button3D(int, int)
public void hline()
throws Exception
interpret command when it runs across a "@hline()"
macro in the string it is parsing.
The macro has the following form:
@hline(color,vofs[,sofs[,eofs]])
The following parameters are recognized:
toColor method. This parameter is required.
Exception - If there isn't a bitmap available to
modify or if the arguments specified to the macro are not
valid.vline()
public void vline()
throws Exception
interpret command when it runs across a "@vline()"
macro in the string it is parsing.
The macro has the following form:
@vline(color,hofs[,sofs[,eofs]])
The following parameters are recognized:
toColor method. This parameter is required.
Exception - If there isn't a bitmap available to
modify or if the arguments specified to the macro are not
valid.hline()
public void brightness()
throws Exception
interpret command
when it runs across a "@brightness()" macro in the string it is
parsing. This macro behaves in a fashion similar to the RGBPixels.adjustBrightness(int) method.
The macro has the following form:
@brightness(percent)
The following parameters are recognized:
Exception - If there isn't a bitmap loaded to convert or if the arguments
specified to the macro are not valid.RGBPixels.adjustBrightness(int)
public void contrast()
throws Exception
interpret command
when it runs across a "@contrast()" macro in the string it is
parsing. This macro behaves in a fashion similar to the RGBPixels.adjustContrast(int) method.
The macro has the following form:
@contrast(percent)
The following parameters are recognized:
Exception - If there isn't a bitmap loaded to convert or if the arguments
specified to the macro are not valid.RGBPixels.adjustBrightness(int)
public void gray()
throws Exception
interpret command when it runs
across a "@gray()" macro in the string it is parsing. This macro
behaves in a fashion similar to the RGBPixels.grayScale()
method and changes a color bitmap to its gray scale equivalent.
The macro takes no paratmeters and has the following form:
@gray()
Exception - If there isn't a bitmap loaded to convert.RGBPixels.grayScale()
public void noise()
throws Exception
interpret command
when it runs across a "@noise()" macro in the string it is
parsing. This macro behaves in a fashion similar to the RGBPixels.noise(int, int) method.
The macro has the following form:
@noise([minper[,maxper]])
The following parameters are recognized:
Exception - If there isn't a bitmap loaded to convert or if the arguments
specified to the macro are not valid.RGBPixels.noise(int, int)
protected void checkArgCount(int required)
throws Exception
fill() to verify that the macro was invoked with the
proper number of arguments. For example the @fill() macro
requires 3 arguments, so it could invoke this method via:
checkArgCount(3).
This method is typically only of interest to those wishing to
extend the ImageGen class to provide additional
macro commands. Refer to the ImageGenEx.java for an
example of extending this class.
Exception - An error indicating the the command was invoked with the
incorrect number of arguments.getArgCount()
protected int checkInt(String val,
boolean allowDefault,
int defValue)
throws Exception
If the user provided a valid integer, or the user omitted the value and you provided a default, the desired integer value will be returned to you.
This method is typically only of interest to those wishing to
extend the ImageGen class to provide additional
macro commands. Refer to the ImageGenEx.java for an
example of extending this class.
val - The string value you want to convert (null is OK)allowDefault - Set to true if you want to provide a default value if the
"val" parameter is null. Set to false if you want to require
that "val" can be evalutated as a integer.defValue - If you allow a default value, then specify it here
Exception - If we had to try and convert the "val" passed to a integer and
it failed.
public int checkIntOrPercent(String val,
int size,
boolean allowDefault,
int defValue)
throws Exception
val - The string value you want to convert (null is OK)size - The size of the bitmap (or range) you want to allow the
resulting value to be within. The maximum value this method
will return will be one less than this size (but at least 0).allowDefault - Set to true if you want to provide a default value if the
"val" parameter is null. Set to false if you want to require
that "val" can be evalutated as a integer.defValue - If you allow a default value, then specify it here
Exception - If we had to try and convert the "val" passed to a integer and
it failed.checkInt(java.lang.String, boolean, int)
protected Color checkColor(String val,
boolean allowDefault,
Color defValue)
throws Exception
If the user provided a valid color value, or the user omitted the value and you provided a default, the desired color value will be returned to you.
This method is typically only of interest to those wishing to
extend the ImageGen class to provide additional
macro commands. Refer to the ImageGenEx.java for an
example of extending this class.
val - The string value you want to convert (null is OK). Color
values can be specified as integers or by a set of color names
- refer to the color conversion method
for more details.allowDefault - Set to true if you want to provide a default value if the
"val" parameter is null. Set to false if you want to require
that "val" can be evalutated as a color value.defValue - If you allow a default value, then specify it here
Color representation of the value specified
in the string (or as the default if the string was null).
Exception - If we had to try and convert the "val" passed to a color and
it failed.Convert.toColor(java.lang.String, java.awt.Color)
public RGBPixels checkRGBPixels()
throws Exception
RGBPixels bitmap which one can
apply a filter on.
Exception - If a bitmap hasn't been created yet.public void setImageHolder(ImageHolder val)
ImageHolder to use as a repository for bitmap information
val - New ImageHolder value to assign.getImageHolder()public ImageHolder getImageHolder()
ImageHolder to use as a repository for bitmap information
setImageHolder(com.ccg.awt.ImageHolder)public void setRGBPixels(RGBPixels val)
RGBPixels object which we are modifying
val - New RGBPixels value to assign.getRGBPixels()public RGBPixels getRGBPixels()
RGBPixels object which we are modifying
This method may return 'null' if the bitmap hasn't been created
yet. Most interpeter commands will want to use the checkRGBPixels() method instead - which will throw an error if
the bitmap hasn't been created yet.
This is this bitmap which a filter is free to change. Typically the filters will fetch the pixel array of the bitmap and adjust the contained pixels.
setRGBPixels(com.ccg.awt.RGBPixels)protected String getArg(int idx)
getArgCount()protected int getArgCount()
getArg(int)public void setLoadDelayMillis(int val)
We came across a ugly problem in IE on a Windows NT server box where the JVM appeared to report that all of the pixels had been grabbed while processing a "@load" macro when in fact they had not. The array used to hold the pixels was then being overwritten later at a unknown time - this was a bad thing and made it appear as though the image processing macros were not being run.
To work around the problem, it was found that adding a simple
"yield" after the fetch of each
bitmap would help. This method can be used to adjust this sleep
value. The values set are processed as follows:
thread yield
will be done, but no sleeping will be done.
val - New int value to assign as described above.getLoadDelayMillis()public int getLoadDelayMillis()
setLoadDelayMillis(int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||