Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scimgdataloader_gimp.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include <qfile.h>
00008 #include <qfileinfo.h>
00009 #include "scimgdataloader_gimp.h"
00010 
00011 ScImgDataLoader_GIMP::ScImgDataLoader_GIMP(void) : ScImgDataLoader()
00012 {
00013        initSupportedFormatList();
00014 }
00015 
00016 void ScImgDataLoader_GIMP::initSupportedFormatList(void)
00017 {
00018        m_supportedFormats.clear();
00019        m_supportedFormats.append( "pat" );
00020 }
00021 
00022 void ScImgDataLoader_GIMP::loadEmbeddedProfile(const QString& fn)
00023 {
00024        m_embeddedProfile.resize(0);
00025        m_profileComponents = 0;
00026 }
00027 
00028 bool ScImgDataLoader_GIMP::loadPicture(const QString& fn, int /*res*/, bool /*thumbnail*/)
00029 {
00030        if (!QFile::exists(fn))
00031               return false;
00032        initialize();
00033        QFile f(fn);
00034        if (f.open(IO_ReadOnly))
00035        {
00036               QDataStream s( &f );
00037               s.setByteOrder( QDataStream::BigEndian );
00038               uint headersize, versionInfo, patternWidth, patternHeight, patternType;
00039               uchar chData, alpha, r, g, b;
00040               uchar magicKey[4];
00041               s >> headersize;
00042               s >> versionInfo;
00043               s >> patternWidth;
00044               s >> patternHeight;
00045               s >> patternType;
00046               QString magic = "";
00047               for( int i = 0; i < 4; i++ )
00048               {
00049                      s >> magicKey[i];
00050                      magic += QChar(magicKey[i]);
00051               }
00052               if (magic != "GPAT")
00053                      return false;
00054               s.device()->at( headersize );
00055               if( !m_image.create( patternWidth, patternHeight, 32 ))
00056                      return false;
00057               m_image.setAlphaBuffer( true );
00058               QRgb *d;
00059               for (uint y = 0; y < patternHeight; y++)
00060               {
00061                      d = (QRgb*)(m_image.scanLine( y ));
00062                      if (patternType == 1)
00063                      {
00064                             for (uint x = 0; x < patternWidth; x++)
00065                             {
00066                                    s >> chData;
00067                                    *d = qRgba(chData, chData, chData, 255);
00068                                    d++;
00069                             }
00070                      }
00071                      else if (patternType == 2)
00072                      {
00073                             for (uint x = 0; x < patternWidth; x++)
00074                             {
00075                                    s >> chData;
00076                                    s >> alpha;
00077                                    *d = qRgba(chData, chData, chData, alpha);
00078                                    d++;
00079                             }
00080                      }
00081                      else if (patternType == 3)
00082                      {
00083                             for (uint x = 0; x < patternWidth; x++)
00084                             {
00085                                    s >> r;
00086                                    s >> g;
00087                                    s >> b;
00088                                    *d = qRgba(r, g, b, 255);
00089                                    d++;
00090                             }
00091                      }
00092                      else if (patternType == 4)
00093                      {
00094                             for (uint x = 0; x < patternWidth; x++)
00095                             {
00096                                    s >> r;
00097                                    s >> g;
00098                                    s >> b;
00099                                    s >> alpha;
00100                                    *d = qRgba(r, g, b, alpha);
00101                                    d++;
00102                             }
00103                      }
00104               }
00105               m_imageInfoRecord.type = 6;
00106               m_imageInfoRecord.exifDataValid = false;
00107               m_imageInfoRecord.xres = 72;
00108               m_imageInfoRecord.yres = 72;
00109               m_imageInfoRecord.BBoxX = 0;
00110               m_imageInfoRecord.colorspace = 0;
00111               m_imageInfoRecord.BBoxH = m_image.height();
00112               return true;
00113        }
00114        return true;
00115 }
00116 
00117 void ScImgDataLoader_GIMP::preloadAlphaChannel(const QString& fn, int res)
00118 {
00119        initialize();
00120        return;
00121 }