add a puzzle game with...

Original commit message from CVS:
* configure.ac:
* gst/games/Makefile.am:
* gst/games/gstpuzzle.c:
add a puzzle game with...
* gst/games/gstvideoimage.c:
* gst/games/gstvideoimage.h:
... full colorspace support (that includes YUV9 and RGB16)) stolen
from videotestsrc and made into something that would be a nice
library for a lot of other plugins.
This commit is contained in:
Benjamin Otte 2005-01-06 06:48:01 +00:00
parent fdfbf3baa5
commit 5e19f0229d
6 changed files with 1544 additions and 0 deletions

View file

@ -1,3 +1,15 @@
2005-01-06 Benjamin Otte <in7y118@public.uni-hamburg.de>
* configure.ac:
* gst/games/Makefile.am:
* gst/games/gstpuzzle.c:
add a puzzle game with...
* gst/games/gstvideoimage.c:
* gst/games/gstvideoimage.h:
... full colorspace support (that includes YUV9 and RGB16)) stolen
from videotestsrc and made into something that would be a nice
library for a lot of other plugins.
2005-01-06 Stephane LOEUILLET <stephane.loeuillet@tiscali.fr> 2005-01-06 Stephane LOEUILLET <stephane.loeuillet@tiscali.fr>
* configure.ac: * configure.ac:

View file

@ -396,6 +396,7 @@ GST_PLUGINS_ALL="\
passthrough \ passthrough \
playback \ playback \
playondemand \ playondemand \
games \
qtdemux \ qtdemux \
realmedia \ realmedia \
rtjpeg \ rtjpeg \
@ -1937,6 +1938,7 @@ gst/festival/Makefile
gst/ffmpegcolorspace/Makefile gst/ffmpegcolorspace/Makefile
gst/filter/Makefile gst/filter/Makefile
gst/flx/Makefile gst/flx/Makefile
gst/games/Makefile
gst/goom/Makefile gst/goom/Makefile
gst/interleave/Makefile gst/interleave/Makefile
gst/law/Makefile gst/law/Makefile

12
gst/games/Makefile.am Normal file
View file

@ -0,0 +1,12 @@
plugin_LTLIBRARIES = libgstpuzzle.la
libgstpuzzle_la_SOURCES = \
gstvideoimage.c \
gstpuzzle.c
libgstpuzzle_la_CFLAGS = $(GST_CFLAGS) $(LIBOIL_CFLAGS) -I$(top_srcdir)/gst/videofilter
libgstpuzzle_la_LIBADD =
libgstpuzzle_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(LIBOIL_LIBS)
noinst_HEADERS = gstvideoimage.h

458
gst/games/gstpuzzle.c Normal file
View file

