13#include <QLoggingCategory>
15Q_DECLARE_LOGGING_CATEGORY(LOG_PXRPLUGIN)
16Q_LOGGING_CATEGORY(LOG_PXRPLUGIN,
"kf.imageformats.plugins.pxr", QtWarningMsg)
23 quint16 ui16(quint8 c1, quint8 c2)
const {
24 return (quint16(c2) << 8) | quint16(c1);
27 quint32 ui32(quint8 c1, quint8 c2, quint8 c3, quint8 c4)
const {
28 return (quint32(c4) << 24) | (quint32(c3) << 16) | (quint32(c2) << 8) | quint32(c1);
39 return (m_rawHeader.
size() == 512 &&
43 bool isSupported()
const
53 return qint32(ui16(m_rawHeader.
at(418), m_rawHeader.
at(419)));
61 return qint32(ui16(m_rawHeader.
at(416), m_rawHeader.
at(417)));
66 return QSize(width(), height());
69 qint32 channel()
const
74 return qint32(ui16(m_rawHeader.
at(424), m_rawHeader.
at(425)));
82 return qint32(ui16(m_rawHeader.
at(426), m_rawHeader.
at(427)));
91 return qint32(ui16(m_rawHeader.
at(428), m_rawHeader.
at(429)));
96 if (channel() == 14 && depth() == 2) {
99 if (channel() == 8 && depth() == 2) {
105 qsizetype strideSize()
const
118 m_rawHeader = d->
read(512);
124 m_rawHeader = d->
peek(512);
131 if (
auto sz = std::max(offset() - qint32(m_rawHeader.
size()), 0)) {
136 return d->
seek(offset());
140class PXRHandlerPrivate
143 PXRHandlerPrivate() {}
144 ~PXRHandlerPrivate() {}
149PXRHandler::PXRHandler()
151 , d(new PXRHandlerPrivate)
155bool PXRHandler::canRead()
const
157 if (canRead(device())) {
164bool PXRHandler::canRead(
QIODevice *device)
167 qCWarning(LOG_PXRPLUGIN) <<
"PXRHandler::canRead() called with no device";
172 if (!h.peek(device)) {
176 return h.isSupported();
179bool PXRHandler::read(
QImage *image)
181 auto&& header = d->m_header;
183 if (!header.read(device())) {
184 qCWarning(LOG_PXRPLUGIN) <<
"PXRHandler::read() invalid header";
188 auto img = imageAlloc(header.size(), header.format());
190 qCWarning(LOG_PXRPLUGIN) <<
"PXRHandler::read() error while allocating the image";
195 if (!header.jumpToImageData(d)) {
196 qCWarning(LOG_PXRPLUGIN) <<
"PXRHandler::read() error while seeking image data";
200 auto size = std::min(img.bytesPerLine(), header.strideSize());
201 for (
auto y = 0, h = img.height(); y < h; ++y) {
202 auto line =
reinterpret_cast<char*
>(img.scanLine(y));
203 if (d->
read(line, size) != size) {
204 qCWarning(LOG_PXRPLUGIN) <<
"PXRHandler::read() error while reading image scanline";
213bool PXRHandler::supportsOption(ImageOption option)
const
224QVariant PXRHandler::option(ImageOption option)
const
229 auto&& h = d->m_header;
232 }
else if (
auto d = device()) {
240 auto&& h = d->m_header;
243 }
else if (
auto d = device()) {
255 if (format ==
"pxr") {
266 if (device->
isReadable() && PXRHandler::canRead(device)) {
280#include "moc_pxr_p.cpp"
QFlags< Capability > Capabilities
char at(qsizetype i) const const
QByteArray fromRawData(const char *data, qsizetype size)
bool isEmpty() const const
qsizetype size() const const
bool startsWith(QByteArrayView bv) const const
void setDevice(QIODevice *device)
bool isOpen() const const
bool isReadable() const const
virtual bool isSequential() const const
QByteArray peek(qint64 maxSize)
QByteArray read(qint64 maxSize)
virtual bool seek(qint64 pos)
QVariant fromValue(T &&value)