# cameramanben/lutcalc architecture

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

- Interactive diagram: https://gitdiagram.com/cameramanben/lutcalc
- Repository: https://github.com/cameramanben/lutcalc

## Overview

##### Main Components
- User Interface (UI) Layer:
- Represented by HTML files (index.html, indexunminified.html, window.html) and CSS (style.css, mobile.css, etc.).
- The UI is built up from multiple JavaScript UI modules (e.g., lutcamerabox.js, lutgammabox.js, luttweaksbox.js, lutanalyst.js, lutlutbox.js, lutgeneratebox.js, lutpreview.js, lutinfobox.js) that handle camera selection, gamma/gamut options, tweaking controls, and previewing LUT output.
- LUT Calculation and Processing Layer:
- Core calculation logic is implemented in lutcalc.js along with helper and functional scripts such as lut.js (for LUT interpolation & splitting), gamma.js, colourspace.js, and specialized adjustment scripts (the twk-*.js files).
- LUT Input/Output (I/O) and Parsing Layer:
- Multiple JavaScript modules handle LUT file formats (e.g., lut-cube.js, lut-davinci.js, lut-3dl.js, lut-lut.js, lut-spi1d.js, lut-spi3d.js, lut-la.js, lutformats.js) for converting between 1D/3D files and their in-memory representations.
- File Handling, Saving and External Integration:
- External helper libraries (FileSaver.js from the filesaver directory and Blob.js from the blob directory) that work with file saving and binary blob data.
- Binary Data Resources:
- The LUT binary files (e.g., LC709.labin, LC709A.labin, V709.labin, cpoutdaylight.labin, cpouttungsten.labin, s709.labin) that contain pre-calculated LUT data.
- External Resources / Dependencies:
- External code (like FileSaver.js and Blob.js) and references to technical standards for gamma and gamut transformations (as noted in the README) could be marked as “Reference Data & External Libraries.”

##### Component Relationships and Data Flows
- The UI layer receives user input (like selecting camera and adjusting tweaks) and triggers events.
- These UI modules call into the core LUT calculation modules or delegate computations to the Web Worker pool via lutmessage.js.
- The LUT processing modules (using functions in lut.js, gamma.js, colourspace.js, etc.) use algorithms like cubic/tricubic interpolation to compute LUT values.
- Once computation is finished, the LUT I/O modules parse and format the results into various output formats (.cube, .3dl, .ilut, .olut, etc.).
- The file handling and saving modules, supported by FileSaver.js and Blob.js, then enable the user to download or save the LUT files.

##### Architectural Patterns and Design Choices
- Modular Design: The project splits the code into distinct modules based on functionality (UI controls, computation, file I/O).
- Separation of Concerns: Each component (interface, processing, file management) is handled by dedicated modules.
- Asynchronous Processing: Usage of web workers demonstrates the adoption of parallel computation to improve performance in generating LUTs.
- Extensibility: The distinct modules for various LUT formats and adjustments suggest that adding new file types or transformation models can be done in isolation.
- Integration of External Libraries: Leveraging FileSaver.js and Blob.js as well as incorporating industry-standard information for camera gamuts and gamma corrections.

##### Technologies, Frameworks, and Libraries
- The project is purely based on HTML5, JavaScript, and CSS – typical for single-page web applications.
- Utilizes Web Workers for parallel processing.
- External libraries include FileSaver.js and Blob.js.
- References to technical gamma/gamut specifications and industry LUT standards inform the processing algorithms.

