55 #include <QtCore/qendian.h> 56 #include <QtGui/QImage> 57 #include <QtCore/QFile> 58 #include <QtCore/QBuffer> 76 #define ICONDIRENTRY_SIZE 16 85 #define ICONDIR_SIZE 6 // Exclude the idEntries field 100 #define BMP_INFOHDR_SIZE 40 150 iconDirEntry->
bWidth = tmp[0];
151 iconDirEntry->
bHeight = tmp[1];
169 tmp[0] = iconEntry.
bWidth;
173 qToLittleEndian<quint16>(iconEntry.
wPlanes, &tmp[4]);
174 qToLittleEndian<quint16>(iconEntry.
wBitCount, &tmp[6]);
175 qToLittleEndian<quint32>(iconEntry.
dwBytesInRes, &tmp[8]);
204 return (iodev->
write((
char*)tmp, 6) == 6) ?
true :
false;
235 qToLittleEndian<quint32>(header.
biSize, &tmp[0]);
236 qToLittleEndian<quint32>(header.
biWidth, &tmp[4]);
237 qToLittleEndian<quint32>(header.
biHeight, &tmp[8]);
238 qToLittleEndian<quint16>(header.
biPlanes, &tmp[12]);
239 qToLittleEndian<quint16>(header.
biBitCount, &tmp[14]);
241 qToLittleEndian<quint32>(header.
biSizeImage, &tmp[20]);
244 qToLittleEndian<quint32>(header.
biClrUsed, &tmp[32]);
270 bool isProbablyICO =
false;
287 isProbablyICO =
true;
337 return isProbablyICO;
392 if (
iod->
read((
char*)rgb, 4) != 4) {
450 if (
iod->
read((
char*)buf,buflen) != buflen) {
502 if (
iod->
read((
char *)buf, bpl) != bpl) {
509 *p++ =
qRgb(*(b+2), *(b+1), *b);
511 *p++ =
qRgba(*(b+2), *(b+1), *b, *(b+3));
527 if (
count() > index) {
532 static const uchar pngMagicData[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
537 const bool isPngImage = (
iod->
read(pngMagic.
size()) == pngMagic);
589 if (!mask.isNull()) {
591 mask.setColor(0,
qRgba(255,255,255,0xff));
592 mask.setColor(1,
qRgba(0 ,0 ,0 ,0xff));
594 if (!mask.isNull()) {
627 for (
int i = 0; i < reader.
count(); i++)
628 images += reader.
iconAt(i);
648 bool retValue =
false;
650 if (images.
count()) {
657 id.idCount = images.
count();
663 for (
int i=0; i<
id.idCount; i++) {
674 if (image.hasAlphaChannel()) {
677 maskImage.
fill(0xff);
682 int bpl_bmp = ((image.width()*nbits+31)/32)*4;
687 entries[i].
bHeight = image.height();
688 entries[i].
bWidth = image.width();
690 + (maskImage.bytesPerLine() * maskImage.height());
715 memset( buf, 0, bpl_bmp );
717 for (y = image.height() - 1; y >= 0; y--) {
719 QRgb *p = (
QRgb *)image.scanLine(y);
733 buffer.
write((
char*)buf, bpl_bmp);
737 maskImage.invertPixels();
739 for (y = maskImage.height() - 1; y >= 0; y--)
740 buffer.
write((
char*)maskImage.scanLine(y), maskImage.bytesPerLine());
746 for (i = 0; i <
id.idCount && bOK; i++) {
750 for (i = 0; i <
id.idCount && bOK; i++) {
752 bOK &= (device->
write(imageData[i]) == (int) imageData[i].size());
759 delete [] bmpHeaders;
771 m_currentIconIndex = 0;
786 if (option == Size) {
792 device->
seek(oldPos);
797 device->
seek(oldPos);
804 return option == Size;
814 bool bCanRead =
false;
821 qWarning(
"QtIcoHandler::canRead() called with no device");
840 bool bSuccess =
false;
841 QImage img = m_pICOReader->iconAt(m_currentIconIndex);
879 return m_pICOReader->count();
887 if (imageNumber < imageCount()) {
888 m_currentIconIndex = imageNumber;
891 return (imageNumber < imageCount()) ? true :
false;
899 return jumpToImage(m_currentIconIndex + 1);
The QVariant class acts like a union for the most common Qt data types.
static bool writeIconDir(QIODevice *iodev, const ICONDIR &iconDir)
void read4BitBMP(QImage &image)
Format
The following image formats are available in Qt.
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
#define QT_END_NAMESPACE
This macro expands to.
void readBMP(QImage &image)
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
bool open(OpenMode openMode)
Reimplemented Function
quint16 qFromLittleEndian< quint16 >(const uchar *src)
bool isNull() const
Returns true if it is a null image, otherwise returns false.
void fill(uint pixel)
Fills the entire image with the given pixelValue.
The QByteArray class provides an array of bytes.
virtual qint64 pos() const
For random-access devices, this function returns the position that data is written to or read from...
ICONDIRENTRY idEntries[1]
bool canRead() const
Verifies if some values (magic bytes) are set as expected in the header of the file.
bool write(const QImage &image)
Reimplemented Function
int bytesPerLine() const
Returns the number of bytes per image scanline.
int count(const T &t) const
Returns the number of occurrences of value in the list.
The QBuffer class provides a QIODevice interface for a QByteArray.
bool read(QImage *image)
Reimplemented Function
void ungetChar(char c)
Puts the character c back into the device, and decrements the current position unless the position is...
static bool write(QIODevice *device, const QList< QImage > &images)
Writes all the QImages in the images list to the given device.
static bool readIconDir(QIODevice *iodev, ICONDIR *iconDir)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
#define ICONDIRENTRY_SIZE
void append(const T &t)
Inserts value at the end of the list.
void setColorCount(int)
Resizes the color table to contain colorCount entries.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
struct ICONDIR * LPICONDIR
ImageOption
This enum describes the different options supported by QImageIOHandler.
int imageCount() const
Reimplemented Function
struct BMP_INFOHDR * LPBMP_INFOHDR
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
Q_CORE_EXPORT void qWarning(const char *,...)
quint32 qFromLittleEndian< quint32 >(const uchar *src)
bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false...
The QImage class provides a hardware-independent image representation that allows direct access to th...
void readColorTable(QImage &image)
#define FALSE
Synonym for false.
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
void read16_24_32BMP(QImage &image)
virtual ~QtIcoHandler()
Destructor for QtIcoHandler.
handler setDevice(device)
ICOReader(QIODevice *iodevice)
void findColorInfo(QImage &image)
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
QtIcoHandler(QIODevice *device)
Constructs an instance of QtIcoHandler initialized to use device.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
static bool readBMPInfoHeader(QIODevice *iodev, BMP_INFOHDR *pHeader)
#define TRUE
Synonym for true.
static const MacSpecialKey entries[NumEntries]
int width() const
Returns the width of the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
struct ICOReader::IcoAttrib icoAttrib
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
bool jumpToImage(int imageNumber)
Reimplemented Function
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
static bool readIconDirEntry(QIODevice *iodev, ICONDIRENTRY *iconDirEntry)
int height() const
Returns the height of the image.
int size() const
Returns the number of bytes in this byte array.
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
static bool canRead(QIODevice *iodev)
The QSize class defines the size of a two-dimensional object using integer point precision.
bool readIconEntry(int index, ICONDIRENTRY *iconEntry)
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
void setAlphaChannel(const QImage &alphaChannel)
Sets the alpha channel of this image to the given alphaChannel.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
bool readBMPHeader(quint32 imageOffset, BMP_INFOHDR *header)
struct ICONDIRENTRY * LPICONDIRENTRY
static const KeyPair *const end
static bool writeIconDirEntry(QIODevice *iodev, const ICONDIRENTRY &iconEntry)
The QIODevice class is the base interface class of all I/O devices in Qt.
static QList< QImage > read(QIODevice *device)
Reads all the icons from the given device, and returns them as a list of QImage objects.
static bool writeBMPInfoHeader(QIODevice *iodev, const BMP_INFOHDR &header)
virtual bool seek(qint64 pos)
For random-access devices, this function sets the current position to pos, returning true on success...
T qToLittleEndian(T source)
static QImage fromData(const uchar *data, int size, const char *format=0)
Constructs a QImage from the first size bytes of the given binary data.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
bool jumpToNextImage()
Reimplemented Function
void read1BitBMP(QImage &image)
void read8BitBMP(QImage &image)
QByteArray name() const
Return the common identifier of the format.