4#include <qplatformdefs.h>
5#include "private/qxbmhandler_p.h"
7#ifndef QT_NO_IMAGEFORMAT_XBM
13#include <private/qtools_p.h>
34 const int buflen = 300;
35 const int maxlen = 4096;
44 while (
buf[0] !=
'#') {
45 readBytes =
device->readLine(
buf, buflen);
48 if (readBytes <= 0 || readBytes >= buflen -1)
53 totalReadBytes += readBytes;
54 if (totalReadBytes >= maxlen)
58 auto parseDefine = [] (
const char *
buf,
int len) ->
int {
59 auto checkChar = [] (
char ch) ->
bool {
61 ||
ch ==
'_' ||
ch ==
'.';
63 auto isAsciiSpace = [] (
char ch) ->
bool {
64 return ch ==
' ' ||
ch ==
'\t';
66 const char define[] =
"#define";
67 constexpr size_t defineLen =
sizeof(define) - 1;
68 if (strncmp(
buf, define, defineLen) != 0)
70 int index = defineLen;
83 w = parseDefine(
buf, readBytes - 1);
85 readBytes =
device->readLine(
buf, buflen);
87 h = parseDefine(
buf, readBytes - 1);
90 if (w <= 0 || w > 32767 || h <= 0 || h > 32767)
98 const int buflen = 300;
107 if ((readBytes =
device->readLine(
buf, buflen)) <= 0) {
112 buf[readBytes] =
'\0';
113 p = strstr(
buf,
"0x");
130 if (
p &&
p < (
buf + readBytes - 3)) {
136 if (++
x ==
w && ++
y <
h) {
142 if ((readBytes =
device->readLine(
buf,buflen)) <= 0)
144 buf[readBytes] =
'\0';
145 p = strstr(
buf,
"0x");
167 int msize =
s.size() + 100;
168 char *
buf =
new char[msize];
170 qsnprintf(
buf, msize,
"#define %s_width %d\n",
s.toUtf8().data(),
w);
172 qsnprintf(
buf, msize,
"#define %s_height %d\n",
s.toUtf8().data(),
h);
174 qsnprintf(
buf, msize,
"static char %s_bits[] = {\n ",
s.toUtf8().data());
184 for (
i=10;
i<16;
i++)
185 hexrep[
i] =
'a' -10 +
i;
188 for (
i=0;
i<8;
i++) {
190 hexrep[15-
i] = hexrep[
i];
197 for (
int y = 0;
y <
h; ++
y) {
199 for (
i = 0;
i < bpl; ++
i) {
200 *
p++ =
'0'; *
p++ =
'x';
201 *
p++ = hexrep[*
b >> 4];
202 *
p++ = hexrep[*
b++ & 0xf];
204 if (
i < bpl - 1 ||
y <
h - 1) {
221 strcpy_s(
p,
sizeof(
" };\n"),
" };\n");
239bool QXbmHandler::readHeader()
253 if (state != Error) {
264 qCWarning(lcImageIo,
"QXbmHandler::canRead() called with no device");
287 if (state == Ready && !readHeader()) {
320 if (state == Ready && !
const_cast<QXbmHandler*
>(
this)->readHeader())
332 fileName =
value.toString();
IOBluetoothDevice * device
int toInt(bool *ok=nullptr, int base=10) const
Returns the byte array converted to an int using base base, which is ten by default.
\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.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
void fill(uint pixel)
Fills the entire image with the given pixelValue.
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue.
\macro QT_RESTRICTED_CAST_FROM_ASCII
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,...)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
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)