Ejemplo n.º 1
0
// blue colored
QImage TorrentProgressWidget::generate(const libtorrent::bitfield& data, int width, quint32* buf, float sstart, float send)
{
	double fact = (data.size()-send-sstart)/float(width);
	double step = qMin<double>(255.0, 255.0/fact);
	
	for(int i=0;i<width;i++)
	{
		int from = i*fact+sstart;
		int to = (i+1)*fact+sstart;
		
		if(to >= (int) data.size())
			to = data.size()-1;
		
		double color = 0;
		do
		{
			color += data[from] ? step : 0;
			from++;
		}
		while(from <= to);
		
		quint32 rcolor = 255 - qMin(quint32(color), 255U);
		buf[i] = 0xff0000ff | (rcolor << 8) | (rcolor << 16);
	}
	
	return QImage((uchar*) buf, width, 1, QImage::Format_RGB32);
}
Ejemplo n.º 2
0
			QList<QPair<int, int> > FindTrues (const libtorrent::bitfield& pieces)
			{
				QList<QPair<int, int> > result;
				bool prevVal = pieces [0];
				int prevPos = 0;
				int size = static_cast<int> (pieces.size ());
				for (int i = 1; i < size; ++i)
					if (pieces [i] != prevVal)
					{
						if (prevVal)
							result << qMakePair (prevPos, i);
						prevPos = i;
						prevVal = 1 - prevVal;
					}
			
				if (!prevPos && prevVal)
					result << qMakePair<int, int> (0, pieces.size ());
				else if (prevVal && result.size () && result.last ().second != size - 1)
					result << qMakePair<int, int> (prevPos, size);
				else if (prevVal && !result.size ())
					result << qMakePair<int, int> (0, size);
			
				return result;
			}
Ejemplo n.º 3
0
 void Context::bitfieldToVector(libtorrent::bitfield const& _input, 
                                std::vector<bool> & _output) const
 {
    _output.resize(_input.size());
    std::copy(_input.begin(), _input.end(), _output.begin());
 }