KExiv2::ImageColorWorkSpace KExiv2::getImageColorWorkSpace() const { // Check Exif values. long exifColorSpace = -1; if (!getExifTagLong("Exif.Photo.ColorSpace", exifColorSpace)) { #ifdef _XMP_SUPPORT_ QVariant var = getXmpTagVariant("Xmp.exif.ColorSpace"); if (!var.isNull()) exifColorSpace = var.toInt(); #endif // _XMP_SUPPORT_ } if (exifColorSpace == 1) { return WORKSPACE_SRGB; // as specified by standard } else if (exifColorSpace == 2) { return WORKSPACE_ADOBERGB; // not in the standard! } else { if (exifColorSpace == 65535) { // A lot of cameras set the Exif.Iop.InteroperabilityIndex, // as documented for ExifTool QString interopIndex = getExifTagString("Exif.Iop.InteroperabilityIndex"); if (!interopIndex.isNull()) { if (interopIndex == "R03") return WORKSPACE_ADOBERGB; else if (interopIndex == "R98") return WORKSPACE_SRGB; } } // Note: Text EXIF ColorSpace tag may just not be present (NEF files) // Nikon camera set Exif.Photo.ColorSpace to uncalibrated or just skip this field, // then add additional information into the makernotes. // Exif.Nikon3.ColorSpace: 1 => sRGB, 2 => AdobeRGB long nikonColorSpace; if (getExifTagLong("Exif.Nikon3.ColorSpace", nikonColorSpace)) { if (nikonColorSpace == 1) return WORKSPACE_SRGB; else if (nikonColorSpace == 2) return WORKSPACE_ADOBERGB; } // Exif.Nikon3.ColorMode is set to "MODE2" for AdobeRGB, but there are sometimes two ColorMode fields // in a NEF, with the first one "COLOR" and the second one "MODE2"; but in this case, ColorSpace (above) was set. if (getExifTagString("Exif.Nikon3.ColorMode").contains("MODE2")) return WORKSPACE_ADOBERGB; //TODO: This makernote tag (0x00b4) must be added to libexiv2 /* long canonColorSpace; if (getExifTagLong("Exif.Canon.ColorSpace", canonColorSpace)) { if (canonColorSpace == 1) return WORKSPACE_SRGB; else if (canonColorSpace == 2) return WORKSPACE_ADOBERGB; } */ // TODO : add more Makernote parsing here ... if (exifColorSpace == 65535) return WORKSPACE_UNCALIBRATED; } return WORKSPACE_UNSPECIFIED; }
int DMetadata::getItemRating(const DMetadataSettingsContainer& settings) const { if (getFilePath().isEmpty()) { return -1; } long rating = -1; bool xmpSupported = hasXmp(); bool iptcSupported = hasIptc(); bool exivSupported = hasExif(); for (NamespaceEntry entry : settings.getReadMapping(QString::fromUtf8(DM_RATING_CONTAINER))) { if (entry.isDisabled) continue; const std::string myStr = entry.namespaceName.toStdString(); const char* nameSpace = myStr.data(); QString value; switch(entry.subspace) { case NamespaceEntry::XMP: if (xmpSupported) value = getXmpTagString(nameSpace, false); break; case NamespaceEntry::IPTC: if (iptcSupported) value = QString::fromUtf8(getIptcTagData(nameSpace)); break; case NamespaceEntry::EXIF: if (exivSupported) getExifTagLong(nameSpace, rating); break; default: break; } if (!value.isEmpty()) { bool ok = false; rating = value.toLong(&ok); if (!ok) { return -1; } } int index = entry.convertRatio.indexOf(rating); // Exact value was not found,but rating is in range, // so we try to approximate it if ((index == -1) && (rating > entry.convertRatio.first()) && (rating < entry.convertRatio.last())) { for (int i = 0 ; i < entry.convertRatio.size() ; ++i) { if (rating > entry.convertRatio.at(i)) { index = i; } } } if (index != -1) { return index; } } return -1; }