# cnlohr/vpxcoding architecture

> Architecture diagram of the GitHub repository cnlohr/vpxcoding, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cnlohr/vpxcoding
- Repository: https://github.com/cnlohr/vpxcoding

## Overview

**┌─ Input Processing ─┐  ┌─ Arithmetic Coding Core ─┐  ┌─ Output Processing ─┐**
- Bitstream Input  │→ │ - Encoding Logic         │→ │ - Compressed Output │
- Probability Data │  │ - Decoding Logic         │  │ - Stream Management │
- ┘   └──────────────────────────┘  └──────────────────┘

##### Detailed Component Breakdown

**Encoding Pipeline (Blue):**
**┌─ Writer Interface ─────┐**
- vpx_start_encode()     │
- vpx_write()            │→ Compressed
- vpx_stop_encode()      │   Bitstream
- ┘

**Decoding Pipeline (Green):**
**┌─ Reader Interface ─────┐**
- vpx_reader_init()      │
- vpx_read()             │→ Decoded
- vpx_reader_has_error() │   Bitstream
- ┘

##### Technical Details

**┌─ Technical Specifications ──────┐**
- 256-byte norm table          │
- Probability range: 0-255     │
- Optional VPXCODING_NOTABLE   │
- Memory-efficient design      │
- ┘

##### Key Elements to Highlight

- Performance metrics from README:
- Encoding: 42.653 MB/s
- Decoding: 29.758 MB/s
- Code size: ~768 bytes per operation

##### Implementation Details

**┌─ Configuration Options ─┐**
- #define VPXCODING_WRITER│
- #define VPXCODING_READER│
- ┘

**┌─ Probability Calculation ───────────────┐**
- probability = probability01 * 257 - 0.5 │
- (Bounded between 0 and 255)            │
- ┘

- → Data Flow            │
- ⇢ Optional Path        │
- □ Core Component       │
- ○ Interface Point      │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        BitInput["Bitstream Input"]
        ProbData["Probability Data"]
    end

    subgraph Core["Arithmetic Coding Core"]
        EncLogic["Encoding Logic"]
        DecLogic["Decoding Logic"]
        NormTable["256-byte Norm Table"]
    end

    subgraph Output
        CompOut["Compressed Output"]
        StreamMgmt["Stream Management"]
    end

    subgraph EncodingPipeline["Encoding Pipeline"]
        WriterAPI["Writer Interface"]:::api
        StartEnc["vpx_start_encode()"]
        Write["vpx_write()"]
        StopEnc["vpx_stop_encode()"]
    end

    subgraph DecodingPipeline["Decoding Pipeline"]
        ReaderAPI["Reader Interface"]:::api
        ReadInit["vpx_reader_init()"]
        Read["vpx_read()"]
        ReadError["vpx_reader_has_error()"]
    end

    subgraph Config["Configuration"]
        ConfigOpts["Configuration Options"]:::config
        DefWriter["#define VPXCODING_WRITER"]
        DefReader["#define VPXCODING_READER"]
    end

    subgraph Performance["Performance Metrics"]
        EncPerf["Encoding: 42.653 MB/s"]
        DecPerf["Decoding: 29.758 MB/s"]
        CodeSize["Code Size: ~768 bytes/op"]
    end

    subgraph ProbCalc["Probability Calculation"]
        Formula["probability = probability01 * 257 - 0.5"]
        Bounds["Bounded: 0-255"]
    end

    BitInput --> EncLogic
    ProbData --> EncLogic
    EncLogic --> CompOut
    CompOut --> StreamMgmt

    BitInput --> DecLogic
    ProbData --> DecLogic
    DecLogic --> StreamMgmt

    WriterAPI --> EncLogic
    StartEnc --> Write
    Write --> StopEnc

    ReaderAPI --> DecLogic
    ReadInit --> Read
    Read --> ReadError

    DefWriter --> ConfigOpts
    DefReader --> ConfigOpts

    NormTable -.-> EncLogic
    NormTable -.-> DecLogic

    %% Styling
    classDef api fill:#f9f,stroke:#333,stroke-width:2px
    classDef config fill:#fcf,stroke:#333,stroke-width:1px
    classDef core fill:#cfe,stroke:#333,stroke-width:2px

    %% Click events
    click Core "https://github.com/cnlohr/vpxcoding/blob/master/vpxcoding.h"
    click EncodingPipeline "https://github.com/cnlohr/vpxcoding/blob/master/vpxcoding.h"
    click DecodingPipeline "https://github.com/cnlohr/vpxcoding/blob/master/vpxcoding.h"
    click Performance "https://github.com/cnlohr/vpxcoding/blob/master/bittester.c"
    click Config "https://github.com/cnlohr/vpxcoding/tree/master/Makefile"
```