@ -0,0 +1,458 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* <2003> David Schleef <ds@schleef.org>
* <2004> Benjamin Otte <otte@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gstvideofilter.h>
#include "gstvideoimage.h"
#include <string.h>
#define GST_TYPE_PUZZLE \
(gst_puzzle_get_type())
#define GST_PUZZLE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PUZZLE,GstPuzzle))
#define GST_PUZZLE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PUZZLE,GstPuzzleClass))
#define GST_IS_PUZZLE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PUZZLE))
#define GST_IS_PUZZLE_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PUZZLE))
typedef struct _GstPuzzle GstPuzzle;
typedef struct _GstPuzzleClass GstPuzzleClass;
struct _GstPuzzle
{
GstVideofilter videofilter;
const GstVideoFormat *format;
/* properties */
guint rows;
guint columns;
guint tiles;
/* state */
guint *permutation;
guint position;
gboolean solved;
};
struct _GstPuzzleClass
{
GstVideofilterClass parent_class;
};
/* GstPuzzle signals and args */
enum
{
/* FILL ME */
LAST_SIGNAL
};
enum
{
ARG_0,
ARG_COLUMNS,
ARG_ROWS
/* FILL ME */
};
static void gst_puzzle_base_init (gpointer g_class);
static void gst_puzzle_class_init (gpointer g_class, gpointer class_data);
static void gst_puzzle_init (GTypeInstance * instance, gpointer g_class);
static void gst_puzzle_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_puzzle_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_puzzle_setup (GstVideofilter * videofilter);
static void draw_puzzle (GstVideofilter * videofilter, void *destp, void *srcp);
GType
gst_puzzle_get_type (void)
{
static GType puzzle_type = 0;
if (!puzzle_type) {
static const GTypeInfo puzzle_info = {
sizeof (GstPuzzleClass),
gst_puzzle_base_init,
NULL,
gst_puzzle_class_init,
NULL,
NULL,
sizeof (GstPuzzle),
0,
gst_puzzle_init,
};
puzzle_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
"GstPuzzle", &puzzle_info, 0);
}
return puzzle_type;
}
static void
gst_puzzle_base_init (gpointer g_class)
{
static GstElementDetails puzzle_details =
GST_ELEMENT_DETAILS ("a simple puzzle",
"Filter/Effect/Video/Games",
"A simple puzzle, use arrow keys and space to restart/solve",
"Benjamin Otte <otte@gnome.org>");
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
int i;
GstVideofilterFormat *f;
gst_element_class_set_details (element_class, &puzzle_details);
for (i = 0; i < gst_video_format_count; i++) {
f = g_new0 (GstVideofilterFormat, 1);
f->fourcc = gst_video_format_list[i].fourcc;
f->bpp = gst_video_format_list[i].bitspp;
f->filter_func = draw_puzzle;
if (gst_video_format_list[i].ext_caps) {
f->depth = gst_video_format_list[i].depth;
f->endianness = G_BYTE_ORDER;
f->red_mask = gst_video_format_list[i].red_mask;
f->green_mask = gst_video_format_list[i].green_mask;
f->blue_mask = gst_video_format_list[i].blue_mask;
}
gst_videofilter_class_add_format (videofilter_class, f);
}
gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
}
static void
gst_puzzle_class_init (gpointer g_class, gpointer class_data)
{
GObjectClass *gobject_class;
GstVideofilterClass *videofilter_class;
gobject_class = G_OBJECT_CLASS (g_class);
videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
gobject_class->set_property = gst_puzzle_set_property;
gobject_class->get_property = gst_puzzle_get_property;
g_object_class_install_property (gobject_class, ARG_ROWS,
g_param_spec_uint ("rows", "rows", "number of rows in puzzle",
1, G_MAXUINT, 4, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, ARG_COLUMNS,
g_param_spec_uint ("columns", "columns", "number of columns in puzzle",
1, G_MAXUINT, 4, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
videofilter_class->setup = gst_puzzle_setup;
}
static void G_GNUC_UNUSED
gst_puzzle_solve (GstPuzzle * puzzle)
{
guint i;
for (i = 0; i < puzzle->tiles; i++) {
puzzle->permutation[i] = i;
}
puzzle->position = puzzle->tiles - 1;
puzzle->solved = TRUE;
}
static gboolean
gst_puzzle_is_solved (GstPuzzle * puzzle)
{
guint i;
if (puzzle->position != puzzle->tiles - 1)
return FALSE;
for (i = 0; i < puzzle->tiles; i++) {
if (puzzle->permutation[i] != i)
return FALSE;
}
return TRUE;
}
#if 0
static void
gst_puzzle_show (GstPuzzle * puzzle)
{
guint i;
for (i = 0; i < puzzle->tiles; i++) {
g_print ("%d ", puzzle->permutation[i]);
}
g_print ("\n");
}
#endif
typedef enum
{
DIR_UP,
DIR_DOWN,
DIR_LEFT,
DIR_RIGHT
} GstPuzzleDirection;
static void
gst_puzzle_move (GstPuzzle * puzzle, GstPuzzleDirection dir)
{
guint next = puzzle->tiles;
switch (dir) {
case DIR_UP:
if (puzzle->position >= puzzle->columns)
next = puzzle->position - puzzle->columns;
break;
case DIR_DOWN:
if (puzzle->tiles - puzzle->position > puzzle->columns)
next = puzzle->position + puzzle->columns;
break;
case DIR_LEFT:
if ((puzzle->position % puzzle->columns) > 0)
next = puzzle->position - 1;
break;
case DIR_RIGHT:
if ((puzzle->position % puzzle->columns) < puzzle->columns - 1)
next = puzzle->position + 1;
break;
default:
g_assert_not_reached ();
}
if (next < puzzle->tiles) {
/* the move was valid */
guint tmp = puzzle->permutation[puzzle->position];
puzzle->permutation[puzzle->position] = puzzle->permutation[next];
puzzle->permutation[next] = tmp;
puzzle->position = next;
puzzle->solved = gst_puzzle_is_solved (puzzle);
}
}
static void
gst_puzzle_shuffle (GstPuzzle * puzzle)
{
guint i;
do {
for (i = 0; i < 100 * puzzle->tiles; i++) {
gst_puzzle_move (puzzle, g_random_int_range (0, 4));
}
} while (gst_puzzle_is_solved (puzzle));
puzzle->solved = FALSE;
}
static gboolean
nav_event_handler (GstPad * pad, GstEvent * event)
{
GstPuzzle *puzzle;
const gchar *type;
puzzle = GST_PUZZLE (gst_pad_get_parent (pad));
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_NAVIGATION:
type = gst_structure_get_string (event->event_data.structure.structure,
"event");
if (g_str_equal (type, "key-press")) {
const gchar *key =
gst_structure_get_string (event->event_data.structure.structure,
"key");
if (g_str_equal (key, "space")) {
if (gst_puzzle_is_solved (puzzle)) {
gst_puzzle_shuffle (puzzle);
} else {
gst_puzzle_solve (puzzle);
}
} else {
if (puzzle->solved)
break;
if (g_str_equal (key, "Left")) {
gst_puzzle_move (puzzle, DIR_LEFT);
} else if (g_str_equal (key, "Right")) {
gst_puzzle_move (puzzle, DIR_RIGHT);
} else if (g_str_equal (key, "Up")) {
gst_puzzle_move (puzzle, DIR_UP);
} else if (g_str_equal (key, "Down")) {
gst_puzzle_move (puzzle, DIR_DOWN);
} else {
break;
}
}
gst_event_unref (event);
return TRUE;
}
break;
default:
break;
}
return gst_pad_event_default (pad, event);
}
static void
gst_puzzle_init (GTypeInstance * instance, gpointer g_class)
{
GstVideofilter *videofilter;
videofilter = GST_VIDEOFILTER (instance);
/* FIXME: this is evil */
gst_pad_set_event_function (videofilter->srcpad, nav_event_handler);
}
static void
gst_puzzle_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstPuzzle *src;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_PUZZLE (object));
src = GST_PUZZLE (object);
GST_DEBUG ("gst_puzzle_set_property");
switch (prop_id) {
case ARG_COLUMNS:
src->columns = g_value_get_uint (value);
src->tiles = src->columns * src->rows;
break;
case ARG_ROWS:
src->rows = g_value_get_uint (value);
src->tiles = src->columns * src->rows;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_puzzle_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstPuzzle *src;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_PUZZLE (object));
src = GST_PUZZLE (object);
switch (prop_id) {
case ARG_COLUMNS:
g_value_set_uint (value, src->columns);
break;
case ARG_ROWS:
g_value_set_uint (value, src->rows);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_puzzle_setup (GstVideofilter * videofilter)
{
GstPuzzle *puzzle;
guint i;
g_return_if_fail (GST_IS_PUZZLE (videofilter));
puzzle = GST_PUZZLE (videofilter);
g_free (puzzle->permutation);
puzzle->permutation = g_new (guint, puzzle->tiles);
for (i = 0; i < puzzle->tiles; i++) {
puzzle->permutation[i] = i;
}
puzzle->position = puzzle->tiles - 1;
/* shuffle a bit */
gst_puzzle_shuffle (puzzle);
puzzle->format = NULL;
}
static void
draw_puzzle (GstVideofilter * videofilter, void *destp, void *srcp)
{
GstPuzzle *puzzle;
int width, height;
guint i;
GstVideoImage dest, src;
puzzle = GST_PUZZLE (videofilter);
if (!puzzle->format) {
puzzle->format =
gst_video_format_find_by_structure (gst_caps_get_structure
(gst_pad_get_negotiated_caps (videofilter->sinkpad), 0));
}
width = gst_videofilter_get_input_width (videofilter);
height = gst_videofilter_get_input_height (videofilter);
gst_video_image_setup (&dest, puzzle->format, destp, width, height);
gst_video_image_setup (&src, puzzle->format, srcp, width, height);
if (width % puzzle->columns != 0) {
guint w = width % puzzle->columns;
gst_video_image_copy_area (&dest, width - w, 0, &src, width - w, 0, w,
height);
}
if (height % puzzle->rows != 0) {
guint h = height % puzzle->rows;
gst_video_image_copy_area (&dest, 0, height - h, &src, 0, height - h, width,
h);
}
width /= puzzle->columns;
height /= puzzle->rows;
for (i = 0; i < puzzle->tiles; i++) {
if (!puzzle->solved && i == puzzle->position) {
gst_video_image_draw_rectangle (&dest, width * (i % puzzle->columns),
height * (i / puzzle->columns), width, height,
&GST_VIDEO_COLOR_WHITE, TRUE);
} else {
gst_video_image_copy_area (&dest, width * (i % puzzle->columns),
height * (i / puzzle->columns), &src,
width * (puzzle->permutation[i] % puzzle->columns),
height * (puzzle->permutation[i] / puzzle->columns), width, height);
}
}
}
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_library_load ("gstvideofilter"))
return FALSE;
return gst_element_register (plugin, "puzzle", GST_RANK_NONE,
GST_TYPE_PUZZLE);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"games",
"a collection of games to showcase features",
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)

946
gst/games/gstvideoimage.c Normal file
View file

@ -0,0 +1,946 @@
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* <2004> Benjamin Otte <otte@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstvideoimage.h"
#ifdef HAVE_LIBOIL
#include <liboil/liboil.h>
#endif
#include <string.h>
const GstVideoColor GST_VIDEO_COLOR_WHITE = { 255, 128, 128, 255, 255, 255 };
const GstVideoColor GST_VIDEO_COLOR_YELLOW = { 226, 0, 155, 255, 255, 0 };
const GstVideoColor GST_VIDEO_COLOR_CYAN = { 179, 170, 0, 0, 255, 255 };
const GstVideoColor GST_VIDEO_COLOR_GREEN = { 150, 46, 21, 0, 255, 0 };
const GstVideoColor GST_VIDEO_COLOR_MAGENTA = { 105, 212, 235, 255, 0, 255 };
const GstVideoColor GST_VIDEO_COLOR_RED = { 76, 85, 255, 255, 0, 0 };
const GstVideoColor GST_VIDEO_COLOR_BLUE = { 29, 255, 107, 0, 0, 255 };
const GstVideoColor GST_VIDEO_COLOR_BLACK = { 16, 128, 128, 0, 0, 0 };
const GstVideoColor GST_VIDEO_COLOR_NEG_I = { 16, 198, 21, 0, 0, 128 };
const GstVideoColor GST_VIDEO_COLOR_POS_Q = { 16, 235, 198, 0, 128, 255 };
const GstVideoColor GST_VIDEO_COLOR_SUPER_BLACK = { 0, 128, 128, 0, 0, 0 };
const GstVideoColor GST_VIDEO_COLOR_DARK_GREY = { 32, 128, 128, 32, 32, 32 };
const GstVideoFormat *
gst_video_format_find_by_structure (const GstStructure * structure)
{
int i;
const char *media_type = gst_structure_get_name (structure);
int ret;
g_return_val_if_fail (structure, NULL);
if (strcmp (media_type, "video/x-raw-yuv") == 0) {
char *s;
int fourcc;
guint32 format;
ret = gst_structure_get_fourcc (structure, "format", &format);
if (!ret)
return NULL;
for (i = 0; i < gst_video_format_count; i++) {
s = gst_video_format_list[i].fourcc;
//g_print("testing " GST_FOURCC_FORMAT " and %s\n", GST_FOURCC_ARGS(format), s);
fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
if (fourcc == format) {
return gst_video_format_list + i;
}
}
} else if (strcmp (media_type, "video/x-raw-rgb") == 0) {
int red_mask;
int green_mask;
int blue_mask;
int depth;
int bpp;
ret = gst_structure_get_int (structure, "red_mask", &red_mask);
ret &= gst_structure_get_int (structure, "green_mask", &green_mask);
ret &= gst_structure_get_int (structure, "blue_mask", &blue_mask);
ret &= gst_structure_get_int (structure, "depth", &depth);
ret &= gst_structure_get_int (structure, "bpp", &bpp);
for (i = 0; i < gst_video_format_count; i++) {
if (strcmp (gst_video_format_list[i].fourcc, "RGB ") == 0 &&
gst_video_format_list[i].red_mask == red_mask &&
gst_video_format_list[i].green_mask == green_mask &&
gst_video_format_list[i].blue_mask == blue_mask &&
gst_video_format_list[i].depth == depth &&
gst_video_format_list[i].bitspp == bpp) {
return gst_video_format_list + i;
}
}
return NULL;
}
g_critical ("format not found for media type %s", media_type);
return NULL;
}
const GstVideoFormat *
gst_video_format_find_by_fourcc (int find_fourcc)
{
int i;
for (i = 0; i < gst_video_format_count; i++) {
char *s;
int fourcc;
s = gst_video_format_list[i].fourcc;
fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
if (find_fourcc == fourcc) {
/* If YUV format, it's good */
if (!gst_video_format_list[i].ext_caps) {
return gst_video_format_list + i;
}
return gst_video_format_list + i;
}
}
return NULL;
}
const GstVideoFormat *
gst_video_format_find_by_name (const char *name)
{
int i;
for (i = 0; i < gst_video_format_count; i++) {
if (strcmp (name, gst_video_format_list[i].name) == 0) {
return gst_video_format_list + i;
}
}
return NULL;
}
GstStructure *
gst_video_format_get_structure (const GstVideoFormat * format)
{
unsigned int fourcc;
g_return_val_if_fail (format, NULL);
fourcc =
GST_MAKE_FOURCC (format->fourcc[0], format->fourcc[1], format->fourcc[2],
format->fourcc[3]);
if (format->ext_caps) {
int endianness;
if (format->bitspp == 16) {
endianness = G_BYTE_ORDER;
} else {
endianness = G_BIG_ENDIAN;
}
return gst_structure_new ("video/x-raw-rgb",
"bpp", G_TYPE_INT, format->bitspp,
"endianness", G_TYPE_INT, endianness,
"depth", G_TYPE_INT, format->depth,
"red_mask", G_TYPE_INT, format->red_mask,
"green_mask", G_TYPE_INT, format->green_mask,
"blue_mask", G_TYPE_INT, format->blue_mask, NULL);
} else {
return gst_structure_new ("video/x-raw-yuv",
"format", GST_TYPE_FOURCC, fourcc, NULL);
}
}
/* returns the size in bytes for one video frame of the given dimensions
* given the fourcc in GstVideotestsrc */
guint
gst_video_format_get_size (const GstVideoFormat * format, guint w, guint h)
{
GstVideoImage p = { 0 };
g_return_val_if_fail (format != NULL, 0);
g_return_val_if_fail (w > 0, 0);
g_return_val_if_fail (h > 0, 0);
gst_video_image_setup (&p, format, NULL, w, h);
return (unsigned long) p.endptr;
}
void
gst_video_image_setup (GstVideoImage * image, const GstVideoFormat * format,
guint8 * data, guint w, guint h)
{
g_return_if_fail (image != NULL);
g_return_if_fail (format != NULL);
g_return_if_fail (w > 0);
g_return_if_fail (h > 0);
image->width = w;
image->height = h;
image->format = format;
format->paint_setup (image, data);
}
void
gst_video_image_paint_hline (GstVideoImage * image, gint x, gint y, gint w,
const GstVideoColor * c)
{
g_return_if_fail (image != NULL);
g_return_if_fail (c != NULL);
g_return_if_fail (w > 0);
/* check coords */
if (y < 0 || y >= image->height)
return;
if (x < 0) {
if (x + w < 0)
return;
w += x;
x = 0;
}
if (x >= image->width)
return;
if (x + w > image->width) {
w = image->width - x;
}
image->format->paint_hline (image, x, y, w, c);
}
void
gst_video_image_draw_rectangle (GstVideoImage * image, gint x, gint y,
gint w, gint h, const GstVideoColor * c, gboolean filled)
{
gint i;
g_return_if_fail (image != NULL);
g_return_if_fail (c != NULL);
g_return_if_fail (w > 0);
g_return_if_fail (h > 0);
/* check coords */
if (x < 0) {
if (x + w < 0)
return;
w += x;
x = 0;
}
if (x >= image->width)
return;
if (x + w > image->width) {
w = image->width - x;
}
if (y < 0) {
if (y + h < 0)
return;
h += y;
y = 0;
}
if (y >= image->height)
return;
if (y + h > image->height) {
y = image->height - y;
}
if (filled) {
for (i = 0; i < h; i++) {
image->format->paint_hline (image, x, y + i, w, c);
}
} else {
h--;
image->format->paint_hline (image, x, i, w, c);
for (i = 1; i < h; i++) {
image->format->paint_hline (image, x, y + i, 1, c);
image->format->paint_hline (image, x + w - 1, y + i, 1, c);
}
image->format->paint_hline (image, x, y + h, w, c);
}
}
void
gst_video_image_copy_hline (GstVideoImage * dest, gint xdest, gint ydest,
GstVideoImage * src, gint xsrc, gint ysrc, gint w)
{
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
g_return_if_fail (dest->format == src->format);
g_return_if_fail (w > 0);
/* check width coords */
if (xdest >= dest->width)
return;
if (xsrc >= src->width)
return;
if (xdest < 0) {
xsrc -= xdest;
w += xdest;
xdest = 0;
}
if (xsrc < 0) {
xdest -= xsrc;
w += xsrc;
xsrc = 0;
}
if (w <= 0)
return;
if (xdest + w > dest->width)
w = dest->width - xdest;
if (xsrc + w > src->width)
w = src->width - xsrc;
/* check height coords */
if (ysrc >= src->height || ysrc < 0)
return;
if (ydest >= dest->height || ydest < 0)
return;
dest->format->copy_hline (dest, xdest, ydest, src, xsrc, ysrc, w);
}
void
gst_video_image_copy_area (GstVideoImage * dest, gint xdest, gint ydest,
GstVideoImage * src, gint xsrc, gint ysrc, gint w, gint h)
{
gint i;
g_return_if_fail (dest != NULL);
g_return_if_fail (src != NULL);
g_return_if_fail (dest->format == src->format);
g_return_if_fail (w > 0);
g_return_if_fail (h > 0);
/* check width coords */
if (xdest >= dest->width)
return;
if (xsrc >= src->width)
return;
if (xdest < 0) {
xsrc -= xdest;
w += xdest;
xdest = 0;
}
if (xsrc < 0) {
xdest -= xsrc;
w += xsrc;
xsrc = 0;
}
if (w <= 0)
return;
if (xdest + w > dest->width)
w = dest->width - xdest;
if (xsrc + w > src->width)
w = src->width - xsrc;
/* check height coords */
if (ydest >= dest->height)
return;
if (ysrc >= src->height)
return;
if (ydest < 0) {
ysrc -= ydest;
h += ydest;
ydest = 0;
}
if (ysrc < 0) {
ydest -= ysrc;
h += ysrc;
ysrc = 0;
}
if (h <= 0)
return;
if (ydest + h > dest->height)
h = dest->height - ydest;
if (ysrc + h > src->height)
h = src->height - ysrc;
for (i = 0; i < h; i++) {
dest->format->copy_hline (dest, xdest, ydest + i, src, xsrc, ysrc + i, w);
}
}
#define ROUND_UP_2(x) (((x)+1)&~1)
#define ROUND_UP_4(x) (((x)+3)&~3)
#define ROUND_UP_8(x) (((x)+7)&~7)
static void
paint_setup_I420 (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->up = p->yp + p->ystride * ROUND_UP_2 (p->height);
p->ustride = ROUND_UP_8 (p->width) / 2;
p->vp = p->up + p->ustride * ROUND_UP_2 (p->height) / 2;
p->vstride = ROUND_UP_8 (p->ystride) / 2;
p->endptr = p->vp + p->vstride * ROUND_UP_2 (p->height) / 2;
}
static void
paint_hline_I420 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int x1 = x / 2;
int x2 = (x + w) / 2;
int offset = y * p->ystride;
int offset1 = (y / 2) * p->ustride;
memset (p->yp + offset + x, c->Y, w);
memset (p->up + offset1 + x1, c->U, x2 - x1);
memset (p->vp + offset1 + x1, c->V, x2 - x1);
}
static void
copy_hline_I420 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int destoffset1 = (ydest / 2) * dest->ustride;
int srcoffset = ysrc * src->ystride;
int srcoffset1 = (ysrc / 2) * src->ustride;
memcpy (dest->yp + destoffset + xdest, src->yp + srcoffset + xsrc, w);
memcpy (dest->up + destoffset1 + xdest / 2, src->up + srcoffset1 + xsrc / 2,
w / 2);
memcpy (dest->vp + destoffset1 + xdest / 2, src->vp + srcoffset1 + xsrc / 2,
w / 2);
}
static void
paint_setup_YV12 (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->vp = p->yp + p->ystride * ROUND_UP_2 (p->height);
p->vstride = ROUND_UP_8 (p->ystride) / 2;
p->up = p->vp + p->vstride * ROUND_UP_2 (p->height) / 2;
p->ustride = ROUND_UP_8 (p->ystride) / 2;
p->endptr = p->up + p->ustride * ROUND_UP_2 (p->height) / 2;
}
static void
paint_setup_YUY2 (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->up = dest + 1;
p->vp = dest + 3;
p->ystride = ROUND_UP_2 (p->width) * 2;
p->endptr = dest + p->ystride * p->height;
}
static void
paint_setup_UYVY (GstVideoImage * p, char *dest)
{
p->yp = dest + 1;
p->up = dest;
p->vp = dest + 2;
p->ystride = ROUND_UP_2 (p->width) * 2;
p->endptr = dest + p->ystride * p->height;
}
static void
paint_setup_YVYU (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->up = dest + 3;
p->vp = dest + 1;
p->ystride = ROUND_UP_2 (p->width * 2);
p->endptr = dest + p->ystride * p->height;
}
#ifndef HAVE_LIBOIL
void
oil_splat_u8 (guint8 * dest, int dstr, guint8 val, int n)
{
int i;
for (i = 0; i < n; i++) {
*dest = val;
dest += dstr;
}
}
#endif
static void
paint_hline_YUY2 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int x1 = x / 2;
int x2 = (x + w) / 2;
int offset = y * p->ystride;
oil_splat_u8 (p->yp + offset + x * 2, 2, c->Y, w);
oil_splat_u8 (p->up + offset + x1 * 4, 4, c->U, x2 - x1);
oil_splat_u8 (p->vp + offset + x1 * 4, 4, c->V, x2 - x1);
}
static void
copy_hline_YUY2 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ydest * src->ystride;
memcpy (dest->yp + destoffset + xdest * 2, src->yp + srcoffset + xsrc * 2,
w * 2);
}
static void
paint_setup_IYU2 (GstVideoImage * p, char *dest)
{
/* untested */
p->yp = dest + 1;
p->up = dest + 0;
p->vp = dest + 2;
p->ystride = ROUND_UP_4 (p->width * 3);
p->endptr = dest + p->ystride * p->height;
}
static void
paint_hline_IYU2 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset;
offset = y * p->ystride;
oil_splat_u8 (p->yp + offset + x * 3, 3, c->Y, w);
oil_splat_u8 (p->up + offset + x * 3, 3, c->U, w);
oil_splat_u8 (p->vp + offset + x * 3, 3, c->V, w);
}
static void
copy_hline_IYU2 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ydest * src->ystride;
memcpy (dest->yp + destoffset + xdest * 3, src->yp + srcoffset + xsrc * 3,
w * 3);
}
static void
paint_setup_Y41B (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->up = p->yp + p->ystride * p->height;
p->ustride = ROUND_UP_8 (p->width) / 4;
p->vp = p->up + p->ustride * p->height;
p->vstride = ROUND_UP_8 (p->width) / 4;
p->endptr = p->vp + p->vstride * p->height;
}
static void
paint_hline_Y41B (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int x1 = x / 4;
int x2 = (x + w) / 4;
int offset = y * p->ystride;
int offset1 = y * p->ustride;
memset (p->yp + offset + x, c->Y, w);
memset (p->up + offset1 + x1, c->U, x2 - x1);
memset (p->vp + offset1 + x1, c->V, x2 - x1);
}
static void
copy_hline_Y41B (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int destoffset1 = ydest * dest->ustride;
int srcoffset = ysrc * src->ystride;
int srcoffset1 = ysrc * src->ustride;
memcpy (dest->yp + destoffset + xdest, src->yp + srcoffset + xsrc, w);
memcpy (dest->up + destoffset1 + xdest / 4, src->up + srcoffset1 + xsrc / 4,
w / 4);
memcpy (dest->vp + destoffset1 + xdest / 4, src->vp + srcoffset1 + xsrc / 4,
w / 4);
}
static void
paint_setup_Y42B (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->up = p->yp + p->ystride * p->height;
p->ustride = ROUND_UP_8 (p->width) / 2;
p->vp = p->up + p->ustride * p->height;
p->vstride = ROUND_UP_8 (p->width) / 2;
p->endptr = p->vp + p->vstride * p->height;
}
static void
paint_hline_Y42B (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int x1 = x / 2;
int x2 = (x + w) / 2;
int offset = y * p->ystride;
int offset1 = y * p->ustride;
memset (p->yp + offset + x, c->Y, w);
memset (p->up + offset1 + x1, c->U, x2 - x1);
memset (p->vp + offset1 + x1, c->V, x2 - x1);
}
static void
copy_hline_Y42B (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int destoffset1 = ydest * dest->ustride;
int srcoffset = ysrc * src->ystride;
int srcoffset1 = ysrc * src->ustride;
memcpy (dest->yp + destoffset + xdest, src->yp + srcoffset + xsrc, w);
memcpy (dest->up + destoffset1 + xdest / 2, src->up + srcoffset1 + xsrc / 2,
w / 2);
memcpy (dest->vp + destoffset1 + xdest / 2, src->vp + srcoffset1 + xsrc / 2,
w / 2);
}
static void
paint_setup_Y800 (GstVideoImage * p, char *dest)
{
/* untested */
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->endptr = dest + p->ystride * p->height;
}
static void
paint_hline_Y800 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset = y * p->ystride;
memset (p->yp + offset + x, c->Y, w);
}
static void
copy_hline_Y800 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ysrc * src->ystride;
memcpy (dest->yp + destoffset + xdest, src->yp + srcoffset + xsrc, w);
}
static void
paint_setup_YVU9 (GstVideoImage * p, char *dest)
{
int h = ROUND_UP_4 (p->height);
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->vp = p->yp + p->ystride * ROUND_UP_4 (p->height);
p->vstride = ROUND_UP_4 (p->ystride / 4);
p->up = p->vp + p->vstride * ROUND_UP_4 (h / 4);
p->ustride = ROUND_UP_4 (p->ystride / 4);
p->endptr = p->up + p->ustride * ROUND_UP_4 (h / 4);
}
static void
paint_setup_YUV9 (GstVideoImage * p, char *dest)
{
/* untested */
int h = ROUND_UP_4 (p->height);
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width);
p->up = p->yp + p->ystride * h;
p->ustride = ROUND_UP_4 (p->ystride / 4);
p->vp = p->up + p->ustride * ROUND_UP_4 (h / 4);
p->vstride = ROUND_UP_4 (p->ystride / 4);
p->endptr = p->vp + p->vstride * ROUND_UP_4 (h / 4);
}
static void
paint_hline_YUV9 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int x1 = x / 4;
int x2 = (x + w) / 4;
int offset = y * p->ystride;
int offset1 = (y / 4) * p->ustride;
memset (p->yp + offset + x, c->Y, w);
memset (p->up + offset1 + x1, c->U, x2 - x1);
memset (p->vp + offset1 + x1, c->V, x2 - x1);
}
static void
copy_hline_YUV9 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int destoffset1 = ydest * dest->ustride;
int srcoffset = ysrc * src->ystride;
int srcoffset1 = ysrc * src->ustride;
memcpy (dest->yp + destoffset + xdest, src->yp + srcoffset + xsrc, w);
memcpy (dest->up + destoffset1 + xdest / 4, src->up + srcoffset1 + xsrc / 4,
w / 4);
memcpy (dest->vp + destoffset1 + xdest / 4, src->vp + srcoffset1 + xsrc / 4,
w / 4);
}
static void
paint_setup_xRGB8888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 1;
p->up = dest + 2;
p->vp = dest + 3;
p->ystride = p->width * 4;
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_setup_xBGR8888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 3;
p->up = dest + 2;
p->vp = dest + 1;
p->ystride = p->width * 4;
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_setup_RGBx8888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 0;
p->up = dest + 1;
p->vp = dest + 2;
p->ystride = p->width * 4;
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_setup_BGRx8888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 2;
p->up = dest + 1;
p->vp = dest + 0;
p->ystride = p->width * 4;
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_setup_RGB888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 0;
p->up = dest + 1;
p->vp = dest + 2;
p->ystride = ROUND_UP_4 (p->width * 3);
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_setup_BGR888 (GstVideoImage * p, char *dest)
{
p->yp = dest + 2;
p->up = dest + 1;
p->vp = dest + 0;
p->ystride = ROUND_UP_4 (p->width * 3);
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_hline_str4 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset = y * p->ystride;
oil_splat_u8 (p->yp + offset + x * 4, 4, c->R, w);
oil_splat_u8 (p->up + offset + x * 4, 4, c->G, w);
oil_splat_u8 (p->vp + offset + x * 4, 4, c->B, w);
}
static void
copy_hline_str4 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ysrc * src->ystride;
memcpy (dest->yp + destoffset + xdest * 4, src->yp + srcoffset + xsrc * 4,
w * 4);
}
static void
paint_hline_str3 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset = y * p->ystride;
oil_splat_u8 (p->yp + offset + x * 3, 3, c->R, w);
oil_splat_u8 (p->up + offset + x * 3, 3, c->G, w);
oil_splat_u8 (p->vp + offset + x * 3, 3, c->B, w);
}
static void
copy_hline_str3 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ysrc * src->ystride;
memcpy (dest->yp + destoffset + xdest * 3, src->yp + srcoffset + xsrc * 3,
w * 3);
}
static void
paint_setup_RGB565 (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width * 2);
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_hline_RGB565 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset = y * p->ystride;
unsigned int a, b;
a = (c->R & 0xf8) | (c->G >> 5);
b = ((c->G << 3) & 0xe0) | (c->B >> 3);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
oil_splat_u8 (p->yp + offset + x * 2 + 0, 2, b, w);
oil_splat_u8 (p->yp + offset + x * 2 + 1, 2, a, w);
#else
oil_splat_u8 (p->yp + offset + x * 2 + 0, 2, a, w);
oil_splat_u8 (p->yp + offset + x * 2 + 1, 2, b, w);
#endif
}
static void
copy_hline_str2 (GstVideoImage * dest, int xdest, int ydest,
GstVideoImage * src, int xsrc, int ysrc, int w)
{
int destoffset = ydest * dest->ystride;
int srcoffset = ysrc * src->ystride;
memcpy (dest->yp + destoffset + xdest * 2, src->yp + srcoffset + xsrc * 2,
w * 2);
}
static void
paint_setup_xRGB1555 (GstVideoImage * p, char *dest)
{
p->yp = dest;
p->ystride = ROUND_UP_4 (p->width * 2);
p->endptr = p->dest + p->ystride * p->height;
}
static void
paint_hline_xRGB1555 (GstVideoImage * p, int x, int y, int w,
const GstVideoColor * c)
{
int offset = y * p->ystride;
unsigned int a, b;
a = ((c->R >> 1) & 0x7c) | (c->G >> 6);
b = ((c->G << 2) & 0xe0) | (c->B >> 3);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
oil_splat_u8 (p->yp + offset + x * 2 + 0, 2, b, w);
oil_splat_u8 (p->yp + offset + x * 2 + 1, 2, a, w);
#else
oil_splat_u8 (p->yp + offset + x * 2 + 0, 2, a, w);
oil_splat_u8 (p->yp + offset + x * 2 + 1, 2, b, w);
#endif
}
const GstVideoFormat gst_video_format_list[] = {
/* packed */
{"YUY2", "YUY2", 16, paint_setup_YUY2, paint_hline_YUY2, copy_hline_YUY2},
{"UYVY", "UYVY", 16, paint_setup_UYVY, paint_hline_YUY2, copy_hline_YUY2},
{"Y422", "Y422", 16, paint_setup_UYVY, paint_hline_YUY2, copy_hline_YUY2},
{"UYNV", "UYNV", 16, paint_setup_UYVY, paint_hline_YUY2, copy_hline_YUY2}, /* FIXME: UYNV? */
{"YVYU", "YVYU", 16, paint_setup_YVYU, paint_hline_YUY2, copy_hline_YUY2},
/* interlaced */
/*{ "IUYV", "IUY2", 16, paint_setup_YVYU, paint_hline_YUY2 }, */
/* inverted */
/*{ "cyuv", "cyuv", 16, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "Y41P", "Y41P", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
/* interlaced */
/*{ "IY41", "IY41", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "Y211", "Y211", 8, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "Y41T", "Y41T", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "Y42P", "Y42P", 16, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "CLJR", "CLJR", 8, paint_setup_YVYU, paint_hline_YUY2 }, */
/*{ "IYU1", "IYU1", 12, paint_setup_YVYU, paint_hline_YUY2 }, */
{"IYU2", "IYU2", 24, paint_setup_IYU2, paint_hline_IYU2, copy_hline_IYU2},
/* planar */
/* YVU9 */
{"YVU9", "YVU9", 9, paint_setup_YVU9, paint_hline_YUV9, copy_hline_YUV9},
/* YUV9 */
{"YUV9", "YUV9", 9, paint_setup_YUV9, paint_hline_YUV9, copy_hline_YUV9},
/* IF09 */
/* YV12 */
{"YV12", "YV12", 12, paint_setup_YV12, paint_hline_I420, copy_hline_I420},
/* I420 */
{"I420", "I420", 12, paint_setup_I420, paint_hline_I420, copy_hline_I420},
/* NV12 */
/* NV21 */
/* CLPL */
/* Y41B */
{"Y41B", "Y41B", 12, paint_setup_Y41B, paint_hline_Y41B, copy_hline_Y41B},
/* Y42B */
{"Y42B", "Y42B", 16, paint_setup_Y42B, paint_hline_Y42B, copy_hline_Y42B},
/* Y800 grayscale */
{"Y800", "Y800", 8, paint_setup_Y800, paint_hline_Y800, copy_hline_Y800},
{"RGB ", "xRGB8888", 32, paint_setup_xRGB8888, paint_hline_str4,
copy_hline_str4,
1, 24, 0x00ff0000, 0x0000ff00, 0x000000ff},
{"RGB ", "xBGR8888", 32, paint_setup_xBGR8888, paint_hline_str4,
copy_hline_str4,
1, 24, 0x000000ff, 0x0000ff00, 0x00ff0000},
{"RGB ", "RGBx8888", 32, paint_setup_RGBx8888, paint_hline_str4,
copy_hline_str4,
1, 24, 0xff000000, 0x00ff0000, 0x0000ff00},
{"RGB ", "BGRx8888", 32, paint_setup_BGRx8888, paint_hline_str4,
copy_hline_str4,
1, 24, 0x0000ff00, 0x00ff0000, 0xff000000},
{"RGB ", "RGB888", 24, paint_setup_RGB888, paint_hline_str3, copy_hline_str3,
1, 24, 0x00ff0000, 0x0000ff00, 0x000000ff},
{"RGB ", "BGR888", 24, paint_setup_BGR888, paint_hline_str3, copy_hline_str3,
1, 24, 0x000000ff, 0x0000ff00, 0x00ff0000},
{"RGB ", "RGB565", 16, paint_setup_RGB565, paint_hline_RGB565,
copy_hline_str2,
1, 16, 0x0000f800, 0x000007e0, 0x0000001f},
{"RGB ", "xRGB1555", 16, paint_setup_xRGB1555, paint_hline_xRGB1555,
copy_hline_str2,
1, 15, 0x00007c00, 0x000003e0, 0x0000001f},
};
const guint gst_video_format_count = G_N_ELEMENTS (gst_video_format_list);

