4#include <qplatformdefs.h>
5#include "private/qxbmhandler_p.h"
7#ifndef QT_NO_IMAGEFORMAT_XBM
13#include <private/qtools_p.h>
14#include <private/qimage_p.h>
32 const int buflen = 300;
33 const int maxlen = 4096;
42 while (
buf[0] !=
'#') {
43 readBytes =
device->readLine(
buf, buflen);
46 if (readBytes <= 0 || readBytes >= buflen -1)
51 totalReadBytes += readBytes;
52 if (totalReadBytes >= maxlen)
56 auto parseDefine = [] (
const char *
buf,
int len) ->
int {
57 auto checkChar = [] (
char ch) ->
bool {
59 ||
ch ==
'_' ||
ch ==
'.';
61 auto isAsciiSpace = [] (
char ch) ->
bool {
62 return ch ==
' ' ||
ch ==
'\t';
64 const char define[] =
"#define";
65 constexpr size_t defineLen =
sizeof(define) - 1;
66 if (strncmp(
buf, define, defineLen) != 0)
68 int index = defineLen;
81 w = parseDefine(
buf, readBytes - 1);
83 readBytes =
device->readLine(
buf, buflen);
85 h = parseDefine(
buf, readBytes - 1);
88 if (w <= 0 || w > 32767 || h <= 0 || h > 32767)
96 const int buflen = 300;
105 if ((readBytes =
device->readLine(
buf, buflen)) <= 0) {
110 buf[readBytes] =
'\0';
111 p = strstr(
buf,
"0x");
119 outImage->setColorCount(2);
120 outImage->setColor(0,
qRgb(255,255,255));
121 outImage->setColor(1,
qRgb(0,0,0));
124 uchar *
b = outImage->scanLine(0);
128 if (
p &&
p < (
buf + readBytes - 3)) {
134 if (++
x ==
w && ++
y <
h) {
135 b = outImage->scanLine(
y);
140 if ((readBytes =
device->readLine(
buf,buflen)) <= 0)
142 buf[readBytes] =
'\0';
143 p = strstr(
buf,
"0x");
165 int msize =
s.
size() + 100;
166 char *
buf =
new char[msize];
168 qsnprintf(
buf, msize,
"#define %s_width %d\n",
s.toUtf8().data(),
w);
170 qsnprintf(
buf, msize,
"#define %s_height %d\n",
s.toUtf8().data(),
h);
172 qsnprintf(
buf, msize,
"static char %s_bits[] = {\n ",
s.toUtf8().data());
182 for (
i=10;
i<16;
i++)
183 hexrep[
i] =
'a' -10 +
i;
186 for (
i=0;
i<8;
i++) {
188 hexrep[15-
i] = hexrep[
i];
195 for (
int y = 0;
y <
h; ++
y) {
197 for (
i = 0;
i < bpl; ++
i) {
198 *
p++ =
'0'; *
p++ =
'x';
199 *
p++ = hexrep[*
b >> 4];
200 *
p++ = hexrep[*
b++ & 0xf];
202 if (
i < bpl - 1 ||
y <
h - 1) {
219 strcpy_s(
p,
sizeof(
" };\n"),
" };\n");
237bool QXbmHandler::readHeader()
251 if (state != Error) {
262 qCWarning(lcImageIo,
"QXbmHandler::canRead() called with no device");
285 if (state == Ready && !readHeader()) {
315 }
else if (
option == Size) {
318 if (state == Ready && !
const_cast<QXbmHandler*
>(
this)->readHeader())
321 }
else if (
option == ImageFormat) {
330 fileName =
value.toString();
IOBluetoothDevice * device
\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.
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.
static bool allocateImage(QSize size, QImage::Format format, QImage *image)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype size() const noexcept
Returns the number of characters in this string.
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool supportsOption(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.
void setOption(ImageOption option, const QVariant &value) override
Sets the option option with the value value.
QVariant option(ImageOption option) const override
Returns the value assigned to option as a QVariant.
bool read(QImage *image) override
Read an image from the device, and stores it in image.
std::list< QString >::iterator Name
Combined button and popup list for selecting options.
constexpr bool isAsciiLetterOrNumber(char32_t c) noexcept
constexpr int fromHex(char32_t c) noexcept
size_t qstrlen(const char *str)
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLenum GLsizei const GLchar * buf
GLfloat GLfloat GLfloat GLfloat h
constexpr QRgb qRgb(int r, int g, int b)
constexpr int qGray(int r, int g, int b)
static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const QString &fileName)
static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
static bool read_xbm_header(QIODevice *device, int &w, int &h)
static bool read_xbm_image(QIODevice *device, QImage *outImage)
static int hex2byte(char *p)