quic: Unify rgb/non-rgb macro declarations

This commit adds a common block of macro declarations at the top of
quic_tmpl.c and quic_rgb_tmpl.c. This block is identical between the 2
files, and is one big step towards making the 2 files identical.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
Frediano Ziglio 2018-07-10 11:02:21 +02:00
parent 79a6ca2a51
commit 3618db77b5
2 changed files with 154 additions and 22 deletions

View File

@ -21,28 +21,59 @@
#define COMPRESS_IMP
#define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
#define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
#define SAME_PIXEL(p1, p2) \
#if defined(ONE_BYTE) || defined(FOUR_BYTE)
# define FARGS_DECL(arg1, ...) (Encoder *encoder, Channel *channel_a, arg1, ##__VA_ARGS__)
# define FARGS_CALL(arg1, ...) (encoder, channel_a, arg1, ##__VA_ARGS__)
# 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) \
SET_a(dest, GET_a(src));
# define DECLARE_STATE_VARIABLES \
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__)
#else
# define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
# define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
# define SAME_PIXEL(p1, p2) \
(GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) && \
GET_b(p1) == GET_b(p2))
#define COPY_PIXEL(dest, src) \
# define COPY_PIXEL(dest, src) \
SET_r(dest, GET_r(src)); \
SET_g(dest, GET_g(src)); \
SET_b(dest, GET_b(src))
#define DECLARE_STATE_VARIABLES \
# define DECLARE_STATE_VARIABLES \
CommonState *state = &encoder->rgb_state
#define DECLARE_CHANNEL_VARIABLES \
# define DECLARE_CHANNEL_VARIABLES \
Channel * const channel_r = encoder->channels; \
Channel * const channel_g = channel_r + 1; \
Channel * const channel_b = channel_g + 1; \
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, ...) \
# define APPLY_ALL_COMP(macro, ...) \
macro(r, ## __VA_ARGS__); \
macro(g, ## __VA_ARGS__); \
macro(b, ## __VA_ARGS__)
#endif
#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
#ifdef QUIC_RGB32
#undef QUIC_RGB32
@ -91,7 +122,7 @@
#define PIXEL rgb32_pixel_t
#define FNAME(name) quic_rgb16_to_32_##name
#define BPC 5
#define COMPRESS_IMP
#undef 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))
@ -628,6 +659,8 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
#undef GET_g
#undef SET_b
#undef GET_b
#undef SET_a
#undef GET_a
#undef UNCOMPRESS_PIX_START
#undef UPDATE_MODEL_COMP
#undef APPLY_ALL_COMP

View File

@ -19,28 +19,53 @@
#include <config.h>
#endif
#define FARGS_DECL(...) (Encoder *encoder, Channel *channel_a, ##__VA_ARGS__)
#define FARGS_CALL(...) (encoder, channel_a, ##__VA_ARGS__)
#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) \
#define COMPRESS_IMP
#if defined(ONE_BYTE) || defined(FOUR_BYTE)
# define FARGS_DECL(arg1, ...) (Encoder *encoder, Channel *channel_a, arg1, ##__VA_ARGS__)
# define FARGS_CALL(arg1, ...) (encoder, channel_a, arg1, ##__VA_ARGS__)
# 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) \
SET_a(dest, GET_a(src));
#define DECLARE_STATE_VARIABLES \
# define DECLARE_STATE_VARIABLES \
CommonState *state = &channel_a->state
#define DECLARE_CHANNEL_VARIABLES \
# define DECLARE_CHANNEL_VARIABLES \
BYTE * const correlate_row_a = channel_a->correlate_row
#define APPLY_ALL_COMP(macro, ...) \
# define APPLY_ALL_COMP(macro, ...) \
macro(a, ## __VA_ARGS__)
#else
# define FARGS_DECL(arg1, ...) (Encoder *encoder, arg1, ##__VA_ARGS__)
# define FARGS_CALL(arg1, ...) (encoder, arg1, ##__VA_ARGS__)
# define SAME_PIXEL(p1, p2) \
(GET_r(p1) == GET_r(p2) && GET_g(p1) == GET_g(p2) && \
GET_b(p1) == GET_b(p2))
# define COPY_PIXEL(dest, src) \
SET_r(dest, GET_r(src)); \
SET_g(dest, GET_g(src)); \
SET_b(dest, GET_b(src))
# define DECLARE_STATE_VARIABLES \
CommonState *state = &encoder->rgb_state
# define DECLARE_CHANNEL_VARIABLES \
Channel * const channel_r = encoder->channels; \
Channel * const channel_g = channel_r + 1; \
Channel * const channel_b = channel_g + 1; \
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__)
#endif
#ifdef ONE_BYTE
#undef ONE_BYTE
#define FNAME(name) quic_one_##name
#define PIXEL one_byte_t
#define BPC 8
#endif
#ifdef FOUR_BYTE
@ -48,13 +73,76 @@
#define FNAME(name) quic_four_##name
#define PIXEL four_bytes_t
#define BPC 8
#endif
#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
#undef 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 == 8
#if BPC == 5
# define golomb_coding golomb_coding_5bpc
# define golomb_decoding golomb_decoding_5bpc
# define update_model update_model_5bpc
# define find_bucket find_bucket_5bpc
# define family family_5bpc
# define BPC_MASK 0x1fU
#elif BPC == 8
# define golomb_coding golomb_coding_8bpc
# define golomb_decoding golomb_decoding_8bpc
# define update_model update_model_8bpc
@ -62,7 +150,7 @@
# define family family_8bpc
# define BPC_MASK 0xffU
#else
# error BPC must be 8
# error BPC must be 5 or 8
#endif
#define _PIXEL_A(channel, curr) ((unsigned int)GET_##channel((curr) - 1))
@ -111,6 +199,8 @@ if (SAME_PIXEL(&prev_row[i - 1], &prev_row[i])) {
} \
}
#ifdef COMPRESS_IMP
static void FNAME_DECL(compress_row0_seg)(int i,
const PIXEL * const cur_row,
const int end,
@ -302,6 +392,8 @@ static void FNAME_DECL(compress_row)(const PIXEL * const prev_row,
spice_assert(DEFwminext > 0);
}
#endif
#define UNCOMPRESS_ONE_ROW0_0(channel) \
correlate_row_##channel[0] = (BYTE)golomb_decoding(find_bucket(channel_##channel, \
correlate_row_##channel[-1])->bestcode, \
@ -559,6 +651,13 @@ static void FNAME_DECL(uncompress_row)(const PIXEL * const prev_row,
#undef family
#undef BPC
#undef BPC_MASK
#undef COMPRESS_IMP
#undef SET_r
#undef GET_r
#undef SET_g
#undef GET_g
#undef SET_b
#undef GET_b
#undef SET_a
#undef GET_a
#undef UNCOMPRESS_PIX_START