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

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

// method: dct_debias_cc
//
// arguments:
//  uint_1* b_red: (input) buffer for red color
//  uint_1* b_grn: (input) buffer for green color
//  uint_1* b_blu: (input) buffer for blue color
//  int_4 width: (input) width of the block
//  int_4 height: (input) height of the block
//
// return:
//  a logical_1 value indicating status
//
// this method removes the DC bias from the image block. note the input image
// block is not necessarily the block on which we want to carry out the DCT.
// if this is the case, we need to find the correct data inside the given
// block
//
logical_1 Image_analysis::dct_debias_cc(uint_1* b_red_a, uint_1* b_grn_a,
					uint_1* b_blu_a, int_4 width_a,
					int_4 height_a) {

  // declare local variables
  //
  int_4 block_size = dct_blk_size_d;
  int_4 off_w = 0, off_h = 0;
    
  // check if the image block was read according to the DCT block size
  //
  if (win_size_d > dct_blk_size_d) {
    block_size = win_size_d;
    off_w = (win_size_d - dct_blk_size_d) / 2;
    off_h = (win_size_d - dct_blk_size_d) / 2;
  }
  
  // debias the image by subtracting the mid value
  //
  for (int_4 i=0; i<dct_blk_size_d; i++) {
    for (int_4 j=0; j<dct_blk_size_d; j++) {
      dct_r_red_d[i * dct_blk_size_d + j] = (float_4)b_red_a[(i + off_h) *
		      block_size + (j + off_w)] - IMAGA_DCT_MID;
      dct_r_grn_d[i * dct_blk_size_d + j] = (float_4)b_grn_a[(i + off_h) *
		      block_size + (j + off_w)] - IMAGA_DCT_MID;
      dct_r_blu_d[i * dct_blk_size_d + j] = (float_4)b_blu_a[(i + off_h) *
		      block_size + (j + off_w)] - IMAGA_DCT_MID;
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
