Improve Colorization slightly.
Colorizations are not cached, and the root color values are recomputed every time. We can share those. Also added an accessor to read the already computed HSV values out of a Colorization. I suppose I could just make it a public field or return the array directly. The rootColor variable is already public. DFU. But now the array will be shared by every instance from the same classRecord, so it seems more important to make sure nothing goes wrong.
This commit is contained in:
@@ -179,6 +179,26 @@ public class ColorPository implements Serializable
|
||||
StringUtil.toString(colors.values().iterator()) + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the HSV values for the root color if not already computed.
|
||||
* This is weird, and used to avoid recomputing it for every single colorization made from
|
||||
* every single ColorRecord in this class. Part of the weirdness is because we
|
||||
* don't serialize these values to ensure backwards compatibility, and so we need to
|
||||
* make sure they're computed prior to being used.
|
||||
*/
|
||||
protected void computeHsv ()
|
||||
{
|
||||
if (_hsv == null) {
|
||||
_hsv = Color.RGBtoHSB(source.getRed(), source.getGreen(), source.getBlue(), null);
|
||||
_fhsv = Colorization.toFixedHSV(_hsv, null);
|
||||
}
|
||||
}
|
||||
|
||||
/** The hsv array shared by all Colorizations created from this instance. */
|
||||
protected transient float[] _hsv;
|
||||
/** The fhsv array shared by all Colorizations created from this instance. */
|
||||
protected transient int[] _fhsv;
|
||||
|
||||
protected transient ColorRecord[] _starters;
|
||||
|
||||
/** Increase this value when object's serialized state is impacted
|
||||
@@ -227,7 +247,7 @@ public class ColorPository implements Serializable
|
||||
// cclass.range, offsets);
|
||||
// }
|
||||
// return _zation;
|
||||
return new Colorization(getColorPrint(), cclass.source, cclass.range, offsets);
|
||||
return new Colorization(getColorPrint(), cclass, offsets);
|
||||
}
|
||||
|
||||
// from interface Comparable<ColorRecord>
|
||||
|
||||
@@ -57,6 +57,20 @@ public class Colorization
|
||||
_fhsv = toFixedHSV(_hsv, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A colorization generated from a ClassRecord.
|
||||
*/
|
||||
protected Colorization (int colorizationId, ColorPository.ClassRecord crec, float[] offsets)
|
||||
{
|
||||
this.colorizationId = colorizationId;
|
||||
this.rootColor = crec.source;
|
||||
this.range = crec.range;
|
||||
crec.computeHsv();
|
||||
_hsv = crec._hsv;
|
||||
_fhsv = crec._fhsv;
|
||||
this.offsets = offsets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root color adjusted by the colorization.
|
||||
*/
|
||||
@@ -65,6 +79,14 @@ public class Colorization
|
||||
return new Color(recolorColor(_hsv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw HSV values of the root color.
|
||||
*/
|
||||
public float getRootHsv (int index)
|
||||
{
|
||||
return _hsv[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts the supplied color by the offsets in this colorization, taking the appropriate
|
||||
* measures for hue (wrapping it around) and saturation and value (clipping).
|
||||
|
||||
Reference in New Issue
Block a user