#include "support/lstrings.h" // ascii_lowercase
#include <QPainter>
-#include <QImage>
#include <QImageReader>
using namespace std;
}
+GuiImage::GuiImage() : is_transformed_(false)
+{}
+
+
GuiImage::GuiImage(GuiImage const & other)
: Image(other), original_(other.original_),
- transformed_(other.transformed_), is_transformed_(other.is_transformed_)
+ transformed_(other.transformed_), is_transformed_(other.is_transformed_),
+ fname_(other.fname_)
{}
}
+QImage const & GuiImage::image() const
+{
+ return is_transformed_ ? transformed_ : original_;
+}
+
+
unsigned int GuiImage::width() const
{
return is_transformed_ ? transformed_.width() : original_.width();
LYXERR(Debug::GRAPHICS, "Image is loaded already!");
return false;
}
-
fname_ = toqstr(filename.absFilename());
+ return load();
+}
+
+bool GuiImage::load()
+{
if (!original_.load(fname_)) {
LYXERR(Debug::GRAPHICS, "Unable to open image");
return false;
}
+ original_.detach();
return true;
}
return false;
if (original_.isNull()) {
- if (!original_.load(fname_))
+ if (!load())
return false;
}
is_transformed_ |= scale(params);
// Clear the pixmap to save some memory.
- if (is_transformed_)
- original_ = QPixmap();
- else
- transformed_ = QPixmap();
+ if (is_transformed_) {
+ original_.detach();
+ original_ = QImage();
+ } else {
+ transformed_.detach();
+ transformed_ = QImage();
+ }
return true;
}
int const new_width = params.bb.xr - params.bb.xl;
int const new_height = params.bb.yt - params.bb.yb;
+ QImage const & image = is_transformed_ ? transformed_ : original_;
+
// No need to check if the width, height are > 0 because the
// Bounding Box would be empty() in this case.
- if (new_width > original_.width() || new_height > original_.height()) {
+ if (new_width > image.width() || new_height > image.height()) {
// Bounds are invalid.
return false;
}
- if (new_width == original_.width() && new_height == original_.height())
+ if (new_width == image.width() && new_height == image.height())
return false;
int const xoffset_l = params.bb.xl;
- int const yoffset_t = (original_.height() > int(params.bb.yt) ?
- original_.height() - params.bb.yt : 0);
+ int const yoffset_t = (image.height() > int(params.bb.yt))
+ ? image.height() - params.bb.yt : 0;
- transformed_ = original_.copy(xoffset_l, yoffset_t,
- new_width, new_height);
+ transformed_ = image.copy(xoffset_l, yoffset_t, new_width, new_height);
return true;
}
if (!params.angle)
return false;
- if (!is_transformed_)
- transformed_ = original_;
-
+ QImage const & image = is_transformed_ ? transformed_ : original_;
QMatrix m;
- m.rotate(-params.angle);
- transformed_ = transformed_.transformed(m);
+ m.rotate(- params.angle);
+ transformed_ = image.transformed(m);
return true;
}
bool GuiImage::scale(Params const & params)
{
- Dimension dim = scaledDimension(params);
+ QImage const & image = is_transformed_ ? transformed_ : original_;
- if (dim.width() == width() && dim.height() == height())
- return false;
+ unsigned int w = image.width();
+ unsigned int h = image.height();
- if (!is_transformed_)
- transformed_ = original_;
+ // scale only when value > 0
+ if (params.scale > 0) {
+ w = (w * params.scale) / 100;
+ h = (h * params.scale) / 100;
+ }
- QMatrix m;
- m.scale(double(dim.width()) / width(), double(dim.height()) / height());
- transformed_ = transformed_.transformed(m);
+ LYXERR(Debug::GRAPHICS, "\n\tparams.scale : " << params.scale
+ << "\n\twidth : " << w
+ << "\n\theight : " << h);
+ if (w == image.width() && h == image.height())
+ return false;
+
+ QMatrix m;
+ m.scale(double(w) / image.width(), double(h) / image.height());
+ transformed_ = image.transformed(m);
return true;
}
#include "graphics/GraphicsImage.h"
-#include <QPixmap>
+#include <QImage>
#include <QString>
namespace lyx {
/// Access to this class is through this static method.
static Image * newImage();
- /// Retrieve the buffered pixmap.
- QPixmap const & pixmap() const
- { return is_transformed_? transformed_ : original_; }
+ /// Retrieve the rendered image.
+ QImage const & image() const;
private:
/// Create a copy
* Load the image file into memory.
*/
bool load(support::FileName const & filename);
+ bool load();
/**
* Finishes the process of modifying transformed_, using
* \c params to decide on color, grayscale etc.
bool scale(Params const & params);
/// Access to the class is through newImage() and clone.
- GuiImage() {}
+ GuiImage();
///
GuiImage(GuiImage const &);
/// The original loaded image.
- QPixmap original_;
+ QImage original_;
/// The transformed image for display.
- QPixmap transformed_;
- /// Buffer the pixmap itself
+ QImage transformed_;
+
+ ///
bool is_transformed_;
///
QString fname_;