/* The copyright in this software is being made available under the BSD
 * License, included below. This software may be subject to other third party
 * and contributor rights, including patent rights, and no such rights are
 * granted under this license.  
 *
 * Copyright (c) 2010-2012, ITU/ISO/IEC
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
 *    be used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef PICTURERESAMPLE_H
#define PICTURERESAMPLE_H

#include "ViewSynDef.h"
#include "ViewSynAPI.h"



//typedef struct upsample_table
//{
//	int value_mul5;
//	int value_mul20;
//}UpsampleTable;

class CPictureResample
{
private:

  // Algorithm 0: Simple repeat /drop pixels
  void RepeatPixel420to444(imgpel** oPic, imgpel** iPic, int Width, int Height);
  void DropPixel444to420  (imgpel** oPic, imgpel** iPic, int Width, int Height);

  unsigned char PixelClip(const int pxlVal);
  
  void DoUpsample(imgpel** Yo, imgpel** Yi, int Width, int Height);
  void DoDownsample(imgpel** Yo, imgpel** Yi, int Width, int Height);

public:
  CPictureResample();
  ~CPictureResample();
  
  //void Set(int iWidth, int iHeight, int iAlg = 0);
  int  State();
  
  // For UV format conversion
  void PictureResample420to444(imgpel** oPic, imgpel** iPic, int Width, int Height);
  void PictureResample444to420(imgpel** oPic, imgpel** iPic, int Width, int Height);

  void PictureResample420to444ForRefView(imgpel** output_left_u, imgpel** input_left_u, 
										 imgpel** output_left_v, imgpel** input_left_v,
										 imgpel** output_right_u,imgpel** input_right_u,
										 imgpel** output_right_v,imgpel** input_right_v,
										 int Width, int Height,int SynDir);
  void PictureResample444to420ForRefView(imgpel** output_left_u, imgpel** input_left_u, 
										 imgpel** output_left_v, imgpel** input_left_v,
										 imgpel** output_right_u,imgpel** input_right_u,
										 imgpel** output_right_v,imgpel** input_right_v,
										 int Width, int Height);
  
  // For picture upsample and downsample
  int UpsampleView(imgpel** Yo, imgpel** Yi, int Width, int Height, int Factor);
  int DownsampleView(imgpel** Yo, imgpel** Yi, int Width, int Height, int Factor);

  int UpsampleRefView(imgpel**left_output_Y,imgpel**left_input_Y,
					  imgpel**left_output_U,imgpel**left_input_U,
					  imgpel**left_output_V,imgpel**left_input_V,
					  imgpel**left_output_depth,imgpel**left_input_depth,
					  imgpel**right_output_Y,imgpel**right_input_Y,
					  imgpel**right_output_U,imgpel**right_input_U,
					  imgpel**right_output_V,imgpel**right_input_V,
					  imgpel**right_output_depth,imgpel**right_input_depth,
					  int Width, int Height, int Factor,int SynDirection);
#if QC_VSP_Asymmetric_Resolution
  int UpsampleRefView420(imgpel**left_output_Y,imgpel**left_input_Y,
					  imgpel**left_output_U,imgpel**left_input_U,
					  imgpel**left_output_V,imgpel**left_input_V,
					  imgpel**left_output_depth,imgpel**left_input_depth,
					  imgpel**right_output_Y,imgpel**right_input_Y,
					  imgpel**right_output_U,imgpel**right_input_U,
					  imgpel**right_output_V,imgpel**right_input_V,
					  imgpel**right_output_depth,imgpel**right_input_depth,
					  int Width, int Height, int Factor,int SynDirection);

  int DownsampleRefView420(imgpel**output_Y,imgpel**input_Y,
						imgpel**output_U,imgpel**input_U,
						imgpel**output_V,imgpel**input_V,
						imgpel**output_depth,imgpel**input_depth,
						int Width, int Height, int Factor);
#endif

  int DownsampleRefView(imgpel**output_Y,imgpel**input_Y,
						imgpel**output_U,imgpel**input_U,
						imgpel**output_V,imgpel**input_V,
						imgpel**output_depth,imgpel**input_depth,
						int Width, int Height, int Factor);

private:
	 // UpsampleTable	  AVCFir6TapUpsampleTable[PIXEL_VALUE_RANGE];
	int PixelValueMul20[PIXEL_VALUE_RANGE];
	int PiXelValueMul5[PIXEL_VALUE_RANGE];
};

#endif
