Qt 4.8
Public Functions | Static Public Functions | Private Types | Private Functions | Properties | List of all members
QPpmHandler Class Reference

#include <qppmhandler_p.h>

Inheritance diagram for QPpmHandler:
QImageIOHandler

Public Functions

bool canRead () const
 Returns true if an image can be read from the device (i. More...
 
QByteArray name () const
 Use format() instead. More...
 
QVariant option (ImageOption option) const
 Returns the value assigned to option as a QVariant. More...
 
 QPpmHandler ()
 
bool read (QImage *image)
 Read an image from the device, and stores it in image. More...
 
void setOption (ImageOption option, const QVariant &value)
 Sets the option option with the value value. More...
 
bool supportsOption (ImageOption option) const
 Returns true if the QImageIOHandler supports the option option; otherwise returns false. More...
 
bool write (const QImage &image)
 Writes the image image to the assigned device. More...
 
- Public Functions inherited from QImageIOHandler
virtual int currentImageNumber () const
 For image formats that support animation, this function returns the sequence number of the current image in the animation. More...
 
virtual QRect currentImageRect () const
 Returns the rect of the current image. More...
 
QIODevicedevice () const
 Returns the device currently assigned to the QImageIOHandler. More...
 
QByteArray format () const
 Returns the format that is currently assigned to QImageIOHandler. More...
 
virtual int imageCount () const
 For image formats that support animation, this function returns the number of images in the animation. More...
 
virtual bool jumpToImage (int imageNumber)
 For image formats that support animation, this function jumps to the image whose sequence number is imageNumber. More...
 
virtual bool jumpToNextImage ()
 For image formats that support animation, this function jumps to the next image. More...
 
virtual int loopCount () const
 For image formats that support animation, this function returns the number of times the animation should loop. More...
 
virtual int nextImageDelay () const
 For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. More...
 
 QImageIOHandler ()
 Constructs a QImageIOHandler object. More...
 
void setDevice (QIODevice *device)
 Sets the device of the QImageIOHandler to device. More...
 
void setFormat (const QByteArray &format)
 Sets the format of the QImageIOHandler to format. More...
 
void setFormat (const QByteArray &format) const
 Sets the format of the QImageIOHandler to format. More...
 
virtual ~QImageIOHandler ()
 Destructs the QImageIOHandler object. More...
 

Static Public Functions

static bool canRead (QIODevice *device, QByteArray *subType=0)
 

Private Types

enum  State { Ready, ReadHeader, Error }
 

Private Functions

bool readHeader ()
 

Properties

int height
 
int mcc
 
State state
 
QByteArray subType
 
char type
 
int width
 

Additional Inherited Members

- Public Types inherited from QImageIOHandler
enum  ImageOption {
  Size, ClipRect, Description, ScaledClipRect,
  ScaledSize, CompressionRatio, Gamma, Quality,
  Name, SubType, IncrementalReading, Endianness,
  Animation, BackgroundColor, ImageFormat
}
 This enum describes the different options supported by QImageIOHandler. More...
 
- Protected Functions inherited from QImageIOHandler
 QImageIOHandler (QImageIOHandlerPrivate &dd)
 Constructs a QImageIOHandler object, using the private member dd. More...
 
- Protected Variables inherited from QImageIOHandler
QScopedPointer< QImageIOHandlerPrivated_ptr
 

Detailed Description

Definition at line 63 of file qppmhandler_p.h.

Enumerations

◆ State

enum QPpmHandler::State
private
Enumerator
Ready 
ReadHeader 
Error 

Definition at line 81 of file qppmhandler_p.h.

Constructors and Destructors

◆ QPpmHandler()

QPpmHandler::QPpmHandler ( )

Definition at line 396 of file qppmhandler.cpp.

397  : state(Ready)
398 {
399 }

Functions

◆ canRead() [1/2]

bool QPpmHandler::canRead ( ) const
virtual

Returns true if an image can be read from the device (i.

e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false.

When reimplementing canRead(), make sure that the I/O device (device()) is left in its original state (e.g., by using peek() rather than read()).

See also
read(), QIODevice::peek()

Implements QImageIOHandler.

Definition at line 410 of file qppmhandler.cpp.

Referenced by createReadHandlerHelper().

411 {
412  if (state == Ready && !canRead(device(), &subType))
413  return false;
414 
415  if (state != Error) {
417  return true;
418  }
419 
420  return false;
421 }
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
QByteArray subType
Definition: qppmhandler_p.h:91
bool canRead() const
Returns true if an image can be read from the device (i.

◆ canRead() [2/2]

bool QPpmHandler::canRead ( QIODevice device,
QByteArray subType = 0 
)
static

Definition at line 423 of file qppmhandler.cpp.

424 {
425  if (!device) {
426  qWarning("QPpmHandler::canRead() called with no device");
427  return false;
428  }
429 
430  char head[2];
431  if (device->peek(head, sizeof(head)) != sizeof(head))
432  return false;
433 
434  if (head[0] != 'P')
435  return false;
436 
437  if (head[1] == '1' || head[1] == '4') {
438  if (subType)
439  *subType = "pbm";
440  } else if (head[1] == '2' || head[1] == '5') {
441  if (subType)
442  *subType = "pgm";
443  } else if (head[1] == '3' || head[1] == '6') {
444  if (subType)
445  *subType = "ppm";
446  } else {
447  return false;
448  }
449  return true;
450 }
qint64 peek(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, without side effects (i.
Definition: qiodevice.cpp:1563
Q_CORE_EXPORT void qWarning(const char *,...)

◆ name()

QByteArray QPpmHandler::name ( ) const
virtual

Use format() instead.

Reimplemented from QImageIOHandler.

Definition at line 526 of file qppmhandler.cpp.

527 {
528  return subType.isEmpty() ? QByteArray("ppm") : subType;
529 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QByteArray subType
Definition: qppmhandler_p.h:91

◆ option()

QVariant QPpmHandler::option ( ImageOption  option) const
virtual

Returns the value assigned to option as a QVariant.

The type of the value depends on the option. For example, option(Size) returns a QSize variant.

See also
setOption(), supportsOption()

Reimplemented from QImageIOHandler.

Definition at line 483 of file qppmhandler.cpp.

484 {
485  if (option == SubType) {
486  return subType;
487  } else if (option == Size) {
488  if (state == Error)
489  return QVariant();
490  if (state == Ready && !const_cast<QPpmHandler*>(this)->readHeader())
491  return QVariant();
492  return QSize(width, height);
493  } else if (option == ImageFormat) {
494  if (state == Error)
495  return QVariant();
496  if (state == Ready && !const_cast<QPpmHandler*>(this)->readHeader())
497  return QVariant();
499  switch (type) {
500  case '1': // ascii PBM
501  case '4': // raw PBM
502  format = QImage::Format_Mono;
503  break;
504  case '2': // ascii PGM
505  case '5': // raw PGM
506  format = QImage::Format_Indexed8;
507  break;
508  case '3': // ascii PPM
509  case '6': // raw PPM
510  format = QImage::Format_RGB32;
511  break;
512  default:
513  break;
514  }
515  return format;
516  }
517  return QVariant();
518 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
Format
The following image formats are available in Qt.
Definition: qimage.h:91
bool readHeader()
QByteArray format() const
Returns the format that is currently assigned to QImageIOHandler.
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QByteArray subType
Definition: qppmhandler_p.h:91

◆ read()

bool QPpmHandler::read ( QImage image)
virtual

Read an image from the device, and stores it in image.

Returns true if the image is successfully read; otherwise returns false.

For image formats that support incremental loading, and for animation formats, the image handler can assume that image points to the previous frame.

See also
canRead()

Implements QImageIOHandler.

Definition at line 452 of file qppmhandler.cpp.

453 {
454  if (state == Error)
455  return false;
456 
457  if (state == Ready && !readHeader()) {
458  state = Error;
459  return false;
460  }
461 
462  if (!read_pbm_body(device(), type, width, height, mcc, image)) {
463  state = Error;
464  return false;
465  }
466 
467  state = Ready;
468  return true;
469 }
bool readHeader()
static bool read_pbm_body(QIODevice *device, char type, int w, int h, int mcc, QImage *outImage)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

◆ readHeader()

bool QPpmHandler::readHeader ( )
private

Definition at line 401 of file qppmhandler.cpp.

Referenced by option(), and read().

402 {
403  state = Error;
405  return false;
406  state = ReadHeader;
407  return true;
408 }
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
static bool read_pbm_header(QIODevice *device, char &type, int &w, int &h, int &mcc)
Definition: qppmhandler.cpp:90

◆ setOption()

void QPpmHandler::setOption ( ImageOption  option,
const QVariant value 
)
virtual

Sets the option option with the value value.

See also
option(), ImageOption

Reimplemented from QImageIOHandler.

Definition at line 520 of file qppmhandler.cpp.

521 {
522  if (option == SubType)
523  subType = value.toByteArray().toLower();
524 }
QByteArray toLower() const
Returns a lowercase copy of the byte array.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
QByteArray subType
Definition: qppmhandler_p.h:91

◆ supportsOption()

bool QPpmHandler::supportsOption ( ImageOption  option) const
virtual

Returns true if the QImageIOHandler supports the option option; otherwise returns false.

For example, if the QImageIOHandler supports the Size option, supportsOption(Size) must return true.

See also
setOption(), option()

Reimplemented from QImageIOHandler.

Definition at line 476 of file qppmhandler.cpp.

477 {
478  return option == SubType
479  || option == Size
480  || option == ImageFormat;
481 }
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ write()

bool QPpmHandler::write ( const QImage image)
virtual

Writes the image image to the assigned device.

Returns true on success; otherwise returns false.

The default implementation does nothing, and simply returns false.

Reimplemented from QImageIOHandler.

Definition at line 471 of file qppmhandler.cpp.

472 {
473  return write_pbm_image(device(), image, subType);
474 }
static bool write_pbm_image(QIODevice *out, const QImage &sourceImage, const QByteArray &sourceFormat)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
QByteArray subType
Definition: qppmhandler_p.h:91

Properties

◆ height

int QPpmHandler::height
private

Definition at line 89 of file qppmhandler_p.h.

Referenced by option(), read(), and readHeader().

◆ mcc

int QPpmHandler::mcc
private

Definition at line 90 of file qppmhandler_p.h.

Referenced by read(), and readHeader().

◆ state

State QPpmHandler::state
private

Definition at line 86 of file qppmhandler_p.h.

Referenced by canRead(), option(), read(), and readHeader().

◆ subType

QByteArray QPpmHandler::subType
mutableprivate

Definition at line 91 of file qppmhandler_p.h.

Referenced by canRead(), name(), option(), setOption(), and write().

◆ type

char QPpmHandler::type
private

Definition at line 87 of file qppmhandler_p.h.

Referenced by option(), read(), and readHeader().

◆ width

int QPpmHandler::width
private

Definition at line 88 of file qppmhandler_p.h.

Referenced by option(), read(), and readHeader().


The documentation for this class was generated from the following files: