update the exponents so that they are the ones the decoder will decode. Return the number of bits used to code the exponents */
| 296 | /* update the exponents so that they are the ones the decoder will |
| 297 | decode. Return the number of bits used to code the exponents */ |
| 298 | static int encode_exp(uint8_t encoded_exp[N/2], |
| 299 | uint8_t exp[N/2], |
| 300 | int nb_exps, |
| 301 | int exp_strategy) |
| 302 | { |
| 303 | int group_size, nb_groups, i, j, k, exp_min; |
| 304 | uint8_t exp1[N/2]; |
| 305 | |
| 306 | switch(exp_strategy) { |
| 307 | case EXP_D15: |
| 308 | group_size = 1; |
| 309 | break; |
| 310 | case EXP_D25: |
| 311 | group_size = 2; |
| 312 | break; |
| 313 | default: |
| 314 | case EXP_D45: |
| 315 | group_size = 4; |
| 316 | break; |
| 317 | } |
| 318 | nb_groups = ((nb_exps + (group_size * 3) - 4) / (3 * group_size)) * 3; |
| 319 | |
| 320 | /* for each group, compute the minimum exponent */ |
| 321 | exp1[0] = exp[0]; /* DC exponent is handled separately */ |
| 322 | k = 1; |
| 323 | for(i=1;i<=nb_groups;i++) { |
| 324 | exp_min = exp[k]; |
| 325 | assert(exp_min >= 0 && exp_min <= 24); |
| 326 | for(j=1;j<group_size;j++) { |
| 327 | if (exp[k+j] < exp_min) |
| 328 | exp_min = exp[k+j]; |
| 329 | } |
| 330 | exp1[i] = exp_min; |
| 331 | k += group_size; |
| 332 | } |
| 333 | |
| 334 | /* constraint for DC exponent */ |
| 335 | if (exp1[0] > 15) |
| 336 | exp1[0] = 15; |
| 337 | |
| 338 | /* Decrease the delta between each groups to within 2 |
| 339 | * so that they can be differentially encoded */ |
| 340 | for (i=1;i<=nb_groups;i++) |
| 341 | exp1[i] = FFMIN(exp1[i], exp1[i-1] + 2); |
| 342 | for (i=nb_groups-1;i>=0;i--) |
| 343 | exp1[i] = FFMIN(exp1[i], exp1[i+1] + 2); |
| 344 | |
| 345 | /* now we have the exponent values the decoder will see */ |
| 346 | encoded_exp[0] = exp1[0]; |
| 347 | k = 1; |
| 348 | for(i=1;i<=nb_groups;i++) { |
| 349 | for(j=0;j<group_size;j++) { |
| 350 | encoded_exp[k+j] = exp1[i]; |
| 351 | } |
| 352 | k += group_size; |
| 353 | } |
| 354 | |
| 355 | #if defined(DEBUG) |
no test coverage detected