blob: 1540d9418d17b09c907283b816e12f5605456d7c [file] [log] [blame]
The Android Open Source Project34a25642009-03-03 19:30:03 -08001//--------------------------------------------------------------------------
2// Include file for jhead program.
3//
4// This include file only defines stuff that goes across modules.
5// I like to keep the definitions for macros and structures as close to
6// where they get used as possible, so include files only get stuff that
7// gets used in more than one file.
8//--------------------------------------------------------------------------
9#define _CRT_SECURE_NO_DEPRECATE 1
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <time.h>
15#include <errno.h>
16#include <ctype.h>
17
18//--------------------------------------------------------------------------
19
20#ifdef _WIN32
21 #include <sys/utime.h>
22#else
23 #include <utime.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <limits.h>
28#endif
29
30
31typedef unsigned char uchar;
32
33#ifndef TRUE
34 #define TRUE 1
35 #define FALSE 0
36#endif
37
Chih-Chung Changd6a02c32009-03-24 20:34:28 -070038#define MAX_COMMENT_SIZE 2000
The Android Open Source Project34a25642009-03-03 19:30:03 -080039
40#ifdef _WIN32
41 #define PATH_MAX _MAX_PATH
Chih-Chung Changd6a02c32009-03-24 20:34:28 -070042 #define SLASH '\\'
43#else
44 #define SLASH '/'
The Android Open Source Project34a25642009-03-03 19:30:03 -080045#endif
46
Chih-Chung Changd6a02c32009-03-24 20:34:28 -070047
The Android Open Source Project34a25642009-03-03 19:30:03 -080048//--------------------------------------------------------------------------
49// This structure is used to store jpeg file sections in memory.
50typedef struct {
51 uchar * Data;
52 int Type;
53 unsigned Size;
54}Section_t;
55
56extern int ExifSectionIndex;
57
58extern int DumpExifMap;
59
60#define MAX_DATE_COPIES 10
61
62//--------------------------------------------------------------------------
63// This structure stores Exif header image elements in a simple manner
64// Used to store camera data as extracted from the various ways that it can be
65// stored in an exif header
66typedef struct {
67 char FileName [PATH_MAX+1];
68 time_t FileDateTime;
69 unsigned FileSize;
70 char CameraMake [32];
71 char CameraModel [40];
72 char DateTime [20];
73 int Height, Width;
74 int Orientation;
75 int IsColor;
76 int Process;
77 int FlashUsed;
78 float FocalLength;
79 float ExposureTime;
80 float ApertureFNumber;
81 float Distance;
82 float CCDWidth;
83 float ExposureBias;
84 float DigitalZoomRatio;
85 int FocalLength35mmEquiv; // Exif 2.2 tag - usually not present.
86 int Whitebalance;
87 int MeteringMode;
88 int ExposureProgram;
89 int ExposureMode;
90 int ISOequivalent;
91 int LightSource;
Chih-Chung Changd6a02c32009-03-24 20:34:28 -070092 int DistanceRange;
93
94 char Comments[MAX_COMMENT_SIZE];
95 int CommentWidchars; // If nonzer, widechar comment, indicates number of chars.
The Android Open Source Project34a25642009-03-03 19:30:03 -080096
97 unsigned ThumbnailOffset; // Exif offset to thumbnail
98 unsigned ThumbnailSize; // Size of thumbnail.
99 unsigned LargestExifOffset; // Last exif data referenced (to check if thumbnail is at end)
100
101 char ThumbnailAtEnd; // Exif header ends with the thumbnail
102 // (we can only modify the thumbnail if its at the end)
103 int ThumbnailSizeOffset;
104
105 int DateTimeOffsets[MAX_DATE_COPIES];
106 int numDateTimeTags;
107
108 int GpsInfoPresent;
109 char GpsLat[31];
110 char GpsLatRaw[31];
111 char GpsLatRef[2];
112 char GpsLong[31];
113 char GpsLongRaw[31];
114 char GpsLongRef[2];
115 char GpsAlt[20];
116}ImageInfo_t;
117
118
119
120#define EXIT_FAILURE 1
121#define EXIT_SUCCESS 0
122
123// jpgfile.c functions
124typedef enum {
125 READ_METADATA = 1,
126 READ_IMAGE = 2,
127 READ_ALL = 3
128}ReadMode_t;
129
130
131typedef struct {
132 unsigned short Tag; // tag value, i.e. TAG_MODEL
133 int Format; // format of data
134 char* Value; // value of data in string format
135 int DataLength; // length of string when format says Value is a string
136 int GpsTag; // bool - the tag is related to GPS info
137} ExifElement_t;
138
139
140typedef struct {
141 unsigned short Tag;
142 char * Desc;
143 int Format;
144 int DataLength; // Number of elements in Format. -1 means any length.
145} TagTable_t;
146
147
148// prototypes for jhead.c functions
149void ErrFatal(char * msg);
150void ErrNonfatal(char * msg, int a1, int a2);
151void FileTimeAsString(char * TimeStr);
152
153// Prototypes for exif.c functions.
154int Exif2tm(struct tm * timeptr, char * ExifTime);
155void process_EXIF (unsigned char * CharBuf, unsigned int length);
156int RemoveThumbnail(unsigned char * ExifSection);
157void ShowImageInfo(int ShowFileInfo);
158void ShowConciseImageInfo(void);
159const char * ClearOrientation(void);
160void PrintFormatNumber(void * ValuePtr, int Format, int ByteCount);
161double ConvertAnyFormat(void * ValuePtr, int Format);
162int Get16u(void * Short);
163unsigned Get32u(void * Long);
164int Get32s(void * Long);
165void Put32u(void * Value, unsigned PutValue);
166void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount);
167int TagNameToValue(const char* tagName);
168
169//--------------------------------------------------------------------------
170// Exif format descriptor stuff
171extern const int BytesPerFormat[];
172#define NUM_FORMATS 12
173
174#define FMT_BYTE 1
175#define FMT_STRING 2
176#define FMT_USHORT 3
177#define FMT_ULONG 4
178#define FMT_URATIONAL 5
179#define FMT_SBYTE 6
180#define FMT_UNDEFINED 7
181#define FMT_SSHORT 8
182#define FMT_SLONG 9
183#define FMT_SRATIONAL 10
184#define FMT_SINGLE 11
185#define FMT_DOUBLE 12
186
187
188// makernote.c prototypes
189extern void ProcessMakerNote(unsigned char * DirStart, int ByteCount,
190 unsigned char * OffsetBase, unsigned ExifLength);
191
192// gpsinfo.c prototypes
193void ProcessGpsInfo(unsigned char * ValuePtr, int ByteCount,
194 unsigned char * OffsetBase, unsigned ExifLength);
195int IsGpsTag(const char* tag);
196int GpsTagToFormatType(unsigned short tag);
197int GpsTagNameToValue(const char* tagName);
198TagTable_t* GpsTagToTagTableEntry(unsigned short tag);
199
200// iptc.c prototpyes
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700201void show_IPTC (unsigned char * CharBuf, unsigned int length);
202void ShowXmp(Section_t XmpSection);
The Android Open Source Project34a25642009-03-03 19:30:03 -0800203
204// Prototypes for myglob.c module
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700205#ifdef _WIN32
206void MyGlob(const char * Pattern , void (*FileFuncParm)(const char * FileName));
207void SlashToNative(char * Path);
208#endif
209
210// Prototypes for paths.c module
211int EnsurePathExists(const char * FileName);
212void CatPath(char * BasePath, const char * FilePath);
The Android Open Source Project34a25642009-03-03 19:30:03 -0800213
214// Prototypes from jpgfile.c
215int ReadJpegSections (FILE * infile, ReadMode_t ReadMode);
216void DiscardData(void);
217void DiscardAllButExif(void);
218int ReadJpegFile(const char * FileName, ReadMode_t ReadMode);
219int ReplaceThumbnail(const char * ThumbFileName);
220int SaveThumbnail(char * ThumbFileName);
221int RemoveSectionType(int SectionType);
222int RemoveUnknownSections(void);
223int WriteJpegFile(const char * FileName);
224Section_t * FindSection(int SectionType);
225Section_t * CreateSection(int SectionType, unsigned char * Data, int size);
226void ResetJpgfile(void);
227
228// Variables from jhead.c used by exif.c
229extern ImageInfo_t ImageInfo;
230extern int ShowTags;
231extern char* formatStr(int format);
232
233//--------------------------------------------------------------------------
234// JPEG markers consist of one or more 0xFF bytes, followed by a marker
235// code byte (which is not an FF). Here are the marker codes of interest
236// in this program. (See jdmarker.c for a more complete list.)
237//--------------------------------------------------------------------------
238
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700239#define M_SOF0 0xC0 // Start Of Frame N
240#define M_SOF1 0xC1 // N indicates which compression process
241#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use
The Android Open Source Project34a25642009-03-03 19:30:03 -0800242#define M_SOF3 0xC3
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700243#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers
The Android Open Source Project34a25642009-03-03 19:30:03 -0800244#define M_SOF6 0xC6
245#define M_SOF7 0xC7
246#define M_SOF9 0xC9
247#define M_SOF10 0xCA
248#define M_SOF11 0xCB
249#define M_SOF13 0xCD
250#define M_SOF14 0xCE
251#define M_SOF15 0xCF
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700252#define M_SOI 0xD8 // Start Of Image (beginning of datastream)
253#define M_EOI 0xD9 // End Of Image (end of datastream)
254#define M_SOS 0xDA // Start Of Scan (begins compressed data)
255#define M_JFIF 0xE0 // Jfif marker
256#define M_EXIF 0xE1 // Exif marker. Also used for XMP data!
257#define M_XMP 0x10E1 // Not a real tag (same value in file as Exif!)
258#define M_COM 0xFE // COMment
The Android Open Source Project34a25642009-03-03 19:30:03 -0800259#define M_DQT 0xDB
260#define M_DHT 0xC4
261#define M_DRI 0xDD
Chih-Chung Changd6a02c32009-03-24 20:34:28 -0700262#define M_IPTC 0xED // IPTC marker
The Android Open Source Project34a25642009-03-03 19:30:03 -0800263
264