# kiruyamomochi/texture2ddecoder architecture

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

- Interactive diagram: https://gitdiagram.com/kiruyamomochi/texture2ddecoder
- Repository: https://github.com/kiruyamomochi/texture2ddecoder

## Overview

Texture2DDecoder exposes a .NET API for turning Unity texture data into decoded pixel images. The main workflow is caller → managed wrapper → native interop → exported native dispatch → format-specific decoder; Crunch data has separate standard and Unity-specific unpackers. The README documents broad platform package availability, but those packaging/build details are not runtime components. Relationships within the native decoder are supported by the exported calls in `dllmain.cpp`; some managed-to-native detail is inferred from the indexed interop files and DLL name.

Main entry points: [`Texture2DDecoderNative/dllmain.cpp`](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/dllmain.cpp) (Native Exports), [`Texture2DDecoderWrapper/TextureDecoder.cs`](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.cs) (Texture API), [`Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs`](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs) (P/Invoke Bindings), [`Texture2DDecoderWrapper/T2DDll.cs`](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/T2DDll.cs) (Native DLL Name)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_managed["Managed API"]
  node_wrapper["Texture API<br/>[TextureDecoder.cs]"]
  node_pinvoke["P/Invoke Bindings"]
  node_dllname["Native DLL Name<br/>[T2DDll.cs]"]
end

subgraph group_native["Native Interface"]
  node_exports["Native Exports<br/>[dllmain.cpp]"]
end

subgraph group_formats["Texture Formats"]
  node_bcn["BCn Decoders<br/>[bcn.cpp]"]
  node_etc["ETC Decoders<br/>[etc.cpp]"]
  node_atc["ATC Decoders<br/>[atc.cpp]"]
  node_astc["ASTC Decoder<br/>[astc.cpp]"]
  node_pvrtc["PVRTC Decoder<br/>[pvrtc.cpp]"]
end

subgraph group_crunch["Crunch Unpacking"]
  node_crunch_api["Crunch Exports<br/>[crunch.cpp]"]
  node_crunch_impl["Crunch Transcoder<br/>[crn_decomp.h]"]
  node_unity_api["Unity Crunch Exports<br/>[unitycrunch.cpp]"]
  node_unity_impl["Unity Crunch Transcoder<br/>[crn_decomp.h]"]
end

subgraph group_helpers["Decode Helpers"]
  node_color["Pixel Color Helpers<br/>[color.h]"]
  node_endian["Endianness Helpers<br/>[endianness.h]"]
  node_fp16["Half-Float Helpers<br/>[fp16.h]"]
end

node_caller(("Application"))
node_image["Decoded Pixel Image"]

node_caller -->|"calls"| node_wrapper
node_wrapper -->|"uses bindings"| node_pinvoke
node_pinvoke -->|"names library"| node_dllname
node_dllname -.->|"loads"| node_exports
node_exports -->|"dispatches"| node_bcn
node_exports -->|"dispatches"| node_etc
node_exports -->|"dispatches"| node_atc
node_exports -->|"dispatches"| node_astc
node_exports -.->|"dispatches"| node_pvrtc
node_exports -.->|"dispatches"| node_crunch_api
node_exports -.->|"dispatches"| node_unity_api
node_crunch_api -->|"unpacks with"| node_crunch_impl
node_unity_api -->|"unpacks with"| node_unity_impl
node_wrapper -->|"returns pixels"| node_image

