]> git.sesse.net Git - kdenlive/blobdiff - src/colorcorrection/histogramgenerator.cpp
Const'ref
[kdenlive] / src / colorcorrection / histogramgenerator.cpp
index 07018be21631ac5e2c277731fb2abbce1da09dfb..c08cb0e12942bf3e859403ad0b0fe3f7ce729bfa 100644 (file)
@@ -19,9 +19,8 @@ HistogramGenerator::HistogramGenerator()
 }
 
 QImage HistogramGenerator::calculateHistogram(const QSize &paradeSize, const QImage &image, const int &components,
-                                              HistogramGenerator::Rec rec, const bool &unscaled, const uint &accelFactor) const
+                                              HistogramGenerator::Rec rec, bool unscaled, uint accelFactor) const
 {
-//    qDebug() << "Histogram rect size is: " << paradeSize.width() << "/" << paradeSize.height();
     if (paradeSize.height() <= 0 || paradeSize.width() <= 0 || image.width() <= 0 || image.height() <= 0) {
         return QImage();
     }
@@ -45,7 +44,7 @@ QImage HistogramGenerator::calculateHistogram(const QSize &paradeSize, const QIm
     const uint ww = paradeSize.width();
     const uint wh = paradeSize.height();
     const uint byteCount = iw*ih;
-    const uint stepsize = 4*accelFactor;
+    const uint stepsize = image.depth() / 8 *accelFactor;
 
     const uchar *bits = image.bits();
     QRgb *col;
@@ -85,7 +84,10 @@ QImage HistogramGenerator::calculateHistogram(const QSize &paradeSize, const QIm
 
     const int d = 20; // Distance for text
     const int partH = (wh-nParts*d)/nParts;
-    const float scaling = (float)partH/(byteCount >> 7);
+    float scaling = 0;
+    int div = byteCount >> 7;
+    if ( div > 0 )
+        scaling = (float)partH/(byteCount >> 7);
     const int dist = 40;
 
     int wy = 0; // Drawing position
@@ -96,34 +98,29 @@ QImage HistogramGenerator::calculateHistogram(const QSize &paradeSize, const QIm
     histogram.fill(qRgba(0, 0, 0, 0));
 
     if (drawY) {
-//        qDebug() << "Drawing Y at " << wy << " with height " << partH;
         drawComponentFull(&davinci, y, scaling, QRect(0, wy, ww, partH + dist), QColor(220, 220, 210, 255), dist, unscaled, 256);
 
         wy += partH + d;
     }
 
     if (drawSum) {
-//        qDebug() << "Drawing S at " << wy << " with height " << partH;
         drawComponentFull(&davinci, s, scaling/3, QRect(0, wy, ww, partH + dist), QColor(220, 220, 210, 255), dist, unscaled, 256);
 
         wy += partH + d;
     }
 
     if (drawR) {
-//        qDebug() << "Drawing R at " << wy << " with height " << partH;
         drawComponentFull(&davinci, r, scaling, QRect(0, wy, ww, partH + dist), QColor(255, 128, 0, 255), dist, unscaled, 256);
 
         wy += partH + d;
     }
 
     if (drawG) {
-//        qDebug() << "Drawing G at " << wy << " with height " << partH;
         drawComponentFull(&davinci, g, scaling, QRect(0, wy, ww, partH + dist), QColor(128, 255, 0, 255), dist, unscaled, 256);
         wy += partH + d;
     }
 
     if (drawB) {
-//        qDebug() << "Drawing B at " << wy << " with height " << partH;
         drawComponentFull(&davinci, b, scaling, QRect(0, wy, ww, partH + dist), QColor(0, 128, 255, 255), dist, unscaled, 256);
 
         wy += partH + d;
@@ -133,7 +130,7 @@ QImage HistogramGenerator::calculateHistogram(const QSize &paradeSize, const QIm
 }
 
 QImage HistogramGenerator::drawComponent(const int *y, const QSize &size, const float &scaling, const QColor &color,
-                                         const bool &unscaled, const uint &max) const
+                                         bool unscaled, uint max) const
 {
     QImage component(max, size.height(), QImage::Format_ARGB32);
     component.fill(qRgba(0, 0, 0, 0));
@@ -162,7 +159,7 @@ QImage HistogramGenerator::drawComponent(const int *y, const QSize &size, const
 }
 
 void HistogramGenerator::drawComponentFull(QPainter *davinci, const int *y, const float &scaling, const QRect &rect,
-                                        const QColor &color, const int &textSpace, const bool &unscaled, const uint &max) const
+                                        const QColor &color, int textSpace, bool unscaled, uint max) const
 {
     QImage component = drawComponent(y, rect.size() - QSize(0, textSpace), scaling, color, unscaled, max);
     davinci->drawImage(rect.topLeft(), component);