Skip to content

Commit

Permalink
Oceanic, Gif, PNG8...
Browse files Browse the repository at this point in the history
Closing in...
  • Loading branch information
tommyettinger committed Dec 12, 2024
1 parent 4aa3746 commit 981f97e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/github/tommyettinger/anim8/AnimatedGif.java
Original file line number Diff line number Diff line change
Expand Up @@ -1734,8 +1734,9 @@ protected void analyzeOceanic() {
final int w = width;
byte paletteIndex;
float r4, r2, r1, g4, g2, g1, b4, b2, b1;
final float s = 0.175f * ditherStrength * (palette.populationBias * palette.populationBias * palette.populationBias),
strength = s * 0.29f / (0.19f + s);
final float populationBias = palette.populationBias;
final float s = 0.175f * ditherStrength / (populationBias * populationBias * populationBias),
strength = s * 0.59f / (0.4f + s);
float[] curErrorRed, nextErrorRed, curErrorGreen, nextErrorGreen, curErrorBlue, nextErrorBlue;
if (palette.curErrorRedFloats == null) {
curErrorRed = (palette.curErrorRedFloats = new FloatArray(w)).items;
Expand Down Expand Up @@ -1777,9 +1778,9 @@ protected void analyzeOceanic() {
float er = curErrorRed[px];
float eg = curErrorGreen[px];
float eb = curErrorBlue[px];
int rr = Math.min(Math.max((int)(((color >>> 24) ) + er + 0.5f), 0), 0xFF);
int gg = Math.min(Math.max((int)(((color >>> 16) & 0xFF) + eg + 0.5f), 0), 0xFF);
int bb = Math.min(Math.max((int)(((color >>> 8) & 0xFF) + eb + 0.5f), 0), 0xFF);
int rr = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 24) ] + er, 0), 1023)] & 255;
int gg = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 16) & 0xFF] + eg, 0), 1023)] & 255;
int bb = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 8) & 0xFF] + eb, 0), 1023)] & 255;
usedEntry[(indexedPixels[i] = paletteIndex =
paletteMapping[((rr << 7) & 0x7C00)
| ((gg << 2) & 0x3E0)
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/github/tommyettinger/anim8/PNG8.java
Original file line number Diff line number Diff line change
Expand Up @@ -3218,8 +3218,9 @@ public void writeOceanicDithered(OutputStream output, Pixmap pixmap) {
final int w = pixmap.getWidth();
final int h = pixmap.getHeight();
float r4, r2, r1, g4, g2, g1, b4, b2, b1;
final float s = 0.175f * ditherStrength * (palette.populationBias * palette.populationBias * palette.populationBias),
strength = s * 0.29f / (0.19f + s);
final float populationBias = palette.populationBias;
final float s = 0.175f * ditherStrength / (populationBias * populationBias * populationBias),
strength = s * 0.59f / (0.4f + s);
float[] curErrorRed, nextErrorRed, curErrorGreen, nextErrorGreen, curErrorBlue, nextErrorBlue;
if (palette.curErrorRedFloats == null) {
curErrorRed = (palette.curErrorRedFloats = new FloatArray(w)).items;
Expand Down Expand Up @@ -3297,9 +3298,9 @@ public void writeOceanicDithered(OutputStream output, Pixmap pixmap) {
float er = curErrorRed[px];
float eg = curErrorGreen[px];
float eb = curErrorBlue[px];
int rr = Math.min(Math.max((int)(((color >>> 24) ) + er + 0.5f), 0), 0xFF);
int gg = Math.min(Math.max((int)(((color >>> 16) & 0xFF) + eg + 0.5f), 0), 0xFF);
int bb = Math.min(Math.max((int)(((color >>> 8) & 0xFF) + eb + 0.5f), 0), 0xFF);
int rr = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 24) ] + er, 0), 1023)] & 255;
int gg = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 16) & 0xFF] + eg, 0), 1023)] & 255;
int bb = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 8) & 0xFF] + eb, 0), 1023)] & 255;
curLine[px] = paletteIndex =
paletteMapping[((rr << 7) & 0x7C00)
| ((gg << 2) & 0x3E0)
Expand Down Expand Up @@ -6646,8 +6647,9 @@ public void writeOceanicDithered(OutputStream output, Array<Pixmap> frames, int
final int h = pixmap.getHeight();
final int flipDir = flipY ? -1 : 1;
float r4, r2, r1, g4, g2, g1, b4, b2, b1;
final float s = 0.175f * ditherStrength * (palette.populationBias * palette.populationBias * palette.populationBias),
strength = s * 0.29f / (0.19f + s);
final float populationBias = palette.populationBias;
final float s = 0.175f * ditherStrength / (populationBias * populationBias * populationBias),
strength = s * 0.59f / (0.4f + s);
float[] curErrorRed, nextErrorRed, curErrorGreen, nextErrorGreen, curErrorBlue, nextErrorBlue;
if (palette.curErrorRedFloats == null) {
curErrorRed = (palette.curErrorRedFloats = new FloatArray(w)).items;
Expand Down Expand Up @@ -6752,9 +6754,9 @@ public void writeOceanicDithered(OutputStream output, Array<Pixmap> frames, int
float er = curErrorRed[px];
float eg = curErrorGreen[px];
float eb = curErrorBlue[px];
int rr = Math.min(Math.max((int) (((color >>> 24)) + er + 0.5f), 0), 0xFF);
int gg = Math.min(Math.max((int) (((color >>> 16) & 0xFF) + eg + 0.5f), 0), 0xFF);
int bb = Math.min(Math.max((int) (((color >>> 8) & 0xFF) + eb + 0.5f), 0), 0xFF);
int rr = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 24) ] + er, 0), 1023)] & 255;
int gg = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 16) & 0xFF] + eg, 0), 1023)] & 255;
int bb = fromLinearLUT[(int)Math.min(Math.max(toLinearLUT[(color >>> 8) & 0xFF] + eb, 0), 1023)] & 255;
byte paletteIndex =
paletteMapping[((rr << 7) & 0x7C00)
| ((gg << 2) & 0x3E0)
Expand Down

0 comments on commit 981f97e

Please sign in to comment.