History

Working on heightfield textures.

Andrzej Kapolka committed 12 years ago

Commit 5b8ff071 parent c2a5c338 files · +245 −12Browse files

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

Unified · Split

interface/src/renderer/TextureCache.cpp+24−7
@@ -382,12 +382,24 @@ void ImageReader::run() { · 381 unmodified lines
382 qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height();382 qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height();
383 image = image.scaled(MAXIMUM_SIZE, MAXIMUM_SIZE, Qt::KeepAspectRatio);383 image = image.scaled(MAXIMUM_SIZE, MAXIMUM_SIZE, Qt::KeepAspectRatio);
384 }384 }
385 int imageArea = image.width() * image.height();
385 386
387 const int EIGHT_BIT_MAXIMUM = 255;
386 if (!image.hasAlphaChannel()) {388 if (!image.hasAlphaChannel()) {
387 if (image.format() != QImage::Format_RGB888) {389 if (image.format() != QImage::Format_RGB888) {
388 image = image.convertToFormat(QImage::Format_RGB888);390 image = image.convertToFormat(QImage::Format_RGB888);
389 }391 }
390 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image), Q_ARG(bool, false));392 int redTotal = 0, greenTotal = 0, blueTotal = 0;
393 for (int y = 0; y < image.height(); y++) {
394 for (int x = 0; x < image.width(); x++) {
395 QRgb rgb = image.pixel(x, y);
396 redTotal += qRed(rgb);
397 greenTotal += qGreen(rgb);
398 blueTotal += qBlue(rgb);
399 }
400 }
401 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image), Q_ARG(bool, false),
402 Q_ARG(const QColor&, QColor(redTotal / imageArea, greenTotal / imageArea, blueTotal / imageArea)));
391 return;403 return;
392 }404 }
393 if (image.format() != QImage::Format_ARGB32) {405 if (image.format() != QImage::Format_ARGB32) {
@@ -397,11 +409,15 @@ void ImageReader::run() { · 3 unmodified lines
397 // check for translucency/false transparency409 // check for translucency/false transparency
398 int opaquePixels = 0;410 int opaquePixels = 0;
399 int translucentPixels = 0;411 int translucentPixels = 0;
400 const int EIGHT_BIT_MAXIMUM = 255;412 int redTotal = 0, greenTotal = 0, blueTotal = 0, alphaTotal = 0;
401 const int RGB_BITS = 24;
402 for (int y = 0; y < image.height(); y++) {413 for (int y = 0; y < image.height(); y++) {
403 for (int x = 0; x < image.width(); x++) {414 for (int x = 0; x < image.width(); x++) {
404 int alpha = image.pixel(x, y) >> RGB_BITS;415 QRgb rgb = image.pixel(x, y);
416 redTotal += qRed(rgb);
417 greenTotal += qGreen(rgb);
418 blueTotal += qBlue(rgb);
419 int alpha = qAlpha(rgb);
420 alphaTotal += alpha;
405 if (alpha == EIGHT_BIT_MAXIMUM) {421 if (alpha == EIGHT_BIT_MAXIMUM) {
406 opaquePixels++;422 opaquePixels++;
407 } else if (alpha != 0) {423 } else if (alpha != 0) {
@@ -409,13 +425,13 @@ void ImageReader::run() { · 1 unmodified line
409 }425 }
410 }426 }
411 }427 }
412 int imageArea = image.width() * image.height();
413 if (opaquePixels == imageArea) {428 if (opaquePixels == imageArea) {
414 qDebug() << "Image with alpha channel is completely opaque:" << _url;429 qDebug() << "Image with alpha channel is completely opaque:" << _url;
415 image = image.convertToFormat(QImage::Format_RGB888);430 image = image.convertToFormat(QImage::Format_RGB888);
416 }431 }
417 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),432 QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image),
418 Q_ARG(bool, translucentPixels >= imageArea / 2));433 Q_ARG(bool, translucentPixels >= imageArea / 2), Q_ARG(const QColor&, QColor(redTotal / imageArea,
434 greenTotal / imageArea, blueTotal / imageArea, alphaTotal / imageArea)));
419}435}
420 436
421void NetworkTexture::downloadFinished(QNetworkReply* reply) {437void NetworkTexture::downloadFinished(QNetworkReply* reply) {
@@ -427,8 +443,9 @@ void NetworkTexture::loadContent(const QByteArray& content) { · 5 unmodified lines
427 QThreadPool::globalInstance()->start(new ImageReader(_self, NULL, _url, content));443 QThreadPool::globalInstance()->start(new ImageReader(_self, NULL, _url, content));
428}444}
429 445
430void NetworkTexture::setImage(const QImage& image, bool translucent) {446void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor) {
431 _translucent = translucent;447 _translucent = translucent;
448 _averageColor = averageColor;
432 449
433 finishedLoading(true);450 finishedLoading(true);
434 imageLoaded(image);451 imageLoaded(image);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t