From 162a859045ec455321909af6aa03b99d9cbbda6e Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Tue, 22 Dec 2020 13:52:29 +0100 Subject: Add getDataView() method to QTextureFileData This method will return a QByteArrayView of the data range corresponding to the level. This avoids a leaky abstraction by moving the needed data pointer arithmetic from the caller to the method. It will also make it easier adding cubemap support in the future. Change-Id: I2415bd88365d8d69ba14aefc77f5f1117f9e0033 Reviewed-by: Eirik Aavitsland --- src/gui/util/qtexturefiledata.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/gui/util/qtexturefiledata.cpp') diff --git a/src/gui/util/qtexturefiledata.cpp b/src/gui/util/qtexturefiledata.cpp index d271541e51..29c6acaeca 100644 --- a/src/gui/util/qtexturefiledata.cpp +++ b/src/gui/util/qtexturefiledata.cpp @@ -167,6 +167,17 @@ int QTextureFileData::dataLength(int level) const return (d && d->lengths.size() > level) ? d->lengths.at(level) : 0; } +QByteArrayView QTextureFileData::getDataView(int level) const +{ + const int dataLength = this->dataLength(level); + const int dataOffset = this->dataOffset(level); + + if (d == nullptr || dataLength == 0) + return QByteArrayView(); + + return QByteArrayView(d->data.constData() + dataOffset, dataLength); +} + void QTextureFileData::setDataLength(int length, int level) { if (d.constData() && level >= 0) { -- cgit v1.2.3