exif.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**************************************************************************
  2. exif.h -- A simple ISO C++ library to parse basic EXIF
  3. information from a JPEG file.
  4. Based on the description of the EXIF file format at:
  5. -- http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
  6. -- http://www.media.mit.edu/pia/Research/deepview/exif.html
  7. -- http://www.exif.org/Exif2-2.PDF
  8. Copyright (c) 2010-2016 Mayank Lahiri
  9. mlahiri@gmail.com
  10. All rights reserved.
  11. Redistribution and use in source and binary forms, with or without
  12. modification, are permitted provided that the following conditions are met:
  13. -- Redistributions of source code must retain the above copyright notice,
  14. this list of conditions and the following disclaimer.
  15. -- Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS
  19. OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef __EXIF_H
  30. #define __EXIF_H
  31. #include <string>
  32. namespace easyexif {
  33. //
  34. // Class responsible for storing and parsing EXIF information from a JPEG blob
  35. //
  36. class EXIFInfo {
  37. public:
  38. // Parsing function for an entire JPEG image buffer.
  39. //
  40. // PARAM 'data': A pointer to a JPEG image.
  41. // PARAM 'length': The length of the JPEG image.
  42. // RETURN: PARSE_EXIF_SUCCESS (0) on succes with 'result' filled out
  43. // error code otherwise, as defined by the PARSE_EXIF_ERROR_* macros
  44. int parseFrom(const unsigned char *data, unsigned length);
  45. int parseFrom(const std::string &data);
  46. // Parsing function for an EXIF segment. This is used internally by parseFrom()
  47. // but can be called for special cases where only the EXIF section is
  48. // available (i.e., a blob starting with the bytes "Exif\0\0").
  49. int parseFromEXIFSegment(const unsigned char *buf, unsigned len);
  50. // Set all data members to default values.
  51. void clear();
  52. // Data fields filled out by parseFrom()
  53. char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
  54. std::string ImageDescription; // Image description
  55. std::string Make; // Camera manufacturer's name
  56. std::string Model; // Camera model
  57. unsigned short Orientation; // Image orientation, start of data corresponds to
  58. // 0: unspecified in EXIF data
  59. // 1: upper left of image
  60. // 3: lower right of image
  61. // 6: upper right of image
  62. // 8: lower left of image
  63. // 9: undefined
  64. unsigned short BitsPerSample; // Number of bits per component
  65. std::string Software; // Software used
  66. std::string DateTime; // File change date and time
  67. std::string DateTimeOriginal; // Original file date and time (may not exist)
  68. std::string DateTimeDigitized; // Digitization date and time (may not exist)
  69. std::string SubSecTimeOriginal; // Sub-second time that original picture was taken
  70. std::string Copyright; // File copyright information
  71. double ExposureTime; // Exposure time in seconds
  72. double FNumber; // F/stop
  73. unsigned short ExposureProgram; // Exposure program
  74. // 0: Not defined
  75. // 1: Manual
  76. // 2: Normal program
  77. // 3: Aperture priority
  78. // 4: Shutter priority
  79. // 5: Creative program
  80. // 6: Action program
  81. // 7: Portrait mode
  82. // 8: Landscape mode
  83. unsigned short ISOSpeedRatings; // ISO speed
  84. double ShutterSpeedValue; // Shutter speed (reciprocal of exposure time)
  85. double ExposureBiasValue; // Exposure bias value in EV
  86. double SubjectDistance; // Distance to focus point in meters
  87. double FocalLength; // Focal length of lens in millimeters
  88. unsigned short FocalLengthIn35mm; // Focal length in 35mm film
  89. char Flash; // 0 = no flash, 1 = flash used
  90. unsigned short FlashReturnedLight;// Flash returned light status
  91. // 0: No strobe return detection function
  92. // 1: Reserved
  93. // 2: Strobe return light not detected
  94. // 3: Strobe return light detected
  95. unsigned short FlashMode; // Flash mode
  96. // 0: Unknown
  97. // 1: Compulsory flash firing
  98. // 2: Compulsory flash suppression
  99. // 3: Automatic mode
  100. unsigned short MeteringMode; // Metering mode
  101. // 1: average
  102. // 2: center weighted average
  103. // 3: spot
  104. // 4: multi-spot
  105. // 5: multi-segment
  106. unsigned ImageWidth; // Image width reported in EXIF data
  107. unsigned ImageHeight; // Image height reported in EXIF data
  108. struct Geolocation_t { // GPS information embedded in file
  109. double Latitude; // Image latitude expressed as decimal
  110. double Longitude; // Image longitude expressed as decimal
  111. double Altitude; // Altitude in meters, relative to sea level
  112. char AltitudeRef; // 0 = above sea level, -1 = below sea level
  113. double DOP; // GPS degree of precision (DOP)
  114. struct Coord_t {
  115. double degrees;
  116. double minutes;
  117. double seconds;
  118. char direction;
  119. } LatComponents, LonComponents; // Latitude, Longitude expressed in deg/min/sec
  120. } GeoLocation;
  121. struct LensInfo_t { // Lens information
  122. double FStopMin; // Min aperture (f-stop)
  123. double FStopMax; // Max aperture (f-stop)
  124. double FocalLengthMin; // Min focal length (mm)
  125. double FocalLengthMax; // Max focal length (mm)
  126. double FocalPlaneXResolution; // Focal plane X-resolution
  127. double FocalPlaneYResolution; // Focal plane Y-resolution
  128. unsigned short FocalPlaneResolutionUnit; // Focal plane resolution unit
  129. // 1: No absolute unit of measurement.
  130. // 2: Inch.
  131. // 3: Centimeter.
  132. // 4: Millimeter.
  133. // 5: Micrometer.
  134. std::string Make; // Lens manufacturer
  135. std::string Model; // Lens model
  136. } LensInfo;
  137. EXIFInfo() {
  138. clear();
  139. }
  140. };
  141. }
  142. // Parse was successful
  143. #define PARSE_EXIF_SUCCESS 0
  144. // No JPEG markers found in buffer, possibly invalid JPEG file
  145. #define PARSE_EXIF_ERROR_NO_JPEG 1982
  146. // No EXIF header found in JPEG file.
  147. #define PARSE_EXIF_ERROR_NO_EXIF 1983
  148. // Byte alignment specified in EXIF file was unknown (not Motorola or Intel).
  149. #define PARSE_EXIF_ERROR_UNKNOWN_BYTEALIGN 1984
  150. // EXIF header was found, but data was corrupted.
  151. #define PARSE_EXIF_ERROR_CORRUPT 1985
  152. #endif