97 lines
2.0 KiB
C++
97 lines
2.0 KiB
C++
#include "sai_p.h"
|
|
|
|
#include "sai.hpp"
|
|
|
|
#include <QFile>
|
|
#include <QDebug>
|
|
#include <QImage>
|
|
|
|
SAIHandler::SAIHandler()
|
|
{
|
|
|
|
}
|
|
|
|
bool SAIHandler::canRead() const
|
|
{
|
|
if (canRead(device())) {
|
|
setFormat("sai");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool SAIHandler::read(QImage *image)
|
|
{
|
|
QFile * file = qobject_cast<QFile*>(device());
|
|
if (!file) {
|
|
return false;
|
|
}
|
|
|
|
sai::Document saiDoc(file->fileName().toUtf8().data());
|
|
if (!saiDoc.IsOpen()) {
|
|
qDebug() << "isOpen false";
|
|
return false;
|
|
}
|
|
|
|
std::uint32_t width, height;
|
|
std::unique_ptr<std::uint8_t[]> PixelData;
|
|
std::tie(PixelData, width, height) = saiDoc.GetThumbnail();
|
|
// std::uint32_t aw, ah;
|
|
// std::tie(aw, ah) = saiDoc.GetCanvasSize();
|
|
// qDebug() << width << height << aw << ah;
|
|
if( PixelData == nullptr || !width || !height ) {
|
|
return false;
|
|
}
|
|
|
|
const unsigned char * bytes = PixelData.get();
|
|
QImage img(bytes, static_cast<int>(width), static_cast<int>(height), QImage::Format_RGB32);
|
|
*image = img;
|
|
return true;
|
|
}
|
|
|
|
bool SAIHandler::write(const QImage &image)
|
|
{
|
|
Q_UNUSED(image)
|
|
return false;
|
|
}
|
|
|
|
bool SAIHandler::canRead(QIODevice *device)
|
|
{
|
|
if (!device) {
|
|
qWarning("SAIHandler::canRead() called with no device");
|
|
return false;
|
|
}
|
|
|
|
// FIXME: check
|
|
return true;
|
|
}
|
|
|
|
QImageIOPlugin::Capabilities SAIPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
|
{
|
|
if (format == "sai") {
|
|
return Capabilities(CanRead);
|
|
}
|
|
|
|
if (!format.isEmpty()) {
|
|
return {};
|
|
}
|
|
|
|
if (!device->isOpen()) {
|
|
return {};
|
|
}
|
|
|
|
Capabilities cap;
|
|
if (device->isReadable() && SAIHandler::canRead(device)) {
|
|
cap |= CanRead;
|
|
}
|
|
return cap;
|
|
}
|
|
|
|
QImageIOHandler *SAIPlugin::create(QIODevice *device, const QByteArray &format) const
|
|
{
|
|
QImageIOHandler *handler = new SAIHandler;
|
|
handler->setDevice(device);
|
|
handler->setFormat(format);
|
|
return handler;
|
|
}
|