update region file format 2 to 3 (WIP)

This commit is contained in:
MihailRis
2024-09-04 23:37:39 +03:00
parent 73a8343f61
commit 184e9c6648
16 changed files with 295 additions and 57 deletions
+41
View File
@@ -0,0 +1,41 @@
# Region File (version 2)
File format BNF (RFC 5234):
```bnf
file = header (*chunk) offsets complete file
header = magic %x02 %x00 magic number, version and reserved
zero byte
magic = %x2E %x56 %x4F %x58 '.VOXREG\0'
%x52 %x45 %x47 %x00
chunk = int32 (*byte) byte array with size prefix
offsets = (1024*int32) offsets table
int32 = 4byte signed big-endian 32 bit integer
byte = %x00-FF 8 bit unsigned integer
```
C struct visualization:
```c
typedef unsigned char byte;
struct file {
// 10 bytes
struct {
char magic[8] = ".VOXREG";
byte version = 2;
byte reserved = 0;
} header;
struct {
int32_t size; // byteorder: big-endian
byte* data;
} chunks[1024]; // file does not contain zero sizes for missing chunks
int32_t offsets[1024]; // byteorder: big-endian
};
```
Offsets table contains chunks positions in file. 0 means that chunk is not present in the file. Minimal valid offset is 10 (header size).
@@ -0,0 +1,26 @@
# Voxels Chunk (version 1)
Voxel regions layer chunk structure.
Values are separated for extRLE8 compression efficiency.
File format BNF (RFC 5234):
```bnf
chunk = (65536*byte) block indices (most significant bytes)
(65536*byte) block indices (least significant bytes)
(65536*byte) block states (most significant bytes)
(65536*byte) block states (least significant bytes)
byte = %x00-FF 8 bit unsigned integer
```
65536 is number of voxels per chunk (16\*256\*16)
## Block state
Block state is encoded in 16 bits:
- 0-2 bits (3) - block rotation index
- 3-5 bits (3) - segment block bits
- 6-7 bits (2) - reserved
- 8-15 bits (8) - user bits
+19 -10
View File
@@ -1,18 +1,21 @@
# Region File (version 2)
# Region File (version 3)
File format BNF (RFC 5234):
```bnf
file = header (*chunk) offsets complete file
header = magic %x02 %x00 magic number, version and reserved
zero byte
header = magic %x02 byte magic number, version and compression
method
magic = %x2E %x56 %x4F %x58 '.VOXREG\0'
%x52 %x45 %x47 %x00
chunk = int32 (*byte) byte array with size prefix
offsets = (1024*int32) offsets table
int32 = 4byte signed big-endian 32 bit integer
chunk = uint32 uint32 (*byte) byte array with size and source size
prefix where source size is
decompressed chunk data size
offsets = (1024*uint32) offsets table
int32 = 4byte unsigned big-endian 32 bit integer
byte = %x00-FF 8 bit unsigned integer
```
@@ -25,17 +28,23 @@ struct file {
// 10 bytes
struct {
char magic[8] = ".VOXREG";
byte version = 2;
byte reserved = 0;
byte version = 3;
byte compression;
} header;
struct {
int32_t size; // byteorder: big-endian
uint32_t size; // byteorder: little-endian
uint32_t sourceSize; // byteorder: little-endian
byte* data;
} chunks[1024]; // file does not contain zero sizes for missing chunks
int32_t offsets[1024]; // byteorder: big-endian
uint32_t offsets[1024]; // byteorder: little-endian
};
```
Offsets table contains chunks positions in file. 0 means that chunk is not present in the file. Minimal valid offset is 10 (header size).
Available compression methods:
0. no compression
1. extRLE8
2. extRLE16
+5 -8
View File
@@ -1,17 +1,14 @@
# Voxels Chunk (version 1)
# Voxels Chunk (version 2)
Voxel regions layer chunk structure.
Values are separated for extRLE8 compression efficiency.
IDs and states are separated for extRLE16 compression efficiency.
File format BNF (RFC 5234):
```bnf
chunk = (65536*byte) block indices (most significant bytes)
(65536*byte) block indices (least significant bytes)
(65536*byte) block states (most significant bytes)
(65536*byte) block states (least significant bytes)
chunk = (65536*uint16) block ids
(65536*uint16) block states
uint16 = 2byte 16 bit little-endian unsigned integer
byte = %x00-FF 8 bit unsigned integer
```