File: metacam.h

package info (click to toggle)
metacam 0.6-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 184 kB
  • ctags: 196
  • sloc: cpp: 1,750; makefile: 70
file content (274 lines) | stat: -rw-r--r-- 6,671 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* This file is -*-C++-*-
------------------------------------------------------------------------------
MetaCam - Extract EXIF information from digital camera files, with
support for Vendor specific blocks.
Copyright (C) 2000 Daniel Stephens (daniel@cheeseplant.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
------------------------------------------------------------------------------

$Id: metacam.h,v 1.3 2001/07/26 14:56:01 daniel Exp $

*/

#ifndef METACAM_H_INCLUDED
#define METACAM_H_INCLUDED

#include <map>
#include <vector>
#include <string>

class IFD;
class IFDEntry;
class istream;
class ostream;

typedef unsigned long tiffUNSIGNED;
typedef signed long tiffSIGNED;

const unsigned short tBYTE      = 1;
const unsigned short tASCII     = 2;
const unsigned short tSHORT     = 3;
const unsigned short tLONG      = 4;
const unsigned short tRATIONAL  = 5;
const unsigned short tSBYTE     = 6;
const unsigned short tUNDEFINED = 7;
const unsigned short tSSHORT    = 8;
const unsigned short tSLONG     = 9;
const unsigned short tSRATIONAL = 10;
const unsigned short tFLOAT     = 11;
const unsigned short tDOUBLE    = 12;

class tiffRATIONAL
{
public:
    tiffUNSIGNED num;
    tiffUNSIGNED den;
    
    tiffRATIONAL() : num(0), den(0) {};
    tiffRATIONAL(tiffUNSIGNED n, tiffUNSIGNED d) : num(n), den(d) {};

    bool operator == (const tiffRATIONAL &r) const {
	return ((num == r.num) && (den == r.den));
    }
    bool operator != (const tiffRATIONAL &r) const {
	return ((num != r.num) || (den != r.den));
    }

    operator double() const {
	double n(num);
	double d(den);
	return n/d;
    }
    
    void Normalize();
};

class tiffSRATIONAL
{
public:
    tiffSIGNED num;
    tiffSIGNED den;
    
    tiffSRATIONAL() : num(0), den(0) {};
    tiffSRATIONAL(tiffSIGNED n, tiffSIGNED d) : num(n), den(d) {};
    
    bool operator == (const tiffSRATIONAL &r) const {
	return ((num == r.num) && (den == r.den));
    }
    bool operator != (const tiffSRATIONAL &r) const {
	return ((num != r.num) || (den != r.den));
    }
    
    operator double() const {
	double n(num);
	double d(den);
	return n/d;
    }

    void Normalize();
};

inline ostream &operator << (ostream &os, const tiffRATIONAL &r)
{
    os << r.num << "/" << r.den;
    return os;
}
    
inline ostream &operator << (ostream &os, const tiffSRATIONAL &r)
{
    os << r.num << "/" << r.den;
    return os;
}

class tiffFile
{
private:
    friend class IFD;
    friend class IFDEntry;

    istream &is;
    unsigned long global_offset;
    bool bigendian;

protected:
    void Seek(unsigned long ofs);
    unsigned long Get_Offset() const {
	return is.tellg()-global_offset;
    }
    void Get_Data(unsigned char *buf, size_t bytes);
    unsigned char  Get_UByte();
    unsigned short Get_UShort();
    unsigned long  Get_ULong();
    signed char    Get_SByte();
    signed short   Get_SShort();
    signed long    Get_SLong();

    unsigned long First_IFD() {
	Seek(4);
	return Get_ULong();
    }
public:
    tiffFile(istream &i, unsigned long ofs=0);

    IFD Get_IFD();
    IFD Get_IFD(unsigned long ofs, unsigned long tagofs=0);
};

class IFDEntry;

class IFD
{
private:
    tiffFile &file;
    unsigned long ofs;
    unsigned short entries;
    unsigned long next_ifd;

    IFDEntry **table;

public:
    IFD(const IFD &);
    IFD &operator=(const IFD &);
    IFD(tiffFile &t, unsigned long o, unsigned long tagofs = 0);
    ~IFD();

    bool operator !() const {return ofs==0;}
    operator bool() const {return ofs!=0;}

    tiffFile &File() const {return file;}
    
    const IFDEntry &operator[](int n) const;
    unsigned short Entries() const {return entries;}
    IFD Next_IFD() const {
	return file.Get_IFD(next_ifd);
    }
};

class IFDEntry
{
    friend class IFD;
private:
    tiffFile &file;

    unsigned long tag;
    unsigned short type;
    unsigned long values;
    unsigned long offset;
public:
    IFDEntry(tiffFile &t) : file(t), tag(0), type(0), values(0), offset(0) {};
    
    static int Type_Length(unsigned short);

    int Length() const {return Type_Length(type) * values;}

    unsigned long  Tag() const {return tag;}
    unsigned short Type() const {return type;}
    unsigned long  Values() const {return values;}
    unsigned long  Offset() const {return offset;}

    void Output_Value(ostream &os) const;

    vector<tiffUNSIGNED> Get_UVALUES() const;
    vector<tiffSIGNED> Get_SVALUES() const;
    vector<tiffRATIONAL> Get_RATIONALS() const;
    vector<tiffSRATIONAL> Get_SRATIONALS() const;
    vector<string> Get_STRINGS() const;
    vector<unsigned char> Get_OPAQUE() const;
};

inline ostream &
operator<<(ostream &os, const IFDEntry &e)
{
    os << "[TAG " << hex << e.Tag() << dec << " TYPE " << e.Type() 
       << " VALUES " << e.Values() << " OFFSET " << e.Offset() << "]";
    return os;
}


class idpair
{
private:
    unsigned long tag;
    unsigned short type;
public:
    idpair() : tag(0), type(0) {};
    idpair(unsigned long a, unsigned short b) : tag(a), type(b) {};

    bool operator==(const idpair &i) const {
	return (tag==i.tag) && (type == i.type);
    }
    bool operator!=(const idpair &i) const {
	return (tag!=i.tag) || (type != i.type);
    }
    bool operator<=(const idpair &i) const {
	if (tag < i.tag) return true;
	if (tag > i.tag) return false;
	return (type <= i.type);
    }
    bool operator<(const idpair &i) const {
	if (tag < i.tag) return true;
	if (tag > i.tag) return false;
	return (type < i.type);
    }
    bool operator>(const idpair &i) const {
	if (tag > i.tag) return true;
	if (tag < i.tag) return false;
	return (type > i.type);
    }
    bool operator>=(const idpair &i) const {
	if (tag > i.tag) return true;
	if (tag < i.tag) return false;
	return (type >= i.type);
    }
};


typedef map<idpair, IFDEntry*> tagmap;

typedef void dpyFunction(ostream &os, const char *, const IFDEntry &e);

struct knowntag
{
    unsigned long tag;
    unsigned short type;
    int verbose;
    const char *name;
    dpyFunction *func;
};



#endif /* METACAM_H_INCLUDED */