Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QJp2Handler Class Reference

The QJp2Handler class provides support for reading and writing JPEG 2000 image files with the Qt plugin system. More...

#include <qjp2handler_p.h>

+ Inheritance diagram for QJp2Handler:
+ Collaboration diagram for QJp2Handler:

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.
 
- Public Member Functions inherited from QImageIOHandler
 QImageIOHandler ()
 Constructs a QImageIOHandler object.
 
virtual ~QImageIOHandler ()
 Destructs the QImageIOHandler object.
 
void setDevice (QIODevice *device)
 Sets the device of the QImageIOHandler to device.
 
QIODevicedevice () 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 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 Public Member Functions inherited from QImageIOHandler
static bool allocateImage (QSize size, QImage::Format format, QImage *image)
 

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 , SupportedSubTypes ,
  OptimizedWrite , ProgressiveScanWrite , ImageTransformation
}
 This enum describes the different options supported by QImageIOHandler. More...
 
enum  Transformation {
  TransformationNone = 0 , TransformationMirror = 1 , TransformationFlip = 2 , TransformationRotate180 = TransformationMirror | TransformationFlip ,
  TransformationRotate90 = 4 , TransformationMirrorAndRotate90 = TransformationMirror | TransformationRotate90 , TransformationFlipAndRotate90 = TransformationFlip | TransformationRotate90 , TransformationRotate270 = TransformationRotate180 | TransformationRotate90
}
 
- Protected Member Functions inherited from QImageIOHandler
 QImageIOHandler (QImageIOHandlerPrivate &dd)
 
- Protected Attributes inherited from QImageIOHandler
QScopedPointer< QImageIOHandlerPrivated_ptr
 

Detailed Description

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:

myLabel->setPixmap(QPixmap("myimage.jp2"));
QPixmap myPixmap;
myPixmap.save("myimage.jp2", "JP2");
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
bool save(const QString &fileName, const char *format=nullptr, int quality=-1) const
Saves the pixmap to the file with the given fileName using the specified image file format and qualit...
Definition qpixmap.cpp:807

Definition at line 19 of file qjp2handler_p.h.

Constructor & Destructor Documentation

◆ QJp2Handler()

QJp2Handler::QJp2Handler ( )

Constructs an instance of QJp2Handler.

Definition at line 147 of file qjp2handler.cpp.

◆ ~QJp2Handler()

QJp2Handler::~QJp2Handler ( )

Destructor for QJp2Handler.

Definition at line 155 of file qjp2handler.cpp.

Member Function Documentation

◆ canRead() [1/2]

bool QJp2Handler::canRead ( ) const
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ canRead() [2/2]

bool QJp2Handler::canRead ( QIODevice * iod,
QByteArray * subType )
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(), QByteArray(), and QByteArrayLiteral.

+ Here is the call graph for this function:

◆ option()

QVariant QJp2Handler::option ( ImageOption option) const
overridevirtual

Get the value associated with option.

See also
setOption()

Reimplemented from QImageIOHandler.

Definition at line 229 of file qjp2handler.cpp.

References d, QImageIOHandler::Quality, and QImageIOHandler::SubType.

◆ read()

bool QJp2Handler::read ( QImage * image)
overridevirtual

\reimp

Implements QImageIOHandler.

Definition at line 204 of file qjp2handler.cpp.

References QImageIOHandler::device(), and QImageReader::read().

+ Here is the call graph for this function:

◆ setOption()

void QJp2Handler::setOption ( ImageOption option,
const QVariant & value )
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"

See also
option()

Reimplemented from QImageIOHandler.

Definition at line 251 of file qjp2handler.cpp.

References d, ok, QByteArrayLiteral, QImageIOHandler::Quality, and QImageIOHandler::SubType.

◆ supportsOption()

bool QJp2Handler::supportsOption ( ImageOption option) const
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.

◆ write()

bool QJp2Handler::write ( const QImage & image)
overridevirtual

\reimp

Reimplemented from QImageIOHandler.

Definition at line 212 of file qjp2handler.cpp.

References d, QImageIOHandler::device(), J2kFormat, and Jp2Format.

+ Here is the call graph for this function:

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