summaryrefslogtreecommitdiff
path: root/src/common/fqterm_exif_extractor.h
blob: c55310851d3ac02bd7a1b69c10b16985a9a1dac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef FQTERM_EXIF_EXTRACTOR
#define FQTERM_EXIF_EXTRACTOR

#include "fqterm_trace.h"

#include <map>
#include <string>
#include <cstdint>

namespace FQTerm {

class ExifExtractor
{
public:

  enum DATATYPE {ZEORGARD = 0, UNSIGNEDCHAR = 1, ASCIISTRING = 2, UNSIGNEDINT16 = 3, UNSIGNEDINT32 = 4, 
    UNSIGNEDRATIONAL = 5, SIGNEDCHAR = 6, UNDEFINED = 7, SIGNEDSHORT = 8, SIGNEDLONG = 9, RATIONAL = 10,
    SIGNEDFLOAT = 11, DOUBLEFLOAT = 12, MAXGUARD = 13};


  ExifExtractor();
  ~ExifExtractor();
  std::string extractExifInfo(std::string fileName);
  std::string extractExifInfo(FILE* file);

  std::string info();

  std::string operator[](const std::string& key);

private:
  void postRead();

  std::string readInfo();
  bool analyzeIFD0TagInfo();

  bool analyzeSubIFDTagInfo();

  bool readIFD0();
  bool readSubIFD();
  bool isReadable();
  bool checkEndian();
  void toggleEndian(void* buf, size_t s);

  void reset();

  bool read(void* buffer, size_t elementSize, size_t count);

  void seek(long offset, int origin);

  void rewind();

  template<class T>
  T gcd(T a, T b) {
    if (a == 0 || b == 0)
      return a + b;
    return gcd(b, a % b);
  }


  bool toggle_;
  std::map<std::string, std::string> exifKeyValuePairs_;
  FILE* exifFile_;
  uint32_t ifdOffset_;
  uint32_t subIfdOffset_;

  static const uint16_t IFD0Tag[16];
  static const char IFD0TagName[16][30];
  static const uint16_t SubIFDTag[38];
  static const char SubIFDTagName[38][30];
  static const char exifHeaderStandard[6];

  std::string exifInformation_;
};



} //namespace FQTerm

#endif