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

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

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

// method: edge_gray_cc
//
// arguments:
//  uint_1* gray_value_a: (output) gray scaled value
//  int_4 width_a: (intput) width of the image
//  int_4 height_a: (input) height of the image
//  uint_1* b_red_a: (input) buffer having the red values
//  uint_1* b_green_a: (input) buffer having the green values
//  uint_1* b_blue_a: (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::edge_gray_cc(float_4* edge_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
      //
      edge_gray_a[i*width_a + j] = (IMAGA_EDGE_RCNST *
				    (float_4)(b_red_a[i*width_a + j]) +
				    IMAGA_EDGE_GCNST *
				    (float_4)(b_green_a[i*width_a + j]) +
				    IMAGA_EDGE_BCNST *
				    (float_4)(b_blue_a[i*width_a + j]));

      // clip the data to fit in the pixel value range
      //
      if (edge_gray_a[i * width_a + j] > IMAGA_EDGE_COLMAX) {
	edge_gray_a[i * width_a + j] = IMAGA_EDGE_COLMAX;
      }
      else if (edge_gray_a[i * width_a + j] < IMAGA_EDGE_COLMIN) {
	edge_gray_a[i * width_a + j] = IMAGA_EDGE_COLMIN;
      }
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
