X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=qdd.cpp;h=d9b788c6c080ee586bdccbdee0cdf0caed22bc2a;hb=929ed30933ca58ca55abeea2217756f6b0b9410e;hp=a4fa907a297549f03d0860bb016d41fb7bf83420;hpb=8989d0f3ce3d2c5074aeb5be4297fda30d3efc67;p=narabu diff --git a/qdd.cpp b/qdd.cpp index a4fa907..d9b788c 100644 --- 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" @@ -29,7 +36,8 @@ struct RansDecodeTable { int cum2sym[prob_scale]; RansDecSymbol dsyms[NUM_SYMS]; }; -RansDecodeTable decode_tables[16]; +#define NUM_TABLES 8 +RansDecodeTable decode_tables[NUM_TABLES]; static const unsigned char std_luminance_quant_tbl[64] = { #if 0 @@ -55,10 +63,34 @@ static const unsigned char std_luminance_quant_tbl[64] = { }; -int pick_stats_for(int y, int x) +const int luma_mapping[64] = { + 0, 0, 1, 1, 2, 2, 3, 3, + 0, 0, 1, 2, 2, 2, 3, 3, + 1, 1, 2, 2, 2, 3, 3, 3, + 1, 1, 2, 2, 2, 3, 3, 3, + 1, 2, 2, 2, 2, 3, 3, 3, + 2, 2, 2, 2, 3, 3, 3, 3, + 2, 2, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, +}; +const int chroma_mapping[64] = { + 0, 1, 1, 2, 2, 2, 3, 3, + 1, 1, 2, 2, 2, 3, 3, 3, + 2, 2, 2, 2, 3, 3, 3, 3, + 2, 2, 2, 3, 3, 3, 3, 3, + 2, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, +}; + +int pick_stats_for(int x, int y, bool is_chroma) { - if (x + y >= 7) return 7; - return x + y; + if (is_chroma) { + return chroma_mapping[y * 8 + x] + 4; + } else { + return luma_mapping[y * 8 + x]; + } } uint32_t read_varint(FILE *fp) @@ -103,8 +135,8 @@ int main(void) exit(1); } - uint32_t sign_bias[16]; - for (unsigned table = 0; table < 16; ++table) { + uint32_t sign_bias[NUM_TABLES]; + for (unsigned table = 0; table < NUM_TABLES; ++table) { uint32_t cum_freq = 0; for (unsigned sym = 0; sym < NUM_SYMS; ++sym) { uint32_t freq = read_varint(fp); @@ -123,7 +155,7 @@ int main(void) // loop over all coefficients for (unsigned y = 0; y < 8; ++y) { for (unsigned x = 0; x < 8; ++x) { - unsigned tbl = pick_stats_for(x, y); + unsigned tbl = pick_stats_for(x, y, false); RansState rans = 0; @@ -183,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; } }