Advertisement
Guest User

Untitled

a guest
Mar 9th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include "argbplugin.h"
  2. #include "argbhandler.h"
  3.  
  4. #include <QVariant>
  5.  
  6. ArgbHandler::ArgbHandler()
  7. {
  8.  
  9. }
  10.  
  11. ArgbHandler::~ArgbHandler()
  12. {
  13.  
  14. }
  15.  
  16. bool ArgbHandler::canRead(QIODevice *device)
  17. {
  18.     return device->peek(4) == "\xCA\xFE\x12\x34";
  19. }
  20.  
  21. bool ArgbHandler::read(QImage *image)
  22. {
  23.     QDataStream input(device());
  24.     quint32 magic, width, height;
  25.     input >> magic >> width >> height;
  26.     if (input.status() != QDataStream::Ok || magic != 0xCAFE1234)
  27.         return false;
  28.  
  29.     QImage result(width, height, QImage::Format_ARGB32);
  30.     for (quint32 y = 0; y < height; ++y) {
  31.         QRgb *scanLine = (QRgb *)result.scanLine(y);
  32.         for (quint32 x = 0; x < width; ++x)
  33.             input >> scanLine[x];
  34.     }
  35.     if (input.status() == QDataStream::Ok)
  36.         *image = result;
  37.     return input.status() == QDataStream::Ok;
  38. }
  39.  
  40. bool ArgbHandler::write(const QImage &image)
  41. {
  42.     QImage result = image.convertToFormat(QImage::Format_ARGB32);
  43.     QDataStream output(device());
  44.     quint32 magic = 0xCAFE1234;
  45.     quint32 width = result.width();
  46.     quint32 height = result.height();
  47.     output << magic << width << height;
  48.     for (quint32 y = 0; y < height; ++y) {
  49.         QRgb *scanLine = (QRgb *)result.scanLine(y);
  50.         for (quint32 x = 0; x < width; ++x)
  51.             output << scanLine[x];
  52.     }
  53.     return output.status() == QDataStream::Ok;
  54. }
  55.  
  56. bool ArgbHandler::supportsOption(ImageOption option) const
  57. {
  58.     return option == Size;
  59. }
  60.  
  61. QVariant ArgbHandler::option(ImageOption option) const
  62. {
  63.     if (option == Size) {
  64.         QByteArray bytes = device()->peek(12);
  65.         QDataStream input(bytes);
  66.         quint32 magic, width, height;
  67.         input >> magic >> width >> height;
  68.         if (input.status() == QDataStream::Ok && magic == 0xCAFE1234)
  69.             return QSize(width, height);
  70.     }
  71.     return QVariant();
  72. }
  73.  
  74. void ArgbHandler::setOption(ImageOption option, const QVariant &value)
  75. {
  76.     if (option == QImageIOHandler::Gamma)
  77.     {
  78.        // this->Gamma = value.toDouble();
  79.        // iluGammaCorrect(this->Gamma);
  80.     }
  81. }
  82. /*
  83. void ArgbHandler::canRead()
  84.         const
  85. {
  86.     if(this->device() == 0);
  87.     {
  88.         qWarning("DevILHandler::canRead() called with no device");
  89.         return false;
  90.     }
  91.  
  92.     return ilIsValidL(IL_TYPE_UNKNOWN, this->Lump, this->Size);
  93. }
  94. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement