mirror of
https://github.com/BinomialLLC/basis_universal.git
synced 2026-08-12 16:19:36 +00:00
Fixing tabs
This commit is contained in:
@@ -213,41 +213,41 @@ First, some enums:
|
||||
|
||||
enum
|
||||
{
|
||||
// Max supported Huffman code size is 16-bits
|
||||
cHuffmanMaxSupportedCodeSize = 16,
|
||||
// Max supported Huffman code size is 16-bits
|
||||
cHuffmanMaxSupportedCodeSize = 16,
|
||||
|
||||
// The maximum number of symbols is 2^14
|
||||
cHuffmanMaxSymsLog2 = 14,
|
||||
cHuffmanMaxSyms = 1 << cHuffmanMaxSymsLog2,
|
||||
// The maximum number of symbols is 2^14
|
||||
cHuffmanMaxSymsLog2 = 14,
|
||||
cHuffmanMaxSyms = 1 << cHuffmanMaxSymsLog2,
|
||||
|
||||
// Small zero runs may range from 3-10 entries
|
||||
cHuffmanSmallZeroRunSizeMin = 3,
|
||||
cHuffmanSmallZeroRunSizeMax = 10,
|
||||
cHuffmanSmallZeroRunExtraBits = 3,
|
||||
// Small zero runs may range from 3-10 entries
|
||||
cHuffmanSmallZeroRunSizeMin = 3,
|
||||
cHuffmanSmallZeroRunSizeMax = 10,
|
||||
cHuffmanSmallZeroRunExtraBits = 3,
|
||||
|
||||
// Big zero runs may range from 11-138 entries
|
||||
cHuffmanBigZeroRunSizeMin = 11,
|
||||
cHuffmanBigZeroRunSizeMax = 138,
|
||||
cHuffmanBigZeroRunExtraBits = 7,
|
||||
// Big zero runs may range from 11-138 entries
|
||||
cHuffmanBigZeroRunSizeMin = 11,
|
||||
cHuffmanBigZeroRunSizeMax = 138,
|
||||
cHuffmanBigZeroRunExtraBits = 7,
|
||||
|
||||
// Small non-zero runs may range from 3-6 entries
|
||||
cHuffmanSmallRepeatSizeMin = 3,
|
||||
cHuffmanSmallRepeatSizeMax = 6,
|
||||
cHuffmanSmallRepeatExtraBits = 2,
|
||||
// Small non-zero runs may range from 3-6 entries
|
||||
cHuffmanSmallRepeatSizeMin = 3,
|
||||
cHuffmanSmallRepeatSizeMax = 6,
|
||||
cHuffmanSmallRepeatExtraBits = 2,
|
||||
|
||||
// Big non-zero run may range from 7-134 entries
|
||||
cHuffmanBigRepeatSizeMin = 7,
|
||||
cHuffmanBigRepeatSizeMax = 134,
|
||||
cHuffmanBigRepeatExtraBits = 7,
|
||||
// Big non-zero run may range from 7-134 entries
|
||||
cHuffmanBigRepeatSizeMin = 7,
|
||||
cHuffmanBigRepeatSizeMax = 134,
|
||||
cHuffmanBigRepeatExtraBits = 7,
|
||||
|
||||
// There are a maximum of 21 symbols in a compressed Huffman code length table.
|
||||
cHuffmanTotalCodelengthCodes = 21,
|
||||
|
||||
// Symbols [0,16] indicate code sizes. Other symbols indicate zero runs or repeats:
|
||||
cHuffmanSmallZeroRunCode = 17,
|
||||
cHuffmanBigZeroRunCode = 18,
|
||||
cHuffmanSmallRepeatCode = 19,
|
||||
cHuffmanBigRepeatCode = 20
|
||||
// There are a maximum of 21 symbols in a compressed Huffman code length table.
|
||||
cHuffmanTotalCodelengthCodes = 21,
|
||||
|
||||
// Symbols [0,16] indicate code sizes. Other symbols indicate zero runs or repeats:
|
||||
cHuffmanSmallZeroRunCode = 17,
|
||||
cHuffmanBigZeroRunCode = 18,
|
||||
cHuffmanSmallRepeatCode = 19,
|
||||
cHuffmanBigRepeatCode = 20
|
||||
};
|
||||
|
||||
A .basis Huffman table consists of 1 to cHuffmanMaxSyms symbols. Each compressed
|
||||
@@ -257,43 +257,43 @@ The table's symbol code lengths are themselves RLE+Huffman coded, just like
|
||||
Deflate. (Note this can be confusing to developers unfamiliar with Deflate.)
|
||||
Each table begins with a small fixed header:
|
||||
|
||||
14 bits: total_used_syms [1, cHuffmanMaxSyms]
|
||||
5 bits: num_codelength_codes [1, cHuffmanTotalCodelengthCodes]
|
||||
|
||||
Next, the code lengths for the small Huffman table which is used to send the compressed codelengths (and RLE/repeat codes) are sent uncompressed but in a reordered manner:
|
||||
|
||||
3*num_codelength_codes bits: Code size of each Huffman symbol for the compressed Huffman codelength table.
|
||||
14 bits: total_used_syms [1, cHuffmanMaxSyms]
|
||||
5 bits: num_codelength_codes [1, cHuffmanTotalCodelengthCodes]
|
||||
|
||||
These code lengths are sent in this order (to help reduce the number that must be sent):
|
||||
|
||||
{
|
||||
cHuffmanSmallZeroRunCode, cHuffmanBigZeroRunCode, cHuffmanSmallRepeatCode, cHuffmanBigRepeatCode,
|
||||
0, 8, 7, 9, 6, 0xA, 5, 0xB, 4, 0xC, 3, 0xD, 2, 0xE, 1, 0xF, 0x10
|
||||
};
|
||||
|
||||
Next, the code lengths for the small Huffman table which is used to send the compressed codelengths (and RLE/repeat codes) are sent uncompressed but in a reordered manner:
|
||||
|
||||
3*num_codelength_codes bits: Code size of each Huffman symbol for the compressed Huffman codelength table.
|
||||
|
||||
These code lengths are sent in this order (to help reduce the number that must be sent):
|
||||
|
||||
{
|
||||
cHuffmanSmallZeroRunCode, cHuffmanBigZeroRunCode, cHuffmanSmallRepeatCode, cHuffmanBigRepeatCode,
|
||||
0, 8, 7, 9, 6, 0xA, 5, 0xB, 4, 0xC, 3, 0xD, 2, 0xE, 1, 0xF, 0x10
|
||||
};
|
||||
|
||||
A canonical Huffman decoding table (of up to 21 symbols) should be built from
|
||||
these code lengths. Immediately following this data are the Huffman symbols
|
||||
(sometimes intermixed with raw bits) which describe how to unpack the
|
||||
codelengths of each symbol in the Huffman table:
|
||||
|
||||
- Symbols [0,16] indicate a specific symbol code length in bits.
|
||||
|
||||
- Symbol cHuffmanSmallZeroRunCode (17) indicates a short run of symbols with 0 bit code lengths.
|
||||
cHuffmanSmallZeroRunExtraBits (3) bits are sent after this symbol, which indicates the run's size after adding the minimum size (cHuffmanSmallZeroRunSizeMin).
|
||||
|
||||
- Symbol cHuffmanBigZeroRunCode (18) indicates a long run of symbols with 0 bit code lengths.
|
||||
cHuffmanBigZeroRunExtraBits (7) bits are sent after this symbol, which indicates the run's size after adding the minimum size (cHuffmanBigZeroRunSizeMin)
|
||||
- Symbols [0,16] indicate a specific symbol code length in bits.
|
||||
|
||||
- Symbol cHuffmanSmallZeroRunCode (17) indicates a short run of symbols with 0 bit code lengths.
|
||||
cHuffmanSmallZeroRunExtraBits (3) bits are sent after this symbol, which indicates the run's size after adding the minimum size (cHuffmanSmallZeroRunSizeMin).
|
||||
|
||||
- Symbol cHuffmanBigZeroRunCode (18) indicates a long run of symbols with 0 bit code lengths.
|
||||
cHuffmanBigZeroRunExtraBits (7) bits are sent after this symbol, which indicates the run's size after adding the minimum size (cHuffmanBigZeroRunSizeMin)
|
||||
|
||||
- Symbol cHuffmanSmallRepeatCode (19) indicates a short run of symbols that repeat the previous symbol's code length.
|
||||
cHuffmanSmallRepeatExtraBits (2) bits are sent after this symbol, which indicates the number of times to repeat the previous symbol's code length,
|
||||
after adding the minimum size (cHuffmanSmallRepeatSizeMin).
|
||||
Cannot be the first symbol, and the previous symbol cannot have a code length of 0.
|
||||
|
||||
- Symbol cHuffmanBigRepeatCode (20) indicates a short run of symbols that repeat the previous symbol's code length.
|
||||
cHuffmanBigRepeatExtraBits (7) bits are sent after this symbol, which indicates the number of times to repeat the previous symbol's code length,
|
||||
after adding the minimum size (cHuffmanBigRepeatSizeMin).
|
||||
Cannot be the first symbol, and the previous symbol cannot have a code length of 0.
|
||||
|
||||
- Symbol cHuffmanSmallRepeatCode (19) indicates a short run of symbols that repeat the previous symbol's code length.
|
||||
cHuffmanSmallRepeatExtraBits (2) bits are sent after this symbol, which indicates the number of times to repeat the previous symbol's code length,
|
||||
after adding the minimum size (cHuffmanSmallRepeatSizeMin).
|
||||
Cannot be the first symbol, and the previous symbol cannot have a code length of 0.
|
||||
|
||||
- Symbol cHuffmanBigRepeatCode (20) indicates a short run of symbols that repeat the previous symbol's code length.
|
||||
cHuffmanBigRepeatExtraBits (7) bits are sent after this symbol, which indicates the number of times to repeat the previous symbol's code length,
|
||||
after adding the minimum size (cHuffmanBigRepeatSizeMin).
|
||||
Cannot be the first symbol, and the previous symbol cannot have a code length of 0.
|
||||
|
||||
There should be exactly total_used_syms code lengths stored in the compressed Huffman table. If not the stream is either corrupted or invalid.
|
||||
|
||||
After all the symbol codelengths are uncompressed, the symbol codes can be computed and the canonical Huffman decoding tables can be built.
|
||||
@@ -310,10 +310,10 @@ At the beginning of the compressed endpoint codebook section are four compressed
|
||||
Huffman tables, stored using the procedure outlined in section 6.0. The Huffman tables
|
||||
appear in this order:
|
||||
|
||||
1. color5_delta_model0
|
||||
2. color5_delta_model1
|
||||
3. color5_delta_model2
|
||||
4. inten_delta_model
|
||||
1. color5_delta_model0
|
||||
2. color5_delta_model1
|
||||
3. color5_delta_model2
|
||||
4. inten_delta_model
|
||||
|
||||
Following the data for these Huffman tables is a single 1-bit code which
|
||||
indicates if the color endpoint codebook is grayscale or not.
|
||||
@@ -322,49 +322,49 @@ Immediately following this code is the compressed color endpoint codebook data.
|
||||
A simple form of DPCM coding is used to send the ETC1S intensity table indices and
|
||||
color values. Here is the procedure to decode the endpoint codebook:
|
||||
|
||||
const int COLOR5_PAL0_PREV_HI = 9, COLOR5_PAL0_DELTA_LO = -9, COLOR5_PAL0_DELTA_HI = 31;
|
||||
const int COLOR5_PAL1_PREV_HI = 21, COLOR5_PAL1_DELTA_LO = -21, COLOR5_PAL1_DELTA_HI = 21;
|
||||
const int COLOR5_PAL2_PREV_HI = 31, COLOR5_PAL2_DELTA_LO = -31, COLOR5_PAL2_DELTA_HI = 9;
|
||||
const int COLOR5_PAL0_PREV_HI = 9, COLOR5_PAL0_DELTA_LO = -9, COLOR5_PAL0_DELTA_HI = 31;
|
||||
const int COLOR5_PAL1_PREV_HI = 21, COLOR5_PAL1_DELTA_LO = -21, COLOR5_PAL1_DELTA_HI = 21;
|
||||
const int COLOR5_PAL2_PREV_HI = 31, COLOR5_PAL2_DELTA_LO = -31, COLOR5_PAL2_DELTA_HI = 9;
|
||||
|
||||
// Assume previous endpoint color is (16, 16, 16), and the previous intensity is 0.
|
||||
color32 prev_color5(16, 16, 16, 0);
|
||||
uint32_t prev_inten = 0;
|
||||
// Assume previous endpoint color is (16, 16, 16), and the previous intensity is 0.
|
||||
color32 prev_color5(16, 16, 16, 0);
|
||||
uint32_t prev_inten = 0;
|
||||
|
||||
// For each endpoint codebook entry
|
||||
for (uint32_t i = 0; i < num_endpoints; i++)
|
||||
{
|
||||
// Decode the intensity delta Huffman code
|
||||
uint32_t inten_delta = sym_codec.decode_huffman(inten_delta_model);
|
||||
m_endpoints[i].m_inten5 = static_cast<uint8_t>((inten_delta + prev_inten) & 7);
|
||||
prev_inten = m_endpoints[i].m_inten5;
|
||||
// For each endpoint codebook entry
|
||||
for (uint32_t i = 0; i < num_endpoints; i++)
|
||||
{
|
||||
// Decode the intensity delta Huffman code
|
||||
uint32_t inten_delta = sym_codec.decode_huffman(inten_delta_model);
|
||||
m_endpoints[i].m_inten5 = static_cast<uint8_t>((inten_delta + prev_inten) & 7);
|
||||
prev_inten = m_endpoints[i].m_inten5;
|
||||
|
||||
// Now decode the endpoint entry's color or intensity value
|
||||
for (uint32_t c = 0; c < (endpoints_are_grayscale ? 1U : 3U); c++)
|
||||
{
|
||||
// The Huffman table we used to decode the delta depends on the previous color's value
|
||||
int delta;
|
||||
if (prev_color5[c] <= basist::COLOR5_PAL0_PREV_HI)
|
||||
delta = sym_codec.decode_huffman(color5_delta_model0);
|
||||
else if (prev_color5[c] <= basist::COLOR5_PAL1_PREV_HI)
|
||||
delta = sym_codec.decode_huffman(color5_delta_model1);
|
||||
else
|
||||
delta = sym_codec.decode_huffman(color5_delta_model2);
|
||||
// Now decode the endpoint entry's color or intensity value
|
||||
for (uint32_t c = 0; c < (endpoints_are_grayscale ? 1U : 3U); c++)
|
||||
{
|
||||
// The Huffman table we used to decode the delta depends on the previous color's value
|
||||
int delta;
|
||||
if (prev_color5[c] <= basist::COLOR5_PAL0_PREV_HI)
|
||||
delta = sym_codec.decode_huffman(color5_delta_model0);
|
||||
else if (prev_color5[c] <= basist::COLOR5_PAL1_PREV_HI)
|
||||
delta = sym_codec.decode_huffman(color5_delta_model1);
|
||||
else
|
||||
delta = sym_codec.decode_huffman(color5_delta_model2);
|
||||
|
||||
// Apply the delta
|
||||
int v = (prev_color5[c] + delta) & 31;
|
||||
// Apply the delta
|
||||
int v = (prev_color5[c] + delta) & 31;
|
||||
|
||||
m_endpoints[i].m_color5[c] = static_cast<uint8_t>(v);
|
||||
m_endpoints[i].m_color5[c] = static_cast<uint8_t>(v);
|
||||
|
||||
prev_color5[c] = static_cast<uint8_t>(v);
|
||||
}
|
||||
prev_color5[c] = static_cast<uint8_t>(v);
|
||||
}
|
||||
|
||||
// If the endpoints are grayscale, set G and B to match R.
|
||||
if (endpoints_are_grayscale)
|
||||
{
|
||||
m_endpoints[i].m_color5[1] = m_endpoints[i].m_color5[0];
|
||||
m_endpoints[i].m_color5[2] = m_endpoints[i].m_color5[0];
|
||||
}
|
||||
}
|
||||
// If the endpoints are grayscale, set G and B to match R.
|
||||
if (endpoints_are_grayscale)
|
||||
{
|
||||
m_endpoints[i].m_color5[1] = m_endpoints[i].m_color5[0];
|
||||
m_endpoints[i].m_color5[2] = m_endpoints[i].m_color5[0];
|
||||
}
|
||||
}
|
||||
|
||||
The rest of the section's data (if any) can be ignored.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user