Merge pull request #4172 from huffman/fix-image-overlay-rescale

Fix image overlay rescale
This commit is contained in:
Andrew Meadows 2015-01-27 13:07:15 -08:00
commit e2ffe00c38
3 changed files with 22 additions and 4 deletions

View file

@ -92,7 +92,13 @@ void ImageOverlay::render(RenderArgs* args) {
QRect fromImage;
if (_wantClipFromImage) {
fromImage = _fromImage;
float scaleX = imageWidth / _texture->getOriginalWidth();
float scaleY = imageHeight / _texture->getOriginalHeight();
fromImage.setX(scaleX * _fromImage.x());
fromImage.setY(scaleY * _fromImage.y());
fromImage.setWidth(scaleX * _fromImage.width());
fromImage.setHeight(scaleY * _fromImage.height());
} else {
fromImage.setX(0);
fromImage.setY(0);

View file

@ -459,6 +459,9 @@ void ImageReader::run() {
_reply->deleteLater();
}
QImage image = QImage::fromData(_content);
int originalWidth = image.width();
int originalHeight = image.height();
// enforce a fixed maximum
const int MAXIMUM_SIZE = 1024;
@ -519,7 +522,8 @@ void ImageReader::run() {
}
QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),
Q_ARG(bool, translucentPixels >= imageArea / 2), Q_ARG(const QColor&, QColor(redTotal / imageArea,
greenTotal / imageArea, blueTotal / imageArea, alphaTotal / imageArea)));
greenTotal / imageArea, blueTotal / imageArea, alphaTotal / imageArea)),
Q_ARG(int, originalWidth), Q_ARG(int, originalHeight));
}
void NetworkTexture::downloadFinished(QNetworkReply* reply) {
@ -531,9 +535,12 @@ void NetworkTexture::loadContent(const QByteArray& content) {
QThreadPool::globalInstance()->start(new ImageReader(_self, NULL, _url, content));
}
void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor) {
void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor, int originalWidth,
int originalHeight) {
_translucent = translucent;
_averageColor = averageColor;
_originalWidth = originalWidth;
_originalHeight = originalHeight;
_width = image.width();
_height = image.height();

View file

@ -150,6 +150,8 @@ public:
/// Returns the lazily-computed average texture color.
const QColor& getAverageColor() const { return _averageColor; }
int getOriginalWidth() const { return _originalWidth; }
int getOriginalHeight() const { return _originalHeight; }
int getWidth() const { return _width; }
int getHeight() const { return _height; }
@ -158,7 +160,8 @@ protected:
virtual void downloadFinished(QNetworkReply* reply);
Q_INVOKABLE void loadContent(const QByteArray& content);
Q_INVOKABLE void setImage(const QImage& image, bool translucent, const QColor& averageColor);
Q_INVOKABLE void setImage(const QImage& image, bool translucent, const QColor& averageColor, int originalWidth,
int originalHeight);
virtual void imageLoaded(const QImage& image);
@ -166,6 +169,8 @@ private:
TextureType _type;
bool _translucent;
QColor _averageColor;
int _originalWidth;
int _originalHeight;
int _width;
int _height;
};