114
gst/games/gstvideoimage.h Normal file
View file

@ -0,0 +1,114 @@
/* GStreamer
* Copyright (C) <2003> David A. Schleef <ds@schleef.org>
* <2004> Benjamin Otte <otte@gnome.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gst/gst.h>
#ifndef __GST_VIDEO_IMAGE_H__
#define __GST_VIDEO_IMAGE_H__
G_BEGIN_DECLS
typedef struct _GstVideoColor GstVideoColor;
typedef struct _GstVideoImage GstVideoImage;
typedef struct _GstVideoFormat GstVideoFormat;
struct _GstVideoColor {
int Y, U, V;
int R, G, B;
};
extern const GstVideoColor GST_VIDEO_COLOR_WHITE;
extern const GstVideoColor GST_VIDEO_COLOR_YELLOW;
extern const GstVideoColor GST_VIDEO_COLOR_CYAN;
extern const GstVideoColor GST_VIDEO_COLOR_GREEN;
extern const GstVideoColor GST_VIDEO_COLOR_MAGENTA;
extern const GstVideoColor GST_VIDEO_COLOR_RED;
extern const GstVideoColor GST_VIDEO_COLOR_BLUE;
extern const GstVideoColor GST_VIDEO_COLOR_BLACK;
extern const GstVideoColor GST_VIDEO_COLOR_NEG_I;
extern const GstVideoColor GST_VIDEO_COLOR_POS_Q;
extern const GstVideoColor GST_VIDEO_COLOR_SUPER_BLACK;
extern const GstVideoColor GST_VIDEO_COLOR_DARK_GREY;
struct _GstVideoImage
{
guint8 * dest; /* pointer to first byte of video data */
guint8 * yp, *up, *vp; /* pointers to first byte of each component
* for both packed/planar YUV and RGB */
guint8 * endptr; /* pointer to byte beyond last video data */
guint ystride;
guint ustride;
guint vstride;
guint width;
guint height;
const GstVideoFormat * format;
};
struct _GstVideoFormat
{
char * fourcc;
char * name;
int bitspp;
void (* paint_setup) (GstVideoImage * p, char *dest);
void (* paint_hline) (GstVideoImage * p, int x, int y, int w, const GstVideoColor *c);
void (* copy_hline) (GstVideoImage * dest, int destx, int desty,
GstVideoImage * src, int srcx, int srcy, int w);
int ext_caps;
int depth;
guint red_mask;
guint green_mask;
guint blue_mask;
};
const GstVideoFormat * gst_video_format_find_by_fourcc (int find_fourcc);
const GstVideoFormat * gst_video_format_find_by_name (const char *name);
const GstVideoFormat * gst_video_format_find_by_structure (const GstStructure *structure);
GstStructure * gst_video_format_get_structure (const GstVideoFormat *format);
guint gst_video_format_get_size (const GstVideoFormat *format,
guint w, guint h);
extern const GstVideoFormat gst_video_format_list[];
extern const guint gst_video_format_count;
void gst_video_image_setup (GstVideoImage *image,
const GstVideoFormat *format,
guint8 *data, guint w, guint h);
/* drawing operations */
void gst_video_image_draw_hline (GstVideoImage *image,
gint x, gint y, gint w,
const GstVideoColor *c);
void gst_video_image_draw_rectangle (GstVideoImage *image,
gint x, gint y, gint w, gint h,
const GstVideoColor *c, gboolean filled);
void gst_video_image_copy_hline (GstVideoImage *dest,
gint xdest, gint ydest,
GstVideoImage *src,
gint xsrc, gint ysrc, gint w);
void gst_video_image_copy_area (GstVideoImage *dest,
gint xdest, gint ydest,
GstVideoImage *src,
gint xsrc, gint ysrc,
gint w, gint h);
G_END_DECLS
#endif /* __GST_VIDEO_IMAGE_H__ */