Qt君


  • 首页

  • 关于

  • 归档

  • 搜索

QVideoFrame转QImage格式对照表

发表于 2019-03-19

主要为通过查询QVideoFrame::imageFormatFromPixelFormat接口获得QImage格式对照表。

对照表

  • Format_ARGB32
  • Format_ARGB32_Premultiplied
  • Format_RGB32
  • Format_RGB24
  • Format_RGB565
  • Format_RGB555
  • Format_ARGB8565_Premultiplied
  • Format_BGRA32
  • Format_BGRA32_Premultiplied
  • Format_BGR32
  • Format_BGR24
  • Format_BGR565
  • Format_BGR555
  • Format_BGRA5658_Premultiplied
  • Format_AYUV444
  • Format_AYUV444_Premultiplied
  • Format_YUV444
  • Format_YUV420P
  • Format_YV12
  • Format_UYVY
  • Format_YUYV
  • Format_NV12
  • Format_NV21
  • Format_IMC1
  • Format_IMC2
  • Format_IMC3
  • Format_IMC4
  • Format_Y8
  • Format_Y16
  • Format_Jpeg
  • Format_CameraRaw
  • Format_AdobeDng
  • NPixelFormats
  • Format_User

判断代码

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
#include <QApplication>
#include <QVideoFrame>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QList<QImage::Format> imageFormats = {
QImage::Format_Invalid,
QImage::Format_Mono,
QImage::Format_MonoLSB,
QImage::Format_Indexed8,
QImage::Format_RGB32,
QImage::Format_ARGB32,
QImage::Format_ARGB32_Premultiplied,
QImage::Format_RGB16,
QImage::Format_ARGB8565_Premultiplied,
QImage::Format_RGB666,
QImage::Format_ARGB6666_Premultiplied,
QImage::Format_RGB555,
QImage::Format_ARGB8555_Premultiplied,
QImage::Format_RGB888,
QImage::Format_RGB444,
QImage::Format_ARGB4444_Premultiplied,
QImage::Format_RGBX8888,
QImage::Format_RGBA8888,
QImage::Format_RGBA8888_Premultiplied,
QImage::Format_BGR30,
QImage::Format_A2BGR30_Premultiplied,
QImage::Format_RGB30,
QImage::Format_A2RGB30_Premultiplied,
QImage::Format_Alpha8,
QImage::Format_Grayscale8,
QImage::NImageFormats
};

QList<QVideoFrame::PixelFormat> pixelFormats = {
QVideoFrame::Format_Invalid,
QVideoFrame::Format_ARGB32,
QVideoFrame::Format_ARGB32_Premultiplied,
QVideoFrame::Format_RGB32,
QVideoFrame::Format_RGB24,
QVideoFrame::Format_RGB565,
QVideoFrame::Format_RGB555,
QVideoFrame::Format_ARGB8565_Premultiplied,
QVideoFrame::Format_BGRA32,
QVideoFrame::Format_BGRA32_Premultiplied,
QVideoFrame::Format_BGR32,
QVideoFrame::Format_BGR24,
QVideoFrame::Format_BGR565,
QVideoFrame::Format_BGR555,
QVideoFrame::Format_BGRA5658_Premultiplied,

QVideoFrame::Format_AYUV444,
QVideoFrame::Format_AYUV444_Premultiplied,
QVideoFrame::Format_YUV444,
QVideoFrame::Format_YUV420P,
QVideoFrame::Format_YV12,
QVideoFrame::Format_UYVY,
QVideoFrame::Format_YUYV,
QVideoFrame::Format_NV12,
QVideoFrame::Format_NV21,
QVideoFrame::Format_IMC1,
QVideoFrame::Format_IMC2,
QVideoFrame::Format_IMC3,
QVideoFrame::Format_IMC4,
QVideoFrame::Format_Y8,
QVideoFrame::Format_Y16,

QVideoFrame::Format_Jpeg,

QVideoFrame::Format_CameraRaw,
QVideoFrame::Format_AdobeDng,

QVideoFrame::NPixelFormats,
QVideoFrame::Format_User
};

for (int i = 0 ; i < pixelFormats.count(); i++) {
QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(pixelFormats.at(i));
qDebug()<<"|"<<pixelFormats.at(i)<<"|"<<(format ? "YES" : "NO")<<"|";
}

return app.exec();
}

C/C++黑魔法-没有临时值的交换

发表于 2019-03-18

使用XOR异或运算符可以做的一件很酷的事情”没有临时值的交换”。

示例1

