]> git.lyx.org Git - features.git/commitdiff
Store and use QImage rather than QPixmap.
authorAngus Leeming <leeming@lyx.org>
Sun, 2 May 2004 12:45:26 +0000 (12:45 +0000)
committerAngus Leeming <leeming@lyx.org>
Sun, 2 May 2004 12:45:26 +0000 (12:45 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8720 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QLImage.C
src/frontends/qt2/QLImage.h
src/frontends/qt2/QLPainter.C

index 0e4f4f840c9531b8664b0f46f565f0a3478e452b..6522f7b8dde4ada00a29aa7c6c045c706113cae5 100644 (file)
@@ -1,3 +1,11 @@
+2004-05-02  Angus Leeming  <leeming@lyx.org>
+
+       * QLImage.[Ch]: store and use QImage rather than QPixmap. Saves
+       a heap of transformations to/from QImage when manipulating the
+       data.
+
+       * QLPainter.C (image): access QLImage::qimage rather than ::qpixmap.
+
 2004-05-02  Angus Leeming  <leeming@lyx.org>
 
        * QLPainter.C (image): set the background colour to
index 132f1f494cd0ddbd38fb591b0557f11011ebaae1..359c19a33c91dc766cddde549e339ff743731fef 100644 (file)
@@ -102,10 +102,9 @@ QLImage::QLImage()
 
 
 QLImage::QLImage(QLImage const & other)
-       : Image(other), pixmap_(other.pixmap_),
-         xformed_pixmap_(other.pixmap_)
-{
-}
+       : Image(other), original_(other.original_),
+         transformed_(other.original_)
+{}
 
 
 QLImage::~QLImage()
@@ -121,32 +120,32 @@ Image * QLImage::clone_impl() const
 
 unsigned int QLImage::getWidth_impl() const
 {
-       return xformed_pixmap_.width();
+       return transformed_.width();
 }
 
 
 unsigned int QLImage::getHeight_impl() const
 {
-       return xformed_pixmap_.height();
+       return transformed_.height();
 }
 
 
 void QLImage::load_impl(string const & filename)
 {
-       if (!pixmap_.isNull()) {
+       if (!original_.isNull()) {
                lyxerr[Debug::GRAPHICS]
                        << "Image is loaded already!" << endl;
                finishedLoading(false);
                return;
        }
 
-       if (!pixmap_.load(toqstr(filename))) {
+       if (!original_.load(toqstr(filename))) {
                lyxerr[Debug::GRAPHICS]
                        << "Unable to open image" << endl;
                finishedLoading(false);
                return;
        }
-       xformed_pixmap_ = pixmap_;
+       transformed_ = original_;
        finishedLoading(true);
 }
 
@@ -178,24 +177,22 @@ QImage & toGray(QImage & img)
 
 bool QLImage::setPixmap_impl(Params const & params)
 {
-       if (pixmap_.isNull() || params.display == NoDisplay)
+       if (original_.isNull() || params.display == NoDisplay)
                return false;
 
        switch (params.display) {
        case GrayscaleDisplay: {
-               QImage i(xformed_pixmap_.convertToImage());
-               xformed_pixmap_.convertFromImage(toGray(i));
+               toGray(transformed_);
                break;
        }
 
        case MonochromeDisplay: {
-                       QImage i(xformed_pixmap_.convertToImage());
-                       xformed_pixmap_.convertFromImage(i, QPixmap::Mono);
-                       break;
-               }
+               transformed_.convertDepth(transformed_.depth(), Qt::MonoOnly);
+               break;
+       }
 
-               default:
-                       break;
+       default:
+               break;
        }
 
        return true;
@@ -204,7 +201,7 @@ bool QLImage::setPixmap_impl(Params const & params)
 
 void QLImage::clip_impl(Params const & params)
 {
-       if (xformed_pixmap_.isNull())
+       if (transformed_.isNull())
                return;
 
        if (params.bb.empty())
@@ -216,46 +213,42 @@ void QLImage::clip_impl(Params const & params)
 
        // No need to check if the width, height are > 0 because the
        // Bounding Box would be empty() in this case.
-       if (new_width > pixmap_.width() || new_height > pixmap_.height()) {
+       if (new_width > original_.width() || new_height > original_.height()) {
                // Bounds are invalid.
                return;
        }
 
-       if (new_width == pixmap_.width() && new_height == pixmap_.height())
+       if (new_width == original_.width() && new_height == original_.height())
                return;
 
        int const xoffset_l = params.bb.xl;
-       int const yoffset_t = (pixmap_.height() > int(params.bb.yt) ?
-                               pixmap_.height() - params.bb.yt : 0);
-
-       xformed_pixmap_.resize(new_width, new_height);
-       QPainter p;
-       p.begin(&xformed_pixmap_);
-       p.drawPixmap(0, 0, pixmap_, xoffset_l, yoffset_t, new_width, new_height);
-       p.end();
+       int const yoffset_t = (original_.height() > int(params.bb.yt) ?
+                              original_.height() - params.bb.yt : 0);
+
+       transformed_ = original_.copy(xoffset_l, yoffset_t,
+                                     new_width, new_height);
 }
 
 
 void QLImage::rotate_impl(Params const & params)
 {
-       if (xformed_pixmap_.isNull())
+       if (transformed_.isNull())
                return;
 
        if (!params.angle)
                return;
 
-       // The angle passed to flimage_rotate is the angle in one-tenth of a
-       // degree units.
-
        QWMatrix m;
        m.rotate(-params.angle);
-       xformed_pixmap_ = xformed_pixmap_.xForm(m);
+
+       transformed_.setAlphaBuffer(true);
+       transformed_ = transformed_.xForm(m);
 }
 
 
 void QLImage::scale_impl(Params const & params)
 {
-       if (xformed_pixmap_.isNull())
+       if (transformed_.isNull())
                return;
 
        unsigned int width;
@@ -267,7 +260,7 @@ void QLImage::scale_impl(Params const & params)
 
        QWMatrix m;
        m.scale(double(width) / getWidth(), double(height) / getHeight());
-       xformed_pixmap_ = xformed_pixmap_.xForm(m);
+       transformed_ = transformed_.xForm(m);
 }
 
 } // namespace graphics
index 581a8bf424baabb3feff87cb80cb1438c37213df..d3f35e567d11e499d5a2a0e52ce0bcada22b7ba1 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "graphics/GraphicsImage.h"
 
-#include <qpixmap.h>
+#include <qimage.h>
 
 namespace lyx {
 namespace graphics {
@@ -30,7 +30,7 @@ public:
        static FormatList loadableFormats();
 
        ~QLImage();
-       QPixmap const & qpixmap() const { return xformed_pixmap_; }
+       QImage const & qimage() const { return transformed_; }
 
 private:
        /// Create a copy
@@ -48,10 +48,9 @@ private:
         */
        virtual void load_impl(std::string const & filename);
        /**
-        * Generate the pixmap, based on the current state of
-        * image_ (clipped, rotated, scaled etc).
-        * Uses the params to decide on color, grayscale etc.
-        * Returns true if the pixmap is created.
+        * Finishes the process of modifying transformed_, using
+        * \c params to decide on color, grayscale etc.
+        * \returns true if successful.
         */
        virtual bool setPixmap_impl(Params const & params);
        /// Clip the image using params.
@@ -66,11 +65,11 @@ private:
        ///
        QLImage(QLImage const &);
 
-       /// the original loaded image
-       QPixmap pixmap_;
+       /// The original loaded image.
+       QImage original_;
 
-       /// the transformed pixmap for display
-       QPixmap xformed_pixmap_;
+       /// The transformed image for display.
+       QImage transformed_;
 };
 
 } // namespace graphics
index f72ab542b50f4714c4fb427cffe038196775ae91..7d9a7d7f545a81dd9dde0232db28797d75f35132 100644 (file)
@@ -170,7 +170,7 @@ void QLPainter::image(int x, int y, int w, int h,
                static_cast<lyx::graphics::QLImage const &>(i);
 
        fillRectangle(x, y, w, h, LColor::graphicsbg);
-       qp_->drawPixmap(x, y, qlimage.qpixmap(), 0, 0, w, h);
+       qp_->drawImage(x, y, qlimage.qimage(), 0, 0, w, h);
 }