]> git.sesse.net Git - narabu/commitdiff
Add more off-by-one fixes.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 16 Oct 2017 21:58:36 +0000 (23:58 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 16 Oct 2017 21:58:36 +0000 (23:58 +0200)
rans.shader

index 0c0bf8b25ff03f1cf5cfba4d0dfa8818e8d5aa3d..8e9c4226a80a0b8595f4072490f93c072cac710d 100644 (file)
@@ -3,7 +3,7 @@
 
 layout(local_size_x = 1) in;
 
-const uint prob_bits = 13;  // Note!
+const uint prob_bits = 12;
 const uint prob_scale = 1 << prob_bits;
 const uint RANS_BYTE_L = (1u << 23);
 const uint BLOCKS_PER_STREAM = 320;
@@ -98,12 +98,12 @@ void encode_coeff(int signed_k, uint sign_bias, inout RansEncoder enc)
 
        if (k >= ESCAPE_LIMIT) {
                // ... boring stuff here
-               RansEncPut(enc.rans, enc.rans_offset, k, 1, prob_bits - 1);
+               RansEncPut(enc.rans, enc.rans_offset, k, 1, prob_bits);
                k = ESCAPE_LIMIT;
        }
 
-       uvec2 sym = ransdist[enc.lut_base + ((k + NUM_SYMS - 1) & (NUM_SYMS - 1))];
-       RansEncPut(enc.rans, enc.rans_offset, sym.x, sym.y, prob_bits);
+       uvec2 sym = ransdist[enc.lut_base + ((k - 1) & (NUM_SYMS - 1))];
+       RansEncPut(enc.rans, enc.rans_offset, sym.x, sym.y, prob_bits + 1);
        
        if (signed_k < 0) {
                enc.rans += sign_bias;