Bottleneck when loading Panasonic RW2 files, #5517

This commit is contained in:
Ingo Weyrich
2019-11-07 18:47:11 +01:00
parent bc6280afdf
commit ffa461d3de
2 changed files with 18 additions and 12 deletions

View File

@@ -54,13 +54,13 @@ Interpreter stdInterpreter;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
TagDirectory::TagDirectory () TagDirectory::TagDirectory ()
: attribs (ifdAttribs), order (HOSTORDER), parent (nullptr) {} : attribs (ifdAttribs), order (HOSTORDER), parent (nullptr), parseJPEG(true) {}
TagDirectory::TagDirectory (TagDirectory* p, const TagAttrib* ta, ByteOrder border) TagDirectory::TagDirectory (TagDirectory* p, const TagAttrib* ta, ByteOrder border)
: attribs (ta), order (border), parent (p) {} : attribs (ta), order (border), parent (p), parseJPEG(true) {}
TagDirectory::TagDirectory (TagDirectory* p, FILE* f, int base, const TagAttrib* ta, ByteOrder border, bool skipIgnored) TagDirectory::TagDirectory (TagDirectory* p, FILE* f, int base, const TagAttrib* ta, ByteOrder border, bool skipIgnored, bool parseJpeg)
: attribs (ta), order (border), parent (p) : attribs (ta), order (border), parent (p), parseJPEG(parseJpeg)
{ {
int numOfTags = get2 (f, order); int numOfTags = get2 (f, order);
@@ -980,9 +980,10 @@ Tag::Tag (TagDirectory* p, FILE* f, int base)
} }
} }
if (tag == 0x002e) { // location of the embedded preview image in raw files of Panasonic cameras if (parent->getParseJpeg() && tag == 0x002e) { // location of the embedded preview image in raw files of Panasonic cameras
ExifManager eManager(f, nullptr, true); ExifManager eManager(f, nullptr, true);
const auto fpos = ftell(f); const auto fpos = ftell(f);
if (fpos >= 0) { if (fpos >= 0) {
eManager.parseJPEG(fpos); // try to parse the exif data from the preview image eManager.parseJPEG(fpos); // try to parse the exif data from the preview image
@@ -1239,7 +1240,7 @@ defsubdirs:
for (size_t j = 0, i = 0; j < count; j++, i++) { for (size_t j = 0, i = 0; j < count; j++, i++) {
int newpos = base + toInt (j * 4, LONG); int newpos = base + toInt (j * 4, LONG);
fseek (f, newpos, SEEK_SET); fseek (f, newpos, SEEK_SET);
directory[i] = new TagDirectory (parent, f, base, attrib->subdirAttribs, order); directory[i] = new TagDirectory (parent, f, base, attrib->subdirAttribs, order, true, parent->getParseJpeg());
} }
// set the terminating NULL // set the terminating NULL
@@ -1374,7 +1375,7 @@ bool Tag::parseMakerNote (FILE* f, int base, ByteOrder bom )
value = new unsigned char[12]; value = new unsigned char[12];
fread (value, 1, 12, f); fread (value, 1, 12, f);
directory = new TagDirectory*[2]; directory = new TagDirectory*[2];
directory[0] = new TagDirectory (parent, f, base, panasonicAttribs, bom); directory[0] = new TagDirectory (parent, f, base, panasonicAttribs, bom, true, parent->getParseJpeg());
directory[1] = nullptr; directory[1] = nullptr;
} else { } else {
return false; return false;
@@ -2777,7 +2778,7 @@ void ExifManager::parseStd (bool skipIgnored) {
parse(false, skipIgnored); parse(false, skipIgnored);
} }
void ExifManager::parse (bool isRaw, bool skipIgnored) void ExifManager::parse (bool isRaw, bool skipIgnored, bool parseJpeg)
{ {
int ifdOffset = IFDOffset; int ifdOffset = IFDOffset;
@@ -2806,7 +2807,7 @@ void ExifManager::parse (bool isRaw, bool skipIgnored)
fseek (f, rml->exifBase + ifdOffset, SEEK_SET); fseek (f, rml->exifBase + ifdOffset, SEEK_SET);
// first read the IFD directory // first read the IFD directory
TagDirectory* root = new TagDirectory (nullptr, f, rml->exifBase, ifdAttribs, order, skipIgnored); TagDirectory* root = new TagDirectory (nullptr, f, rml->exifBase, ifdAttribs, order, skipIgnored, parseJpeg);
// fix ISO issue with nikon and panasonic cameras // fix ISO issue with nikon and panasonic cameras
Tag* make = root->getTag ("Make"); Tag* make = root->getTag ("Make");
@@ -3174,7 +3175,7 @@ void ExifManager::parseJPEG (int offset)
rml.reset(new rtengine::RawMetaDataLocation(0)); rml.reset(new rtengine::RawMetaDataLocation(0));
} }
rml->exifBase = tiffbase; rml->exifBase = tiffbase;
parse (false); parse (false, true, false);
if (rmlCreated) { if (rmlCreated) {
rml.reset(); rml.reset();
} }

View File

@@ -119,11 +119,12 @@ protected:
const TagAttrib* attribs; // descriptor table to decode the tags const TagAttrib* attribs; // descriptor table to decode the tags
ByteOrder order; // byte order ByteOrder order; // byte order
TagDirectory* parent; // parent directory (NULL if root) TagDirectory* parent; // parent directory (NULL if root)
bool parseJPEG;
static Glib::ustring getDumpKey (int tagID, const Glib::ustring &tagName); static Glib::ustring getDumpKey (int tagID, const Glib::ustring &tagName);
public: public:
TagDirectory (); TagDirectory ();
TagDirectory (TagDirectory* p, FILE* f, int base, const TagAttrib* ta, ByteOrder border, bool skipIgnored = true); TagDirectory (TagDirectory* p, FILE* f, int base, const TagAttrib* ta, ByteOrder border, bool skipIgnored = true, bool parseJpeg = true);
TagDirectory (TagDirectory* p, const TagAttrib* ta, ByteOrder border); TagDirectory (TagDirectory* p, const TagAttrib* ta, ByteOrder border);
virtual ~TagDirectory (); virtual ~TagDirectory ();
@@ -135,6 +136,10 @@ public:
{ {
return parent; return parent;
} }
inline bool getParseJpeg() const
{
return parseJPEG;
}
TagDirectory* getRoot (); TagDirectory* getRoot ();
inline int getCount () const inline int getCount () const
{ {
@@ -346,7 +351,7 @@ class ExifManager
Tag* saveCIFFMNTag (TagDirectory* root, int len, const char* name); Tag* saveCIFFMNTag (TagDirectory* root, int len, const char* name);
void parseCIFF (int length, TagDirectory* root); void parseCIFF (int length, TagDirectory* root);
void parse (bool isRaw, bool skipIgnored = true); void parse (bool isRaw, bool skipIgnored = true, bool parseJpeg = true);
public: public:
FILE* f; FILE* f;