click node_wrapper "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.cs"
click node_pinvoke "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs"
click node_dllname "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/T2DDll.cs"
click node_exports "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/dllmain.cpp"
click node_bcn "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/bcn.cpp"
click node_etc "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/etc.cpp"
click node_atc "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/atc.cpp"
click node_astc "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/astc.cpp"
click node_pvrtc "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/pvrtc.cpp"
click node_crunch_api "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/crunch.cpp"
click node_crunch_impl "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/crunch/crn_decomp.h"
click node_unity_api "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/unitycrunch.cpp"
click node_unity_impl "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/unitycrunch/crn_decomp.h"
click node_color "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/color.h"
click node_endian "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/endianness.h"
click node_fp16 "https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/fp16/fp16.h"

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_wrapper,node_pinvoke,node_dllname toneBlue
class node_exports toneAmber
class node_bcn,node_etc,node_atc,node_astc,node_pvrtc toneMint
class node_crunch_api,node_crunch_impl,node_unity_api,node_unity_impl toneRose
class node_color,node_endian,node_fp16,node_caller,node_image toneIndigo
```

## Components

### Managed API

- [Texture API](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.cs): `Texture2DDecoderWrapper/TextureDecoder.cs`
- [P/Invoke Bindings](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs): `Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs`
- [Native DLL Name](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderWrapper/T2DDll.cs): `Texture2DDecoderWrapper/T2DDll.cs`

### Native Interface

- [Native Exports](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/dllmain.cpp): `Texture2DDecoderNative/dllmain.cpp`

### Texture Formats

- [BCn Decoders](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/bcn.cpp): `Texture2DDecoderNative/bcn.cpp`
- [ETC Decoders](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/etc.cpp): `Texture2DDecoderNative/etc.cpp`
- [ATC Decoders](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/atc.cpp): `Texture2DDecoderNative/atc.cpp`
- [ASTC Decoder](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/astc.cpp): `Texture2DDecoderNative/astc.cpp`
- [PVRTC Decoder](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/pvrtc.cpp): `Texture2DDecoderNative/pvrtc.cpp`

### Crunch Unpacking

- [Crunch Exports](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/crunch.cpp): `Texture2DDecoderNative/crunch.cpp`
- [Crunch Transcoder](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/crunch/crn_decomp.h): `Texture2DDecoderNative/crunch/crn_decomp.h`
- [Unity Crunch Exports](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/unitycrunch.cpp): `Texture2DDecoderNative/unitycrunch.cpp`
- [Unity Crunch Transcoder](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/unitycrunch/crn_decomp.h): `Texture2DDecoderNative/unitycrunch/crn_decomp.h`

### Decode Helpers

- [Pixel Color Helpers](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/color.h): `Texture2DDecoderNative/color.h`
- [Endianness Helpers](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/endianness.h): `Texture2DDecoderNative/endianness.h`
- [Half-Float Helpers](https://github.com/kiruyamomochi/texture2ddecoder/blob/main/Texture2DDecoderNative/fp16/fp16.h): `Texture2DDecoderNative/fp16/fp16.h`

### Other components

- **Application**
- **Decoded Pixel Image**

## Connections

- Application → Texture API: calls (evidence: `README.md`)
- Texture API → P/Invoke Bindings: uses bindings (evidence: `Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs`)
- P/Invoke Bindings → Native DLL Name: names library (evidence: `Texture2DDecoderWrapper/TextureDecoder.PInvoke.cs`)
- Native DLL Name → Native Exports: loads
- Native Exports → BCn Decoders: dispatches (evidence: `Texture2DDecoderNative/dllmain.cpp`)
- Native Exports → ETC Decoders: dispatches (evidence: `Texture2DDecoderNative/dllmain.cpp`)
- Native Exports → ATC Decoders: dispatches (evidence: `Texture2DDecoderNative/dllmain.cpp`)
- Native Exports → ASTC Decoder: dispatches (evidence: `Texture2DDecoderNative/dllmain.cpp`)
- Native Exports → PVRTC Decoder: dispatches
- Native Exports → Crunch Exports: dispatches
- Native Exports → Unity Crunch Exports: dispatches
- Crunch Exports → Crunch Transcoder: unpacks with (evidence: `Texture2DDecoderNative/crunch.cpp`)
- Unity Crunch Exports → Unity Crunch Transcoder: unpacks with (evidence: `Texture2DDecoderNative/unitycrunch.cpp`)
- Texture API → Decoded Pixel Image: returns pixels (evidence: `Texture2DDecoderWrapper/TextureDecoder.cs`)
