Skip to content

Commit 793e399

Browse files
CopilotLeeGoDamn
authored andcommitted
feat: Add ccap CLI tool with camera enumeration, capture, and format conversion
Introduce a new command-line interface (CLI) tool 'ccap' that provides comprehensive camera control and image capture capabilities. This addition enables users to interact with camera devices directly from the command line. Key features: - Camera device enumeration with detailed information display - Image capture with configurable frame count and output directory - Multi-format support: BMP, PNG, JPEG, and internal raw formats - Cross-platform compatibility (Linux, macOS, Windows) - Wuffs integration for efficient image encoding - Preview functionality using native camera APIs Implementation details: - Add CLI module with CMakeLists.txt build configuration - Implement ccap_cli.cpp with command parsing and execution logic - Add ccap_cli.h header with CLI interface definitions - Integrate ccap_cli_wuffs.cpp for image format handling - Update root CMakeLists.txt to include CLI target - Apply code review feedback: fix texture upload, improve string bounds checking, and simplify wuffs implementation Command-line options: --help, -h Display usage information --list-devices, -l List all available camera devices --device, -d <id> Select camera device by ID (default: 0) --capture, -c <count> Capture specified number of frames --output, -o <path> Set output directory for captured images --format, -f <fmt> Set output format (bmp, png, jpeg, internal) --preview, -p Enable camera preview window Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com>
1 parent 1866c61 commit 793e399

5 files changed

Lines changed: 1175 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ if(CCAP_BUILD_EXAMPLES)
229229
include(examples/desktop.cmake)
230230
endif()
231231

232+
# ############### CLI Tool ################
233+
option(CCAP_BUILD_CLI "Build ccap CLI tool" ${CCAP_IS_ROOT_PROJECT})
234+
message(STATUS "ccap: CCAP_BUILD_CLI=${CCAP_BUILD_CLI}")
235+
236+
if(CCAP_BUILD_CLI)
237+
add_subdirectory(cli)
238+
endif()
239+
232240
# ############### Tests ################
233241
message(STATUS "ccap: CCAP_BUILD_TESTS=${CCAP_BUILD_TESTS}")
234242

