# munmaks/pgm-compressor architecture

> Architecture diagram of the GitHub repository munmaks/pgm-compressor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/munmaks/pgm-compressor
- Repository: https://github.com/munmaks/pgm-compressor

## Overview

##### Project Type and Purpose
- This project is a command‐line image compressor/decompressor written in C. Its primary function is to compress images in PGM format into a QTC format (using a quadtree-based algorithm) and to perform the reverse operation.
- The README describes options for compression (with adjustable filtering via an “alpha” parameter), decompression, and additional functionalities such as displaying the segmentation grid.

##### Analyzing the File Structure
- Top-Level Files/Folders:
– “src” contains the core implementation files (e.g., main.c, bits_operations.c, grid.c, option.c, pixmap.c, qtree.c).
– “include” holds the corresponding header files that declare the functions and types used across modules.
– “docs” includes Doxygen-generated documentation that further explains each component.
– “PGM” and “QTC” directories likely serve as default output locations for decompressed and compressed images, respectively.
– The makefile and Doxyfile are present for building the project and generating docs.
- Architectural Clues:
– The existence of modules such as “qtree” (handling the quadtree algorithm), “grid” (handling segmentation grid functions), “pixmap” (managing image pixel data), and “option” (dealing with command-line options) reflects a modular design that separates input/output handling, image data manipulation, and the core compression/decompression algorithms.
– The structure suggests a layered approach: a layer responsible for interfacing with the user (main.c & command-line options), a core image processing layer (using modules in src and include), and a presentation/utility layer (e.g., grid for visualization, bits_operations for low-level processing).

a. Main Components:
- Command-Line Interface (CLI) Module:
- Represented by main.c, it parses command-line arguments (compression vs. decompression modes, options like –a, –g, etc.).
- Compression/Decompression Engine:
- Contains the core processes that route input to either the compression algorithm (quadtree construction, optional filtering, grid segmentation) or decompression algorithm.
- Input/Output Handlers:
- Modules that read/write PGM and QTC files.
- Use the “PGM” and “QTC” directories for default output file locations.
- Core Modules:
- Qtree: Implements the quadtree building and traversal (qtree.c / qtree.h).
- Pixmap: Handles image representation (pixmap.c / pixmap.h).
- Grid: Manages segmentation or display grid for image partitioning (grid.c / grid.h).
- Option: Deals with command-line option parsing and configuration (option.c / option.h).
- Bits Operations: Contains low-level manipulations used during image processing.
b. Relationships and Interactions:
- That the engine interacts with the input/output modules (reading a PGM file when compressing or reading a QTC file when decompressing and then writing the result to the respective output directory).
- Optionally, illustrate the dependency of the filtering mechanism (activated by the –a option) on the image processing pipeline.
c. Architectural Patterns:
- Modular design: Each functionality (file I/O, quadtree processing, image manipulation) is encapsulated in its own module.
- Separation of concerns: The CLI and core processing engines are clearly separated.
- Layered approach: The “presentation” of results (grid output for segmentation) is decoupled from the compression algorithm.
d. Relevant Technologies and Tools:
- The project is written in C using modules compiled together by a makefile.
- Doxygen is utilized for documentation.
- The compiler (gcc) and make (build automation) are essential external tools.

##### Elements
- “CLI/Main Controller”
- “Compression Engine”
- “Decompression Engine”
- “Quadtree Module” (qtree)
- “Pixmap Module”
- “Grid Module”
- “Option Parsing Module”
- “Bits Operations Utility”
- “Input/Output Handlers” (for PGM and QTC files)
- Annotations such as “adjust filtering (alpha parameter)”, “build via make”, and “default output directories (PGM, QTC)” to provide clarity.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Subsystem
    subgraph "User Interface"
        CLI["CLI/Main Controller"]:::ui
        Option["Option Parsing Module"]:::ui
    end

    %% Core Processing Subsystem
    subgraph "Core Processing"
        Engine["Compression/Decompression Engine"]:::core
        Pixmap["Pixmap Module"]:::core
        Qtree["Quadtree Module"]:::core
        Bits["Bits Operations Utility"]:::core
        Grid["Grid Module"]:::core
    end

    %% File I/O Subsystem
    subgraph "File I/O"
        PGM["Input/Output Handlers for PGM Files"]:::io
        QTC["Input/Output Handlers for QTC Files"]:::io
    end

    %% Build and Documentation Subsystem
    subgraph "Build & Documentation"
        Makefile["Build (makefile)"]:::build
        Docs["Documentation (Doxyfile & docs)"]:::build
    end

    %% Connections between subsystems
    CLI --> Option
    Option --> Engine
    Engine --> Pixmap
    Pixmap --> Qtree
    Qtree --> Bits
    Bits --> Grid
    Grid --> PGM
    Grid --> QTC

    %% Click Events
    click CLI "https://github.com/munmaks/pgm-compressor/blob/main/src/main.c"
    click Option "https://github.com/munmaks/pgm-compressor/blob/main/src/option.c"
    click Option "https://github.com/munmaks/pgm-compressor/blob/main/include/option.h"
    click Qtree "https://github.com/munmaks/pgm-compressor/blob/main/src/qtree.c"
    click Qtree "https://github.com/munmaks/pgm-compressor/blob/main/include/qtree.h"
    click Pixmap "https://github.com/munmaks/pgm-compressor/blob/main/src/pixmap.c"
    click Pixmap "https://github.com/munmaks/pgm-compressor/blob/main/include/pixmap.h"
    click Grid "https://github.com/munmaks/pgm-compressor/blob/main/src/grid.c"
    click Grid "https://github.com/munmaks/pgm-compressor/blob/main/include/grid.h"
    click Bits "https://github.com/munmaks/pgm-compressor/blob/main/src/bits_operations.c"
    click Bits "https://github.com/munmaks/pgm-compressor/blob/main/include/bits_operations.h"
    click PGM "https://github.com/munmaks/pgm-compressor/tree/main/PGM"
    click QTC "https://github.com/munmaks/pgm-compressor/tree/main/QTC"
    click Makefile "https://github.com/munmaks/pgm-compressor/tree/main/makefile"
    click Docs "https://github.com/munmaks/pgm-compressor/tree/main/Doxyfile"
    click Docs "https://github.com/munmaks/pgm-compressor/tree/main/docs"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef core fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef io fill:#ABEBC6,stroke:#229954,stroke-width:2px;
    classDef build fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
```
