gst-libs/gst/video/: Add helper function needed for video sinks.
authorJulien Moutte <julien@moutte.net>
Wed, 16 Nov 2005 15:59:21 +0000 (15:59 +0000)
committerJulien Moutte <julien@moutte.net>
Wed, 16 Nov 2005 15:59:21 +0000 (15:59 +0000)
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.

ChangeLog
gst-libs/gst/video/gstvideosink.c
gst-libs/gst/video/gstvideosink.h
gst-libs/gst/video/videosink.h

index 727d3be..9284212 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
index fc0009e..e716951 100644 (file)
 
 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
index 6a73f87..49f5522 100644 (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__ */
index 6a73f87..49f5522 100644 (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__ */