]> git.sesse.net Git - narabu/blobdiff - qdd.cpp
Update qdd with newer DC coefficient predictions.
[narabu] / qdd.cpp
diff --git a/qdd.cpp b/qdd.cpp
index 522957d3f8de83afd17a291d8fb4f4eb460af866..d9b788c6c080ee586bdccbdee0cdf0caed22bc2a 100644 (file)
--- a/qdd.cpp
+++ b/qdd.cpp
@@ -6,8 +6,15 @@
 
 #define WIDTH 1280
 #define HEIGHT 720
+#define WIDTH_BLOCKS (WIDTH/8)
+#define WIDTH_BLOCKS_CHROMA (WIDTH/16)
+#define HEIGHT_BLOCKS (HEIGHT/8)
+#define NUM_BLOCKS (WIDTH_BLOCKS * HEIGHT_BLOCKS)
+#define NUM_BLOCKS_CHROMA (WIDTH_BLOCKS_CHROMA * HEIGHT_BLOCKS)
+
 #define NUM_SYMS 256
 #define ESCAPE_LIMIT (NUM_SYMS - 1)
+#define BLOCKS_PER_STREAM 320
 
 #include "ryg_rans/rans_byte.h"
 
@@ -208,10 +215,17 @@ int main(void)
        }
        fclose(fp);
 
-       // DC coefficient pred from the right to left
-       for (unsigned yb = 0; yb < HEIGHT; yb += 8) {
-               for (int xb = WIDTH - 16; xb >= 0; xb -= 8) {
-                       coeff[yb * WIDTH + xb] += coeff[yb * WIDTH + (xb + 8)];
+       // DC coefficient pred from the right to left (within each slice)
+       for (unsigned block_idx = 0; block_idx < NUM_BLOCKS; block_idx += BLOCKS_PER_STREAM) {
+               int prev_k = 128;
+
+               for (unsigned subblock_idx = BLOCKS_PER_STREAM; subblock_idx --> 0; ) {
+                       unsigned yb = (block_idx + subblock_idx) / WIDTH_BLOCKS;
+                       unsigned xb = (block_idx + subblock_idx) % WIDTH_BLOCKS;
+                       int k = coeff[(yb * 8) * WIDTH + (xb * 8)];
+
+                       prev_k += k;
+                       coeff[(yb * 8) * WIDTH + (xb * 8)] = prev_k;
                }
        }