History

Get rid of unused, expensive "average color" nonsense.

Andrzej Kapolka committed 12 years ago

Commit bc3bba91 parent 35d0fa76 files · +5 −52Browse files

Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 6 files). Show all

Unified · Split

interface/src/renderer/TextureCache.cpp+4−13
@@ -257,7 +257,6 @@ Texture::~Texture() { · 256 unmodified lines
257 257
258NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) :258NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) :
259 Resource(url),259 Resource(url),
260 _averageColor(1.0f, 1.0f, 1.0f, 1.0f),
261 _translucent(false) {260 _translucent(false) {
262 261
263 if (!url.isValid()) {262 if (!url.isValid()) {
@@ -300,27 +299,20 @@ void ImageReader::run() { · 36 unmodified lines
300 image = image.convertToFormat(QImage::Format_ARGB32);299 image = image.convertToFormat(QImage::Format_ARGB32);
301 }300 }
302 301
303 // sum up the colors for the average and check for translucency302 // check for translucency
304 glm::vec4 accumulated;
305 int translucentPixels = 0;303 int translucentPixels = 0;
306 const int EIGHT_BIT_MAXIMUM = 255;304 const int EIGHT_BIT_MAXIMUM = 255;
305 const int RGB_BITS = 24;
307 for (int y = 0; y < image.height(); y++) {306 for (int y = 0; y < image.height(); y++) {
308 for (int x = 0; x < image.width(); x++) {307 for (int x = 0; x < image.width(); x++) {
309 QRgb pixel = image.pixel(x, y);308 int alpha = image.pixel(x, y) >> RGB_BITS;
310 accumulated.r += qRed(pixel);
311 accumulated.g += qGreen(pixel);
312 accumulated.b += qBlue(pixel);
313
314 int alpha = qAlpha(pixel);
315 if (alpha != 0 && alpha != EIGHT_BIT_MAXIMUM) {309 if (alpha != 0 && alpha != EIGHT_BIT_MAXIMUM) {
316 translucentPixels++;310 translucentPixels++;
317 }311 }
318 accumulated.a += alpha;
319 }312 }
320 }313 }
321 int imageArea = image.width() * image.height();314 int imageArea = image.width() * image.height();
322 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),315 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),
323 Q_ARG(const glm::vec4&, accumulated / (float) (imageArea * EIGHT_BIT_MAXIMUM)),
324 Q_ARG(bool, translucentPixels >= imageArea / 2));316 Q_ARG(bool, translucentPixels >= imageArea / 2));
325 _reply->deleteLater();317 _reply->deleteLater();
326}318}
@@ -330,8 +322,7 @@ void NetworkTexture::downloadFinished(QNetworkReply* reply) { · 3 unmodified lines
330 QThreadPool::globalInstance()->start(new ImageReader(_self, reply));322 QThreadPool::globalInstance()->start(new ImageReader(_self, reply));
331}323}
332 324
333void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) {325void NetworkTexture::setImage(const QImage& image, bool translucent) {
334 _averageColor = averageColor;
335 _translucent = translucent;326 _translucent = translucent;
336 327
337 finishedLoading(true);328 finishedLoading(true);