From 2cc7f5057c7ac2009682eae96e4c357460d26716 Mon Sep 17 00:00:00 2001 From: Tommy Ettinger Date: Tue, 24 May 2022 21:57:54 -0700 Subject: [PATCH] Various minor cleanup. --- .../github/tommyettinger/anim8/OtherMath.java | 6 ++--- .../tommyettinger/anim8/PaletteReducer.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/github/tommyettinger/anim8/OtherMath.java b/src/main/java/com/github/tommyettinger/anim8/OtherMath.java index 3b937667..1755778b 100644 --- a/src/main/java/com/github/tommyettinger/anim8/OtherMath.java +++ b/src/main/java/com/github/tommyettinger/anim8/OtherMath.java @@ -149,8 +149,8 @@ private static float atanUnchecked(final float i) { final float c3 = c * c2; final float c5 = c3 * c2; final float c7 = c5 * c2; - return Math.copySign(0.7853981633974483f + - (0.999215f * c - 0.3211819f * c3 + 0.1462766f * c5 - 0.0389929f * c7), i); + return Math.signum(i) * (0.7853981633974483f + + (0.999215f * c - 0.3211819f * c3 + 0.1462766f * c5 - 0.0389929f * c7)); } /** @@ -163,7 +163,7 @@ private static float atanUnchecked(final float i) { *
* Credit for this goes to the 1955 research study "Approximations for Digital Computers," by RAND Corporation. This * is sheet 9's algorithm, which is the second-fastest and second-least precise. The algorithm on sheet 8 is faster, - * but only by a very small degree, and is considerably less precise. That study provides an {@link #atan(float)} + * but only by a very small degree, and is considerably less precise. That study provides an atan(float) * method, and the small code to make that work as atan2() was worked out from Wikipedia. * @param y y-component of the point to find the angle towards; note the parameter order is unusual by convention * @param x x-component of the point to find the angle towards; note the parameter order is unusual by convention diff --git a/src/main/java/com/github/tommyettinger/anim8/PaletteReducer.java b/src/main/java/com/github/tommyettinger/anim8/PaletteReducer.java index a8d2d0e6..0a8b4b3a 100644 --- a/src/main/java/com/github/tommyettinger/anim8/PaletteReducer.java +++ b/src/main/java/com/github/tommyettinger/anim8/PaletteReducer.java @@ -61,7 +61,8 @@ * Neue is the default currently because it is the only dither that both handles gradients well and preserves color * well. Blue Noise dither also handles gradients well, but doesn't always recognize color changes. Scatter handles * color well, but can have some banding. Pattern dither usually handles gradients exceptionally well, but can have - * severe issues when it doesn't preserve lightness faithfully with small palettes. The list goes on.) + * severe issues when it doesn't preserve lightness faithfully with small palettes. The list goes on. Neue can + * introduce error if the palette perfectly matches the image already; in that case, use Solid.) *
  • {@link #reduceKnoll(Pixmap)} (Thomas Knoll's Pattern Dithering, used more or less verbatim; this version has * a heavy grid pattern that looks like an artifact. While the square grid here is a bit bad, it becomes very hard * to see when the palette is large enough. This reduction is the slowest here, currently, and may noticeably delay @@ -95,7 +96,8 @@ * the other algorithms take comparable amounts of time to each other, but KnollRoberts and especially Knoll are * sluggish.)
  • *
  • {@link #reduceSolid(Pixmap)} (No dither! Solid colors! Mostly useful when you want to preserve blocky parts - * of a source image, or for some kinds of pixel/low-color art.)
  • + * of a source image, or for some kinds of pixel/low-color art. If you have a palette that perfectly matches the + * image you are dithering, then you won't need dither, and this will be the best option.) * * * @@ -257,19 +259,18 @@ public static float reverseLight(float L) { * would be needed. */ public static final float[] TRI_BLUE_NOISE_MULTIPLIERS = ConstantData.TRI_BLUE_NOISE_MULTIPLIERS; - private static final double[] EXACT_LOOKUP = new double[256]; - private static final double[] ANALYTIC_LOOKUP = new double[256]; +// private static final double[] EXACT_LOOKUP = new double[256]; +// private static final double[] ANALYTIC_LOOKUP = new double[256]; static { - double r, g, b, l, m, s; float rf, gf, bf, lf, mf, sf; int idx = 0; for (int ri = 0; ri < 32; ri++) { - rf = (float) (r = ri * ri * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 + rf = (float) (ri * ri * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 for (int gi = 0; gi < 32; gi++) { - gf = (float) (g = gi * gi * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 + gf = (float) (gi * gi * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 for (int bi = 0; bi < 32; bi++) { - bf = (float) (b = bi * bi * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 + bf = (float) (bi * bi * 0.0010405827263267429); // 1.0 / 31.0 / 31.0 lf = OtherMath.cbrt(0.4121656120f * rf + 0.5362752080f * gf + 0.0514575653f * bf); mf = OtherMath.cbrt(0.2118591070f * rf + 0.6807189584f * gf + 0.1074065790f * bf); @@ -285,10 +286,10 @@ public static float reverseLight(float L) { } } } - for (int i = 1; i < 256; i++) { - EXACT_LOOKUP[i] = OtherMath.barronSpline(i / 255f, 4f, 0.5f); - ANALYTIC_LOOKUP[i] = OtherMath.barronSpline(i / 255f, 3f, 0.5f); - } +// for (int i = 1; i < 256; i++) { +// EXACT_LOOKUP[i] = OtherMath.barronSpline(i / 255f, 4f, 0.5f); +// ANALYTIC_LOOKUP[i] = OtherMath.barronSpline(i / 255f, 3f, 0.5f); +// } // // double r, g, b, x, y, z;