You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
14 KiB

2 years ago
#ifndef __ZMF_UTILS_H__
#define __ZMF_UTILS_H__
#include <stdarg.h>
#ifdef __GNUC__
#pragma GCC visibility push(default)
#endif
/**
* @file zmf_utils.h
* @brief ZMF图像转换工具函数
*/
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup ZmfLog
* @brief ZMF模块的日志打印等级
* @{
*/
/**
* @brief
*/
typedef enum {
ZmfLogDebug = 0,
ZmfLogInfo = 1,
ZmfLogWarn = 2,
ZmfLogError = 3,
} ZmfLogLevel;
/**
* @brief zmf的日志系统
* @param iLogLevel @ref ZmfLogLevel
* @param format
* @param argv
* @note
*/
void Zmf_LogV(int iLogLevel, const char *format, va_list argv);
/**
* @}
*/
/**
* @defgroup ZmfVideoType
* @{
*/
/**
* @brief ZMF模块支持的图像类型
*/
typedef enum {
ZmfPixelFormatI420 = 1, /**< @brief YUVI420格式,通道顺序Y-U-V,4:1:1 */
ZmfPixelFormatIYUV = 2, /**< @brief IYUV格式 */
ZmfPixelFormatRGB24 = 3, /**< @brief RGB24格式 */
ZmfPixelFormatABGR = 4, /**< @brief ABGR格式 */
ZmfPixelFormatARGB = 5, /**< @brief ARGB格式 */
ZmfPixelFormatARGB4444 = 6, /**< @brief ARGB4444格式 */
ZmfPixelFormatRGB565 = 7, /**< @brief RGB565格式 */
ZmfPixelFormatARGB1555 = 8, /**< @brief ARGB1555格式 */
ZmfPixelFormatYUY2 = 9, /**< @brief YUY2格式 */
ZmfPixelFormatYV12 = 10, /**< @brief YV12格式 */
ZmfPixelFormatUYVY = 11, /**< @brief UYVY格式 */
ZmfPixelFormatMJPG = 12, /**< @brief Motion JPG格式 */
ZmfPixelFormatNV21 = 13, /**< @brief NV21格式 */
ZmfPixelFormatNV12 = 14, /**< @brief NV12格式 */
ZmfPixelFormatBGRA = 15, /**< @brief BGRA格式 */
ZmfPixelFormatRGBA = 16, /**< @brief RGBA格式 */
} ZmfPixelFormatType;
/**
* @}
*/
/**
* @defgroup ZmfVideoInterface
*
* @{
*/
/**
* @brief I420图像转换成别的类型
* @param dstFrame
* @param dstStride
* @param dstFormat @see ZmfPixelFormatType
* @param srcFrame
* @param srcWidth
* @param srcHeight
* @return int
* dstFormat ZmfPixelFormatMJPG时,\n
* 0: \n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_FMT_ANY: yuv fomat不支持\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* dstFormat ZmfPixelFormatMJPG时,\n
* 0: dstFrame的大小,\n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_FMT_ANY: yuv fomat不支持\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* @see Zmf_ImageFromYV12, Zmf_ConvertToI420, Zmf_ScaleI420, Zmf_MirrorI420UpDown
*/
int Zmf_ImageFromI420 (void* dstFrame, int dstFormat, int dstStride,
const void* srcFrame, int srcWidth, int srcHeight);
///@cond
/** deprecated, use Zmf_ImageFromI420 */
int Zmf_ConvertFromI420 (void* dstFrame, int dstFormat,
const void* srcFrame, int srcWidth, int srcHeight);
///@endcond
/**
* @brief YV12图像转换成别的类型
* @param dstFrame
* @param dstFormat @ref ZmfPixelFormatType
* @param dstStride
* @param srcFrame
* @param srcWidth
* @param srcHeight
* @return int\n
* 0: \n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_FMT_ANY: yuv fomat不支持\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* @see Zmf_ImageFromI420
*/
int Zmf_ImageFromYV12 (void* dstFrame, int dstFormat, int dstStride,
const void* srcFrame, int srcWidth, int srcHeight);
///@cond
/** deprecated, use Zmf_ImageFromYV12 */
int Zmf_ConvertFromYV12 (void* dstFrame, int dstFormat,
const void* srcFrame, int srcWidth, int srcHeight);
///@endcond
/**
* @brief I420
* @param dstFrame
* @param srcFormat @ref ZmfPixelFormatType
* @param srcFrame
* @param srcBufLen
* @param srcWidth
* @param srcHeight
* @param crop_x
* @param crop_y
* @param dstWidth (4)
* @param dstHeight (4)
* @param rotateAngle
* @return int\n
* 0: \n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_FMT_ANY: yuv fomat不支持\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* @see Zmf_ImageFromI420, Zmf_ScaleI420, Zmf_MirrorI420UpDown
*/
int Zmf_ConvertToI420(void* dstFrame,
int srcFormat, const void* srcFrame, unsigned srcBufLen,
int srcWidth, int srcHeight, int crop_x, int crop_y,
int *dstWidth, int *dstHeight, int rotateAngle);
/**
* @brief I420图像类型
*/
typedef struct {
unsigned char *data;
int width, height, angle;
} ZmfI420Image;
/**
* @brief ()
*/
typedef enum {
ZmfAnchorLeftTop = 0,
ZmfAnchorRightTop = 1,
ZmfAnchorLeftBottom = 2,
ZmfAnchorRightBottom = ZmfAnchorRightTop | ZmfAnchorLeftBottom,
ZmfAnchorLeftCenter = 4,
ZmfAnchorTopCenter = 8,
ZmfAnchorRightCenter = ZmfAnchorLeftCenter | ZmfAnchorRightTop,
ZmfAnchorBottomCenter = ZmfAnchorTopCenter | ZmfAnchorLeftBottom,
ZmfAnchorCenter = ZmfAnchorLeftCenter | ZmfAnchorTopCenter
} ZmfAnchorSite;
/**
* I420图像中扣出并转为ABGR图像
*/
int Zmf_BitmapFromI420(
void* bitmap, int stride, int width, int height, ZmfPixelFormatType format,
const ZmfI420Image* i420, int i420OffsetX, int i420OffsetY, ZmfAnchorSite anchor);
/**
* ABGR图像覆盖到 I420图像中
*/
int Zmf_BitmapToI420(
const void* bitmap, int stride, int width, int height, ZmfPixelFormatType format,
const ZmfI420Image* i420, int i420OffsetX, int i420OffsetY, ZmfAnchorSite anchor);
/**
* @brief I420图像
* @param srcFrame
* @param srcWidth
* @param srcHeight
* @param dstFrame
* @param dstWidth
* @param dstHeight
* @return int\n
* 0: \n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* @see Zmf_ConvertToI420, Zmf_ImageFromI420, Zmf_MirrorI420UpDown
*/
int Zmf_ScaleI420(void* srcFrame, int srcWidth, int srcHeight,
void* dstFrame, int dstWidth, int dstHeight);
/**
* @brief I420图像
* @param srcFrame
* @param dstFrame
* @param width
* @param height
* @return int\n
* 0: \n
* -ZMF_ERROR_ARGUMENT_INVALID: \n
* -ZMF_ERROR_YUV_NOT_SUPPORTED:ZMF不支持使用libyuv\n
* -ZMF_ERROR_YUV_LIB_ERROR: libyuv报错\n
* @see Zmf_ConvertToI420, Zmf_ImageFromI420, Zmf_ScaleI420
*/
int Zmf_MirrorI420UpDown(void* srcFrame, void* dstFrame,
int width, int height);
/**
* @brief THEA收集信息的等级枚举
*/
enum ZmfTessarCollectLevel {
ZmfTessarError, /**< @brief 等级为错误的THEA信息 */
ZmfTessarWarn, /**< @brief 等级为警告的THEA信息 */
ZmfTessarImportant, /**< @brief 等级为重要的THEA信息 */
ZmfTessarDebug, /**< @brief 等级为调试的THEA信息 */
};
/**
* @brief THEA收集信息的类型枚举
*/
enum ZmfTessarCollectType {
ZmfTessarData = 0x01,
ZmfTessarEvent = 0x02,
ZmfTessarAll = 0x03,
};
/**
* @brief THEA ID
* @return intTHEA ID的结果\n
* >0: THEA ID\n
* -ZMF_ERROR_TESSAR_ID_FULL: zmf中的THEA ID已满\n
*/
int Zmf_TessarRegister();
/**
* @brief THEA ID
* @param id id, @ref Zmf_TessarRegister
* @note
*/
void Zmf_TessarDeregister(int id);
/**
* @brief THEA字符串(json)
* @param level THEA等级, @ref ZmfTessarCollectLevel
* @param type , @ref ZmfTessarCollectType
* @param id id, @ref Zmf_TessarRegister
* @return const char*, NULL @ref Zmf_GetLastError \n
* :\n
* -ZMF_ERROR_TESSAR_ID_INVALID: id无效\n
* -ZMF_ERROR_TESSAR_UNREGISTERED: id对应的THEA未注册\n
*/
const char* Zmf_GetTessarData(int level, int type, int id);
/**
* @brief THEA数据
* @param keys , @ref TessarKey
* @param values , keys对应
* @param size keys数组大小
* @param flag event=05s内若有相同事件
* @return int
* @retval >=0
* @warning values数组使values数组内容和大小与key对应
*/
int Zmf_TessarRecord(int keys[], int values[], const int size, int flag);
/**
* @brief THEA消息通知回调函数
*
* @param[in] cookie cookie, , NULL
* @param[in] callback , NULL表示取消回调
* @param[in] bError @ref ZmfTessarError
* @param[in] bWarn @ref ZmfTessarWarn
*
* @return
* - 0 :
* - -ZMF_ERROR_PARAM_INVALID : cookie为NULL
*/
int Zmf_TessarSetCallback(void* cookie,
void (*callback)(void* cookie, const int event_code, const char* extend_info, int len),
int bError, int bWarn);
/**
* @brief THEA事件
*
* @param[in] cookie cookie, , NULL
* @param[in] eventCode
*
* @return
* - 0 :
* - -ZMF_ERROR_PARAM_INVALID : cookie为NULL或eventCode<=0
* - -ZMF_ERROR_TESSAR_SUBEVENT_INVALID_COOKIE : @ref Zmf_TessarSetCallback cookie
*/
int Zmf_TessarSubscribeEvent(void* cookie, int eventCode);
/**
* @brief THEA事件
*
* @param[in] cookie cookie, , NULL
* @param[in] eventCode , -1
*
* @return
* - 0 :
* - -ZMF_ERROR_PARAM_INVALID : cookie为NULL
* - -ZMF_ERROR_TESSAR_SUBEVENT_INVALID_COOKIE : @ref Zmf_TessarSetCallback cookie
*
* @remark
* @ref Zmf_TessarSetCallback
* Error等级事件使Error事件依然会上报
*/
int Zmf_TessarUnsubscribeEvent(void* cookie, int eventCode);
/**
* @brief last error
* @param code "[ErrorNumber][DomainCode]."
* @param msg
* @return
*/
int Zmf_GetLastError(char code[16], char msg[2048]);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/**
* @}
*/
#ifdef __GNUC__
#pragma GCC visibility pop
#endif
#endif