mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-06-03 17:08:08 -04:00
Highlights of the patch: - Supersede MR !249 - Added FP16 and FP32 images support thus preserving HDR values (read / write, required libjxl 0.9+). - Added Gray8 and Gray16 support (read / write). - Indexed images are saved as Gray8 when palette is gray scale. - Binary images are saved as Gray8 (does JXL natively support binary images?). - Simplified writing process by partially removing the use of additional buffers. - Added XMP metadata support by decoding/encoding Boxes. - Changed maximum image size in pixels in accordance with JXL feature level 5 (still limited to 256 megapixels). Compatibility: - Older versions of this plugin load FP images correctly as UINT16 (obviously losing HDR info). - HDR images saved with this patch are also loaded correctly by Gimp and Photoshop. - Grayscale images saved with this patch are also loaded correctly by Gimp and Photoshop. Compilation modifiers for cmake file: - `JXL_HDR_PRESERVATION_DISABLED`: disable the FP support (behaves like previous versions). - `JXL_DECODE_BOXES_DISABLED`: disable metadata reading (behaves like previous versions).
101 lines
2.4 KiB
C++
101 lines
2.4 KiB
C++
/*
|
|
JPEG XL (JXL) support for QImage.
|
|
|
|
SPDX-FileCopyrightText: 2021 Daniel Novomesky <dnovomesky@gmail.com>
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#ifndef KIMG_JXL_P_H
|
|
#define KIMG_JXL_P_H
|
|
|
|
#include <QByteArray>
|
|
#include <QColorSpace>
|
|
#include <QImage>
|
|
#include <QImageIOHandler>
|
|
#include <QImageIOPlugin>
|
|
#include <QList>
|
|
#include <QVariant>
|
|
|
|
#include <jxl/decode.h>
|
|
|
|
class QJpegXLHandler : public QImageIOHandler
|
|
{
|
|
public:
|
|
QJpegXLHandler();
|
|
~QJpegXLHandler();
|
|
|
|
bool canRead() const override;
|
|
bool read(QImage *image) override;
|
|
bool write(const QImage &image) override;
|
|
|
|
static bool canRead(QIODevice *device);
|
|
|
|
QVariant option(ImageOption option) const override;
|
|
void setOption(ImageOption option, const QVariant &value) override;
|
|
bool supportsOption(ImageOption option) const override;
|
|
|
|
int imageCount() const override;
|
|
int currentImageNumber() const override;
|
|
bool jumpToNextImage() override;
|
|
bool jumpToImage(int imageNumber) override;
|
|
|
|
int nextImageDelay() const override;
|
|
|
|
int loopCount() const override;
|
|
|
|
private:
|
|
bool ensureParsed() const;
|
|
bool ensureALLCounted() const;
|
|
bool ensureDecoder();
|
|
bool countALLFrames();
|
|
bool decode_one_frame();
|
|
bool rewind();
|
|
bool decodeBoxes();
|
|
|
|
enum ParseJpegXLState {
|
|
ParseJpegXLError = -1,
|
|
ParseJpegXLNotParsed = 0,
|
|
ParseJpegXLSuccess = 1,
|
|
ParseJpegXLBasicInfoParsed = 2,
|
|
ParseJpegXLFinished = 3,
|
|
};
|
|
|
|
ParseJpegXLState m_parseState;
|
|
int m_quality;
|
|
int m_currentimage_index;
|
|
int m_previousimage_index;
|
|
QImageIOHandler::Transformations m_transformations;
|
|
|
|
QByteArray m_rawData;
|
|
|
|
JxlDecoder *m_decoder;
|
|
void *m_runner;
|
|
JxlBasicInfo m_basicinfo;
|
|
|
|
QList<int> m_framedelays;
|
|
int m_next_image_delay;
|
|
|
|
QImage m_current_image;
|
|
QColorSpace m_colorspace;
|
|
QByteArray m_xmp;
|
|
|
|
QImage::Format m_input_image_format;
|
|
QImage::Format m_target_image_format;
|
|
|
|
JxlPixelFormat m_input_pixel_format;
|
|
size_t m_buffer_size;
|
|
};
|
|
|
|
class QJpegXLPlugin : public QImageIOPlugin
|
|
{
|
|
Q_OBJECT
|
|
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "jxl.json")
|
|
|
|
public:
|
|
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
|
|
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
|
|
};
|
|
|
|
#endif // KIMG_JXL_P_H
|