Skip to content

Commit e101d01

Browse files
committed
added bw,bw_dot,colored,colored_dot,interactive noninteractive play. and also added custom media file pi and pv with encription(not as powerful as cryptographic encription though
1 parent 6e4b036 commit e101d01

11 files changed

Lines changed: 4972 additions & 1436 deletions

File tree

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ if(PYTHONIC_ENABLE_OPENCL)
108108
endif()
109109
endif()
110110

111+
# ============================================================================
112+
# Optional: OpenCV for image/video processing and webcam support
113+
# ============================================================================
114+
option(PYTHONIC_ENABLE_OPENCV "Enable OpenCV for advanced image/video processing and webcam support" OFF)
115+
116+
if(PYTHONIC_ENABLE_OPENCV)
117+
find_package(OpenCV QUIET COMPONENTS core imgproc videoio imgcodecs)
118+
if(OpenCV_FOUND)
119+
message(STATUS "Found OpenCV: ${OpenCV_VERSION}")
120+
message(STATUS " OpenCV image/video processing enabled")
121+
message(STATUS " Webcam capture enabled")
122+
set(PYTHONIC_OPENCV_FOUND TRUE)
123+
else()
124+
message(WARNING "OpenCV not found. OpenCV features disabled.")
125+
message(STATUS " Install OpenCV: sudo apt install libopencv-dev (Ubuntu)")
126+
message(STATUS " Or: brew install opencv (macOS)")
127+
set(PYTHONIC_ENABLE_OPENCV OFF)
128+
endif()
129+
endif()
130+
111131
# Create a library
112132
add_library(pythonic src/pythonicDispatchStubs.cpp)
113133

@@ -136,6 +156,13 @@ if(PYTHONIC_OPENCL_FOUND)
136156
target_link_libraries(pythonic PUBLIC ${OpenCL_LIBRARIES})
137157
endif()
138158

159+
# Link OpenCV if enabled
160+
if(PYTHONIC_OPENCV_FOUND)
161+
target_compile_definitions(pythonic PUBLIC PYTHONIC_ENABLE_OPENCV)
162+
target_include_directories(pythonic PUBLIC ${OpenCV_INCLUDE_DIRS})
163+
target_link_libraries(pythonic PUBLIC ${OpenCV_LIBS})
164+
endif()
165+
139166
# Precompiled headers to speed up compilation
140167
target_precompile_headers(pythonic PRIVATE
141168
<algorithm>

README.md

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,30 @@ brew install imagemagick ffmpeg
9797
#include <pythonic/pythonic.hpp>
9898
using namespace Pythonic;
9999

100-
// Print image in braille (black & white)
100+
// Print image in braille (black & white, high resolution)
101101
print("photo.png", Type::image);
102102

103-
// Print image in true color
104-
print("photo.png", Type::image, Render::colored);
103+
// Print image in true color (block characters)
104+
print("photo.png", Type::image, Mode::colored);
105+
106+
// Print image in colored braille (combines color + high resolution)
107+
print("photo.png", Type::image, Mode::colored_dot);
105108

106109
// Play video in true color
107-
print("video.mp4", Type::video, Render::colored);
110+
print("video.mp4", Type::video, Mode::colored);
108111
```
109112
113+
### Rendering Modes
114+
115+
Pythonic supports four rendering modes for images and videos:
116+
117+
| Mode | Description | Resolution | Colors |
118+
| ------------------- | --------------------------- | ---------------------- | ------------------------------ |
119+
| `Mode::bw_dot` | Braille patterns (default) | 8x terminal resolution | B&W |
120+
| `Mode::bw` | Block characters (▀▄█) | 2x terminal resolution | B&W |
121+
| `Mode::colored` | Block characters with color | 2x terminal resolution | True color |
122+
| `Mode::colored_dot` | Braille with color | 8x terminal resolution | True color (averaged per cell) |
123+
110124
## Optional: Audio Playback for Videos
111125
112126
To play videos with synchronized audio, you need SDL2 or PortAudio:
@@ -160,10 +174,10 @@ Use in code:
160174
using namespace Pythonic;
161175

162176
// Play video with audio
163-
print("video.mp4", Type::video, Render::BW, Audio::on);
177+
print("video.mp4", Type::video, Mode::bw_dot, Parser::default_parser, Audio::on);
164178

165179
// Play video with audio in true color
166-
print("video.mp4", Type::video, Render::colored, Audio::on);
180+
print("video.mp4", Type::video, Mode::colored, Parser::default_parser, Audio::on);
167181
```
168182
169183
> **Note:** If audio libraries are not available, `Audio::on` will automatically fall back to silent video playback.
@@ -197,6 +211,82 @@ cmake --build build
197211

198212
> **Note:** OpenCL support is optional. If not available, video rendering will use CPU with optimized buffering.
199213
214+
## Optional: OpenCV for Webcam and Advanced Processing
215+
216+
For webcam capture and advanced image/video processing, you can enable OpenCV support:
217+
218+
### Ubuntu/Debian:
219+
220+
```bash
221+
sudo apt-get install libopencv-dev
222+
```
223+
224+
### macOS:
225+
226+
```bash
227+
brew install opencv
228+
```
229+
230+
### Windows (vcpkg):
231+
232+
```bash
233+
vcpkg install opencv:x64-windows
234+
```
235+
236+
Then build with OpenCV support:
237+
238+
```bash
239+
cmake -B build -DPYTHONIC_ENABLE_OPENCV=ON
240+
cmake --build build
241+
```
242+
243+
Use in code:
244+
245+
```cpp
246+
#include <pythonic/pythonic.hpp>
247+
using namespace Pythonic;
248+
249+
// Capture from webcam (requires OpenCV)
250+
print("0", Type::webcam); // Use device 0
251+
print("/dev/video0", Type::webcam); // Linux device path
252+
253+
// Use OpenCV backend for image/video processing
254+
print("photo.png", Type::image, Mode::colored, Parser::opencv);
255+
print("video.mp4", Type::video, Mode::colored_dot, Parser::opencv);
256+
```
257+
258+
### Parser Backends
259+
260+
| Parser | Description | Supports |
261+
| ------------------------ | -------------------------------------------------- | -------------------- |
262+
| `Parser::default_parser` | FFmpeg for video, ImageMagick for images (default) | All media formats |
263+
| `Parser::opencv` | OpenCV for everything | Media files + webcam |
264+
265+
> **Note:** Webcam capture always requires OpenCV. If OpenCV is not available, an exception is thrown for webcam sources.
266+
267+
## Proprietary Media Format (.pi, .pv)
268+
269+
Pythonic includes a media encryption system for protecting images and videos:
270+
271+
```cpp
272+
#include <pythonic/pythonicMedia.hpp>
273+
using namespace pythonic::media;
274+
275+
// Convert image to encrypted Pythonic format
276+
convert("photo.jpg"); // Creates photo.pi
277+
278+
// Convert video to encrypted Pythonic format
279+
convert("video.mp4"); // Creates video.pv
280+
281+
// Revert back to original format
282+
revert("photo.pi"); // Creates photo_restored.jpg
283+
revert("video.pv"); // Creates video_restored.mp4
284+
285+
// Print encrypted files directly (auto-detected)
286+
print("photo.pi"); // Works like original image
287+
print("video.pv"); // Works like original video
288+
```
289+
200290
## Disclaimer:
201291

202292
We’re looking for users to test the library and provide feedback!

0 commit comments

Comments
 (0)