22 #ifndef __HQX_COMMON_H_ 23 #define __HQX_COMMON_H_ 28 #define MASK_2 0x0000FF00 29 #define MASK_13 0x00FF00FF 30 #define MASK_RGB 0x00FFFFFF 31 #define MASK_ALPHA 0xFF000000 33 #define Ymask 0x00FF0000 34 #define Umask 0x0000FF00 35 #define Vmask 0x000000FF 36 #define trY 0x00300000 37 #define trU 0x00000700 38 #define trV 0x00000006 41 extern uint32_t RGBtoYUV[16777216];
43 static inline uint32_t rgb_to_yuv(uint32_t c)
46 return RGBtoYUV[MASK_RGB & c];
51 static inline int yuv_diff(uint32_t yuv1, uint32_t yuv2) {
52 return (( abs((
int)((yuv1 & Ymask) - (yuv2 & Ymask))) > trY ) ||
53 ( abs((
int)((yuv1 & Umask) - (yuv2 & Umask))) > trU ) ||
54 ( abs((
int)((yuv1 & Vmask) - (yuv2 & Vmask))) > trV ) );
57 static inline int Diff(uint32_t c1, uint32_t c2)
59 return yuv_diff(rgb_to_yuv(c1), rgb_to_yuv(c2));
63 static inline uint32_t Interpolate_2(uint32_t c1,
int w1, uint32_t c2,
int w2,
int s)
70 (((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2) << (24-s)) & MASK_ALPHA) +
71 ((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2) >> s) & MASK_2) +
72 ((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2) >> s) & MASK_13);
75 static inline uint32_t Interpolate_3(uint32_t c1,
int w1, uint32_t c2,
int w2, uint32_t c3,
int w3,
int s)
78 (((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2 + ((c3 & MASK_ALPHA) >> 24) * w3) << (24-s)) & MASK_ALPHA) +
79 ((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2 + (c3 & MASK_2) * w3) >> s) & MASK_2) +
80 ((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2 + (c3 & MASK_13) * w3) >> s) & MASK_13);
83 static inline uint32_t Interp1(uint32_t c1, uint32_t c2)
86 return Interpolate_2(c1, 3, c2, 1, 2);
89 static inline uint32_t Interp2(uint32_t c1, uint32_t c2, uint32_t c3)
92 return Interpolate_3(c1, 2, c2, 1, c3, 1, 2);
95 static inline uint32_t Interp3(uint32_t c1, uint32_t c2)
98 return Interpolate_2(c1, 7, c2, 1, 3);
101 static inline uint32_t Interp4(uint32_t c1, uint32_t c2, uint32_t c3)
104 return Interpolate_3(c1, 2, c2, 7, c3, 7, 4);
107 static inline uint32_t Interp5(uint32_t c1, uint32_t c2)
110 return Interpolate_2(c1, 1, c2, 1, 1);
113 static inline uint32_t Interp6(uint32_t c1, uint32_t c2, uint32_t c3)
116 return Interpolate_3(c1, 5, c2, 2, c3, 1, 3);
119 static inline uint32_t Interp7(uint32_t c1, uint32_t c2, uint32_t c3)
122 return Interpolate_3(c1, 6, c2, 1, c3, 1, 3);
125 static inline uint32_t Interp8(uint32_t c1, uint32_t c2)
128 return Interpolate_2(c1, 5, c2, 3, 3);
131 static inline uint32_t Interp9(uint32_t c1, uint32_t c2, uint32_t c3)
134 return Interpolate_3(c1, 2, c2, 3, c3, 3, 3);
137 static inline uint32_t Interp10(uint32_t c1, uint32_t c2, uint32_t c3)
140 return Interpolate_3(c1, 14, c2, 1, c3, 1, 4);