This commit is contained in:
Wim Taymans 2017-05-26 09:09:31 +02:00
parent 5b037661d9
commit 0f6b3a7cab
33 changed files with 652 additions and 673 deletions

View file

@ -17,8 +17,7 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
typedef enum typedef enum {
{
GRAY = 0, GRAY = 0,
YELLOW, YELLOW,
CYAN, CYAN,
@ -37,8 +36,7 @@ typedef enum
typedef struct _Pixel Pixel; typedef struct _Pixel Pixel;
struct _Pixel struct _Pixel {
{
unsigned char R; unsigned char R;
unsigned char G; unsigned char G;
unsigned char B; unsigned char B;
@ -47,8 +45,7 @@ struct _Pixel
unsigned char V; unsigned char V;
}; };
static Pixel colors[N_COLORS] = static Pixel colors[N_COLORS] = {
{
{191, 191, 191, 0, 0, 0}, /* GRAY */ {191, 191, 191, 0, 0, 0}, /* GRAY */
{191, 191, 0, 0, 0, 0}, /* YELLOW */ {191, 191, 0, 0, 0, 0}, /* YELLOW */
{0, 191, 191, 0, 0, 0}, /* CYAN */ {0, 191, 191, 0, 0, 0}, /* CYAN */
@ -63,24 +60,22 @@ static Pixel colors[N_COLORS] =
{9, 9, 9, 0, 0, 0}, /* DARK BLACK */ {9, 9, 9, 0, 0, 0}, /* DARK BLACK */
{29, 29, 29, 0, 0, 0}, /* LIGHT BLACK */ {29, 29, 29, 0, 0, 0}, /* LIGHT BLACK */
}; };
/* YUV values are computed in init_colors() */ /* YUV values are computed in init_colors() */
typedef struct _DrawingData DrawingData; typedef struct _DrawingData DrawingData;
typedef void (*DrawPixelFunc) (DrawingData *dd, typedef void (*DrawPixelFunc) (DrawingData * dd, int x, Pixel * pixel);
int x,
Pixel *pixel);
struct _DrawingData { struct _DrawingData {
char* line; char *line;
int width; int width;
int height; int height;
int stride; int stride;
DrawPixelFunc draw_pixel; DrawPixelFunc draw_pixel;
}; };
static inline void static inline void update_yuv(Pixel * pixel)
update_yuv (Pixel *pixel)
{ {
uint16_t y, u, v; uint16_t y, u, v;
@ -99,8 +94,7 @@ update_yuv (Pixel *pixel)
pixel->V = v + 128; pixel->V = v + 128;
} }
static void static void init_colors(void)
init_colors (void)
{ {
int i; int i;
@ -110,20 +104,18 @@ init_colors (void)
} }
for (i = 0; i < N_COLORS; i++) { for (i = 0; i < N_COLORS; i++) {
update_yuv (&colors[i]); update_yuv(&colors[i]);
} }
} }
static void static void draw_pixel_rgb(DrawingData * dd, int x, Pixel * color)
draw_pixel_rgb (DrawingData *dd, int x, Pixel *color)
{ {
dd->line[3 * x + 0] = color->R; dd->line[3 * x + 0] = color->R;
dd->line[3 * x + 1] = color->G; dd->line[3 * x + 1] = color->G;
dd->line[3 * x + 2] = color->B; dd->line[3 * x + 2] = color->B;
} }
static void static void draw_pixel_uyvy(DrawingData * dd, int x, Pixel * color)
draw_pixel_uyvy (DrawingData *dd, int x, Pixel *color)
{ {
if (x & 1) { if (x & 1) {
/* odd pixel */ /* odd pixel */
@ -136,10 +128,7 @@ draw_pixel_uyvy (DrawingData *dd, int x, Pixel *color)
} }
} }
static int static int drawing_data_init(DrawingData * dd, struct impl *this, char *data)
drawing_data_init (DrawingData *dd,
struct impl *this,
char* data)
{ {
struct spa_video_info *format = &this->current_format; struct spa_video_info *format = &this->current_format;
struct spa_rectangle *size = &format->info.raw.size; struct spa_rectangle *size = &format->info.raw.size;
@ -150,11 +139,9 @@ drawing_data_init (DrawingData *dd,
if (format->info.raw.format == this->type.video_format.RGB) { if (format->info.raw.format == this->type.video_format.RGB) {
dd->draw_pixel = draw_pixel_rgb; dd->draw_pixel = draw_pixel_rgb;
} } else if (format->info.raw.format == this->type.video_format.UYVY) {
else if (format->info.raw.format == this->type.video_format.UYVY) {
dd->draw_pixel = draw_pixel_uyvy; dd->draw_pixel = draw_pixel_uyvy;
} } else
else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;
dd->line = data; dd->line = data;
@ -165,27 +152,21 @@ drawing_data_init (DrawingData *dd,
return SPA_RESULT_OK; return SPA_RESULT_OK;
} }
static inline void static inline void draw_pixels(DrawingData * dd, int offset, Color color, int length)
draw_pixels (DrawingData *dd,
int offset,
Color color,
int length)
{ {
int x; int x;
for (x = offset; x < offset + length; x++) { for (x = offset; x < offset + length; x++) {
dd->draw_pixel (dd, x, &colors[color]); dd->draw_pixel(dd, x, &colors[color]);
} }
} }
static inline void static inline void next_line(DrawingData * dd)
next_line (DrawingData *dd)
{ {
dd->line += dd->stride; dd->line += dd->stride;
} }
static void static void draw_smpte_snow(DrawingData * dd)
draw_smpte_snow (DrawingData *dd)
{ {
int h, w; int h, w;
int y1, y2; int y1, y2;
@ -200,9 +181,9 @@ draw_smpte_snow (DrawingData *dd)
for (j = 0; j < 7; j++) { for (j = 0; j < 7; j++) {
int x1 = j * w / 7; int x1 = j * w / 7;
int x2 = (j + 1) * w / 7; int x2 = (j + 1) * w / 7;
draw_pixels (dd, x1, j, x2 - x1); draw_pixels(dd, x1, j, x2 - x1);
} }
next_line (dd); next_line(dd);
} }
for (i = y1; i < y2; i++) { for (i = y1; i < y2; i++) {
@ -211,89 +192,87 @@ draw_smpte_snow (DrawingData *dd)
int x2 = (j + 1) * w / 7; int x2 = (j + 1) * w / 7;
Color c = (j & 1) ? BLACK : BLUE - j; Color c = (j & 1) ? BLACK : BLUE - j;
draw_pixels (dd, x1, c, x2 - x1); draw_pixels(dd, x1, c, x2 - x1);
} }
next_line (dd); next_line(dd);
} }
for (i = y2; i < h; i++) { for (i = y2; i < h; i++) {
int x = 0; int x = 0;
/* negative I */ /* negative I */
draw_pixels (dd, x, NEG_I, w / 6); draw_pixels(dd, x, NEG_I, w / 6);
x += w / 6; x += w / 6;
/* white */ /* white */
draw_pixels (dd, x, WHITE, w / 6); draw_pixels(dd, x, WHITE, w / 6);
x += w / 6; x += w / 6;
/* positive Q */ /* positive Q */
draw_pixels (dd, x, POS_Q, w / 6); draw_pixels(dd, x, POS_Q, w / 6);
x += w / 6; x += w / 6;
/* pluge */ /* pluge */
draw_pixels (dd, x, DARK_BLACK, w / 12); draw_pixels(dd, x, DARK_BLACK, w / 12);
x += w / 12; x += w / 12;
draw_pixels (dd, x, BLACK, w / 12); draw_pixels(dd, x, BLACK, w / 12);
x += w / 12; x += w / 12;
draw_pixels (dd, x, LIGHT_BLACK, w / 12); draw_pixels(dd, x, LIGHT_BLACK, w / 12);
x += w / 12; x += w / 12;
/* war of the ants (a.k.a. snow) */ /* war of the ants (a.k.a. snow) */
for (j = x; j < w; j++) { for (j = x; j < w; j++) {
Pixel p; Pixel p;
unsigned char r = rand (); unsigned char r = rand();
p.R = r; p.R = r;
p.G = r; p.G = r;
p.B = r; p.B = r;
update_yuv (&p); update_yuv(&p);
dd->draw_pixel (dd, j, &p); dd->draw_pixel(dd, j, &p);
} }
next_line (dd); next_line(dd);
} }
} }
static void static void draw_snow(DrawingData * dd)
draw_snow (DrawingData *dd)
{ {
int x, y; int x, y;
for (y = 0; y < dd->height; y++) { for (y = 0; y < dd->height; y++) {
for (x = 0; x < dd->width; x++) { for (x = 0; x < dd->width; x++) {
Pixel p; Pixel p;
unsigned char r = rand (); unsigned char r = rand();
p.R = r; p.R = r;
p.G = r; p.G = r;
p.B = r; p.B = r;
update_yuv (&p); update_yuv(&p);
dd->draw_pixel (dd, x, &p); dd->draw_pixel(dd, x, &p);
} }
next_line (dd); next_line(dd);
} }
} }
static int static int draw(struct impl *this, char *data)
draw (struct impl *this, char *data)
{ {
DrawingData dd; DrawingData dd;
int res; int res;
uint32_t pattern; uint32_t pattern;
init_colors (); init_colors();
res = drawing_data_init (&dd, this, data); res = drawing_data_init(&dd, this, data);
if (res != SPA_RESULT_OK) if (res != SPA_RESULT_OK)
return res; return res;
pattern = this->props.pattern; pattern = this->props.pattern;
if (pattern == this->type.pattern_smpte_snow) if (pattern == this->type.pattern_smpte_snow)
draw_smpte_snow (&dd); draw_smpte_snow(&dd);
else if (pattern == this->type.pattern_snow) else if (pattern == this->type.pattern_snow)
draw_snow (&dd); draw_snow(&dd);
else else
return SPA_RESULT_NOT_IMPLEMENTED; return SPA_RESULT_NOT_IMPLEMENTED;