Commit 3f26dbbf authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

transform: factor common macro code

parent 4ee68dda
...@@ -113,44 +113,14 @@ static void R270(int *sx, int *sy, int w, int h, int dx, int dy) ...@@ -113,44 +113,14 @@ static void R270(int *sx, int *sy, int w, int h, int dx, int dy)
} }
typedef void (*convert_t)(int *, int *, int, int, int, int); typedef void (*convert_t)(int *, int *, int, int, int, int);
#define PLANAR(f) \ #define PLANE(f,bits) \
static void Plane8_##f(plane_t *restrict dst, const plane_t *restrict src) \ static void Plane##bits##_##f(plane_t *restrict dst, const plane_t *restrict src) \
{ \ { \
for (int y = 0; y < dst->i_visible_lines; y++) { \ const uint##bits##_t *src_pixels = (const void *)src->p_pixels; \
for (int x = 0; x < dst->i_visible_pitch; x++) { \ uint##bits##_t *restrict dst_pixels = (void *)dst->p_pixels; \
int sx, sy; \ const unsigned src_width = src->i_pitch / sizeof (*src_pixels); \
(f)(&sx, &sy, dst->i_visible_pitch, dst->i_visible_lines, x, y); \ const unsigned dst_width = dst->i_pitch / sizeof (*dst_pixels); \
dst->p_pixels[y * dst->i_pitch + x] = \ const unsigned dst_visible_width = dst->i_visible_pitch / sizeof (*dst_pixels); \
src->p_pixels[sy * src->i_pitch + sx]; \
} \
} \
} \
\
static void Plane16_##f(plane_t *restrict dst, const plane_t *restrict src) \
{ \
const uint16_t *src_pixels = (const uint16_t *)src->p_pixels; \
uint16_t *restrict dst_pixels = (uint16_t *)dst->p_pixels; \
unsigned src_width = src->i_pitch / 2; \
unsigned dst_width = dst->i_pitch / 2; \
unsigned dst_visible_width = dst->i_visible_pitch / 2; \
\
for (int y = 0; y < dst->i_visible_lines; y++) { \
for (unsigned x = 0; x < dst_visible_width; x++) { \
int sx, sy; \
(f)(&sx, &sy, dst_visible_width, dst->i_visible_lines, x, y); \
dst_pixels[y * dst_width + x] = \
src_pixels[sy * src_width + sx]; \
} \
} \
} \
\
static void Plane32_##f(plane_t *restrict dst, const plane_t *restrict src) \
{ \
const uint32_t *src_pixels = (const uint32_t *)src->p_pixels; \
uint32_t *restrict dst_pixels = (uint32_t *)dst->p_pixels; \
unsigned src_width = src->i_pitch / 4; \
unsigned dst_width = dst->i_pitch / 4; \
unsigned dst_visible_width = dst->i_visible_pitch / 4; \
\ \
for (int y = 0; y < dst->i_visible_lines; y++) { \ for (int y = 0; y < dst->i_visible_lines; y++) { \
for (unsigned x = 0; x < dst_visible_width; x++) { \ for (unsigned x = 0; x < dst_visible_width; x++) { \
...@@ -160,9 +130,10 @@ static void Plane32_##f(plane_t *restrict dst, const plane_t *restrict src) \ ...@@ -160,9 +130,10 @@ static void Plane32_##f(plane_t *restrict dst, const plane_t *restrict src) \
src_pixels[sy * src_width + sx]; \ src_pixels[sy * src_width + sx]; \
} \ } \
} \ } \
} \ }
\
static void YUYV_##f(plane_t *restrict dst, const plane_t *restrict src) \ #define PLANE_YUY2(f) \
static void PlaneYUY2_##f(plane_t *restrict dst, const plane_t *restrict src) \
{ \ { \
unsigned dst_visible_width = dst->i_visible_pitch / 2; \ unsigned dst_visible_width = dst->i_visible_pitch / 2; \
\ \
...@@ -196,13 +167,16 @@ static void YUYV_##f(plane_t *restrict dst, const plane_t *restrict src) \ ...@@ -196,13 +167,16 @@ static void YUYV_##f(plane_t *restrict dst, const plane_t *restrict src) \
} \ } \
} }
PLANAR(HFlip) #define PLANES(f) \
PLANAR(VFlip) PLANE(f,8) PLANE(f,16) PLANE(f,32) PLANE_YUY2(f)
PLANAR(Transpose)
PLANAR(AntiTranspose) PLANES(HFlip)
PLANAR(R90) PLANES(VFlip)
PLANAR(R180) PLANES(Transpose)
PLANAR(R270) PLANES(AntiTranspose)
PLANES(R90)
PLANES(R180)
PLANES(R270)
typedef struct { typedef struct {
char name[16]; char name[16];
...@@ -216,7 +190,7 @@ typedef struct { ...@@ -216,7 +190,7 @@ typedef struct {
} transform_description_t; } transform_description_t;
#define DESC(str, rotated, f, invf) \ #define DESC(str, rotated, f, invf) \
{ str, rotated, f, invf, Plane8_##f, Plane16_##f, Plane32_##f, YUYV_##f } { str, rotated, f, invf, Plane8_##f, Plane16_##f, Plane32_##f, PlaneYUY2_##f }
static const transform_description_t descriptions[] = { static const transform_description_t descriptions[] = {
DESC("90", true, R90, R270), DESC("90", true, R90, R270),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment