diff --git a/QOI.fu b/QOI.fu index 27b81f6..313d60c 100644 --- a/QOI.fu +++ b/QOI.fu @@ -121,9 +121,9 @@ public class QOIEncoder encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 0xff); - int dg = g - (lastPixel >> 8 & 0xff); - int db = b - (lastPixel & 0xff); + int dr = (r - (lastPixel >> 16) & 0xff ^ 0x80) - 0x80; + int dg = (g - (lastPixel >> 8) & 0xff ^ 0x80) - 0x80; + int db = (b - lastPixel & 0xff ^ 0x80) - 0x80; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) diff --git a/transpiled/QOI.c b/transpiled/QOI.c index ac9fb5c..4235aef 100644 --- a/transpiled/QOI.c +++ b/transpiled/QOI.c @@ -163,9 +163,9 @@ bool QOIEncoder_Encode(QOIEncoder *self, int width, int height, int const *pixel encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 255); - int dg = g - (lastPixel >> 8 & 255); - int db = b - (lastPixel & 255); + int dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + int dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + int db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = (uint8_t) (106 + (dr << 4) + (dg << 2) + db); else { diff --git a/transpiled/QOI.cpp b/transpiled/QOI.cpp index e1d06a9..732b9e3 100644 --- a/transpiled/QOI.cpp +++ b/transpiled/QOI.cpp @@ -67,9 +67,9 @@ bool QOIEncoder::encode(int width, int height, int const * pixels, bool alpha, b encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 255); - int dg = g - (lastPixel >> 8 & 255); - int db = b - (lastPixel & 255); + int dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + int dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + int db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = static_cast(106 + (dr << 4) + (dg << 2) + db); else { diff --git a/transpiled/QOI.cs b/transpiled/QOI.cs index a5cbbc9..bfae617 100644 --- a/transpiled/QOI.cs +++ b/transpiled/QOI.cs @@ -88,9 +88,9 @@ public bool Encode(int width, int height, int[] pixels, bool alpha, bool linearC encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 255); - int dg = g - (lastPixel >> 8 & 255); - int db = b - (lastPixel & 255); + int dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + int dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + int db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = (byte) (106 + (dr << 4) + (dg << 2) + db); else { diff --git a/transpiled/QOI.d b/transpiled/QOI.d index ad8f6a9..e6907f8 100644 --- a/transpiled/QOI.d +++ b/transpiled/QOI.d @@ -88,9 +88,9 @@ class QOIEncoder encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 255); - int dg = g - (lastPixel >> 8 & 255); - int db = b - (lastPixel & 255); + int dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + int dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + int db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = cast(ubyte)(106 + (dr << 4) + (dg << 2) + db); else { diff --git a/transpiled/QOI.js b/transpiled/QOI.js index 6d15f37..f1fc029 100644 --- a/transpiled/QOI.js +++ b/transpiled/QOI.js @@ -96,9 +96,9 @@ export class QOIEncoder encodedOffset += 5; } else { - let dr = r - (lastPixel >> 16 & 255); - let dg = g - (lastPixel >> 8 & 255); - let db = b - (lastPixel & 255); + let dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + let dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + let db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = 106 + (dr << 4) + (dg << 2) + db; else { diff --git a/transpiled/QOI.py b/transpiled/QOI.py index 4b522ff..7f7c2bc 100644 --- a/transpiled/QOI.py +++ b/transpiled/QOI.py @@ -94,9 +94,9 @@ def encode(self, width: int, height: int, pixels: array.array, alpha: bool, line encoded[encoded_offset + 4] = pixel >> 24 & 255 encoded_offset += 5 else: - dr: int = r - (last_pixel >> 16 & 255) - dg: int = g - (last_pixel >> 8 & 255) - db: int = b - (last_pixel & 255) + dr: int = (((r - (last_pixel >> 16)) & 255) ^ 128) - 128 + dg: int = (((g - (last_pixel >> 8)) & 255) ^ 128) - 128 + db: int = (((b - last_pixel) & 255) ^ 128) - 128 if dr >= -2 and dr <= 1 and dg >= -2 and dg <= 1 and db >= -2 and db <= 1: encoded[encoded_offset] = 106 + (dr << 4) + (dg << 2) + db encoded_offset += 1 diff --git a/transpiled/QOI.swift b/transpiled/QOI.swift index 2fef440..2aac0b1 100644 --- a/transpiled/QOI.swift +++ b/transpiled/QOI.swift @@ -99,9 +99,9 @@ public class QOIEncoder encodedOffset += 5 } else { - var dr : Int = r - lastPixel >> 16 & 255 - let dg : Int = g - lastPixel >> 8 & 255 - var db : Int = b - lastPixel & 255 + var dr : Int = (r - lastPixel >> 16) & 255 ^ 128 - 128 + let dg : Int = (g - lastPixel >> 8) & 255 ^ 128 - 128 + var db : Int = (b - lastPixel) & 255 ^ 128 - 128 if dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1 { encoded[encodedOffset] = UInt8(106 + dr << 4 + dg << 2 + db) encodedOffset += 1 diff --git a/transpiled/QOI.ts b/transpiled/QOI.ts index d624295..7d252b6 100644 --- a/transpiled/QOI.ts +++ b/transpiled/QOI.ts @@ -96,9 +96,9 @@ export class QOIEncoder encodedOffset += 5; } else { - let dr: number = r - (lastPixel >> 16 & 255); - let dg: number = g - (lastPixel >> 8 & 255); - let db: number = b - (lastPixel & 255); + let dr: number = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + let dg: number = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + let db: number = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = 106 + (dr << 4) + (dg << 2) + db; else { diff --git a/transpiled/QOIEncoder.java b/transpiled/QOIEncoder.java index 9995230..597a621 100644 --- a/transpiled/QOIEncoder.java +++ b/transpiled/QOIEncoder.java @@ -97,9 +97,9 @@ public final boolean encode(int width, int height, int[] pixels, boolean alpha, encodedOffset += 5; } else { - int dr = r - (lastPixel >> 16 & 255); - int dg = g - (lastPixel >> 8 & 255); - int db = b - (lastPixel & 255); + int dr = (((r - (lastPixel >> 16)) & 255) ^ 128) - 128; + int dg = (((g - (lastPixel >> 8)) & 255) ^ 128) - 128; + int db = (((b - lastPixel) & 255) ^ 128) - 128; if (dr >= -2 && dr <= 1 && dg >= -2 && dg <= 1 && db >= -2 && db <= 1) encoded[encodedOffset++] = (byte) (106 + (dr << 4) + (dg << 2) + db); else {