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];
50 static inline int yuv_diff(uint32_t yuv1, uint32_t yuv2) {
51 return (( abs((
int)((yuv1 & Ymask) - (yuv2 & Ymask))) > trY ) ||
52 ( abs((
int)((yuv1 & Umask) - (yuv2 & Umask))) > trU ) ||
53 ( abs((
int)((yuv1 & Vmask) - (yuv2 & Vmask))) > trV ) );
56 static inline int Diff(uint32_t c1, uint32_t c2)
58 return yuv_diff(rgb_to_yuv(c1), rgb_to_yuv(c2));
62 static inline uint32_t Interpolate_2(uint32_t c1,
int w1, uint32_t c2,
int w2,
int s)
68 (((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2) << (24-s)) & MASK_ALPHA) +
69 ((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2) >> s) & MASK_2) +
70 ((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2) >> s) & MASK_13);
73 static inline uint32_t Interpolate_3(uint32_t c1,
int w1, uint32_t c2,
int w2, uint32_t c3,
int w3,
int s)
76 (((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2 + ((c3 & MASK_ALPHA) >> 24) * w3) << (24-s)) & MASK_ALPHA) +
77 ((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2 + (c3 & MASK_2) * w3) >> s) & MASK_2) +
78 ((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2 + (c3 & MASK_13) * w3) >> s) & MASK_13);
81 static inline uint32_t Interp1(uint32_t c1, uint32_t c2)
84 return Interpolate_2(c1, 3, c2, 1, 2);
87 static inline uint32_t Interp2(uint32_t c1, uint32_t c2, uint32_t c3)
90 return Interpolate_3(c1, 2, c2, 1, c3, 1, 2);
93 static inline uint32_t Interp3(uint32_t c1, uint32_t c2)
96 return Interpolate_2(c1, 7, c2, 1, 3);
99 static inline uint32_t Interp4(uint32_t c1, uint32_t c2, uint32_t c3)
102 return Interpolate_3(c1, 2, c2, 7, c3, 7, 4);
105 static inline uint32_t Interp5(uint32_t c1, uint32_t c2)
108 return Interpolate_2(c1, 1, c2, 1, 1);
111 static inline uint32_t Interp6(uint32_t c1, uint32_t c2, uint32_t c3)
114 return Interpolate_3(c1, 5, c2, 2, c3, 1, 3);
117 static inline uint32_t Interp7(uint32_t c1, uint32_t c2, uint32_t c3)
120 return Interpolate_3(c1, 6, c2, 1, c3, 1, 3);
123 static inline uint32_t Interp8(uint32_t c1, uint32_t c2)
126 return Interpolate_2(c1, 5, c2, 3, 3);
129 static inline uint32_t Interp9(uint32_t c1, uint32_t c2, uint32_t c3)
132 return Interpolate_3(c1, 2, c2, 3, c3, 3, 3);
135 static inline uint32_t Interp10(uint32_t c1, uint32_t c2, uint32_t c3)
138 return Interpolate_3(c1, 14, c2, 1, c3, 1, 4);