yuv2rgb 项目使用教程
1. 项目的目录结构及介绍
yuv2rgb/
├── CMakeLists.txt
├── LICENSE
├── README.md
├── include/
│ └── yuv2rgb.h
├── src/
│ ├── main.c
│ └── yuv2rgb.c
└── tests/
└── test_yuv2rgb.c
- CMakeLists.txt: 用于构建项目的CMake配置文件。
- LICENSE: 项目的许可证文件。
- README.md: 项目的基本介绍和使用说明。
- include/: 包含项目的头文件。
- yuv2rgb.h: 定义了yuv2rgb转换的接口。
- src/: 包含项目的源代码文件。
- main.c: 项目的启动文件。
- yuv2rgb.c: yuv2rgb转换的实现代码。
- tests/: 包含项目的测试代码。
- test_yuv2rgb.c: yuv2rgb转换的测试代码。
2. 项目的启动文件介绍
项目的启动文件是 src/main.c
。这个文件包含了程序的入口点 main
函数,负责初始化和调用yuv2rgb转换功能。以下是 main.c
的主要内容:
#include <stdio.h>
#include "yuv2rgb.h"
int main(int argc, char *argv[]) {
if (argc < 4) {
fprintf(stderr, "Usage: %s <input_yuv_file> <output_rgb_file> <width> <height>\n", argv[0]);
return 1;
}
const char *input_file = argv[1];
const char *output_file = argv[2];
int width = atoi(argv[3]);
int height = atoi(argv[4]);
if (convert_yuv_to_rgb(input_file, output_file, width, height) != 0) {
fprintf(stderr, "Failed to convert YUV to RGB\n");
return 1;
}
printf("Conversion successful!\n");
return 0;
}
3. 项目的配置文件介绍
项目使用 CMakeLists.txt
作为构建配置文件。以下是 CMakeLists.txt
的主要内容:
cmake_minimum_required(VERSION 3.10)
project(yuv2rgb)
set(CMAKE_C_STANDARD 99)
include_directories(include)
add_executable(yuv2rgb src/main.c src/yuv2rgb.c)
enable_testing()
add_executable(test_yuv2rgb tests/test_yuv2rgb.c src/yuv2rgb.c)
add_test(NAME test_yuv2rgb COMMAND test_yuv2rgb)
- cmake_minimum_required: 指定所需的CMake最低版本。
- project: 定义项目名称。
- set(CMAKE_C_STANDARD 99): 设置C语言标准为C99。
- include_directories(include): 包含头文件目录。
- add_executable: 定义可执行文件及其源代码文件。
- enable_testing: 启用测试功能。
- add_executable(test_yuv2rgb ...): 定义测试可执行文件及其源代码文件。
- add_test: 添加测试命令。