forked from KangLin/RabbitIm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tool.h
134 lines (112 loc) · 5.4 KB
/
Tool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef TOOL_H
#define TOOL_H
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
#pragma execution_character_set("utf-8")
#endif
extern "C" {
#include "libswscale/swscale.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
}
#include <QWidget>
#include <QVideoFrame>
#include "qxmpp/QXmppRtpChannel.h"
#ifdef RABBITIM_USER_OPENCV
#include "opencv2/opencv.hpp"
#endif
class CTool : public QObject
{
Q_OBJECT
public:
explicit CTool(QObject *parent = 0);
~CTool();
public:
//设置ffmpeg日志输出
static int SetFFmpegLog();
/* 格式转换
* 如果转换成功,则调用者使用完 outFrame 后,需要调用 avpicture_free(&outFrame) 释放内存
* 成功返回0,不成功返回非0 */
static int ConvertFormat(/*[in]*/const QVideoFrame &inFrame, /* 要转换的帧 */
/*[out]*/AVPicture &outFrame, /* 转换后的帧 */
/*[in]*/int nOutWidth, /* 转换后的帧的宽度 */
/*[in]*/int nOutHeight, /* 转换后的帧的高度 */
/*[in]*/AVPixelFormat pixelFormat = AV_PIX_FMT_RGB32);
static int ConvertFormat(/*[in]*/const QXmppVideoFrame &inFrame, /* 要转换的帧 */
/*[out]*/AVPicture &outFrame, /* 转换后的帧 */
/*[in]*/int nOutWidth, /* 转换后的帧的宽度 */
/*[in]*/int nOutHeight, /* 转换后的帧的高度 */
/*[in]*/AVPixelFormat pixelFormat = AV_PIX_FMT_RGB32);
static int ConvertFormat(const AVPicture &inFrame, /* 要转换的帧 */
int nInWidth, /* 要转换的帧的宽度 */
int nInHeight, /* 要转换的帧的高度 */
AVPixelFormat inPixelFormat, /* 要转换的帧的格式 */
AVPicture &outFrame, /* 转换后的帧 */
int nOutWidth, /* 转换后的帧的宽度 */
int nOutHeight, /* 转换后的帧的高度 */
AVPixelFormat outPixelFormat); /* 转换后的帧的格式 */
//格式映射
static AVPixelFormat QVideoFrameFormatToFFMpegPixFormat(const QVideoFrame::PixelFormat format);
static AVPixelFormat QXmppVideoFrameFormatToFFMpegPixFormat(const QXmppVideoFrame::PixelFormat format);
#ifdef RABBITIM_USER_OPENCV
/* 对图像进行旋转
* 参数:
* src:源图像
* _cneter:旋转中心
* angle:角度
* 返回值:旋转后的图像 */
static cv::Mat ImageRotate(cv::Mat & src, const CvPoint &_center, double angle);
#endif
/* 对YUV420sp(NV12、NV21)存储格式的图像旋转+-90度
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度
* mode=1为顺时针旋转90度,mode=-1为逆时针旋转90度 */
static void YUV420spRotate90(uchar *dst, const uchar *src, int srcWidth, int srcHeight, int mode);
/* 对YUV420sp(NV12、NV21)存储格式的图像旋转90度
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度 */
static void YUV420spRotate90(uchar *dst, const uchar *src, int srcWidth, int srcHeight);
/* 对YUV420sp(NV12、NV21)存储格式的图像旋转-90度
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度 */
static void YUV420spRotateNegative90(uchar *dst, const uchar *src, int srcWidth, int srcHeight);
/* 对YUV420sp(NV12、NV21)存储格式的图像做镜像
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度
* mode=1为x轴镜像,mode=0为y轴镜像,mode=-1为x、y轴都镜像。 */
static void YUV420spMirror(uchar* dst, const uchar *src, int srcWidth, int srcHeight, int mode = 0);
/* 以Y轴做镜像
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度 */
static void YUV420spMirrorY(uchar *dst, const uchar *src, int srcWidth, int srcHeight);
/* 以XY轴做镜像
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度 */
static void YUV420spMirrorXY(uchar *dst, const uchar *src, int srcWidth, int srcHeight);
/* 以X轴做镜像
* dst:操作后的图像
* src:要操作的图像
* srcWidth:要操作图像的宽度
* srcHeight:要操作图像的高度 */
static void YUV420spMirrorX(uchar *dst, const uchar *src, int srcWidth, int srcHeight);
//设置窗口中的所有子窗体背景为透明
static int SetAllChildrenTransparent(QWidget *pWin);
/*获取字节数的大小文本,例如1024返回1B;20140711
* size:字节大小
* prec:精度,小数的保留的位数 */
static QString GetSizeString(qint64 size, int prec = 2);
signals:
public slots:
};
#endif // TOOL_H