From 4752b4d6b2d8e8bfd31445c0c0a8f3b183fe81e0 Mon Sep 17 00:00:00 2001 From: selim mustafaev Date: Thu, 13 Sep 2018 10:12:21 +0300 Subject: [PATCH] Parsing few more tags --- .gitignore | 1 + TIFF.cpp | 45 +++++++++++++++++++++++++++++++++++++++++---- TIFF.h | 23 +++++++++++++++++++++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9f11b75..990936c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +cmake-build-debug/ diff --git a/TIFF.cpp b/TIFF.cpp index d405625..7d10d7a 100644 --- a/TIFF.cpp +++ b/TIFF.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include static const std::map tagDescriptions = { {NEW_SUBFILE_TYPE, "New subfile type"}, @@ -26,7 +28,14 @@ static const std::map tagDescriptions = { {DATE_TIME, "Date/Time"}, {XML_PACKET, "XML Packet"}, {CFA_REPEAT_PATTERN_DIM, "CFA repeat pattern"}, - {CFA_PATTERN, "CFA pattern"} + {CFA_PATTERN, "CFA pattern"}, + {EXPOSURE_TIME, "Exposure time (seconds)"}, + {F_NUMBER, "F-Number (relative aperture)"}, + {EXIF_IFD, "EXIF IFD offset"}, + {ISO_SPEED_RATINGS, "ISO"}, + {DATE_TIME_ORIGINAL, "Date/time original"}, + {FOCAL_LENGTH, "Focal length (mm)"}, + {TIFF_EP_STANDARD_ID, "TIFF/EP standard ID"} }; std::ostream &operator<<(std::ostream &stream, Compression compression) { @@ -48,7 +57,7 @@ std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr) { case PALETTE_COLOR: stream << "palette color"; break; case TRANSPARENCY_MASK: stream << "transparency mask"; break; case YCBCR: stream << "YCbCr (YUV)"; break; - case COLOR_FILTER_ARRAY: stream << "color filter array"; break; + case COLOR_FILTER_ARRAY: stream << "CFA (color filter array)"; break; case LINEAR_RAW: stream << "linear raw"; break; default: stream << "undefined"; break; } @@ -57,7 +66,7 @@ std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr) { } template std::ostream& operator<<(std::ostream& stream, const RationalType& rational) { - stream << std::to_string(rational.numerator) + "/" + std::to_string(rational.denominator); + stream << 1.0*rational.numerator/rational.denominator; return stream; } @@ -98,7 +107,17 @@ std::ostream& operator<<(std::ostream& stream, PlanarConfiguration conf) { template std::ostream& operator<<(std::ostream& stream, const std::vector& vector) { - stream << " (" + std::to_string(vector.size()) + ")"; + std::ios_base::fmtflags f(stream.flags()); + if(vector.size() > 10) { + stream << " (" + std::to_string(vector.size()) + ")"; + } else { + stream << std::setw(0) << "[" << vector[0]; + std::accumulate(std::next(vector.begin()), vector.end(), std::string(), [&stream](std::string a, T elem){ + stream << ", " << elem; + }); + stream << "]"; + } + stream.flags(f); return stream; } @@ -107,6 +126,23 @@ std::ostream& operator<<(std::ostream& stream, const std::vector& return stream; } +std::ostream& operator<<(std::ostream& stream, const std::vector& vector) { + std::string pattern; + for(auto filter: vector) { + switch (filter) { + case RED: pattern += "R"; break; + case GREEN: pattern += "G"; break; + case BLUE: pattern += "B"; break; + case CYAN: pattern += "C"; break; + case MAGENTA: pattern += "M"; break; + case YELLOW: pattern += "Y"; break; + case WHITE: pattern += "W"; break; + } + } + stream << pattern; + return stream; +} + template void ImageFileDirectory::parseValueImpl(char *filePtr, IfdEntry *entry) { size_t sizeOfValue = sizeOfType(entry->type)*entry->numberOfValues; @@ -132,6 +168,7 @@ void ImageFileDirectory::parseValue(char *filePtr, IfdEntry *entry) { case ORIENTATION: parseValueImpl(filePtr, entry); break; case PLANAR_CONFIGURATION: parseValueImpl(filePtr, entry); break; case CFA_REPEAT_PATTERN_DIM: parseValueImpl(filePtr, entry); break; + case CFA_PATTERN: parseValueImpl(filePtr, entry); break; default: parseValueImpl(filePtr, entry); break; } } diff --git a/TIFF.h b/TIFF.h index a5f2ffe..afc2e96 100644 --- a/TIFF.h +++ b/TIFF.h @@ -53,7 +53,14 @@ enum TiffTag: uint16_t { DATE_TIME = 0x132, XML_PACKET = 0x2BC, CFA_REPEAT_PATTERN_DIM = 0x828D, - CFA_PATTERN = 0x828E + CFA_PATTERN = 0x828E, + EXPOSURE_TIME = 0x829A, + F_NUMBER = 0x829D, + EXIF_IFD = 0x8769, + ISO_SPEED_RATINGS = 0x8827, + DATE_TIME_ORIGINAL = 0x9003, + FOCAL_LENGTH = 0x920A, + TIFF_EP_STANDARD_ID = 0x9216 }; @@ -117,7 +124,17 @@ struct RationalType { using Rational = RationalType; using SRational = RationalType; -typedef uint16_t CFAPatternDim; + +enum CFAPatternDim: uint16_t {}; +enum CFAPattern: uint8_t { + RED = 0, + GREEN = 1, + BLUE = 2, + CYAN = 3, + MAGENTA = 4, + YELLOW = 5, + WHITE = 6 +}; std::ostream& operator<<(std::ostream& stream, Compression compression); std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr); @@ -133,6 +150,8 @@ public: Compression, PhotometricInterpretation, std::vector, std::vector, ResolutionUnit, std::vector, Orientation, std::vector, PlanarConfiguration, std::vector, + CFAPatternDim, std::vector, + CFAPattern, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector, std::vector>;