1 /*
2  * Copyright (C) 2003 Maxim Stepin ( maxst@hiend3d.com )
3  *
4  * Copyright (C) 2010 Cameron Zemek ( grom@zeminvaders.net)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #include <stdint.h>
22 #include "hqx.h"
23 #include "common.h"
24 
25 #define PIXEL00_0     *dp = w[5];
26 #define PIXEL00_11    *dp = Interp1_16(w[5], w[4]);
27 #define PIXEL00_12    *dp = Interp1_16(w[5], w[2]);
28 #define PIXEL00_20    *dp = Interp2_16(w[5], w[2], w[4]);
29 #define PIXEL00_50    *dp = Interp5_16(w[2], w[4]);
30 #define PIXEL00_80    *dp = Interp8_16(w[5], w[1]);
31 #define PIXEL00_81    *dp = Interp8_16(w[5], w[4]);
32 #define PIXEL00_82    *dp = Interp8_16(w[5], w[2]);
33 #define PIXEL01_0     *(dp+1) = w[5];
34 #define PIXEL01_10    *(dp+1) = Interp1_16(w[5], w[1]);
35 #define PIXEL01_12    *(dp+1) = Interp1_16(w[5], w[2]);
36 #define PIXEL01_14    *(dp+1) = Interp1_16(w[2], w[5]);
37 #define PIXEL01_21    *(dp+1) = Interp2_16(w[2], w[5], w[4]);
38 #define PIXEL01_31    *(dp+1) = Interp3_16(w[5], w[4]);
39 #define PIXEL01_50    *(dp+1) = Interp5_16(w[2], w[5]);
40 #define PIXEL01_60    *(dp+1) = Interp6_16(w[5], w[2], w[4]);
41 #define PIXEL01_61    *(dp+1) = Interp6_16(w[5], w[2], w[1]);
42 #define PIXEL01_82    *(dp+1) = Interp8_16(w[5], w[2]);
43 #define PIXEL01_83    *(dp+1) = Interp8_16(w[2], w[4]);
44 #define PIXEL02_0     *(dp+2) = w[5];
45 #define PIXEL02_10    *(dp+2) = Interp1_16(w[5], w[3]);
46 #define PIXEL02_11    *(dp+2) = Interp1_16(w[5], w[2]);
47 #define PIXEL02_13    *(dp+2) = Interp1_16(w[2], w[5]);
48 #define PIXEL02_21    *(dp+2) = Interp2_16(w[2], w[5], w[6]);
49 #define PIXEL02_32    *(dp+2) = Interp3_16(w[5], w[6]);
50 #define PIXEL02_50    *(dp+2) = Interp5_16(w[2], w[5]);
51 #define PIXEL02_60    *(dp+2) = Interp6_16(w[5], w[2], w[6]);
52 #define PIXEL02_61    *(dp+2) = Interp6_16(w[5], w[2], w[3]);
53 #define PIXEL02_81    *(dp+2) = Interp8_16(w[5], w[2]);
54 #define PIXEL02_83    *(dp+2) = Interp8_16(w[2], w[6]);
55 #define PIXEL03_0     *(dp+3) = w[5];
56 #define PIXEL03_11    *(dp+3) = Interp1_16(w[5], w[2]);
57 #define PIXEL03_12    *(dp+3) = Interp1_16(w[5], w[6]);
58 #define PIXEL03_20    *(dp+3) = Interp2_16(w[5], w[2], w[6]);
59 #define PIXEL03_50    *(dp+3) = Interp5_16(w[2], w[6]);
60 #define PIXEL03_80    *(dp+3) = Interp8_16(w[5], w[3]);
61 #define PIXEL03_81    *(dp+3) = Interp8_16(w[5], w[2]);
62 #define PIXEL03_82    *(dp+3) = Interp8_16(w[5], w[6]);
63 #define PIXEL10_0     *(dp+dpL) = w[5];
64 #define PIXEL10_10    *(dp+dpL) = Interp1_16(w[5], w[1]);
65 #define PIXEL10_11    *(dp+dpL) = Interp1_16(w[5], w[4]);
66 #define PIXEL10_13    *(dp+dpL) = Interp1_16(w[4], w[5]);
67 #define PIXEL10_21    *(dp+dpL) = Interp2_16(w[4], w[5], w[2]);
68 #define PIXEL10_32    *(dp+dpL) = Interp3_16(w[5], w[2]);
69 #define PIXEL10_50    *(dp+dpL) = Interp5_16(w[4], w[5]);
70 #define PIXEL10_60    *(dp+dpL) = Interp6_16(w[5], w[4], w[2]);
71 #define PIXEL10_61    *(dp+dpL) = Interp6_16(w[5], w[4], w[1]);
72 #define PIXEL10_81    *(dp+dpL) = Interp8_16(w[5], w[4]);
73 #define PIXEL10_83    *(dp+dpL) = Interp8_16(w[4], w[2]);
74 #define PIXEL11_0     *(dp+dpL+1) = w[5];
75 #define PIXEL11_30    *(dp+dpL+1) = Interp3_16(w[5], w[1]);
76 #define PIXEL11_31    *(dp+dpL+1) = Interp3_16(w[5], w[4]);
77 #define PIXEL11_32    *(dp+dpL+1) = Interp3_16(w[5], w[2]);
78 #define PIXEL11_70    *(dp+dpL+1) = Interp7_16(w[5], w[4], w[2]);
79 #define PIXEL12_0     *(dp+dpL+2) = w[5];
80 #define PIXEL12_30    *(dp+dpL+2) = Interp3_16(w[5], w[3]);
81 #define PIXEL12_31    *(dp+dpL+2) = Interp3_16(w[5], w[2]);
82 #define PIXEL12_32    *(dp+dpL+2) = Interp3_16(w[5], w[6]);
83 #define PIXEL12_70    *(dp+dpL+2) = Interp7_16(w[5], w[6], w[2]);
84 #define PIXEL13_0     *(dp+dpL+3) = w[5];
85 #define PIXEL13_10    *(dp+dpL+3) = Interp1_16(w[5], w[3]);
86 #define PIXEL13_12    *(dp+dpL+3) = Interp1_16(w[5], w[6]);
87 #define PIXEL13_14    *(dp+dpL+3) = Interp1_16(w[6], w[5]);
88 #define PIXEL13_21    *(dp+dpL+3) = Interp2_16(w[6], w[5], w[2]);
89 #define PIXEL13_31    *(dp+dpL+3) = Interp3_16(w[5], w[2]);
90 #define PIXEL13_50    *(dp+dpL+3) = Interp5_16(w[6], w[5]);
91 #define PIXEL13_60    *(dp+dpL+3) = Interp6_16(w[5], w[6], w[2]);
92 #define PIXEL13_61    *(dp+dpL+3) = Interp6_16(w[5], w[6], w[3]);
93 #define PIXEL13_82    *(dp+dpL+3) = Interp8_16(w[5], w[6]);
94 #define PIXEL13_83    *(dp+dpL+3) = Interp8_16(w[6], w[2]);
95 #define PIXEL20_0     *(dp+dpL+dpL) = w[5];
96 #define PIXEL20_10    *(dp+dpL+dpL) = Interp1_16(w[5], w[7]);
97 #define PIXEL20_12    *(dp+dpL+dpL) = Interp1_16(w[5], w[4]);
98 #define PIXEL20_14    *(dp+dpL+dpL) = Interp1_16(w[4], w[5]);
99 #define PIXEL20_21    *(dp+dpL+dpL) = Interp2_16(w[4], w[5], w[8]);
100 #define PIXEL20_31    *(dp+dpL+dpL) = Interp3_16(w[5], w[8]);
101 #define PIXEL20_50    *(dp+dpL+dpL) = Interp5_16(w[4], w[5]);
102 #define PIXEL20_60    *(dp+dpL+dpL) = Interp6_16(w[5], w[4], w[8]);
103 #define PIXEL20_61    *(dp+dpL+dpL) = Interp6_16(w[5], w[4], w[7]);
104 #define PIXEL20_82    *(dp+dpL+dpL) = Interp8_16(w[5], w[4]);
105 #define PIXEL20_83    *(dp+dpL+dpL) = Interp8_16(w[4], w[8]);
106 #define PIXEL21_0     *(dp+dpL+dpL+1) = w[5];
107 #define PIXEL21_30    *(dp+dpL+dpL+1) = Interp3_16(w[5], w[7]);
108 #define PIXEL21_31    *(dp+dpL+dpL+1) = Interp3_16(w[5], w[8]);
109 #define PIXEL21_32    *(dp+dpL+dpL+1) = Interp3_16(w[5], w[4]);
110 #define PIXEL21_70    *(dp+dpL+dpL+1) = Interp7_16(w[5], w[4], w[8]);
111 #define PIXEL22_0     *(dp+dpL+dpL+2) = w[5];
112 #define PIXEL22_30    *(dp+dpL+dpL+2) = Interp3_16(w[5], w[9]);
113 #define PIXEL22_31    *(dp+dpL+dpL+2) = Interp3_16(w[5], w[6]);
114 #define PIXEL22_32    *(dp+dpL+dpL+2) = Interp3_16(w[5], w[8]);
115 #define PIXEL22_70    *(dp+dpL+dpL+2) = Interp7_16(w[5], w[6], w[8]);
116 #define PIXEL23_0     *(dp+dpL+dpL+3) = w[5];
117 #define PIXEL23_10    *(dp+dpL+dpL+3) = Interp1_16(w[5], w[9]);
118 #define PIXEL23_11    *(dp+dpL+dpL+3) = Interp1_16(w[5], w[6]);
119 #define PIXEL23_13    *(dp+dpL+dpL+3) = Interp1_16(w[6], w[5]);
120 #define PIXEL23_21    *(dp+dpL+dpL+3) = Interp2_16(w[6], w[5], w[8]);
121 #define PIXEL23_32    *(dp+dpL+dpL+3) = Interp3_16(w[5], w[8]);
122 #define PIXEL23_50    *(dp+dpL+dpL+3) = Interp5_16(w[6], w[5]);
123 #define PIXEL23_60    *(dp+dpL+dpL+3) = Interp6_16(w[5], w[6], w[8]);
124 #define PIXEL23_61    *(dp+dpL+dpL+3) = Interp6_16(w[5], w[6], w[9]);
125 #define PIXEL23_81    *(dp+dpL+dpL+3) = Interp8_16(w[5], w[6]);
126 #define PIXEL23_83    *(dp+dpL+dpL+3) = Interp8_16(w[6], w[8]);
127 #define PIXEL30_0     *(dp+dpL+dpL+dpL) = w[5];
128 #define PIXEL30_11    *(dp+dpL+dpL+dpL) = Interp1_16(w[5], w[8]);
129 #define PIXEL30_12    *(dp+dpL+dpL+dpL) = Interp1_16(w[5], w[4]);
130 #define PIXEL30_20    *(dp+dpL+dpL+dpL) = Interp2_16(w[5], w[8], w[4]);
131 #define PIXEL30_50    *(dp+dpL+dpL+dpL) = Interp5_16(w[8], w[4]);
132 #define PIXEL30_80    *(dp+dpL+dpL+dpL) = Interp8_16(w[5], w[7]);
133 #define PIXEL30_81    *(dp+dpL+dpL+dpL) = Interp8_16(w[5], w[8]);
134 #define PIXEL30_82    *(dp+dpL+dpL+dpL) = Interp8_16(w[5], w[4]);
135 #define PIXEL31_0     *(dp+dpL+dpL+dpL+1) = w[5];
136 #define PIXEL31_10    *(dp+dpL+dpL+dpL+1) = Interp1_16(w[5], w[7]);
137 #define PIXEL31_11    *(dp+dpL+dpL+dpL+1) = Interp1_16(w[5], w[8]);
138 #define PIXEL31_13    *(dp+dpL+dpL+dpL+1) = Interp1_16(w[8], w[5]);
139 #define PIXEL31_21    *(dp+dpL+dpL+dpL+1) = Interp2_16(w[8], w[5], w[4]);
140 #define PIXEL31_32    *(dp+dpL+dpL+dpL+1) = Interp3_16(w[5], w[4]);
141 #define PIXEL31_50    *(dp+dpL+dpL+dpL+1) = Interp5_16(w[8], w[5]);
142 #define PIXEL31_60    *(dp+dpL+dpL+dpL+1) = Interp6_16(w[5], w[8], w[4]);
143 #define PIXEL31_61    *(dp+dpL+dpL+dpL+1) = Interp6_16(w[5], w[8], w[7]);
144 #define PIXEL31_81    *(dp+dpL+dpL+dpL+1) = Interp8_16(w[5], w[8]);
145 #define PIXEL31_83    *(dp+dpL+dpL+dpL+1) = Interp8_16(w[8], w[4]);
146 #define PIXEL32_0     *(dp+dpL+dpL+dpL+2) = w[5];
147 #define PIXEL32_10    *(dp+dpL+dpL+dpL+2) = Interp1_16(w[5], w[9]);
148 #define PIXEL32_12    *(dp+dpL+dpL+dpL+2) = Interp1_16(w[5], w[8]);
149 #define PIXEL32_14    *(dp+dpL+dpL+dpL+2) = Interp1_16(w[8], w[5]);
150 #define PIXEL32_21    *(dp+dpL+dpL+dpL+2) = Interp2_16(w[8], w[5], w[6]);
151 #define PIXEL32_31    *(dp+dpL+dpL+dpL+2) = Interp3_16(w[5], w[6]);
152 #define PIXEL32_50    *(dp+dpL+dpL+dpL+2) = Interp5_16(w[8], w[5]);
153 #define PIXEL32_60    *(dp+dpL+dpL+dpL+2) = Interp6_16(w[5], w[8], w[6]);
154 #define PIXEL32_61    *(dp+dpL+dpL+dpL+2) = Interp6_16(w[5], w[8], w[9]);
155 #define PIXEL32_82    *(dp+dpL+dpL+dpL+2) = Interp8_16(w[5], w[8]);
156 #define PIXEL32_83    *(dp+dpL+dpL+dpL+2) = Interp8_16(w[8], w[6]);
157 #define PIXEL33_0     *(dp+dpL+dpL+dpL+3) = w[5];
158 #define PIXEL33_11    *(dp+dpL+dpL+dpL+3) = Interp1_16(w[5], w[6]);
159 #define PIXEL33_12    *(dp+dpL+dpL+dpL+3) = Interp1_16(w[5], w[8]);
160 #define PIXEL33_20    *(dp+dpL+dpL+dpL+3) = Interp2_16(w[5], w[8], w[6]);
161 #define PIXEL33_50    *(dp+dpL+dpL+dpL+3) = Interp5_16(w[8], w[6]);
162 #define PIXEL33_80    *(dp+dpL+dpL+dpL+3) = Interp8_16(w[5], w[9]);
163 #define PIXEL33_81    *(dp+dpL+dpL+dpL+3) = Interp8_16(w[5], w[6]);
164 #define PIXEL33_82    *(dp+dpL+dpL+dpL+3) = Interp8_16(w[5], w[8]);
165 
166 #define HQ4X_BITS 16
167 #define HQ4X_BYTES 2
168 #define HQ4X_TYPE uint16_t
169 #define HQ4X_CPY(to, from) (to) = (from)
170 
171 #define HQ4X_FUNC hq4x_16
172 #define HQ4X_RB_FUNC hq4x_16_rb
173 
174 #define RGB_TO_YUV_FUNC rgb16_to_yuv
175 #define DIFF_FUNC Diff16
176 
177 #include "hq4x-int.h"
178