mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Store and use QImage rather than QPixmap.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8720 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ca9190c9d1
commit
32d281cba0
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user