| 1 | # Bitstream compression |
| 2 | |
| 3 | This algorithm is to apply on a ready to write bitstream, after having computed data configuration checksum and optional padding, before line checksum. |
| 4 | |
| 5 | Principle is to replace serie of `0x00` by a dedicated value: |
| 6 | - a serie of `8 * 0x00` is replaced by one value (said `key8Z` in the rest of |
| 7 | this document); |
| 8 | - a serie of `4 * 0x00` is replaced by one value (said `key4Z` in the rest of |
| 9 | this document); |
| 10 | - a serie of `2 * 0x00` is replaced by one value (said `key2Z` in the rest of |
| 11 | this document); |
| 12 | |
| 13 | Those values are stored in the header area (line starting with `0x51`), line starting with `0x10` must be updated too (bit 13). |
| 14 | |
| 15 | ## Optional padding |
| 16 | |
| 17 | This algorithm is applied 8 bytes by 8 bytes. So if lines are not multiple of 64bits, a serie of dummy bits (set to `1`) must be added. |
| 18 | |
| 19 | ## Select values to use |
| 20 | |
| 21 | This step consist to search all values not used for data/EBR configuration (it's more or less the creation of an histogram): |
| 22 | ```python |
| 23 | lst = [0 for i in range(0, 256)] |
| 24 | for i in range(len(dataCfg)): |
| 25 | line = dataCfg[i] |
| 26 | for v in line: |
| 27 | lst[v] += 1 |
| 28 | unusedVal = [i for i,val in enumerate(lst) if val==0] |
| 29 | |
| 30 | ``` |
| 31 | - `key8Z` take the value for index 0 (smallest value) |
| 32 | - `key4Z` take the value for index 1 |
| 33 | - `key2Z` take the value for index 2 (highest value) |
| 34 | |
| 35 | There may not be enough unused values for some or all keys, in which case the key-specific packing is not performed (in the most severe case, the file is not packed at all if all possible byte values are used). |
| 36 | |
| 37 | Line starting with `0x51` must be updated accordingly, and bit `13` for line `0x10` must be set |
| 38 | |
| 39 | ## Conversion |
| 40 | |
| 41 | This step is applied line by line and 8 bytes by 8 bytes. |
| 42 | |
| 43 | The principle is more or less to find/replace sequentially series of `0x00`: |
| 44 | |
| 45 | For example: |
| 46 | - `[0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00]` |
| 47 | - `[key8Z]` |
| 48 | - `[0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF]` |
| 49 | - `[key4Z 0x00 0x00 0x00 0xFF]` |
| 50 | - `[key4Z key2Z 0x00 0xFF]` |