8
9
10
11
12
27#define WBMPFIXEDHEADER_SIZE 2
35 unsigned int count = 0;
39 if (++count >
sizeof(*num))
42 if (!iodev->getChar(
reinterpret_cast<
char *>(&c)))
45 res = (res << 7) | (c & 0x7F);
55 quint64 tmp = num & 0x7F;
59 quint8 c = num & 0x7F;
61 tmp = (tmp << 8) | (c | 0x80);
65 quint8 c = tmp & 0xFF;
66 if (!iodev->putChar(c))
86 if (readMultiByteInt(iodev, &hdr->width)
87 && readMultiByteInt(iodev, &hdr->height)) {
102 if (writeMultiByteInt(iodev, hdr.width) &&
103 writeMultiByteInt(iodev, hdr.height))
112 int h = image.height();
113 int bpl = (image.width() + 7) / 8;
115 for (
int l=0; l<h; l++) {
116 if (iodev->write(
reinterpret_cast<
const char *>(image.constScanLine(l)), bpl) != bpl)
127 int h = image.height();
128 int bpl = (image.width() + 7) / 8;
130 for (
int l = 0; l < h; l++) {
131 if (iodev->read(
reinterpret_cast<
char *>(image.scanLine(l)), bpl) != bpl)
157 memset(&hdr, 0,
sizeof(hdr));
162 if (!readWBMPHeader(iodev, &hdr))
166 if (!QImageIOHandler::allocateImage(QSize(hdr.width, hdr.height), QImage::Format_Mono, &image))
168 if (!readWBMPData(iodev, image))
176 if (image.format() != QImage::Format_Mono)
177 image = image.convertToFormat(QImage::Format_Mono);
179 if (image.colorTable().at(0) == image.colorTable().at(1)) {
181 image.fill((qGray(image.colorTable().at(0)) < 128) ? 0 : 1);
182 }
else if (qGray(image.colorTable().at(0)) > qGray(image.colorTable().at(1))) {
184 image.invertPixels();
189 hdr.width = image.width();
190 hdr.height = image.height();
192 if (!writeWBMPHeader(iodev, hdr))
195 if (!writeWBMPData(iodev, image))
205 if (device->isSequential())
209 qint64 oldPos = device->pos();
213 if ((hdr.type == 0) && (hdr.format == 0)) {
214 const qint64 imageSize = hdr.height * ((qint64(hdr.width) + 7) / 8);
215 qint64 available = device->bytesAvailable();
216 device->seek(oldPos);
217 return (imageSize == available);
220 device->seek(oldPos);
226
227
229 m_reader(
new WBMPReader(device))
234
235
242
243
244
247 bool bCanRead =
false;
249 QIODevice *device = QImageIOHandler::device();
256 qWarning(
"QWbmpHandler::canRead() called with no device");
263
266 bool bSuccess =
false;
267 QImage img = m_reader->readImage();
278
284 return m_reader->writeImage(image);
288
289
292 if (option == QImageIOHandler::Size) {
293 QIODevice *device = QImageIOHandler::device();
294 if (device->isSequential())
298 qint64 oldPos = device->pos();
302 device->seek(oldPos);
303 return QSize(hdr.width, hdr.height);
306 device->seek(oldPos);
308 }
else if (option == QImageIOHandler::ImageFormat) {
309 return QVariant(QImage::Format_Mono);
317 return (option == QImageIOHandler::Size) ||
318 (option == QImageIOHandler::ImageFormat);
ImageOption
This enum describes the different options supported by QImageIOHandler.
The QWbmpHandler class provides support for the WBMP image format.
bool canRead() const override
Verifies if some values (magic bytes) are set as expected in the header of the file.
QVariant option(ImageOption option) const override
Only Size option is supported.
~QWbmpHandler()
Destructor for QWbmpHandler.
bool supportsOption(ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
bool write(const QImage &image) override
\reimp
bool read(QImage *image) override
\reimp
bool writeImage(QImage image)
WBMPReader(QIODevice *iodevice)
static bool canRead(QIODevice *iodevice)
static bool writeWBMPData(QIODevice *iodev, const QImage &image)
static bool writeWBMPHeader(QIODevice *iodev, const WBMPHeader &hdr)
static bool writeMultiByteInt(QIODevice *iodev, quint32 num)
#define WBMPFIXEDHEADER_SIZE
static bool readMultiByteInt(QIODevice *iodev, quint32 *num)
static bool readWBMPHeader(QIODevice *iodev, WBMPHeader *hdr)
static bool readWBMPData(QIODevice *iodev, QImage &image)