6#include "iohandlerfactory.h"
10#include <lcms2_plugin.h>
16#include <qstringliteral.h>
18#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
19#include <qiodevicebase.h>
35cmsUInt32Number IOHandlerFactory::read(cmsIOHANDLER *iohandler,
void *Buffer, cmsUInt32Number size, cmsUInt32Number count)
37 QFile *
const myFile =
static_cast<QFile *
>(iohandler->stream);
38 const cmsUInt32Number numberOfBytesRequested = size * count;
39 const qint64 numberOfBytesRead = myFile->
read(
40 static_cast<char *
>(Buffer),
42 if (numberOfBytesRead != numberOfBytesRequested) {
56cmsBool IOHandlerFactory::seek(cmsIOHANDLER *iohandler, cmsUInt32Number offset)
58 QFile *
const myFile =
static_cast<QFile *
>(iohandler->stream);
59 const bool seekSucceeded = myFile->
seek(offset);
61 qDebug() << QStringLiteral(
"Seek error; probably corrupted file");
72cmsUInt32Number IOHandlerFactory::tell(cmsIOHANDLER *iohandler)
74 const QFile *
const myFile =
static_cast<QFile *
>(iohandler->stream);
75 return static_cast<cmsUInt32Number
>(myFile->
pos());
91cmsBool IOHandlerFactory::write(cmsIOHANDLER *iohandler, cmsUInt32Number size,
const void *Buffer)
104cmsBool IOHandlerFactory::close(cmsIOHANDLER *iohandler)
106 QFile *
const myFile =
static_cast<QFile *
>(iohandler->stream);
108 iohandler->stream =
nullptr;
109 _cmsFree(iohandler->ContextID, iohandler);
132cmsIOHANDLER *IOHandlerFactory::createReadOnly(cmsContext ContextID,
const QString &fileName)
134 cmsIOHANDLER *
const result =
static_cast<cmsIOHANDLER *
>(
135 _cmsMallocZero(ContextID,
sizeof(cmsIOHANDLER))
137 if (result ==
nullptr) {
141 QFile *
const fileObject =
new QFile(fileName);
142 if (fileObject ==
nullptr) {
147 const qint64 fileSize = fileObject->
size();
150 const bool isFileSizeOkay = PerceptualColor::isInRange<qint64>(
153 std::numeric_limits<cmsInt32Number>::max());
154 if ((!openSucceeded) || (!isFileSizeOkay)) {
156 _cmsFree(ContextID, result);
161 result->ContextID = ContextID;
164 result->ReportedSize =
static_cast<cmsUInt32Number
>(fileSize);
165 result->stream =
static_cast<void *
>(fileObject);
166 result->UsedSpace = 0;
167 result->PhysicalFile[0] = 0;
172 result->Close = close;
174 result->Write = write;
The namespace of this library.
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
virtual qint64 size() const const override
virtual qint64 pos() const const override
virtual bool seek(qint64 pos) override
QByteArray read(qint64 maxSize)