docs: remove old 0.10 Since markers
[platform/upstream/gstreamer.git] / ext / pango / gstbasetextoverlay.c
index dc68f33..be1cd6e 100644 (file)
@@ -121,48 +121,6 @@ GST_DEBUG_CATEGORY (pango_debug);
 #define MINIMUM_OUTLINE_OFFSET 1.0
 #define DEFAULT_SCALE_BASIS    640
 
-#define COMP_Y(ret, r, g, b) \
-{ \
-   ret = (int) (((19595 * r) >> 16) + ((38470 * g) >> 16) + ((7471 * b) >> 16)); \
-   ret = CLAMP (ret, 0, 255); \
-}
-
-#define COMP_U(ret, r, g, b) \
-{ \
-   ret = (int) (-((11059 * r) >> 16) - ((21709 * g) >> 16) + ((32768 * b) >> 16) + 128); \
-   ret = CLAMP (ret, 0, 255); \
-}
-
-#define COMP_V(ret, r, g, b) \
-{ \
-   ret = (int) (((32768 * r) >> 16) - ((27439 * g) >> 16) - ((5329 * b) >> 16) + 128); \
-   ret = CLAMP (ret, 0, 255); \
-}
-
-#define BLEND(ret, alpha, v0, v1) \
-{ \
-       ret = (v0 * alpha + v1 * (255 - alpha)) / 255; \
-}
-
-#define OVER(ret, alphaA, Ca, alphaB, Cb, alphaNew)    \
-{ \
-    gint _tmp; \
-    _tmp = (Ca * alphaA + Cb * alphaB * (255 - alphaA) / 255) / alphaNew; \
-    ret = CLAMP (_tmp, 0, 255); \
-}
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-# define CAIRO_ARGB_A 3
-# define CAIRO_ARGB_R 2
-# define CAIRO_ARGB_G 1
-# define CAIRO_ARGB_B 0
-#else
-# define CAIRO_ARGB_A 0
-# define CAIRO_ARGB_R 1
-# define CAIRO_ARGB_G 2
-# define CAIRO_ARGB_B 3
-#endif
-
 enum
 {
   PROP_0,
@@ -189,12 +147,7 @@ enum
   PROP_LAST
 };
 
