/*
 *******************************************************************************
 *  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 VIDEO_SNAPSHOT_MECHANISM_H
#define VIDEO_SNAPSHOT_MECHANISM_H

#ifdef __cplusplus
extern "C" {
#endif

#include <ssm_info.h>
#include <sync_shared_memory.h>


#define ISP_PARAMS_PATH_LENGTH_MAX 127

typedef struct VMF_SNAP_HANDLE_T VMF_SNAP_HANDLE_T;

typedef struct {
	unsigned int dwStartX;
	unsigned int dwStartY;
	unsigned int dwCropWidth;
	unsigned int dwCropHeight;
	unsigned int dwBufSize;
	void* pOutBuffer;
	//! Quantization parameter, range: 0~200, better quality is between 0~100
	unsigned int dwQp;
}VMF_SNAP_CROP_PARAMS_T;

typedef struct
{
	unsigned int bExifEnable;
	//! EXIF IFD0 information
	char* pcMake;                   //! Max. len: 64 bytes including NULL for termination.
	char* pcModel;                  //! Max. len: 64 bytes including NULL for termination.
	unsigned int dwOrientation;
	unsigned int adwXResolution[2]; //! Default value is 1/72inch, {72, 1}
	unsigned int adwYResolution[2]; //! Default value is 1/72inch, {72, 1}
	unsigned int dwResolutionUnit;  //! Unit of XResolution(0x011a)/YResolution(0x011b). '1' means no-unit, '2' means inch, '3' means centimeter. 
	                                //! Default value is '2'(inch).
	char* pcSoftware;               //! Max. len: 64 bytes including NULL for termination.
	char* pcDateTime;               //! Format: "YYYY:MM:DD HH:MM:SS", 20 bytes including NULL for termination. 
	                                //! If pcDateTime is Null, SDK will fill frame date and time.
	char* pcArtist;
	char* pcCopyright;
	unsigned int bExifSubIfdPointer;
	unsigned int bGpsInfoIfdPointer;

	//! EXIF SubIFD information
	unsigned int adwExposureTime[2];//! 1/8 seconds means {1, 8}
	unsigned int adwFNumber[2];
	unsigned int dwExposureProgram;
	unsigned int dwIsoSpeedRatings;
	char acExifVersion[4];
	char* pcDateTimeOriginal;       //! Format: "YYYY:MM:DD HH:MM:SS", 20 bytes including NULL for termination.
	char* pcDateTimeDigitized;      //! Format: "YYYY:MM:DD HH:MM:SS", 20 bytes including NULL for termination.
	unsigned int adwExposureBiasValue[2];
	unsigned int dwMeteringMode;
	unsigned int dwLightSource;
	unsigned int adwFocalLength[2];
	char* pcMakerNote;              //! Max. len: 64 bytes including NULL for termination.
	unsigned int dwColorSpace;
	unsigned int dwExifImageWidth;  //! If dwExifImageWidth is 0, SDK will fill encoded width.
	unsigned int dwExifImageHeight; //! If dwExifImageHeight is 0, SDK will fill encoded height.

	unsigned int bExposureMode;
	unsigned int dwExposureMode;

	unsigned int bWhiteBalance;
	unsigned int dwWhiteBalance;

	unsigned int bDigitalZoomRatio;
	unsigned int adwDigitalZoomRatio[2];

	unsigned int bSceneCaptureType;
	unsigned int dwSceneCaptureType;

	unsigned int bContrast;
	unsigned int dwContrast;

	unsigned int bSaturation;
	unsigned int dwSaturation;

	unsigned int bSharpness;
	unsigned int dwSharpness;	

	//! EXIF GPS information
	char* pcGpsLatitudeRef;         //! Format: "N" or "S", 2 bytes including NULL for termination.
	unsigned int bGpsLatitude;	
	unsigned int adwGpsLatitude[6];

	char* pcGpsLongitudeRef;        //! Format: "E" or "W", 2 bytes including NULL for termination.
	unsigned int bGpsLongitude;	
	unsigned int adwGpsLongitude[6];

	unsigned int bGpsLatitudeRef;	
	char cGPSAltitudeRef;           //! Format: 0 (above sea level) or 1 (below sea level), 1 bytes.
	unsigned int bGPSAltitude;	
	unsigned int adwGPSAltitude[2];

	char* pcGpsDateStamp;           //! Format: "YYYY:MM:DD", 11 bytes including NULL for termination.
	unsigned int bGpsTimeStamp;	
	unsigned int adwGpsTimeStamp[6];
} VMF_SNAP_EXIF_T;

/*
 * A data Structure for SNAP Init
 */
typedef struct {
	//! The Output pin of isp  
	const char *pszOutPinPrefix;    
	//! The index of stream.
	unsigned int dwStreamIdx;	
	//! The pointer to video source handle	
	void *pVsrcHandle;
	//! Quantization parameter, range: 0~200, better quality is between 0~100
	unsigned int dwQp;
} VMF_SNAP_INITOPT_T;

/**
 * @brief Function to initial snapshot device
 *
 * @param[in] ptOpt The initial options about snapshot.
 * @return Success: VMF_SNAP_HANDLE_T  Fail: NULL.
 */
VMF_SNAP_HANDLE_T* VMF_SNAP_Init(const VMF_SNAP_INITOPT_T* ptOpt);

/**
 * @brief Function to release a snapshot object.
 *
 * @param[in] ptHandle The handle of snapshot object.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_SNAP_Release(VMF_SNAP_HANDLE_T* ptHandle);

/**
 * @brief Start processing snapshot
 *
 * @param[in] ptSnapHandle The handle of snapshot object.
 * @param[in] dwOutWidth The rs width of snapshot.
 * @param[in] dwOutHeight The rs height of snapshot.
 * @param[in] dwBufSize The size of the output buffer.
 * @param[in] pOutBuffer The output buffer of snapshot.
 * @return Success: jpeg size  Fail: negative integer.
 */
int VMF_SNAP_ProcessOneFrame(VMF_SNAP_HANDLE_T* ptSnapHandle, unsigned int dwOutWidth, unsigned int dwOutHeight, unsigned int dwBufSize, void *pOutBuffer);

/**
 * @brief Start processing snapshot
 *
 * @param[in] ptSnapHandle The handle of snapshot object.
 * @param[in] dwBufSize The size of the output buffer.
 * @param[in] ptCropInfo The crop infomation of snapshot.
 * @return Success: jpeg size  Fail: negative integer.
 */
int VMF_SNAP_ProcessOneFrame_AREA(VMF_SNAP_HANDLE_T* ptSnapHandle, unsigned int dwBufSize, VMF_SNAP_CROP_PARAMS_T* ptCropInfo);

/**
 * @brief Start processing snapshot YUV
 *
 * @param[in] ptSsmBuff The ssm buffer of snapshot.
 * @param[in] ptCropInfo The crop infomation of snapshot.
 * @return Success: jpeg size  Fail: negative integer.
 */
int VMF_SNAP_ProcessOneFrame_YUV(SSM_BUFFER_T* ptSsmBuff, VMF_SNAP_CROP_PARAMS_T* ptCropInfo);

/**
 * @brief Configure snapshot EXIF information
 *
 * @param[in] ptSnapHandle The handle of snapshot object.
 * @param[in] ptCropInfo The EXIF infomation of snapshot.
 * @return Success: 0  Fail: negative integer.
 */
int VMF_SNAP_ConfigExif(VMF_SNAP_HANDLE_T* ptSnapHandle, VMF_SNAP_EXIF_T* ptExifInfo);

/**
 * @brief Configure snapshot EXIF information
 *
 * @param[in] ptSnapHandle The handle of snapshot object.
 * @param[in] bTnEnable Enable thumbnail.
 * @param[in] dwTnQp The thumbnail Qp
 * @param[in] dwTnWidth The thumbnail width
 * @param[in] dwTnHeight The thumbnail height
 * @return Success: 0  Fail: negative integer.
 */
int VMF_SNAP_ConfigThumbnail(VMF_SNAP_HANDLE_T *ptSnapHandle, unsigned int bTnEnable, unsigned int dwTnQp, unsigned int dwTnWidth, unsigned int dwTnHeight);

#ifdef __cplusplus
}
#endif

#endif

