Skip to content

Commit

Permalink
Fixed wrong division hack
Browse files Browse the repository at this point in the history
The numerator can be negative, thus the bit-hack yields wrong results.
  • Loading branch information
gfoidl committed Mar 24, 2023
1 parent 0a1f05b commit b694956
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Webp/Lossless/LosslessUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ private static uint ClampedAddSubtractHalf(uint c0, uint c1, uint c2)
}

[MethodImpl(InliningOptions.ShortMethod)]
private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) >> 1))); // >> 1 is bit-hack for / 2
private static int AddSubtractComponentHalf(int a, int b) => (int)Clip255((uint)(a + ((a - b) / 2)));

[MethodImpl(InliningOptions.ShortMethod)]
private static int AddSubtractComponentFull(int a, int b, int c) => (int)Clip255((uint)(a + b - c));
Expand Down

0 comments on commit b694956

Please sign in to comment.