Skip to content

Commit 6174fc8

Browse files
committed
Cleanup sym_to_phy and phy_to_sym
- Pass by reference for singular values (mostly so we can distinguish singletons and arrays in code reviews). - Pass PCB by ref rather than relying on write elision. - Add some missing statics for module local functions
1 parent 32068b2 commit 6174fc8

7 files changed

Lines changed: 118 additions & 115 deletions

Source/astcenc_compress_symbolic.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,9 @@ void compress_symbolic_block(
12041204
scb->constant_color[3] = astc::flt2int_rtn(alpha * 65535.0f);
12051205
}
12061206

1207+
physical_compressed_block pcb;
1208+
symbolic_to_physical(*bsd, *scb, pcb);
1209+
physical_to_symbolic(*bsd, pcb, *scb);
12071210
return;
12081211
}
12091212

@@ -1447,7 +1450,6 @@ void compress_symbolic_block(
14471450
}
14481451
}
14491452

1450-
14511453
// Modes 7, 10 (13 is unreachable)
14521454
best_errorvals_in_modes[3 * (partition_count - 2) + 5 + 2] = best_errorval_in_mode;
14531455

@@ -1460,8 +1462,9 @@ void compress_symbolic_block(
14601462

14611463
END_OF_TESTS:
14621464
// compress/decompress to a physical block
1463-
physical_compressed_block psb = symbolic_to_physical(bsd, scb);
1464-
physical_to_symbolic(bsd, psb, scb);
1465+
physical_compressed_block pcb;
1466+
symbolic_to_physical(*bsd, *scb, pcb);
1467+
physical_to_symbolic(*bsd, pcb, *scb);
14651468
}
14661469

14671470
#endif

Source/astcenc_entry.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,15 @@ static void compress_image(
598598
int x = rem - (y * row_blocks);
599599

600600
// Decompress
601-
int offset = ((z * yblocks + y) * xblocks + x) * 16;
602-
const uint8_t *bp = buffer + offset;
603601
fetch_imageblock(decode_mode, image, &pb, bsd, x * block_x, y * block_y, z * block_z, swizzle);
602+
604603
symbolic_compressed_block scb;
605604
compress_symbolic_block(ctx, image, decode_mode, bsd, &pb, &scb, temp_buffers);
606-
*(physical_compressed_block*) bp = symbolic_to_physical(bsd, &scb);
605+
606+
int offset = ((z * yblocks + y) * xblocks + x) * 16;
607+
uint8_t *bp = buffer + offset;
608+
physical_compressed_block* pcb = reinterpret_cast<physical_compressed_block*>(bp);
609+
symbolic_to_physical(*bsd, scb, *pcb);
607610
}
608611

609612
ctx.manage_compress.complete_task_assignment(count);
@@ -773,10 +776,13 @@ astcenc_error astcenc_decompress_image(
773776
const uint8_t* bp = data + offset;
774777
physical_compressed_block pcb = *(physical_compressed_block *) bp;
775778
symbolic_compressed_block scb;
776-
physical_to_symbolic(context->bsd, pcb, &scb);
779+
780+
physical_to_symbolic(*context->bsd, pcb, scb);
781+
777782
decompress_symbolic_block(context->config.profile, context->bsd,
778783
x * block_x, y * block_y, z * block_z,
779784
&scb, &pb);
785+
780786
write_imageblock(image_out, &pb, context->bsd,
781787
x * block_x, y * block_y, z * block_z, swizzle);
782788
}

Source/astcenc_image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "astcenc_internal.h"
2626

2727
// conversion functions between the LNS representation and the FP16 representation.
28-
float float_to_lns(float p)
28+
static float float_to_lns(float p)
2929
{
3030
if (astc::isnan(p) || p <= 1.0f / 67108864.0f)
3131
{
@@ -66,7 +66,7 @@ float float_to_lns(float p)
6666
return p1 + 1.0f;
6767
}
6868

69-
uint16_t lns_to_sf16(uint16_t p)
69+
static uint16_t lns_to_sf16(uint16_t p)
7070
{
7171
uint16_t mc = p & 0x7FF;
7272
uint16_t ec = p >> 11;

Source/astcenc_integer_sequence.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static const uint8_t integer_of_trits[3][3][3][3][3] = {
329329
}
330330
};
331331

332-
void find_number_of_bits_trits_quints(
332+
static void find_number_of_bits_trits_quints(
333333
int quantization_level,
334334
int* bits,
335335
int* trits,

Source/astcenc_internal.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,22 +1125,19 @@ void decompress_symbolic_block(
11251125
const symbolic_compressed_block* scb,
11261126
imageblock* blk);
11271127

1128-
physical_compressed_block symbolic_to_physical(
1129-
const block_size_descriptor* bsd,
1130-
const symbolic_compressed_block* sc);
1128+
void symbolic_to_physical(
1129+
const block_size_descriptor& bsd,
1130+
const symbolic_compressed_block& scb,
1131+
physical_compressed_block& pcb);
11311132

11321133
void physical_to_symbolic(
1133-
const block_size_descriptor* bsd,
1134-
physical_compressed_block pb,
1135-
symbolic_compressed_block* res);
1134+
const block_size_descriptor& bsd,
1135+
const physical_compressed_block& pcb,
1136+
symbolic_compressed_block& scb);
11361137

11371138
uint16_t unorm16_to_sf16(
11381139
uint16_t p);
11391140

1140-
uint16_t lns_to_sf16(
1141-
uint16_t p);
1142-
1143-
11441141
struct astcenc_context
11451142
{
11461143
astcenc_config config;

0 commit comments

Comments
 (0)