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 */
7
8 #include "scimagecacheproxy.h"
9 #include "scimagestructs.h"
10
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
21 const qint32 ExifValues::dsVersion = 1;
22
operator <<(QDataStream & stream,const ExifValues & exif)23 QDataStream & operator<< (QDataStream& stream, const ExifValues & exif)
24 {
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
27 << exif.cameraVendor << exif.comment << exif.userComment << exif.artist << exif.copyright
28 << exif.dateTime << exif.thumbnail;
29 return stream;
30 }
31
operator >>(QDataStream & stream,ExifValues & exif)32 QDataStream & operator>> (QDataStream& stream, ExifValues & exif)
33 {
34 qint32 w, h, ori, iso;
35 stream >> w >> h >> ori >> exif.ExposureTime >> exif.ApertureFNumber >> iso >> exif.cameraName
36 >> exif.cameraVendor >> exif.comment >> exif.userComment >> exif.artist >> exif.copyright
37 >> exif.dateTime >> exif.thumbnail;
38 exif.width = w;
39 exif.height = h;
40 exif.orientation = ori;
41 exif.ISOequivalent = iso;
42 return stream;
43 }
44
ExifValues()45 ExifValues::ExifValues()
46 {
47 init();
48 }
49
init()50 void ExifValues::init()
51 {
52 width = 0;
53 height = 0;
54 orientation = 1;
55 ExposureTime = 0;
56 ApertureFNumber = 0;
57 ISOequivalent = 0;
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);
65 thumbnail = QImage();
66 }
67
68 const qint32 ImageInfoRecord::iirVersion = 1;
69
ImageInfoRecord()70 ImageInfoRecord::ImageInfoRecord()
71 {
72 init();
73 }
74
init()75 void ImageInfoRecord::init()
76 {
77 type = ImageTypeOther; /* 0 = jpg, 1 = tiff, 2 = psd, 3 = eps/ps, 4 = pdf, 5 = jpg2000, 6 = other */
78 xres = 72;
79 yres = 72;
80 BBoxX = 0;
81 BBoxH = 0;
82 colorspace = ColorSpaceRGB; /* 0 = RGB 1 = CMYK 2 = Grayscale 3 = Duotone */
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();
92 numberOfPages = 1;
93 actualPageNumber = 0; // default
94 clipPath.resize(0);
95 usedPath.resize(0);
96 profileName.resize(0);
97 layerInfo.clear();
98 duotoneColors.clear();
99 exifInfo.init();
100 }
101
canSerialize() const102 bool ImageInfoRecord::canSerialize() const
103 {
104 return PDSpathData.empty() && RequestProps.empty() && layerInfo.empty() && duotoneColors.empty();
105 }
106
serialize(ScImageCacheProxy & cache) const107 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
deserialize(const ScImageCacheProxy & cache)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 {
175 QByteArray exif = QByteArray::fromBase64(exifData.toLatin1());
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
191