Debian Codegraph @

xbmc/pictures/PictureInfoTag.cpp

raw
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "PictureInfoTag.h"
10
11 #include "ServiceBroker.h"
12 #include "addons/ExtsMimeSupportList.h"
13 #include "addons/ImageDecoder.h"
14 #include "addons/addoninfo/AddonType.h"
15 #include "guilib/guiinfo/GUIInfoLabels.h"
16 #include "utils/Archive.h"
17 #include "utils/CharsetConverter.h"
18 #include "utils/StringUtils.h"
19 #include "utils/URIUtils.h"
20 #include "utils/Variant.h"
21
22 #include <algorithm>
23 #include <vector>
24
25 using namespace KODI::ADDONS;
26
27 CPictureInfoTag::ExifInfo::ExifInfo(const ExifInfo_t& other)
28 : CameraMake(other.CameraMake),
29 CameraModel(other.CameraModel),
30 DateTime(other.DateTime),
31 Height(other.Height),
32 Width(other.Width),
33 Orientation(other.Orientation),
34 IsColor(other.IsColor),
35 Process(other.Process),
36 FlashUsed(other.FlashUsed),
37 FocalLength(other.FocalLength),
38 ExposureTime(other.ExposureTime),
39 ApertureFNumber(other.ApertureFNumber),
40 Distance(other.Distance),
41 CCDWidth(other.CCDWidth),
42 ExposureBias(other.ExposureBias),
43 DigitalZoomRatio(other.DigitalZoomRatio),
44 FocalLength35mmEquiv(other.FocalLength35mmEquiv),
45 Whitebalance(other.Whitebalance),
46 MeteringMode(other.MeteringMode),
47 ExposureProgram(other.ExposureProgram),
48 ExposureMode(other.ExposureMode),
49 ISOequivalent(other.ISOequivalent),
50 LightSource(other.LightSource),
51 CommentsCharset(EXIF_COMMENT_CHARSET_CONVERTED),
52 XPCommentsCharset(EXIF_COMMENT_CHARSET_CONVERTED),
53 Comments(Convert(other.CommentsCharset, other.Comments)),
54 FileComment(Convert(EXIF_COMMENT_CHARSET_UNKNOWN, other.FileComment)),
55 XPComment(Convert(other.XPCommentsCharset, other.XPComment)),
56 Description(other.Description),
57 ThumbnailOffset(other.ThumbnailOffset),
58 ThumbnailSize(other.ThumbnailSize),
59 LargestExifOffset(other.LargestExifOffset),
60 ThumbnailAtEnd(other.ThumbnailAtEnd),
61 ThumbnailSizeOffset(other.ThumbnailSizeOffset),
62 DateTimeOffsets(other.DateTimeOffsets, other.DateTimeOffsets + other.numDateTimeTags),
63 GpsInfoPresent(other.GpsInfoPresent),
64 GpsLat(other.GpsLat),
65 GpsLong(other.GpsLong),
66 GpsAlt(other.GpsAlt)
67 {
68 }
69
70 std::string CPictureInfoTag::ExifInfo::Convert(int charset, const char* data)
71 {
72 std::string value;
73
74 // The charset used for the UserComment is stored in CommentsCharset:
75 // Ascii, Unicode (UCS2), JIS (X208-1990), Unknown (application specific)
76 if (charset == EXIF_COMMENT_CHARSET_UNICODE)
77 {
78 g_charsetConverter.ucs2ToUTF8(std::u16string(reinterpret_cast<const char16_t*>(data)), value);
79 }
80 else
81 {
82 // Ascii doesn't need to be converted (EXIF_COMMENT_CHARSET_ASCII)
83 // Unknown data can't be converted as it could be any codec (EXIF_COMMENT_CHARSET_UNKNOWN)
84 // JIS data can't be converted as CharsetConverter and iconv lacks support (EXIF_COMMENT_CHARSET_JIS)
85 g_charsetConverter.unknownToUTF8(data, value);
86 }
87
88 return value;
89 }
90
91 CPictureInfoTag::IPTCInfo::IPTCInfo(const IPTCInfo_t& other)
92 : RecordVersion(other.RecordVersion),
93 SupplementalCategories(other.SupplementalCategories),
94 Keywords(other.Keywords),
95 Caption(other.Caption),
96 Author(other.Author),
97 Headline(other.Headline),
98 SpecialInstructions(other.SpecialInstructions),
99 Category(other.Category),
100 Byline(other.Byline),
101 BylineTitle(other.BylineTitle),
102 Credit(other.Credit),
103 Source(other.Source),
104 CopyrightNotice(other.CopyrightNotice),
105 ObjectName(other.ObjectName),
106 City(other.City),
107 State(other.State),
108 Country(other.Country),
109 TransmissionReference(other.TransmissionReference),
110 Date(other.Date),
111 Urgency(other.Urgency),
112 ReferenceService(other.ReferenceService),
113 CountryCode(other.CountryCode),
114 TimeCreated(other.TimeCreated),
115 SubLocation(other.SubLocation),
116 ImageType(other.ImageType)
117 {
118 }
119
120 void CPictureInfoTag::Reset()
121 {
122 m_exifInfo = {};
123 m_iptcInfo = {};
124 m_isLoaded = false;
125 m_isInfoSetExternally = false;
126 m_dateTimeTaken.Reset();
127 }
128
129 bool CPictureInfoTag::Load(const std::string &path)
130 {
131 m_isLoaded = false;
132
133 // Get file extensions to find addon related to it.
134 std::string strExtension = URIUtils::GetExtension(path);
135 StringUtils::ToLower(strExtension);
136 if (!strExtension.empty() && CServiceBroker::IsAddonInterfaceUp())
137 {
138 // Load via available image decoder addons
139 auto addonInfos = CServiceBroker::GetExtsMimeSupportList().GetExtensionSupportedAddonInfos(
140 strExtension, CExtsMimeSupportList::FilterSelect::all);
141 for (const auto& addonInfo : addonInfos)
142 {
143 if (addonInfo.first != ADDON::AddonType::IMAGEDECODER)
144 continue;
145
146 std::unique_ptr<CImageDecoder> result = std::make_unique<CImageDecoder>(addonInfo.second, "");
147 if (result->LoadInfoTag(path, this))
148 {
149 m_isLoaded = true;
150 break;
151 }
152 }
153 }
154
155 // Load by Kodi's included own way
156 if (!m_isLoaded)
157 {
158 ExifInfo_t exifInfo;
159 IPTCInfo_t iptcInfo;
160
161 if (process_jpeg(path.c_str(), &exifInfo, &iptcInfo))
162 {
163 m_exifInfo = ExifInfo(exifInfo);
164 m_iptcInfo = IPTCInfo(iptcInfo);
165 m_isLoaded = true;
166 }
167 }
168
169 ConvertDateTime();
170
171 return m_isLoaded;
172 }
173
174 void CPictureInfoTag::Archive(CArchive& ar)
175 {
176 if (ar.IsStoring())
177 {
178 ar << m_isLoaded;
179 ar << m_isInfoSetExternally;
180 ar << m_exifInfo.ApertureFNumber;
181 ar << m_exifInfo.CameraMake;
182 ar << m_exifInfo.CameraModel;
183 ar << m_exifInfo.CCDWidth;
184 ar << m_exifInfo.Comments;
185 ar << m_exifInfo.Description;
186 ar << m_exifInfo.DateTime;
187 for (std::vector<int>::size_type i = 0; i < MAX_DATE_COPIES; ++i)
188 {
189 if (i < m_exifInfo.DateTimeOffsets.size())
190 ar << m_exifInfo.DateTimeOffsets[i];
191 else
192 ar << static_cast<int>(0);
193 }
194 ar << m_exifInfo.DigitalZoomRatio;
195 ar << m_exifInfo.Distance;
196 ar << m_exifInfo.ExposureBias;
197 ar << m_exifInfo.ExposureMode;
198 ar << m_exifInfo.ExposureProgram;
199 ar << m_exifInfo.ExposureTime;
200 ar << m_exifInfo.FlashUsed;
201 ar << m_exifInfo.FocalLength;
202 ar << m_exifInfo.FocalLength35mmEquiv;
203 ar << m_exifInfo.GpsInfoPresent;
204 ar << m_exifInfo.GpsAlt;
205 ar << m_exifInfo.GpsLat;
206 ar << m_exifInfo.GpsLong;
207 ar << m_exifInfo.Height;
208 ar << m_exifInfo.IsColor;
209 ar << m_exifInfo.ISOequivalent;
210 ar << m_exifInfo.LargestExifOffset;
211 ar << m_exifInfo.LightSource;
212 ar << m_exifInfo.MeteringMode;
213 ar << static_cast<int>(m_exifInfo.DateTimeOffsets.size());
214 ar << m_exifInfo.Orientation;
215 ar << m_exifInfo.Process;
216 ar << m_exifInfo.ThumbnailAtEnd;
217 ar << m_exifInfo.ThumbnailOffset;
218 ar << m_exifInfo.ThumbnailSize;
219 ar << m_exifInfo.ThumbnailSizeOffset;
220 ar << m_exifInfo.Whitebalance;
221 ar << m_exifInfo.Width;
222 ar << m_dateTimeTaken;
223
224 ar << m_iptcInfo.Author;
225 ar << m_iptcInfo.Byline;
226 ar << m_iptcInfo.BylineTitle;
227 ar << m_iptcInfo.Caption;
228 ar << m_iptcInfo.Category;
229 ar << m_iptcInfo.City;
230 ar << m_iptcInfo.Urgency;
231 ar << m_iptcInfo.CopyrightNotice;
232 ar << m_iptcInfo.Country;
233 ar << m_iptcInfo.CountryCode;
234 ar << m_iptcInfo.Credit;
235 ar << m_iptcInfo.Date;
236 ar << m_iptcInfo.Headline;
237 ar << m_iptcInfo.Keywords;
238 ar << m_iptcInfo.ObjectName;
239 ar << m_iptcInfo.ReferenceService;
240 ar << m_iptcInfo.Source;
241 ar << m_iptcInfo.SpecialInstructions;
242 ar << m_iptcInfo.State;
243 ar << m_iptcInfo.SupplementalCategories;
244 ar << m_iptcInfo.TransmissionReference;
245 ar << m_iptcInfo.TimeCreated;
246 ar << m_iptcInfo.SubLocation;
247 ar << m_iptcInfo.ImageType;
248 }
249 else
250 {
251 ar >> m_isLoaded;
252 ar >> m_isInfoSetExternally;
253 ar >> m_exifInfo.ApertureFNumber;
254 ar >> m_exifInfo.CameraMake;
255 ar >> m_exifInfo.CameraModel;
256 ar >> m_exifInfo.CCDWidth;
257 ar >> m_exifInfo.Comments;
258 m_exifInfo.CommentsCharset = EXIF_COMMENT_CHARSET_CONVERTED; // Store and restore the comment charset converted
259 ar >> m_exifInfo.Description;
260 ar >> m_exifInfo.DateTime;
261 m_exifInfo.DateTimeOffsets.clear();
262 m_exifInfo.DateTimeOffsets.reserve(MAX_DATE_COPIES);
263 for (std::vector<int>::size_type i = 0; i < MAX_DATE_COPIES; ++i)
264 {
265 int dateTimeOffset;
266 ar >> dateTimeOffset;
267 m_exifInfo.DateTimeOffsets.push_back(dateTimeOffset);
268 }
269 ar >> m_exifInfo.DigitalZoomRatio;
270 ar >> m_exifInfo.Distance;
271 ar >> m_exifInfo.ExposureBias;
272 ar >> m_exifInfo.ExposureMode;
273 ar >> m_exifInfo.ExposureProgram;
274 ar >> m_exifInfo.ExposureTime;
275 ar >> m_exifInfo.FlashUsed;
276 ar >> m_exifInfo.FocalLength;
277 ar >> m_exifInfo.FocalLength35mmEquiv;
278 ar >> m_exifInfo.GpsInfoPresent;
279 ar >> m_exifInfo.GpsAlt;
280 ar >> m_exifInfo.GpsLat;
281 ar >> m_exifInfo.GpsLong;
282 ar >> m_exifInfo.Height;
283 ar >> m_exifInfo.IsColor;
284 ar >> m_exifInfo.ISOequivalent;
285 ar >> m_exifInfo.LargestExifOffset;
286 ar >> m_exifInfo.LightSource;
287 ar >> m_exifInfo.MeteringMode;
288 int numDateTimeTags;
289 ar >> numDateTimeTags;
290 m_exifInfo.DateTimeOffsets.resize(numDateTimeTags);
291 ar >> m_exifInfo.Orientation;
292 ar >> m_exifInfo.Process;
293 ar >> m_exifInfo.ThumbnailAtEnd;
294 ar >> m_exifInfo.ThumbnailOffset;
295 ar >> m_exifInfo.ThumbnailSize;
296 ar >> m_exifInfo.ThumbnailSizeOffset;
297 ar >> m_exifInfo.Whitebalance;
298 ar >> m_exifInfo.Width;
299 ar >> m_dateTimeTaken;
300
301 ar >> m_iptcInfo.Author;
302 ar >> m_iptcInfo.Byline;
303 ar >> m_iptcInfo.BylineTitle;
304 ar >> m_iptcInfo.Caption;
305 ar >> m_iptcInfo.Category;
306 ar >> m_iptcInfo.City;
307 ar >> m_iptcInfo.Urgency;
308 ar >> m_iptcInfo.CopyrightNotice;
309 ar >> m_iptcInfo.Country;
310 ar >> m_iptcInfo.CountryCode;
311 ar >> m_iptcInfo.Credit;
312 ar >> m_iptcInfo.Date;
313 ar >> m_iptcInfo.Headline;
314 ar >> m_iptcInfo.Keywords;
315 ar >> m_iptcInfo.ObjectName;
316 ar >> m_iptcInfo.ReferenceService;
317 ar >> m_iptcInfo.Source;
318 ar >> m_iptcInfo.SpecialInstructions;
319 ar >> m_iptcInfo.State;
320 ar >> m_iptcInfo.SupplementalCategories;
321 ar >> m_iptcInfo.TransmissionReference;
322 ar >> m_iptcInfo.TimeCreated;
323 ar >> m_iptcInfo.SubLocation;
324 ar >> m_iptcInfo.ImageType;
325 }
326 }
327
328 void CPictureInfoTag::Serialize(CVariant& value) const
329 {
330 value["aperturefnumber"] = m_exifInfo.ApertureFNumber;
331 value["cameramake"] = m_exifInfo.CameraMake;
332 value["cameramodel"] = m_exifInfo.CameraModel;
333 value["ccdwidth"] = m_exifInfo.CCDWidth;
334 value["comments"] = m_exifInfo.Comments;
335 value["description"] = m_exifInfo.Description;
336 value["datetime"] = m_exifInfo.DateTime;
337 for (std::vector<int>::size_type i = 0; i < MAX_DATE_COPIES; ++i)
338 {
339 if (i < m_exifInfo.DateTimeOffsets.size())
340 value["datetimeoffsets"][static_cast<int>(i)] = m_exifInfo.DateTimeOffsets[i];
341 else
342 value["datetimeoffsets"][static_cast<int>(i)] = static_cast<int>(0);
343 }
344 value["digitalzoomratio"] = m_exifInfo.DigitalZoomRatio;
345 value["distance"] = m_exifInfo.Distance;
346 value["exposurebias"] = m_exifInfo.ExposureBias;
347 value["exposuremode"] = m_exifInfo.ExposureMode;
348 value["exposureprogram"] = m_exifInfo.ExposureProgram;
349 value["exposuretime"] = m_exifInfo.ExposureTime;
350 value["flashused"] = m_exifInfo.FlashUsed;
351 value["focallength"] = m_exifInfo.FocalLength;
352 value["focallength35mmequiv"] = m_exifInfo.FocalLength35mmEquiv;
353 value["gpsinfopresent"] = m_exifInfo.GpsInfoPresent;
354 value["gpsinfo"]["alt"] = m_exifInfo.GpsAlt;
355 value["gpsinfo"]["lat"] = m_exifInfo.GpsLat;
356 value["gpsinfo"]["long"] = m_exifInfo.GpsLong;
357 value["height"] = m_exifInfo.Height;
358 value["iscolor"] = m_exifInfo.IsColor;
359 value["isoequivalent"] = m_exifInfo.ISOequivalent;
360 value["largestexifoffset"] = m_exifInfo.LargestExifOffset;
361 value["lightsource"] = m_exifInfo.LightSource;
362 value["meteringmode"] = m_exifInfo.MeteringMode;
363 value["numdatetimetags"] = static_cast<int>(m_exifInfo.DateTimeOffsets.size());
364 value["orientation"] = m_exifInfo.Orientation;
365 value["process"] = m_exifInfo.Process;
366 value["thumbnailatend"] = m_exifInfo.ThumbnailAtEnd;
367 value["thumbnailoffset"] = m_exifInfo.ThumbnailOffset;
368 value["thumbnailsize"] = m_exifInfo.ThumbnailSize;
369 value["thumbnailsizeoffset"] = m_exifInfo.ThumbnailSizeOffset;
370 value["whitebalance"] = m_exifInfo.Whitebalance;
371 value["width"] = m_exifInfo.Width;
372
373 value["author"] = m_iptcInfo.Author;
374 value["byline"] = m_iptcInfo.Byline;
375 value["bylinetitle"] = m_iptcInfo.BylineTitle;
376 value["caption"] = m_iptcInfo.Caption;
377 value["category"] = m_iptcInfo.Category;
378 value["city"] = m_iptcInfo.City;
379 value["urgency"] = m_iptcInfo.Urgency;
380 value["copyrightnotice"] = m_iptcInfo.CopyrightNotice;
381 value["country"] = m_iptcInfo.Country;
382 value["countrycode"] = m_iptcInfo.CountryCode;
383 value["credit"] = m_iptcInfo.Credit;
384 value["date"] = m_iptcInfo.Date;
385 value["headline"] = m_iptcInfo.Headline;
386 value["keywords"] = m_iptcInfo.Keywords;
387 value["objectname"] = m_iptcInfo.ObjectName;
388 value["referenceservice"] = m_iptcInfo.ReferenceService;
389 value["source"] = m_iptcInfo.Source;
390 value["specialinstructions"] = m_iptcInfo.SpecialInstructions;
391 value["state"] = m_iptcInfo.State;
392 value["supplementalcategories"] = m_iptcInfo.SupplementalCategories;
393 value["transmissionreference"] = m_iptcInfo.TransmissionReference;
394 value["timecreated"] = m_iptcInfo.TimeCreated;
395 value["sublocation"] = m_iptcInfo.SubLocation;
396 value["imagetype"] = m_iptcInfo.ImageType;
397 }
398
399 void CPictureInfoTag::ToSortable(SortItem& sortable, Field field) const
400 {
401 if (field == FieldDateTaken && m_dateTimeTaken.IsValid())
402 sortable[FieldDateTaken] = m_dateTimeTaken.GetAsDBDateTime();
403 }
404
405 const std::string CPictureInfoTag::GetInfo(int info) const
406 {
407 if (!m_isLoaded && !m_isInfoSetExternally) // If no metadata has been loaded from the picture file or set with SetInfo(), just return
408 return "";
409
410 std::string value;
411 switch (info)
412 {
413 case SLIDESHOW_RESOLUTION:
414 value = StringUtils::Format("{} x {}", m_exifInfo.Width, m_exifInfo.Height);
415 break;
416 case SLIDESHOW_COLOUR:
417 value = m_exifInfo.IsColor ? "Colour" : "Black and White";
418 break;
419 case SLIDESHOW_PROCESS:
420 switch (m_exifInfo.Process)
421 {
422 case M_SOF0:
423 // don't show it if its the plain old boring 'baseline' process, but do
424 // show it if its something else, like 'progressive' (used on web sometimes)
425 value = "Baseline";
426 break;
427 case M_SOF1: value = "Extended sequential"; break;
428 case M_SOF2: value = "Progressive"; break;
429 case M_SOF3: value = "Lossless"; break;
430 case M_SOF5: value = "Differential sequential"; break;
431 case M_SOF6: value = "Differential progressive"; break;
432 case M_SOF7: value = "Differential lossless"; break;
433 case M_SOF9: value = "Extended sequential, arithmetic coding"; break;
434 case M_SOF10: value = "Progressive, arithmetic coding"; break;
435 case M_SOF11: value = "Lossless, arithmetic coding"; break;
436 case M_SOF13: value = "Differential sequential, arithmetic coding"; break;
437 case M_SOF14: value = "Differential progressive, arithmetic coding"; break;
438 case M_SOF15: value = "Differential lossless, arithmetic coding"; break;
439 default: value = "Unknown"; break;
440 }
441 break;
442 case SLIDESHOW_COMMENT:
443 value = m_exifInfo.FileComment;
444 break;
445 case SLIDESHOW_EXIF_COMMENT:
446 value = m_exifInfo.Comments;
447 break;
448 case SLIDESHOW_EXIF_XPCOMMENT:
449 value = m_exifInfo.XPComment;
450 break;
451 case SLIDESHOW_EXIF_LONG_DATE_TIME:
452 if (m_dateTimeTaken.IsValid())
453 value = m_dateTimeTaken.GetAsLocalizedDateTime(true);
454 break;
455 case SLIDESHOW_EXIF_DATE_TIME:
456 if (m_dateTimeTaken.IsValid())
457 value = m_dateTimeTaken.GetAsLocalizedDateTime();
458 break;
459 case SLIDESHOW_EXIF_LONG_DATE:
460 if (m_dateTimeTaken.IsValid())
461 value = m_dateTimeTaken.GetAsLocalizedDate(true);
462 break;
463 case SLIDESHOW_EXIF_DATE:
464 if (m_dateTimeTaken.IsValid())
465 value = m_dateTimeTaken.GetAsLocalizedDate();
466 break;
467 case SLIDESHOW_EXIF_DESCRIPTION:
468 value = m_exifInfo.Description;
469 break;
470 case SLIDESHOW_EXIF_CAMERA_MAKE:
471 value = m_exifInfo.CameraMake;
472 break;
473 case SLIDESHOW_EXIF_CAMERA_MODEL:
474 value = m_exifInfo.CameraModel;
475 break;
476 // case SLIDESHOW_EXIF_SOFTWARE:
477 // value = m_exifInfo.Software;
478 case SLIDESHOW_EXIF_APERTURE:
479 if (m_exifInfo.ApertureFNumber)
480 value = StringUtils::Format("{:3.1f}", m_exifInfo.ApertureFNumber);
481 break;
482 case SLIDESHOW_EXIF_ORIENTATION:
483 switch (m_exifInfo.Orientation)
484 {
485 case 1: value = "Top Left"; break;
486 case 2: value = "Top Right"; break;
487 case 3: value = "Bottom Right"; break;
488 case 4: value = "Bottom Left"; break;
489 case 5: value = "Left Top"; break;
490 case 6: value = "Right Top"; break;
491 case 7: value = "Right Bottom"; break;
492 case 8: value = "Left Bottom"; break;
493 }
494 break;
495 case SLIDESHOW_EXIF_FOCAL_LENGTH:
496 if (m_exifInfo.FocalLength)
497 {
498 value = StringUtils::Format("{:4.2f}mm", m_exifInfo.FocalLength);
499 if (m_exifInfo.FocalLength35mmEquiv != 0)
500 value += StringUtils::Format(" (35mm Equivalent = {}mm)", m_exifInfo.FocalLength35mmEquiv);
501 }
502 break;
503 case SLIDESHOW_EXIF_FOCUS_DIST:
504 if (m_exifInfo.Distance < 0)
505 value = "Infinite";
506 else if (m_exifInfo.Distance > 0)
507 value = StringUtils::Format("{:4.2f}m", m_exifInfo.Distance);
508 break;
509 case SLIDESHOW_EXIF_EXPOSURE:
510 switch (m_exifInfo.ExposureProgram)
511 {
512 case 1: value = "Manual"; break;
513 case 2: value = "Program (Auto)"; break;
514 case 3: value = "Aperture priority (Semi-Auto)"; break;
515 case 4: value = "Shutter priority (semi-auto)"; break;
516 case 5: value = "Creative Program (based towards depth of field)"; break;
517 case 6: value = "Action program (based towards fast shutter speed)"; break;
518 case 7: value = "Portrait Mode"; break;
519 case 8: value = "Landscape Mode"; break;
520 }
521 break;
522 case SLIDESHOW_EXIF_EXPOSURE_TIME:
523 if (m_exifInfo.ExposureTime)
524 {
525 if (m_exifInfo.ExposureTime < 0.010f)
526 value = StringUtils::Format("{:6.4f}s", m_exifInfo.ExposureTime);
527 else
528 value = StringUtils::Format("{:5.3f}s", m_exifInfo.ExposureTime);
529 if (m_exifInfo.ExposureTime <= 0.5f)
530 value += StringUtils::Format(" (1/{})", static_cast<int>(0.5f + 1 / m_exifInfo.ExposureTime));
531 }
532 break;
533 case SLIDESHOW_EXIF_EXPOSURE_BIAS:
534 if (m_exifInfo.ExposureBias != 0)
535 value = StringUtils::Format("{:4.2f} EV", m_exifInfo.ExposureBias);
536 break;
537 case SLIDESHOW_EXIF_EXPOSURE_MODE:
538 switch (m_exifInfo.ExposureMode)
539 {
540 case 0: value = "Automatic"; break;
541 case 1: value = "Manual"; break;
542 case 2: value = "Auto bracketing"; break;
543 }
544 break;
545 case SLIDESHOW_EXIF_FLASH_USED:
546 if (m_exifInfo.FlashUsed >= 0)
547 {
548 if (m_exifInfo.FlashUsed & 1)
549 {
550 value = "Yes";
551 switch (m_exifInfo.FlashUsed)
552 {
553 case 0x5: value = "Yes (Strobe light not detected)"; break;
554 case 0x7: value = "Yes (Strobe light detected)"; break;
555 case 0x9: value = "Yes (Manual)"; break;
556 case 0xd: value = "Yes (Manual, return light not detected)"; break;
557 case 0xf: value = "Yes (Manual, return light detected)"; break;
558 case 0x19: value = "Yes (Auto)"; break;
559 case 0x1d: value = "Yes (Auto, return light not detected)"; break;
560 case 0x1f: value = "Yes (Auto, return light detected)"; break;
561 case 0x41: value = "Yes (Red eye reduction mode)"; break;
562 case 0x45: value = "Yes (Red eye reduction mode return light not detected)"; break;
563 case 0x47: value = "Yes (Red eye reduction mode return light detected)"; break;
564 case 0x49: value = "Yes (Manual, red eye reduction mode)"; break;
565 case 0x4d: value = "Yes (Manual, red eye reduction mode, return light not detected)"; break;
566 case 0x4f: value = "Yes (Manual, red eye reduction mode, return light detected)"; break;
567 case 0x59: value = "Yes (Auto, red eye reduction mode)"; break;
568 case 0x5d: value = "Yes (Auto, red eye reduction mode, return light not detected)"; break;
569 case 0x5f: value = "Yes (Auto, red eye reduction mode, return light detected)"; break;
570 }
571 }
572 else
573 value = m_exifInfo.FlashUsed == 0x18 ? "No (Auto)" : "No";
574 }
575 break;
576 case SLIDESHOW_EXIF_WHITE_BALANCE:
577 return m_exifInfo.Whitebalance ? "Manual" : "Auto";
578 case SLIDESHOW_EXIF_LIGHT_SOURCE:
579 switch (m_exifInfo.LightSource)
580 {
581 case 1: value = "Daylight"; break;
582 case 2: value = "Fluorescent"; break;
583 case 3: value = "Incandescent"; break;
584 case 4: value = "Flash"; break;
585 case 9: value = "Fine Weather"; break;
586 case 11: value = "Shade"; break;
587 default:; //Quercus: 17-1-2004 There are many more modes for this, check Exif2.2 specs
588 // If it just says 'unknown' or we don't know it, then
589 // don't bother showing it - it doesn't add any useful information.
590 }
591 break;
592 case SLIDESHOW_EXIF_METERING_MODE:
593 switch (m_exifInfo.MeteringMode)
594 {
595 case 2: value = "Center weight"; break;
596 case 3: value = "Spot"; break;
597 case 5: value = "Matrix"; break;
598 }
599 break;
600 case SLIDESHOW_EXIF_ISO_EQUIV:
601 if (m_exifInfo.ISOequivalent)
602 value = StringUtils::Format("{:2}", m_exifInfo.ISOequivalent);
603 break;
604 case SLIDESHOW_EXIF_DIGITAL_ZOOM:
605 if (m_exifInfo.DigitalZoomRatio)
606 value = StringUtils::Format("{:1.3f}x", m_exifInfo.DigitalZoomRatio);
607 break;
608 case SLIDESHOW_EXIF_CCD_WIDTH:
609 if (m_exifInfo.CCDWidth)
610 value = StringUtils::Format("{:4.2f}mm", m_exifInfo.CCDWidth);
611 break;
612 case SLIDESHOW_EXIF_GPS_LATITUDE:
613 value = m_exifInfo.GpsLat;
614 break;
615 case SLIDESHOW_EXIF_GPS_LONGITUDE:
616 value = m_exifInfo.GpsLong;
617 break;
618 case SLIDESHOW_EXIF_GPS_ALTITUDE:
619 value = m_exifInfo.GpsAlt;
620 break;
621 case SLIDESHOW_IPTC_SUP_CATEGORIES: value = m_iptcInfo.SupplementalCategories; break;
622 case SLIDESHOW_IPTC_KEYWORDS: value = m_iptcInfo.Keywords; break;
623 case SLIDESHOW_IPTC_CAPTION: value = m_iptcInfo.Caption; break;
624 case SLIDESHOW_IPTC_AUTHOR: value = m_iptcInfo.Author; break;
625 case SLIDESHOW_IPTC_HEADLINE: value = m_iptcInfo.Headline; break;
626 case SLIDESHOW_IPTC_SPEC_INSTR: value = m_iptcInfo.SpecialInstructions; break;
627 case SLIDESHOW_IPTC_CATEGORY: value = m_iptcInfo.Category; break;
628 case SLIDESHOW_IPTC_BYLINE: value = m_iptcInfo.Byline; break;
629 case SLIDESHOW_IPTC_BYLINE_TITLE: value = m_iptcInfo.BylineTitle; break;
630 case SLIDESHOW_IPTC_CREDIT: value = m_iptcInfo.Credit; break;
631 case SLIDESHOW_IPTC_SOURCE: value = m_iptcInfo.Source; break;
632 case SLIDESHOW_IPTC_COPYRIGHT_NOTICE: value = m_iptcInfo.CopyrightNotice; break;
633 case SLIDESHOW_IPTC_OBJECT_NAME: value = m_iptcInfo.ObjectName; break;
634 case SLIDESHOW_IPTC_CITY: value = m_iptcInfo.City; break;
635 case SLIDESHOW_IPTC_STATE: value = m_iptcInfo.State; break;
636 case SLIDESHOW_IPTC_COUNTRY: value = m_iptcInfo.Country; break;
637 case SLIDESHOW_IPTC_TX_REFERENCE: value = m_iptcInfo.TransmissionReference; break;
638 case SLIDESHOW_IPTC_DATE: value = m_iptcInfo.Date; break;
639 case SLIDESHOW_IPTC_URGENCY: value = m_iptcInfo.Urgency; break;
640 case SLIDESHOW_IPTC_COUNTRY_CODE: value = m_iptcInfo.CountryCode; break;
641 case SLIDESHOW_IPTC_REF_SERVICE: value = m_iptcInfo.ReferenceService; break;
642 case SLIDESHOW_IPTC_TIMECREATED: value = m_iptcInfo.TimeCreated; break;
643 case SLIDESHOW_IPTC_SUBLOCATION: value = m_iptcInfo.SubLocation; break;
644 case SLIDESHOW_IPTC_IMAGETYPE: value = m_iptcInfo.ImageType; break;
645 default:
646 break;
647 }
648 return value;
649 }
650
651 int CPictureInfoTag::TranslateString(const std::string &info)
652 {
653 if (StringUtils::EqualsNoCase(info, "filename")) return SLIDESHOW_FILE_NAME;
654 else if (StringUtils::EqualsNoCase(info, "path")) return SLIDESHOW_FILE_PATH;
655 else if (StringUtils::EqualsNoCase(info, "filesize")) return SLIDESHOW_FILE_SIZE;
656 else if (StringUtils::EqualsNoCase(info, "filedate")) return SLIDESHOW_FILE_DATE;
657 else if (StringUtils::EqualsNoCase(info, "slideindex")) return SLIDESHOW_INDEX;
658 else if (StringUtils::EqualsNoCase(info, "resolution")) return SLIDESHOW_RESOLUTION;
659 else if (StringUtils::EqualsNoCase(info, "slidecomment")) return SLIDESHOW_COMMENT;
660 else if (StringUtils::EqualsNoCase(info, "colour")) return SLIDESHOW_COLOUR;
661 else if (StringUtils::EqualsNoCase(info, "process")) return SLIDESHOW_PROCESS;
662 else if (StringUtils::EqualsNoCase(info, "exiftime")) return SLIDESHOW_EXIF_DATE_TIME;
663 else if (StringUtils::EqualsNoCase(info, "exifdate")) return SLIDESHOW_EXIF_DATE;
664 else if (StringUtils::EqualsNoCase(info, "longexiftime")) return SLIDESHOW_EXIF_LONG_DATE_TIME;
665 else if (StringUtils::EqualsNoCase(info, "longexifdate")) return SLIDESHOW_EXIF_LONG_DATE;
666 else if (StringUtils::EqualsNoCase(info, "exifdescription")) return SLIDESHOW_EXIF_DESCRIPTION;
667 else if (StringUtils::EqualsNoCase(info, "cameramake")) return SLIDESHOW_EXIF_CAMERA_MAKE;
668 else if (StringUtils::EqualsNoCase(info, "cameramodel")) return SLIDESHOW_EXIF_CAMERA_MODEL;
669 else if (StringUtils::EqualsNoCase(info, "exifcomment")) return SLIDESHOW_EXIF_COMMENT;
670 else if (StringUtils::EqualsNoCase(info, "exifsoftware")) return SLIDESHOW_EXIF_SOFTWARE;
671 else if (StringUtils::EqualsNoCase(info, "aperture")) return SLIDESHOW_EXIF_APERTURE;
672 else if (StringUtils::EqualsNoCase(info, "focallength")) return SLIDESHOW_EXIF_FOCAL_LENGTH;
673 else if (StringUtils::EqualsNoCase(info, "focusdistance")) return SLIDESHOW_EXIF_FOCUS_DIST;
674 else if (StringUtils::EqualsNoCase(info, "exposure")) return SLIDESHOW_EXIF_EXPOSURE;
675 else if (StringUtils::EqualsNoCase(info, "exposuretime")) return SLIDESHOW_EXIF_EXPOSURE_TIME;
676 else if (StringUtils::EqualsNoCase(info, "exposurebias")) return SLIDESHOW_EXIF_EXPOSURE_BIAS;
677 else if (StringUtils::EqualsNoCase(info, "exposuremode")) return SLIDESHOW_EXIF_EXPOSURE_MODE;
678 else if (StringUtils::EqualsNoCase(info, "flashused")) return SLIDESHOW_EXIF_FLASH_USED;
679 else if (StringUtils::EqualsNoCase(info, "whitebalance")) return SLIDESHOW_EXIF_WHITE_BALANCE;
680 else if (StringUtils::EqualsNoCase(info, "lightsource")) return SLIDESHOW_EXIF_LIGHT_SOURCE;
681 else if (StringUtils::EqualsNoCase(info, "meteringmode")) return SLIDESHOW_EXIF_METERING_MODE;
682 else if (StringUtils::EqualsNoCase(info, "isoequivalence")) return SLIDESHOW_EXIF_ISO_EQUIV;
683 else if (StringUtils::EqualsNoCase(info, "digitalzoom")) return SLIDESHOW_EXIF_DIGITAL_ZOOM;
684 else if (StringUtils::EqualsNoCase(info, "ccdwidth")) return SLIDESHOW_EXIF_CCD_WIDTH;
685 else if (StringUtils::EqualsNoCase(info, "orientation")) return SLIDESHOW_EXIF_ORIENTATION;
686 else if (StringUtils::EqualsNoCase(info, "supplementalcategories")) return SLIDESHOW_IPTC_SUP_CATEGORIES;
687 else if (StringUtils::EqualsNoCase(info, "keywords")) return SLIDESHOW_IPTC_KEYWORDS;
688 else if (StringUtils::EqualsNoCase(info, "caption")) return SLIDESHOW_IPTC_CAPTION;
689 else if (StringUtils::EqualsNoCase(info, "author")) return SLIDESHOW_IPTC_AUTHOR;
690 else if (StringUtils::EqualsNoCase(info, "headline")) return SLIDESHOW_IPTC_HEADLINE;
691 else if (StringUtils::EqualsNoCase(info, "specialinstructions")) return SLIDESHOW_IPTC_SPEC_INSTR;
692 else if (StringUtils::EqualsNoCase(info, "category")) return SLIDESHOW_IPTC_CATEGORY;
693 else if (StringUtils::EqualsNoCase(info, "byline")) return SLIDESHOW_IPTC_BYLINE;
694 else if (StringUtils::EqualsNoCase(info, "bylinetitle")) return SLIDESHOW_IPTC_BYLINE_TITLE;
695 else if (StringUtils::EqualsNoCase(info, "credit")) return SLIDESHOW_IPTC_CREDIT;
696 else if (StringUtils::EqualsNoCase(info, "source")) return SLIDESHOW_IPTC_SOURCE;
697 else if (StringUtils::EqualsNoCase(info, "copyrightnotice")) return SLIDESHOW_IPTC_COPYRIGHT_NOTICE;
698 else if (StringUtils::EqualsNoCase(info, "objectname")) return SLIDESHOW_IPTC_OBJECT_NAME;
699 else if (StringUtils::EqualsNoCase(info, "city")) return SLIDESHOW_IPTC_CITY;
700 else if (StringUtils::EqualsNoCase(info, "state")) return SLIDESHOW_IPTC_STATE;
701 else if (StringUtils::EqualsNoCase(info, "country")) return SLIDESHOW_IPTC_COUNTRY;
702 else if (StringUtils::EqualsNoCase(info, "transmissionreference")) return SLIDESHOW_IPTC_TX_REFERENCE;
703 else if (StringUtils::EqualsNoCase(info, "iptcdate")) return SLIDESHOW_IPTC_DATE;
704 else if (StringUtils::EqualsNoCase(info, "urgency")) return SLIDESHOW_IPTC_URGENCY;
705 else if (StringUtils::EqualsNoCase(info, "countrycode")) return SLIDESHOW_IPTC_COUNTRY_CODE;
706 else if (StringUtils::EqualsNoCase(info, "referenceservice")) return SLIDESHOW_IPTC_REF_SERVICE;
707 else if (StringUtils::EqualsNoCase(info, "latitude")) return SLIDESHOW_EXIF_GPS_LATITUDE;
708 else if (StringUtils::EqualsNoCase(info, "longitude")) return SLIDESHOW_EXIF_GPS_LONGITUDE;
709 else if (StringUtils::EqualsNoCase(info, "altitude")) return SLIDESHOW_EXIF_GPS_ALTITUDE;
710 else if (StringUtils::EqualsNoCase(info, "timecreated")) return SLIDESHOW_IPTC_TIMECREATED;
711 else if (StringUtils::EqualsNoCase(info, "sublocation")) return SLIDESHOW_IPTC_SUBLOCATION;
712 else if (StringUtils::EqualsNoCase(info, "imagetype")) return SLIDESHOW_IPTC_IMAGETYPE;
713 return 0;
714 }
715
716 void CPictureInfoTag::SetInfo(const std::string &key, const std::string& value)
717 {
718 int info = TranslateString(key);
719
720 switch (info)
721 {
722 case SLIDESHOW_RESOLUTION:
723 {
724 std::vector<std::string> dimension;
725 StringUtils::Tokenize(value, dimension, ",");
726 if (dimension.size() == 2)
727 {
728 m_exifInfo.Width = atoi(dimension[0].c_str());
729 m_exifInfo.Height = atoi(dimension[1].c_str());
730 m_isInfoSetExternally = true; // Set the internal state to show metadata has been set by call to SetInfo
731 }
732 break;
733 }
734 case SLIDESHOW_EXIF_DATE_TIME:
735 {
736 m_exifInfo.DateTime = value;
737 m_isInfoSetExternally = true; // Set the internal state to show metadata has been set by call to SetInfo
738 ConvertDateTime();
739 break;
740 }
741 default:
742 break;
743 }
744 }
745
746 const CDateTime& CPictureInfoTag::GetDateTimeTaken() const
747 {
748 return m_dateTimeTaken;
749 }
750
751 void CPictureInfoTag::ConvertDateTime()
752 {
753 const std::string& dateTime = m_exifInfo.DateTime;
754 if (dateTime.length() >= 19 && dateTime[0] != ' ')
755 {
756 int year = atoi(dateTime.substr(0, 4).c_str());
757 int month = atoi(dateTime.substr(5, 2).c_str());
758 int day = atoi(dateTime.substr(8, 2).c_str());
759 int hour = atoi(dateTime.substr(11,2).c_str());
760 int min = atoi(dateTime.substr(14,2).c_str());
761 int sec = atoi(dateTime.substr(17,2).c_str());
762 m_dateTimeTaken.SetDateTime(year, month, day, hour, min, sec);
763 }
764 }