Qt 4.8
Public Functions | Static Public Functions | Properties | List of all members
QPngHandler Class Reference

#include <qpnghandler_p.h>

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

Properties

QPngHandlerPrivated
 

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 qpnghandler_p.h.

Constructors and Destructors

◆ QPngHandler()

QPngHandler::QPngHandler ( )

Definition at line 927 of file qpnghandler.cpp.

928  : d(new QPngHandlerPrivate(this))
929 {
930 }
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82

◆ ~QPngHandler()

QPngHandler::~QPngHandler ( )

Definition at line 932 of file qpnghandler.cpp.

933 {
934  if (d->png_ptr)
935  png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_info);
936  delete d;
937 }
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
png_struct * png_ptr

Functions

◆ canRead() [1/2]

bool QPngHandler::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 939 of file qpnghandler.cpp.

Referenced by createReadHandlerHelper(), and read().

940 {
942  return false;
943 
945  setFormat("png");
946  return true;
947  }
948 
949  return false;
950 }
void setFormat(const QByteArray &format)
Sets the format of the QImageIOHandler to format.
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
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 QPngHandler::canRead ( QIODevice device)
static

Definition at line 952 of file qpnghandler.cpp.

953 {
954  if (!device) {
955  qWarning("QPngHandler::canRead() called with no device");
956  return false;
957  }
958 
959  return device->peek(8) == "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
960 }
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 QPngHandler::name ( ) const
virtual

Use format() instead.

Reimplemented from QImageIOHandler.

Definition at line 1014 of file qpnghandler.cpp.

1015 {
1016  return "png";
1017 }

◆ option()

QVariant QPngHandler::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 983 of file qpnghandler.cpp.

984 {
986  return QVariant();
988  return QVariant();
989 
990  if (option == Gamma)
991  return d->gamma;
992  else if (option == Quality)
993  return d->quality;
994  else if (option == Description)
995  return d->description;
996  else if (option == Size)
997  return QSize(png_get_image_width(d->png_ptr, d->info_ptr),
998  png_get_image_height(d->png_ptr, d->info_ptr));
999  else if (option == ImageFormat)
1000  return d->readImageFormat();
1001  return 0;
1002 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
QImage::Format readImageFormat()
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
png_struct * png_ptr
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ read()

bool QPngHandler::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 962 of file qpnghandler.cpp.

963 {
964  if (!canRead())
965  return false;
966  return d->readPngImage(image);
967 }
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
bool readPngImage(QImage *image)
bool canRead() const
Returns true if an image can be read from the device (i.

◆ setOption()

void QPngHandler::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 1004 of file qpnghandler.cpp.

1005 {
1006  if (option == Gamma)
1007  d->gamma = value.toFloat();
1008  else if (option == Quality)
1009  d->quality = value.toInt();
1010  else if (option == Description)
1011  d->description = value.toString();
1012 }
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.
float toFloat(bool *ok=0) const
Returns the variant as a float if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2725

◆ supportsOption()

bool QPngHandler::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 974 of file qpnghandler.cpp.

975 {
976  return option == Gamma
977  || option == Description
978  || option == ImageFormat
979  || option == Quality
980  || option == Size;
981 }
QVariant option(ImageOption option) const
Returns the value assigned to option as a QVariant.

◆ write()

bool QPngHandler::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 969 of file qpnghandler.cpp.

970 {
971  return write_png_image(image, device(), d->quality, d->gamma, d->description);
972 }
QPngHandlerPrivate * d
Definition: qpnghandler_p.h:82
static bool write_png_image(const QImage &image, QIODevice *device, int quality, float gamma, const QString &description)
QIODevice * device() const
Returns the device currently assigned to the QImageIOHandler.

Properties

◆ d

QPngHandlerPrivate* QPngHandler::d
private

Definition at line 82 of file qpnghandler_p.h.

Referenced by canRead(), option(), read(), setOption(), write(), and ~QPngHandler().


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