]> git.sesse.net Git - narabu/commitdiff
Symbolize NUM_SYMS a bit.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Sep 2017 09:53:21 +0000 (11:53 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Sep 2017 09:53:21 +0000 (11:53 +0200)
narabu.cpp
qdc.cpp

index 1419ff0bc42a57c64600983002dab6136dcec466..2eb29dcd46877d788de0ee43a03e443352b1308b 100644 (file)
@@ -122,11 +122,11 @@ int main(int argc, char **argv)
                                exit(1);
                        }
 
-                       decode_tables[table].dsyms[(sym + 1) & 255].sym_start = cum_freq;
-                       decode_tables[table].dsyms[(sym + 1) & 255].sym_freq = *freq;
+                       decode_tables[table].dsyms[(sym + 1) & (NUM_SYMS - 1)].sym_start = cum_freq;
+                       decode_tables[table].dsyms[(sym + 1) & (NUM_SYMS - 1)].sym_freq = *freq;
                        for (uint32_t i = 0; i < freq; ++i) {
                                if (cum_freq < prob_scale)
-                                       decode_tables[table].cum2sym[cum_freq] = (sym + 1) & 255;
+                                       decode_tables[table].cum2sym[cum_freq] = (sym + 1) & (NUM_SYMS - 1);
                                ++cum_freq;
                        }
                }
diff --git a/qdc.cpp b/qdc.cpp
index 951915225f8784ff1ede25c8978db48ea6395a2a..46eb6886e5fd305de89dc78dcc177d2ad3dab32c 100644 (file)
--- a/qdc.cpp
+++ b/qdc.cpp
@@ -212,7 +212,7 @@ public:
                        printf("%d: cumfreqs=%d freqs=%d prob_bits=%d\n", i, s.cum_freqs[i], s.freqs[i], prob_bits + 1);
                        RansEncSymbolInit(&esyms[i], s.cum_freqs[i], s.freqs[i], prob_bits + 1);
                }
-               sign_bias = s.cum_freqs[256];
+               sign_bias = s.cum_freqs[NUM_SYMS];
        }
 
        void clear()
@@ -270,7 +270,7 @@ public:
                        RansEncPut(&rans, &ptr, k, 1, prob_bits);
                        k = ESCAPE_LIMIT;
                }
-               RansEncPutSymbol(&rans, &ptr, &esyms[(k - 1) & 255]);
+               RansEncPutSymbol(&rans, &ptr, &esyms[(k - 1) & (NUM_SYMS - 1)]);
                if (signed_k < 0) {
                        rans += sign_bias;
                }
@@ -404,7 +404,7 @@ void find_optimal_stream_assignment(int base)
        double inv_sum[64];
        for (unsigned i = 0; i < 64; ++i) {
                double s = 0.0;
-               for (unsigned k = 0; k < 256; ++k) {
+               for (unsigned k = 0; k < NUM_SYMS; ++k) {
                        s += stats[i + base].freqs[k] + 0.5;
                }
                inv_sum[i] = 1.0 / s;
@@ -413,7 +413,7 @@ void find_optimal_stream_assignment(int base)
        for (unsigned i = 0; i < 64; ++i) {
                for (unsigned j = 0; j < 64; ++j) {
                        double d = 0.0;
-                       for (unsigned k = 0; k < 256; ++k) {
+                       for (unsigned k = 0; k < NUM_SYMS; ++k) {
                                double p1 = (stats[i + base].freqs[k] + 0.5) * inv_sum[i];
                                double p2 = (stats[j + base].freqs[k] + 0.5) * inv_sum[j];
 
@@ -771,7 +771,7 @@ int main(int argc, char **argv)
                                                k = ESCAPE_LIMIT;
                                                extra_bits += 12;  // escape this one
                                        }
-                                       ++s_luma.freqs[(k - 1) & 255];
+                                       ++s_luma.freqs[(k - 1) & (NUM_SYMS - 1)];
                                }
                        }
                        // Chroma
@@ -787,8 +787,8 @@ int main(int argc, char **argv)
                                                k_cr = ESCAPE_LIMIT;
                                                extra_bits += 12;  // escape this one
                                        }
-                                       ++s_chroma.freqs[(k_cb - 1) & 255];
-                                       ++s_chroma.freqs[(k_cr - 1) & 255];
+                                       ++s_chroma.freqs[(k_cb - 1) & (NUM_SYMS - 1)];
+                                       ++s_chroma.freqs[(k_cr - 1) & (NUM_SYMS - 1)];
                                }
                        }
                }
@@ -803,10 +803,10 @@ int main(int argc, char **argv)
 #endif
 
        for (unsigned i = 0; i < 64; ++i) {
-               stats[i].freqs[255] /= 2;  // zero, has no sign bits (yes, this is trickery)
+               stats[i].freqs[NUM_SYMS - 1] /= 2;  // zero, has no sign bits (yes, this is trickery)
                stats[i].normalize_freqs(prob_scale);
-               stats[i].cum_freqs[256] += stats[i].freqs[255];
-               stats[i].freqs[255] *= 2;
+               stats[i].cum_freqs[NUM_SYMS] += stats[i].freqs[NUM_SYMS - 1];
+               stats[i].freqs[NUM_SYMS - 1] *= 2;
        }
 
        FILE *codedfp = fopen("coded.dat", "wb");