4#include "private/qppmhandler_p.h"
6#ifndef QT_NO_IMAGEFORMAT_PPM
14#include <private/qlocale_p.h>
15#include <private/qtools_p.h>
27 const int buflen = 100;
40 bool hasOverflow =
false;
47 const int cValue =
c -
'0';
48 if (
val <= (INT_MAX - cValue) / 10) {
71 return hasOverflow ? -1 :
val;
96 if (!
ok || w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 || mcc > 0xffff)
142 pbm_bpl = mcc < 256 ? 3*
w : 6*
w;
146 for (
y=0;
y<
h;
y++) {
147 if (
device->read((
char *)buf24, pbm_bpl) != pbm_bpl) {
174 }
else if (nbits == 8 && mcc > 255) {
177 for (
y=0;
y<
h;
y++) {
178 if (
device->read((
char *)buf16, pbm_bpl) != pbm_bpl) {
186 *
p++ = (
b[0] << 8 |
b[1]) * 255 / mcc;
192 for (
y=0;
y<
h;
y++) {
194 if (
device->read((
char *)
p, pbm_bpl) != pbm_bpl)
196 if (nbits == 8 && mcc < 255) {
198 p[
i] = (
p[
i] * 255) / mcc;
206 for (
y = 0;
y <
h &&
ok;
y++) {
214 for (
int i=0;
i<8;
i++) {
218 b = (
b << 1) | (0 & 1);
223 }
else if (nbits == 8) {
275 bool gray =
format ==
"pgm";
282 switch (
image.format()) {
292 if (
image.hasAlphaChannel())
300 if (
image.depth() == 1 &&
image.colorCount() == 2) {
304 for (
int y=0;
y<
image.height();
y++) {
322 switch (
image.depth()) {
397 const QRgb *
b =
reinterpret_cast<const QRgb *
>(
image.constScanLine(
y));
425bool QPpmHandler::readHeader()
439 if (state != Error) {
450 qCWarning(lcImageIo,
"QPpmHandler::canRead() called with no device");
455 if (
device->
peek(head,
sizeof(head)) !=
sizeof(head))
461 if (head[1] ==
'1' || head[1] ==
'4') {
464 }
else if (head[1] ==
'2' || head[1] ==
'5') {
467 }
else if (head[1] ==
'3' || head[1] ==
'6') {
481 if (state == Ready && !readHeader()) {
514 if (state == Ready && !
const_cast<QPpmHandler*
>(
this)->readHeader())
520 if (state == Ready && !
const_cast<QPpmHandler*
>(
this)->readHeader())
IOBluetoothDevice * device
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
QByteArray toLower() const &
QByteArray left(qsizetype len) const
Returns a byte array that contains the first len bytes of this byte array.
\inmodule QtCore \reentrant
qint64 peek(char *data, qint64 maxlen)
ImageOption
This enum describes the different options supported by QImageIOHandler.
static bool allocateImage(QSize size, QImage::Format format, QImage *image)
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
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.
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.
void setOption(ImageOption option, const QVariant &value) override
Sets the option option with the value value.
bool write(const QImage &image) override
Writes the image image to the assigned device.
bool canRead() const override
Returns true if an image can be read from the device (i.e., the image format is supported,...
bool read(QImage *image) override
Read an image from the device, and stores it in image.
QVariant option(ImageOption option) const override
Returns the value assigned to option as a QVariant.
bool supportsOption(ImageOption option) const override
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
static constexpr QRgba64 fromRgba64(quint64 c)
constexpr uint toArgb32() const
qsizetype size() const
Returns the number of characters in this string.
QString & insert(qsizetype i, QChar c)
QString & append(QChar c)
Combined button and popup list for selecting options.
constexpr bool isAsciiDigit(char32_t c) noexcept
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
constexpr bool ascii_isspace(uchar c)
#define qCWarning(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage)
static QRgb scale_pbm_color(quint16 mx, quint16 rv, quint16 gv, quint16 bv)
static bool read_pbm_header(QIODevice *device, char &type, int &w, int &h, int &mcc)
static int read_pbm_int(QIODevice *d, bool *ok)
static QT_BEGIN_NAMESPACE void discard_pbm_line(QIODevice *d)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr QRgb qRgb(int r, int g, int b)
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qGray(int r, int g, int b)
constexpr int qBlue(QRgb rgb)
QTextStream out(stdout)
[7]