From 1686d5becc5dfc5a025e461a4760ab17614cce62 Mon Sep 17 00:00:00 2001 From: Matthew Frazier Date: Mon, 18 Aug 2014 09:24:49 -0400 Subject: [PATCH] add Math.round() to Pixel.correctLevel() The old versions of setRed/Green/Blue cast doubles to ints whenever necessary. I thought the new versions would, but they actually didn't because they passed the values through Pixel.correctLevel(int). I assumed Jython would downcast the doubles to ints, but that was wrong. So, I added a Pixel.correctLevel(double) that rounds the value passed in before passing it to Pixel.correctLevel(int). --- jes/java/Pixel.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jes/java/Pixel.java b/jes/java/Pixel.java index ea3d7c1..b7cffb5 100644 --- a/jes/java/Pixel.java +++ b/jes/java/Pixel.java @@ -42,6 +42,17 @@ public static void setWrapLevels (boolean wrap) { wrapLevels = wrap; } + /** + * Round and correct a color level to be within 0 and 255, + * according to the current wrapLevels setting. + * + * @param level The user-provided level. + * @return A value within 0 and 255. + */ + public static int correctLevel (double level) { + return correctLevel((int) Math.round(level)); + } + /** * Correct a color level to be within 0 and 255, * according to the current wrapLevels setting.