Skip to content

Commit bf05d08

Browse files
CopilotLeeGoDamnwysaid
authored
Enhance web documentation design, download section, and markdown-based docs (#33)
* Initial plan * Enhance web documentation with GLFW-style design and download section Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * Fix code review issues: XSS prevention, error handling, event parameter Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * Address additional code review feedback: remove unused variable, fix deprecated API Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * Fix language switching and convert docs to markdown-based rendering Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * Improve security and performance of markdown documentation loading Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * Add DOMPurify for XSS protection in markdown rendering Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> * docs: reorganize README layout following best practices - Move official website link to description section with blockquote - Keep badge row for project status only (CI, license, language, platform) - Remove workflow badges from website (docs/index.html) - Follow GLFW/SDL/OpenCV layout best practices * Enhance documentation with syntax highlighting and improved styling - Add Highlight.js (vs2015 theme) for syntax highlighting - Replace hardcoded HTML spans with library-based highlighting - Add language modules: cpp, c, bash, shell, cmake - Update documentation page styling - Set overall background to #E8E8E8 (light grey) - Set code blocks to #1E1E1E (dark grey, VSCode style) - Set sidebar to #F5F5F5 - Remove CSS color inheritance that was blocking syntax colors - Improve Installation section display - Change to fixed 2-column layout for better readability - Increase card padding and font sizes - Optimize to prevent horizontal scrolling - Fix language tags - Change 'cmd' to 'shell' in markdown files - Add shell language module to support Windows commands * fix: improve documentation page and API robustness Fixes identified in PR code review: **docs/js/main.js:** - Improve platform asset classification using regex word boundaries instead of indexOf() to avoid substring conflicts (e.g., 'darwin-linux' misclassification) - Add cache expiration mechanism (1 hour) for GitHub API responses to show latest release information - Enhance URL validation to restrict to HTTPS and authorized GitHub domains (github.com, github.io, githubusercontent.com) **docs/documentation.html:** - Fix footer documentation links to point to correct GitHub file locations instead of non-existent local markdown files - Add ARIA labels (role='navigation', aria-label) for better accessibility - Implement slugify() function to generate stable heading IDs from text (e.g., 'C++ API Reference' -> 'cpp-api-reference') for durable anchor links - Improve error messages with context-specific feedback (network vs file not found) - Fix missing closing brace in generateSidebar() function - Optimize sidebar navigation to make all headings clickable without duplication **README.md:** - Restore 'Dual Language APIs' feature description (was commented out) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: LeeGoDamn <243561453+LeeGoDamn@users.noreply.github.com> Co-authored-by: wangyang (wysaid) <wysaid@gmail.com>
1 parent e198969 commit bf05d08

8 files changed

Lines changed: 2172 additions & 570 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
A high-performance, lightweight cross-platform camera capture library with hardware-accelerated pixel format conversion, providing complete C++ and pure C language interfaces.
1414

15+
> 🌐 **Official Website:** [ccap.work](https://ccap.work)
16+
1517
## Table of Contents
1618

1719
- [Features](#features)
@@ -29,7 +31,7 @@ A high-performance, lightweight cross-platform camera capture library with hardw
2931
- **Lightweight**: Zero external dependencies - uses only system frameworks
3032
- **Cross Platform**: Windows (DirectShow), macOS/iOS (AVFoundation), Linux (V4L2)
3133
- **Multiple Formats**: RGB, BGR, YUV (NV12/I420) with automatic conversion
32-
- **Dual Language APIs**: ✨ **New Complete Pure C Interface** - Both modern C++ API and traditional C99 interface for various project integration and language bindings
34+
- **Dual Language APIs**: ✨ **Complete Pure C Interface** - Both modern C++ API and traditional C99 interface for various project integration and language bindings
3335
- **Production Ready**: Comprehensive test suite with 95%+ accuracy validation
3436
- **Virtual Camera Support**: Compatible with OBS Virtual Camera and similar tools
3537

README.zh-CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
高性能、轻量级的跨平台相机捕获库,支持硬件加速的像素格式转换,提供完整的 C++ 和纯 C 语言接口。
1414

15+
> 🌐 **官方网站:** [ccap.work](https://ccap.work)
16+
1517
## 目录
1618

1719
- [特性](#特性)

docs/content/documentation.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# ccap Documentation
2+
3+
**ccap** is a high-performance, lightweight cross-platform camera capture library with hardware-accelerated pixel format conversion. It provides both modern C++ and pure C99 interfaces for maximum compatibility.
4+
5+
## Key Features
6+
7+
- Zero external dependencies - uses only system frameworks
8+
- Hardware-accelerated format conversion (AVX2, Apple Accelerate, NEON)
9+
- Cross-platform: Windows, macOS, iOS, Linux
10+
- Dual API: Modern C++17 and pure C99
11+
12+
## Installation
13+
14+
### Build from Source
15+
16+
```bash
17+
git clone https://github.com/wysaid/CameraCapture.git
18+
cd CameraCapture
19+
./scripts/build_and_install.sh
20+
```
21+
22+
### CMake FetchContent
23+
24+
```cmake
25+
include(FetchContent)
26+
FetchContent_Declare(
27+
ccap
28+
GIT_REPOSITORY https://github.com/wysaid/CameraCapture.git
29+
GIT_TAG main
30+
)
31+
FetchContent_MakeAvailable(ccap)
32+
33+
target_link_libraries(your_app PRIVATE ccap::ccap)
34+
```
35+
36+
### Homebrew (macOS)
37+
38+
```bash
39+
brew tap wysaid/ccap
40+
brew install ccap
41+
```
42+
43+
## Basic Usage
44+
45+
### C++ Example
46+
47+
```cpp
48+
#include <ccap.h>
49+
50+
int main() {
51+
ccap::Provider provider;
52+
53+
// List available cameras
54+
auto devices = provider.findDeviceNames();
55+
for (size_t i = 0; i < devices.size(); ++i) {
56+
printf("[%zu] %s\n", i, devices[i].c_str());
57+
}
58+
59+
// Open and start camera
60+
if (provider.open("", true)) {
61+
auto frame = provider.grab(3000);
62+
if (frame) {
63+
printf("Captured: %dx%d\n", frame->width, frame->height);
64+
}
65+
}
66+
return 0;
67+
}
68+
```
69+
70+
## C++ API Reference
71+
72+
### ccap::Provider
73+
74+
```cpp
75+
class Provider {
76+
public:
77+
// Device discovery
78+
std::vector<std::string> findDeviceNames();
79+
80+
// Device management
81+
bool open(std::string_view deviceName, bool autoStart = true);
82+
bool open(int deviceIndex, bool autoStart = true);
83+
bool isOpened() const;
84+
void close();
85+
86+
// Capture control
87+
bool start();
88+
void stop();
89+
bool isStarted() const;
90+
91+
// Frame capture
92+
std::shared_ptr<VideoFrame> grab(uint32_t timeoutInMs = 0xffffffff);
93+
void setNewFrameCallback(std::function<bool(const std::shared_ptr<VideoFrame>&)> callback);
94+
95+
// Property configuration
96+
bool set(PropertyName prop, double value);
97+
template<class T> bool set(PropertyName prop, T value);
98+
double get(PropertyName prop);
99+
100+
// Device info
101+
std::optional<DeviceInfo> getDeviceInfo() const;
102+
};
103+
```
104+
105+
### ccap::VideoFrame
106+
107+
```cpp
108+
struct VideoFrame {
109+
uint8_t* data[3] = {}; // Raw pixel data planes
110+
uint32_t stride[3] = {}; // Stride for each plane
111+
112+
PixelFormat pixelFormat = PixelFormat::Unknown;
113+
uint32_t width = 0;
114+
uint32_t height = 0;
115+
uint32_t sizeInBytes = 0;
116+
uint64_t timestamp = 0; // Timestamp in nanoseconds
117+
uint64_t frameIndex = 0;
118+
FrameOrientation orientation = FrameOrientation::Default;
119+
120+
std::shared_ptr<Allocator> allocator;
121+
void* nativeHandle = nullptr;
122+
};
123+
```
124+
125+
### Property Configuration
126+
127+
```cpp
128+
// Set specific resolution
129+
provider.set(ccap::PropertyName::Width, 1920);
130+
provider.set(ccap::PropertyName::Height, 1080);
131+
132+
// Set camera's internal format
133+
provider.set(ccap::PropertyName::PixelFormatInternal,
134+
static_cast<double>(ccap::PixelFormat::NV12));
135+
136+
// Set camera's output format
137+
provider.set(ccap::PropertyName::PixelFormatOutput,
138+
static_cast<double>(ccap::PixelFormat::BGR24));
139+
```
140+
141+
## OpenCV Integration
142+
143+
```cpp
144+
#include <ccap_opencv.h>
145+
146+
auto frame = provider.grab();
147+
cv::Mat mat = ccap::convertRgbFrameToMat(*frame);
148+
```
149+
150+
## Properties
151+
152+
| Property | Description |
153+
|----------|-------------|
154+
| `Width` | Frame width in pixels |
155+
| `Height` | Frame height in pixels |
156+
| `FrameRate` | Capture frame rate |
157+
| `PixelFormatInternal` | Camera's internal pixel format |
158+
| `PixelFormatOutput` | Output pixel format (with conversion) |
159+
| `FrameOrientation` | Frame orientation/rotation |
160+
161+
## Pixel Formats
162+
163+
| Format | Description |
164+
|--------|-------------|
165+
| `NV12` | YUV 4:2:0 semi-planar |
166+
| `NV12f` | YUV 4:2:0 semi-planar (full range) |
167+
| `I420` | YUV 4:2:0 planar |
168+
| `I420f` | YUV 4:2:0 planar (full range) |
169+
| `RGB24` | 24-bit RGB |
170+
| `BGR24` | 24-bit BGR |
171+
| `RGBA32` | 32-bit RGBA |
172+
| `BGRA32` | 32-bit BGRA |
173+
174+
## Platform Guides
175+
176+
### Windows
177+
178+
Uses DirectShow for camera access. Requires MSVC 2019 or later.
179+
180+
```shell
181+
cl your_code.c /I"path\to\ccap\include" ^
182+
/link "path\to\ccap\lib\ccap.lib" ole32.lib oleaut32.lib uuid.lib
183+
```
184+
185+
### macOS
186+
187+
Uses AVFoundation for camera access. Requires Xcode 11+ and macOS 10.13+.
188+
189+
```bash
190+
gcc -std=c99 your_code.c -o your_app \
191+
-I/path/to/ccap/include \
192+
-L/path/to/ccap/lib -lccap \
193+
-framework Foundation -framework AVFoundation \
194+
-framework CoreMedia -framework CoreVideo
195+
```
196+
197+
### Linux
198+
199+
Uses V4L2 for camera access. Requires GCC 7+ or Clang 6+.
200+
201+
```bash
202+
gcc -std=c99 your_code.c -o your_app \
203+
-I/path/to/ccap/include \
204+
-L/path/to/ccap/lib -lccap \
205+
-lpthread
206+
```
207+
208+
### iOS
209+
210+
Uses AVFoundation for camera access. Requires Xcode 11+ and iOS 13.0+.
211+
212+
**CocoaPods:**
213+
214+
```ruby
215+
pod 'ccap'
216+
```
217+
218+
**Camera Permission** - Add the following to your Info.plist:
219+
220+
```xml
221+
<key>NSCameraUsageDescription</key>
222+
<string>This app requires camera access to capture video.</string>
223+
```

0 commit comments

Comments
 (0)