fix up more enums
[platform/upstream/gst-plugins-good.git] / ext / gdk_pixbuf / pixbufscale.c
index 5d4d044..9edef40 100644 (file)
@@ -1,6 +1,7 @@
 /* GStreamer
  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
  * Copyright (C) <2004> Jan Schmidt <thaytan@mad.scientist.com>
+ * Copyright (C) <2004> Tim-Philipp Mueller <t.i.m@orange.net>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include <gst/video/video.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+#define ROUND_UP_2(x)  (((x)+1)&~1)
+#define ROUND_UP_4(x)  (((x)+3)&~3)
+#define ROUND_UP_8(x)  (((x)+7)&~7)
+
+/* These match the ones gstffmpegcolorspace uses (Tim) */
+#define GST_RGB24_ROWSTRIDE(width)    (ROUND_UP_4 ((width)*3))
+#define GST_RGB24_SIZE(width,height)  ((height)*GST_RGB24_ROWSTRIDE(width))
+
+
 /* debug variable definition */
 GST_DEBUG_CATEGORY (pixbufscale_debug);
 #define GST_CAT_DEFAULT pixbufscale_debug
@@ -71,10 +81,10 @@ gst_pixbufscale_method_get_type (void)
 {
   static GType pixbufscale_method_type = 0;
   static GEnumValue pixbufscale_methods[] = {
-    {GST_PIXBUFSCALE_NEAREST, "0", "Nearest Neighbour"},
-    {GST_PIXBUFSCALE_TILES, "1", "Tiles"},
-    {GST_PIXBUFSCALE_BILINEAR, "2", "Bilinear"},
-    {GST_PIXBUFSCALE_HYPER, "3", "Hyper"},
+    {GST_PIXBUFSCALE_NEAREST, "Nearest Neighbour", "nearest"},
+    {GST_PIXBUFSCALE_TILES, "Tiles", "tiles"},
+    {GST_PIXBUFSCALE_BILINEAR, "Bilinear", "bilinear"},
+    {GST_PIXBUFSCALE_HYPER, "Hyper", "hyper"},
     {0, NULL, NULL},
   };
 
@@ -172,13 +182,16 @@ gst_pixbufscale_getcaps (GstPad * pad)
       pixbufscale->srcpad;
   othercaps = gst_pad_get_allowed_caps (otherpad);
 
-  caps = gst_caps_copy (othercaps);
+  caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad));
+  gst_caps_free (othercaps);
+
   for (i = 0; i < gst_caps_get_size (caps); i++) {
     GstStructure *structure = gst_caps_get_structure (caps, i);
 
     gst_structure_set (structure,
-        "width", GST_TYPE_INT_RANGE, 16, G_MAXINT,
-        "height", GST_TYPE_INT_RANGE, 16, G_MAXINT, NULL);
+        "width", GST_TYPE_INT_RANGE, 16, 4096,
+        "height", GST_TYPE_INT_RANGE, 16, 4096, NULL);
+    gst_structure_remove_field (structure, "pixel-aspect-ratio");
   }
 
   GST_DEBUG ("getcaps are: %" GST_PTR_FORMAT, caps);
@@ -193,8 +206,12 @@ gst_pixbufscale_link (GstPad * pad, const GstCaps * caps)
   GstPad *otherpad;
   GstStructure *structure;
   int height, width;
+  gchar *caps_string;
+
+  caps_string = gst_caps_to_string (caps);
+  GST_DEBUG ("gst_pixbufscale_link %s\n", caps_string);
+  g_free (caps_string);
 
-  GST_DEBUG ("gst_pixbufscale_link %s\n", gst_caps_to_string (caps));
   pixbufscale = GST_PIXBUFSCALE (gst_pad_get_parent (pad));
 
   otherpad = (pad == pixbufscale->srcpad) ? pixbufscale->sinkpad :
@@ -213,8 +230,10 @@ gst_pixbufscale_link (GstPad * pad, const GstCaps * caps)
     pixbufscale->from_width = width;
     pixbufscale->from_height = height;
 
-    pixbufscale->from_buf_size = width * height * 3;
-    pixbufscale->to_buf_size = width * height * 3;
+    pixbufscale->from_buf_size = GST_RGB24_SIZE (width, height);
+    pixbufscale->to_buf_size = GST_RGB24_SIZE (width, height);
+    pixbufscale->from_stride = GST_RGB24_ROWSTRIDE (width);
+    pixbufscale->to_stride = GST_RGB24_ROWSTRIDE (width);
 
     pixbufscale->inited = TRUE;
 
@@ -250,10 +269,12 @@ gst_pixbufscale_link (GstPad * pad, const GstCaps * caps)
   }
 
   if (gst_pad_is_negotiated (otherpad)) {
-    pixbufscale->from_buf_size = pixbufscale->from_width *
-        pixbufscale->from_height * 3;
-    pixbufscale->to_buf_size = pixbufscale->to_width *
-        pixbufscale->to_height * 3;
+    pixbufscale->from_buf_size =
+        GST_RGB24_SIZE (pixbufscale->from_width, pixbufscale->from_height);
+    pixbufscale->to_buf_size =
+        GST_RGB24_SIZE (pixbufscale->to_width, pixbufscale->to_height);
+    pixbufscale->from_stride = GST_RGB24_ROWSTRIDE (pixbufscale->from_width);
+    pixbufscale->to_stride = GST_RGB24_ROWSTRIDE (pixbufscale->to_width);
     pixbufscale->inited = TRUE;
   }
 
@@ -330,10 +351,11 @@ pixbufscale_scale (GstPixbufScale * scale, unsigned char *dest,
   src_pixbuf = gdk_pixbuf_new_from_data
       (src, GDK_COLORSPACE_RGB, FALSE,
       8, scale->from_width, scale->from_height,
-      3 * scale->from_width, NULL, NULL);
+      GST_RGB24_ROWSTRIDE (scale->from_width), NULL, NULL);
   dest_pixbuf = gdk_pixbuf_new_from_data
       (dest, GDK_COLORSPACE_RGB, FALSE,
-      8, scale->to_width, scale->to_height, 3 * scale->to_width, NULL, NULL);
+      8, scale->to_width, scale->to_height,
+      GST_RGB24_ROWSTRIDE (scale->to_width), NULL, NULL);
   gdk_pixbuf_scale (src_pixbuf, dest_pixbuf, 0, 0, scale->to_width,
       scale->to_height, 0, 0,
       (double) scale->to_width / scale->from_width,
@@ -380,12 +402,17 @@ gst_pixbufscale_chain (GstPad * pad, GstData * _data)
       pixbufscale->to_width, pixbufscale->to_height, size,
       pixbufscale->from_buf_size, pixbufscale->to_buf_size);
 
-  g_return_if_fail (size == pixbufscale->from_buf_size);
+  if (size != pixbufscale->from_buf_size) {
+    GST_ERROR ("Incoming RGB data is %d bytes (expected: %d bytes) (%dx%d)\n",
+        size, pixbufscale->from_buf_size, pixbufscale->from_width,
+        pixbufscale->from_height);
+    return;
+  }
 
   outbuf = gst_pad_alloc_buffer (pixbufscale->srcpad,
       GST_BUFFER_OFFSET_NONE, pixbufscale->to_buf_size);
 
-  GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
+  gst_buffer_stamp (outbuf, buf);
 
   pixbufscale_scale (pixbufscale, GST_BUFFER_DATA (outbuf), data);