4#include <QGuiApplication>
6#include <QImageIOHandler>
34 if (!dev ||
count <= 0)
40 res = dev->
pos() - prevPos;
66 QImageIOPlugin::Capabilities
res;
69 QCFType<CFArrayRef> cfSourceTypes = CGImageSourceCopyTypeIdentifiers();
70 CFIndex
len = CFArrayGetCount(cfSourceTypes);
71 if (CFArrayContainsValue(cfSourceTypes, CFRangeMake(0,
len), cfUti))
74 QCFType<CFArrayRef> cfDestTypes = CGImageDestinationCopyTypeIdentifiers();
75 len = CFArrayGetCount(cfDestTypes);
76 if (CFArrayContainsValue(cfDestTypes, CFRangeMake(0,
len), cfUti))
85 return h.readImage(
out);
91 return h.writeImage(
in, uti);
110 const void *rawData =
b->data().constData() +
b->pos();
111 cgDataProvider = CGDataProviderCreateWithData(
nullptr, rawData,
size_t(
b->data().size() -
b->pos()),
nullptr);
129 QCFType<CGImageRef> cgImage = CGImageSourceCreateImageAtIndex(
cgImageSource, 0,
nullptr);
139 out->setDotsPerMeterX(
qRound(dpi / 0.0254f));
141 out->setDotsPerMeterY(
qRound(dpi / 0.0254f));
151 CFNumberRef cfNumber =
static_cast<CFNumberRef
>(CFDictionaryGetValue(
cfImageDict,
property));
154 if (CFNumberGetValue(cfNumber, kCFNumberIntType, &intVal)) {
163static QImageIOHandler::Transformations
exif2Qt(
int exifOrientation)
165 switch (exifOrientation) {
186static int qt2Exif(QImageIOHandler::Transformations transformation)
188 switch (transformation) {
206 qWarning(
"Invalid Qt image transformation");
246 static const CGDataConsumerCallbacks cgCallbacks = { &
cbPutBytes,
nullptr };
252 QCFType<CGDataConsumerRef> cgDataConsumer = CGDataConsumerCreate(
q_ptr->
device(), &cgCallbacks);
253 QCFType<CFStringRef> cfUti = uti.toCFString();
254 QCFType<CGImageDestinationRef> cgImageDest = CGImageDestinationCreateWithDataConsumer(cgDataConsumer, cfUti, 1,
nullptr);
255 if (!cgImageDest || !cgImage)
258 QCFType<CFNumberRef> cfQuality =
nullptr;
259 QCFType<CFNumberRef> cfOrientation =
nullptr;
260 const void *dictKeys[2];
261 const void *dictVals[2];
268 float quality = (
ok && writeQuality >= 0 ? (
qMin(writeQuality, 100)) : 75) / 100.0f;
269 cfQuality = CFNumberCreate(
nullptr, kCFNumberFloatType, &quality);
270 dictKeys[dictSize] =
static_cast<const void *
>(kCGImageDestinationLossyCompressionQuality);
271 dictVals[dictSize] =
static_cast<const void *
>(cfQuality);
276 cfOrientation = CFNumberCreate(
nullptr, kCFNumberIntType, &orient);
277 dictKeys[dictSize] =
static_cast<const void *
>(kCGImagePropertyOrientation);
278 dictVals[dictSize] =
static_cast<const void *
>(cfOrientation);
282 QCFType<CFDictionaryRef> cfProps =
nullptr;
284 cfProps = CFDictionaryCreate(
nullptr, dictKeys, dictVals, dictSize,
285 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
287 CGImageDestinationAddImage(cgImageDest, cgImage, cfProps);
288 return CGImageDestinationFinalize(cgImageDest);
void setOption(QImageIOHandler::ImageOption option, const QVariant &value)
QList< QVariant > writeOptions
QCFType< CGImageSourceRef > cgImageSource
bool writeImage(const QImage &in, const QString &uti)
QIIOFHelper(QImageIOHandler *q)
QCFType< CGDataProviderRef > cgDataProvider
bool readImage(QImage *out)
bool getIntProperty(CFStringRef property, int *value)
QVariant imageProperty(QImageIOHandler::ImageOption option)
QCFType< CFDictionaryRef > cfImageDict
static bool writeImage(QImageIOHandler *q_ptr, const QImage &in, const QString &uti)
static QImageIOPlugin::Capabilities systemCapabilities(const QString &uti)
static bool readImage(QImageIOHandler *q_ptr, QImage *out)
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
ImageOption
This enum describes the different options supported by QImageIOHandler.
virtual bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
@ TransformationRotate270
@ TransformationFlipAndRotate90
@ TransformationMirrorAndRotate90
@ TransformationRotate180
qsizetype size() const noexcept
T value(qsizetype i) const
void resize(qsizetype size)
constexpr int & rheight() noexcept
Returns a reference to the height.
constexpr int & rwidth() noexcept
Returns a reference to the width.
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
static size_t cbPutBytes(void *info, const void *buffer, size_t count)
static size_t cbGetBytes(void *info, void *buffer, size_t count)
static void cbRewind(void *)
static int qt2Exif(QImageIOHandler::Transformations transformation)
static off_t cbSkipForward(void *info, off_t count)
static QImageIOHandler::Transformations exif2Qt(int exifOrientation)
Combined button and popup list for selecting options.
QImage qt_mac_toQImage(CGImageRef image)
CGImageRef qt_mac_toCGImage(const QImage &inImage)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
QImage qt_mac_toQImage(CGImageRef image)
QT_BEGIN_NAMESPACE CGImageRef qt_mac_toCGImage(const QImage &qImage)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLenum GLenum GLsizei count
GLenum GLuint GLenum GLsizei const GLchar * buf
GLfloat GLfloat GLfloat GLfloat h
GLdouble GLdouble GLdouble GLdouble q
unsigned long long quint64
QTextStream out(stdout)
[7]