From 32d281cba0a2e4d0e8425a34a1a8d1f5e7251412 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sun, 2 May 2004 12:45:26 +0000 Subject: [PATCH] Store and use QImage rather than QPixmap. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8720 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 8 +++++ src/frontends/qt2/QLImage.C | 63 ++++++++++++++++------------------- src/frontends/qt2/QLImage.h | 19 +++++------ src/frontends/qt2/QLPainter.C | 2 +- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 0e4f4f840c..6522f7b8dd 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2004-05-02 Angus Leeming + + * 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 * QLPainter.C (image): set the background colour to diff --git a/src/frontends/qt2/QLImage.C b/src/frontends/qt2/QLImage.C index 132f1f494c..359c19a33c 100644 --- a/src/frontends/qt2/QLImage.C +++ b/src/frontends/qt2/QLImage.C @@ -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); + int const yoffset_t = (original_.height() > int(params.bb.yt) ? + original_.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(); + 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 diff --git a/src/frontends/qt2/QLImage.h b/src/frontends/qt2/QLImage.h index 581a8bf424..d3f35e567d 100644 --- a/src/frontends/qt2/QLImage.h +++ b/src/frontends/qt2/QLImage.h @@ -16,7 +16,7 @@ #include "graphics/GraphicsImage.h" -#include +#include 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 diff --git a/src/frontends/qt2/QLPainter.C b/src/frontends/qt2/QLPainter.C index f72ab542b5..7d9a7d7f54 100644 --- a/src/frontends/qt2/QLPainter.C +++ b/src/frontends/qt2/QLPainter.C @@ -170,7 +170,7 @@ void QLPainter::image(int x, int y, int w, int h, static_cast(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); }