2002-09-26 12:20:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Library <2002> Ronald Bultje <rbultje@ronald.bitfreak.net>
|
2007-12-18 00:13:26 +00:00
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
2002-09-26 12:20:12 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-10-31 20:03:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-15 14:16:02 +00:00
|
|
|
#include <string.h>
|
2012-06-04 14:15:25 +00:00
|
|
|
#include <stdio.h>
|
2011-06-15 14:16:02 +00:00
|
|
|
|
2002-09-26 12:20:12 +00:00
|
|
|
#include "video.h"
|
2011-10-31 01:23:21 +00:00
|
|
|
#include "gstvideometa.h"
|
2002-09-26 12:20:12 +00:00
|
|
|
|
2012-05-29 13:12:16 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstvideo
|
|
|
|
* @short_description: Support library for video operations
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* This library contains some helper functions and includes the
|
|
|
|
* videosink and videofilter base classes.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2011-06-17 13:29:50 +00:00
|
|
|
/**
|
2012-06-05 10:47:22 +00:00
|
|
|
* gst_video_calculate_display_ratio:
|
|
|
|
* @dar_n: Numerator of the calculated display_ratio
|
|
|
|
* @dar_d: Denominator of the calculated display_ratio
|
|
|
|
* @video_width: Width of the video frame in pixels
|
|
|
|
* @video_height: Height of the video frame in pixels
|
|
|
|
* @video_par_n: Numerator of the pixel aspect ratio of the input video.
|
|
|
|
* @video_par_d: Denominator of the pixel aspect ratio of the input video.
|
|
|
|
* @display_par_n: Numerator of the pixel aspect ratio of the display device
|
|
|
|
* @display_par_d: Denominator of the pixel aspect ratio of the display device
|
2011-08-24 11:52:20 +00:00
|
|
|
*
|
2012-06-05 10:47:22 +00:00
|
|
|
* Given the Pixel Aspect Ratio and size of an input video frame, and the
|
|
|
|
* pixel aspect ratio of the intended display device, calculates the actual
|
|
|
|
* display ratio the video will be rendered with.
|
2011-06-17 13:29:50 +00:00
|
|
|
*
|
2012-06-05 10:47:22 +00:00
|
|
|
* Returns: A boolean indicating success and a calculated Display Ratio in the
|
|
|
|
* dar_n and dar_d parameters.
|
|
|
|
* The return value is FALSE in the case of integer overflow or other error.
|
2011-06-17 13:29:50 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2012-06-05 10:47:22 +00:00
|
|
|
gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
|
|
|
|
guint video_width, guint video_height,
|
|
|
|
guint video_par_n, guint video_par_d,
|
|
|
|
guint display_par_n, guint display_par_d)
|
2011-06-17 13:29:50 +00:00
|
|
|
{
|
2012-06-05 10:47:22 +00:00
|
|
|
gint num, den;
|
|
|
|
gint tmp_n, tmp_d;
|
2011-08-24 11:52:20 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
g_return_val_if_fail (dar_n != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (dar_d != NULL, FALSE);
|
2012-04-19 10:03:19 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
/* Calculate (video_width * video_par_n * display_par_d) /
|
|
|
|
* (video_height * video_par_d * display_par_n) */
|
|
|
|
if (!gst_util_fraction_multiply (video_width, video_height, video_par_n,
|
|
|
|
video_par_d, &tmp_n, &tmp_d))
|
|
|
|
goto error_overflow;
|
2011-06-17 13:29:50 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
if (!gst_util_fraction_multiply (tmp_n, tmp_d, display_par_d, display_par_n,
|
|
|
|
&num, &den))
|
|
|
|
goto error_overflow;
|
2011-06-17 13:29:50 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
g_return_val_if_fail (num > 0, FALSE);
|
|
|
|
g_return_val_if_fail (den > 0, FALSE);
|
2011-06-17 13:29:50 +00:00
|
|
|
|
2012-06-05 10:47:22 +00:00
|
|
|
*dar_n = num;
|
|
|
|
*dar_d = den;
|
2012-03-27 13:01:01 +00:00
|
|
|
|
2011-06-17 13:29:50 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-06-05 10:47:22 +00:00
|
|
|
error_overflow:
|
2011-06-17 13:29:50 +00:00
|
|
|
{
|
2012-06-05 10:47:22 +00:00
|
|
|
GST_WARNING ("overflow in multiply");
|
2011-06-17 13:29:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2012-08-20 08:50:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_video_alignment_reset:
|
|
|
|
* @align: a #GstVideoAlignment
|
|
|
|
*
|
|
|
|
* Set @align to its default values with no padding and no alignment.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_video_alignment_reset (GstVideoAlignment * align)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_if_fail (align != NULL);
|
|
|
|
|
|
|
|
align->padding_top = 0;
|
|
|
|
align->padding_bottom = 0;
|
|
|
|
align->padding_left = 0;
|
|
|
|
align->padding_right = 0;
|
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++)
|
|
|
|
align->stride_align[i] = 0;
|
|
|
|
}
|