[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/core/tiles
From:       Casper Boemann <cbr () boemann ! dk>
Date:       2005-08-09 18:08:09
Message-ID: 1123610889.890803.14452.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 444318 by boemann:

added nConseqPixels() and += to the rectIterator



 M  +7 -0      kis_iterator.h  
 M  +5 -0      kis_tilediterator.h  
 M  +42 -0     kis_tiledrectiterator.cc  


--- trunk/koffice/krita/core/tiles/kis_iterator.h #444317:444318
@@ -52,6 +52,13 @@
 	/// Returns a pointer to the pixel data as it was at the moment of the last memento creation.
 	inline const Q_UINT8 * oldRawData() const { return ACTUAL_RECTITERATOR::oldRawData();};
 
+	/// Returns the number of consequtive pixels that we point at
+	/// This is useful for optimizing
+	inline Q_INT32 nConseqPixels() const { return ACTUAL_RECTITERATOR::nConseqPixels(); };
+	
+	/// Advances a number of pixels until it reaches the end of the rect
+	inline KisRectIterator & operator+=(int n) { ACTUAL_RECTITERATOR::operator+=(n); return *this; };
+	
 	/// Advances one pixel going to the beginning of the next line when it reaches the end of a line
 	inline KisRectIterator & operator++() { ACTUAL_RECTITERATOR::operator++(); return *this; };
 	
--- trunk/koffice/krita/core/tiles/kis_tilediterator.h #444317:444318
@@ -80,6 +80,11 @@
 	~KisTiledRectIterator();
 
 public:
+	Q_INT32 nConseqPixels() const;
+	
+	/// Advances a number of pixels until it reaches the end of the rect
+	KisTiledRectIterator & operator+=(int n);
+	
 	/// Advances one pixel. Going to the beginning of the next line when it reaches the end of a line
 	KisTiledRectIterator & operator++();
 
--- trunk/koffice/krita/core/tiles/kis_tiledrectiterator.cc #444317:444318
@@ -120,6 +120,48 @@
 {
 }
 
+Q_INT32 KisTiledRectIterator::nConseqPixels() const
+{
+	if(m_leftInTile || (m_rightInTile != KisTile::WIDTH - 1))
+		return m_rightInTile - m_xInTile + 1;
+	else
+		return KisTile::WIDTH * (m_bottomInTile - m_yInTile + 1) - m_xInTile;
+}
+
+KisTiledRectIterator & KisTiledRectIterator::operator+=(int n)
+{
+	int remainInTile;
+	
+	remainInTile= (m_bottomInTile - m_yInTile) * (m_rightInTile - m_leftInTile + 1);
+	remainInTile += m_rightInTile - m_xInTile + 1;
+	
+	// This while loop may not bet the fastest, but usually it's not entered more than once.
+	while(n >= remainInTile)
+	{
+		n -= remainInTile;
+		nextTile();
+		if(m_beyondEnd)
+			return *this;
+		m_yInTile = m_topInTile;
+		m_xInTile = m_leftInTile;
+	}
+
+	int lWidth = m_rightInTile - m_leftInTile + 1;
+	while(n >= lWidth)
+	{
+		n -= lWidth;
+		m_yInTile++;
+	}
+	m_xInTile += n;
+	m_x = m_col * KisTile::WIDTH + m_xInTile;
+	m_y = m_row * KisTile::HEIGHT + m_yInTile;
+	fetchTileData(m_col, m_row);
+	m_offset = m_pixelSize * (m_yInTile * KisTile::WIDTH + m_xInTile);
+	
+	return *this;
+}
+
+
 KisTiledRectIterator & KisTiledRectIterator::operator ++ ()
 {
 	// advance through rect completing each tile before moving on
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic