Ejemplo n.º 1
0
/**
 * @brief Find the biggest common step from a set of all steps.
 */
std::size_t greatestCommonDivisor( const std::set<std::size_t>& steps )
{
	if( steps.size() == 1 )
	{
		return *steps.begin();
	}
	std::set<std::size_t> allSteps;
	for( std::set<std::size_t>::const_iterator itA = steps.begin(), itB = ++steps.begin(), itEnd = steps.end(); itB != itEnd; ++itA, ++itB )
	{
		allSteps.insert( greatestCommonDivisor( *itB, *itA ) );
	}
	return greatestCommonDivisor( allSteps );
}
Ejemplo n.º 2
0
    inline stick::Int64 greatestCommonDivisor(stick::Int64 _a, stick::Int64 _b)
    {
        if (_b == 0)
            return _a;

        return greatestCommonDivisor(_b, _a % _b);
    }
Ejemplo n.º 3
0
    inline int greatestCommonDivisor(int _a, int _b)
    {
        if (_b == 0)
            return _a;

        return greatestCommonDivisor(_b, _a % _b);
    }
Ejemplo n.º 4
0
    inline T greatestCommonDivisor(T _a, T _b)
    {
        if (_b == 0)
            return _a;

        return greatestCommonDivisor(_b, std::fmod(_a, _b));
    }
Ejemplo n.º 5
0
    void setInitialCounter(rowcount_t prevRecCount)
    {
        if (numerator)
        {
            IHThorEnthArg * helper = static_cast <IHThorEnthArg *> (queryHelper());
            if(denominator == 0) denominator = 1;

            counter = (rowcount_t)((helper->getSampleNumber()-1) * greatestCommonDivisor(numerator, denominator));
            if (counter >= denominator)
                counter %= denominator;
            rowcount_t maxBatch = (RCMAX - denominator) / numerator;
            while (prevRecCount > 0)
            {
                rowcount_t next = prevRecCount;
                if (next > maxBatch) next = maxBatch;
                counter = (counter + next * numerator) % denominator;
                prevRecCount -= next;
            }
        }
        else
            abortSoon = true;
#if THOR_TRACE_LEVEL >= 5
        ActPrintLog("ENTH: init - Numerator = %"RCPF"d, Denominator = %"RCPF"d", numerator, denominator);   
        ActPrintLog("%s: Initial value of counter %"RCPF"d", actStr.str(), counter);
#endif
    }
int RatioLayoutedFrame::greatestCommonDivisor(int a, int b)
{
  if (b==0)
  {
    return a;
  }
  return greatestCommonDivisor(b, a % b);
}
void RatioLayoutedFrame::setAspectRatio(unsigned short width, unsigned short height)
{
  int divisor = greatestCommonDivisor(width, height);
  if (divisor != 0) {
    aspect_ratio_.setWidth(width / divisor);
    aspect_ratio_.setHeight(height / divisor);
  }
}
// Returns the size of the video
IntSize MediaPlayerPrivateGStreamerBase::naturalSize() const
{
    if (!hasVideo())
        return IntSize();

    if (!m_videoSize.isEmpty())
        return m_videoSize;

    GRefPtr<GstCaps> caps = currentVideoSinkCaps();
    if (!caps)
        return IntSize();


    // TODO: handle possible clean aperture data. See
    // https://bugzilla.gnome.org/show_bug.cgi?id=596571
    // TODO: handle possible transformation matrix. See
    // https://bugzilla.gnome.org/show_bug.cgi?id=596326

    // Get the video PAR and original size, if this fails the
    // video-sink has likely not yet negotiated its caps.
    int pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride;
    IntSize originalSize;
    GstVideoFormat format;
    if (!getVideoSizeAndFormatFromCaps(caps.get(), originalSize, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride))
        return IntSize();

    LOG_MEDIA_MESSAGE("Original video size: %dx%d", originalSize.width(), originalSize.height());
    LOG_MEDIA_MESSAGE("Pixel aspect ratio: %d/%d", pixelAspectRatioNumerator, pixelAspectRatioDenominator);

    // Calculate DAR based on PAR and video size.
    int displayWidth = originalSize.width() * pixelAspectRatioNumerator;
    int displayHeight = originalSize.height() * pixelAspectRatioDenominator;

    // Divide display width and height by their GCD to avoid possible overflows.
    int displayAspectRatioGCD = greatestCommonDivisor(displayWidth, displayHeight);
    displayWidth /= displayAspectRatioGCD;
    displayHeight /= displayAspectRatioGCD;

    // Apply DAR to original video size. This is the same behavior as in xvimagesink's setcaps function.
    guint64 width = 0, height = 0;
    if (!(originalSize.height() % displayHeight)) {
        LOG_MEDIA_MESSAGE("Keeping video original height");
        width = gst_util_uint64_scale_int(originalSize.height(), displayWidth, displayHeight);
        height = static_cast<guint64>(originalSize.height());
    } else if (!(originalSize.width() % displayWidth)) {
        LOG_MEDIA_MESSAGE("Keeping video original width");
        height = gst_util_uint64_scale_int(originalSize.width(), displayHeight, displayWidth);
        width = static_cast<guint64>(originalSize.width());
    } else {
        LOG_MEDIA_MESSAGE("Approximating while keeping original video height");
        width = gst_util_uint64_scale_int(originalSize.height(), displayWidth, displayHeight);
        height = static_cast<guint64>(originalSize.height());
    }

    LOG_MEDIA_MESSAGE("Natural size: %" G_GUINT64_FORMAT "x%" G_GUINT64_FORMAT, width, height);
    m_videoSize = IntSize(static_cast<int>(width), static_cast<int>(height));
    return m_videoSize;
}
Ejemplo n.º 9
0
rational rational::operator* (const rational& second) const{
    rational result;
    result.denom = this -> denom * second.denom;
    result.num = this -> num * second.num;
    int gcd = greatestCommonDivisor(result.num,result.denom);
    result.num = result.num / gcd;
    result.denom = result.denom /gcd;
    return  result;
}
Ejemplo n.º 10
0
rational rational::operator- (const rational& second) const{
    rational result;
    result.denom = this -> denom * second.denom;
    int multi_first = result.denom / this -> denom;
    int multi_sec = result.denom / second.denom;
    result.num = (this -> num * multi_first) - (second.num * multi_sec);
    int gcd = greatestCommonDivisor(result.num , result.denom);
    int temp = result.num; result.num = temp / gcd;
    temp = result.denom; result.denom = temp / gcd;
    return result;
}
Ejemplo n.º 11
0
rational::rational(int n, int d){
    num = n;
    denom =d;
    if ((denom < 0) && (num > 0)) {
        num = -num;
        denom = -denom;
    }
    int gcd = greatestCommonDivisor(num, denom);
    num = num / gcd;
    denom = denom / gcd;
}
Ejemplo n.º 12
0
void DisplaySettingsDialog::fillResolutions()
{
    ui.comboBoxReso->clear();
    const QList<QSize> resos = screen.availableResolutions();
    foreach (const QSize& reso, resos)
    {
        QSize ratio = reso / greatestCommonDivisor(reso.width(), reso.height());
        QString text = tr("%1 x %2 (%3:%4)")
        .arg(reso.width()).arg(reso.height())
        .arg(ratio.width()).arg(ratio.height());
        ui.comboBoxReso->addItem(text, reso);
    }
Ejemplo n.º 13
0
/**
 * @brief Extract step from a sorted vector of time values.
 */
std::size_t extractStep( const std::vector<Time>& times )
{
	if( times.size() <= 1 )
	{
		return 1;
	}
	std::set<std::size_t> allSteps;
	for( std::vector<Time>::const_iterator itA = times.begin(), itB = ++times.begin(), itEnd = times.end(); itB != itEnd; ++itA, ++itB )
	{
		allSteps.insert( *itB - *itA );
	}
	return greatestCommonDivisor( allSteps );
}
Ejemplo n.º 14
0
/**
 * @brief Extract step from a sorted vector of time values.
 */
std::size_t extractStep( const std::vector<detail::FileNumbers>::const_iterator& timesBegin, const std::vector<detail::FileNumbers>::const_iterator& timesEnd, const std::size_t i )
{
	if( std::distance( timesBegin, timesEnd ) <= 1 )
	{
		return 1;
	}
	std::set<std::size_t> allSteps;
	for( std::vector<detail::FileNumbers>::const_iterator itA = timesBegin, itB = boost::next(timesBegin), itEnd = timesEnd; itB != itEnd; ++itA, ++itB )
	{
		allSteps.insert( itB->getTime( i ) - itA->getTime( i ) );
	}
	return greatestCommonDivisor( allSteps );
}
Ejemplo n.º 15
0
/**
 * @brief Find the biggest common step from a set of all steps.
 */
void Sequence::extractStep( const std::set<std::size_t>& steps )
{
	if( steps.size() == 1 )
	{
		_step = *steps.begin();
		return;
	}
	std::set<std::size_t> allSteps;
	for( std::set<std::size_t>::const_iterator itA = steps.begin(), itB = ++steps.begin(), itEnd = steps.end(); itB != itEnd; ++itA, ++itB )
	{
		allSteps.insert( greatestCommonDivisor( *itB, *itA ) );
	}
	extractStep( allSteps );
}
Ejemplo n.º 16
0
static int32_t leastCommonMultiple(int32_t a, int32_t b, int32_t &result)
{
    return safeMultiply(a, b / greatestCommonDivisor(a, b), result);
}
Ejemplo n.º 17
0
static int greatestCommonDivisor(int a, int b)
{
    if (b == 0)
        return a;
    return greatestCommonDivisor(b, a % b);
}
Ejemplo n.º 18
0
unsigned long greatestCommonDivisor( unsigned long a, unsigned long b )
{
	return b == 0 ? a : greatestCommonDivisor( b, a%b);
}