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) {
53 if (maxDigits > 0 && --maxDigits == 0)
70 if (maxDigits > 0 && --maxDigits == 0)
75 return hasOverflow ? -1 :
val;
100 if (!
ok || w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 || mcc > 0xffff)
108 return QRgba64::fromRgba64((rv * 0xffffu) / mx, (gv * 0xffffu) / mx, (bv * 0xffffu) / mx, 0xffff).toArgb32();
146 pbm_bpl = mcc < 256 ? 3*
w : 6*
w;
150 for (
y=0;
y<
h;
y++) {
151 if (
device->read((
char *)buf24, pbm_bpl) != pbm_bpl) {
155 p = (
QRgb *)outImage->scanLine(
y);
178 }
else if (nbits == 8 && mcc > 255) {
181 for (
y=0;
y<
h;
y++) {
182 if (
device->read((
char *)buf16, pbm_bpl) != pbm_bpl) {
186 uchar *
p = outImage->scanLine(
y);
190 *
p++ = (
b[0] << 8 |
b[1]) * 255 / mcc;
196 for (
y=0;
y<
h;
y++) {
197 uchar *
p = outImage->scanLine(
y);
198 if (
device->read((
char *)
p, pbm_bpl) != pbm_bpl)
200 if (nbits == 8 && mcc < 255) {
202 p[
i] = (
p[
i] * 255) / mcc;
210 for (
y = 0;
y <
h &&
ok;
y++) {
211 p = outImage->scanLine(
y);
218 for (
int i=0;
i<8;
i++) {
222 b = (
b << 1) | (0 & 1);
227 }
else if (nbits == 8) {
264 outImage->setColorCount(2);
265 outImage->setColor(0,
qRgb(255,255,255));
266 outImage->setColor(1,
qRgb(0,0,0));
278 bool gray =
format ==
"pgm";
285 switch (
image.format()) {
295 if (
image.hasAlphaChannel())
303 if (
image.depth() == 1 &&
image.colorCount() == 2) {
307 for (
int y=0;
y<
image.height();
y++) {
325 switch (
image.depth()) {
400 const QRgb *
b =
reinterpret_cast<const QRgb *
>(
image.constScanLine(
y));
428bool QPpmHandler::readHeader()
442 if (state != Error) {
453 qCWarning(lcImageIo,
"QPpmHandler::canRead() called with no device");
464 if (
head[1] ==
'1' ||
head[1] ==
'4') {
467 }
else if (
head[1] ==
'2' ||
head[1] ==
'5') {
470 }
else if (
head[1] ==
'3' ||
head[1] ==
'6') {
484 if (state == Ready && !readHeader()) {
514 }
else if (
option == Size) {
517 if (state == Ready && !
const_cast<QPpmHandler*
>(
this)->readHeader())
520 }
else if (
option == ImageFormat) {
523 if (state == Ready && !
const_cast<QPpmHandler*
>(
this)->readHeader())
IOBluetoothDevice * device
constexpr QByteArrayView left(qsizetype n) const
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
QByteArray toLower() const &
\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.
Format
The following image formats are available in Qt.
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)
qsizetype size() const noexcept
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 int read_pbm_int(QIODevice *d, bool *ok, int maxDigits=-1)
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, QByteArrayView 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 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]
manager head(request, this, [this](QRestReply &reply) { if(reply.isSuccess()) })
[6]