Subversion Repositories Scribus

Rev

Rev 24752 | 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
 
14539 jghali 8
#include "scimagecacheproxy.h"
5937 jghali 9
#include "scimagestructs.h"
10
 
14539 jghali 11
#include <QByteArray>
12
#include <QDataStream>
13
 
14
#define SC_DEBUG_FILE defined(DEBUG_SCIMAGECACHE)
15
#include "scdebug.h"
16
 
17
namespace {
18
        const QDataStream::Version dsVersion = QDataStream::Qt_4_0;
19
}
20
 
24758 jghali 21
constexpr qint32 ExifValues::dsVersion;
22
 
14539 jghali 23
QDataStream & operator<< (QDataStream& stream, const ExifValues & exif)
24
{
19938 jghali 25
        stream << static_cast<qint32>(exif.width) << static_cast<qint32>(exif.height) << static_cast<qint32>(exif.orientation)
26
                   << exif.ExposureTime << exif.ApertureFNumber << static_cast<qint32>(exif.ISOequivalent) << exif.cameraName
14539 jghali 27
                   << exif.cameraVendor << exif.comment << exif.userComment << exif.artist << exif.copyright
28
                   << exif.dateTime << exif.thumbnail;
29
        return stream;
30
}
31
 
32
QDataStream & operator>> (QDataStream& stream, ExifValues & exif)
33
{
19938 jghali 34
        qint32 w, h, ori, iso;
35
        stream >> w >> h >> ori >> exif.ExposureTime >> exif.ApertureFNumber >> iso >> exif.cameraName
14539 jghali 36
                   >> exif.cameraVendor >> exif.comment >> exif.userComment >> exif.artist >> exif.copyright
37
                   >> exif.dateTime >> exif.thumbnail;
38
        exif.width = w;
39
        exif.height = h;
19938 jghali 40
        exif.orientation = ori;
14539 jghali 41
        exif.ISOequivalent = iso;
42
        return stream;
43
}
44
 
22598 craig 45
ExifValues::ExifValues()
5937 jghali 46
{
47
        init();
48
}
49
 
22598 craig 50
void ExifValues::init()
5937 jghali 51
{
52
        width = 0;
53
        height = 0;
19938 jghali 54
        orientation = 1;
7980 fschmid 55
        ExposureTime = 0;
56
        ApertureFNumber = 0;
57
        ISOequivalent = 0;
10508 cbradney 58
        cameraName.resize(0);
59
        cameraVendor.resize(0);
60
        comment.resize(0);
61
        userComment.resize(0);
62
        artist.resize(0);
63
        copyright.resize(0);
64
        dateTime.resize(0);
5937 jghali 65
        thumbnail = QImage();
66
}
67
 
24758 jghali 68
constexpr qint32 ImageInfoRecord::iirVersion;
69
 
22598 craig 70
ImageInfoRecord::ImageInfoRecord()
5937 jghali 71
{
72
        init();
73
}
74
 
22598 craig 75
void ImageInfoRecord::init()
5937 jghali 76
{
11331 jghali 77
        type = ImageTypeOther;  /* 0 = jpg, 1 = tiff, 2 = psd, 3 = eps/ps, 4 = pdf, 5 = jpg2000, 6 = other */
5937 jghali 78
        xres = 72;
79
        yres = 72;
80
        BBoxX = 0;
81
        BBoxH = 0;
11331 jghali 82
        colorspace = ColorSpaceRGB; /* 0 = RGB  1 = CMYK  2 = Grayscale 3 = Duotone */
5937 jghali 83
        valid = false;
84
        isRequest = false;
85
        progressive = false;
86
        isEmbedded = false;
87
        exifDataValid = false;
88
        lowResType = 1; /* 0 = full Resolution, 1 = 72 dpi, 2 = 36 dpi */
89
        lowResScale = 1.0;
90
        PDSpathData.clear();
91
        RequestProps.clear();
12080 avox 92
        numberOfPages = 1;
93
        actualPageNumber = 0; // default
10508 cbradney 94
        clipPath.resize(0);
95
        usedPath.resize(0);
96
        profileName.resize(0);
5937 jghali 97
        layerInfo.clear();
6085 fschmid 98
        duotoneColors.clear();
5937 jghali 99
        exifInfo.init();
100
}
14539 jghali 101
 
102
bool ImageInfoRecord::canSerialize() const
103
{
104
        return PDSpathData.empty() && RequestProps.empty() && layerInfo.empty() && duotoneColors.empty();
105
}
106
 
107
bool ImageInfoRecord::serialize(ScImageCacheProxy & cache) const
108
{
109
        if (!canSerialize())
110
        {
111
                scDebug() << "cannot serialize" << PDSpathData.empty() << RequestProps.empty() << layerInfo.empty() << duotoneColors.empty();
112
                return false;
113
        }
114
 
115
        cache.addInfo("iirVersion", QString::number(iirVersion));
116
        cache.addInfo("type", QString::number(static_cast<int>(type)));
117
        cache.addInfo("xres", QString::number(xres));
118
        cache.addInfo("yres", QString::number(yres));
119
        cache.addInfo("BBoxX", QString::number(BBoxX));
120
        cache.addInfo("BBoxH", QString::number(BBoxH));
121
        cache.addInfo("colorspace", QString::number(static_cast<int>(colorspace)));
122
        cache.addInfo("valid", QString::number(static_cast<int>(valid)));
123
        cache.addInfo("isRequest", QString::number(static_cast<int>(isRequest)));
124
        cache.addInfo("progressive", QString::number(static_cast<int>(progressive)));
125
        cache.addInfo("isEmbedded", QString::number(static_cast<int>(isEmbedded)));
126
        cache.addInfo("lowResType", QString::number(lowResType));
127
        cache.addInfo("lowResScale", QString::number(lowResScale, 'g', 15));
128
        cache.addInfo("clipPath", clipPath);
129
        cache.addInfo("profileName", profileName);
130
 
131
        if (exifDataValid)
132
        {
133
                QByteArray exif;
134
                QDataStream es(&exif, QIODevice::WriteOnly);
135
                es.setVersion(dsVersion);
136
                es << ExifValues::dsVersion;
137
                es << exifInfo;
138
                cache.addInfo("exifInfo", exif.toBase64());
139
        }
140
 
141
        return true;
142
}
143
 
144
bool ImageInfoRecord::deserialize(const ScImageCacheProxy & cache)
145
{
146
        PDSpathData.clear();
147
        RequestProps.clear();
148
        layerInfo.clear();
149
        duotoneColors.clear();
150
        usedPath.resize(0);
151
        int v1 = cache.getInfo("iirVersion").toInt();
152
        if (v1 != iirVersion)
153
        {
154
                scDebug() << "image info version mismatch" << v1 << "!=" << iirVersion;
155
                return false;
156
        }
157
        type = static_cast<ImageTypeEnum>(cache.getInfo("type").toInt());
158
        xres = cache.getInfo("xres").toInt();
159
        yres = cache.getInfo("yres").toInt();
160
        BBoxX = cache.getInfo("BBoxX").toInt();
161
        BBoxH = cache.getInfo("BBoxH").toInt();
162
        colorspace = static_cast<ColorSpaceEnum>(cache.getInfo("colorspace").toInt());
163
        valid = cache.getInfo("valid").toInt() != 0;
164
        isRequest = cache.getInfo("isRequest").toInt() != 0;
165
        progressive = cache.getInfo("progressive").toInt() != 0;
166
        isEmbedded = cache.getInfo("isEmbedded").toInt() != 0;
167
        lowResType = cache.getInfo("lowResType").toInt();
168
        lowResScale = cache.getInfo("lowResScale").toDouble();
169
        clipPath = cache.getInfo("clipPath");
170
        profileName = cache.getInfo("profileName");
171
        QString exifData = cache.getInfo("exifInfo");
172
        exifDataValid = !exifData.isNull();
173
        if (exifDataValid)
174
        {
18194 fschmid 175
                QByteArray exif = QByteArray::fromBase64(exifData.toLatin1());
14539 jghali 176
                QDataStream es(exif);
177
                es.setVersion(dsVersion);
178
                qint32 v2;
179
                es >> v2;
180
                if (v2 != ExifValues::dsVersion)
181
                {
182
                        scDebug() << "exif version mismatch" << v2 << "!=" << ExifValues::dsVersion;
183
                        return false;
184
                }
185
                es >> exifInfo;
186
        }
187
 
188
        return true;
189
}
190