1
2
3
a ^= b;
b ^= a;
a ^= b;

示例2

1
a ^= b ^= a ^= b;

示例3

1
2
3
a = a + b;
b = a - b;
a = a - b;

示例4

1
b = (a + b) - ( a = b);

注意

  • 示例3与示例4中使用+运算符(当a+b或a-b超出int类型范围时)可能造成溢出,导致ab变量交换不正确。

为Qt程序添加启动图片

发表于 2019-03-17

有时候程序加载过程中时间过长需要先加载图片以避免黑屏的尴尬。

用法1

  • 在显示splash.png图片过程中执行用户启动程序的初始工作,等待完成后调用finish即可关闭启动图片。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QPixmap pixmap(":/splash.png"); // 装载图片
    QSplashScreen splash(pixmap); // 初始化图片到QSplashScreen
    splash.show(); // 显示图片
    app.processEvents(); // 刷新事件循环
    ...
    QMainWindow window;
    window.show();
    splash.finish(&window); // 完成后自动close
    return app.exec();
    }

用法2

  • 在加载过程中可以调用splash->showMessage("Message");来显示文字;
  • 如果想绘制图形通过设置pixmap的指针或重写void QSplashScreen::drawContents(QPainter *painter)接口即可。

C/C++黑魔法-防御性编程

发表于 2019-03-16

在使用常数作为比较的时候往往会将x == 0写作x = 0,会使得程序陷入错误,由此我们可以使用编译器特性。

  • 使用判断常数在左边0 == x而不是x == 0,使得0 = x可以被捕获为错误;
  • 使用此用法在误写的0 = x时,编译器将始终将”0 = x”标记错误。

解决ptlib库ptlib_config.h不存在的问题

发表于 2019-03-14

解决ptlib_config.h编译不存在的问题,以及使用ptlib库的编译错误。

以下为编译ptlib2.19输出信息

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
1>------ 已启动全部重新生成: 项目: PTLib Static, 配置: Debug Win32 ------
1>Using default getdate bison file.
1>已复制 1 个文件。
1>Configuring Build Options
1>PTLib Configure 1.26 - opened configure.ac
1>Predefine variable "ac_top_build_prefix" as "D:\Document\workspace\ptlib\src\ptlib\msos\../../../Lib/Win32/"
1>Could not open ptlib.pc
1>Could not open ptlib_cfg.dxy
1>Written make/ptlib_config.mak
1>Written D:\Document\workspace\ptlib\src\ptlib\msos\../../../Lib/Win32/include/ptlib_config.h
1>Configuration completed.
1>Updating revision include file.
...
1>Console_2017.vcxproj -> D:\Document\workspace\ptlib\src\ptlib\msos\..\..\..\lib\ptlibsd.lib
2>------ 已启动全部重新生成: 项目: PTLib DLL, 配置: Debug Win32 ------
2>Merging symbols ...
2>MergeSym version 1.12.1 on Windows 10 by Equivalence
2>
2>Symbols merged: 1909 added, 0 removed, 16530 total.
2>dllmain.cxx
2> 正在创建库 D:\Document\workspace\ptlib\src\ptlib\msos\..\..\..\lib\ptlibd.lib 和对象 D:\Document\workspace\ptlib\src\ptlib\msos\..\..\..\lib\ptlibd.exp
2>PTLib_2017.vcxproj -> D:\Document\workspace\ptlib\src\ptlib\msos\..\..\..\lib\ptlibd.dll
3>------ 已启动全部重新生成: 项目: Hello World DLL, 配置: Debug Win32 ------
3>hello.cxx
3>helloDLL_2017.vcxproj -> D:\Document\workspace\ptlib\samples\hello_world\..\..\bin\Hello World DLL\Win32\Debug\Hello World DLL.exe
========== 全部重新生成: 成功 3 个,失败 0 个,跳过 0 个 ==========

