#include "bccmodels.h"
+#include "bcresources.h"
+#include "condition.h"
+#include "linklist.h"
+#include "mutex.h"
+#include "thread.h"
#include "clip.h"
static inline float clp(const int n, float v) {
ZTYP(int);
ZTYP(float);
-// All variables are unsigned
-// y -> 24 bits u, v, -> 8 bits r, g, b -> 8 bits
-#define YUV_TO_RGB(y, u, v, r, g, b) \
-{ \
- (r) = ((y + vtor_tab[v]) >> 16); \
- (g) = ((y + utog_tab[u] + vtog_tab[v]) >> 16); \
- (b) = ((y + utob_tab[u]) >> 16); \
- CLAMP(r, 0, 0xff); CLAMP(g, 0, 0xff); CLAMP(b, 0, 0xff); \
-}
-
-// y -> 0 - 1 float
-// u, v, -> 8 bits
-// r, g, b -> float
-#define YUV_TO_FLOAT(y, u, v, r, g, b) \
-{ \
- (r) = y + vtor_float_tab[v]; \
- (g) = y + utog_float_tab[u] + vtog_float_tab[v]; \
- (b) = y + utob_float_tab[u]; \
-}
-
-// y -> 0 - 1 float
-// u, v, -> 16 bits
-// r, g, b -> float
-#define YUV16_TO_RGB_FLOAT(y, u, v, r, g, b) \
-{ \
- (r) = y + v16tor_float_tab[v]; \
- (g) = y + u16tog_float_tab[u] + v16tog_float_tab[v]; \
- (b) = y + u16tob_float_tab[u]; \
-}
-
-// y -> 24 bits u, v-> 16 bits
-#define YUV_TO_RGB16(y, u, v, r, g, b) \
-{ \
- (r) = ((y + vtor_tab16[v]) >> 8); \
- (g) = ((y + utog_tab16[u] + vtog_tab16[v]) >> 8); \
- (b) = ((y + utob_tab16[u]) >> 8); \
- CLAMP(r, 0, 0xffff); CLAMP(g, 0, 0xffff); CLAMP(b, 0, 0xffff); \
-}
-
-
-
-
-#define RGB_TO_YUV(y, u, v, r, g, b) \
-{ \
- y = ((rtoy_tab[r] + gtoy_tab[g] + btoy_tab[b]) >> 16); \
- u = ((rtou_tab[r] + gtou_tab[g] + btou_tab[b]) >> 16); \
- v = ((rtov_tab[r] + gtov_tab[g] + btov_tab[b]) >> 16); \
- CLAMP(y, 0, 0xff); CLAMP(u, 0, 0xff); CLAMP(v, 0, 0xff); \
-}
-
-// r, g, b -> 16 bits
-#define RGB_TO_YUV16(y, u, v, r, g, b) \
-{ \
- y = ((rtoy_tab16[r] + gtoy_tab16[g] + btoy_tab16[b]) >> 8); \
- u = ((rtou_tab16[r] + gtou_tab16[g] + btou_tab16[b]) >> 8); \
- v = ((rtov_tab16[r] + gtov_tab16[g] + btov_tab16[b]) >> 8); \
- CLAMP(y, 0, 0xffff); CLAMP(u, 0, 0xffff); CLAMP(v, 0, 0xffff); \
-}
-
#define xfer_flat_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
oty_t *out = (oty_t *)(output_rows[i + out_y] + out_x * out_pixelsize); \
#define xfer_flat_row_in(ity_t) \
// yuv420p 2x2
#define xfer_yuv420p_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *yop = (oty_t *)(out_yp + out_rofs); \
out_rofs = i / 2 * total_out_w / 2 + out_x / 2; \
oty_t *vop = (oty_t *)(out_vp + out_rofs); \
#define xfer_yuv420p_row_in(ity_t) \
- int in_rofs = row_table[i] * total_in_w; \
+ int in_r = row_table[i]; \
+ int in_rofs = in_r * total_in_w; \
uint8_t *yip_row = in_yp + in_rofs; \
- in_rofs = row_table[i] / 2 * total_in_w / 2; \
+ in_rofs = in_r / 2 * total_in_w / 2; \
+ uint8_t *uip_row = in_up + in_rofs; \
+ uint8_t *vip_row = in_vp + in_rofs; \
+ for( unsigned j=0; j<out_w; ++j ) { \
+ int in_ofs = column_table[j]; \
+ ity_t *yip = (ity_t *)(yip_row + in_ofs); \
+ in_ofs /= 2; \
+ ity_t *uip = (ity_t *)(uip_row + in_ofs); \
+ ity_t *vip = (ity_t *)(vip_row + in_ofs); \
+
+// yuv420pi 2x2
+#define xfer_yuv420pi_row_out(oty_t) \
+ for( unsigned i=y0; i<y1; ++i ) { \
+ int out_rofs = i * total_out_w + out_x; \
+ oty_t *yop = (oty_t *)(out_yp + out_rofs); \
+ int ot_k = ((i/4)<<1) + (i&1); \
+ out_rofs = ot_k * total_out_w / 2 + out_x / 2; \
+ oty_t *uop = (oty_t *)(out_up + out_rofs); \
+ oty_t *vop = (oty_t *)(out_vp + out_rofs); \
+
+#define xfer_yuv420pi_row_in(ity_t) \
+ int in_r = row_table[i]; \
+ int in_rofs = in_r * total_in_w; \
+ uint8_t *yip_row = in_yp + in_rofs; \
+ int in_k = ((in_r/4)<<1) + (in_r&1); \
+ in_rofs = in_k * total_in_w / 2; \
uint8_t *uip_row = in_up + in_rofs; \
uint8_t *vip_row = in_vp + in_rofs; \
for( unsigned j=0; j<out_w; ++j ) { \
// yuv422p 2x1
#define xfer_yuv422p_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *yop = (oty_t *)(out_yp + out_rofs); \
out_rofs = i * total_out_w / 2 + out_x / 2; \
// yuv444p 1x1
#define xfer_yuv444p_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *yop = (oty_t *)((oty_t *)(out_yp + out_rofs)); \
oty_t *uop = (oty_t *)(out_up + out_rofs); \
// yuv411p 4x1
#define xfer_yuv411p_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *yop = (oty_t *)(out_yp + out_rofs); \
out_rofs = i * total_out_w / 4 + out_x / 4; \
// yuv410p 4x4
#define xfer_yuv410p_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *yop = (oty_t *)(out_yp + out_rofs); \
out_rofs = i / 4 * total_out_w / 4 + out_x / 4; \
// rgb_floatp
#define xfer_rgb_fltp_row_out(oty_t) \
- for( unsigned i=0; i<out_h; ++i ) { \
+ for( unsigned i=y0; i<y1; ++i ) { \
int out_rofs = i * total_out_w + out_x; \
oty_t *rop = (oty_t *)(out_yp + out_rofs); \
oty_t *gop = (oty_t *)(out_up + out_rofs); \
uint32_t bg_r, bg_g, bg_b;
void xfer();
-
- static void init();
- static class Tables { public: Tables() { init(); } } tables;
- static int rtoy_tab[0x100], gtoy_tab[0x100], btoy_tab[0x100];
- static int rtou_tab[0x100], gtou_tab[0x100], btou_tab[0x100];
- static int rtov_tab[0x100], gtov_tab[0x100], btov_tab[0x100];
- static int vtor_tab[0x100], vtog_tab[0x100];
- static int utog_tab[0x100], utob_tab[0x100];
- static float vtor_float_tab[0x100], vtog_float_tab[0x100];
- static float utog_float_tab[0x100], utob_float_tab[0x100];
- static int rtoy_tab16[0x10000], gtoy_tab16[0x10000], btoy_tab16[0x10000];
- static int rtou_tab16[0x10000], gtou_tab16[0x10000], btou_tab16[0x10000];
- static int rtov_tab16[0x10000], gtov_tab16[0x10000], btov_tab16[0x10000];
- static int vtor_tab16[0x10000], vtog_tab16[0x10000];
- static int utog_tab16[0x10000], utob_tab16[0x10000];
- static float v16tor_float_tab[0x10000], v16tog_float_tab[0x10000];
- static float u16tog_float_tab[0x10000], u16tob_float_tab[0x10000];
+ void xfer_slices(int slices);
+ typedef void (BC_Xfer::*xfer_fn)(unsigned y0, unsigned y1);
+ xfer_fn xfn;
+
+ class Slicer : public ListItem<Slicer>, public Thread {
+ public:
+ Condition *init, *complete;
+ Slicer(BC_Xfer *xp);
+ ~Slicer();
+ void slice(BC_Xfer *xp, unsigned y0, unsigned y1);
+ void run();
+ BC_Xfer *xp;
+ int done, y0, y1;
+ };
+
+ class SlicerList : public List<Slicer>, public Mutex {
+ public:
+ int count;
+ Slicer *get_slicer(BC_Xfer *xp);
+ void reset();
+ SlicerList();
+ ~SlicerList();
+ };
+ static SlicerList slicers;
void init(
uint8_t **output_rows, int out_colormodel, int out_x, int out_y, int out_w, int out_h,