![]() |
Qt 6.x
The Qt SDK
|
The QJp2Handler class provides support for reading and writing JPEG 2000 image files with the Qt plugin system. More...
#include <qjp2handler_p.h>
Public Member Functions | |
QJp2Handler () | |
Constructs an instance of QJp2Handler. | |
~QJp2Handler () | |
Destructor for QJp2Handler. | |
bool | canRead () const override |
\reimp | |
bool | read (QImage *image) override |
\reimp | |
bool | write (const QImage &image) override |
\reimp | |
QVariant | option (ImageOption option) const override |
Get the value associated with option. | |
void | setOption (ImageOption option, const QVariant &value) override |
The JPEG 2000 handler supports two options. | |
bool | supportsOption (ImageOption option) const override |
This function will return true if option is set to either QImageIOHandler::Quality or QImageIOHandler::Subtype. | |
![]() | |
QImageIOHandler () | |
Constructs a QImageIOHandler object. | |
virtual | ~QImageIOHandler () |
Destructs the QImageIOHandler object. | |
void | setDevice (QIODevice *device) |
Sets the device of the QImageIOHandler to device. | |
QIODevice * | device () const |
Returns the device currently assigned to the QImageIOHandler. | |
void | setFormat (const QByteArray &format) |
Sets the format of the QImageIOHandler to format. | |
void | setFormat (const QByteArray &format) const |
Sets the format of the QImageIOHandler to format. | |
QByteArray | format () const |
Returns the format that is currently assigned to QImageIOHandler. | |
virtual bool | canRead () const =0 |
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 . | |
virtual bool | read (QImage *image)=0 |
Read an image from the device, and stores it in image. | |
virtual bool | write (const QImage &image) |
Writes the image image to the assigned device. | |
virtual QVariant | option (ImageOption option) const |
Returns the value assigned to option as a QVariant. | |
virtual void | setOption (ImageOption option, const QVariant &value) |
Sets the option option with the value value. | |
virtual bool | supportsOption (ImageOption option) const |
Returns true if the QImageIOHandler supports the option option; otherwise returns false . | |
virtual bool | jumpToNextImage () |
For image formats that support animation, this function jumps to the next image. | |
virtual bool | jumpToImage (int imageNumber) |
For image formats that support animation, this function jumps to the image whose sequence number is imageNumber. | |
virtual int | loopCount () const |
For image formats that support animation, this function returns the number of times the animation should loop. | |
virtual int | imageCount () const |
For image formats that support animation, this function returns the number of images in the animation. | |
virtual int | nextImageDelay () const |
For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. | |
virtual int | currentImageNumber () const |
For image formats that support animation, this function returns the sequence number of the current image in the animation. | |
virtual QRect | currentImageRect () const |
Returns the rect of the current image. | |
Static Public Member Functions | |
static bool | canRead (QIODevice *iod, QByteArray *subType) |
Verifies if some values (magic bytes) are set as expected in the header of the file. | |
![]() | |
static bool | allocateImage (QSize size, QImage::Format format, QImage *image) |
The QJp2Handler class provides support for reading and writing JPEG 2000 image files with the Qt plugin system.
Currently, it only supports dynamically-loaded plugins.
JPEG files comes in two subtypes: the JPEG 2000 file format (.jp2) and the JPEG 2000 code stream format (
.j2k,
.jpc, or
.j2c). QJp2Handler can read and write both types.
To select a subtype, use the setOption() function with the QImageIOHandler::SubType option and a parameter value of "jp2" or "j2k".
To set the image quality when writing, you can use setOption() with the QImageIOHandler::Quality option, or QImageWriter::setQuality() if your are using a QImageWriter object to write the image. The image quality is specified as an int in the range 0 to 100. 0 means maximum compression and 99 means minimum compression. 100 selects lossless encoding, and this is the default value.
The JPEG handler is only available as a plugin, and this enables you to use normal QImage and QPixmap functions to read and write images. For example:
Definition at line 19 of file qjp2handler_p.h.
QJp2Handler::QJp2Handler | ( | ) |
Constructs an instance of QJp2Handler.
Definition at line 147 of file qjp2handler.cpp.
QJp2Handler::~QJp2Handler | ( | ) |
Destructor for QJp2Handler.
Definition at line 155 of file qjp2handler.cpp.
|
overridevirtual |
\reimp
Implements QImageIOHandler.
Definition at line 192 of file qjp2handler.cpp.
References canRead(), QImageIOHandler::device(), and QImageIOHandler::setFormat().
Referenced by canRead(), and QJp2Plugin::capabilities().
|
static |
Verifies if some values (magic bytes) are set as expected in the header of the file.
If the magic bytes were found, we assume that we can read the file. The function will assume that the iod is pointing to the beginning of the JPEG 2000 header. (i.e. it will for instance not seek to the beginning of a file before reading).
If subType is not 0, it will contain "jp2" or "j2k" upon successful return.
Definition at line 170 of file qjp2handler.cpp.
References header(), QIODevice::peek(), QByteArrayLiteral, and QString::startsWith().
|
overridevirtual |
Get the value associated with option.
Reimplemented from QImageIOHandler.
Definition at line 229 of file qjp2handler.cpp.
References d, QImageIOHandler::Quality, and QImageIOHandler::SubType.
|
overridevirtual |
\reimp
Implements QImageIOHandler.
Definition at line 204 of file qjp2handler.cpp.
References QImageIOHandler::device(), and QImageReader::read().
|
overridevirtual |
The JPEG 2000 handler supports two options.
Set option to QImageIOHandler::Quality to balance between quality and the compression level, where value should be an integer in the interval [0-100]. 0 is maximum compression (low quality) and 100 is lossless compression (high quality).
Set option to QImageIOHandler::Subtype to choose the subtype, where value should be a string equal to either "jp2" or "j2k"
Reimplemented from QImageIOHandler.
Definition at line 251 of file qjp2handler.cpp.
References d, ok, QByteArrayLiteral, QImageIOHandler::Quality, and QImageIOHandler::SubType.
|
overridevirtual |
This function will return true if option is set to either QImageIOHandler::Quality or QImageIOHandler::Subtype.
Reimplemented from QImageIOHandler.
Definition at line 272 of file qjp2handler.cpp.
References QImageIOHandler::Quality, and QImageIOHandler::SubType.
|
overridevirtual |
\reimp
Reimplemented from QImageIOHandler.
Definition at line 212 of file qjp2handler.cpp.
References d, QImageIOHandler::device(), J2kFormat, Jp2Format, and Jpeg2000JasperReader::write().