How cod-e-codes/ascii-colorizer works
Purpose and Entry Points
ascii-colorizer is a Rust CLI that renders image files or video frames as ANSI-colored ASCII art. The executable entry point is src/main.rs; reusable conversion and playback logic is exposed from src/lib.rs. Cargo package/build metadata is in Cargo.toml.
CLI Orchestration
The CLI accepts an input path, dimensions, character-detail mode, color mode, output destination, media type override, and video FPS. It selects image or video processing based on explicit --type or automatic detection, then routes output either to the terminal or a saved text file. Primary paths: src/main.rs, src/lib.rs.
Image Conversion Pipeline
For images, the application loads a supported raster format, resizes it to the requested character dimensions (respecting optional height limits), converts pixels to luminance/ASCII glyphs, and emits either TrueColor ANSI sequences or uncolored text. This is the direct single-render path implemented in src/lib.rs.
Video Streaming and Playback
Video input is decoded externally through ffmpeg, with metadata or probing supplied by ffprobe. Frames are processed incrementally rather than loaded as a full video; pixel and ASCII buffers are reused to reduce allocation during live playback. Each frame follows the same resize/color/ASCII conversion path as images. Core integration boundary: src/lib.rs.
Terminal and File Output Boundary
Live video rendering writes frames to an alternate terminal screen, controls timing at the chosen FPS, and restores terminal state on completion or Ctrl+C. Saved video output is serialized as text frames separated by form-feed characters. Image rendering can similarly target stdout or a file. Terminal ANSI support is a runtime requirement; TrueColor is preferred. Paths: src/main.rs, src/lib.rs.
Runtime Dependencies and Distribution
The binary runs on Rust-supported Windows, Linux, and macOS targets. Video processing requires ffmpeg and ffprobe available on PATH; image decoding is handled by Rust dependencies declared in Cargo.toml. CI validates builds/tests on pushes and pull requests through .github/workflows/ci.yml; tagged releases build platform archives and publish GitHub Release assets via .github/workflows/release.yml.
Main entry points: lib.rs Frame playback processing · Cargo.toml Cargo package · main.rs CLI entry point · ci.yml Build and test CI
Components 13
Rust application
- Cargo package · Declares Rust image dependencies and the CLI package.
Cargo.toml - CLI entry point · Parses options and selects media processing and destination.
src/main.rs - Conversion library · Exposes reusable rendering and playback logic.
src/lib.rs - Media type routing · Uses an override or automatic detection to choose image or video flow.
src/main.rs
Media processing
- Raster image load · Loads supported image formats through Rust dependencies.
src/lib.rs - Resize and ASCII render · Resizes pixels, maps luminance to glyphs, and optionally adds TrueColor ANSI.
src/lib.rs - Video metadata probe · Uses ffprobe from PATH to inspect video input.
src/lib.rs - Incremental frame decode · Streams frames from ffmpeg rather than loading the full video.
src/lib.rs - Frame playback processing · Reuses pixel and ASCII buffers while rendering each decoded frame.
src/lib.rs
Output targets
- Terminal playback · Uses an alternate screen, FPS timing, and cleanup on completion or Ctrl+C.
src/lib.rs - Text file output · Writes images as text or video frames separated by form feeds.
src/lib.rs
Build and release
- Build and test CI · Validates pushes and pull requests on supported targets.
.github/workflows/ci.yml - Release publishing · Builds platform archives and publishes tagged release assets.
.github/workflows/release.yml
Connections 16
- Cargo package → CLI entry point: builds
- Cargo package → Conversion library: links
- CLI entry point → Media type routing: input and options
- CLI entry point → Conversion library: invokes
- Media type routing → Raster image load: image input
- Media type routing → Video metadata probe: video input
- Raster image load → Resize and ASCII render: pixels
- Video metadata probe → Incremental frame decode: metadata
- Incremental frame decode → Frame playback processing: decoded frames
- Frame playback processing → Resize and ASCII render: frame pixels
- Resize and ASCII render → Terminal playback: ANSI or text
- Resize and ASCII render → Text file output: single image text
- Frame playback processing → Terminal playback: timed frame output
- Frame playback processing → Text file output: form-feed frames
- Build and test CI → Cargo package: builds and tests
- Release publishing → Cargo package: builds archives