Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "argbplugin.h"
- #include "argbhandler.h"
- #include <QVariant>
- ArgbHandler::ArgbHandler()
- {
- }
- ArgbHandler::~ArgbHandler()
- {
- }
- bool ArgbHandler::canRead(QIODevice *device)
- {
- return device->peek(4) == "\xCA\xFE\x12\x34";
- }
- bool ArgbHandler::read(QImage *image)
- {
- QDataStream input(device());
- quint32 magic, width, height;
- input >> magic >> width >> height;
- if (input.status() != QDataStream::Ok || magic != 0xCAFE1234)
- return false;
- QImage result(width, height, QImage::Format_ARGB32);
- for (quint32 y = 0; y < height; ++y) {
- QRgb *scanLine = (QRgb *)result.scanLine(y);
- for (quint32 x = 0; x < width; ++x)
- input >> scanLine[x];
- }
- if (input.status() == QDataStream::Ok)
- *image = result;
- return input.status() == QDataStream::Ok;
- }
- bool ArgbHandler::write(const QImage &image)
- {
- QImage result = image.convertToFormat(QImage::Format_ARGB32);
- QDataStream output(device());
- quint32 magic = 0xCAFE1234;
- quint32 width = result.width();
- quint32 height = result.height();
- output << magic << width << height;
- for (quint32 y = 0; y < height; ++y) {
- QRgb *scanLine = (QRgb *)result.scanLine(y);
- for (quint32 x = 0; x < width; ++x)
- output << scanLine[x];
- }
- return output.status() == QDataStream::Ok;
- }
- bool ArgbHandler::supportsOption(ImageOption option) const
- {
- return option == Size;
- }
- QVariant ArgbHandler::option(ImageOption option) const
- {
- if (option == Size) {
- QByteArray bytes = device()->peek(12);
- QDataStream input(bytes);
- quint32 magic, width, height;
- input >> magic >> width >> height;
- if (input.status() == QDataStream::Ok && magic == 0xCAFE1234)
- return QSize(width, height);
- }
- return QVariant();
- }
- void ArgbHandler::setOption(ImageOption option, const QVariant &value)
- {
- if (option == QImageIOHandler::Gamma)
- {
- // this->Gamma = value.toDouble();
- // iluGammaCorrect(this->Gamma);
- }
- }
- /*
- void ArgbHandler::canRead()
- const
- {
- if(this->device() == 0);
- {
- qWarning("DevILHandler::canRead() called with no device");
- return false;
- }
- return ilIsValidL(IL_TYPE_UNKNOWN, this->Lump, this->Size);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement