# danfekete/bmp2c architecture

> Architecture diagram of the GitHub repository danfekete/bmp2c, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danfekete/bmp2c
- Repository: https://github.com/danfekete/bmp2c

## Overview

bmp2c is a command-line bitmap-to-C-data converter. Its main workflow parses options and an input path, reads a bitmap, prepares grayscale pixels, converts them to a monochrome image with optional Floyd–Steinberg dithering, run-length encodes the result, and writes a C header. An optional test mode decodes the compressed bitmap through a drawing callback for display. The README is empty; relationships below are based on the shown main routine and source-index references, so unsampled behavior is not inferred.

Main entry points: [`src/buffer.c`](https://github.com/danfekete/bmp2c/blob/master/src/buffer.c) (Color buffer), [`src/rle.c`](https://github.com/danfekete/bmp2c/blob/master/src/rle.c) (RLE encoder), [`src/bmp.c`](https://github.com/danfekete/bmp2c/blob/master/src/bmp.c) (BMP reader), [`src/mono.c`](https://github.com/danfekete/bmp2c/blob/master/src/mono.c) (Monochrome processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input and options"]
  node_arguments["Option parser<br/>[argparse.c]"]
  node_bitmap["BMP reader<br/>[bmp.c]"]
end

subgraph group_image["Image processing"]
  node_colorbuffer["Color buffer<br/>[buffer.c]"]
  node_color["Color conversion<br/>[color.c]"]
  node_monochrome["Monochrome processing<br/>[mono.c]"]
end

subgraph group_output["Encoding and output"]
  node_rle["RLE encoder<br/>[rle.c]"]
  node_header["Header writer<br/>[h_writer.c]"]
  node_draw["Test renderer<br/>[draw.c]"]
end

node_user(("CLI user"))
node_display["Display callback<br/>[main.c]"]

node_user -->|"provides options"| node_arguments
node_arguments -.->|"selects input"| node_bitmap
node_user -->|"provides bitmap"| node_bitmap
node_bitmap -->|"returns pixels"| node_colorbuffer
node_colorbuffer -->|"uses color data"| node_color
node_colorbuffer -->|"supplies pixels"| node_monochrome
node_user -->|"runs conversion"| node_monochrome
node_monochrome -->|"encodes pixels"| node_rle
node_rle -->|"writes encoded data"| node_header
node_rle -->|"decodes for test"| node_draw
node_draw -.->|"calls callback"| node_display

click node_arguments "https://github.com/danfekete/bmp2c/blob/master/argparse/argparse.c"
click node_bitmap "https://github.com/danfekete/bmp2c/blob/master/src/bmp.c"
click node_colorbuffer "https://github.com/danfekete/bmp2c/blob/master/src/buffer.c"
click node_color "https://github.com/danfekete/bmp2c/blob/master/src/color.c"
click node_monochrome "https://github.com/danfekete/bmp2c/blob/master/src/mono.c"
click node_rle "https://github.com/danfekete/bmp2c/blob/master/src/rle.c"
click node_header "https://github.com/danfekete/bmp2c/blob/master/src/h_writer.c"
click node_draw "https://github.com/danfekete/bmp2c/blob/master/src/draw.c"
click node_display "https://github.com/danfekete/bmp2c/blob/master/src/main.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_arguments,node_bitmap,node_user toneBlue
class node_colorbuffer,node_color,node_monochrome toneAmber
class node_rle,node_header,node_draw toneMint
class node_display toneTeal
```

## Components

### Input and options

- [Option parser](https://github.com/danfekete/bmp2c/blob/master/argparse/argparse.c): `argparse/argparse.c`
- [BMP reader](https://github.com/danfekete/bmp2c/blob/master/src/bmp.c): `src/bmp.c`

### Image processing

- [Color buffer](https://github.com/danfekete/bmp2c/blob/master/src/buffer.c): `src/buffer.c`
- [Color conversion](https://github.com/danfekete/bmp2c/blob/master/src/color.c): `src/color.c`
- [Monochrome processing](https://github.com/danfekete/bmp2c/blob/master/src/mono.c): `src/mono.c`

### Encoding and output

- [RLE encoder](https://github.com/danfekete/bmp2c/blob/master/src/rle.c): `src/rle.c`
- [Header writer](https://github.com/danfekete/bmp2c/blob/master/src/h_writer.c): `src/h_writer.c`
- [Test renderer](https://github.com/danfekete/bmp2c/blob/master/src/draw.c): `src/draw.c`

### Other components

- **CLI user**
- [Display callback](https://github.com/danfekete/bmp2c/blob/master/src/main.c): `src/main.c`

## Connections

- CLI user → Option parser: provides options
- Option parser → BMP reader: selects input
- CLI user → BMP reader: provides bitmap
- BMP reader → Color buffer: returns pixels (evidence: `src/bmp.c`)
- Color buffer → Color conversion: uses color data
- Color buffer → Monochrome processing: supplies pixels (evidence: `src/mono.c`)
- CLI user → Monochrome processing: runs conversion
- Monochrome processing → RLE encoder: encodes pixels (evidence: `src/rle.c`)
- RLE encoder → Header writer: writes encoded data
- RLE encoder → Test renderer: decodes for test
- Test renderer → Display callback: calls callback
