gst-libs/gst/video/: Add helper function needed for video sinks.

Original commit message from CVS:
2005-11-16  Julien MOUTTE  <julien@moutte.net>

* gst-libs/gst/video/gstvideosink.c:
(gst_video_sink_center_rect):
* gst-libs/gst/video/videosink.h: Add helper function needed
for video sinks.
This commit is contained in:
Julien Moutte 2005-11-16 15:59:21 +00:00
parent 0f873a9ab4
commit 451645fd56
4 changed files with 67 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2005-11-16 Julien MOUTTE <julien@moutte.net>
* gst-libs/gst/video/gstvideosink.c: (gst_video_sink_center_rect):
* gst-libs/gst/video/videosink.h: Add helper function needed
for video sinks.
2005-11-16 Tim-Philipp Müller <tim at centricular dot net>
* gst/videoscale/gstvideoscale.c:

View file

@ -27,6 +27,45 @@
static GstElementClass *parent_class = NULL;
void
gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst,
GstVideoRectangle * result, gboolean scaling)
{
g_return_if_fail (result != NULL);
if (!scaling) {
result->w = MIN (src.w, dst.w);
result->h = MIN (src.h, dst.h);
result->x = (dst.w - result->w) / 2;
result->y = (dst.h - result->h) / 2;
} else {
gdouble src_ratio, dst_ratio;
src_ratio = (gdouble) src.w / src.h;
dst_ratio = (gdouble) dst.w / dst.h;
if (src_ratio > dst_ratio) {
result->w = dst.w;
result->h = dst.w / src_ratio;
result->x = 0;
result->y = (dst.h - result->h) / 2;
} else if (src_ratio < dst_ratio) {
result->w = dst.h * src_ratio;
result->h = dst.h;
result->x = (dst.w - result->w) / 2;
result->y = 0;
} else {
result->x = 0;
result->y = 0;
result->w = dst.w;
result->h = dst.h;
}
}
GST_DEBUG ("source is %dx%d dest is %dx%d, result is %dx%d with x,y %dx%d",
src.w, src.h, dst.w, dst.h, result->w, result->h, result->x, result->y);
}
/* Initing stuff */
static void

View file

@ -46,6 +46,14 @@ G_BEGIN_DECLS
typedef struct _GstVideoSink GstVideoSink;
typedef struct _GstVideoSinkClass GstVideoSinkClass;
typedef struct _GstVideoRectangle GstVideoRectangle;
struct _GstVideoRectangle {
gint x;
gint y;
gint w;
gint h;
};
struct _GstVideoSink {
GstBaseSink element;
@ -63,6 +71,9 @@ struct _GstVideoSinkClass {
GType gst_video_sink_get_type (void);
void gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst,
GstVideoRectangle *result, gboolean scaling);
G_END_DECLS
#endif /* __GST_VIDEO_SINK_H__ */

View file

@ -46,6 +46,14 @@ G_BEGIN_DECLS
typedef struct _GstVideoSink GstVideoSink;
typedef struct _GstVideoSinkClass GstVideoSinkClass;
typedef struct _GstVideoRectangle GstVideoRectangle;
struct _GstVideoRectangle {
gint x;
gint y;
gint w;
gint h;
};
struct _GstVideoSink {
GstBaseSink element;
@ -63,6 +71,9 @@ struct _GstVideoSinkClass {
GType gst_video_sink_get_type (void);
void gst_video_sink_center_rect (GstVideoRectangle src, GstVideoRectangle dst,
GstVideoRectangle *result, gboolean scaling);
G_END_DECLS
#endif /* __GST_VIDEO_SINK_H__ */