cli/CMakeLists.txt

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# cli/CMakeLists.txt
2+
# CMake configuration for ccap CLI tool
3+
cmake_minimum_required(VERSION 3.14)
4+
5+
# CLI-specific options (only available when building CLI)
6+
option(CCAP_CLI_WITH_GLFW "Enable GLFW window preview for CLI tool" ON)
7+
option(CCAP_CLI_WITH_WUFFS "Enable wuffs library for additional image format support" OFF)
8+
9+
message(STATUS "ccap CLI: CCAP_CLI_WITH_GLFW=${CCAP_CLI_WITH_GLFW}")
10+
message(STATUS "ccap CLI: CCAP_CLI_WITH_WUFFS=${CCAP_CLI_WITH_WUFFS}")
11+
12+
set(CLI_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
13+
14+
# CLI source files
15+
set(CLI_SOURCES
16+
${CLI_SOURCE_DIR}/ccap_cli.cpp
17+
)
18+
19+
# Add wuffs source if enabled
20+
if(CCAP_CLI_WITH_WUFFS)
21+
list(APPEND CLI_SOURCES ${CLI_SOURCE_DIR}/ccap_cli_wuffs.cpp)
22+
endif()
23+
24+
# Create CLI executable
25+
add_executable(ccap_tool ${CLI_SOURCES})
26+
27+
# Set output name to 'ccap' for the CLI tool
28+
set_target_properties(ccap_tool PROPERTIES
29+
OUTPUT_NAME "ccap"
30+
CXX_STANDARD 17
31+
CXX_STANDARD_REQUIRED ON
32+
)
33+
34+
# Link against ccap library
35+
target_link_libraries(ccap_tool PRIVATE ccap)
36+
37+
# Include directories
38+
target_include_directories(ccap_tool PRIVATE
39+
${CMAKE_SOURCE_DIR}/include
40+
${CLI_SOURCE_DIR}
41+
)
42+
43+
# Compile definitions
44+
target_compile_definitions(ccap_tool PRIVATE
45+
_CRT_SECURE_NO_WARNINGS=1
46+
)
47+
48+
# GLFW setup for preview functionality
49+
if(CCAP_CLI_WITH_GLFW)
50+
set(GLFW_CLI_AVAILABLE OFF)
51+
52+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
53+
# Try to find system GLFW on Linux
54+
find_package(glfw3 QUIET)
55+
if(glfw3_FOUND)
56+
set(GLFW_CLI_AVAILABLE ON)
57+
set(GLFW_CLI_TARGET glfw)
58+
message(STATUS "ccap CLI: Using system GLFW")
59+
else()
60+
message(STATUS "ccap CLI: System GLFW not found. Install with: sudo apt-get install libglfw3-dev")
61+
message(STATUS "ccap CLI: GLFW preview will be disabled")
62+
endif()
63+
else()
64+
# On non-Linux platforms, check if GLFW is already available from examples
65+
if(TARGET glfw)
66+
set(GLFW_CLI_AVAILABLE ON)
67+
set(GLFW_CLI_TARGET glfw)
68+
message(STATUS "ccap CLI: Using GLFW from examples")
69+
else()
70+
# Fetch GLFW ourselves
71+
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
72+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
73+
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
74+
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
75+
76+
# Use bundled GLFW from examples
77+
set(GLFW_DIR ${CMAKE_SOURCE_DIR}/examples/desktop/glfw)
78+
if(EXISTS ${GLFW_DIR}/CMakeLists.txt)
79+
add_subdirectory(${GLFW_DIR} ${CMAKE_BINARY_DIR}/glfw_cli EXCLUDE_FROM_ALL)
80+
set(GLFW_CLI_AVAILABLE ON)
81+
set(GLFW_CLI_TARGET glfw)
82+
message(STATUS "ccap CLI: Using bundled GLFW from examples")
83+
else()
84+
message(STATUS "ccap CLI: GLFW not found. Preview disabled.")
85+
endif()
86+
endif()
87+
endif()
88+
89+
if(GLFW_CLI_AVAILABLE)
90+
target_compile_definitions(ccap_tool PRIVATE CCAP_CLI_WITH_GLFW=1)
91+
target_link_libraries(ccap_tool PRIVATE ${GLFW_CLI_TARGET})
92+
93+
# Include GLAD and GLFW headers
94+
target_include_directories(ccap_tool PRIVATE
95+
${CMAKE_SOURCE_DIR}/examples/desktop/glad
96+
${CMAKE_SOURCE_DIR}/examples/desktop/glfw/include
97+
${CMAKE_SOURCE_DIR}/examples/desktop
98+
)
99+
100+
# Platform-specific OpenGL linking
101+
if(APPLE)
102+
target_link_libraries(ccap_tool PRIVATE "-framework OpenGL")
103+
elseif(WIN32)
104+
target_link_libraries(ccap_tool PRIVATE opengl32)
105+
endif()
106+
107+
message(STATUS "ccap CLI: GLFW preview enabled")
108+
else()
109+
message(STATUS "ccap CLI: GLFW preview disabled")
110+
endif()
111+
endif()
112+
113+
# Wuffs setup for additional image format support
114+
if(CCAP_CLI_WITH_WUFFS)
115+
include(FetchContent)
116+
117+
message(STATUS "ccap CLI: Fetching wuffs library...")
118+
119+
FetchContent_Declare(
120+
wuffs
121+
GIT_REPOSITORY https://github.com/google/wuffs.git
122+
GIT_TAG v0.4.0-alpha.8
123+
EXCLUDE_FROM_ALL
124+
)
125+
126+
FetchContent_MakeAvailable(wuffs)
127+
128+
target_compile_definitions(ccap_tool PRIVATE CCAP_CLI_WITH_WUFFS=1)
129+
target_include_directories(ccap_tool PRIVATE ${wuffs_SOURCE_DIR}/release/c)
130+
131+
message(STATUS "ccap CLI: wuffs library enabled for additional image formats")
132+
endif()
133+
134+
# MSVC-specific settings
135+
if(MSVC)
136+
target_compile_options(ccap_tool PRIVATE
137+
/MP
138+
/std:c++17
139+
/Zc:__cplusplus
140+
/Zc:preprocessor
141+
/source-charset:utf-8
142+
/wd4996
143+
)
144+
else()
145+
target_compile_options(ccap_tool PRIVATE
146+
-std=c++17
147+
)
148+
endif()
149+
150+
# Installation
151+
if(CCAP_INSTALL)
152+
install(TARGETS ccap_tool
153+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
154+
)
155+
endif()

0 commit comments

Comments
 (0)