Showing the changes to interface/src/renderer/TextureCache.cpp (1 of 5 files). Show all
Unified · Split
| @@ -273,27 +273,28 @@ NetworkTexture::NetworkTexture(const QUrl& url, bool normalMap) : · 272 unmodified lines | |||
| 273 | class ImageReader : public QRunnable { | 273 | class ImageReader : public QRunnable { |
| 274 | public: | 274 | public: |
| 275 | 275 | ||
| 276 | ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data); | 276 | ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply); |
| 277 | 277 | ||
| 278 | virtual void run(); | 278 | virtual void run(); |
| 279 | 279 | ||
| 280 | private: | 280 | private: |
| 281 | 281 | ||
| 282 | QWeakPointer<Resource> _texture; | 282 | QWeakPointer<Resource> _texture; |
| 283 | QByteArray _data; | 283 | QNetworkReply* _reply; |
| 284 | }; | 284 | }; |
| 285 | 285 | ||
| 286 | ImageReader::ImageReader(const QWeakPointer<Resource>& texture, const QByteArray& data) : | 286 | ImageReader::ImageReader(const QWeakPointer<Resource>& texture, QNetworkReply* reply) : |
| 287 | _texture(texture), | 287 | _texture(texture), |
| 288 | _data(data) { | 288 | _reply(reply) { |
| 289 | } | 289 | } |
| 290 | 290 | ||
| 291 | void ImageReader::run() { | 291 | void ImageReader::run() { |
| 292 | QSharedPointer<Resource> texture = _texture.toStrongRef(); | 292 | QSharedPointer<Resource> texture = _texture.toStrongRef(); |
| 293 | if (texture.isNull()) { | 293 | if (texture.isNull()) { |
| 294 | _reply->deleteLater(); | ||
| 294 | return; | 295 | return; |
| 295 | } | 296 | } |
| 296 | QImage image = QImage::fromData(_data); | 297 | QImage image = QImage::fromData(_reply->readAll()); |
| 297 | if (image.format() != QImage::Format_ARGB32) { | 298 | if (image.format() != QImage::Format_ARGB32) { |
| 298 | image = image.convertToFormat(QImage::Format_ARGB32); | 299 | image = image.convertToFormat(QImage::Format_ARGB32); |
| 299 | } | 300 | } |
| @@ -320,11 +321,12 @@ void ImageReader::run() { · 20 unmodified lines | |||
| 320 | QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image), | 321 | QMetaObject::invokeMethod(texture.data(), "setImage", Q_ARG(const QImage&, image), |
| 321 | Q_ARG(const glm::vec4&, accumulated / (imageArea * EIGHT_BIT_MAXIMUM)), | 322 | Q_ARG(const glm::vec4&, accumulated / (imageArea * EIGHT_BIT_MAXIMUM)), |
| 322 | Q_ARG(bool, translucentPixels >= imageArea / 2)); | 323 | Q_ARG(bool, translucentPixels >= imageArea / 2)); |
| 324 | _reply->deleteLater(); | ||
| 323 | } | 325 | } |
| 324 | 326 | ||
| 325 | void NetworkTexture::downloadFinished(QNetworkReply* reply) { | 327 | void NetworkTexture::downloadFinished(QNetworkReply* reply) { |
| 326 | // send the reader off to the thread pool | 328 | // send the reader off to the thread pool |
| 327 | QThreadPool::globalInstance()->start(new ImageReader(_self, reply->readAll())); | 329 | QThreadPool::globalInstance()->start(new ImageReader(_self, reply)); |
| 328 | } | 330 | } |
| 329 | 331 | ||
| 330 | void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) { | 332 | void NetworkTexture::setImage(const QImage& image, const glm::vec4& averageColor, bool translucent) { |