00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef INCL_PLEXIF
00018 #define INCL_PLEXIF
00019
00020 #ifdef _MSC_VER // The microsoft compiler generates masses
00021
00022 #pragma warning(disable: 4786) // for debugger warnings for sets and maps
00023 #endif
00024
00025 #include "plpaintlibdefs.h"
00026 #include "plcountedpointer.h"
00027
00028 #include <cstdio>
00029 #include <vector>
00030 #include <string>
00031 #include <map>
00032
00033 struct jpeg_decompress_struct;
00034 struct jpeg_compress_struct;
00035
00036
00037 struct _PLExifTranslator;
00038 struct _PLExifTagValues;
00039 struct _PLExifFormatter;
00040
00041 class PLExifTag;
00042 typedef PLCountedPointer<PLExifTag> PLExifTagCPtr;
00043 typedef std::vector<PLExifTagCPtr> PLExifTagList;
00044 typedef PLCountedArrayPointer<PLBYTE> PLByteCPtr;
00045
00046
00047 class PLExif
00048 {
00049 public:
00050 PLExif();
00051 ~PLExif();
00052
00053
00054
00055 void Clear();
00056
00057
00058 size_t GetRawDataSize() const;
00059 PLBYTE * GetRawData();
00060 const PLBYTE * GetRawData() const;
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 const PLExifTagList & GetAllTags() const;
00073 const PLExifTagList & GetMainTags() const;
00074 const PLExifTagList & GetSubTags() const;
00075 const PLExifTagList & GetManufacturerTags() const;
00076
00077
00078
00079
00080 const PLExifTagCPtr * GetAllTagsC(size_t & size) const;
00081 const PLExifTagCPtr * GetMainTagsC(size_t & size) const;
00082 const PLExifTagCPtr * GetSubTagsC(size_t & size) const;
00083 const PLExifTagCPtr * GetManufacturerTagsC(size_t & size) const;
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 PLExifTag * GetTag(const char * TagShortName) const;
00098 PLExifTag * GetTag(const std::string & TagShortName) const
00099 { return GetTag(TagShortName.c_str()); }
00100
00101
00102
00103 PLExifTag * GetTag(const char * TagShortName, std::string & Value) const;
00104 PLExifTag * GetTag(const std::string & TagShortName, std::string & Value) const
00105 { return GetTag(TagShortName.c_str(), Value); }
00106
00107
00108
00109 PLExifTag * GetTagCommon(const char * TagShortName, std::string & Value) const;
00110 PLExifTag * GetTagCommon(const std::string & TagShortName, std::string & Value) const
00111 { return GetTagCommon(TagShortName.c_str(), Value); }
00112
00113
00114
00115 PLExifTag * GetTag(const char * TagShortName, double & Value) const;
00116 PLExifTag * GetTag(const std::string & TagShortName, double & Value) const
00117 { return GetTag(TagShortName.c_str(), Value); }
00118
00119
00120
00121 std::string & TagStr(const char * TagShortName) const;
00122 std::string & TagStr(const std::string & TagShortName) const
00123 { return TagStr(TagShortName.c_str()); }
00124
00125
00126
00127 std::string & TagStrCommon(const char * TagShortName) const;
00128 std::string & TagStrCommon(const std::string & TagShortName) const
00129 { return TagStrCommon(TagShortName.c_str()); }
00130
00131
00132
00133
00134
00135 const char * TagCStr(const char * TagShortName) const;
00136 const char * TagCStr(const std::string & TagShortName) const
00137 { return TagCStr(TagShortName.c_str()); }
00138
00139
00140
00141 const char * TagCStrCommon(const char * TagShortName) const;
00142 const char * TagCStrCommon(const std::string & TagShortName) const
00143 { return TagCStrCommon(TagShortName.c_str()); }
00144
00145
00146
00147 void ReadData(const jpeg_decompress_struct * pcinfo);
00148
00149
00150 void WriteData(jpeg_compress_struct * pcinfo);
00151
00152
00153 private:
00154 void decode();
00155
00156 void ReadIFD(const _PLExifTagValues * Tags, char * Prefix, PLExifTagList & sectionList);
00157 void ExpandBinaryTag(const std::string & Src, const _PLExifTagValues *Tags, PLUINT Type, PLExifTagList & sectionList);
00158 void DecodeCanCustomFncs(const PLExifTag & rootTag, const _PLExifTagValues *Tags, PLExifTagList & sectionList);
00159
00160 void CopyTag(const char * Src, const char * Dst);
00161 void SetTag(const char * Dst, const char * Value);
00162 void SetTag(const char * Dst, const std::string & Value)
00163 { SetTag(Dst, Value.c_str()); }
00164 void AddTag(const char * Dst, const char * SrcTag, const char * Skip = NULL, const char * Sep = NULL);
00165 void AddStr(const char * Dst, const std::string & SrcStr, const char * Skip = NULL, const char * Sep = NULL);
00166 void FormatRange(double Low, double High, std::string & Str);
00167
00168
00169
00170
00171 void SetPos(size_t Pos);
00172 size_t GetPos();
00173
00174 PLWORD GetU16();
00175 PLLONG GetU32();
00176 void Read(void * Buffer, size_t Size);
00177
00178
00179
00180 private:
00181
00182 PLByteCPtr m_Data;
00183 size_t m_DataSize;
00184
00185
00186
00187
00188 size_t m_Pos;
00189 size_t m_IdfOffset;
00190 bool m_Endian;
00191
00192 PLExifTagList m_AllTags;
00193 PLExifTagList m_MainTags;
00194 PLExifTagList m_SubTags;
00195 PLExifTagList m_ManufacturerTags;
00196
00197 typedef std::map<std::string, PLExifTagCPtr> TagMap;
00198 TagMap m_Tags;
00199
00200 };
00201
00202
00203 class PLExifTag
00204 {
00205 public:
00206
00207 ~PLExifTag();
00208
00209
00210 const char * GetShortNameCStr() const;
00211 const char * GetDescriptionCStr() const;
00212
00213
00214 const char * GetValueCStr() const;
00215
00216 const char * GetValueCommonCStr() const;
00217
00218
00219 const std::string & GetShortName() const;
00220 const std::string GetDescription() const;
00221
00222
00223 const std::string & GetValue() const;
00224
00225 const std::string & GetValueCommon() const;
00226
00227 private:
00228
00229 size_t RenDef(PLBYTE * & Buffer);
00230 size_t RenUDef(PLBYTE * & Buffer);
00231 size_t RenUndef(PLBYTE * & Buffer);
00232 size_t RenStr(PLBYTE * & Buffer);
00233 size_t RenURat(PLBYTE * & Buffer);
00234 size_t RenRat(PLBYTE * & Buffer);
00235
00236
00237 void CnvRat(std::string & result);
00238 void CnvRatAp(std::string & result);
00239 void CnvFrac(std::string & result);
00240 void CnvApexShutter(std::string & result);
00241 void CnvApexAp(std::string & result);
00242 void CnvCompCfg(std::string & result);
00243 void CnvCanINo(std::string & result);
00244 void CnvCanSNo(std::string & result);
00245 void CnvCanFlash(std::string & result);
00246 void CnvCanAFPnt(std::string & result);
00247
00248
00249
00250 friend struct _PLExifTagValues;
00251 friend struct _PLExifFormatter;
00252
00253 private:
00254 PLExifTag(PLUINT TagNo, PLUINT Format, PLUINT NoComp);
00255
00256 void CleanWorkingArea();
00257 void Swizzle();
00258 void Render();
00259 void DoTranslation();
00260 void Value(size_t Index);
00261 double GetDouble(size_t Index);
00262
00263
00264 const _PLExifTagValues * m_Tag;
00265 const _PLExifFormatter * m_Fmt;
00266
00267 std::string m_ShortName;
00268 std::string m_Lookup;
00269
00270 size_t m_TagNo;
00271 size_t m_Format;
00272 size_t m_NoComp;
00273 size_t m_Size;
00274 PLByteCPtr m_Buffer;
00275 size_t m_Pos;
00276
00277
00278 std::string m_Value;
00279 std::string m_Common;
00280 PLLONG m_Num;
00281 PLLONG m_Den;
00282 PLLONG m_Int;
00283 PLUINT m_UInt;
00284 double m_Double;
00285
00286 private:
00287
00288
00289
00290
00291 friend class PLExif;
00292
00293 private:
00294
00295 static _PLExifTagValues MainTags[];
00296 static _PLExifTagValues SubTags[];
00297 static _PLExifTagValues NikonTags[];
00298 static _PLExifTagValues Nikon2Tags[];
00299 static _PLExifTagValues OlympusTags[];
00300 static _PLExifTagValues CanonTags[];
00301 static _PLExifTagValues CanonSet1[];
00302 static _PLExifTagValues CanonSet2[];
00303 static _PLExifTagValues CanonCFn[];
00304 static _PLExifTagValues FujifilmTags[];
00305 static _PLExifTagValues CasioTags[];
00306 static _PLExifFormatter rgExifFormat[];
00307 };
00308
00309
00310
00311
00312
00313
00314 #endif