/* C1V2 video decoder (the format is specified in r32x/c1.py). Portable C99: the same * file builds for the SH-2 and for the host test (player32x/c1/host_test.c). */ #ifndef C1DEC_H #define C1DEC_H #include /* Stored width (a multiple of 16): 320, or narrower with black borders (option 3, * 288). Build with -DC1_WIDTH=288; the stream's header must say the same. */ #ifndef C1_WIDTH #define C1_WIDTH 320 #endif #define C1_W C1_WIDTH #define C1_FBW 320 /* a frame-buffer row: the VDP always shows 320 */ #define C1_FBX ((C1_FBW - C1_W) / 2) /* the left border */ #define C1_ROWS 192 #define C1_MBX (C1_W / 16) #define C1_MBY (C1_ROWS / 16) #define C1_NMB (C1_MBX * C1_MBY) #define C1_HALF (C1_NMB / 2) #define C1_LINES 224 typedef struct { uint8_t *y; /* C1_ROWS x C1_W */ uint8_t *cb; /* C1_ROWS/2 x C1_W/2 */ uint8_t *cr; } c1_planes; /* Scratch and table copies, one per CPU (the two SH-2s decode at the same time); * c1_fast_init fills the tables. */ typedef struct { /* offsets are fixed: c1asm.s uses them */ int32_t t[64]; /* +0 IDCT pass 1 (the assembly keeps int16 tT[c*8+u] here) */ int32_t res[64]; /* +256 IDCT output */ int16_t coef[64]; /* +512 dequantised block */ int16_t si[64]; /* +640 intra steps for this frame's q */ int16_t kt[64]; /* +768 IDCT basis transposed: kt[c*8+v] = C1_K[v*8+c] */ uint8_t zigzag[64]; /* +896 */ uint8_t mintra[64]; /* +960 */ uint8_t cl5[768]; /* +1024 C1_CL5; the conversion tables start here */ int32_t cbt[256]; /* +1792 (BCB[u] << 16) | (GCB[u] & 0xFFFF) */ int32_t crt[256]; /* +2816 (RCR[v] << 16) | (GCR[v] & 0xFFFF) */ uint16_t (*clock)(void); /* C1_PROF builds: a tick source, and the sums per phase */ uint32_t prof[3]; /* skip copies, MC copies, IDCT + add */ /* Butterfly IDCT constants, x16 (c1dec.c idct_bfly_add): K[0][0], the even part's * K[2][0], K[6][0], K[2][1], K[6][1], and ko[k*4 + c] = K[2k+1][c] for c < 4. */ int16_t k0; /* int16 throughout: every operand fits, so gcc can use MULS.W */ int16_t ke[4]; int16_t ko[16]; int16_t t16[64]; /* the butterfly's pass-1 output, t16[u*8 + c] */ int16_t rblk[6][64] __attribute__((aligned(4))); /* an INTER MB's residuals (longword-filled: aligned) */ uint16_t ue8[256]; /* ue() by the next 8 bits: (length << 8) | value, 0 if longer */ } c1_fast_t; void c1_fast_init(c1_fast_t *f); /* The MB where half 2 starts in this payload (format v3: chosen per frame). */ static inline int c1_split(const uint8_t *payload) { return payload[4]; } /* Decode half h (0: MBs 0..split-1, 1: split..239) of one payload against ref into cur. * cur must hold the frame before ref (two buffers in turn): a SKIP MB is copied from ref * only when prev[mb] says it changed in ref's frame, else cur has it already. Start with * prev all 1. changed[mb] = 1 for each MB of the half that is not a SKIP, else 0 (prev * and changed may not alias). Returns 0, or negative on a malformed payload. The halves * are independent: one SH-2 can decode each. */ int c1_decode_half(c1_fast_t *f, const uint8_t *payload, int h, const c1_planes *ref, c1_planes *cur, const uint8_t *prev, uint8_t *changed); /* RGB555 words of the MBs mb0..mb1-1 with mask[mb] != 0 into dst (stored row r, column * x at dst + r * C1_FBW + C1_FBX + x; dst 4-byte aligned). */ void c1_to_rgb555(const c1_fast_t *f, const c1_planes *p, volatile uint16_t *dst, const uint8_t *mask, int mb0, int mb1); /* The 32X line table for direct colour: line i -> word offset base + row(i) * C1_FBW. */ void c1_line_table(volatile uint16_t *table, uint16_t base); #endif