Parsing few more tags

This commit is contained in:
selim mustafaev 2018-09-13 10:12:21 +03:00
parent a467b687dc
commit 4752b4d6b2
3 changed files with 63 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.idea/ .idea/
cmake-build-debug/

View File

@ -2,6 +2,8 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <iomanip> #include <iomanip>
#include <algorithm>
#include <numeric>
static const std::map<TiffTag, std::string> tagDescriptions = { static const std::map<TiffTag, std::string> tagDescriptions = {
{NEW_SUBFILE_TYPE, "New subfile type"}, {NEW_SUBFILE_TYPE, "New subfile type"},
@ -26,7 +28,14 @@ static const std::map<TiffTag, std::string> tagDescriptions = {
{DATE_TIME, "Date/Time"}, {DATE_TIME, "Date/Time"},
{XML_PACKET, "XML Packet"}, {XML_PACKET, "XML Packet"},
{CFA_REPEAT_PATTERN_DIM, "CFA repeat pattern"}, {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) { 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 PALETTE_COLOR: stream << "palette color"; break;
case TRANSPARENCY_MASK: stream << "transparency mask"; break; case TRANSPARENCY_MASK: stream << "transparency mask"; break;
case YCBCR: stream << "YCbCr (YUV)"; 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; case LINEAR_RAW: stream << "linear raw"; break;
default: stream << "undefined"; break; default: stream << "undefined"; break;
} }
@ -57,7 +66,7 @@ std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr) {
} }
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& stream, const RationalType<T>& rational) { std::ostream& operator<<(std::ostream& stream, const RationalType<T>& rational) {
stream << std::to_string(rational.numerator) + "/" + std::to_string(rational.denominator); stream << 1.0*rational.numerator/rational.denominator;
return stream; return stream;
} }
@ -98,7 +107,17 @@ std::ostream& operator<<(std::ostream& stream, PlanarConfiguration conf) {
template<typename T> template<typename T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vector) { std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vector) {
std::ios_base::fmtflags f(stream.flags());
if(vector.size() > 10) {
stream << "<vector> (" + std::to_string(vector.size()) + ")"; stream << "<vector> (" + 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; return stream;
} }
@ -107,6 +126,23 @@ std::ostream& operator<<(std::ostream& stream, const std::vector<CFAPatternDim>&
return stream; return stream;
} }
std::ostream& operator<<(std::ostream& stream, const std::vector<CFAPattern>& 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<typename T> template<typename T>
void ImageFileDirectory::parseValueImpl(char *filePtr, IfdEntry *entry) { void ImageFileDirectory::parseValueImpl(char *filePtr, IfdEntry *entry) {
size_t sizeOfValue = sizeOfType(entry->type)*entry->numberOfValues; size_t sizeOfValue = sizeOfType(entry->type)*entry->numberOfValues;
@ -132,6 +168,7 @@ void ImageFileDirectory::parseValue(char *filePtr, IfdEntry *entry) {
case ORIENTATION: parseValueImpl<Orientation>(filePtr, entry); break; case ORIENTATION: parseValueImpl<Orientation>(filePtr, entry); break;
case PLANAR_CONFIGURATION: parseValueImpl<PlanarConfiguration>(filePtr, entry); break; case PLANAR_CONFIGURATION: parseValueImpl<PlanarConfiguration>(filePtr, entry); break;
case CFA_REPEAT_PATTERN_DIM: parseValueImpl<CFAPatternDim>(filePtr, entry); break; case CFA_REPEAT_PATTERN_DIM: parseValueImpl<CFAPatternDim>(filePtr, entry); break;
case CFA_PATTERN: parseValueImpl<CFAPattern>(filePtr, entry); break;
default: parseValueImpl<T>(filePtr, entry); break; default: parseValueImpl<T>(filePtr, entry); break;
} }
} }

23
TIFF.h
View File

@ -53,7 +53,14 @@ enum TiffTag: uint16_t {
DATE_TIME = 0x132, DATE_TIME = 0x132,
XML_PACKET = 0x2BC, XML_PACKET = 0x2BC,
CFA_REPEAT_PATTERN_DIM = 0x828D, 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<uint32_t>; using Rational = RationalType<uint32_t>;
using SRational = RationalType<int32_t>; using SRational = RationalType<int32_t>;
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, Compression compression);
std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr); std::ostream& operator<<(std::ostream& stream, PhotometricInterpretation pr);
@ -133,6 +150,8 @@ public:
Compression, PhotometricInterpretation, std::vector<Compression>, std::vector<PhotometricInterpretation>, Compression, PhotometricInterpretation, std::vector<Compression>, std::vector<PhotometricInterpretation>,
ResolutionUnit, std::vector<ResolutionUnit>, Orientation, std::vector<Orientation>, ResolutionUnit, std::vector<ResolutionUnit>, Orientation, std::vector<Orientation>,
PlanarConfiguration, std::vector<PlanarConfiguration>, PlanarConfiguration, std::vector<PlanarConfiguration>,
CFAPatternDim, std::vector<CFAPatternDim>,
CFAPattern, std::vector<CFAPattern>,
std::vector<uint8_t>, std::vector<uint16_t>, std::vector<uint32_t>, std::vector<Rational>, std::vector<uint8_t>, std::vector<uint16_t>, std::vector<uint32_t>, std::vector<Rational>,
std::vector<int8_t>, std::vector<int16_t>, std::vector<int32_t>, std::vector<SRational>, std::vector<int8_t>, std::vector<int16_t>, std::vector<int32_t>, std::vector<SRational>,
std::vector<float>, std::vector<double>>; std::vector<float>, std::vector<double>>;