// file: $USFS/class/image_analysis/v1.0/imaga_rle_10.cc
//

// isip include files
//
#include "image_analysis.h"

#include "image_analysis_constants.h"
#include <integral_constants.h>

// method: rle_category_cc
//
// arguments: none
//
// return: a logical_1 value indicating status
//
// this method computes the category for the DCT coefficient
//
logical_1 Image_analysis::rle_category_cc(float_4 value_a, int_4 &cat_a,
					  int_4&  offset_a) {

  // value of log 2
  //
  static float_4 logtwo_l = log(2.0);
  
  // get rid of sign
  //
  float_4 temp_l = fabs(value_a);

  // find the category --- note that categories are defined in terms of
  // intervals of 2^k to 2^(k+1)
  //
  if (temp_l == 0) {
    cat_a = 0;
    offset_a = 0;
  }
  else {
    cat_a = (int_4)floor(log(temp_l)/logtwo_l) + 1;
    offset_a = (int_4)(temp_l - pow(2.0, cat_a - 1));
    if (value_a < 0) {
      cat_a *= -1;
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
