typedef unsigned char u8; typedef signed char s8; #define C1 (19595) #define C2 (38470) #define C3 (7471) #define C4 (32767) #define C5 (-15119) #define C6 (-17648) #define C7 (13282) #define C8 (-32767) #define C9 (19485) #define CONST (1 << 15) void foo(u8 *in, u8 *out, int n) { int i; u8 *read = in, *write = out; u8 x1, x2, x3, y1 = 0; s8 y2, y3; for(i = 0; i < n; i++) { x1 = *read++; x2 = *read++; x3 = *read++; y1 = (u8) ((C1 * x1 + C2 * x2 + C3 * x3 + CONST) >> 16); y2 = (s8) ((C4 * x1 + C5 * x2 + C6 * x3 + CONST) >> 16); y3 = (s8) ((C7 * x1 + C8 * x2 + C9 * x3 + CONST) >> 16); *write++ = y1; *write++ = (u8) y2; *write++ = (u8) y3; } }