mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kimgio: implement size option for tiff plugin
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
b3e9998d8c
commit
5365b4788e
2 changed files with 79 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include "tiff.h"
|
#include "tiff.h"
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QVariant>
|
||||||
#include <kdebug.h>
|
#include <kdebug.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -348,6 +349,81 @@ QByteArray TIFFHandler::name() const
|
||||||
return s_tiffpluginformat;
|
return s_tiffpluginformat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TIFFHandler::supportsOption(QImageIOHandler::ImageOption option) const
|
||||||
|
{
|
||||||
|
switch (option) {
|
||||||
|
case QImageIOHandler::Size: {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant TIFFHandler::option(QImageIOHandler::ImageOption option) const
|
||||||
|
{
|
||||||
|
switch (option) {
|
||||||
|
case QImageIOHandler::Size: {
|
||||||
|
const qint64 devicepos = device()->pos();
|
||||||
|
|
||||||
|
s_tifferrorhandler = TIFFSetErrorHandler(tiff_error_handler);
|
||||||
|
s_tiffwarninghandler = TIFFSetWarningHandler(tiff_warning_handler);
|
||||||
|
|
||||||
|
TIFF* tiffclient = TIFFClientOpen(
|
||||||
|
"TIFFHandler", "r",
|
||||||
|
device(),
|
||||||
|
tiff_read_proc,
|
||||||
|
tiff_write_proc,
|
||||||
|
tiff_seek_proc,
|
||||||
|
tiff_close_proc,
|
||||||
|
tiff_size_proc,
|
||||||
|
tiff_mapfile_proc,
|
||||||
|
tiff_unmapfile_proc
|
||||||
|
);
|
||||||
|
if (!Q_UNLIKELY(tiffclient)) {
|
||||||
|
kWarning() << "Could not open client";
|
||||||
|
TIFFSetErrorHandler(s_tifferrorhandler);
|
||||||
|
TIFFSetWarningHandler(s_tiffwarninghandler);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t tiffwidth = 0;
|
||||||
|
int tiffresult = TIFFGetField(tiffclient, TIFFTAG_IMAGEWIDTH, &tiffwidth);
|
||||||
|
if (Q_UNLIKELY(tiffresult != 1)) {
|
||||||
|
kWarning() << "Could not get image width";
|
||||||
|
TIFFClose(tiffclient);
|
||||||
|
TIFFSetErrorHandler(s_tifferrorhandler);
|
||||||
|
TIFFSetWarningHandler(s_tiffwarninghandler);
|
||||||
|
device()->seek(devicepos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t tiffheight = 0;
|
||||||
|
tiffresult = TIFFGetField(tiffclient, TIFFTAG_IMAGELENGTH, &tiffheight);
|
||||||
|
if (Q_UNLIKELY(tiffresult != 1)) {
|
||||||
|
kWarning() << "Could not get image length";
|
||||||
|
TIFFClose(tiffclient);
|
||||||
|
TIFFSetErrorHandler(s_tifferrorhandler);
|
||||||
|
TIFFSetWarningHandler(s_tiffwarninghandler);
|
||||||
|
device()->seek(devicepos);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TIFFClose(tiffclient);
|
||||||
|
TIFFSetErrorHandler(s_tifferrorhandler);
|
||||||
|
TIFFSetWarningHandler(s_tiffwarninghandler);
|
||||||
|
device()->seek(devicepos);
|
||||||
|
return QVariant(QSize(tiffwidth, tiffheight));
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Q_UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
bool TIFFHandler::canRead(QIODevice *device)
|
bool TIFFHandler::canRead(QIODevice *device)
|
||||||
{
|
{
|
||||||
if (Q_UNLIKELY(!device)) {
|
if (Q_UNLIKELY(!device)) {
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
|
|
||||||
QByteArray name() const final;
|
QByteArray name() const final;
|
||||||
|
|
||||||
|
bool supportsOption(QImageIOHandler::ImageOption option) const final;
|
||||||
|
QVariant option(QImageIOHandler::ImageOption option) const final;
|
||||||
|
|
||||||
static bool canRead(QIODevice *device);
|
static bool canRead(QIODevice *device);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue