X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=qdc.cpp;h=4bb3e9e75c3696eec5b60ed7a976fbefb212d912;hb=3fb87c6b953be3382cd216c74ff6aa025c8eaa2a;hp=094f3b6b7e0e80b451b288bcce4d458cbcabde45;hpb=24788ba6718ad43947927e45955cfe4fc95c295e;p=narabu diff --git a/qdc.cpp b/qdc.cpp index 094f3b6..4bb3e9e 100644 --- a/qdc.cpp +++ b/qdc.cpp @@ -5,8 +5,8 @@ #include #include -//#include "ryg_rans/rans64.h" -#include "ryg_rans/rans_byte.h" +#include "ryg_rans/rans64.h" +//#include "ryg_rans/rans_byte.h" #include "ryg_rans/renormalize.h" #include @@ -198,11 +198,7 @@ int pick_stats_for(int x, int y, bool is_chroma) void write_varint(int x, FILE *fp) { - while (x >= 128) { - putc((x & 0x7f) | 0x80, fp); - x >>= 7; - } - putc(x, fp); + fwrite(&x, sizeof(x), 1, fp); } class RansEncoder { @@ -217,7 +213,7 @@ public: { for (int i = 0; i < NUM_SYMS; i++) { //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); + Rans64EncSymbolInit(&esyms[i], s.cum_freqs[i], s.freqs[i], prob_bits + 1); } sign_bias = s.cum_freqs[NUM_SYMS]; } @@ -226,12 +222,12 @@ public: { out_end = out_buf.get() + out_max_size; ptr = out_end; // *end* of output buffer - RansEncInit(&rans); + Rans64EncInit(&rans); } uint32_t save_block(FILE *codedfp) // Returns number of bytes. { - RansEncFlush(&rans, &ptr); + Rans64EncFlush(&rans, (uint32_t **)&ptr); //printf("post-flush = %08x\n", rans); uint32_t num_rans_bytes = out_end - ptr; @@ -268,16 +264,16 @@ public: void encode_coeff(short signed_k) { - //printf("encoding coeff %d (sym %d), rans before encoding = %08x\n", signed_k, ((abs(signed_k) - 1) & 255), rans); + //printf("encoding coeff %d (sym %d), rans before encoding = %016lx\n", signed_k, ((abs(signed_k) - 1) & 255), rans); unsigned short k = abs(signed_k); if (k >= ESCAPE_LIMIT) { // Put the coefficient as a 1/(2^12) symbol _before_ // the 255 coefficient, since the decoder will read the // 255 coefficient first. - RansEncPut(&rans, &ptr, k, 1, prob_bits); + Rans64EncPut(&rans, (uint32_t **)&ptr, k, 1, prob_bits); k = ESCAPE_LIMIT; } - RansEncPutSymbol(&rans, &ptr, &esyms[(k - 1) & (NUM_SYMS - 1)]); + Rans64EncPutSymbol(&rans, (uint32_t **)&ptr, &esyms[(k - 1) & (NUM_SYMS - 1)], prob_bits + 1); if (signed_k < 0) { rans += sign_bias; } @@ -290,8 +286,8 @@ private: unique_ptr out_buf; uint8_t *out_end; uint8_t *ptr; - RansState rans; - RansEncSymbol esyms[NUM_SYMS]; + Rans64State rans; + Rans64EncSymbol esyms[NUM_SYMS]; uint32_t sign_bias; uint32_t last_block = 0; // Not a valid 4-byte rANS block (?)