diff --git a/common/quic_rgb_tmpl.c b/common/quic_rgb_tmpl.c index 2221201..29f1cab 100644 --- a/common/quic_rgb_tmpl.c +++ b/common/quic_rgb_tmpl.c @@ -19,71 +19,10 @@ #include #endif +#define COMPRESS_IMP + #define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__) #define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__) - -#ifdef QUIC_RGB32 -#undef QUIC_RGB32 -#define PIXEL rgb32_pixel_t -#define FNAME(name) quic_rgb32_##name -#define BPC 8 -#define COMPRESS_IMP -#define SET_r(pix, val) ((pix)->r = val) -#define GET_r(pix) ((pix)->r) -#define SET_g(pix, val) ((pix)->g = val) -#define GET_g(pix) ((pix)->g) -#define SET_b(pix, val) ((pix)->b = val) -#define GET_b(pix) ((pix)->b) -#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0) -#endif - -#ifdef QUIC_RGB24 -#undef QUIC_RGB24 -#define PIXEL rgb24_pixel_t -#define FNAME(name) quic_rgb24_##name -#define BPC 8 -#define COMPRESS_IMP -#define SET_r(pix, val) ((pix)->r = val) -#define GET_r(pix) ((pix)->r) -#define SET_g(pix, val) ((pix)->g = val) -#define GET_g(pix) ((pix)->g) -#define SET_b(pix, val) ((pix)->b = val) -#define GET_b(pix) ((pix)->b) -#define UNCOMPRESS_PIX_START(pix) -#endif - -#ifdef QUIC_RGB16 -#undef QUIC_RGB16 -#define PIXEL rgb16_pixel_t -#define FNAME(name) quic_rgb16_##name -#define BPC 5 -#define COMPRESS_IMP -#define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10)) -#define GET_r(pix) ((*(pix) >> 10) & 0x1f) -#define SET_g(pix, val) (*(pix) = (*(pix) & ~(0x1f << 5)) | ((val) << 5)) -#define GET_g(pix) ((*(pix) >> 5) & 0x1f) -#define SET_b(pix, val) (*(pix) = (*(pix) & ~0x1f) | (val)) -#define GET_b(pix) (*(pix) & 0x1f) -#define UNCOMPRESS_PIX_START(pix) (*(pix) = 0) -#endif - -#ifdef QUIC_RGB16_TO_32 -#undef QUIC_RGB16_TO_32 -#define PIXEL rgb32_pixel_t -#define FNAME(name) quic_rgb16_to_32_##name -#define BPC 5 -#define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2)) -#define GET_r(pix) ((pix)->r >> 3) -#define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2)) -#define GET_g(pix) ((pix)->g >> 3) -#define SET_b(pix, val) ((pix)->b = ((val) << 3) | (((val) & 0x1f) >> 2)) -#define GET_b(pix) ((pix)->b >> 3) -#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0) -#endif - -#define FNAME_DECL(name) FNAME(name) FARGS_DECL -#define FNAME_CALL(name) FNAME(name) FARGS_CALL - #define SAME_PIXEL(p1, p2) \ (GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) && \ GET_b(p1) == GET_b(p2)) @@ -100,6 +39,70 @@ BYTE * const correlate_row_r = channel_r->correlate_row; \ BYTE * const correlate_row_g = channel_g->correlate_row; \ BYTE * const correlate_row_b = channel_b->correlate_row +#define APPLY_ALL_COMP(macro, ...) \ + macro(r, ## __VA_ARGS__); \ + macro(g, ## __VA_ARGS__); \ + macro(b, ## __VA_ARGS__) + +#ifdef QUIC_RGB32 +#undef QUIC_RGB32 +#define PIXEL rgb32_pixel_t +#define FNAME(name) quic_rgb32_##name +#define BPC 8 +#define SET_r(pix, val) ((pix)->r = val) +#define GET_r(pix) ((pix)->r) +#define SET_g(pix, val) ((pix)->g = val) +#define GET_g(pix) ((pix)->g) +#define SET_b(pix, val) ((pix)->b = val) +#define GET_b(pix) ((pix)->b) +#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0) +#endif + +#ifdef QUIC_RGB24 +#undef QUIC_RGB24 +#define PIXEL rgb24_pixel_t +#define FNAME(name) quic_rgb24_##name +#define BPC 8 +#define SET_r(pix, val) ((pix)->r = val) +#define GET_r(pix) ((pix)->r) +#define SET_g(pix, val) ((pix)->g = val) +#define GET_g(pix) ((pix)->g) +#define SET_b(pix, val) ((pix)->b = val) +#define GET_b(pix) ((pix)->b) +#define UNCOMPRESS_PIX_START(pix) +#endif + +#ifdef QUIC_RGB16 +#undef QUIC_RGB16 +#define PIXEL rgb16_pixel_t +#define FNAME(name) quic_rgb16_##name +#define BPC 5 +#define SET_r(pix, val) (*(pix) = (*(pix) & ~(0x1f << 10)) | ((val) << 10)) +#define GET_r(pix) ((*(pix) >> 10) & 0x1f) +#define SET_g(pix, val) (*(pix) = (*(pix) & ~(0x1f << 5)) | ((val) << 5)) +#define GET_g(pix) ((*(pix) >> 5) & 0x1f) +#define SET_b(pix, val) (*(pix) = (*(pix) & ~0x1f) | (val)) +#define GET_b(pix) (*(pix) & 0x1f) +#define UNCOMPRESS_PIX_START(pix) (*(pix) = 0) +#endif + +#ifdef QUIC_RGB16_TO_32 +#undef QUIC_RGB16_TO_32 +#define PIXEL rgb32_pixel_t +#define FNAME(name) quic_rgb16_to_32_##name +#define BPC 5 +#define COMPRESS_IMP +#define SET_r(pix, val) ((pix)->r = ((val) << 3) | (((val) & 0x1f) >> 2)) +#define GET_r(pix) ((pix)->r >> 3) +#define SET_g(pix, val) ((pix)->g = ((val) << 3) | (((val) & 0x1f) >> 2)) +#define GET_g(pix) ((pix)->g >> 3) +#define SET_b(pix, val) ((pix)->b = ((val) << 3) | (((val) & 0x1f) >> 2)) +#define GET_b(pix) ((pix)->b >> 3) +#define UNCOMPRESS_PIX_START(pix) ((pix)->pad = 0) +#endif + +#define FNAME_DECL(name) FNAME(name) FARGS_DECL +#define FNAME_CALL(name) FNAME(name) FARGS_CALL #if BPC == 5 # define golomb_coding golomb_coding_5bpc @@ -156,11 +159,6 @@ correlate_row_##channel[index]) #define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index) -#define APPLY_ALL_COMP(macro, ...) \ - macro(r, ## __VA_ARGS__); \ - macro(g, ## __VA_ARGS__); \ - macro(b, ## __VA_ARGS__) - #define RLE_PRED_IMP \ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) { \ if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) { \ @@ -212,6 +210,9 @@ static void FNAME_DECL(compress_row0_seg)(int i, state->waitcnt = stopidx - end; } +#undef COMPRESS_ONE_ROW0_0 +#undef COMPRESS_ONE_ROW0 + static void FNAME_DECL(compress_row0)(const PIXEL *cur_row, unsigned int width) { DECLARE_STATE_VARIABLES; @@ -605,8 +606,6 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row, #undef UPDATE_MODEL #undef DECORRELATE_0 #undef DECORRELATE -#undef COMPRESS_ONE_ROW0_0 -#undef COMPRESS_ONE_ROW0 #undef COMPRESS_ONE_0 #undef COMPRESS_ONE #undef CORRELATE_0 diff --git a/common/quic_tmpl.c b/common/quic_tmpl.c index 525eb99..96db766 100644 --- a/common/quic_tmpl.c +++ b/common/quic_tmpl.c @@ -19,28 +19,11 @@ #include #endif -#ifdef ONE_BYTE -#undef ONE_BYTE -#define FNAME(name) quic_one_##name -#define PIXEL one_byte_t -#endif - -#ifdef FOUR_BYTE -#undef FOUR_BYTE -#define FNAME(name) quic_four_##name -#define PIXEL four_bytes_t -#endif - #define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__) #define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__) -#define FNAME_DECL(name) FNAME(name) FARGS_DECL -#define FNAME_CALL(name) FNAME(name) FARGS_CALL - -#define BPC 8 - +#define UNCOMPRESS_PIX_START(row) do { } while (0) #define SET_a(pix, val) ((pix)->a = val) #define GET_a(pix) ((pix)->a) - #define SAME_PIXEL(p1, p2) \ (GET_a(p1) == GET_a(p2)) #define COPY_PIXEL(dest, src) \ @@ -49,6 +32,27 @@ CommonState *state = &channel_a->state #define DECLARE_CHANNEL_VARIABLES \ BYTE * const correlate_row_a = channel_a->correlate_row +#define APPLY_ALL_COMP(macro, ...) \ + macro(a, ## __VA_ARGS__) + +#ifdef ONE_BYTE +#undef ONE_BYTE +#define FNAME(name) quic_one_##name +#define PIXEL one_byte_t +#define BPC 8 + +#endif + +#ifdef FOUR_BYTE +#undef FOUR_BYTE +#define FNAME(name) quic_four_##name +#define PIXEL four_bytes_t +#define BPC 8 + +#endif + +#define FNAME_DECL(name) FNAME(name) FARGS_DECL +#define FNAME_CALL(name) FNAME(name) FARGS_CALL #if BPC == 8 # define golomb_coding golomb_coding_8bpc @@ -64,13 +68,6 @@ #define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1)) #define _PIXEL_B(channel, prev) ((unsigned int)GET_##channel(prev)) -#define RLE_PRED_IMP \ -if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) { \ - if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) { \ - goto do_run; \ - } \ -} - /* a */ #define DECORRELATE_0(channel, curr, bpc_mask)\ @@ -107,8 +104,12 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) { correlate_row_##channel[index]) #define UPDATE_MODEL(index) APPLY_ALL_COMP(UPDATE_MODEL_COMP, index) -#define APPLY_ALL_COMP(macro, ...) \ - macro(a, ## __VA_ARGS__) +#define RLE_PRED_IMP \ +if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) { \ + if (run_index != i && i > 2 && SAME_PIXEL(&cur_row[i - 1], &cur_row[i - 2])) { \ + goto do_run; \ + } \ +} static void FNAME_DECL(compress_row0_seg)(int i, const PIXEL * const cur_row, @@ -301,8 +302,6 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row, spice_assert(DEFwminext > 0); } -#define UNCOMPRESS_PIX_START(row) do { } while (0) - #define UNCOMPRESS_ONE_ROW0_0(channel) \ correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel, \ correlate_row_##channel[-1])->bestcode, \ @@ -542,10 +541,17 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row, #undef _PIXEL_B #undef SAME_PIXEL #undef RLE_PRED_IMP +#undef UPDATE_MODEL #undef DECORRELATE_0 #undef DECORRELATE +#undef COMPRESS_ONE_0 +#undef COMPRESS_ONE #undef CORRELATE_0 #undef CORRELATE +#undef UNCOMPRESS_ONE_ROW0_0 +#undef UNCOMPRESS_ONE_ROW0 +#undef UNCOMPRESS_ONE_0 +#undef UNCOMPRESS_ONE #undef golomb_coding #undef golomb_decoding #undef update_model @@ -553,17 +559,10 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row, #undef family #undef BPC #undef BPC_MASK -#undef UPDATE_MODEL -#undef UNCOMPRESS_PIX_START -#undef UPDATE_MODEL_COMP -#undef COMPRESS_ONE_0 -#undef COMPRESS_ONE -#undef UNCOMPRESS_ONE_ROW0 -#undef UNCOMPRESS_ONE_ROW0_0 -#undef UNCOMPRESS_ONE_0 -#undef UNCOMPRESS_ONE #undef SET_a #undef GET_a +#undef UNCOMPRESS_PIX_START +#undef UPDATE_MODEL_COMP #undef APPLY_ALL_COMP #undef DECLARE_STATE_VARIABLES #undef DECLARE_CHANNEL_VARIABLES