bool ossimGui::StaticTileImageCache::addTile(const QImage& image)
{
   OpenThreads::ScopedLock<OpenThreads::Mutex> lock(m_mutex);
   bool result = false;
   
   ossimIrect tileRect(image.offset().x(),
                       image.offset().y(),
                       image.offset().x() + (image.width()-1),
                       image.offset().y() + (image.height()-1));
   ossimIrect cacheRect = m_cacheRect;
   
   if(tileRect.intersects(cacheRect))
   {
      ossimIrect clipRect = tileRect.clipToRect(cacheRect);
      
      // now fill the clipped rect
      ossim_uint32 srcY = clipRect.ul().y-tileRect.ul().y;
      ossim_uint32 srcX = clipRect.ul().x-tileRect.ul().x;
      ossim_uint32 destY = clipRect.ul().y-cacheRect.ul().y;
      ossim_uint32 destX = clipRect.ul().x-cacheRect.ul().x;
      ossimIpt offset = tileRect.ul() - cacheRect.ul();
      ossim_uint32 x,y;
      for(y = 0; y < clipRect.height(); ++y)
      {
         ossim_uint32* cachePtr = ((ossim_uint32*)m_cache->scanLine(y+destY))+destX;
         ossim_uint32* tilePtr  = ((ossim_uint32*)image.scanLine(y+srcY))+srcX;
         for(x = 0; x < clipRect.width(); ++x)
         {
            *cachePtr = *tilePtr;
            ++cachePtr;
            ++tilePtr;
         }
      }
      ossimIpt tilePoint(tileRect.ul());

      for(y = 0; y < tileRect.height(); y+=m_tileSize.y)
      {
         tilePoint.x = tileRect.ul().x;
         for(x = 0; x < tileRect.width(); x+=m_tileSize.x)
         {
            ossim_int32 idx = getTileIndex(m_cacheRect, m_numberOfTiles, tilePoint);
            if(idx>=0)
            {
               m_validTileArray[idx] = true;
            }
            tilePoint.x+= m_tileSize.x;
         }
         tilePoint.y+=m_tileSize.y;
      }
      result = true;      
   }
   
   return result;
}
Example #2
0
void Waveform::paintEvent(QPaintEvent * /*event*/)
{
    QPainter painter(this);

    painter.fillRect(rect(), Qt::black);

    if (m_active) {
        WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent"
                             << "windowPosition" << m_windowPosition
                             << "windowLength" << m_windowLength;
        qint64 pos = m_windowPosition;
        const qint64 windowEnd = m_windowPosition + m_windowLength;
        int destLeft = 0;
        int destRight = 0;
        while (pos < windowEnd) {
            const TilePoint point = tilePoint(pos);
            WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "pos" << pos
                                 << "tileIndex" << point.index
                                 << "positionOffset" << point.positionOffset
                                 << "pixelOffset" << point.pixelOffset;

            if (point.index != NullIndex) {
                const Tile &tile = m_tiles[point.index];
                if (tile.painted) {
                    const qint64 sectionLength = qMin((m_tileLength - point.positionOffset),
                                                     (windowEnd - pos));
                    Q_ASSERT(sectionLength > 0);

                    const int sourceRight = tilePixelOffset(point.positionOffset + sectionLength);
                    destRight = windowPixelOffset(pos - m_windowPosition + sectionLength);

                    QRect destRect = rect();
                    destRect.setLeft(destLeft);
                    destRect.setRight(destRight);

                    QRect sourceRect(QPoint(), m_pixmapSize);
                    sourceRect.setLeft(point.pixelOffset);
                    sourceRect.setRight(sourceRight);

                    WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "tileIndex" << point.index
                                         << "source" << point.pixelOffset << sourceRight
                                         << "dest" << destLeft << destRight;

                    painter.drawPixmap(destRect, *tile.pixmap, sourceRect);

                    destLeft = destRight;

                    if (point.index < m_tiles.count()) {
                        pos = tilePosition(point.index + 1);
                        WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "pos ->" << pos;
                    } else {
                        // Reached end of tile array
                        WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "reached end of tile array";
                        break;
                    }
                } else {
                    // Passed last tile which is painted
                    WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "tile" << point.index << "not painted";
                    break;
                }
            } else {
                // pos is past end of tile array
                WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "pos" << pos << "past end of tile array";
                break;
            }
        }

        WAVEFORM_PAINT_DEBUG << "Waveform::paintEvent" << "final pos" << pos << "final x" << destRight;
    }
}