Skip to content

Commit

Permalink
Various minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed May 25, 2022
1 parent 390db74 commit 2cc7f50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/github/tommyettinger/anim8/OtherMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -163,7 +163,7 @@ private static float atanUnchecked(final float i) {
* <br>
* 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
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/github/tommyettinger/anim8/PaletteReducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.)</li>
* 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.)</li>
* <li>{@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
Expand Down Expand Up @@ -95,7 +96,8 @@
* the other algorithms take comparable amounts of time to each other, but KnollRoberts and especially Knoll are
* sluggish.)</li>
* <li>{@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.)</li>
* 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.)</li>
* </ul>
* </li>
* </ul>
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 2cc7f50

Please sign in to comment.