// file: $USFS/class/image_analysis/v6.1/imaga_dct_07.cc
//

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

// method: dct_filter_cc
//
// arguments: none
//
// return:
//  a logical_1 value indicating status
//
// this method filters the zigzag-ordered dct coefficients, averaging
// adjacent coefficients into one feature value.
//  
logical_1 Image_analysis::dct_filter_cc() {

  // remove the dc component
  //
  dct_r_red_d[0] = 0;
  dct_r_grn_d[0] = 0;
  dct_r_blu_d[0] = 0;

  // check the validity of the filter size
  //
  if (dct_filter_size_d == (-1)) {
    error_handler_cc((char_1*)"dct_filter_cc",
		     (char_1*)"invalid dct filter size");
    return ISIP_FALSE;
  }
  
  // filter the coefficients
  // 
  for (int_4 i=0; i<IMAGA_DCT_FEATURE_SIZE; i++) {
    dct_t_red_filter_d[i] = 0;
    dct_t_grn_filter_d[i] = 0;
    dct_t_blu_filter_d[i] = 0;

    // loop over dct coefficients in the specified range
    //
    for (int_4 j=0; j<dct_filter_size_d; j++) {
      dct_t_red_filter_d[i] += dct_r_red_d[i * dct_filter_size_d + j]
	* dct_r_red_d[i * dct_filter_size_d + j];
      dct_t_grn_filter_d[i] += dct_r_grn_d[i * dct_filter_size_d + j]
	* dct_r_grn_d[i * dct_filter_size_d + j];
      dct_t_blu_filter_d[i] += dct_r_blu_d[i * dct_filter_size_d + j]
	* dct_r_blu_d[i * dct_filter_size_d + j];
    }

    // average the feature values
    //
    dct_t_red_filter_d[i] /= dct_filter_size_d;
    dct_t_grn_filter_d[i] /= dct_filter_size_d;
    dct_t_blu_filter_d[i] /= dct_filter_size_d;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
