Images: Implement internal DIB image plugin.
For use for clipboard/DnD operations on Windows by its Lighthouse plugin (to prevent having to export qt_read_dib(), qt_write_dib()). Change-Id: I79e69bf7cecb16cc47ea29de6805fc52e4df1007 Reviewed-on: http://codereview.qt.nokia.com/1714 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Oliver Wolff <oliver.wolff@nokia.com>
This commit is contained in:
parent
bc0a0281d5
commit
5abf4f55b1
@ -646,11 +646,16 @@ bool qt_read_dib(QDataStream &s, QImage &image)
|
||||
return read_dib_body(s, bi, -1, -BMP_FILEHDR_SIZE, image);
|
||||
}
|
||||
|
||||
QBmpHandler::QBmpHandler()
|
||||
: state(Ready)
|
||||
QBmpHandler::QBmpHandler(InternalFormat fmt) :
|
||||
m_format(fmt), state(Ready)
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray QBmpHandler::formatName() const
|
||||
{
|
||||
return m_format == BmpFormat ? "bmp" : "dib";
|
||||
}
|
||||
|
||||
bool QBmpHandler::readHeader()
|
||||
{
|
||||
state = Error;
|
||||
@ -663,7 +668,7 @@ bool QBmpHandler::readHeader()
|
||||
s.setByteOrder(QDataStream::LittleEndian);
|
||||
|
||||
// read BMP file header
|
||||
if (!read_dib_fileheader(s, fileHeader))
|
||||
if (m_format == BmpFormat && !read_dib_fileheader(s, fileHeader))
|
||||
return false;
|
||||
|
||||
// read BMP info header
|
||||
@ -676,11 +681,11 @@ bool QBmpHandler::readHeader()
|
||||
|
||||
bool QBmpHandler::canRead() const
|
||||
{
|
||||
if (state == Ready && !canRead(device()))
|
||||
if (m_format == BmpFormat && state == Ready && !canRead(device()))
|
||||
return false;
|
||||
|
||||
if (state != Error) {
|
||||
setFormat("bmp");
|
||||
setFormat(formatName());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -732,6 +737,12 @@ bool QBmpHandler::read(QImage *image)
|
||||
|
||||
bool QBmpHandler::write(const QImage &img)
|
||||
{
|
||||
if (m_format == DibFormat) {
|
||||
QDataStream dibStream(device());
|
||||
dibStream.setByteOrder(QDataStream::LittleEndian); // Intel byte order
|
||||
return qt_write_dib(dibStream, img);
|
||||
}
|
||||
|
||||
QImage image;
|
||||
switch (img.format()) {
|
||||
case QImage::Format_ARGB8565_Premultiplied:
|
||||
@ -829,7 +840,7 @@ void QBmpHandler::setOption(ImageOption option, const QVariant &value)
|
||||
|
||||
QByteArray QBmpHandler::name() const
|
||||
{
|
||||
return "bmp";
|
||||
return formatName();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -81,10 +81,20 @@ struct BMP_INFOHDR { // BMP information header
|
||||
qint32 biClrImportant; // number of important colors
|
||||
};
|
||||
|
||||
// BMP-Handler, which is also able to read and write the DIB
|
||||
// (Device-Independent-Bitmap) format used internally in the Windows operating
|
||||
// system for OLE/clipboard operations. DIB is a subset of BMP (without file
|
||||
// header). The Windows-Lighthouse plugin accesses the DIB-functionality.
|
||||
|
||||
class QBmpHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
QBmpHandler();
|
||||
enum InternalFormat {
|
||||
DibFormat,
|
||||
BmpFormat
|
||||
};
|
||||
|
||||
explicit QBmpHandler(InternalFormat fmt = BmpFormat);
|
||||
bool canRead() const;
|
||||
bool read(QImage *image);
|
||||
bool write(const QImage &image);
|
||||
@ -99,11 +109,16 @@ public:
|
||||
|
||||
private:
|
||||
bool readHeader();
|
||||
inline QByteArray formatName() const;
|
||||
|
||||
enum State {
|
||||
Ready,
|
||||
ReadHeader,
|
||||
Error
|
||||
};
|
||||
|
||||
const InternalFormat m_format;
|
||||
|
||||
State state;
|
||||
BMP_FILEHDR fileHeader;
|
||||
BMP_INFOHDR infoHeader;
|
||||
|
@ -359,6 +359,8 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
|
||||
#ifndef QT_NO_IMAGEFORMAT_BMP
|
||||
} else if (testFormat == "bmp") {
|
||||
handler = new QBmpHandler;
|
||||
} else if (testFormat == "dib") {
|
||||
handler = new QBmpHandler(QBmpHandler::DibFormat);
|
||||
#endif
|
||||
#ifndef QT_NO_IMAGEFORMAT_XPM
|
||||
} else if (testFormat == "xpm") {
|
||||
|
@ -201,6 +201,8 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device,
|
||||
#ifndef QT_NO_IMAGEFORMAT_BMP
|
||||
} else if (testFormat == "bmp") {
|
||||
handler = new QBmpHandler;
|
||||
} else if (testFormat == "dib") {
|
||||
handler = new QBmpHandler(QBmpHandler::DibFormat);
|
||||
#endif
|
||||
#ifndef QT_NO_IMAGEFORMAT_XPM
|
||||
} else if (testFormat == "xpm") {
|
||||
|
Loading…
Reference in New Issue
Block a user