/*
 *******************************************************************************
 *  Copyright (c) 2010-2022 VATICS(KNERON) Inc. All rights reserved.
 *
 *  +-----------------------------------------------------------------+
 *  | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
 *  | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH  |
 *  | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
 *  | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE   |
 *  | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE   |
 *  | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.        |
 *  |                                                                 |
 *  | THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT   |
 *  | ANY PRIOR NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY |
 *  | VATICS(KNERON) INC.                                             |
 *  +-----------------------------------------------------------------+
 *
 *******************************************************************************
 */
#ifndef YUV_RGB_CVT_H
#define YUV_RGB_CVT_H

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

#include <stdint.h>

#define VMF_CVT_PRIMIT_COLOR_CNT 3  //! The nubmer of RGB/YUV color channels

/**
 * An enumeration for CVT swing mode
 */
typedef enum {
	VMF_CVT_STUDIO = 0,		//Studio swing :Y[16,235], U[16,240], V[16,240]
	VMF_CVT_FULL,			//Full swing   :Y[ 0,255], U[ 0,255], V[ 0,255]
	VMF_CVT_SWING_MODE_CNT
} VMF_CVT_SWING_MODE;

/**
 * An enumeration for CVT ITUR mode
 */
typedef enum {
	VMF_CVT_BT601 = 0,		//Rec. ITU_R BT601
	VMF_CVT_BT709,			//Rec. ITU_R BT709
	VMF_CVT_ITUR_MODE_CNT
} VMF_CVT_ITUR_MODE;

/**
 * An enumeration for CVT YUV sample mode
 */
typedef enum {
	VMF_CVT_YCbCr444 = 0,	//Sample mode 444
	VMF_CVT_YCbCr422,		//Sample mode 422
	VMF_CVT_YCbCr420,		//Sample mode 420
	VMF_CVT_SAMPLE_MODE_CNT
} VMF_CVT_SAMPLE_MODE;

/**
 * An enumeration for CVT conversion mode
 */
typedef enum {
	VMF_CVT_RGB_2_YCbCr = 0,	//From RGB to YUV
	VMF_CVT_YCbCr_2_RGB,		//From YUV to RGB
	VMF_CVT_CVT_MODE_CNT
} VMF_CVT_MODE;

/**
 * A structure for CVT init option
 */
typedef struct {
	VMF_CVT_SWING_MODE eSwing;		//! The swing mode of CVT.
	VMF_CVT_ITUR_MODE eItur;		//! The ITUR recommendation.
	VMF_CVT_SAMPLE_MODE eSample;	//! The YUV sample mode.
	VMF_CVT_MODE eCvt;				//! The converting mode.
	uint32_t dwWidth;				//! The width of the frame.
	uint32_t dwHeight;				//! The height of the frame.
	void *pUsrData;					//! The pointer of additional user data.
}VMF_CVT_INITOPT_T;

/**
 *	A structure for CVT data buffer
 */
typedef struct {
	uint8_t *apbyInBuf[VMF_CVT_PRIMIT_COLOR_CNT + 1];	//The array of pointer for input frame.
	uint8_t *apbyOutBuf[VMF_CVT_PRIMIT_COLOR_CNT + 1];	//The array of pointer for output frame.
}VMF_CVT_BUFFER_T;

typedef struct vmf_cvt_handle_t VMF_CVT_HANDLE_T;

/**
 * @brief Function to initialize a CVT handle.
 *
 * @param[in] The CVT object's initializing option.
 * @return Null: Fail, Others: The handle of CVT object.
 */
VMF_CVT_HANDLE_T *VMF_CVT_Init(const VMF_CVT_INITOPT_T *);

/**
 * @brief Function to release a CVT handle.
 *
 * @param[in] The handle of CVT object.
 * @return 0 with no errors, -1 otherwise
 */
int VMF_CVT_Release(VMF_CVT_HANDLE_T *);

/**
 * @brief Function to reset the width of CVT object.
 *
 * @param[in] The handle of CVT object.
 * @param[in] The new width.
 * @return 0 with no errors, -1 otherwise
 */
int VMF_CVT_ResetWidth(VMF_CVT_HANDLE_T *, uint32_t);

/**
 * @brief Function to reset the height of CVT object.
 *
 * @param[in] The handle of CVT object.
 * @param[in] The new height.
 * @return 0 with no errors, -1 otherwise
 */
int VMF_CVT_ResetHeight(VMF_CVT_HANDLE_T *, uint32_t);

/**
 * @brief Process converting (blocking).
 *
 * @param[in] The handle of CVT object.
 * @param[in] The pointer of VMF_CVT_BUFFERT_T structure.
 * @return 0 with no errors, -1 otherwise
 */
int VMF_CVT_ProcessOneFrame(VMF_CVT_HANDLE_T *, VMF_CVT_BUFFER_T *);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif //YUV_RGB_CVT_H
