7#include <QtCore/qdebug.h>
8#include <QtGui/qimage.h>
16#ifndef QT_NO_DATASTREAM
51static const FaceOffset faceOffsets[6] = { {2, 1}, {0, 1}, {1, 0}, {1, 2}, {1, 1}, {3, 1} };
100 {
FormatL6V5U5, 0, 16, 0x0000001f, 0x000003e0, 0x0000fc00, 0x00000000 },
101 {
FormatX8L8V8U8, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 },
256 for (
unsigned bit = 0; bit <
size; bit += 8) {
276 quint8(
Y - 0.39465 * (U - 128) - 0.58060 * (V - 128)),
277 quint8(
Y + 2.03211 * (U - 128)));
311 const double fx =
nx / 127.5 - 1.0;
312 const double fy =
ny / 127.5 - 1.0;
313 const double fxfy = 1.0 - fx * fx - fy * fy;
314 return fxfy > 0 ? 255 * std::sqrt(fxfy) : 0;
326 return 2.0 * c0 / 3.0 + c1 / 3.0;
331 return c0 / 2.0 + c1 / 2.0;
336 return c0 / 3.0 + 2.0 * c1 / 3.0;
346 a[0] =
a[1] =
a[2] =
a[3] = 255;
361 r[3] =
g[3] =
b[3] =
a[3] = 0;
364 for (
int k = 0; k < 4; k++)
365 for (
int l = 0; l < 4; l++) {
373template <DXTVersions version>
377 for (
int i = 0;
i < 16;
i++) {
382 else if (version ==
Three)
384 alphas = alphas >> 4;
388template <DXTVersions version>
393 a[0] = alphas & 0xff;
394 a[1] = (alphas >> 8) & 0xff;
396 a[2] = (6*
a[0] + 1*
a[1]) / 7;
397 a[3] = (5*
a[0] + 2*
a[1]) / 7;
398 a[4] = (4*
a[0] + 3*
a[1]) / 7;
399 a[5] = (3*
a[0] + 4*
a[1]) / 7;
400 a[6] = (2*
a[0] + 5*
a[1]) / 7;
401 a[7] = (1*
a[0] + 6*
a[1]) / 7;
403 a[2] = (4*
a[0] + 1*
a[1]) / 5;
404 a[3] = (3*
a[0] + 2*
a[1]) / 5;
405 a[4] = (2*
a[0] + 3*
a[1]) / 5;
406 a[5] = (1*
a[0] + 4*
a[1]) / 5;
411 for (
int i = 0;
i < 16;
i++) {
417 else if (version ==
Five)
419 alphas = alphas >> 3;
423template <DXTVersions version>
433 setAlphaDXT32Helper<Two>(rgbArr, alphas);
439 setAlphaDXT32Helper<Three>(rgbArr, alphas);
445 setAlphaDXT45Helper<Four>(rgbArr, alphas);
451 setAlphaDXT45Helper<Five>(rgbArr, alphas);
457 setAlphaDXT45Helper<Five>(rgbArr, alphas);
465template <DXTVersions version>
487 setAlphaDXT<version>(arr,
alpha);
491 for (
quint32 k = 0; k < kMax; k++) {
493 for (
quint32 l = 0; l < lMax; l++) {
494 QRgb pixel = arr[k * 4 + l];
548 memset(arr, 0,
sizeof(
QRgb) * 16);
550 for (
int k = 0; k < 16; ++k) {
552 arr[k] =
qRgba(0, 0,
a, 0);
558 for (
quint32 k = 0; k < kMax; k++) {
560 for (
quint32 l = 0; l < lMax; l++) {
561 QRgb pixel = arr[k * 4 + l];
590 masks[
i] = (masks[
i] >> shifts[
i]) << (8 -
bits[
i]);
635 double sign = (
value & 0x8000) == 0x8000 ? -1.0 : 1.0;
640 return sign * std::pow(2.0, -14.0) * fraction / 1024.0;
642 return sign * std::pow(2.0, exp - 15) * (1 + fraction / 1024.0);
765 colors[
i] = (tmp + 0x7FFF) >> 8;
785 const quint8 un = u + 128;
798 for (
int i = 0;
i < 256; ++
i) {
800 s >>
r >>
g >>
b >>
a;
818 for (
int i = 0;
i < 16; ++
i) {
820 s >>
r >>
g >>
b >>
a;
831 if (
width % 2 == 1) {
885 quint8 r =
qint8((tmp & 0x001f) >> 0) * 0xff/0x1f + 128;
886 quint8 g =
qint8((tmp & 0x03e0) >> 5) * 0xff/0x1f + 128;
903 s >>
v >> u >>
a >> l;
940 v = (
v + 0x8000) >> 8;
941 u = (u + 0x8000) >> 8;
961 quint8 a = 0xff * ((tmp & 0xc0000000) >> 30) / 3;
979 s >> uyvy[0] >> uyvy[1] >> uyvy[2] >> uyvy[3];
983 if (
width % 2 == 1) {
984 s >> uyvy[0] >> uyvy[1] >> uyvy[2] >> uyvy[3];
999 s >> rgbg[1] >> rgbg[0] >> rgbg[3] >> rgbg[2];
1000 line[
x++] =
qRgb(rgbg[0], rgbg[1], rgbg[2]);
1001 line[
x++] =
qRgb(rgbg[0], rgbg[3], rgbg[2]);
1003 if (
width % 2 == 1) {
1004 s >> rgbg[1] >> rgbg[0] >> rgbg[3] >> rgbg[2];
1020 s >> yuyv[0] >> yuyv[1] >> yuyv[2] >> yuyv[3];
1024 if (
width % 2 == 1) {
1025 s >> yuyv[0] >> yuyv[1] >> yuyv[2] >> yuyv[3];
1040 s >> grgb[1] >> grgb[0] >> grgb[3] >> grgb[2];
1041 line[
x++] =
qRgb(grgb[1], grgb[0], grgb[3]);
1042 line[
x++] =
qRgb(grgb[1], grgb[2], grgb[3]);
1044 if (
width % 2 == 1) {
1045 s >> grgb[1] >> grgb[0] >> grgb[3] >> grgb[2];
1215 return 256 +
w *
h * 8;
1217 return w *
h * 4 * 2;
1234 return ((
w + 3)/4) * ((
h + 3)/4) * 8;
1239 return ((
w + 3)/4) * ((
h + 3)/4) * 16;
1256 return w *
h * 4 * 2;
1260 return w *
h * 1 * 2;
1262 return w *
h * 2 * 2;
1264 return w *
h * 4 * 2;
1266 return w *
h * 1 * 4;
1268 return w *
h * 2 * 4;
1270 return w *
h * 4 * 4;
1298 for (
int i = 0;
i < 6;
i++) {
1345 m_scanState(ScanNotScanned)
1354 if (m_scanState != ScanError) {
1364 if (!ensureScanned() ||
device()->isSequential())
1466 qWarning() <<
"unknown format" << subType;
1479 if (!ensureScanned())
1490 m_currentImage = imageNumber;
1497 qWarning() <<
"DDSHandler::canRead() called with no device";
1507bool QDDSHandler::ensureScanned()
const
1509 if (m_scanState != ScanNotScanned)
1510 return m_scanState == ScanSuccess;
1512 m_scanState = ScanError;
1518 qWarning() <<
"Sequential devices are not supported";
1527 s >> that->m_header;
1529 s >> that->m_header10;
1536 if (!verifyHeader(m_header))
1543 m_scanState = ScanSuccess;
1547bool QDDSHandler::verifyHeader(
const DDSHeader &dds)
const
1552 if ((
flags & requiredFlags) != requiredFlags) {
1553 qWarning() <<
"Wrong dds.flags - not all required flags present. "
1554 "Actual flags :" <<
flags;
1570 if (dds.
width > INT_MAX || dds.
height > INT_MAX) {
1571 qWarning() <<
"Can't read image with w/h bigger than INT_MAX";
IOBluetoothDevice * device
QByteArray toUpper() const &
QByteArray toLower() const &
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
QVariant option(QImageIOHandler::ImageOption option) const override
Returns the value assigned to option as a QVariant.
int imageCount() const override
For image formats that support animation, this function returns the number of images in the animation...
void setOption(ImageOption option, const QVariant &value) override
Sets the option option with the value value.
bool read(QImage *image) override
Read an image from the device, and stores it in image.
bool jumpToImage(int imageNumber) override
For image formats that support animation, this function jumps to the image whose sequence number is i...
bool supportsOption(QImageIOHandler::ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
bool write(const QImage &image) override
Writes the image image to the assigned device.
\inmodule QtCore\reentrant
FloatingPointPrecision
The precision of floating point numbers used for reading/writing the data.
\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 peek(char *data, qint64 maxlen)
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success,...
ImageOption
This enum describes the different options supported by QImageIOHandler.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
Format
The following image formats are available in Qt.
@ Format_ARGB32_Premultiplied
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
#define QByteArrayLiteral(str)
static const size_t formatInfosSize
static quint8 calcC3(quint8 c0, quint8 c1)
static QImage readUYVY(QDataStream &s, quint32 width, quint32 height)
static bool isCubeMap(const DDSHeader &dds)
static double readFloat16(QDataStream &s)
static QImage readQ16W16V16U16(QDataStream &s, const quint32 width, const quint32 height)
static QImage readR32F(QDataStream &s, const quint32 width, const quint32 height)
static QImage readPalette4Image(QDataStream &s, quint32 width, quint32 height)
static quint8 calcC2a(quint8 c0, quint8 c1)
static QImage readYUY2(QDataStream &s, quint32 width, quint32 height)
static QImage readDXT4(QDataStream &s, quint32 width, quint32 height)
static QImage readR16F(QDataStream &s, const quint32 width, const quint32 height)
static QImage readDXT(QDataStream &s, quint32 width, quint32 height)
static QImage readDXT1(QDataStream &s, quint32 width, quint32 height)
static QImage readLayer(QDataStream &s, const DDSHeader &dds, const int format, quint32 width, quint32 height)
static const FaceOffset faceOffsets[6]
void setAlphaDXT< Four >(QRgb *rgbArr, quint64 alphas)
static QImage readCxV8U8(QDataStream &s, const quint32 width, const quint32 height)
static QImage readTexture(QDataStream &s, const DDSHeader &dds, const int format, const int mipmapLevel)
void setAlphaDXT< RXGB >(QRgb *rgbArr, quint64 alphas)
static QImage readDXT3(QDataStream &s, quint32 width, quint32 height)
void setAlphaDXT45Helper(QRgb *rgbArr, quint64 alphas)
static QImage readRG32F(QDataStream &s, const quint32 width, const quint32 height)
static int maskLength(quint32 mask)
static QImage readDXT2(QDataStream &s, quint32 width, quint32 height)
static QImage readARGB32F(QDataStream &s, const quint32 width, const quint32 height)
static quint32 readValue(QDataStream &s, quint32 size)
static QImage readRG16F(QDataStream &s, const quint32 width, const quint32 height)
static QImage readATI2(QDataStream &s, quint32 width, quint32 height)
static QRgb yuv2rgb(quint8 Y, quint8 U, quint8 V)
static QImage readRXGB(QDataStream &s, quint32 width, quint32 height)
static QImage readR8G8B8G8(QDataStream &s, quint32 width, quint32 height)
static QImage readA2R10G10B10(QDataStream &s, const DDSHeader &dds, quint32 width, quint32 height)
static qint64 mipmapOffset(const DDSHeader &dds, const int format, const int level)
static int formatByName(const QByteArray &name)
static const quint32 dx10Magic
static QImage readUnsignedImage(QDataStream &s, const DDSHeader &dds, quint32 width, quint32 height, bool hasAlpha)
static Format getFormat(const DDSHeader &dds)
static const quint32 ddsMagic
void setAlphaDXT< Five >(QRgb *rgbArr, quint64 alphas)
static QImage readX8L8V8U8(QDataStream &s, quint32 width, quint32 height)
static float readFloat32(QDataStream &s)
static QImage readV8U8(QDataStream &s, quint32 width, quint32 height)
void setAlphaDXT< Two >(QRgb *rgbArr, quint64 alphas)
static QImage readL6V5U5(QDataStream &s, quint32 width, quint32 height)
static int maskToShift(quint32 mask)
static QImage readARGB16(QDataStream &s, quint32 width, quint32 height)
static const qint64 headerSize
static QImage readARGB16F(QDataStream &s, const quint32 width, const quint32 height)
static const quint32 ddsSize
static QImage readA2W10V10U10(QDataStream &s, quint32 width, quint32 height)
static QImage readQ8W8V8U8(QDataStream &s, quint32 width, quint32 height)
void setAlphaDXT< Three >(QRgb *rgbArr, quint64 alphas)
static const quint32 pixelFormatSize
static const Format knownFourCCs[]
static QImage readV16U16(QDataStream &s, quint32 width, quint32 height)
static void decodeColor(quint16 color, quint8 &red, quint8 &green, quint8 &blue)
static QImage readG8R8G8B8(QDataStream &s, quint32 width, quint32 height)
static QByteArray formatName(int format)
static void DXTFillColors(QRgb *result, quint16 c0, quint16 c1, quint32 table, bool dxt1a=false)
static QImage readDXT5(QDataStream &s, quint32 width, quint32 height)
static qint64 mipmapSize(const DDSHeader &dds, const int format, const int level)
static bool hasAlpha(const DDSHeader &dds)
static quint8 getNormalZ(quint8 nx, quint8 ny)
static QImage readCubeMap(QDataStream &s, const DDSHeader &dds, const int fmt)
static quint8 calcC2(quint8 c0, quint8 c1)
void setAlphaDXT(QRgb *rgbArr, quint64 alphas)
static QRgb invertRXGBColors(QRgb pixel)
static const FormatInfo formatInfos[]
static QImage readPalette8Image(QDataStream &s, quint32 width, quint32 height)
static const FormatName formatNames[]
void setAlphaDXT32Helper(QRgb *rgbArr, quint64 alphas)
static const size_t formatNamesSize
static const size_t knownFourCCsSize
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLint level
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLfloat GLfloat GLfloat alpha
GLenum GLenum GLsizei void * table
GLenum GLint GLint * precision
static QT_BEGIN_NAMESPACE const QRgb colors[][14]
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr QRgb qRgb(int r, int g, int b)
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr QRgb qRgba(int r, int g, int b, int a)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
unsigned long long quint64
QT_BEGIN_NAMESPACE typedef signed char qint8
QVideoFrameFormat::PixelFormat fmt
QFileInfo info(fileName)
[8]