2 * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3 * Copyright (c) 2002-2007, Professor Benoit Macq
4 * Copyright (c) 2001-2003, David Janssens
5 * Copyright (c) 2002-2003, Yannick Verschueren
6 * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
7 * Copyright (c) 2005, Herve Drolon, FreeImage Team
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 #include <xmmintrin.h>
36 #include "opj_includes.h"
39 /* This table contains the norms of the basis function of the reversible MCT. */
41 static const double mct_norms[3] = { 1.732, .8292, .8292 };
44 /* This table contains the norms of the basis function of the irreversible MCT. */
46 static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
48 const OPJ_FLOAT64 * get_mct_norms ()
53 const OPJ_FLOAT64 * get_mct_norms_real ()
55 return mct_norms_real;
59 /* Foward reversible MCT. */
68 for(i = 0; i < n; ++i) {
72 int y = (r + (g * 2) + b) >> 2;
82 /* Inverse reversible MCT. */
91 for (i = 0; i < n; ++i) {
95 int g = y - ((u + v) >> 2);
105 /* Get norm of basis function of reversible MCT. */
107 double mct_getnorm(int compno) {
108 return mct_norms[compno];
112 /* Foward irreversible MCT. */
114 void mct_encode_real(
121 for(i = 0; i < n; ++i) {
125 int y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
126 int u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
127 int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
135 /* Inverse irreversible MCT. */
137 void mct_decode_real(
145 __m128 vrv, vgu, vgv, vbu;
146 vrv = _mm_set1_ps(1.402f);
147 vgu = _mm_set1_ps(0.34413f);
148 vgv = _mm_set1_ps(0.71414f);
149 vbu = _mm_set1_ps(1.772f);
150 for (i = 0; i < (n >> 3); ++i) {
154 vy = _mm_load_ps(c0);
155 vu = _mm_load_ps(c1);
156 vv = _mm_load_ps(c2);
157 vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
158 vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
159 vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
160 _mm_store_ps(c0, vr);
161 _mm_store_ps(c1, vg);
162 _mm_store_ps(c2, vb);
167 vy = _mm_load_ps(c0);
168 vu = _mm_load_ps(c1);
169 vv = _mm_load_ps(c2);
170 vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
171 vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
172 vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
173 _mm_store_ps(c0, vr);
174 _mm_store_ps(c1, vg);
175 _mm_store_ps(c2, vb);
182 for(i = 0; i < n; ++i) {
186 float r = y + (v * 1.402f);
187 float g = y - (u * 0.34413f) - (v * (0.71414f));
188 float b = y + (u * 1.772f);
196 /* Get norm of basis function of irreversible MCT. */
198 double mct_getnorm_real(int compno) {
199 return mct_norms_real[compno];
203 opj_bool mct_encode_custom(
205 OPJ_BYTE * pCodingdata,
206 // size of components
210 // nb of components (i.e. size of pData)
212 // tells if the data is signed
215 OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
219 OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp;
220 OPJ_INT32 * lCurrentData = 00;
221 OPJ_INT32 * lCurrentMatrix = 00;
222 OPJ_INT32 ** lData = (OPJ_INT32 **) pData;
223 OPJ_UINT32 lMultiplicator = 1 << 13;
226 lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
227 if (! lCurrentData) {
231 lCurrentMatrix = lCurrentData + pNbComp;
233 for (i =0;i<lNbMatCoeff;++i) {
234 lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * lMultiplicator);
237 for (i = 0; i < n; ++i) {
238 lMctPtr = lCurrentMatrix;
239 for (j=0;j<pNbComp;++j) {
240 lCurrentData[j] = (*(lData[j]));
243 for (j=0;j<pNbComp;++j) {
245 for (k=0;k<pNbComp;++k) {
246 *(lData[j]) += fix_mul(*lMctPtr, lCurrentData[k]);
254 opj_free(lCurrentData);
259 opj_bool mct_decode_custom(
261 OPJ_BYTE * pDecodingData,
262 /* size of components */
266 /* nb of components (i.e. size of pData) */
268 /* tells if the data is signed */
276 OPJ_FLOAT32 * lCurrentData = 00;
277 OPJ_FLOAT32 * lCurrentResult = 00;
278 OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
280 lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
286 lCurrentResult = lCurrentData + pNbComp;
291 lMct = (OPJ_FLOAT32 *) pDecodingData;
295 lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
300 lCurrentResult[j] = 0;
304 lCurrentResult[j] += *(lMct++) * lCurrentData[k];
306 *(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
309 opj_free(lCurrentData);
313 void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
315 OPJ_FLOAT32 * pMatrix)
317 OPJ_UINT32 i,j,lIndex;
318 OPJ_FLOAT32 lCurrentValue;
319 OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
320 OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
322 for (i=0;i<pNbComps;++i) {
326 for (j=0;j<pNbComps;++j) {
327 lCurrentValue = lMatrix[lIndex];
329 lNorms[i] += lCurrentValue * lCurrentValue;
331 lNorms[i] = sqrt(lNorms[i]);