From a4c82072a2f4b8247491c42c9dc2b8c93c4d5244 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 30 Jan 2015 02:00:35 +0100 Subject: [PATCH 1/2] changing texture size limit from 1024*1024 to 2M i.e. (1024 * 2048). It's dynamic and resizes the texture to the best fit within the 2M area. --- libraries/render-utils/src/TextureCache.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 3644ded81c..a0c47585c7 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -458,13 +458,18 @@ void ImageReader::run() { int originalWidth = image.width(); int originalHeight = image.height(); - // enforce a fixed maximum - const int MAXIMUM_SIZE = 1024; - if (image.width() > MAXIMUM_SIZE || image.height() > MAXIMUM_SIZE) { - qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height(); - image = image.scaled(MAXIMUM_SIZE, MAXIMUM_SIZE, Qt::KeepAspectRatio); - } + // enforce a fixed maximum area (1024 * 2048) + const float MAXIMUM_AREA_SIZE = 2097152.0f; int imageArea = image.width() * image.height(); + if (imageArea > MAXIMUM_AREA_SIZE) { + float scaleRatio = sqrtf(MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); + int resizeWidth = static_cast(std::floor(scaleRatio * static_cast(image.width()))); + int resizeHeight = static_cast(std::floor(scaleRatio * static_cast(image.height()))); + qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height() << + " scaled to :" << resizeWidth << resizeHeight; + image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio); + imageArea = image.width() * image.height(); + } const int EIGHT_BIT_MAXIMUM = 255; if (!image.hasAlphaChannel()) { From ff29b1c8cc3954108edc7085a2afba3c9b74c420 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 30 Jan 2015 02:18:51 +0100 Subject: [PATCH 2/2] style/conversion fixes --- libraries/render-utils/src/TextureCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index a0c47585c7..a97b3f599a 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -459,14 +459,14 @@ void ImageReader::run() { int originalHeight = image.height(); // enforce a fixed maximum area (1024 * 2048) - const float MAXIMUM_AREA_SIZE = 2097152.0f; + const int MAXIMUM_AREA_SIZE = 2097152; int imageArea = image.width() * image.height(); if (imageArea > MAXIMUM_AREA_SIZE) { - float scaleRatio = sqrtf(MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); + float scaleRatio = sqrtf((float)MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); int resizeWidth = static_cast(std::floor(scaleRatio * static_cast(image.width()))); int resizeHeight = static_cast(std::floor(scaleRatio * static_cast(image.height()))); qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height() << - " scaled to :" << resizeWidth << resizeHeight; + " scaled to:" << resizeWidth << resizeHeight; image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio); imageArea = image.width() * image.height(); }