qBittorrent
anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos Class Reference
Collaboration diagram for anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos:

Public Member Functions

 PieceIndexToImagePos (const BitTorrent::TorrentInfo &torrentInfo, const QImage &image)
 
ImageRange imagePos (const BitTorrent::TorrentInfo::PieceRange &pieces) const
 
int pieceIndex (int imagePos) const
 

Private Attributes

const qlonglong m_bytesPerPixel
 
const BitTorrent::TorrentInfo m_torrentInfo
 

Detailed Description

Definition at line 52 of file piecesbar.cpp.

Constructor & Destructor Documentation

◆ PieceIndexToImagePos()

anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos::PieceIndexToImagePos ( const BitTorrent::TorrentInfo torrentInfo,
const QImage &  image 
)
inline

Definition at line 55 of file piecesbar.cpp.

57  {((image.width() > 0) && (torrentInfo.totalSize() >= image.width()))
58  ? torrentInfo.totalSize() / image.width() : -1}
59  , m_torrentInfo {torrentInfo}
60  {
61  if ((m_bytesPerPixel > 0) && (m_bytesPerPixel < 10))
62  qDebug() << "PieceIndexToImagePos: torrent size is too small for correct computaions."
63  << "Torrent size =" << torrentInfo.totalSize() << "Image width = " << image.width();
64  }
qlonglong totalSize() const

References BitTorrent::TorrentInfo::totalSize().

Here is the call graph for this function:

Member Function Documentation

◆ imagePos()

ImageRange anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos::imagePos ( const BitTorrent::TorrentInfo::PieceRange pieces) const
inline

Definition at line 66 of file piecesbar.cpp.

67  {
68  if (m_bytesPerPixel < 0)
69  return {0, 0};
70 
71  // the type conversion is used to prevent integer overflow with torrents of 2+ GiB size
72  const qlonglong pieceLength = m_torrentInfo.pieceLength();
73  return makeInterval<ImageRange::IndexType>(
74  (pieces.first() * pieceLength) / m_bytesPerPixel,
75  (pieces.last() * pieceLength + m_torrentInfo.pieceLength(pieces.last()) - 1) / m_bytesPerPixel);
76  }
constexpr IndexType last() const
Definition: indexrange.h:156
constexpr IndexType first() const
Definition: indexrange.h:151

References IndexRange< Index, IndexDiff >::first(), and IndexRange< Index, IndexDiff >::last().

Here is the call graph for this function:

◆ pieceIndex()

int anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos::pieceIndex ( int  imagePos) const
inline

Definition at line 78 of file piecesbar.cpp.

79  {
81  }
ImageRange imagePos(const BitTorrent::TorrentInfo::PieceRange &pieces) const
Definition: piecesbar.cpp:66

Member Data Documentation

◆ m_bytesPerPixel

const qlonglong anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos::m_bytesPerPixel
private

Definition at line 84 of file piecesbar.cpp.

◆ m_torrentInfo

const BitTorrent::TorrentInfo anonymous_namespace{piecesbar.cpp}::PieceIndexToImagePos::m_torrentInfo
private

Definition at line 85 of file piecesbar.cpp.


The documentation for this class was generated from the following file: