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

#include <qxpmhandler_p.h>

Inheritance diagram for QXpmHandler:
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...
 
 QXpmHandler ()
 
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)
 

Private Types

enum  State { Ready, ReadHeader, Error }
 

Private Functions

bool readHeader ()
 
bool readImage (QImage *image)
 

Properties

QByteArray buffer
 
int cpp
 
QString fileName
 
int height
 
int index
 
int ncols
 
State state
 
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 62 of file qxpmhandler_p.h.

Enumerations

◆ State

enum QXpmHandler::State
private
Enumerator
Ready 
ReadHeader 
Error 

Definition at line 81 of file qxpmhandler_p.h.

Constructors and Destructors

◆ QXpmHandler()

QXpmHandler::QXpmHandler ( )

Definition at line 1175 of file qxpmhandler.cpp.

1176  : state(Ready), index(0)
1177 {
1178 }

Functions

◆ canRead() [1/2]

bool QXpmHandler::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 1208 of file qxpmhandler.cpp.

Referenced by createReadHandlerHelper(), and read().

1209 {
1210  if (state == Ready && !canRead(device()))
1211  return false;
1212 
1213  if (state != Error) {
1214  setFormat("xpm");
1215  return true;
1216  }
1217 
1218  return false;
1219 }
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
bool canRead() const
Returns true if an image can be read from the device (i.
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

◆ canRead() [2/2]

bool QXpmHandler::canRead ( QIODevice device)
static

Definition at line 1221 of file qxpmhandler.cpp.

1222 {
1223  if (!device) {
1224  qWarning("QXpmHandler::canRead() called with no device");
1225  return false;
1226  }
1227 
1228  char head[6];
1229  if (device->peek(head, sizeof(head)) != sizeof(head))
1230  return false;
1231 
1232  return qstrncmp(head, "/* XPM", 6) == 0;
1233 }
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 *,...)
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101

◆ name()

QByteArray QXpmHandler::name ( ) const
virtual

Use format() instead.

Reimplemented from QImageIOHandler.

Definition at line 1288 of file qxpmhandler.cpp.

1289 {
1290  return "xpm";
1291 }

◆ option()

QVariant QXpmHandler::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 1254 of file qxpmhandler.cpp.

1255 {
1256  if (option == Name) {
1257  return fileName;
1258  } else if (option == Size) {
1259  if (state == Error)
1260  return QVariant();
1261  if (state == Ready && !const_cast<QXpmHandler*>(this)->readHeader())
1262  return QVariant();
1263  return QSize(width, height);
1264  } else if (option == ImageFormat) {
1265  if (state == Error)
1266  return QVariant();
1267  if (state == Ready && !const_cast<QXpmHandler*>(this)->readHeader())
1268  return QVariant();
1269  // If we have more than 256 colors in the table, we need to
1270  // figure out, if it contains transparency. That means reading
1271  // the whole color table, which is too much work work pre-checking
1272  // the image format
1273  if (ncols <= 256)
1274  return QImage::Format_Indexed8;
1275  else
1276  return QImage::Format_Invalid;
1277  }
1278 
1279  return QVariant();
1280 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool readHeader()
QString fileName
Definition: qxpmhandler_p.h:93
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ read()

bool QXpmHandler::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 1235 of file qxpmhandler.cpp.

1236 {
1237  if (!canRead())
1238  return false;
1239  return readImage(image);
1240 }
bool canRead() const
Returns true if an image can be read from the device (i.
bool readImage(QImage *image)

◆ readHeader()

bool QXpmHandler::readHeader ( )
private

Definition at line 1180 of file qxpmhandler.cpp.

Referenced by option(), and readImage().

1181 {
1182  state = Error;
1183  if (!read_xpm_header(device(), 0, index, buffer, &cpp, &ncols, &width, &height))
1184  return false;
1185  state = ReadHeader;
1186  return true;
1187 }
QByteArray buffer
Definition: qxpmhandler_p.h:91
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
static bool read_xpm_header(QIODevice *device, const char *const *source, int &index, QByteArray &state, int *cpp, int *ncols, int *w, int *h)

◆ readImage()

bool QXpmHandler::readImage ( QImage image)
private

Definition at line 1189 of file qxpmhandler.cpp.

Referenced by read().

1190 {
1191  if (state == Error)
1192  return false;
1193 
1194  if (state == Ready && !readHeader()) {
1195  state = Error;
1196  return false;
1197  }
1198 
1199  if (!read_xpm_body(device(), 0, index, buffer, cpp, ncols, width, height, *image)) {
1200  state = Error;
1201  return false;
1202  }
1203 
1204  state = Ready;
1205  return true;
1206 }
bool readHeader()
QByteArray buffer
Definition: qxpmhandler_p.h:91
static bool read_xpm_body(QIODevice *device, const char *const *source, int &index, QByteArray &state, int cpp, int ncols, int w, int h, QImage &image)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

◆ setOption()

void QXpmHandler::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 1282 of file qxpmhandler.cpp.

1283 {
1284  if (option == Name)
1285  fileName = value.toString();
1286 }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QString fileName
Definition: qxpmhandler_p.h:93
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ supportsOption()

bool QXpmHandler::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 1247 of file qxpmhandler.cpp.

1248 {
1249  return option == Name
1250  || option == Size
1251  || option == ImageFormat;
1252 }
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ write()

bool QXpmHandler::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 1242 of file qxpmhandler.cpp.

1243 {
1244  return write_xpm_image(image, device(), fileName);
1245 }
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.
static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const QString &fileName)
QString fileName
Definition: qxpmhandler_p.h:93

Properties

◆ buffer

QByteArray QXpmHandler::buffer
private

Definition at line 91 of file qxpmhandler_p.h.

Referenced by readHeader(), and readImage().

◆ cpp

int QXpmHandler::cpp
private

Definition at line 90 of file qxpmhandler_p.h.

Referenced by readHeader(), and readImage().

◆ fileName

QString QXpmHandler::fileName
private

Definition at line 93 of file qxpmhandler_p.h.

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

◆ height

int QXpmHandler::height
private

Definition at line 88 of file qxpmhandler_p.h.

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

◆ index

int QXpmHandler::index
private

Definition at line 92 of file qxpmhandler_p.h.

Referenced by readHeader(), and readImage().

◆ ncols

int QXpmHandler::ncols
private

Definition at line 89 of file qxpmhandler_p.h.

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

◆ state

State QXpmHandler::state
private

Definition at line 86 of file qxpmhandler_p.h.

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

◆ width

int QXpmHandler::width
private

Definition at line 87 of file qxpmhandler_p.h.

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


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