Created
August 24, 2012 15:04
-
-
Save clausecker/3451755 to your computer and use it in GitHub Desktop.
Improved Paeth-transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
int naive_paeth(int a, int b, int c) { | |
int | |
p = a + b - c, | |
pa = abs(p - a), | |
pb = abs(p - b), | |
pc = abs(p - c); | |
if (pa <= pb && pa <= pc) return a; | |
if (pb <= pc) return b; | |
return c; | |
} | |
int libpng_paeth(int a, int b, int c) { | |
int pa, pb, pc, p; | |
p = b - c; | |
pc = a - c; | |
pa = abs(p); | |
pb = abs(pc); | |
pc = abs(p + pc); | |
/* Find the best predictor, the least of pa, pb, pc favoring the earlier | |
* ones in the case of a tie. | |
*/ | |
if (pb < pa) pa = pb, a = b; | |
if (pc < pa) a = c; | |
return a; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment