ganeswidgets/src/hgvgimage.cpp
changeset 1 e48454f237ca
parent 0 89c329efa980
child 2 49c70dcc3f17
--- a/ganeswidgets/src/hgvgimage.cpp	Mon Apr 19 14:40:06 2010 +0300
+++ b/ganeswidgets/src/hgvgimage.cpp	Mon May 03 13:32:54 2010 +0300
@@ -75,7 +75,7 @@
 }
 
 
-void HgVgImage::setImage(QImage& image)
+void HgVgImage::setImage(const QImage& image)
 {
     if (image.isNull())
         return;
@@ -89,6 +89,12 @@
 
 }
 
+QImage HgVgImage::getQImage() const
+{
+    return mQImage;
+}
+
+
 void HgVgImage::releaseImage()
 {
     if (mVgImage != VG_INVALID_HANDLE)
@@ -108,6 +114,8 @@
 
 void HgVgImage::upload(bool mirror)
 {
+    if( mQImage.isNull())
+        return;    
     
     if (mVgImage == VG_INVALID_HANDLE)
     {            
@@ -140,8 +148,12 @@
             return;
         }
         
-        vgImageSubData(mVgImage, mQImage.bits(), mQImage.bytesPerLine(), 
-            format, 0, 0, mQImage.width(), mQImage.height() );        
+        // bits function performs deep copy if we dont fetch data with const specifier.
+        const uchar *bits = mQImage.bits();
+        
+        vgImageSubData(mVgImage, bits, mQImage.bytesPerLine(), 
+            format, 0, 0, mQImage.width(), mQImage.height() );
+        
     }
     
     if (mirror && mMirrorImage == VG_INVALID_HANDLE)
@@ -162,10 +174,10 @@
         {
             qreal t = qreal(i) / qreal(mirrorImage.height());
             int a = (int)(t * 255.0);
+            uchar* scanline = mirrorImage.scanLine(i);
             for (int j = 0; j < mirrorImage.width(); j++)
             {
-                QRgb rgb = mirrorImage.pixel(j, i);
-                mirrorImage.setPixel(j, i, qRgba(qRed(rgb), qGreen(rgb), qBlue(rgb), a));
+                scanline[j*4+3] = a;
             }        
         }