mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
Updated astc-encoder.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <array>
|
||||
|
||||
/** @brief Unpacked quint triplets <low,middle,high> for each packed value */
|
||||
// TODO: Bitpack these into a uint16_t?
|
||||
static const uint8_t quints_of_integer[128][3] {
|
||||
{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {3, 0, 0},
|
||||
{4, 0, 0}, {0, 4, 0}, {4, 4, 0}, {4, 4, 4},
|
||||
@@ -99,6 +100,7 @@ static const uint8_t integer_of_quints[5][5][5] {
|
||||
};
|
||||
|
||||
/** @brief Unpacked trit quintuplets <low,...,high> for each packed value */
|
||||
// TODO: Bitpack these into a uint16_t?
|
||||
static const uint8_t trits_of_integer[256][5] {
|
||||
{0, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {2, 0, 0, 0, 0}, {0, 0, 2, 0, 0},
|
||||
{0, 1, 0, 0, 0}, {1, 1, 0, 0, 0}, {2, 1, 0, 0, 0}, {1, 0, 2, 0, 0},
|
||||
@@ -334,44 +336,41 @@ static const uint8_t integer_of_trits[3][3][3][3][3] {
|
||||
*/
|
||||
struct btq_count
|
||||
{
|
||||
/** @brief The quantization level. */
|
||||
uint8_t quant;
|
||||
|
||||
/** @brief The number of bits. */
|
||||
uint8_t bits;
|
||||
uint8_t bits:6;
|
||||
|
||||
/** @brief The number of trits. */
|
||||
uint8_t trits;
|
||||
uint8_t trits:1;
|
||||
|
||||
/** @brief The number of quints. */
|
||||
uint8_t quints;
|
||||
uint8_t quints:1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The table of bits, trits, and quints needed for a quant encode.
|
||||
*/
|
||||
static const std::array<btq_count, 21> btq_counts {{
|
||||
{ QUANT_2, 1, 0, 0 },
|
||||
{ QUANT_3, 0, 1, 0 },
|
||||
{ QUANT_4, 2, 0, 0 },
|
||||
{ QUANT_5, 0, 0, 1 },
|
||||
{ QUANT_6, 1, 1, 0 },
|
||||
{ QUANT_8, 3, 0, 0 },
|
||||
{ QUANT_10, 1, 0, 1 },
|
||||
{ QUANT_12, 2, 1, 0 },
|
||||
{ QUANT_16, 4, 0, 0 },
|
||||
{ QUANT_20, 2, 0, 1 },
|
||||
{ QUANT_24, 3, 1, 0 },
|
||||
{ QUANT_32, 5, 0, 0 },
|
||||
{ QUANT_40, 3, 0, 1 },
|
||||
{ QUANT_48, 4, 1, 0 },
|
||||
{ QUANT_64, 6, 0, 0 },
|
||||
{ QUANT_80, 4, 0, 1 },
|
||||
{ QUANT_96, 5, 1, 0 },
|
||||
{ QUANT_128, 7, 0, 0 },
|
||||
{ QUANT_160, 5, 0, 1 },
|
||||
{ QUANT_192, 6, 1, 0 },
|
||||
{ QUANT_256, 8, 0, 0 }
|
||||
{ 1, 0, 0 }, // QUANT_2
|
||||
{ 0, 1, 0 }, // QUANT_3
|
||||
{ 2, 0, 0 }, // QUANT_4
|
||||
{ 0, 0, 1 }, // QUANT_5
|
||||
{ 1, 1, 0 }, // QUANT_6
|
||||
{ 3, 0, 0 }, // QUANT_8
|
||||
{ 1, 0, 1 }, // QUANT_10
|
||||
{ 2, 1, 0 }, // QUANT_12
|
||||
{ 4, 0, 0 }, // QUANT_16
|
||||
{ 2, 0, 1 }, // QUANT_20
|
||||
{ 3, 1, 0 }, // QUANT_24
|
||||
{ 5, 0, 0 }, // QUANT_32
|
||||
{ 3, 0, 1 }, // QUANT_40
|
||||
{ 4, 1, 0 }, // QUANT_48
|
||||
{ 6, 0, 0 }, // QUANT_64
|
||||
{ 4, 0, 1 }, // QUANT_80
|
||||
{ 5, 1, 0 }, // QUANT_96
|
||||
{ 7, 0, 0 }, // QUANT_128
|
||||
{ 5, 0, 1 }, // QUANT_160
|
||||
{ 6, 1, 0 }, // QUANT_192
|
||||
{ 8, 0, 0 } // QUANT_256
|
||||
}};
|
||||
|
||||
/**
|
||||
@@ -382,44 +381,38 @@ static const std::array<btq_count, 21> btq_counts {{
|
||||
*/
|
||||
struct ise_size
|
||||
{
|
||||
/** @brief The quantization level. */
|
||||
uint8_t quant;
|
||||
|
||||
/** @brief The scaling parameter. */
|
||||
uint8_t scale;
|
||||
|
||||
/** @brief The rounding parameter. */
|
||||
uint8_t round;
|
||||
uint8_t scale:6;
|
||||
|
||||
/** @brief The divisor parameter. */
|
||||
uint8_t divisor;
|
||||
uint8_t divisor:2;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The table of scale, round, and divisors needed for quant sizing.
|
||||
*/
|
||||
static const std::array<ise_size, 21> ise_sizes {{
|
||||
{ QUANT_2, 1, 0, 1 },
|
||||
{ QUANT_3, 8, 4, 5 },
|
||||
{ QUANT_4, 2, 0, 1 },
|
||||
{ QUANT_5, 7, 2, 3 },
|
||||
{ QUANT_6, 13, 4, 5 },
|
||||
{ QUANT_8, 3, 0, 1 },
|
||||
{ QUANT_10, 10, 2, 3 },
|
||||
{ QUANT_12, 18, 4, 5 },
|
||||
{ QUANT_16, 4, 0, 1 },
|
||||
{ QUANT_20, 13, 2, 3 },
|
||||
{ QUANT_24, 23, 4, 5 },
|
||||
{ QUANT_32, 5, 0, 1 },
|
||||
{ QUANT_40, 16, 2, 3 },
|
||||
{ QUANT_48, 28, 4, 5 },
|
||||
{ QUANT_64, 6, 0, 1 },
|
||||
{ QUANT_80, 19, 2, 3 },
|
||||
{ QUANT_96, 33, 4, 5 },
|
||||
{ QUANT_128, 7, 0, 1 },
|
||||
{ QUANT_160, 22, 2, 3 },
|
||||
{ QUANT_192, 38, 4, 5 },
|
||||
{ QUANT_256, 8, 0, 1 }
|
||||
{ 1, 0 }, // QUANT_2
|
||||
{ 8, 2 }, // QUANT_3
|
||||
{ 2, 0 }, // QUANT_4
|
||||
{ 7, 1 }, // QUANT_5
|
||||
{ 13, 2 }, // QUANT_6
|
||||
{ 3, 0 }, // QUANT_8
|
||||
{ 10, 1 }, // QUANT_10
|
||||
{ 18, 2 }, // QUANT_12
|
||||
{ 4, 0 }, // QUANT_16
|
||||
{ 13, 1 }, // QUANT_20
|
||||
{ 23, 2 }, // QUANT_24
|
||||
{ 5, 0 }, // QUANT_32
|
||||
{ 16, 1 }, // QUANT_40
|
||||
{ 28, 2 }, // QUANT_48
|
||||
{ 6, 0 }, // QUANT_64
|
||||
{ 19, 1 }, // QUANT_80
|
||||
{ 33, 2 }, // QUANT_96
|
||||
{ 7, 0 }, // QUANT_128
|
||||
{ 22, 1 }, // QUANT_160
|
||||
{ 38, 2 }, // QUANT_192
|
||||
{ 8, 0 } // QUANT_256
|
||||
}};
|
||||
|
||||
/* See header for documentation. */
|
||||
@@ -435,7 +428,8 @@ unsigned int get_ise_sequence_bitcount(
|
||||
}
|
||||
|
||||
auto& entry = ise_sizes[quant_level];
|
||||
return (entry.scale * character_count + entry.round) / entry.divisor;
|
||||
unsigned int divisor = (entry.divisor << 1) + 1;
|
||||
return (entry.scale * character_count + divisor - 1) / divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,7 +639,6 @@ void encode_ise(
|
||||
// Write out just bits
|
||||
else
|
||||
{
|
||||
promise(character_count > 0);
|
||||
for (unsigned int i = 0; i < character_count; i++)
|
||||
{
|
||||
write_bits(input_data[i], bits, bit_offset, output_data);
|
||||
@@ -685,10 +678,10 @@ void decode_ise(
|
||||
|
||||
if (trits)
|
||||
{
|
||||
static const unsigned int bits_to_read[5] { 2, 2, 1, 2, 1 };
|
||||
static const unsigned int block_shift[5] { 0, 2, 4, 5, 7 };
|
||||
static const unsigned int next_lcounter[5] { 1, 2, 3, 4, 0 };
|
||||
static const unsigned int hcounter_incr[5] { 0, 0, 0, 0, 1 };
|
||||
static const uint8_t bits_to_read[5] { 2, 2, 1, 2, 1 };
|
||||
static const uint8_t block_shift[5] { 0, 2, 4, 5, 7 };
|
||||
static const uint8_t next_lcounter[5] { 1, 2, 3, 4, 0 };
|
||||
static const uint8_t hcounter_incr[5] { 0, 0, 0, 0, 1 };
|
||||
unsigned int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data);
|
||||
bit_offset += bits_to_read[lcounter];
|
||||
tq_blocks[hcounter] |= tdata << block_shift[lcounter];
|
||||
@@ -698,10 +691,10 @@ void decode_ise(
|
||||
|
||||
if (quints)
|
||||
{
|
||||
static const unsigned int bits_to_read[3] { 3, 2, 2 };
|
||||
static const unsigned int block_shift[3] { 0, 3, 5 };
|
||||
static const unsigned int next_lcounter[3] { 1, 2, 0 };
|
||||
static const unsigned int hcounter_incr[3] { 0, 0, 1 };
|
||||
static const uint8_t bits_to_read[3] { 3, 2, 2 };
|
||||
static const uint8_t block_shift[3] { 0, 3, 5 };
|
||||
static const uint8_t next_lcounter[3] { 1, 2, 0 };
|
||||
static const uint8_t hcounter_incr[3] { 0, 0, 1 };
|
||||
unsigned int tdata = read_bits(bits_to_read[lcounter], bit_offset, input_data);
|
||||
bit_offset += bits_to_read[lcounter];
|
||||
tq_blocks[hcounter] |= tdata << block_shift[lcounter];
|
||||
@@ -714,6 +707,7 @@ void decode_ise(
|
||||
if (trits)
|
||||
{
|
||||
unsigned int trit_blocks = (character_count + 4) / 5;
|
||||
promise(trit_blocks > 0);
|
||||
for (unsigned int i = 0; i < trit_blocks; i++)
|
||||
{
|
||||
const uint8_t *tritptr = trits_of_integer[tq_blocks[i]];
|
||||
@@ -728,6 +722,7 @@ void decode_ise(
|
||||
if (quints)
|
||||
{
|
||||
unsigned int quint_blocks = (character_count + 2) / 3;
|
||||
promise(quint_blocks > 0);
|
||||
for (unsigned int i = 0; i < quint_blocks; i++)
|
||||
{
|
||||
const uint8_t *quintptr = quints_of_integer[tq_blocks[i]];
|
||||
|
||||
Reference in New Issue
Block a user