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

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

// method: gabor_convolve_cc
//
// arguments:
//  float_8* result_buf: (output) result after the convolution
//  float_8* image_buf: (input) image data block
//  float_8* filter_buf: (input) filter data block
//  int_4 width: (input) width of the image data block
//  int_4 height: (input) height of the image data block
//
// return: a logical_1 value indicating status
//
// this method performs 2-d convolution between two buffers
//
logical_1 Image_analysis::gabor_convolve_cc(float_8* result_buf_a,
					    float_8* image_buf_a,
					    float_8* filter_buf_a,
					    int_4 width_a, int_4 height_a) {
  
  // loop through the entire data block
  //
  for (int_4 i = 0; i < height_a; i++) {
    for (int_4 j = 0; j < width_a; j++) {
      
      // initialize the data
      //
      result_buf_a[i * width_a + j] = 0;
      
      // convolution at one pixel
      //
      for (int_4 m = 0; m < gabor_num_row_d; m++) {
	
	// temp variable
	//
	int_4 i_m = i - m;
	
	for (int_4 n = 0; n < gabor_num_col_d; n++) {
	  
	  // temp variable
	  //
	  int_4 j_n = j - n;
	  
	  // check for validity of data
	  //
	  if ((i_m >= 0) && (j_n >= 0)
	       && (i_m < height_a) && (j_n < width_a)) {	    
	    result_buf_a[i * width_a + j] +=
	      (image_buf_a[i_m * width_a + j_n] *
	       filter_buf_a[m * gabor_num_col_d + n]); 
	  }
	}
      }
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}
	  
  
