Class PdColor
- java.lang.Object
-
- jv.object.PsObject
-
- jv.number.PdColor
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, PsUpdateIf
public final class PdColor extends PsObject
RGBA color class with info panel and update functionality.The class is derived from PsObject rather than java.awt.Color since the focus of this class is the update functionality and handling of an info panel for interactive modifications. This class allows interactive modification of a color similar to the class PuDouble and PuInteger allow for double and integer numbers. Also, java.awt.Color cannot be modified after construction.
- See Also:
PdColor_IP,PdColor_Dialog, Serialized Form- Author:
- Konrad Polthier
- Version:
- 15.10.05, 1.75 revised (kp) New method to blend integer colors.
19.07.03, 1.70 revised (kp) New method brighter().
21.09.02, 1.60 revised (kp) Use updatePanels() instead of directly asking the inspectors.
12.09.02, 1.50 revised (kp) Alpha channel stored separate, no longer in array for efficiency.
09.12.01, 1.40 revised (kp) New method getColorFromName() implemented.
11.07.00, 1.30 revised (kp) New conversion methods, slight bug in hsv2rgb removed.
01.01.00, 1.20 revised (kp) Set of methods cleaned up, public interface tightened.
07.08.99, 1.10 revised (kp) Converted to AWT 1.1.
00.00.98, 1.00 created (kp)
-
-
Field Summary
-
Fields inherited from class jv.object.PsObject
HAS_BOUNDARY_PANEL, HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_LABEL_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, HAS_VECTOR_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_FOCUSSED, IS_PICKED, IS_SELECTED, IS_USED, NUM_TAGS
-
-
Constructor Summary
Constructors Constructor and Description PdColor()Constructor of color in RGB mode with alpha disabled.PdColor(int size, boolean bAlpha)Constructor of color in RGB mode with number of color components and possible alpha channel.PdColor(java.lang.String name, PsUpdateIf parent)Constructor of color in RGB mode with alpha disabled.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static java.awt.Colorblend(double a, java.awt.Color v, double b, java.awt.Color w)Interpolate between two colors with given weights.static intblend(double a, int v, double b, int w)Interpolate between two colors with given weights.voidblend(double a, PdColor v, double b, PdColor w)Interpolate between two colors with given weights.voidblendBase(PdColor v, double b, PdColor w)Interpolate between two colors with given weights.static java.awt.Colorbrighter(java.awt.Color color)Modified against official Java implementation to ensure that the brighter color is visually different.java.lang.Objectclone()Duplicate color and data array.static java.awt.Colorcmyk2rgb(int c, int m, int y, int k)Convert a set of (cyan, magenta, yellow, black) to RGB color.static booleancopy(java.awt.Color[] dataDest, int destInd, java.awt.Color[] dataSrc, int srcInd, int size)Assign some colors of a given array of colors to an existing destination array.voidcopy(double[] anArray, int aSize)Copy color components excluding alpha.voidcopy(int[] anArray, int aSize)Copy color components excluding alpha.voidcopy(PdColor v)Copy color components including alpha.static booleancopy(PdColor[] dataDest, int destInd, PdColor[] dataSrc, int srcInd, int size)Copies some colors of a given array of colors into an existing destination array.static java.awt.Color[]copyNew(java.awt.Color[] data)Create an new array with copies of all colors of a given array of colors.static java.awt.Color[]copyNew(java.awt.Color[] data, int size)Create an new array with copies of the first 'size' colors of a given array of colors.static PdColorcopyNew(PdColor v)Create a new color as clone of argument color.static PdColor[]copyNew(PdColor[] data)Create an new array with copies of all colors of a given array of colors.static PdColor[]copyNew(PdColor[] data, int size)Create an new array with copies of the first 'size' colors of a given array of colors.voidenableAlpha(boolean flag)Enable or disable alpha channel.booleanequals(java.awt.Color col)Determines whether another color is equal to this color.booleanequals(PdColor col)Determines whether another color is equal to this color.intgetAlpha()Get alpha component if alpha is enabled, otherwise result is 0.intgetBlue()Get blue color component ifsize==3, otherwise result is 0.java.awt.ColorgetColor()Convert color components in a java.awt.Color instance.static intgetColor(int a, int[] rgb)Convert RGBA color components in range [0,255] to integer color.static intgetColor(int a, int r, int g, int b)Convert RGBA color components in range [0,255] to integer color.static java.awt.ColorgetColorFromID(int colorID, boolean bDirect)Returns an indexed color, either red, green, blue in direct mode, or cyan, magenta, yellow in indirect mode based in incrementable numbers 0, 1, 2.static java.awt.ColorgetColorFromName(java.lang.String color)Convert a verbal color descriptor into a color instance.static java.awt.ColorgetDimmedColor(java.awt.Color col, double dim)Get a color whose components are dimmed by a factor.static java.awt.ColorgetDimmedColor(java.awt.Color col, double dim, double offset)Get a color whose components are dimmed by a factor and shifted by an offset.static java.awt.ColorgetDimmedColor(java.awt.Color col, int dim)Get a color whose components are dimmed by a factor.static intgetDimmedColor(int[] rgb, int dim)Get a color whose components are dimmed by a factor.static intgetDimmedColor(int rgb, double dim)Get a color whose components are dimmed by a factor.static intgetDimmedColor(int rgb, double dim, double offset)Get a color whose components are dimmed by a factor and shifted by an offset.static intgetDimmedColor(int rgb, int dim)Get a color whose components are dimmed by a factor.intgetEntry(int ind)Get a color component with given index.intgetGreen()Get green color component ifsize==3, otherwise result is 0.intgetGrey()Get grey color ifsize==1, otherwise result is 0.static intgetMax(int rgb)Get maximal value of all components.static intgetMin(int rgb)Get minimal value of all components.intgetRed()Get red color component ifsize==3, otherwise result is 0.intgetSize()Return number of components excluding alpha.static java.awt.ColorgetXORColor(java.awt.Color colCurr, java.awt.Color colPref, java.awt.Color colAlt, int eps)Choose a new color depending on the distance to an existing color.booleanhasAlpha()Check whether alpha channel is used.static java.awt.Colorhsl2rgb(int hi, int li, int si)static java.awt.Colorhsv2rgb(java.awt.Color hsv)Conversion of color spaces.static java.awt.Colorhsv2rgb(int h, int s, int v)Conversion of color spaces.static voidhsv2rgb(PdColor rgb, PdColor hsv)Conversion of color spaces.static inthsv2rgbAsInt(int h, int s, int v)Conversion of color spaces.intindexOfMax()Find component in color with maximal value.intindexOfMin()Find component in color with minimal value.voidinit()Initialize and reset components to 0.booleanisEnabled()Check whether color dialog is enabled or disabled.intmax()Find maximal value of component in color.intmin()Find minimal value of component in color.static java.awt.ColorparseColor(java.lang.String colorString)Parse rgb color from a given string where each component is integer in the range 0..255 or a float in the range [0.,1.], or the whole color string is in Html HEX representation such as "#FF0039".static java.awt.ColorparseNamedColor(java.lang.String str)Parse a named color string into a java.awt.Color.static java.awt.Color[]realloc(java.awt.Color[] data, int arraySize)Allocate an array of Java colors and assign default color black.static PdColor[]realloc(PdColor[] data, int arraySize, int colorSize)Allocate an array of colors, where all colors have the same dimension.static PdColor[]realloc(PdColor[] data, int arraySize, int colorSize, boolean bAlpha)Allocate an array of colors, where all colors have the same dimension.static int[]rgb2cmyk(int r, int g, int b)Convert a set of (cyan, magenta, yellow, black) to RGB color.static java.awt.Colorrgb2hsl(int ri, int gi, int bi)static voidrgb2hsv(PdColor hsv, PdColor rgb)Conversion of color spaces.static java.awt.Colorrgb2yiq(int ri, int gi, int bi)voidset(double grey)Set grey component of this color using double arguments in [0., 1.].voidset(double red, double green, double blue)Set components of this color using double arguments in [0., 1.].voidset(double red, double green, double blue, double alpha)Set components of this color using double arguments in [0., 1.].voidset(int grey)Set grey component of this color using integer argument in [0, 255].voidset(int red, int green, int blue)Set components of this color using integer argument in [0, 255].voidset(int red, int green, int blue, int alpha)Set components of this color using double arguments in [0, 255].voidsetAlpha(double alpha)Set alpha component of this color using double argument in [0., 1.].voidsetAlpha(int alpha)Set alpha component of this color using integer argument in [0, 255].voidsetColor(java.awt.Color aColor)Set color components to components of argument color.voidsetConstant(int value)Set all color components excluding alpha to the same value.voidsetEnabled(boolean flag)Enable or disable the color dialog for interactive use.voidsetEntry(int ind, double value)Set a color component with given index to value.voidsetEntry(int ind, int value)Set a color component with given index to value.voidsetSize(int aSize)Set number of components of color excluding alpha.static java.lang.StringtoString(java.awt.Color col, java.lang.String sep)Get string representation of color components with given separator string.static java.lang.StringtoStringAsFloat(java.awt.Color col, java.lang.String sep)Get string representation of color components with given separator string and range of color components scaled to interval [0.,1.].static java.awt.Coloryiq2rgb(int yi, int ii, int qi)-
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, assureInspector, clearTag, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, getSymbol, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, newInspector, newInspector, removeInspector, removeInspector, removeUpdateListener, setName, setParent, setSymbol, setTag, toString, update, updatePanels
-
-
-
-
Constructor Detail
-
PdColor
public PdColor()
Constructor of color in RGB mode with alpha disabled. Calls PdColor(m_numDefColors, false).
-
PdColor
public PdColor(int size, boolean bAlpha)Constructor of color in RGB mode with number of color components and possible alpha channel.- Parameters:
size- number of color components excluding alphabAlpha-trueto enable alpha channel
-
PdColor
public PdColor(java.lang.String name, PsUpdateIf parent)Constructor of color in RGB mode with alpha disabled.- Parameters:
name- name of color, e.g. used as header in info panelparent- parent receives update events, e.g. when color changes through info panel
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
Check whether color dialog is enabled or disabled.
-
setEnabled
public void setEnabled(boolean flag)
Enable or disable the color dialog for interactive use. If disabled, the color variable can still be modified by callssetValue(double), and the color dialog is always updated.
-
getColor
public static int getColor(int a, int r, int g, int b)Convert RGBA color components in range [0,255] to integer color.- Returns:
- integer color representation in RGBA format
- Version:
- 16.06.07, 1.00 created (kp)
-
getColor
public static int getColor(int a, int[] rgb)Convert RGBA color components in range [0,255] to integer color.- Returns:
- integer color representation in RGBA format
- Version:
- 16.06.07, 1.00 created (kp)
-
getColorFromName
public static java.awt.Color getColorFromName(java.lang.String color)
Convert a verbal color descriptor into a color instance. Currently all static names in java.awt.Color supported.- Parameters:
color- Name of color, e.g. white, gray, orange- Returns:
- instance of java.awt.Color representing the color
- Version:
- 09.12.01, 1.00 created (kp)
-
getColorFromID
public static java.awt.Color getColorFromID(int colorID, boolean bDirect)Returns an indexed color, either red, green, blue in direct mode, or cyan, magenta, yellow in indirect mode based in incrementable numbers 0, 1, 2.- Parameters:
colorID- ID of color in {0, 1, 2}bDirect- Mode determines if direct or complementary colors.- Returns:
- instance of java.awt.Color representing the color
- Version:
- 30.06.13, 1.00 created (kp)
-
getSize
public int getSize()
Return number of components excluding alpha.
-
setSize
public void setSize(int aSize)
Set number of components of color excluding alpha. Note, alpha must be enabled separately. Note, alpha should be enabled before this method is called to allow this method to allocate alpha channel simultaneously with of other channels. All memory allocations are done in this method.- Parameters:
aSize- number of color components, e.g. 3 in rgb mode.
-
equals
public boolean equals(java.awt.Color col)
Determines whether another color is equal to this color. The result istrueif both colors have same color components excluding alpha. Result is alsotrueif argument color is null and this color has no entries.Alpha is not compared since Java1.1 does not support alpha in java.awt.Color.
- Parameters:
col- the color to compare with- Returns:
trueif the color component are the same;falseotherwise.
-
equals
public boolean equals(PdColor col)
Determines whether another color is equal to this color. The result istrueif both colors have same size and equal components including alpha. Result is alsotrueif argument color is null and this color has no entries.- Parameters:
col- the color to compare with- Returns:
trueif the objects are the same;falseotherwise.
-
getGrey
public int getGrey()
Get grey color ifsize==1, otherwise result is 0.
-
getRed
public int getRed()
Get red color component ifsize==3, otherwise result is 0.
-
getGreen
public int getGreen()
Get green color component ifsize==3, otherwise result is 0.
-
getBlue
public int getBlue()
Get blue color component ifsize==3, otherwise result is 0.
-
getAlpha
public int getAlpha()
Get alpha component if alpha is enabled, otherwise result is 0.
-
getMax
public static int getMax(int rgb)
Get maximal value of all components.- Since:
- JavaView 3.54.001
- Version:
- 05.09.04, 1.00 created (kp)
-
getMin
public static int getMin(int rgb)
Get minimal value of all components.- Since:
- JavaView 3.54.001
- Version:
- 05.09.04, 1.00 created (kp)
-
brighter
public static java.awt.Color brighter(java.awt.Color color)
Modified against official Java implementation to ensure that the brighter color is visually different. Each color componentxis mapped to127+x/2. As a consequence we have: 1. black.brighter() returns grey=(128,128,128) 2. applying brighter to blue returns lighter blue = (128,128,255) 3. non pure color (non zero rgb) will eventually return whiteThis method is intended as a replacement of java.awt.Color#brighter. The original method simply multiplies each component with something like 1.4 which has no visual consequences for dark colors.
- Since:
- JavaView 2.86.000
- Version:
- 19.07.03, 1.00 created (kp)
-
getDimmedColor
public static int getDimmedColor(int[] rgb, int dim)Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
rgb- color to modify.dim- factor in [0,255] to be multiplied to all color components.- Returns:
- new color value
- Since:
- JavaView 3.54.000
- Version:
- 30.08.04, 1.00 created (kp)
-
getDimmedColor
public static int getDimmedColor(int rgb, int dim)Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
rgb- color to modify.dim- factor in [0,255] to be multiplied to all color components.- Returns:
- new color value
- Since:
- JavaView 3.54.000
- Version:
- 30.08.04, 1.00 created (kp)
-
getDimmedColor
public static int getDimmedColor(int rgb, double dim)Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
rgb- color to modify.dim- factor in [0,1] to be multiplied to all color components.- Returns:
- new color
-
getDimmedColor
public static java.awt.Color getDimmedColor(java.awt.Color col, int dim)Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
col- color to modify.dim- factor in [0,255] to be multiplied to all color components.- Returns:
- new color
- Since:
- JavaView 3.54.003
- Version:
- 06.09.04, 1.00 created (kp)
-
getDimmedColor
public static java.awt.Color getDimmedColor(java.awt.Color col, double dim)Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
col- color to modify.dim- factor in [0,1] to be multiplied to all color components.- Returns:
- new color
-
getDimmedColor
public static java.awt.Color getDimmedColor(java.awt.Color col, double dim, double offset)Get a color whose components are dimmed by a factor and shifted by an offset. Offset plus product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
col- color to modify.dim- factor in [0,1] to be multiplied to all color components.offset- constant in [0,255] to be added to all color components after dimming.- Returns:
- new color TODO: use getDimmedColor(int rgb, double dim, double offset) to avoid multiple Color instantiation.
-
getDimmedColor
public static int getDimmedColor(int rgb, double dim, double offset)Get a color whose components are dimmed by a factor and shifted by an offset. Offset plus product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.- Parameters:
rgb- color to modify.dim- factor in [0,1] to be multiplied to all color components.offset- constant in [0,255] to be added to all color components after dimming.- Returns:
- new color
- Since:
- JavaView 3.54.001
- Version:
- 05.09.04, 1.00 created (kp)
-
getColor
public java.awt.Color getColor()
Convert color components in a java.awt.Color instance.- Returns:
- java.awt.Color instance of color components,
nullif less than 3 components available.
-
setColor
public void setColor(java.awt.Color aColor)
Set color components to components of argument color. This color must have enough color components. Alpha channel remains unchanged. Info panel is updated if it exists.- Parameters:
aColor- color to be assigned.
-
hasAlpha
public boolean hasAlpha()
Check whether alpha channel is used.- Returns:
trueof alpha channel is used;falseotherwise.- See Also:
enableAlpha(boolean)
-
enableAlpha
public void enableAlpha(boolean flag)
Enable or disable alpha channel. Internally, an alpha channel is allocated or removed.- Parameters:
flag-trueto enable alpha channel.- See Also:
setSize(int)
-
getEntry
public int getEntry(int ind)
Get a color component with given index.- Parameters:
ind- index of requested color component- Returns:
- value in [0,255] of color component; 0 if index out of bounds
-
setEntry
public void setEntry(int ind, int value)Set a color component with given index to value.- Parameters:
ind- index of color component to be modifiedvalue- value in [0,255] for all components of color
-
setEntry
public void setEntry(int ind, double value)Set a color component with given index to value.- Parameters:
ind- index of color component to be modifiedvalue- value in [0.,1.] for all components of color- Since:
- JavaView 2.32
-
setConstant
public void setConstant(int value)
Set all color components excluding alpha to the same value.- Parameters:
value- value in [0,255] for all components of color
-
setAlpha
public void setAlpha(int alpha)
Set alpha component of this color using integer argument in [0, 255]. Alpha must be enabled in order to be effective.- Parameters:
alpha- new alpha component in [0, 255]
-
setAlpha
public void setAlpha(double alpha)
Set alpha component of this color using double argument in [0., 1.]. Alpha must be enabled to allow assignment of new value.- Parameters:
alpha- new alpha component in [0., 1.]
-
set
public void set(int grey)
Set grey component of this color using integer argument in [0, 255]. Color must havesize == 1excluding alpha. If this color has too few components then a warning is issued without changes.- Parameters:
grey- new grey component in [0, 255]
-
set
public void set(int red, int green, int blue)Set components of this color using integer argument in [0, 255]. Color must havesize == 3excluding alpha. If this color has too few components then a warning is issued without changes.- Parameters:
red- new red color component in [0, 255]green- new green color component in [0, 255]blue- new blue color component in [0, 255]
-
set
public void set(int red, int green, int blue, int alpha)Set components of this color using double arguments in [0, 255]. If this color has too few components then a warning is issued without changes. If alpha is disabled then its value is ignored.- Parameters:
red- new red color component in [0, 255]green- new green color component in [0, 255]blue- new blue color component in [0, 255]alpha- new alpha components in [0, 255]
-
set
public void set(double grey)
Set grey component of this color using double arguments in [0., 1.]. Color must havesize == 1excluding alpha. If this color has too few components then a warning is issued without changes.- Parameters:
grey- new grey component in [0., 1.]
-
set
public void set(double red, double green, double blue)Set components of this color using double arguments in [0., 1.]. If this color has too few components then a warning is issued without changes.- Parameters:
red- new red color component in [0., 1.]green- new green color component in [0., 1.]blue- new blue color component in [0., 1.]
-
set
public void set(double red, double green, double blue, double alpha)Set components of this color using double arguments in [0., 1.]. If this color has too few components then a warning is issued without changes. If alpha is disabled then its value is ignored.- Parameters:
red- new red color component in [0., 1.]green- new green color component in [0., 1.]blue- new blue color component in [0., 1.]alpha- new alpha components in [0., 1.]
-
clone
public java.lang.Object clone()
Duplicate color and data array.- Overrides:
clonein classPsObject- See Also:
PsObject.copy(PsObject)- Version:
- 05.07.00, 1.00 created (kp)
-
copyNew
public static PdColor copyNew(PdColor v)
Create a new color as clone of argument color.- Parameters:
v- source color to clone
-
copy
public void copy(PdColor v)
Copy color components including alpha. Source and destination colors must have same size, except if destination color is empty then allocated space of size of source color.- Parameters:
v- source color to copy
-
copy
public void copy(int[] anArray, int aSize)Copy color components excluding alpha. Source and destination colors must have same size, except if destination color is empty then method allocates of size of source array.- Parameters:
anArray- new color components in [0, 255]aSize- number of entries in array
-
copy
public void copy(double[] anArray, int aSize)Copy color components excluding alpha. Source and destination colors must have same size, except if destination color is empty then method allocates space of size of source array.- Parameters:
anArray- new color components in [0., 1.]aSize- number of entries in array
-
max
public int max()
Find maximal value of component in color.- Returns:
- value of maximal component
- See Also:
min(),indexOfMax()
-
min
public int min()
Find minimal value of component in color.- Returns:
- value of minimal component
- See Also:
min(),indexOfMax()
-
indexOfMax
public int indexOfMax()
Find component in color with maximal value.- Returns:
- index of maximal component
-
indexOfMin
public int indexOfMin()
Find component in color with minimal value.- Returns:
- index of minimal component
-
blend
public static int blend(double a, int v, double b, int w)Interpolate between two colors with given weights. Usesthis = v*a + w*bincluding alpha component.Avoid negative values, method uses absolute value of each weight.
- Parameters:
a- weight of first color vv- first colorb- weight of second color ww- second color- See Also:
blend(double, PdColor, double, PdColor)- Version:
- 15.10.05, 1.00 created (kp)
-
blend
public static java.awt.Color blend(double a, java.awt.Color v, double b, java.awt.Color w)Interpolate between two colors with given weights. Usesthis = v*a + w*bincluding alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.Avoid negative values, method uses absolute value of each weight.
- Parameters:
a- weight of first color vv- first colorb- weight of second color ww- second color- See Also:
blend(double, PdColor, double, PdColor)- Version:
- 29.05.03, 1.10 revised (kp) Handle negative weights.
-
blend
public void blend(double a, PdColor v, double b, PdColor w)Interpolate between two colors with given weights. Usesthis = v*a + w*bincluding alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.Avoid negative values, method uses absolute value of each weight. All new color components are clipped to the range [0,255].
- Parameters:
a- weight of first color vv- first colorb- weight of second color ww- second color- See Also:
blendBase(PdColor, double, PdColor)- Version:
- 29.05.03, 1.10 revised (kp) Handle negative weights.
-
blendBase
public void blendBase(PdColor v, double b, PdColor w)
Interpolate between two colors with given weights. Usesthis = v + w*bincluding alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.- Parameters:
v- first colorb- weight of second color ww- second color- See Also:
blend(double, PdColor, double, PdColor)
-
realloc
public static java.awt.Color[] realloc(java.awt.Color[] data, int arraySize)Allocate an array of Java colors and assign default color black. If argumentdata!=nullthen as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array. Assignment of default color does not waist memory since assignment is made to a static class.If requested array size is 0 then method returns an array of length 0.
- Parameters:
data- possibly empty array of colorsarraySize- number of colors in new array- Version:
- 11.07.00, 1.20 revised (kp) If arraySize is 0 then return an array of length 0.
18.04.00, 1.10 revised (kp) Assign default colors if array is enlarged.
02.04.00, 1.00 created (kp) From similar PdColor methods.
-
realloc
public static PdColor[] realloc(PdColor[] data, int arraySize, int colorSize)
Allocate an array of colors, where all colors have the same dimension. If argumentdata!=nullthen as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array. Colors have no alpha channel.- Parameters:
data- possibly empty array of colorsarraySize- number of colors in new arraycolorSize- dimension of colors in new array- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
realloc
public static PdColor[] realloc(PdColor[] data, int arraySize, int colorSize, boolean bAlpha)
Allocate an array of colors, where all colors have the same dimension. If argumentdata!=nullthen as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array.- Parameters:
data- possibly empty array of colorsarraySize- number of colors in new arraycolorSize- dimension of colors in new arraybAlpha- flag whether alpha is enabled- Version:
- 26.12.99, 1.10 revised (kp) Use System.arraycopy internally.
-
copyNew
public static PdColor[] copyNew(PdColor[] data)
Create an new array with copies of all colors of a given array of colors. The new array contains new colors containing the same data as the original colors.- Parameters:
data- array of colors- Returns:
- new array with same number of colors as argument array
- See Also:
copyNew(PdColor [], int),copy(PdColor [], int, PdColor [], int, int)
-
copyNew
public static PdColor[] copyNew(PdColor[] data, int size)
Create an new array with copies of the first 'size' colors of a given array of colors. The new array contains new colors containing the same data as the original colors.- Parameters:
data- array of colorssize- number of copied colors of array- Returns:
- new array with number of colors equal to argument 'size'
- See Also:
copyNew(PdColor []),copy(PdColor [], int, PdColor [], int, int)
-
copyNew
public static java.awt.Color[] copyNew(java.awt.Color[] data)
Create an new array with copies of all colors of a given array of colors. The new array contains new colors containing the same data as the original colors.- Parameters:
data- array of colors- Returns:
- new array with same number of colors as argument array
- See Also:
copyNew(Color [], int),copy(Color [], int, Color [], int, int)- Version:
- 26.12.01, 1.00 created (kp) From similar PdColor methods.
-
copyNew
public static java.awt.Color[] copyNew(java.awt.Color[] data, int size)Create an new array with copies of the first 'size' colors of a given array of colors. The new array contains new colors containing the same data as the original colors.- Parameters:
data- array of colorssize- number of copied colors of array- Returns:
- new array with number of colors equal to argument 'size'
- See Also:
copyNew(Color []),copy(Color [], int, Color [], int, int)- Version:
- 26.12.01, 1.00 created (kp) From similar PdColor methods.
-
copy
public static boolean copy(java.awt.Color[] dataDest, int destInd, java.awt.Color[] dataSrc, int srcInd, int size)Assign some colors of a given array of colors to an existing destination array. Both source and destination array must exist already.
Destination array must be large enough, i.e.for (int i=0; i<size; i++) dataDest[destInd+i] = dataSrc[srcInd+i];dataDest.length >= destInd+size.- Parameters:
dataDest- destination array of colorsdestInd- index of first destination color in dataDestdataSrc- source array of colorssrcInd- index of first source color in dataSrc used for copyingsize- number of assigned colors of array- Returns:
- true if destination array is large enough
- See Also:
copy(PdColor)- Version:
- 02.04.00, 1.00 created (kp) From similar PdColor methods.
-
copy
public static boolean copy(PdColor[] dataDest, int destInd, PdColor[] dataSrc, int srcInd, int size)
Copies some colors of a given array of colors into an existing destination array. All colors in source and destination array must exist already.
Destination array must be large enough, i.e.for (int i=0; i<size; i++) dataDest[destInd+i] = dataSrc[srcInd+i];dataDest.length >= destInd+size.- Parameters:
dataDest- destination array of colorsdestInd- index of first destination color in dataDestdataSrc- source array of colorssrcInd- index of first source color in dataSrc used for copyingsize- number of copied colors of array- Returns:
trueif destination array is large enough- See Also:
copy(PdColor)
-
hsv2rgb
public static java.awt.Color hsv2rgb(java.awt.Color hsv)
Conversion of color spaces.
-
hsv2rgbAsInt
public static int hsv2rgbAsInt(int h, int s, int v)Conversion of color spaces. All values h,s,v are in range [0,255].- Since:
- JavaView 2.90.001
- Version:
- 11.08.03, 1.00 created (kp)
-
hsv2rgb
public static java.awt.Color hsv2rgb(int h, int s, int v)Conversion of color spaces.
-
hsl2rgb
public static java.awt.Color hsl2rgb(int hi, int li, int si)
-
rgb2hsl
public static java.awt.Color rgb2hsl(int ri, int gi, int bi)
-
yiq2rgb
public static java.awt.Color yiq2rgb(int yi, int ii, int qi)
-
rgb2yiq
public static java.awt.Color rgb2yiq(int ri, int gi, int bi)
-
cmyk2rgb
public static java.awt.Color cmyk2rgb(int c, int m, int y, int k)Convert a set of (cyan, magenta, yellow, black) to RGB color. CMYK color representation is used in print media.- Since:
- JavaView 2.49.002
- Version:
- 13.01.03, 1.00 created (kp)
-
rgb2cmyk
public static int[] rgb2cmyk(int r, int g, int b)Convert a set of (cyan, magenta, yellow, black) to RGB color. CMYK color representation is used in print media.- Since:
- JavaView 2.49.002
- Version:
- 13.01.03, 1.00 created (kp)
-
parseColor
public static java.awt.Color parseColor(java.lang.String colorString)
Parse rgb color from a given string where each component is integer in the range 0..255 or a float in the range [0.,1.], or the whole color string is in Html HEX representation such as "#FF0039".Colors are interpreted as HEX colors if the string starts with '#' character. Otherwise they are interpreted as float color if a '.' is found within the string, or else as integer colors.
Color components in int of float representation may be separated using either blanks, commas, semicolons or vertical bars.
- Parameters:
colorString- string with integer color components- Returns:
- java.awt.Color instance of color components,
nullif less than 3 components available. - Version:
- 15.12.13, 1.20 revised (kp) Vertical bar added as separator, better error checking.
12.10.02, 1.10 revised (kp) Html notation implemented.
24.08.00, 1.00 created (kp)
-
parseNamedColor
public static java.awt.Color parseNamedColor(java.lang.String str)
Parse a named color string into a java.awt.Color. The color name can be one of the following:black blue cyan gray darkGray lightGray grey darkGrey lightGrey green magenta orange pink red white yellow
and optionally the name can be preprended with a blank separated prefixdark light
. For example, 'dark red'.- Since:
- JavaView 3.97.002
- Version:
- 25.09.06, 1.00 created (kp)
-
getXORColor
public static java.awt.Color getXORColor(java.awt.Color colCurr, java.awt.Color colPref, java.awt.Color colAlt, int eps)Choose a new color depending on the distance to an existing color. If the preferred color more than eps away from the current color then return the preferred color. Otherwise return the alternate color.- Parameters:
colCurr- current color against which the new color is compared.colPref- new preferred colorcolAlt- alternative color choice returned if preferred color is eps-close to current coloreps- distance threshold in [0,255] compared to current color.- Returns:
- either colPref or colAlt
- Since:
- JavaView 3.55.001
- Version:
- 09.09.04, 1.00 created (kp)
-
toString
public static java.lang.String toString(java.awt.Color col, java.lang.String sep)Get string representation of color components with given separator string.- Since:
- JavaView 3.97.078
- Version:
- 10.06.07, 1.00 created (kp)
-
toStringAsFloat
public static java.lang.String toStringAsFloat(java.awt.Color col, java.lang.String sep)Get string representation of color components with given separator string and range of color components scaled to interval [0.,1.].- Since:
- JavaView 3.97.078
- Version:
- 10.06.07, 1.00 created (kp)
-
-
"