diff --git a/core/src/main/java/com/threerings/media/image/ColorPository.java b/core/src/main/java/com/threerings/media/image/ColorPository.java index c600cce3..cdaf0f03 100644 --- a/core/src/main/java/com/threerings/media/image/ColorPository.java +++ b/core/src/main/java/com/threerings/media/image/ColorPository.java @@ -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 diff --git a/core/src/main/java/com/threerings/media/image/Colorization.java b/core/src/main/java/com/threerings/media/image/Colorization.java index 002ffd72..f5b4a453 100644 --- a/core/src/main/java/com/threerings/media/image/Colorization.java +++ b/core/src/main/java/com/threerings/media/image/Colorization.java @@ -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).