...
1
2
3
4
5 package jpeg
6
7
8
9
61
62
63 const (
64 fix_0_298631336 = 2446
65 fix_0_390180644 = 3196
66 fix_0_541196100 = 4433
67 fix_0_765366865 = 6270
68 fix_0_899976223 = 7373
69 fix_1_175875602 = 9633
70 fix_1_501321110 = 12299
71 fix_1_847759065 = 15137
72 fix_1_961570560 = 16069
73 fix_2_053119869 = 16819
74 fix_2_562915447 = 20995
75 fix_3_072711026 = 25172
76 )
77
78 const (
79 constBits = 13
80 pass1Bits = 2
81 centerJSample = 128
82 )
83
84
85
86 func fdct(b *block) {
87
88 for y := 0; y < 8; y++ {
89 x0 := b[y*8+0]
90 x1 := b[y*8+1]
91 x2 := b[y*8+2]
92 x3 := b[y*8+3]
93 x4 := b[y*8+4]
94 x5 := b[y*8+5]
95 x6 := b[y*8+6]
96 x7 := b[y*8+7]
97
98 tmp0 := x0 + x7
99 tmp1 := x1 + x6
100 tmp2 := x2 + x5
101 tmp3 := x3 + x4
102
103 tmp10 := tmp0 + tmp3
104 tmp12 := tmp0 - tmp3
105 tmp11 := tmp1 + tmp2
106 tmp13 := tmp1 - tmp2
107
108 tmp0 = x0 - x7
109 tmp1 = x1 - x6
110 tmp2 = x2 - x5
111 tmp3 = x3 - x4
112
113 b[y*8+0] = (tmp10 + tmp11 - 8*centerJSample) << pass1Bits
114 b[y*8+4] = (tmp10 - tmp11) << pass1Bits
115 z1 := (tmp12 + tmp13) * fix_0_541196100
116 z1 += 1 << (constBits - pass1Bits - 1)
117 b[y*8+2] = (z1 + tmp12*fix_0_765366865) >> (constBits - pass1Bits)
118 b[y*8+6] = (z1 - tmp13*fix_1_847759065) >> (constBits - pass1Bits)
119
120 tmp10 = tmp0 + tmp3
121 tmp11 = tmp1 + tmp2
122 tmp12 = tmp0 + tmp2
123 tmp13 = tmp1 + tmp3
124 z1 = (tmp12 + tmp13) * fix_1_175875602
125 z1 += 1 << (constBits - pass1Bits - 1)
126 tmp0 = tmp0 * fix_1_501321110
127 tmp1 = tmp1 * fix_3_072711026
128 tmp2 = tmp2 * fix_2_053119869
129 tmp3 = tmp3 * fix_0_298631336
130 tmp10 = tmp10 * -fix_0_899976223
131 tmp11 = tmp11 * -fix_2_562915447
132 tmp12 = tmp12 * -fix_0_390180644
133 tmp13 = tmp13 * -fix_1_961570560
134
135 tmp12 += z1
136 tmp13 += z1
137 b[y*8+1] = (tmp0 + tmp10 + tmp12) >> (constBits - pass1Bits)
138 b[y*8+3] = (tmp1 + tmp11 + tmp13) >> (constBits - pass1Bits)
139 b[y*8+5] = (tmp2 + tmp11 + tmp12) >> (constBits - pass1Bits)
140 b[y*8+7] = (tmp3 + tmp10 + tmp13) >> (constBits - pass1Bits)
141 }
142
143
144 for x := 0; x < 8; x++ {
145 tmp0 := b[0*8+x] + b[7*8+x]
146 tmp1 := b[1*8+x] + b[6*8+x]
147 tmp2 := b[2*8+x] + b[5*8+x]
148 tmp3 := b[3*8+x] + b[4*8+x]
149
150 tmp10 := tmp0 + tmp3 + 1<<(pass1Bits-1)
151 tmp12 := tmp0 - tmp3
152 tmp11 := tmp1 + tmp2
153 tmp13 := tmp1 - tmp2
154
155 tmp0 = b[0*8+x] - b[7*8+x]
156 tmp1 = b[1*8+x] - b[6*8+x]
157 tmp2 = b[2*8+x] - b[5*8+x]
158 tmp3 = b[3*8+x] - b[4*8+x]
159
160 b[0*8+x] = (tmp10 + tmp11) >> pass1Bits
161 b[4*8+x] = (tmp10 - tmp11) >> pass1Bits
162
163 z1 := (tmp12 + tmp13) * fix_0_541196100
164 z1 += 1 << (constBits + pass1Bits - 1)
165 b[2*8+x] = (z1 + tmp12*fix_0_765366865) >> (constBits + pass1Bits)
166 b[6*8+x] = (z1 - tmp13*fix_1_847759065) >> (constBits + pass1Bits)
167
168 tmp10 = tmp0 + tmp3
169 tmp11 = tmp1 + tmp2
170 tmp12 = tmp0 + tmp2
171 tmp13 = tmp1 + tmp3
172 z1 = (tmp12 + tmp13) * fix_1_175875602
173 z1 += 1 << (constBits + pass1Bits - 1)
174 tmp0 = tmp0 * fix_1_501321110
175 tmp1 = tmp1 * fix_3_072711026
176 tmp2 = tmp2 * fix_2_053119869
177 tmp3 = tmp3 * fix_0_298631336
178 tmp10 = tmp10 * -fix_0_899976223
179 tmp11 = tmp11 * -fix_2_562915447
180 tmp12 = tmp12 * -fix_0_390180644
181 tmp13 = tmp13 * -fix_1_961570560
182
183 tmp12 += z1
184 tmp13 += z1
185 b[1*8+x] = (tmp0 + tmp10 + tmp12) >> (constBits + pass1Bits)
186 b[3*8+x] = (tmp1 + tmp11 + tmp13) >> (constBits + pass1Bits)
187 b[5*8+x] = (tmp2 + tmp11 + tmp12) >> (constBits + pass1Bits)
188 b[7*8+x] = (tmp3 + tmp10 + tmp13) >> (constBits + pass1Bits)
189 }
190 }
191
View as plain text