From 17c7ec684d4085fcb31a8c453e8f223a1aa1d8db Mon Sep 17 00:00:00 2001 From: Hombre57 Date: Sun, 17 Sep 2017 23:05:34 +0200 Subject: [PATCH] PixelShift detection for PEF files was broken (see #4008) --- rtengine/imagedata.cc | 23 +++++++++++ rtengine/imagedata.h | 15 +++----- rtexif/rtexif.cc | 89 +++++++++++++++++++++++++++---------------- rtexif/rtexif.h | 14 +++---- 4 files changed, 92 insertions(+), 49 deletions(-) diff --git a/rtengine/imagedata.cc b/rtengine/imagedata.cc index 4be057685..3d9c3276a 100644 --- a/rtengine/imagedata.cc +++ b/rtengine/imagedata.cc @@ -23,6 +23,8 @@ #include "imagedata.h" #include "iptcpairs.h" +#define PRINT_HDR_PS_DETECTION 0 + using namespace rtengine; extern "C" IptcData *iptc_data_new_from_jpeg_file (FILE* infile); @@ -477,6 +479,9 @@ void FrameData::extractInfo () if (hdr) { if (hdr->toInt() > 0 && hdr->toInt(2) > 0) { isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> \"HDR\" tag found\n"); +#endif } } else { rtexif::Tag* dm = mnote->findTag("DriveMode"); @@ -486,6 +491,9 @@ void FrameData::extractInfo () buffer[3] = 0; if (!strcmp(buffer, "HDR")) { isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> DriveMode = \"HDR\"\n"); +#endif } } } @@ -494,6 +502,9 @@ void FrameData::extractInfo () rtexif::Tag* q = mnote->findTag("Quality"); if (q && q->toInt() == 7) { isPixelShift = true; +#if PRINT_HDR_PS_DETECTION + printf("PixelShift detected ! -> \"Quality\" = 7\n"); +#endif } } } @@ -546,12 +557,18 @@ void FrameData::extractInfo () if (bitspersample == 32) { sampleFormat = IIOSF_FLOAT; isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> sampleFormat = %d\n", sampleFormat); +#endif } } } else if (photometric == PHOTOMETRIC_CFA) { if (sampleformat == SAMPLEFORMAT_IEEEFP) { sampleFormat = IIOSF_FLOAT; isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> sampleFormat = %d\n", sampleFormat); +#endif } else if (sampleformat == SAMPLEFORMAT_INT || sampleformat == SAMPLEFORMAT_UINT) { if (bitspersample == 8) { // shouldn't occur... sampleFormat = IIOSF_UNSIGNED_CHAR; @@ -563,9 +580,15 @@ void FrameData::extractInfo () if (compression == COMPRESSION_SGILOG24) { sampleFormat = IIOSF_LOGLUV24; isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> sampleFormat = %d\n", sampleFormat); +#endif } else if (compression == COMPRESSION_SGILOG) { sampleFormat = IIOSF_LOGLUV32; isHDR = true; +#if PRINT_HDR_PS_DETECTION + printf("HDR detected ! -> sampleFormat = %d\n", sampleFormat); +#endif } } } diff --git a/rtengine/imagedata.h b/rtengine/imagedata.h index 4850e9f60..07119e5f0 100644 --- a/rtengine/imagedata.h +++ b/rtengine/imagedata.h @@ -20,17 +20,12 @@ #define __IMAGEDATA_H__ #include -#include -#include - -#include - -#include - -#include "../rtexif/rtexif.h" - -#include "procparams.h" #include "rawimage.h" +#include +#include +#include "../rtexif/rtexif.h" +#include "procparams.h" +#include #include "rtengine.h" namespace rtengine diff --git a/rtexif/rtexif.cc b/rtexif/rtexif.cc index c5aa44670..c6ffabec9 100644 --- a/rtexif/rtexif.cc +++ b/rtexif/rtexif.cc @@ -35,6 +35,9 @@ #include "../rtgui/version.h" #include "../rtgui/ppversion.h" +// see end of ExifManager::parse(bool, bool) +#define PRINT_METADATA_TREE 0 + using namespace std; namespace rtexif @@ -288,12 +291,14 @@ bool TagDirectory::CPBDump (const Glib::ustring &commFName, const Glib::ustring kf->set_string ("RT General", "DefaultProcParams", defaultPParams); kf->set_boolean ("RT General", "FlaggingMode", flagMode); + kf->set_integer ("Common Data", "FrameCount", cfs->frameCount); + kf->set_integer ("Common Data", "SampleFormat", cfs->sampleFormat); + kf->set_boolean ("Common Data", "IsHDR", cfs->isHDR); + kf->set_boolean ("Common Data", "IsPixelShift", cfs->isPixelShift); kf->set_double ("Common Data", "FNumber", cfs->fnumber); kf->set_double ("Common Data", "Shutter", cfs->shutter); kf->set_double ("Common Data", "FocalLength", cfs->focalLen); kf->set_integer ("Common Data", "ISO", cfs->iso); - kf->set_boolean ("Common Data", "IsHDR", cfs->isHDR); - kf->set_boolean ("Common Data", "IsPixelShift", cfs->isPixelShift); kf->set_string ("Common Data", "Lens", cfs->lens); kf->set_string ("Common Data", "Make", cfs->camMake); kf->set_string ("Common Data", "Model", cfs->camModel); @@ -457,13 +462,18 @@ Tag* TagDirectory::findTag (const char* name, bool lookUpward) const return t; } - for (size_t i = 0; i < tags.size(); i++) { - if (tags[i]->isDirectory()) { - TagDirectory *dir = tags[i]->getDirectory(); - Tag* t = dir->findTag (name); + for (auto tag : tags) { + if (tag->isDirectory()) { + TagDirectory *dir; + int i = 0; + while ((dir = tag->getDirectory(i)) != nullptr) { + TagDirectory *dir = tag->getDirectory(); + Tag* t = dir->findTag (name); - if (t) { - return t; + if (t) { + return t; + } + ++i; } } } @@ -492,15 +502,19 @@ std::vector TagDirectory::findTags (int ID) for (auto tag : tags) { if (tag->isDirectory()) { - TagDirectory *dir = tag->getDirectory(); - std::vector subTagList = dir->findTags (ID); + TagDirectory *dir; + int i = 0; + while ((dir = tag->getDirectory(i)) != nullptr) { + std::vector subTagList = dir->findTags (ID); - if (!subTagList.empty()) { - // concatenating the 2 vectors - // not really optimal in a memory efficiency pov - for (auto tag2 : subTagList) { - tagList.push_back(tag2); + if (!subTagList.empty()) { + // concatenating the 2 vectors + // not really optimal in a memory efficiency pov + for (auto tag2 : subTagList) { + tagList.push_back(tag2); + } } + ++i; } } } @@ -521,15 +535,19 @@ std::vector TagDirectory::findTags (const char* name) for (auto tag : tags) { if (tag->isDirectory()) { - TagDirectory *dir = tag->getDirectory(); - std::vector subTagList = dir->findTags (name); + TagDirectory *dir; + int i = 0; + while ((dir = tag->getDirectory(i)) != nullptr) { + std::vector subTagList = dir->findTags (name); - if (!subTagList.empty()) { - // concatenating the 2 vectors - // not really optimal in a memory efficiency pov - for (auto tag2 : subTagList) { - tagList.push_back(tag2); + if (!subTagList.empty()) { + // concatenating the 2 vectors + // not really optimal in a memory efficiency pov, but adding 10 items should be a maximum + for (auto tag2 : subTagList) { + tagList.push_back(tag2); + } } + ++i; } } } @@ -540,7 +558,7 @@ std::vector TagDirectory::findTags (const char* name) Tag* TagDirectory::findTagUpward (const char* name) const { - Tag* t = getTag(name); + Tag* t = findTag(name); if (t) { return t; } @@ -2650,7 +2668,6 @@ void ExifManager::parseStd (bool skipIgnored) { parse(false, skipIgnored); } -// return a root TagDirectory void ExifManager::parse (bool isRaw, bool skipIgnored) { int ifdOffset = IFDOffset; @@ -2924,8 +2941,10 @@ void ExifManager::parse (bool isRaw, bool skipIgnored) frames.push_back(sft->getParent()); frameRootDetected = true; - //printf("\n--------------- FRAME -----------------------------\n\n"); - //sft->getParent()->printAll (); +#if PRINT_METADATA_TREE + printf("\n--------------- FRAME (SUBFILETYPE) ---------------\n\n"); + sft->getParent()->printAll (); +#endif } } } @@ -2939,8 +2958,10 @@ void ExifManager::parse (bool isRaw, bool skipIgnored) frames.push_back(sft->getParent()); frameRootDetected = true; - //printf("\n--------------- FRAME -----------------------------\n\n"); - //sft->getParent()->printAll (); +#if PRINT_METADATA_TREE + printf("\n--------------- FRAME (OSUBFILETYPE) ---------------\n\n"); + sft->getParent()->printAll (); +#endif } } } @@ -2955,8 +2976,10 @@ void ExifManager::parse (bool isRaw, bool skipIgnored) frames.push_back(pi->getParent()); //frameRootDetected = true; not used afterward - //printf("\n--------------- FRAME -----------------------------\n\n"); - //pi->getParent()->printAll (); +#if PRINT_METADATA_TREE + printf("\n--------------- FRAME (PHOTOMETRIC) ---------------\n\n"); + pi->getParent()->printAll (); +#endif } } } @@ -2968,8 +2991,10 @@ void ExifManager::parse (bool isRaw, bool skipIgnored) roots.push_back(root); - //printf("\n~~~~~~~~~ ROOT ~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); - //root->printAll (); +#if PRINT_METADATA_TREE + printf("\n~~~~~~~~~ ROOT ~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); + root->printAll (); +#endif } while (ifdOffset && !onlyFirst); diff --git a/rtexif/rtexif.h b/rtexif/rtexif.h index bd2d82977..666c3a552 100644 --- a/rtexif/rtexif.h +++ b/rtexif/rtexif.h @@ -19,15 +19,15 @@ #ifndef _MEXIF3_ #define _MEXIF3_ -#include #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include #include