##### Elements
- Clear labels: Each block should be clearly labeled (e.g., “UI Components”, “Calculation Engine”, “Web Workers”, “LUT Parsers & Formatters”, “File Handling & External Libraries”).
- Interaction paths: Especially note how the UI interacts with Web Workers and then how the computation results flow to the file saving modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        subgraph "HTML & CSS"
            A1["index.html"]:::ui
            A2["indexunminified.html"]:::ui
            A3["window.html"]:::ui
            A4["style.css"]:::ui
            A5["mobile.css"]:::ui
        end
        subgraph "UI JavaScript Modules"
            B1["lutcamerabox.js"]:::ui
            B2["lutgammabox.js"]:::ui
            B3["luttweaksbox.js"]:::ui
            B4["lutanalyst.js"]:::ui
            B5["lutlutbox.js"]:::ui
            B6["lutgeneratebox.js"]:::ui
            B7["lutpreview.js"]:::ui
            B8["lutinfobox.js"]:::ui
        end
    end

    subgraph "LUT Calculation & Processing Layer"
        subgraph "Core Calculation"
            C1["lutcalc.js"]:::calc
            C2["lut.js"]:::calc
            C3["gamma.js"]:::calc
            C4["colourspace.js"]:::calc
        end
        subgraph "Tweaks/Adjustment Scripts"
            D1["twk-asccdl.js"]:::tweaks
            D2["twk-blank.js"]:::tweaks
            D3["twk-blkgam.js"]:::tweaks
            D4["twk-blkhi.js"]:::tweaks
            D5["twk-cs.js"]:::tweaks
            D6["twk-display.js"]:::tweaks
            D7["twk-fc.js"]:::tweaks
            D8["twk-gamlim.js"]:::tweaks
            D9["twk-hg.js"]:::tweaks
            D10["twk-knee.js"]:::tweaks
            D11["twk-la.js"]:::tweaks
            D12["twk-multi.js"]:::tweaks
            D13["twk-psstcdl.js"]:::tweaks
            D14["twk-sampler.js"]:::tweaks
            D15["twk-sdrsat.js"]:::tweaks
            D16["twk-white.js"]:::tweaks
        end
        subgraph "Web Worker Pool"
            E1["colourspaceworker.js"]:::workers
            E2["gammaworker.js"]:::workers
            E3["lutmessage.js"]:::workers
        end
    end

    subgraph "LUT I/O & Parsing Layer"
        F1["lut-cube.js"]:::io
        F2["lut-davinci.js"]:::io
        F3["lut-3dl.js"]:::io
        F4["lut-lut.js"]:::io
        F5["lut-spi1d.js"]:::io
        F6["lut-spi3d.js"]:::io
        F7["lut-la.js"]:::io
        F8["lutformats.js"]:::io
        F9["lutfile.js"]:::io
    end

    subgraph "File Handling & External Integration"
        G1["FileSaver.js"]:::filefill
        G2["Blob.js"]:::filefill
    end

    subgraph "Binary Data Resources"
        H1["AlexaX2.labin"]:::binary
        H2["Amira709.labin"]:::binary
        H3["Cine709.labin"]:::binary
        H4["LC709.labin"]:::binary
        H5["LC709A.labin"]:::binary
        H6["V709.labin"]:::binary
        H7["cpoutdaylight.labin"]:::binary
        H8["cpouttungsten.labin"]:::binary
        H9["s709.labin"]:::binary
    end

    %% Data Flow Arrows
    %% UI to Calculation
    B1 -->|"triggers"| C1
    B2 -->|"triggers"| C1
    B3 -->|"triggers adjustments"| D1
    B4 -->|"analyzes LUT"| C1
    B5 -->|"configures LUT"| C1
    B6 -->|"initiates generation"| C1
    B7 -->|"requests preview"| C1
    B8 -->|"displays info"| C1

    %% UI to Web Workers
    B1 -->|"delegates task"| E3
    B2 -->|"delegates task"| E3

    %% Tweaks influence Core Calculation
    D1 -->|"adjusts"| C1
    D2 -->|"adjusts"| C1
    D3 -->|"adjusts"| C1
    D4 -->|"adjusts"| C1
    D5 -->|"adjusts"| C1
    D6 -->|"adjusts"| C1
    D7 -->|"adjusts"| C1
    D8 -->|"adjusts"| C1
    D9 -->|"adjusts"| C1
    D10 -->|"adjusts"| C1
    D11 -->|"adjusts"| C1
    D12 -->|"adjusts"| C1
    D13 -->|"adjusts"| C1
    D14 -->|"adjusts"| C1
    D15 -->|"adjusts"| C1
    D16 -->|"adjusts"| C1

    %% Core Calculation to LUT I/O & Parsing
    C1 -->|"formats output"| F1
    C1 -->|"formats output"| F2
    C1 -->|"formats output"| F3
    C1 -->|"formats output"| F4
    C1 -->|"formats output"| F5
    C1 -->|"formats output"| F6
    C1 -->|"formats output"| F7
    C1 -->|"formats output"| F8
    C1 -->|"formats output"| F9

    %% LUT I/O to File Handling
    F1 -->|"sends file"| G1
    F2 -->|"sends file"| G1
    F3 -->|"sends file"| G1
    F4 -->|"sends file"| G1
    F5 -->|"sends file"| G1
    F6 -->|"sends file"| G1
    F7 -->|"sends file"| G1
    F8 -->|"sends file"| G1
    F9 -->|"sends file"| G1

    %% Binary Data Resources to Core Calculation
    H1 -->|"provides LUT data"| C1
    H2 -->|"provides LUT data"| C1
    H3 -->|"provides LUT data"| C1
    H4 -->|"provides LUT data"| C1
    H5 -->|"provides LUT data"| C1
    H6 -->|"provides LUT data"| C1
    H7 -->|"provides LUT data"| C1
    H8 -->|"provides LUT data"| C1
    H9 -->|"provides LUT data"| C1

    %% Click Events for UI Layer
    click A1 "https://github.com/cameramanben/lutcalc/blob/master/index.html"
    click A2 "https://github.com/cameramanben/lutcalc/blob/master/indexunminified.html"
    click A3 "https://github.com/cameramanben/lutcalc/blob/master/window.html"
    click A4 "https://github.com/cameramanben/lutcalc/blob/master/style.css"
    click A5 "https://github.com/cameramanben/lutcalc/blob/master/mobile.css"
    click B1 "https://github.com/cameramanben/lutcalc/blob/master/js/lutcamerabox.js"
    click B2 "https://github.com/cameramanben/lutcalc/blob/master/js/lutgammabox.js"
    click B3 "https://github.com/cameramanben/lutcalc/blob/master/js/luttweaksbox.js"
    click B4 "https://github.com/cameramanben/lutcalc/blob/master/js/lutanalyst.js"
    click B5 "https://github.com/cameramanben/lutcalc/blob/master/js/lutlutbox.js"
    click B6 "https://github.com/cameramanben/lutcalc/blob/master/js/lutgeneratebox.js"
    click B7 "https://github.com/cameramanben/lutcalc/blob/master/js/lutpreview.js"
    click B8 "https://github.com/cameramanben/lutcalc/blob/master/js/lutinfobox.js"

    %% Click Events for LUT Calculation and Processing Layer
    click C1 "https://github.com/cameramanben/lutcalc/blob/master/js/lutcalc.js"
    click C2 "https://github.com/cameramanben/lutcalc/blob/master/js/lut.js"
    click C3 "https://github.com/cameramanben/lutcalc/blob/master/js/gamma.js"
    click C4 "https://github.com/cameramanben/lutcalc/blob/master/js/colourspace.js"
    click D1 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-asccdl.js"
    click D2 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-blank.js"
    click D3 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-blkgam.js"
    click D4 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-blkhi.js"
    click D5 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-cs.js"
    click D6 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-display.js"
    click D7 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-fc.js"
    click D8 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-gamlim.js"
    click D9 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-hg.js"
    click D10 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-knee.js"
    click D11 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-la.js"
    click D12 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-multi.js"
    click D13 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-psstcdl.js"
    click D14 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-sampler.js"
    click D15 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-sdrsat.js"
    click D16 "https://github.com/cameramanben/lutcalc/blob/master/js/twk-white.js"
    click E1 "https://github.com/cameramanben/lutcalc/blob/master/js/colourspaceworker.js"
    click E2 "https://github.com/cameramanben/lutcalc/blob/master/js/gammaworker.js"
    click E3 "https://github.com/cameramanben/lutcalc/blob/master/js/lutmessage.js"

    %% Click Events for LUT I/O & Parsing Layer
    click F1 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-cube.js"
    click F2 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-davinci.js"
    click F3 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-3dl.js"
    click F4 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-lut.js"
    click F5 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-spi1d.js"
    click F6 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-spi3d.js"
    click F7 "https://github.com/cameramanben/lutcalc/blob/master/js/lut-la.js"
    click F8 "https://github.com/cameramanben/lutcalc/blob/master/js/lutformats.js"
    click F9 "https://github.com/cameramanben/lutcalc/blob/master/js/lutfile.js"

    %% Click Events for File Handling & External Integration
    click G1 "https://github.com/cameramanben/lutcalc/blob/master/filesaver/FileSaver.js"
    click G2 "https://github.com/cameramanben/lutcalc/blob/master/blob/Blob.js"

    %% Click Events for Binary Data Resources
    click H1 "https://github.com/cameramanben/lutcalc/blob/master/AlexaX2.labin"
    click H2 "https://github.com/cameramanben/lutcalc/blob/master/Amira709.labin"
    click H3 "https://github.com/cameramanben/lutcalc/blob/master/Cine709.labin"
    click H4 "https://github.com/cameramanben/lutcalc/blob/master/LC709.labin"
    click H5 "https://github.com/cameramanben/lutcalc/blob/master/LC709A.labin"
    click H6 "https://github.com/cameramanben/lutcalc/blob/master/V709.labin"
    click H7 "https://github.com/cameramanben/lutcalc/blob/master/cpoutdaylight.labin"
    click H8 "https://github.com/cameramanben/lutcalc/blob/master/cpouttungsten.labin"
    click H9 "https://github.com/cameramanben/lutcalc/blob/master/s709.labin"

classDef ui fill:#a8e6cf,stroke:#333,stroke-width:1px;
classDef calc fill:#a2d2ff,stroke:#333,stroke-width:1px;
classDef tweaks fill:#cdb4db,stroke:#333,stroke-width:1px;
classDef workers fill:#ffb347,stroke:#333,stroke-width:1px;
classDef io fill:#fef9a7,stroke:#333,stroke-width:1px;
classDef filefill fill:#ffaaa5,stroke:#333,stroke-width:1px;
classDef binary fill:#d3d3d3,stroke:#333,stroke-width:1px;
```