使用ptlib库编译程序出错信息

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
include\ptlib\atomic.h(150): warning C4804: “-”: 在操作中使用类型“bool”不安全
include\ptlib\atomic.h(155): error C3861: “_InterlockedAdd”: 找不到标识符
include\ptlib\atomic.h(156): error C3861: “_InterlockedAdd”: 找不到标识符
include\ptlib\atomic.h(156): warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
include\ptlib\atomic.h(157): error C3861: “_InterlockedAdd”: 找不到标识符
include\ptlib\atomic.h(158): error C3861: “_InterlockedAdd”: 找不到标识符
include\ptlib\atomic.h(158): warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
include\ptlib\atomic.h(159): error C3861: “_InterlockedAdd64”: 找不到标识符
include\ptlib\atomic.h(159): error C3861: “_InterlockedExchange64”: 找不到标识符
include\ptlib\atomic.h(159): error C3861: “_InterlockedExchangeAdd64”: 找不到标识符
include\ptlib\atomic.h(160): error C3861: “_InterlockedAdd64”: 找不到标识符
include\ptlib\atomic.h(160): error C3861: “_InterlockedExchange64”: 找不到标识符
include\ptlib\atomic.h(160): error C3861: “_InterlockedExchangeAdd64”: 找不到标识符
include\ptlib\atomic.h(160): warning C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型
include\ptlib/pstring.h(1947): error C2504: “PWCharArray”: 未定义基类
include\ptlib/pstring.h(1954): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
include\ptlib/pstring.h(1954): error C2143: 语法错误: 缺少“,”(在“&”的前面)
include\ptlib/pstring.h(1948): error C2664: “PObject::Comparison PObject::InternalCompareObjectMemoryDirect(const PObject *,const PObject *,int)”: 无法将参数 1 从“const PWideString *”转换为“const PObject *”
include\ptlib/pstring.h(1948): note: 与指向的类型无关;强制转换要求 reinterpret_cast、C 样式强制转换或函数样式强制转换
include\ptlib/pstring.h(1954): error C2065: “arr”: 未声明的标识符
include\ptlib/pstring.h(1954): error C2614: “PWideString”: 非法的成员初始化:“PWCharArray”不是基或成员
include\ptlib/pstring.h(1955): error C2039: “AsUCS2”: 不是“PString”的成员
include\ptlib/pstring.h(110): note: 参见“PString”的声明
include\ptlib/pstring.h(1955): error C2614: “PWideString”: 非法的成员初始化:“PWCharArray”不是基或成员
include\ptlib/pstring.h(1957): error C2653: “PWCharArray”: 不是类或命名空间名称
include\ptlib/pstring.h(1958): error C2653: “PWCharArray”: 不是类或命名空间名称
include\ptlib/pstring.h(1958): error C2039: “AsUCS2”: 不是“PString”的成员
include\ptlib/pstring.h(110): note: 参见“PString”的声明
include\ptlib/pstring.h(1961): error C2440: “<function-style-cast>”: 无法从“const PWideString”转换为“PString”
include\ptlib/pstring.h(1961): note: 无构造函数可以接受源类型,或构造函数重载决策不明确
include\ptlib/pstring.h(1963): error C3861: “GetSize”: 找不到标识符
include\ptlib/pstring.h(1966): error C2614: “PWideString”: 非法的成员初始化:“PWCharArray”不是基或成员
include\ptlib/pstring.h(2156): error C2039: “AsUCS2”: 不是“PConstantString<PString>”的成员
include\ptlib/pstring.h(2148): note: 参见“PConstantString<PString>”的声明
include\ptlib/pstring.h(2156): error C2614: “PWideString”: 非法的成员初始化:“PWCharArray”不是基或成员
include\ptlib/pstring.h(2157): error C2653: “PWCharArray”: 不是类或命名空间名称
include\ptlib/pstring.h(2157): error C2039: “AsUCS2”: 不是“PConstantString<PString>”的成员
include\ptlib/pstring.h(2148): note: 参见“PConstantString<PString>”的声明
include\ptlib/pstring.h(2158): error C2653: “PWCharArray”: 不是类或命名空间名称
include\ptlib/pstring.h(2158): error C2039: “AsUCS2”: 不是“PConstantString<PString>”的成员
include\ptlib/pstring.h(2148): note: 参见“PConstantString<PString>”的声明

解决问题

  • 编译ptlib会根据系统编译器产生新的ptlib_config.h文件;

    1
    Written D:\Document\workspace\ptlib\src\ptlib\msos\../../../Lib/Win32/include/ptlib_config.h
  • 一般路径为:

    1
    ptlib\lib\Win32\include\ptlib_config.h
  • 需要注意的是不可直接修改ptlib_config.h.in文件,不然会可能导致以上的编译出错信息。

    1
    ptlib\include\ptlib_config.h.in

解决使用ptlib库编译"realloc"参数不足问题

发表于 2019-03-13

解决使用ptlib库导致的编译错误qlist.h(98): warning C4003: 类函数宏的调用“realloc”参数不足的问题。

编译错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qlist.h(98): warning C4003: 类函数宏的调用“realloc”参数不足
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qlist.h(98): error C2059: 语法错误:“,”
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qlist.h(98): error C3254: “QListData”: 类包含显式重写“Reallocate”,但并不从包含函数声明的接口派生
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qlist.h(98): error C2838: “Reallocate”: 成员声明中的限定名称非法
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qlist.h(577): warning C4003: 类函数宏的调用“realloc”参数不足
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(244): error C2059: 语法错误:“字符串”
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(260): note: 参见对正在编译的 类 模板 实例化 "QVarLengthArray<T,Prealloc>" 的引用
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(244): error C3254: “QVarLengthArray<T,Prealloc>”: 类包含显式重写“Reallocate”,但并不从包含函数声明的接口派生
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(244): error C2838: “Reallocate”: 成员声明中的限定名称非法
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(362): warning C4346: “QVarLengthArray<T,Prealloc>::PMemoryHeap::Reallocate”: 依赖名称不是类型
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(362): note: 用“typename”为前缀来表示类型
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(362): error C2988: 不可识别的模板声明/定义
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(362): error C2059: 语法错误:“字符串”
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(363): error C2063: “Reallocate”: 不是一个函数
D:\Qt\Qt5.12.1\5.12.1\msvc2017\include\QtCore/qvarlengtharray.h(363): error C2226: 语法错误: 意外的“QVarLengthArray<T,Prealloc>::PMemoryHeap::Reallocate”类型

问题分析

  • 由于使用了ptlib库编译,编译错误又提示类函数宏的调用“realloc”参数不足的问题,就查找了一下ptlib关于realloc的接口;
  • 找到ptlib下的object.h头文件包含以下宏定义;
    1
    2
    3
    4
    5
    6
    7
    /** Override of system call for memory check system.
    This macro is used to allocate memory via the memory check system selected
    with the <code>PMEMORY_CHECK</code> compile time option. It will include the source file
    and line into the memory allocation to allow the PMemoryHeap class to keep
    track of the memory block.
    */
    #define realloc(p,s) PMemoryHeap::Reallocate(p, s, __FILE__, __LINE__)

解决问题

  • 在引用ptlib的头文件下使用使用undef宏定义解开realloc即可解决。
    1
    #undef realloc(p,s)

关于编译器C2838与C3254的错误代码

  • C3254为”explicit override”类包含显式重写”override”,但并不从包含函数声明的接口派生;
  • C2838为类、结构或联合使用完全限定名重新声明另一个类、结构或联合的成员。

QtCreator配置环境变量

发表于 2019-03-12

使用QtCreator编译程序往往会出现一些编译的问题(库路径或头文件路径找不到),QtCreator可以配置环境变量以解决一些上述的问题。

1. 进入Projects(项目)

enter_projects

2. 点击Details(详情)

details

3. 如有需要可以清除系统环境变量

envir

4. 找到INCLUDE与LIB进行设置

include_lib

5.如需要修改或添加其他变量在右侧按钮设置即可

Linux命令之火车来了

发表于 2019-03-11

使用sl命令在Linux终端开出火车动画

  • 安装sl命令

    1
    sudo apt install sl
  • 运行sl命令

  • 效果
    linux_sl_command.gif

C/C++黑魔法-编译期运行的sizeof

发表于 2019-03-10

本文介绍sizeof内执行的表达式会在编译期运行

  • 看下列示例输出i++没有被执行,最后的打印依然为0;
  • 从这个示例可以看出,sizeof内不建议使用表达式。
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>

int main(int argc, char *argv[])
{
int i = 0;
printf("%d\n", sizeof(i++)); // 输出: 4
printf("%d\n", i); // 输出: 0

return 0;
}

关于更多

  • 文章首发于微信公众号你才小学生(nicaixiaoxuesheng)
  • 后续更新于Qtbig哥(qtbig.com)

C/C++黑魔法-不会出错的http

发表于 2019-03-09

作者在编写代码中无意加入一组URL,编译通过了。
在C99标准中,可以直接将URL嵌入到函数内的源代码中。
为什么能这样呢?原因在于使用了goto语法,http:为跳转到的地方。

1
2
3
4
5
6
#include <stdio.h>

int main(int argc, char** argv) {
http://qtbig.com/
printf("Hello World");
}

关于更多

  • 文章首发于微信公众号你才小学生(nicaixiaoxuesheng)
  • 后续更新于Qtbig哥(qtbig.com)
1…252627…32
Qt君

Qt君

313 日志
41 标签
© 2019 Qt君
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4
粤ICP备 - 16070052号