Skip to content

Commit

Permalink
MMVII: Exif: Add Exif read capability to cDataFileIm2D
Browse files Browse the repository at this point in the history
  • Loading branch information
meynardc committed Dec 16, 2024
1 parent ee74847 commit 05d17a9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
27 changes: 20 additions & 7 deletions MMVII/include/MMVII_ExifData.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
namespace MMVII {


// FIXME CM: interface that with cDataFileIm2D (cache lazy read ?)

class cExifData {
public:
cExifData() {}
void reset();
void reset(); // Reset all tags to nullopt

std::optional<std::string> mExifVersion;
// Main Tags
std::optional<unsigned> mPixelXDimension;
std::optional<unsigned> mPixelYDimension;

Expand All @@ -25,13 +23,16 @@ class cExifData {

std::optional<double> mFNumber;
std::optional<double> mExposureTime_s;
std::optional<double> mOrientation;

std::optional<std::string> mMake;
std::optional<std::string> mModel;
std::optional<std::string> mLensMake;
std::optional<std::string> mLensModel;

// Other Tags
std::optional<std::string> mExifVersion;
std::optional<double> mOrientation;

std::optional<double> mXResolution;
std::optional<double> mYResolution;
std::optional<unsigned> mResolutionUnit;
Expand All @@ -51,21 +52,33 @@ class cExifData {
std::optional<double> mGPSLatitude_deg;
std::optional<std::string> mGPSTimeStamp;
std::optional<std::string> mGPSDateStamp;
std::optional<uint64_t> mGPSTimeUTC_s;
std::optional<uint64_t> mGPSTimeUTC_s; // Unix UTC time from GPS receiver
std::optional<uint64_t> mGPSTimeUTC_ns;

std::optional<double> mDateTimeNumber_s; // Not Unix Epoch, but related to. Can be used to sort images.
std::optional<double> mDateTimeDigitizedNumber_s;
std::optional<double> mDateTimeOriginalNumber_s;

// Fill this structure from file aName (SVP: true: return false on error, false: halt program with error message)
bool FromFile(const std::string &aName, bool SVP=true);
// Fill only main tags
bool FromFileMainOnly(const std::string &aName, bool SVP=true);

static std::vector<std::string> StringListFromFile(const std::string &aName, bool SVP=true);
/*
* static methods
*/

// Fill argument anExif
static bool FromFile(const std::string &aName, cExifData &anExif, bool SVP=true);
// Return a struct
static cExifData CreateFromFile(const std::string &aName, bool SVP=true);

// Idem for main tags only
static bool FromFileMainOnly(const std::string &aName, cExifData &anExif, bool SVP=true);
static cExifData CreateFromFileMainOnly(const std::string &aName, bool SVP=true);

// Return a list of ALL exif tags found from file
static std::vector<std::string> StringListFromFile(const std::string &aName, bool SVP=true);
};


Expand Down
15 changes: 11 additions & 4 deletions MMVII/include/MMVII_Image2D.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef _MMVII_Images2D_H_
#define _MMVII_Images2D_H_

#include "MMVII_ExifData.h"
#include "MMVII_Images.h"

namespace MMVII
Expand Down Expand Up @@ -43,8 +44,11 @@ class cDataFileIm2D : public cRect2
const int & NbChannel () const ; ///< std accessor
const eTyNums & Type () const ; ///< std accessor
const std::string & Name() const; ///< std accessor
bool IsEmpty() const;
void AssertNotEmpty() const;
bool IsEmpty() const;
void AssertNotEmpty() const;
const cExifData& ExifDataAll(bool SVP=true) const;
const cExifData& ExifDataMain(bool SVP=true) const;
std::vector<std::string> ExifStrings(bool SVP=true) const;

/// Create a descriptor on existing file
static cDataFileIm2D Create(const std::string & aName,eForceGray);
Expand All @@ -67,13 +71,14 @@ class cDataFileIm2D : public cRect2

virtual ~cDataFileIm2D();

static bool IsPostFixNameImage(const std::string & aPost);
static bool IsNameWith_PostFixImage(const std::string & aPost);
static bool IsPostFixNameImage(const std::string & aPost);
static bool IsNameWith_PostFixImage(const std::string & aPost);
eForceGray ForceGray() const; ///< Accessor

private :
friend class cGdalApi;
enum class eCreationState {Created, AtFirstWrite, CreatedNoUpdate};
enum class eExifState {NotRead, MainTagsRead, AllTagsRead};
cDataFileIm2D(const std::string &,eTyNums,const cPt2di & aSz,int aNbChannel, const tOptions& aOptions, eForceGray, eCreationState) ;

void SetCreated() const;
Expand All @@ -85,6 +90,8 @@ class cDataFileIm2D : public cRect2
int mNbChannel; ///< Number of channels
eForceGray mForceGray;
tOptions mCreateOptions; ///< GDAL Creations options, depend of output driver (JPEG, TIFF, ...)
mutable cExifData mExifData;
mutable eExifState mExifState;
mutable eCreationState mCreationState; ///< support for creation of non updatable file image (create/write at once: .png, .jpg, ...)
};

Expand Down
23 changes: 13 additions & 10 deletions MMVII/src/ImagesBase/AppliExifData.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "MMVII_ExifData.h"
#include "MMVII_Image2D.h"
#include "cMMVII_Appli.h"

namespace MMVII
Expand Down Expand Up @@ -44,25 +45,22 @@ std::ostream& operator<<(std::ostream& os, std::optional<T> const& opt)

int cAppli_ExifData::Exe()
{
const auto default_precision{std::cout.precision()};
constexpr auto max_precision{std::numeric_limits<long double>::digits10};

for (const auto & aName : VectMainSet(0))
{
std::cout << "####### " << aName <<":" << std::endl;
auto aDataFileIm=cDataFileIm2D::Create(aName,eForceGray::No);
std::cout << "####### " << aDataFileIm.Name() <<":" << std::endl;
if (mDisp == 2) {
auto anExifList = cExifData::StringListFromFile(aName);
auto anExifList = aDataFileIm.ExifStrings();
for (const auto &s : anExifList)
std::cout << s << std::endl;
} else {
cExifData anExif;
if (mDisp == 0)
anExif = cExifData::CreateFromFile(aName);
else
anExif = cExifData::CreateFromFileMainOnly(aName);
std::cout << std::setprecision(17);
cExifData anExif = mDisp == 0 ? aDataFileIm.ExifDataAll() : aDataFileIm.ExifDataMain();

#define DISP_EXIF(key) std::cout << #key << ": " << anExif.m##key << std::endl;

DISP_EXIF(ExifVersion);

DISP_EXIF(PixelXDimension);
DISP_EXIF(PixelYDimension);

Expand All @@ -75,6 +73,7 @@ int cAppli_ExifData::Exe()
DISP_EXIF(Model);
DISP_EXIF(LensMake);
DISP_EXIF(LensModel);

if (mDisp == 0) {
DISP_EXIF(XResolution);
DISP_EXIF(YResolution);
Expand All @@ -90,13 +89,15 @@ int cAppli_ExifData::Exe()
DISP_EXIF(DateTimeDigitized);
DISP_EXIF(SubSecTimeDigitized);

std::cout << std::setprecision(max_precision);
DISP_EXIF(DateTimeNumber_s);
DISP_EXIF(DateTimeOriginalNumber_s);
DISP_EXIF(DateTimeDigitizedNumber_s);

DISP_EXIF(GPSLongitude_deg);
DISP_EXIF(GPSLatitude_deg);
DISP_EXIF(GPSAltitude_m);
std::cout << std::setprecision(default_precision);

DISP_EXIF(GPSDateStamp);
DISP_EXIF(GPSTimeStamp);
Expand All @@ -105,6 +106,8 @@ int cAppli_ExifData::Exe()

DISP_EXIF(ExifVersion);
}
std::cout << std::setprecision(default_precision);
#undef DISP_EXIF
}
std::cout << std::endl;
}
Expand Down
27 changes: 27 additions & 0 deletions MMVII/src/ImagesBase/FileImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ cDataFileIm2D::cDataFileIm2D(const std::string & aName, eTyNums aType, const cPt
mNbChannel (aNbChannel),
mForceGray (isFG),
mCreateOptions (aOptions),
mExifState (eExifState::NotRead),
mCreationState (aCreationState)
{
}
Expand Down Expand Up @@ -219,6 +220,32 @@ void cDataFileIm2D::SetCreatedNoUpdate() const
mCreationState = eCreationState::CreatedNoUpdate;
}

const cExifData& cDataFileIm2D::ExifDataAll(bool SVP) const
{
if (mExifState != eExifState::AllTagsRead)
{
mExifData.FromFile(mName,SVP);
mExifState = eExifState::AllTagsRead;

}
return mExifData;
}

const cExifData& cDataFileIm2D::ExifDataMain(bool SVP) const
{
if (mExifState != eExifState::MainTagsRead && mExifState != eExifState::AllTagsRead)
{
mExifData.FromFileMainOnly(mName,SVP);
mExifState = eExifState::MainTagsRead;
}
return mExifData;
}

std::vector<std::string> cDataFileIm2D::ExifStrings(bool SVP) const
{
return cExifData::StringListFromFile(mName,SVP);
}



bool cDataFileIm2D::IsPostFixNameImage(const std::string & aPost)
Expand Down

0 comments on commit 05d17a9

Please sign in to comment.