-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinternal_hqx_common.h
executable file
·142 lines (121 loc) · 4.51 KB
/
internal_hqx_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (C) 2003 Maxim Stepin ( [email protected] )
*
* Copyright (C) 2010 Cameron Zemek ( [email protected])
* Copyright (C) 2011 Francois Gannaz <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __INTERNAL_HQX_COMMON_H_
#define __INTERNAL_HQX_COMMON_H_
#include <stdlib.h>
#include <stdint.h>
#define XBR_INTERNAL
#include "filters.h"
#define MASK_2 0x0000FF00
#define MASK_13 0x00FF00FF
#define MASK_RGB 0x00FFFFFF
#define MASK_ALPHA 0xFF000000
#define Ymask 0x00FF0000
#define Umask 0x0000FF00
#define Vmask 0x000000FF
#define trY 0x00300000
#define trU 0x00000700
#define trV 0x00000006
/* RGB to YUV lookup table */
static XBR_INLINE uint32_t rgb_to_yuv(const xbr_data *data, uint32_t c)
{
// Mask against MASK_RGB to discard the alpha channel
return data->rgbtoyuv[MASK_RGB & c];
}
/* Test if there is difference in color */
static XBR_INLINE int yuv_diff(uint32_t yuv1, uint32_t yuv2) {
return (( abs((yuv1 & Ymask) - (yuv2 & Ymask)) > trY ) ||
( abs((yuv1 & Umask) - (yuv2 & Umask)) > trU ) ||
( abs((yuv1 & Vmask) - (yuv2 & Vmask)) > trV ) );
}
static XBR_INLINE int Diff(const xbr_data *data, uint32_t c1, uint32_t c2)
{
return yuv_diff(rgb_to_yuv(data, c1), rgb_to_yuv(data, c2));
}
/* Interpolate functions */
static XBR_INLINE uint32_t Interpolate_2(uint32_t c1, int w1, uint32_t c2, int w2, int s)
{
if (c1 == c2) {
return c1;
}
return
(((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2) << (24-s)) & MASK_ALPHA) +
((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2) >> s) & MASK_2) +
((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2) >> s) & MASK_13);
}
static XBR_INLINE uint32_t Interpolate_3(uint32_t c1, int w1, uint32_t c2, int w2, uint32_t c3, int w3, int s)
{
return
(((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2 + ((c3 & MASK_ALPHA) >> 24) * w3) << (24-s)) & MASK_ALPHA) +
((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2 + (c3 & MASK_2) * w3) >> s) & MASK_2) +
((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2 + (c3 & MASK_13) * w3) >> s) & MASK_13);
}
static XBR_INLINE void Interp1(uint32_t * pc, uint32_t c1, uint32_t c2)
{
//*pc = (c1*3+c2) >> 2;
*pc = Interpolate_2(c1, 3, c2, 1, 2);
}
static XBR_INLINE void Interp2(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*2+c2+c3) >> 2;
*pc = Interpolate_3(c1, 2, c2, 1, c3, 1, 2);
}
static XBR_INLINE void Interp3(uint32_t * pc, uint32_t c1, uint32_t c2)
{
//*pc = (c1*7+c2)/8;
*pc = Interpolate_2(c1, 7, c2, 1, 3);
}
static XBR_INLINE void Interp4(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*2+(c2+c3)*7)/16;
*pc = Interpolate_3(c1, 2, c2, 7, c3, 7, 4);
}
static XBR_INLINE void Interp5(uint32_t * pc, uint32_t c1, uint32_t c2)
{
//*pc = (c1+c2) >> 1;
*pc = Interpolate_2(c1, 1, c2, 1, 1);
}
static XBR_INLINE void Interp6(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*5+c2*2+c3)/8;
*pc = Interpolate_3(c1, 5, c2, 2, c3, 1, 3);
}
static XBR_INLINE void Interp7(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*6+c2+c3)/8;
*pc = Interpolate_3(c1, 6, c2, 1, c3, 1, 3);
}
static XBR_INLINE void Interp8(uint32_t * pc, uint32_t c1, uint32_t c2)
{
//*pc = (c1*5+c2*3)/8;
*pc = Interpolate_2(c1, 5, c2, 3, 3);
}
static XBR_INLINE void Interp9(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*2+(c2+c3)*3)/8;
*pc = Interpolate_3(c1, 2, c2, 3, c3, 3, 3);
}
static XBR_INLINE void Interp10(uint32_t * pc, uint32_t c1, uint32_t c2, uint32_t c3)
{
//*pc = (c1*14+c2+c3)/16;
*pc = Interpolate_3(c1, 14, c2, 1, c3, 1, 4);
}
#endif