From 3e2a9acbd680d41ad79176537326c1a8deaeb98f Mon Sep 17 00:00:00 2001 From: Marco Gittler Date: Mon, 25 Feb 2008 16:42:18 +0000 Subject: [PATCH] use smaller pix for cache (very fast), but the clip itself is slow down painting on long videos svn path=/branches/KDE4/; revision=1936 --- src/clipitem.cpp | 89 ++++++++++++++++++++++++++---------------------- src/clipitem.h | 6 ++-- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index d144b0f7..b0abdc95 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -57,7 +57,7 @@ ClipItem::ClipItem(DocClipBase *clip, int track, int startpos, const QRectF & re setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); - connect (this , SIGNAL (prepareAudioThumb(double,QPainterPath)) , this, SLOT (slotPrepareAudioThumb(double,QPainterPath))); + connect (this , SIGNAL (prepareAudioThumb(double,QPainterPath,int,int)) , this, SLOT (slotPrepareAudioThumb(double,QPainterPath,int,int))); setBrush(QColor(100, 100, 150)); if (m_clipType == VIDEO || m_clipType == AV) { m_hasThumbs = true; @@ -222,13 +222,15 @@ int ClipItem::endPos() painter->drawLine(l2); } if (m_clipType == AV || m_clipType==AUDIO ){ + int startpixel=0; + int endpixel=400; QPainterPath path= m_clipType==AV ? roundRectPathLower : roundRectPathUpper.united(roundRectPathLower); painter->fillPath(path,QBrush(QColor(200,200,200,127))); int channels=2; double pixelForOneFrame=(double)br.width()/duration(); if (framePixelWidth!=pixelForOneFrame){ - emit prepareAudioThumb(pixelForOneFrame,path); + emit prepareAudioThumb(pixelForOneFrame,path,startpixel,endpixel); /* re.x() changeds every time on move, so the path has to be rebuild every time QRectF re=path.boundingRect(); @@ -273,9 +275,10 @@ int ClipItem::endPos() } */ } - - if (!audioThumbCachePic.isNull() ) - painter->drawPixmap(path.boundingRect().x(),path.boundingRect().y(),audioThumbCachePic); + for (int startCache=startpixel-startpixel%100;startCachedrawPixmap(path.boundingRect().x()+startCache,path.boundingRect().y(),audioThumbCachePic[startCache]); + } /*if ( channelPaths.size() ) for (int i=0;idrawPath(channelPaths[i]); @@ -375,53 +378,59 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) return MOVE; } -void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path){ +void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame,QPainterPath path,int startpixel, int endpixel){ int channels=2; QRectF re=path.boundingRect(); - if (audioThumbCachePic.isNull() || framePixelWidth!=pixelForOneFrame){ - audioThumbCachePic=QPixmap(re.width(),re.height()); - audioThumbCachePic.fill(QColor(200,200,200,127)); - } + if ( (!audioThumbWasDrawn || framePixelWidth!=pixelForOneFrame ) && !baseClip()->audioFrameChache.isEmpty()){ - QMap positiveChannelPaths; - QMap negativeChannelPaths; - QPainter pixpainter(&audioThumbCachePic); - QPen audiopen; - audiopen.setWidth(0); - pixpainter.setPen(audiopen); - pixpainter.setRenderHint(QPainter::Antialiasing,true); - for (int i=0;i19 ) - continue; - QMap frame_channel_data=baseClip()->audioFrameChache[(int)frame]; + if (audioThumbCachePic[startCache].isNull() || framePixelWidth!=pixelForOneFrame){ + audioThumbCachePic[startCache]=QPixmap(100,re.height()); + audioThumbCachePic[startCache].fill(QColor(200,200,200,127)); + } - for (int channel=0;channel 0;channel++){ + QMap positiveChannelPaths; + QMap negativeChannelPaths; + QPainter pixpainter(&audioThumbCachePic[startCache]); + QPen audiopen; + audiopen.setWidth(0); + pixpainter.setPen(audiopen); + pixpainter.setRenderHint(QPainter::Antialiasing,true); + for (int i=0;i19 ) + continue; + QMap frame_channel_data=baseClip()->audioFrameChache[(int)frame]; - positiveChannelPaths[channel].lineTo(samples,0.1+y+( (int)frame_channel_data[channel][sample] -127/2 ) * (audioThumbCachePic.height()/channels) / 64 ); - negativeChannelPaths[channel].lineTo(samples,0.1+y-( (int)frame_channel_data[channel][sample] -127/2 ) * (audioThumbCachePic.height()/channels) / 64 ); + for (int channel=0;channel 0;channel++){ + + int y=audioThumbCachePic[startCache].height()*channel/channels+ (/*re.height()*/audioThumbCachePic[startCache].height()/channels)/2; + + positiveChannelPaths[channel].lineTo(samples,0.1+y+( (int)frame_channel_data[channel][sample] -127/2 ) * (audioThumbCachePic[startCache].height()/channels) / 64 ); + negativeChannelPaths[channel].lineTo(samples,0.1+y-( (int)frame_channel_data[channel][sample] -127/2 ) * (audioThumbCachePic[startCache].height()/channels) / 64 ); + } + } + for (int i=0;i audioThumbCachePic; bool audioThumbWasDrawn; double framePixelWidth; QMap channelPaths; @@ -121,10 +121,10 @@ class ClipItem : public QObject, public QGraphicsRectItem void slotGetStartThumb(); void slotGetEndThumb(); void slotGotAudioData(); - void slotPrepareAudioThumb(double,QPainterPath); + void slotPrepareAudioThumb(double,QPainterPath,int,int); signals: void getThumb(int, int); - void prepareAudioThumb(double,QPainterPath); + void prepareAudioThumb(double,QPainterPath,int,int); }; -- 2.39.2