| OLD | NEW |
| 1 /* | 1 /* |
| 2 * The copyright in this software is being made available under the 2-clauses | 2 * The copyright in this software is being made available under the 2-clauses |
| 3 * BSD License, included below. This software may be subject to other third | 3 * BSD License, included below. This software may be subject to other third |
| 4 * party and contributor rights, including patent rights, and no such rights | 4 * party and contributor rights, including patent rights, and no such rights |
| 5 * are granted under this license. | 5 * are granted under this license. |
| 6 * | 6 * |
| 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium | 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium |
| 8 * Copyright (c) 2002-2014, Professor Benoit Macq | 8 * Copyright (c) 2002-2014, Professor Benoit Macq |
| 9 * Copyright (c) 2001-2003, David Janssens | 9 * Copyright (c) 2001-2003, David Janssens |
| 10 * Copyright (c) 2002-2003, Yannick Verschueren | 10 * Copyright (c) 2002-2003, Yannick Verschueren |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 /** | 118 /** |
| 119 Explicit calculation of the Quantization Stepsizes | 119 Explicit calculation of the Quantization Stepsizes |
| 120 */ | 120 */ |
| 121 static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
epsize_t *bandno_stepsize); | 121 static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
epsize_t *bandno_stepsize); |
| 122 /** | 122 /** |
| 123 Inverse wavelet transform in 2-D. | 123 Inverse wavelet transform in 2-D. |
| 124 */ | 124 */ |
| 125 static OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32
i, DWT1DFN fn); | 125 static OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32
i, DWT1DFN fn); |
| 126 | 126 |
| 127 static OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tilec, | 127 static OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tilec, |
| 128 » » » » » » » » » »
void (*p_function)(OPJ_INT32 *, OPJ_SIZE_T,OPJ_INT32,OPJ_INT32,OPJ_INT32) ); | 128 » » » » » » » » » »
void(*p_function)(OPJ_INT32 *, OPJ_SIZE_T, OPJ_INT32, OPJ_INT32, OPJ_INT32))
; |
| 129 | 129 |
| 130 static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
INT32 i); | 130 static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
INT32 i); |
| 131 | 131 |
| 132 /* <summary> */ | 132 /* <summary> */ |
| 133 /* Inverse 9-7 wavelet transform in 1-D. */ | 133 /* Inverse 9-7 wavelet transform in 1-D. */ |
| 134 /* </summary> */ | 134 /* </summary> */ |
| 135 static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt); | 135 static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt); |
| 136 | 136 |
| 137 static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
t a, OPJ_INT32 x, OPJ_INT32 size); | 137 static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
t a, OPJ_INT32 x, OPJ_INT32 size); |
| 138 | 138 |
| 139 static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
ct a , OPJ_INT32 x, OPJ_INT32 nb_elts_read); | 139 static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
ct a , OPJ_INT32 x, OPJ_INT32 nb_elts_read); |
| 140 | 140 |
| 141 #ifdef __SSE__ | 141 #ifdef __SSE__ |
| 142 static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
8 c); | 142 static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
8 c); |
| 143 | 143 |
| 144 static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OP
J_INT32 m, __m128 c); | 144 static void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OP
J_INT32 m, __m128 c); |
| 145 | 145 |
| 146 #else | 146 #else |
| 147 static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT
32 c); | 147 static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT
32 c); |
| 148 | 148 |
| 149 static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
T32 m, OPJ_FLOAT32 c); | 149 static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
T32 m, OPJ_FLOAT32 c); |
| 150 | 150 |
| 151 #endif | 151 #endif |
| 152 | 152 |
| 153 /*@}*/ | 153 /*@}*/ |
| 154 | 154 |
| 155 /*@}*/ | 155 /*@}*/ |
| 156 | 156 |
| 157 #define IDX_S(i) (i)*2 | 157 #define IDX_S(i) (i)*2 |
| 158 #define IDX_D(i) 1+(i)*2 | 158 #define IDX_D(i) 1 + (i)* 2 |
| 159 #define UNDERFLOW_SN(i) ((i)>=sn&&sn>0) | 159 #define UNDERFLOW_SN(i) ((i) >= sn&&sn>0) |
| 160 #define UNDERFLOW_DN(i) ((i)>=dn&&dn>0) | 160 #define UNDERFLOW_DN(i) ((i) >= dn&&dn>0) |
| 161 #define OVERFLOW_S(i) (IDX_S(i)>=a_count) | 161 #define OVERFLOW_S(i) (IDX_S(i) >= a_count) |
| 162 #define OVERFLOW_D(i) (IDX_D(i)>=a_count) | 162 #define OVERFLOW_D(i) (IDX_D(i) >= a_count) |
| 163 | 163 |
| 164 #define OPJ_S(i) a[IDX_S(i)] | 164 #define OPJ_S(i) a[IDX_S(i)] |
| 165 #define OPJ_D(i) a[IDX_D(i)] | 165 #define OPJ_D(i) a[IDX_D(i)] |
| 166 #define OPJ_S_(i) ((i)<0?OPJ_S(0):(UNDERFLOW_SN(i)?OPJ_S(sn-1):OVERFLOW_S(i)?OPJ
_S(i-1):OPJ_S(i))) | 166 #define OPJ_S_(i) ((i)<0 ? OPJ_S(0) : (UNDERFLOW_SN(i) ? OPJ_S(sn - 1) : OVERFLO
W_S(i) ? OPJ_S(i - 1) : OPJ_S(i))) |
| 167 #define OPJ_D_(i) ((i)<0?OPJ_D(0):(UNDERFLOW_DN(i)?OPJ_D(dn-1):OVERFLOW_D(i)?OPJ
_D(i-1):OPJ_D(i))) | 167 #define OPJ_D_(i) ((i)<0 ? OPJ_D(0) : (UNDERFLOW_DN(i) ? OPJ_D(dn - 1) : OVERFLO
W_D(i) ? OPJ_D(i - 1) : OPJ_D(i))) |
| 168 /* new */ | 168 /* new */ |
| 169 #define OPJ_SS_(i) ((i)<0?OPJ_S(0):(UNDERFLOW_DN(i)?OPJ_S(dn-1):OVERFLOW_S(i)?OP
J_S(i-1):OPJ_S(i))) | 169 #define OPJ_SS_(i) ((i)<0 ? OPJ_S(0) : (UNDERFLOW_DN(i) ? OPJ_S(dn - 1) : OVERFL
OW_S(i) ? OPJ_S(i - 1) : OPJ_S(i))) |
| 170 #define OPJ_DD_(i) ((i)<0?OPJ_D(0):(UNDERFLOW_SN(i)?OPJ_D(sn-1):OVERFLOW_D(i)?OP
J_D(i-1):OPJ_D(i))) | 170 #define OPJ_DD_(i) ((i)<0 ? OPJ_D(0) : (UNDERFLOW_SN(i) ? OPJ_D(sn - 1) : OVERFL
OW_D(i) ? OPJ_D(i - 1) : OPJ_D(i))) |
| 171 | 171 |
| 172 /* <summary> */ | 172 /* <summary> */ |
| 173 /* This table contains the norms of the 5-3 wavelets for different bands. */ | 173 /* This table contains the norms of the 5-3 wavelets for different bands. */ |
| 174 /* </summary> */ | 174 /* </summary> */ |
| 175 static const OPJ_FLOAT64 opj_dwt_norms[4][10] = { | 175 static const OPJ_FLOAT64 opj_dwt_norms[4][10] = { |
| 176 {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, | 176 {1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3}, |
| 177 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, | 177 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, |
| 178 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, | 178 {1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9}, |
| 179 {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93} | 179 {.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93} |
| 180 }; | 180 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 191 | 191 |
| 192 /* | 192 /* |
| 193 ========================================================== | 193 ========================================================== |
| 194 local functions | 194 local functions |
| 195 ========================================================== | 195 ========================================================== |
| 196 */ | 196 */ |
| 197 | 197 |
| 198 /* <summary> */ | 198 /* <summary> */ |
| 199 /* Forward lazy transform (horizontal). */ | 199 /* Forward lazy transform (horizontal). */ |
| 200 /* </summary> */ | 200 /* </summary> */ |
| 201 void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32
sn, OPJ_INT32 cas) { | 201 static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
_INT32 sn, OPJ_INT32 cas) { |
| 202 OPJ_INT32 i; | 202 OPJ_INT32 i; |
| 203 OPJ_INT32 * l_dest = b; | 203 OPJ_INT32 * l_dest = b; |
| 204 OPJ_INT32 * l_src = a+cas; | 204 OPJ_INT32 * l_src = a+cas; |
| 205 | 205 |
| 206 for (i=0; i<sn; ++i) { | 206 for (i=0; i<sn; ++i) { |
| 207 *l_dest++ = *l_src; | 207 *l_dest++ = *l_src; |
| 208 l_src += 2; | 208 l_src += 2; |
| 209 } | 209 } |
| 210 | 210 |
| 211 l_dest = b + sn; | 211 l_dest = b + sn; |
| 212 l_src = a + 1 - cas; | 212 l_src = a + 1 - cas; |
| 213 | 213 |
| 214 for (i=0; i<dn; ++i) { | 214 for (i=0; i<dn; ++i) { |
| 215 *l_dest++=*l_src; | 215 *l_dest++=*l_src; |
| 216 l_src += 2; | 216 l_src += 2; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 /* <summary> */ | 220 /* <summary> */ |
| 221 /* Forward lazy transform (vertical). */ | 221 /* Forward lazy transform (vertical). */ |
| 222 /* </summary> */ | 222 /* </summary> */ |
| 223 void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32
sn, OPJ_INT32 x, OPJ_INT32 cas) { | 223 static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) { |
| 224 OPJ_INT32 i = sn; | 224 OPJ_INT32 i = sn; |
| 225 OPJ_INT32 * l_dest = b; | 225 OPJ_INT32 * l_dest = b; |
| 226 OPJ_INT32 * l_src = a+cas; | 226 OPJ_INT32 * l_src = a+cas; |
| 227 | 227 |
| 228 while (i--) { | 228 while (i--) { |
| 229 *l_dest = *l_src; | 229 *l_dest = *l_src; |
| 230 l_dest += x; | 230 l_dest += x; |
| 231 l_src += 2; | 231 l_src += 2; |
| 232 } /* b[i*x]=a[2*i+cas]; */ | 232 } /* b[i*x]=a[2*i+cas]; */ |
| 233 | 233 |
| 234 l_dest = b + sn * x; | 234 l_dest = b + sn * x; |
| 235 l_src = a + 1 - cas; | 235 l_src = a + 1 - cas; |
| 236 | 236 |
| 237 i = dn; | 237 i = dn; |
| 238 while (i--) { | 238 while (i--) { |
| 239 *l_dest = *l_src; | 239 *l_dest = *l_src; |
| 240 l_dest += x; | 240 l_dest += x; |
| 241 l_src += 2; | 241 l_src += 2; |
| 242 } /*b[(sn+i)*x]=a[(2*i+1-cas)];*/ | 242 } /*b[(sn+i)*x]=a[(2*i+1-cas)];*/ |
| 243 } | 243 } |
| 244 | 244 |
| 245 /* <summary> */ | 245 /* <summary> */ |
| 246 /* Inverse lazy transform (horizontal). */ | 246 /* Inverse lazy transform (horizontal). */ |
| 247 /* </summary> */ | 247 /* </summary> */ |
| 248 void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { | 248 static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { |
| 249 OPJ_INT32 *ai = a; | 249 OPJ_INT32 *ai = a; |
| 250 OPJ_INT32 *bi = h->mem + h->cas; | 250 OPJ_INT32 *bi = h->mem + h->cas; |
| 251 OPJ_INT32 i = h->sn; | 251 OPJ_INT32 i = h->sn; |
| 252 while( i-- ) { | 252 while( i-- ) { |
| 253 *bi = *(ai++); | 253 *bi = *(ai++); |
| 254 bi += 2; | 254 bi += 2; |
| 255 } | 255 } |
| 256 ai = a + h->sn; | 256 ai = a + h->sn; |
| 257 bi = h->mem + 1 - h->cas; | 257 bi = h->mem + 1 - h->cas; |
| 258 i = h->dn ; | 258 i = h->dn ; |
| 259 while( i-- ) { | 259 while( i-- ) { |
| 260 *bi = *(ai++); | 260 *bi = *(ai++); |
| 261 bi += 2; | 261 bi += 2; |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 /* <summary> */ | 265 /* <summary> */ |
| 266 /* Inverse lazy transform (vertical). */ | 266 /* Inverse lazy transform (vertical). */ |
| 267 /* </summary> */ | 267 /* </summary> */ |
| 268 void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { | 268 static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { |
| 269 OPJ_INT32 *ai = a; | 269 OPJ_INT32 *ai = a; |
| 270 OPJ_INT32 *bi = v->mem + v->cas; | 270 OPJ_INT32 *bi = v->mem + v->cas; |
| 271 OPJ_INT32 i = v->sn; | 271 OPJ_INT32 i = v->sn; |
| 272 while( i-- ) { | 272 while( i-- ) { |
| 273 *bi = *ai; | 273 *bi = *ai; |
| 274 bi += 2; | 274 bi += 2; |
| 275 ai += x; | 275 ai += x; |
| 276 } | 276 } |
| 277 ai = a + (v->sn * x); | 277 ai = a + (v->sn * x); |
| 278 bi = v->mem + 1 - v->cas; | 278 bi = v->mem + 1 - v->cas; |
| 279 i = v->dn ; | 279 i = v->dn ; |
| 280 while( i-- ) { | 280 while( i-- ) { |
| 281 *bi = *ai; | 281 *bi = *ai; |
| 282 bi += 2; | 282 bi += 2; |
| 283 ai += x; | 283 ai += x; |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 | 287 |
| 288 /* <summary> */ | 288 /* <summary> */ |
| 289 /* Forward 5-3 wavelet transform in 1-D. */ | 289 /* Forward 5-3 wavelet transform in 1-D. */ |
| 290 /* </summary> */ | 290 /* </summary> */ |
| 291 void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OPJ_INT32
sn, OPJ_INT32 cas) { | 291 static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OPJ
_INT32 sn, OPJ_INT32 cas) { |
| 292 OPJ_INT32 i; | 292 OPJ_INT32 i; |
| 293 | 293 |
| 294 if (!cas) { | 294 if (!cas) { |
| 295 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | 295 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ |
| 296 for (i = 0; i < dn; i++) OPJ_D(i) -= (OPJ_S_(i) + OPJ_S_
(i + 1)) >> 1; | 296 for (i = 0; i < dn; i++) OPJ_D(i) -= (OPJ_S_(i) + OPJ_S_
(i + 1)) >> 1; |
| 297 for (i = 0; i < sn; i++) OPJ_S(i) += (OPJ_D_(i - 1) + OP
J_D_(i) + 2) >> 2; | 297 for (i = 0; i < sn; i++) OPJ_S(i) += (OPJ_D_(i - 1) + OP
J_D_(i) + 2) >> 2; |
| 298 } | 298 } |
| 299 } else { | 299 } else { |
| 300 if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT *
/ | 300 if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT *
/ |
| 301 OPJ_S(0) *= 2; | 301 OPJ_S(0) *= 2; |
| 302 else { | 302 else { |
| 303 for (i = 0; i < dn; i++) OPJ_S(i) -= (OPJ_DD_(i) + OPJ_D
D_(i - 1)) >> 1; | 303 for (i = 0; i < dn; i++) OPJ_S(i) -= (OPJ_DD_(i) + OPJ_D
D_(i - 1)) >> 1; |
| 304 for (i = 0; i < sn; i++) OPJ_D(i) += (OPJ_SS_(i) + OPJ_S
S_(i + 1) + 2) >> 2; | 304 for (i = 0; i < sn; i++) OPJ_D(i) += (OPJ_SS_(i) + OPJ_S
S_(i + 1) + 2) >> 2; |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 /* <summary> */ | 309 /* <summary> */ |
| 310 /* Inverse 5-3 wavelet transform in 1-D. */ | 310 /* Inverse 5-3 wavelet transform in 1-D. */ |
| 311 /* </summary> */ | 311 /* </summary> */ |
| 312 void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OPJ_INT32
sn, OPJ_INT32 cas) { | 312 static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OP
J_INT32 sn, OPJ_INT32 cas) { |
| 313 OPJ_INT32 i; | 313 OPJ_INT32 i; |
| 314 | 314 |
| 315 if (!cas) { | 315 if (!cas) { |
| 316 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | 316 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ |
| 317 for (i = 0; i < sn; i++) OPJ_S(i) -= (OPJ_D_(i - 1) + OP
J_D_(i) + 2) >> 2; | 317 for (i = 0; i < sn; i++) OPJ_S(i) -= (OPJ_D_(i - 1) + OP
J_D_(i) + 2) >> 2; |
| 318 for (i = 0; i < dn; i++) OPJ_D(i) += (OPJ_S_(i) + OPJ_S_
(i + 1)) >> 1; | 318 for (i = 0; i < dn; i++) OPJ_D(i) += (OPJ_S_(i) + OPJ_S_
(i + 1)) >> 1; |
| 319 } | 319 } |
| 320 } else { | 320 } else { |
| 321 if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ | 321 if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */ |
| 322 OPJ_S(0) /= 2; | 322 OPJ_S(0) /= 2; |
| 323 else { | 323 else { |
| 324 for (i = 0; i < sn; i++) OPJ_D(i) -= (OPJ_SS_(i) + OPJ_S
S_(i + 1) + 2) >> 2; | 324 for (i = 0; i < sn; i++) OPJ_D(i) -= (OPJ_SS_(i) + OPJ_S
S_(i + 1) + 2) >> 2; |
| 325 for (i = 0; i < dn; i++) OPJ_S(i) += (OPJ_DD_(i) + OPJ_D
D_(i - 1)) >> 1; | 325 for (i = 0; i < dn; i++) OPJ_S(i) += (OPJ_DD_(i) + OPJ_D
D_(i - 1)) >> 1; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 /* <summary> */ | 330 /* <summary> */ |
| 331 /* Inverse 5-3 wavelet transform in 1-D. */ | 331 /* Inverse 5-3 wavelet transform in 1-D. */ |
| 332 /* </summary> */ | 332 /* </summary> */ |
| 333 void opj_dwt_decode_1(opj_dwt_t *v) { | 333 static void opj_dwt_decode_1(opj_dwt_t *v) { |
| 334 opj_dwt_decode_1_(v->mem, v->mem_count, v->dn, v->sn, v->cas); | 334 opj_dwt_decode_1_(v->mem, v->mem_count, v->dn, v->sn, v->cas); |
| 335 } | 335 } |
| 336 | 336 |
| 337 /* <summary> */ | 337 /* <summary> */ |
| 338 /* Forward 9-7 wavelet transform in 1-D. */ | 338 /* Forward 9-7 wavelet transform in 1-D. */ |
| 339 /* </summary> */ | 339 /* </summary> */ |
| 340 void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn, OPJ_I
NT32 sn, OPJ_INT32 cas) { | 340 static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_SIZE_T a_count, OPJ_INT32 dn
, OPJ_INT32 sn, OPJ_INT32 cas) { |
| 341 OPJ_INT32 i; | 341 OPJ_INT32 i; |
| 342 if (!cas) { | 342 if (!cas) { |
| 343 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ | 343 if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ |
| 344 for (i = 0; i < dn; i++) | 344 for (i = 0; i < dn; i++) |
| 345 OPJ_D(i) -= opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i
+ 1), 12993); | 345 OPJ_D(i) -= opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i
+ 1), 12993); |
| 346 for (i = 0; i < sn; i++) | 346 for (i = 0; i < sn; i++) |
| 347 OPJ_S(i) -= opj_int_fix_mul(OPJ_D_(i - 1) + OPJ_
D_(i), 434); | 347 OPJ_S(i) -= opj_int_fix_mul(OPJ_D_(i - 1) + OPJ_
D_(i), 434); |
| 348 for (i = 0; i < dn; i++) | 348 for (i = 0; i < dn; i++) |
| 349 OPJ_D(i) += opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i
+ 1), 7233); | 349 OPJ_D(i) += opj_int_fix_mul(OPJ_S_(i) + OPJ_S_(i
+ 1), 7233); |
| 350 for (i = 0; i < sn; i++) | 350 for (i = 0; i < sn; i++) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 365 for (i = 0; i < sn; i++) | 365 for (i = 0; i < sn; i++) |
| 366 OPJ_D(i) += opj_int_fix_mul(OPJ_SS_(i) + OPJ_SS_
(i + 1), 3633); | 366 OPJ_D(i) += opj_int_fix_mul(OPJ_SS_(i) + OPJ_SS_
(i + 1), 3633); |
| 367 for (i = 0; i < dn; i++) | 367 for (i = 0; i < dn; i++) |
| 368 OPJ_S(i) = opj_int_fix_mul(OPJ_S(i), 5038);
/*5038 */ | 368 OPJ_S(i) = opj_int_fix_mul(OPJ_S(i), 5038);
/*5038 */ |
| 369 for (i = 0; i < sn; i++) | 369 for (i = 0; i < sn; i++) |
| 370 OPJ_D(i) = opj_int_fix_mul(OPJ_D(i), 6659);
/*6660 */ | 370 OPJ_D(i) = opj_int_fix_mul(OPJ_D(i), 6659);
/*6660 */ |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_
t *bandno_stepsize) { | 375 static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
epsize_t *bandno_stepsize) { |
| 376 OPJ_INT32 p, n; | 376 OPJ_INT32 p, n; |
| 377 p = opj_int_floorlog2(stepsize) - 13; | 377 p = opj_int_floorlog2(stepsize) - 13; |
| 378 n = 11 - opj_int_floorlog2(stepsize); | 378 n = 11 - opj_int_floorlog2(stepsize); |
| 379 bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff
; | 379 bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff
; |
| 380 bandno_stepsize->expn = numbps - p; | 380 bandno_stepsize->expn = numbps - p; |
| 381 } | 381 } |
| 382 | 382 |
| 383 /* | 383 /* |
| 384 ========================================================== | 384 ========================================================== |
| 385 DWT interface | 385 DWT interface |
| 386 ========================================================== | 386 ========================================================== |
| 387 */ | 387 */ |
| 388 | 388 |
| 389 | 389 |
| 390 /* <summary> */ | 390 /* <summary> */ |
| 391 /* Forward 5-3 wavelet transform in 2-D. */ | 391 /* Forward 5-3 wavelet transform in 2-D. */ |
| 392 /* </summary> */ | 392 /* </summary> */ |
| 393 INLINE OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tilec,void (
*p_function)(OPJ_INT32 *, OPJ_SIZE_T,OPJ_INT32,OPJ_INT32,OPJ_INT32) ) | 393 static INLINE OPJ_BOOL opj_dwt_encode_procedure(const opj_tcd_tilecomp_t * tilec
, void(*p_function)(OPJ_INT32 *, OPJ_SIZE_T, OPJ_INT32, OPJ_INT32, OPJ_INT32)) |
| 394 { | 394 { |
| 395 OPJ_INT32 i, j, k; | 395 OPJ_INT32 i, j, k; |
| 396 OPJ_INT32 *a = 00; | 396 OPJ_INT32 *a = 00; |
| 397 OPJ_INT32 *aj = 00; | 397 OPJ_INT32 *aj = 00; |
| 398 OPJ_INT32 *bj = 00; | 398 OPJ_INT32 *bj = 00; |
| 399 OPJ_INT32 w, l; | 399 OPJ_INT32 w, l; |
| 400 | 400 |
| 401 OPJ_INT32 rw; /* width of the resolution level compute
d */ | 401 OPJ_INT32 rw; /* width of the resolution level compute
d */ |
| 402 OPJ_INT32 rh; /* height of the resolution level comput
ed */ | 402 OPJ_INT32 rh; /* height of the resolution level comput
ed */ |
| 403 OPJ_SIZE_T l_data_count; | 403 OPJ_SIZE_T l_data_count; |
| 404 OPJ_SIZE_T l_data_size; | 404 OPJ_SIZE_T l_data_size; |
| 405 | 405 |
| 406 opj_tcd_resolution_t * l_cur_res = 0; | 406 opj_tcd_resolution_t * l_cur_res = 0; |
| 407 opj_tcd_resolution_t * l_last_res = 0; | 407 opj_tcd_resolution_t * l_last_res = 0; |
| 408 | 408 |
| 409 w = tilec->x1-tilec->x0; | 409 w = tilec->x1-tilec->x0; |
| 410 l = (OPJ_INT32)tilec->numresolutions-1; | 410 l = (OPJ_INT32)tilec->numresolutions-1; |
| 411 a = tilec->data; | 411 a = tilec->data; |
| 412 | 412 |
| 413 l_cur_res = tilec->resolutions + l; | 413 l_cur_res = tilec->resolutions + l; |
| 414 l_last_res = l_cur_res - 1; | 414 l_last_res = l_cur_res - 1; |
| 415 | 415 |
| 416 » l_data_count = opj_dwt_max_resolution( tilec->resolutions,tilec->numreso
lutions); | 416 » l_data_count = opj_dwt_max_resolution(tilec->resolutions, tilec->numreso
lutions) * (OPJ_UINT32)sizeof(OPJ_INT32); |
| 417 l_data_size = l_data_count * (OPJ_UINT32)sizeof(OPJ_INT32); | 417 l_data_size = l_data_count * (OPJ_UINT32)sizeof(OPJ_INT32); |
| 418 bj = (OPJ_INT32*)opj_malloc(l_data_size); | 418 bj = (OPJ_INT32*)opj_malloc(l_data_size); |
| 419 if (! bj) { | 419 if (! bj) { |
| 420 return OPJ_FALSE; | 420 return OPJ_FALSE; |
| 421 } | 421 } |
| 422 i = l; | 422 i = l; |
| 423 | 423 |
| 424 while (i--) { | 424 while (i--) { |
| 425 OPJ_INT32 rw1; /* width of the resolution level once lo
wer than computed one */ | 425 OPJ_INT32 rw1; /* width of the resolution level once lo
wer than computed one */ |
| 426 OPJ_INT32 rh1; /* height of the resolution level once l
ower than computed one */ | 426 OPJ_INT32 rh1; /* height of the resolution level once l
ower than computed one */ |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 OPJ_FLOAT64 norm = opj_dwt_norms_real[orient][level]; | 541 OPJ_FLOAT64 norm = opj_dwt_norms_real[orient][level]; |
| 542 stepsize = (1 << (gain)) / norm; | 542 stepsize = (1 << (gain)) / norm; |
| 543 } | 543 } |
| 544 opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), (O
PJ_INT32)(prec + gain), &tccp->stepsizes[bandno]); | 544 opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), (O
PJ_INT32)(prec + gain), &tccp->stepsizes[bandno]); |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 /* <summary> */ | 548 /* <summary> */ |
| 549 /* Determine maximum computed resolution level for inverse wavelet transform */ | 549 /* Determine maximum computed resolution level for inverse wavelet transform */ |
| 550 /* </summary> */ | 550 /* </summary> */ |
| 551 OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i
) { | 551 static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
INT32 i) { |
| 552 OPJ_UINT32 mr = 0; | 552 OPJ_UINT32 mr = 0; |
| 553 OPJ_UINT32 w; | 553 OPJ_UINT32 w; |
| 554 while( --i ) { | 554 while( --i ) { |
| 555 ++r; | 555 ++r; |
| 556 if( mr < ( w = (OPJ_UINT32)(r->x1 - r->x0) ) ) | 556 if( mr < ( w = (OPJ_UINT32)(r->x1 - r->x0) ) ) |
| 557 mr = w ; | 557 mr = w ; |
| 558 if( mr < ( w = (OPJ_UINT32)(r->y1 - r->y0) ) ) | 558 if( mr < ( w = (OPJ_UINT32)(r->y1 - r->y0) ) ) |
| 559 mr = w ; | 559 mr = w ; |
| 560 } | 560 } |
| 561 return mr ; | 561 return mr ; |
| 562 } | 562 } |
| 563 | 563 |
| 564 /* <summary> */ | 564 /* <summary> */ |
| 565 /* Inverse wavelet transform in 2-D. */ | 565 /* Inverse wavelet transform in 2-D. */ |
| 566 /* </summary> */ | 566 /* </summary> */ |
| 567 OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres,
DWT1DFN dwt_1D) { | 567 static OPJ_BOOL opj_dwt_decode_tile(const opj_tcd_tilecomp_t* tilec, OPJ_UINT32
numres, DWT1DFN dwt_1D) { |
| 568 opj_dwt_t h; | 568 opj_dwt_t h; |
| 569 opj_dwt_t v; | 569 opj_dwt_t v; |
| 570 | 570 |
| 571 opj_tcd_resolution_t* tr = tilec->resolutions; | 571 opj_tcd_resolution_t* tr = tilec->resolutions; |
| 572 | 572 |
| 573 OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resoluti
on level computed */ | 573 OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resoluti
on level computed */ |
| 574 OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolut
ion level computed */ | 574 OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolut
ion level computed */ |
| 575 | 575 |
| 576 OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); | 576 OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); |
| 577 | 577 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 (dwt_1D)(&v); | 614 (dwt_1D)(&v); |
| 615 for(k = 0; k < rh; ++k) { | 615 for(k = 0; k < rh; ++k) { |
| 616 tiledp[k * w + j] = v.mem[k]; | 616 tiledp[k * w + j] = v.mem[k]; |
| 617 } | 617 } |
| 618 } | 618 } |
| 619 } | 619 } |
| 620 opj_aligned_free(h.mem); | 620 opj_aligned_free(h.mem); |
| 621 return OPJ_TRUE; | 621 return OPJ_TRUE; |
| 622 } | 622 } |
| 623 | 623 |
| 624 void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OP
J_INT32 x, OPJ_INT32 size){ | 624 static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
t a, OPJ_INT32 x, OPJ_INT32 size){ |
| 625 OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas); | 625 OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas); |
| 626 OPJ_INT32 count = w->sn; | 626 OPJ_INT32 count = w->sn; |
| 627 OPJ_INT32 i, k; | 627 OPJ_INT32 i, k; |
| 628 | 628 |
| 629 for(k = 0; k < 2; ++k){ | 629 for(k = 0; k < 2; ++k){ |
| 630 if ( count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_
t) bi & 0x0f) == 0 && (x & 0x0f) == 0 ) { | 630 if ( count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_
t) bi & 0x0f) == 0 && (x & 0x0f) == 0 ) { |
| 631 /* Fast code path */ | 631 /* Fast code path */ |
| 632 for(i = 0; i < count; ++i){ | 632 for(i = 0; i < count; ++i){ |
| 633 OPJ_INT32 j = i; | 633 OPJ_INT32 j = i; |
| 634 bi[i*8 ] = a[j]; | 634 bi[i*8 ] = a[j]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 bi = (OPJ_FLOAT32*) (w->wavelet + 1 - w->cas); | 660 bi = (OPJ_FLOAT32*) (w->wavelet + 1 - w->cas); |
| 661 a += w->sn; | 661 a += w->sn; |
| 662 size -= w->sn; | 662 size -= w->sn; |
| 663 count = w->dn; | 663 count = w->dn; |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 | 666 |
| 667 void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a ,
OPJ_INT32 x, OPJ_INT32 nb_elts_read){ | 667 static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
ct a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){ |
| 668 opj_v4_t* restrict bi = v->wavelet + v->cas; | 668 opj_v4_t* restrict bi = v->wavelet + v->cas; |
| 669 OPJ_INT32 i; | 669 OPJ_INT32 i; |
| 670 | 670 |
| 671 for(i = 0; i < v->sn; ++i){ | 671 for(i = 0; i < v->sn; ++i){ |
| 672 memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOA
T32)); | 672 memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOA
T32)); |
| 673 } | 673 } |
| 674 | 674 |
| 675 a += v->sn * x; | 675 a += v->sn * x; |
| 676 bi = v->wavelet + 1 - v->cas; | 676 bi = v->wavelet + 1 - v->cas; |
| 677 | 677 |
| 678 for(i = 0; i < v->dn; ++i){ | 678 for(i = 0; i < v->dn; ++i){ |
| 679 memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOA
T32)); | 679 memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOA
T32)); |
| 680 } | 680 } |
| 681 } | 681 } |
| 682 | 682 |
| 683 #ifdef __SSE__ | 683 #ifdef __SSE__ |
| 684 | 684 |
| 685 void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){ | 685 static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
8 c){ |
| 686 __m128* restrict vw = (__m128*) w; | 686 __m128* restrict vw = (__m128*) w; |
| 687 OPJ_INT32 i; | 687 OPJ_INT32 i; |
| 688 /* 4x unrolled loop */ | 688 /* 4x unrolled loop */ |
| 689 for(i = 0; i < count >> 2; ++i){ | 689 for(i = 0; i < count >> 2; ++i){ |
| 690 *vw = _mm_mul_ps(*vw, c); | 690 *vw = _mm_mul_ps(*vw, c); |
| 691 vw += 2; | 691 vw += 2; |
| 692 *vw = _mm_mul_ps(*vw, c); | 692 *vw = _mm_mul_ps(*vw, c); |
| 693 vw += 2; | 693 vw += 2; |
| 694 *vw = _mm_mul_ps(*vw, c); | 694 *vw = _mm_mul_ps(*vw, c); |
| 695 vw += 2; | 695 vw += 2; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 724 c = _mm_mul_ps(c, vl[0]); | 724 c = _mm_mul_ps(c, vl[0]); |
| 725 for(; m < k; ++m){ | 725 for(; m < k; ++m){ |
| 726 __m128 tmp = vw[-1]; | 726 __m128 tmp = vw[-1]; |
| 727 vw[-1] = _mm_add_ps(tmp, c); | 727 vw[-1] = _mm_add_ps(tmp, c); |
| 728 vw += 2; | 728 vw += 2; |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 | 731 |
| 732 #else | 732 #else |
| 733 | 733 |
| 734 void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c) | 734 static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT
32 c) |
| 735 { | 735 { |
| 736 OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; | 736 OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; |
| 737 OPJ_INT32 i; | 737 OPJ_INT32 i; |
| 738 for(i = 0; i < count; ++i){ | 738 for(i = 0; i < count; ++i){ |
| 739 OPJ_FLOAT32 tmp1 = fw[i*8 ]; | 739 OPJ_FLOAT32 tmp1 = fw[i*8 ]; |
| 740 OPJ_FLOAT32 tmp2 = fw[i*8 + 1]; | 740 OPJ_FLOAT32 tmp2 = fw[i*8 + 1]; |
| 741 OPJ_FLOAT32 tmp3 = fw[i*8 + 2]; | 741 OPJ_FLOAT32 tmp3 = fw[i*8 + 2]; |
| 742 OPJ_FLOAT32 tmp4 = fw[i*8 + 3]; | 742 OPJ_FLOAT32 tmp4 = fw[i*8 + 3]; |
| 743 fw[i*8 ] = tmp1 * c; | 743 fw[i*8 ] = tmp1 * c; |
| 744 fw[i*8 + 1] = tmp2 * c; | 744 fw[i*8 + 1] = tmp2 * c; |
| 745 fw[i*8 + 2] = tmp3 * c; | 745 fw[i*8 + 2] = tmp3 * c; |
| 746 fw[i*8 + 3] = tmp4 * c; | 746 fw[i*8 + 3] = tmp4 * c; |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 | 749 |
| 750 void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m,
OPJ_FLOAT32 c) | 750 static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
T32 m, OPJ_FLOAT32 c) |
| 751 { | 751 { |
| 752 OPJ_FLOAT32* restrict fl = (OPJ_FLOAT32*) l; | 752 OPJ_FLOAT32* restrict fl = (OPJ_FLOAT32*) l; |
| 753 OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; | 753 OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; |
| 754 OPJ_INT32 i; | 754 OPJ_INT32 i; |
| 755 for(i = 0; i < m; ++i){ | 755 for(i = 0; i < m; ++i){ |
| 756 OPJ_FLOAT32 tmp1_1 = fl[0]; | 756 OPJ_FLOAT32 tmp1_1 = fl[0]; |
| 757 OPJ_FLOAT32 tmp1_2 = fl[1]; | 757 OPJ_FLOAT32 tmp1_2 = fl[1]; |
| 758 OPJ_FLOAT32 tmp1_3 = fl[2]; | 758 OPJ_FLOAT32 tmp1_3 = fl[2]; |
| 759 OPJ_FLOAT32 tmp1_4 = fl[3]; | 759 OPJ_FLOAT32 tmp1_4 = fl[3]; |
| 760 OPJ_FLOAT32 tmp2_1 = fw[-4]; | 760 OPJ_FLOAT32 tmp2_1 = fw[-4]; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 929 |
| 930 for(k = 0; k < rh; ++k){ | 930 for(k = 0; k < rh; ++k){ |
| 931 memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * size
of(OPJ_FLOAT32)); | 931 memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * size
of(OPJ_FLOAT32)); |
| 932 } | 932 } |
| 933 } | 933 } |
| 934 } | 934 } |
| 935 | 935 |
| 936 opj_aligned_free(h.wavelet); | 936 opj_aligned_free(h.wavelet); |
| 937 return OPJ_TRUE; | 937 return OPJ_TRUE; |
| 938 } | 938 } |
| OLD | NEW |