mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-07-22 04:54:19 -04:00
Re-added DDS plugin support
Fork of [Qt 5.6 DDS plugin](https://code.qt.io/cgit/qt/qtimageformats.git/tree/src/plugins/imageformats/dds/qddshandler.cpp?h=5.6) under LGPL2.1. - Merged all files in dds_p.h and dds.cpp - Added support for Qt 6 image allocation limit - Added checks for null image and datastream errors - The plugin is disabled by default CCBUG: 380956 Closes: #12
This commit is contained in:
@ -31,6 +31,12 @@ endif()
|
||||
|
||||
##################################
|
||||
|
||||
if(KIMAGEFORMATS_DDS)
|
||||
kimageformats_add_plugin(kimg_dds SOURCES dds.cpp)
|
||||
endif()
|
||||
|
||||
##################################
|
||||
|
||||
if (BUILD_EPS_PLUGIN)
|
||||
if (TARGET Qt6::PrintSupport)
|
||||
kimageformats_add_plugin(kimg_eps SOURCES eps.cpp)
|
||||
|
1933
src/imageformats/dds.cpp
Normal file
1933
src/imageformats/dds.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4
src/imageformats/dds.json
Normal file
4
src/imageformats/dds.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Keys": [ "dds" ],
|
||||
"MimeTypes": [ "image/x-dds" ]
|
||||
}
|
143
src/imageformats/dds_p.h
Normal file
143
src/imageformats/dds_p.h
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
This file is part of the KDE project
|
||||
SPDX-FileCopyrightText: 2015 The Qt Company Ltd
|
||||
SPDX-FileCopyrightText: 2013 Ivan Komissarov
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
|
||||
*/
|
||||
|
||||
#ifndef QDDSHANDLER_H
|
||||
#define QDDSHANDLER_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
|
||||
struct DDSPixelFormat
|
||||
{
|
||||
enum DDSPixelFormatFlags {
|
||||
FlagAlphaPixels = 0x00000001,
|
||||
FlagAlpha = 0x00000002,
|
||||
FlagFourCC = 0x00000004,
|
||||
FlagPaletteIndexed4 = 0x00000008,
|
||||
FlagPaletteIndexed8 = 0x00000020,
|
||||
FlagRGB = 0x00000040,
|
||||
FlagYUV = 0x00000200,
|
||||
FlagLuminance = 0x00020000,
|
||||
FlagNormal = 0x00080000,
|
||||
FlagRGBA = FlagAlphaPixels | FlagRGB,
|
||||
FlagLA = FlagAlphaPixels | FlagLuminance
|
||||
};
|
||||
|
||||
quint32 size;
|
||||
quint32 flags;
|
||||
quint32 fourCC;
|
||||
quint32 rgbBitCount;
|
||||
quint32 rBitMask;
|
||||
quint32 gBitMask;
|
||||
quint32 bBitMask;
|
||||
quint32 aBitMask;
|
||||
};
|
||||
|
||||
struct DDSHeader
|
||||
{
|
||||
enum DDSFlags {
|
||||
FlagCaps = 0x000001,
|
||||
FlagHeight = 0x000002,
|
||||
FlagWidth = 0x000004,
|
||||
FlagPitch = 0x000008,
|
||||
FlagPixelFormat = 0x001000,
|
||||
FlagMipmapCount = 0x020000,
|
||||
FlagLinearSize = 0x080000,
|
||||
FlagDepth = 0x800000
|
||||
};
|
||||
|
||||
enum DDSCapsFlags {
|
||||
CapsComplex = 0x000008,
|
||||
CapsTexture = 0x001000,
|
||||
CapsMipmap = 0x400000
|
||||
};
|
||||
|
||||
enum DDSCaps2Flags {
|
||||
Caps2CubeMap = 0x0200,
|
||||
Caps2CubeMapPositiveX = 0x0400,
|
||||
Caps2CubeMapNegativeX = 0x0800,
|
||||
Caps2CubeMapPositiveY = 0x1000,
|
||||
Caps2CubeMapNegativeY = 0x2000,
|
||||
Caps2CubeMapPositiveZ = 0x4000,
|
||||
Caps2CubeMapNegativeZ = 0x8000,
|
||||
Caps2Volume = 0x200000
|
||||
};
|
||||
|
||||
enum { ReservedCount = 11 };
|
||||
|
||||
quint32 magic;
|
||||
quint32 size;
|
||||
quint32 flags;
|
||||
quint32 height;
|
||||
quint32 width;
|
||||
quint32 pitchOrLinearSize;
|
||||
quint32 depth;
|
||||
quint32 mipMapCount;
|
||||
quint32 reserved1[ReservedCount];
|
||||
DDSPixelFormat pixelFormat;
|
||||
quint32 caps;
|
||||
quint32 caps2;
|
||||
quint32 caps3;
|
||||
quint32 caps4;
|
||||
quint32 reserved2;
|
||||
};
|
||||
|
||||
struct DDSHeaderDX10
|
||||
{
|
||||
quint32 dxgiFormat;
|
||||
quint32 resourceDimension;
|
||||
quint32 miscFlag;
|
||||
quint32 arraySize;
|
||||
quint32 reserved;
|
||||
};
|
||||
|
||||
class QDDSHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
QDDSHandler();
|
||||
|
||||
bool canRead() const override;
|
||||
bool read(QImage *image) override;
|
||||
bool write(const QImage &image) override;
|
||||
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
void setOption(ImageOption option, const QVariant &value) override;
|
||||
bool supportsOption(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
int imageCount() const override;
|
||||
bool jumpToImage(int imageNumber) override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
bool ensureScanned() const;
|
||||
bool verifyHeader(const DDSHeader &dds) const;
|
||||
|
||||
private:
|
||||
enum ScanState {
|
||||
ScanError = -1,
|
||||
ScanNotScanned = 0,
|
||||
ScanSuccess = 1,
|
||||
};
|
||||
|
||||
DDSHeader m_header;
|
||||
int m_format;
|
||||
DDSHeaderDX10 m_header10;
|
||||
int m_currentImage;
|
||||
mutable ScanState m_scanState;
|
||||
};
|
||||
|
||||
class QDDSPlugin : public QImageIOPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "dds.json")
|
||||
public:
|
||||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
|
||||
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
|
||||
};
|
||||
|
||||
#endif // QDDSHANDLER_H
|
Reference in New Issue
Block a user