// file: $USFS/class/image_analysis/v6.2/imaga_gabor_05.cc
//

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

// method: gabor_gray_cc
//
// arguments:
//  uint_1* gabor_gray: (output) gray scaled value
//  int_4 width: (input) width of the image
//  int_4 height: (input) height of the image
//  uint_1* b_red: (input) buffer having the red values
//  uint_1* b_green: (input) buffer having the green values
//  uint_1* b_blue: (input) buffer having the blue values
//
// return: a logical_1 value indicating the status
//
// this method computes the equivalent gray scale value from
// the weighted combinations of red, green and blue
//
logical_1 Image_analysis::gabor_gray_cc(float_8* gabor_gray_a, int_4 width_a,
					int_4 height_a, uint_1* b_red_a,
					uint_1* b_green_a, uint_1* b_blue_a) {
  
  // looping through the entire data
  //
  for (int_4 i = 0; i < height_a; i++) {
    for (int_4 j = 0; j < width_a; j++) {
      
      // computing the equivalent gray scale value from the
      // individual red, green and blue values
      //
      gabor_gray_a[i * width_a + j] = (IMAGA_EDGE_RCNST *
				       (float_8)(b_red_a[i * width_a + j]) +
				       IMAGA_EDGE_GCNST *
				       (float_8)(b_green_a[i * width_a + j]) +
				       IMAGA_EDGE_BCNST *
				       (float_8)(b_blue_a[i * width_a + j]));

      // clipping the value to fall between [0, 255]
      //
      if (gabor_gray_a[i * width_a + j] > IMAGA_HIST_MAX) {
	gabor_gray_a[i * width_a + j] = IMAGA_HIST_MAX;
      }
      else if (gabor_gray_a[i * width_a + j] < IMAGA_HIST_MIN) {
	gabor_gray_a[i * width_a + j] = IMAGA_HIST_MIN;
      }
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
