File: specifications.md

package info (click to toggle)
libbgcode 0.0~git20250220.5041c09-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,188 kB
  • sloc: cpp: 3,700; python: 255; makefile: 6
file content (184 lines) | stat: -rw-r--r-- 5,212 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Specifications
The new binarized G-code file consists of a file header followed by an ordered succession of blocks, in the following sequence:
1. File Header
2. File Metadata Block (optional)
3. Printer Metadata Block
4. Thumbnails Blocks (optional)
5. Print Metadata Block
6. Slicer Metadata Block
7. G-code Blocks

All of the multi-byte integers are encoded in little-endian byte ordering.

## File header

The file header contains the following data:

|               | type     | size    | description                        |
| ------------- | -------- | ------- | ---------------------------------- |
| Magic Number  | uint32_t | 4 bytes | GCDE                               |
| Version       | uint32_t | 4 bytes | Version of the G-code binarization |
| Checksum type | uint16_t | 2 bytes | Algorithm used for checksum        |

The size in bytes of the file header is 10.

Current value for `Version` is **1**

Possible values for `Checksum type` are:
```
0 = None
1 = CRC32
```

## Blocks

All blocks have the following structure:
* [Block header](#block-header)
* [Block parameters](#block-parameters)
* [Block data](#block-data)
* [Block checksum (optional)](#block-checksum)

### Block header

The block header is the same for all blocks.
It is defined as:

|                   | type     | size    | description                        |
| ----------------- | -------- | ------- | ---------------------------------- |
| Type              | uint16_t | 2 bytes | Block type                         |
| Compression       | uint16_t | 2 bytes | Compression algorithm              |
| Uncompressed size | uint32_t | 4 bytes | Size of the data when uncompressed |
| Compressed size   | uint32_t | 4 bytes | Size of the data when compressed   |

The size in bytes of the block header is **8** when `Compression` = **0** and **12** in all other cases.

Possible values for `Type` are:
```
0 = File Metadata Block
1 = GCode Block
2 = Slicer Metadata Block
3 = Printer Metadata Block
4 = Print Metadata Block
5 = Thumbnail Block
```

Possible values for `Compression` are:
```
0 = No compression
1 = Deflate algorithm
2 = Heatshrink algorithm with window size 11 and lookahead size 4
3 = Heatshrink algorithm with window size 12 and lookahead size 4
```

### Block parameters
Block parameters are used to let readers be able to interpret the block data.

Each block type may define its own parameters, so the size in bytes may vary.

### Block data
Block data content is described by the block paramenters.

The size in bytes of the block data is defined in the block header.
For `Compression` = **0** it is `Uncompressed size`, otherwise it is `Compressed size`.

### Block checksum
Block checksum is present when the `Checksum type` in the file header is different from **0**.

The size in bytes depends on the selected algorithm. For CRC32 it is **4**.

### Block types

  * [File metadata](#file-metadata)
  * [Printer metadata](#printer-metadata)
  * [Thumbnail](#thumbnail)
  * [Print metadata](#print-metadata)
  * [Slicer metadata](#slicer-metadata)
  * [GCode](#gcode)

### File metadata
Table of key-value pairs of generic metadata, such as producer (software), etc.

#### Parameters
|          | type     | size    | description   |
| -------- | -------- | ------- | ------------- |
| Encoding | uint16_t | 2 bytes | Encoding type |

Possible values for `Encoding` are:
```
0 = INI encoding
```

### Printer metadata
Table of key-value pairs of metadata consumed by printer, such as printer model, nozzle diameter etc.

#### Parameters
|          | type     | size    | description   |
| -------- | -------- | ------- | ------------- |
| Encoding | uint16_t | 2 bytes | Encoding type |

Possible values for `Encoding` are:
```
0 = INI encoding
```

### Thumbnail
Image data for thumbnail.
Each thumbnail is defined in its own block.

#### Parameters
|        | type     | size    | description  |
| ------ | -------- | ------- | ------------ |
| Format | uint16_t | 2 bytes | Image format |
| Width  | uint16_t | 2 bytes | Image width  |
| Height | uint16_t | 2 bytes | Image height |

Possible values for `Format` are:
```
0 = PNG format
1 = JPG format
2 = QOI format
```

### Print metadata
Table of key-value pairs of print metadata, such as print time or material consumed, etc.

#### Parameters
|          | type     | size    | description   |
| -------- | -------- | ------- | ------------- |
| Encoding | uint16_t | 2 bytes | Encoding type |


Possible values for `Encoding` are:
```
0 = INI encoding
```

### Slicer metadata
Table of key-value pairs of metadata produced and consumed by the software generating the G-code file.

#### Parameters
|          | type     | size    | description   |
| -------- | -------- | ------- | ------------- |
| Encoding | uint16_t | 2 bytes | Encoding type |

Possible values for `Encoding` are:
```
0 = INI encoding
```

### GCode
G-code data.

#### Parameters
|          | type     | size    | description   |
| -------- | -------- | ------- | ------------- |
| Encoding | uint16_t | 2 bytes | Encoding type |

Possible values for `Encoding` are:
```
0 = No encoding
1 = MeatPack algorithm
2 = MeatPack algorithm modified to keep comment lines
```