42 #include "private/qppmhandler_p.h" 44 #ifndef QT_NO_IMAGEFORMAT_PPM 62 const int buflen = 100;
67 digit = isdigit((
uchar) c);
70 val = 10*val + c -
'0';
80 else if (isspace((
uchar) c))
93 if (device->
read(buf, 3) != 3)
96 if (!(buf[0] ==
'P' && isdigit((
uchar) buf[1]) && isspace((
uchar) buf[2])))
100 if (type < '1' || type >
'6')
106 if (type ==
'1' || type ==
'4')
111 if (w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0)
149 *outImage =
QImage(w, h, format);
154 pbm_bpl = (nbits*w+7)/8;
158 pbm_bpl = mcc < 256 ? 3*w : 6*w;
162 for (y=0; y<h; y++) {
163 if (device->
read((
char *)buf24, pbm_bpl) != pbm_bpl) {
172 *p++ =
qRgb(b[0],b[1],b[2]);
175 *p++ =
qRgb(((
int(b[0]) * 256 +
int(b[1]) + 1) * 256) / (mcc + 1) - 1,
176 ((
int(b[2]) * 256 +
int(b[3]) + 1) * 256) / (mcc + 1) - 1,
177 ((
int(b[4]) * 256 +
int(b[5]) + 1) * 256) / (mcc + 1) - 1);
184 for (y=0; y<h; y++) {
185 if (device->
read((
char *)outImage->
scanLine(y), pbm_bpl)
193 for (y=0; y<h; y++) {
201 for (
int i=0; i<8; i++) {
205 b = (b << 1) | (0 & 1);
210 }
else if (nbits == 8) {
248 }
else if (nbits == 8) {
250 for (
int i=0; i<=maxc; i++)
251 outImage->
setColor(i,
qRgb(i*255/maxc,i*255/maxc,i*255/maxc));
260 QImage image = sourceImage;
263 format = format.
left(3);
264 bool gray = format ==
"pgm";
266 if (format ==
"pbm") {
268 }
else if (image.
depth() == 1) {
294 for (
int y=0; y<image.
height(); y++) {
312 switch (image.
depth()) {
318 for (
uint y=0; y<h; y++) {
320 if (w != (
uint)out->
write((
char*)line, w))
327 str.
insert(1, gray ?
'5' :
'6');
332 uint bpl = w*(gray ? 1 : 3);
334 for (
uint y=0; y<h; y++) {
351 if (bpl != (
uint)out->
write((
char*)buf, bpl))
359 str.
insert(1, gray ?
'5' :
'6');
363 uint bpl = w*(gray ? 1 : 3);
365 for (
uint y=0; y<h; y++) {
382 if (bpl != (
uint)out->
write((
char*)buf, bpl))
426 qWarning(
"QPpmHandler::canRead() called with no device");
431 if (device->
peek(head,
sizeof(head)) !=
sizeof(head))
437 if (head[1] ==
'1' || head[1] ==
'4') {
440 }
else if (head[1] ==
'2' || head[1] ==
'5') {
443 }
else if (head[1] ==
'3' || head[1] ==
'6') {
487 }
else if (option ==
Size) {
533 #endif // QT_NO_IMAGEFORMAT_PPM The QVariant class acts like a union for the most common Qt data types.
bool supportsOption(ImageOption option) const
Returns true if the QImageIOHandler supports the option option; otherwise returns false...
static int read_pbm_int(QIODevice *d)
Format
The following image formats are available in Qt.
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
#define QT_END_NAMESPACE
This macro expands to.
QByteArray & append(char c)
Appends the character ch to this byte array.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
The QByteArray class provides an array of bytes.
bool getChar(char *c)
Reads one character from the device and stores it in c.
QByteArray toLower() const
Returns a lowercase copy of the byte array.
int bytesPerLine() const
Returns the number of bytes per image scanline.
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Format format() const
Returns the format of the image.
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
void setColorCount(int)
Resizes the color table to contain colorCount entries.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QByteArray name() const
Use format() instead.
ImageOption
This enum describes the different options supported by QImageIOHandler.
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
void detach()
If multiple images share common data, this image makes a copy of the data and detaches itself from th...
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
int qGray(int r, int g, int b)
bool write(const QImage &image)
Writes the image image to the assigned device.
int depth() const
Returns the depth of the image.
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage)
QSize size() const
Returns the size of the image, i.
int length() const
Same as size().
QRgb qRgb(int r, int g, int b)
Returns the ARGB quadruplet (255, {r}, {g}, {b}).
int width() const
Returns the width of the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
qint64 readLine(char *data, qint64 maxlen)
This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes...
int colorCount() const
Returns the size of the color table for the image.
bool read(QImage *image)
Read an image from the device, and stores it in image.
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
int height() const
Returns the height of the image.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QSize class defines the size of a two-dimensional object using integer point precision.
void setOption(ImageOption option, const QVariant &value)
Sets the option option with the value value.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
static const KeyPair *const end
The QIODevice class is the base interface class of all I/O devices in Qt.
bool canRead() const
Returns true if an image can be read from the device (i.
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
QRgb color(int i) const
Returns the color in the color table at index i.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
static bool read_pbm_header(QIODevice *device, char &type, int &w, int &h, int &mcc)
QByteArray & insert(int i, char c)
Inserts character ch at index position i in the byte array.