1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <qimageiohandler.h>
5#include <qstringlist.h>
6
7#ifdef QT_NO_IMAGEFORMAT_JPEG
8#undef QT_NO_IMAGEFORMAT_JPEG
9#endif
10#include <qjpeghandler_p.h>
11
12QT_BEGIN_NAMESPACE
13
14class QJpegPlugin : public QImageIOPlugin
15{
16 Q_OBJECT
17 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "jpeg.json")
18public:
19 Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
20 QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
21};
22
23QImageIOPlugin::Capabilities QJpegPlugin::capabilities(QIODevice *device, const QByteArray &format) const
24{
25 if (format == "jpeg" || format == "jpg")
26 return Capabilities(CanRead | CanWrite);
27 if (!format.isEmpty())
28 return { };
29 if (!device->isOpen())
30 return { };
31
32 Capabilities cap;
33 if (device->isReadable() && QJpegHandler::canRead(device))
34 cap |= CanRead;
35 if (device->isWritable())
36 cap |= CanWrite;
37 return cap;
38}
39
40QImageIOHandler *QJpegPlugin::create(QIODevice *device, const QByteArray &format) const
41{
42 QImageIOHandler *handler = new QJpegHandler;
43 handler->setDevice(device);
44 handler->setFormat(format);
45 return handler;
46}
47
48QT_END_NAMESPACE
49
50#include "main.moc"
51

source code of qtbase/src/plugins/imageformats/jpeg/main.cpp