Subversion Repositories Scribus

Rev

Rev 17754 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5977 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
10223 cbradney 7
#include <QFile>
8
#include <QFileInfo>
8569 jghali 9
#include <QByteArray>
10
#include <QImageReader>
11
#include <QList>
5937 jghali 12
#include "scimgdataloader_qt.h"
13
 
14
ScImgDataLoader_QT::ScImgDataLoader_QT(void) : ScImgDataLoader()
15
{
16
        initSupportedFormatList();
17
}
18
 
19
void ScImgDataLoader_QT::initSupportedFormatList(void)
20
{
21
        m_supportedFormats.clear();
8569 jghali 22
        QList<QByteArray> fmtList = QImageReader::supportedImageFormats();
23
        for (int i = 0; i < fmtList.count(); i++)
10398 cbradney 24
                m_supportedFormats.append( fmtList[i].toLower() );
5937 jghali 25
}
26
 
12141 avox 27
void ScImgDataLoader_QT::loadEmbeddedProfile(const QString& fn, int /*page*/)
5937 jghali 28
{
29
        m_embeddedProfile.resize(0);
30
        m_profileComponents = 0;
31
}
32
 
12141 avox 33
bool ScImgDataLoader_QT::loadPicture(const QString& fn, int /*page*/, int /*res*/, bool /*thumbnail*/)
5937 jghali 34
{
35
        if (!QFile::exists(fn))
36
                return false;
37
        initialize();
38
        if (m_image.load(fn))
39
        {
11331 jghali 40
                m_imageInfoRecord.type = ImageTypeOther;
5937 jghali 41
                m_imageInfoRecord.exifDataValid = false;
42
                float xres = m_image.dotsPerMeterX() * 0.0254;
43
                float yres = m_image.dotsPerMeterY() * 0.0254;
44
                int resInf = m_imageInfoRecord.lowResType;
17754 jghali 45
                m_imageInfoRecord.colorspace = ColorSpaceRGB;
24639 jghali 46
                if (m_image.isGrayscale() || (m_image.depth() == 1 && m_image.allGray()))
17754 jghali 47
                        m_imageInfoRecord.colorspace = ColorSpaceGray;
10561 fschmid 48
                m_image = m_image.convertToFormat(QImage::Format_ARGB32);
8562 jghali 49
                m_image.setDotsPerMeterX (qMax(2834, (int) (xres / 0.0254)));
50
                m_image.setDotsPerMeterY (qMax(2834, (int) (yres / 0.0254)));
51
                m_imageInfoRecord.xres = qMax(72, qRound(xres));
52
                m_imageInfoRecord.yres = qMax(72, qRound(yres));
5937 jghali 53
                m_imageInfoRecord.lowResType = resInf;
54
                m_imageInfoRecord.BBoxX = 0;
55
                m_imageInfoRecord.BBoxH = m_image.height();
56
                return true;
57
        }
11468 fschmid 58
        return false; //TODO: I think this should be false!
5937 jghali 59
}
60
 
12141 avox 61
bool ScImgDataLoader_QT::preloadAlphaChannel(const QString& fn, int /*page*/, int res, bool& hasAlpha)
5937 jghali 62
{
63
        initialize();
11468 fschmid 64
        hasAlpha = false;
5937 jghali 65
        QFileInfo fi = QFileInfo(fn);
66
        if (!fi.exists())
11468 fschmid 67
                return false;
10561 fschmid 68
        QString ext = fi.suffix().toLower();
5937 jghali 69
        if ((ext == "jpg") || (ext == "jpeg"))
11468 fschmid 70
        {
71
                hasAlpha = false;
72
                return true;
73
        }
5937 jghali 74
        if (m_image.load(fn))
11468 fschmid 75
        {
11611 jghali 76
                hasAlpha = m_image.hasAlphaChannel();
77
                if (m_image.hasAlphaChannel())
78
                        m_image = m_image.convertToFormat(QImage::Format_ARGB32);
79
                else
80
                        m_image = QImage(); // Discard data immediately
11468 fschmid 81
                return true;
82
        }
83
        return false;
5937 jghali 84
}