]> git.sesse.net Git - narabu/commitdiff
Add support for repeating blocks. About 2% size reduction.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 6 Oct 2017 18:08:46 +0000 (20:08 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 6 Oct 2017 18:08:46 +0000 (20:08 +0200)
coded.dat
narabu.cpp
qdc.cpp

index b249f4cc37271b75b0e67e977769665a3160db63..a81138917ee68b42279ee1b4130f012bcade8d81 100644 (file)
Binary files a/coded.dat and b/coded.dat differ
index bb1209c7fc3ebe7c4bf66123567736cb6bff3854..0ac4f71d75ab58794da432e64c22ea0811cdb437 100644 (file)
@@ -223,6 +223,7 @@ int main(int argc, char **argv)
        printf("%d err=0x%x\n", __LINE__, glGetError());
 
        // Decode all luma blocks.
+       size_t last_src_offset = 0, last_src_len = 0;
        for (unsigned y = 0; y < 8; ++y) {
                 for (unsigned x = 0; x < 8; ++x) {
                        unsigned coeff_num = y * 8 + x;
@@ -235,8 +236,16 @@ int main(int argc, char **argv)
                                }
 
                                CoeffStream *stream = &streams[coeff_num * num_blocks + block_idx / BLOCKS_PER_STREAM];
-                               stream->src_offset = ptr - coded.data();
-                               stream->src_len = *num_rans_bytes;
+                               if (*num_rans_bytes == 0) {
+                                       // Repeat last stream.
+                                       stream->src_offset = last_src_offset;
+                                       stream->src_len = last_src_len;
+                               } else {
+                                       stream->src_offset = ptr - coded.data();
+                                       stream->src_len = *num_rans_bytes;
+                                       last_src_offset = stream->src_offset;
+                                       last_src_len = last_src_len;
+                               }
 
                                // TODO: check len
                                ptr += *num_rans_bytes;
diff --git a/qdc.cpp b/qdc.cpp
index 41ef04df00f95f3714e1617326fb4d4c4f5ddefa..0339e12af0ad07ba2616530b30bd1b2012258745 100644 (file)
--- a/qdc.cpp
+++ b/qdc.cpp
@@ -235,22 +235,14 @@ public:
                //printf("post-flush = %08x\n", rans);
 
                uint32_t num_rans_bytes = out_end - ptr;
-#if 0
-               if (num_rans_bytes == 4) {
-                       uint32_t block;
-                       memcpy(&block, ptr, 4);
-
-                       if (block == last_block) {
-                               write_varint(0, codedfp);
-                               clear();
-                               return 1;
-                       }
-
-                       last_block = block;
+               if (num_rans_bytes == last_block.size() &&
+                   memcmp(last_block.data(), ptr, last_block.size()) == 0) {
+                       write_varint(0, codedfp);
+                       clear();
+                       return 1;
                } else {
-                       last_block = 0;
+                       last_block = string((const char *)ptr, num_rans_bytes);
                }
-#endif
 
                write_varint(num_rans_bytes, codedfp);
                //fwrite(&num_rans_bytes, 1, 4, codedfp);
@@ -294,7 +286,7 @@ private:
        RansEncSymbol esyms[NUM_SYMS];
        uint32_t sign_bias;
 
-       uint32_t last_block = 0;  // Not a valid 4-byte rANS block (?)
+       std::string last_block;
 };
 
 static constexpr int dc_scalefac = 8;  // Matches the FDCT's gain.