// file: $USFS/class/image_analysis/v3.0/imaga_edge_10.cc
//

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

#include <integral_constants.h>

// method: edge_convolve_cc
//
// arguments:
//  float_4* result_buf_a: (output) result after the convolution
//  float_4* conv_buf1_a: (input) image_matrix
//  float_4* conv_buf2_a: (input) mask to be convolved
//  int_4 width_a: (input) width of the image
//  int_4 height_a: (input) height of the image
//
// return: a logical_1 value indicating status
//
// this method performs the convolution of the gaussian mask with the image
//
logical_1 Image_analysis::edge_convolve_cc(float_4* result_buf_a,
					   float_4* conv_buf1_a,
					   float_4* conv_buf2_a,
					   int_4 width_a, int_4 height_a) {
  
  // computing a limit to take care of the pixels in the first
  // and the last lines
  //
  int_4 lim = edge_r_msize_d / 2;
  
  // looping through the entire image
  //
  for (int_4 i=0; i<height_a; i++) {
    for (int_4 j=0; j<width_a; j++) {
      
      // initializing the data
      //
      result_buf_a[i * width_a + j] = 0;
      
      // loop through the mask
      //
      for (int_4 m=0; m<edge_r_msize_d; m++) {
	
	// declaring a varibale for checking the edges in vertical
	// direction
	//
	int_4 x_lim = i + lim - m;
	
	for(int_4 n=0; n<edge_r_msize_d; n++) {
	  
	  // declaring a varible for checking the edges in horizontal
	  // direction
	  //
	  int_4 y_lim = j + lim - n;
	  
	  // checking for the edges in the horizontal and vertical direction
	  //
	  if (((x_lim >= (int)0 && (y_lim >= (int)0))
	       && ((x_lim < height_a) && y_lim < width_a))) {
	    
	    // convolving the image with the gaussian mask
	    //
	    result_buf_a[i * width_a + j] += (conv_buf1_a[x_lim * width_a + y_lim] *
					      conv_buf2_a[m * edge_r_msize_d + n]); 
	  }
	}
      }
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
	  
  
