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
382382 qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height();
383383 image = image.scaled(MAXIMUM_SIZE, MAXIMUM_SIZE, Qt::KeepAspectRatio);
384384 }
385+ int imageArea = image.width() * image.height();
385386
387+ const int EIGHT_BIT_MAXIMUM = 255;
386388 if (!image.hasAlphaChannel()) {
387389 if (image.format() != QImage::Format_RGB888) {
388390 image = image.convertToFormat(QImage::Format_RGB888);
389391 }
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)));
391403 return;
392404 }
393405 if (image.format() != QImage::Format_ARGB32) {
@@ -397,11 +409,15 @@ void ImageReader::run() { · 3 unmodified lines
397409 // check for translucency/false transparency
398410 int opaquePixels = 0;
399411 int translucentPixels = 0;
400− const int EIGHT_BIT_MAXIMUM = 255;
401− const int RGB_BITS = 24;
412+ int redTotal = 0, greenTotal = 0, blueTotal = 0, alphaTotal = 0;
402413 for (int y = 0; y < image.height(); y++) {
403414 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;
405421 if (alpha == EIGHT_BIT_MAXIMUM) {
406422 opaquePixels++;
407423 } else if (alpha != 0) {
@@ -409,13 +425,13 @@ void ImageReader::run() { · 1 unmodified line
409425 }
410426 }
411427 }
412− int imageArea = image.width() * image.height();
413428 if (opaquePixels == imageArea) {
414429 qDebug() << "Image with alpha channel is completely opaque:" << _url;
415430 image = image.convertToFormat(QImage::Format_RGB888);
416431 }
417432 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)));
419435 }
420436
421437 void NetworkTexture::downloadFinished(QNetworkReply* reply) {
@@ -427,8 +443,9 @@ void NetworkTexture::loadContent(const QByteArray& content) { · 5 unmodified lines
427443 QThreadPool::globalInstance()->start(new ImageReader(_self, NULL, _url, content));
428444 }
429445
430−void NetworkTexture::setImage(const QImage& image, bool translucent) {
446+void NetworkTexture::setImage(const QImage& image, bool translucent, const QColor& averageColor) {
431447 _translucent = translucent;
448+ _averageColor = averageColor;
432449
433450 finishedLoading(true);
434451 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