From 1f6932bdcbec165cb5a89fa72ef5a1770b61eeed Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 27 Jan 2015 08:09:20 -0800 Subject: [PATCH 1/4] Update TextureCache to store original image dimensions (pre-scale) --- libraries/render-utils/src/TextureCache.cpp | 10 ++++++++-- libraries/render-utils/src/TextureCache.h | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 4c9abc74a1..58032a0916 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -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,11 @@ 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(); diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index efcccc4b8c..6d115223a2 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -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,7 @@ 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 +168,8 @@ private: TextureType _type; bool _translucent; QColor _averageColor; + int _originalWidth; + int _originalHeight; int _width; int _height; }; From d27a26967fd53c00e405a3a9b20a4785c0d4c206 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 27 Jan 2015 08:09:47 -0800 Subject: [PATCH 2/4] Update ImageOverlay to take texture rescaling into account --- interface/src/ui/overlays/ImageOverlay.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index e18f99072f..519e0c603d 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -93,6 +93,14 @@ void ImageOverlay::render(RenderArgs* args) { QRect fromImage; if (_wantClipFromImage) { fromImage = _fromImage; + float originalWidth = _texture->getOriginalWidth(); + float originalHeight = _texture->getOriginalHeight(); + float scaleX = imageWidth / originalWidth; + float scaleY = imageHeight / originalHeight; + 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); From 6a9f135e1c5b743285aca48e5ffe69aba1428f7d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 27 Jan 2015 08:11:37 -0800 Subject: [PATCH 3/4] Cleanup image clipping in ImageOverlay --- interface/src/ui/overlays/ImageOverlay.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 519e0c603d..0c5d9a7737 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -92,11 +92,9 @@ void ImageOverlay::render(RenderArgs* args) { QRect fromImage; if (_wantClipFromImage) { - fromImage = _fromImage; - float originalWidth = _texture->getOriginalWidth(); - float originalHeight = _texture->getOriginalHeight(); - float scaleX = imageWidth / originalWidth; - float scaleY = imageHeight / originalHeight; + 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()); From 9fd352e1dcf2cdc9137e99aafd42918e6c0f5e49 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 27 Jan 2015 10:27:05 -0800 Subject: [PATCH 4/4] Break long lines in TextureCache.h/cpp --- libraries/render-utils/src/TextureCache.cpp | 3 ++- libraries/render-utils/src/TextureCache.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 58032a0916..372b4732f5 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -535,7 +535,8 @@ 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, int originalWidth, int originalHeight) { +void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor, int originalWidth, + int originalHeight) { _translucent = translucent; _averageColor = averageColor; _originalWidth = originalWidth; diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index 6d115223a2..c4264b95f6 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -160,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, int originalWidth, int originalHeight); + Q_INVOKABLE void setImage(const QImage& image, bool translucent, const QColor& averageColor, int originalWidth, + int originalHeight); virtual void imageLoaded(const QImage& image);