-/* FIXME: video-blend.c doesn't support formats with more than 8 bit per
- * component (which get unpacked into ARGB64 or AYUV64) yet, such as:
- *  v210, v216, UYVP, GRAY16_LE, GRAY16_BE */
-#define VIDEO_FORMATS "{ BGRx, RGBx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, \
-    I420, YV12, AYUV, YUY2, UYVY, v308, Y41B, Y42B, Y444, \
-    NV12, NV21, A420, YUV9, YVU9, IYU1, GRAY8 }"
+#define VIDEO_FORMATS GST_VIDEO_OVERLAY_COMPOSITION_BLEND_FORMATS
 
 static GstStaticPadTemplate src_template_factory =
 GST_STATIC_PAD_TEMPLATE ("src",
@@ -464,24 +417,20 @@ gst_base_text_overlay_class_init (GstBaseTextOverlayClass * klass)
           "Shift Y position up or down. Unit is pixels.", G_MININT, G_MAXINT,
           DEFAULT_PROP_DELTAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstBaseTextOverlay:xpos
+   * GstBaseTextOverlay:xpos:
    *
    * Horizontal position of the rendered text when using positioned alignment.
-   *
-   * Since: 0.10.31
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_XPOS,
       g_param_spec_double ("xpos", "horizontal position",
           "Horizontal position when using position alignment", 0, 1.0,
           DEFAULT_PROP_XPOS,
           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstBaseTextOverlay:ypos
+   * GstBaseTextOverlay:ypos:
    *
    * Vertical position of the rendered text when using positioned alignment.
-   *
-   * Since: 0.10.31
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_YPOS,
       g_param_spec_double ("ypos", "vertical position",
           "Vertical position when using position alignment", 0, 1.0,
@@ -499,24 +448,20 @@ gst_base_text_overlay_class_init (GstBaseTextOverlayClass * klass)
           "for syntax.", DEFAULT_PROP_FONT_DESC,
           G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstBaseTextOverlay:color
+   * GstBaseTextOverlay:color:
    *
    * Color of the rendered text.
-   *
-   * Since: 0.10.31
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_COLOR,
       g_param_spec_uint ("color", "Color",
           "Color to use for text (big-endian ARGB).", 0, G_MAXUINT32,
           DEFAULT_PROP_COLOR,
           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstTextOverlay:outline-color
+   * GstTextOverlay:outline-color:
    *
    * Color of the outline of the rendered text.
-   *
-   * Since: 0.10.35
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_OUTLINE_COLOR,
       g_param_spec_uint ("outline-color", "Text Outline Color",
           "Color to use for outline the text (big-endian ARGB).", 0,
@@ -524,25 +469,21 @@ gst_base_text_overlay_class_init (GstBaseTextOverlayClass * klass)
           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
 
   /**
-   * GstBaseTextOverlay:line-alignment
+   * GstBaseTextOverlay:line-alignment:
    *
    * Alignment of text lines relative to each other (for multi-line text)
-   *
-   * Since: 0.10.15
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LINE_ALIGNMENT,
       g_param_spec_enum ("line-alignment", "line alignment",
           "Alignment of text lines relative to each other.",
           GST_TYPE_BASE_TEXT_OVERLAY_LINE_ALIGN, DEFAULT_PROP_LINE_ALIGNMENT,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstBaseTextOverlay:silent
+   * GstBaseTextOverlay:silent:
    *
    * If set, no text is rendered. Useful to switch off text rendering
    * temporarily without removing the textoverlay element from the pipeline.
-   *
-   * Since: 0.10.15
-   **/
+   */
   /* FIXME 0.11: rename to "visible" or "text-visible" or "render-text" */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SILENT,
       g_param_spec_boolean ("silent", "silent",
@@ -550,14 +491,12 @@ gst_base_text_overlay_class_init (GstBaseTextOverlayClass * klass)
           DEFAULT_PROP_SILENT,
           G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
   /**
-   * GstBaseTextOverlay:wait-text
+   * GstBaseTextOverlay:wait-text:
    *
    * If set, the video will block until a subtitle is received on the text pad.
    * If video and subtitles are sent in sync, like from the same demuxer, this
    * property should be set.
-   *
-   * Since: 0.10.20
-   **/
+   */
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WAIT_TEXT,
       g_param_spec_boolean ("wait-text", "Wait Text",
           "Whether to wait for subtitles",
@@ -1035,7 +974,7 @@ gst_base_text_overlay_src_query (GstPad * pad, GstObject * parent,
       break;
     }
     default:
-      ret = gst_pad_peer_query (overlay->video_sinkpad, query);
+      ret = gst_pad_query_default (pad, parent, query);
       break;
   }
 
@@ -1381,13 +1320,18 @@ gst_base_text_overlay_render_pangocairo (GstBaseTextOverlay * overlay,
 
   /* draw shadow text */
   {
-    PangoAttrList *origin_attr, *filtered_attr;
+    PangoAttrList *origin_attr, *filtered_attr, *temp_attr;
 
+    /* Store a ref on the original attributes for later restoration */
     origin_attr =
         pango_attr_list_ref (pango_layout_get_attributes (overlay->layout));
+    /* Take a copy of the original attributes, because pango_attr_list_filter
+     * modifies the passed list */
+    temp_attr = pango_attr_list_copy (origin_attr);
     filtered_attr =
-        pango_attr_list_filter (pango_attr_list_copy (origin_attr),
+        pango_attr_list_filter (temp_attr,
         gst_text_overlay_filter_foreground_attr, NULL);
+    pango_attr_list_unref (temp_attr);
 
     cairo_save (cr);
     cairo_translate (cr, overlay->shadow_offset, overlay->shadow_offset);
@@ -1540,6 +1484,34 @@ gst_base_text_overlay_shade_rgb24 (GstBaseTextOverlay * overlay,
   }
 }
 
+static void
+gst_base_text_overlay_shade_IYU1 (GstBaseTextOverlay * overlay,
+    GstVideoFrame * frame, gint x0, gint x1, gint y0, gint y1)
+{
+  gint y, x, stride, shading_val, tmp;
+  guint8 *p;
+
+  shading_val = overlay->shading_value;
+  stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
+
+  /* IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...) */
+  for (y = y0; y < y1; ++y) {
+    p = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
+    /* move to Y0 or Y1 (we pretend the chroma is the last of the 3 bytes) */
+    /* FIXME: we're not pixel-exact here if x0 is an odd number, but it's
+     * unlikely anyone will notice.. */
+    p += (y * stride) + ((x0 / 2) * 3) + 1;
+    for (x = x0; x < x1; x += 2) {
+      tmp = *p + shading_val;
+      *p++ = CLAMP (tmp, 0, 255);
+      tmp = *p + shading_val;
+      *p++ = CLAMP (tmp, 0, 255);
+      /* skip chroma */
+      p++;
+    }
+  }
+}
+
 #define ARGB_SHADE_FUNCTION(name, OFFSET)      \
 static inline void \
 gst_base_text_overlay_shade_##name (GstBaseTextOverlay * overlay, GstVideoFrame * dest, \
@@ -1625,6 +1597,7 @@ gst_base_text_overlay_shade_background (GstBaseTextOverlay * overlay,
     case GST_VIDEO_FORMAT_YUV9:
     case GST_VIDEO_FORMAT_YVU9:
     case GST_VIDEO_FORMAT_GRAY8:
+    case GST_VIDEO_FORMAT_A420:
       gst_base_text_overlay_shade_planar_Y (overlay, frame, x0, x1, y0, y1);
       break;
     case GST_VIDEO_FORMAT_AYUV:
@@ -1661,6 +1634,9 @@ gst_base_text_overlay_shade_background (GstBaseTextOverlay * overlay,
     case GST_VIDEO_FORMAT_RGB:
       gst_base_text_overlay_shade_rgb24 (overlay, frame, x0, x1, y0, y1);
       break;
+    case GST_VIDEO_FORMAT_IYU1:
+      gst_base_text_overlay_shade_IYU1 (overlay, frame, x0, x1, y0, y1);
+      break;
     default:
       GST_FIXME_OBJECT (overlay, "implement background shading for format %s",
           gst_video_format_to_string (GST_VIDEO_FRAME_FORMAT (frame)));