blob: 2eca8b8df41215c3f26e21d0c1cb78adae7078c0 [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
38#define MAX_COMMENT 2000
39
40#ifdef _WIN32
41 #define PATH_MAX _MAX_PATH
42#endif
43
44//--------------------------------------------------------------------------
45// This structure is used to store jpeg file sections in memory.
46typedef struct {
47 uchar * Data;
48 int Type;
49 unsigned Size;
50}Section_t;
51
52extern int ExifSectionIndex;
53
54extern int DumpExifMap;
55
56#define MAX_DATE_COPIES 10
57
58//--------------------------------------------------------------------------
59// This structure stores Exif header image elements in a simple manner
60// Used to store camera data as extracted from the various ways that it can be
61// stored in an exif header
62typedef struct {
63 char FileName [PATH_MAX+1];
64 time_t FileDateTime;
65 unsigned FileSize;
66 char CameraMake [32];
67 char CameraModel [40];
68 char DateTime [20];
69 int Height, Width;
70 int Orientation;
71 int IsColor;
72 int Process;
73 int FlashUsed;
74 float FocalLength;
75 float ExposureTime;
76 float ApertureFNumber;
77 float Distance;
78 float CCDWidth;
79 float ExposureBias;
80 float DigitalZoomRatio;
81 int FocalLength35mmEquiv; // Exif 2.2 tag - usually not present.
82 int Whitebalance;
83 int MeteringMode;
84 int ExposureProgram;
85 int ExposureMode;
86 int ISOequivalent;
87 int LightSource;
88 char Comments[MAX_COMMENT];
89
90 unsigned ThumbnailOffset; // Exif offset to thumbnail
91 unsigned ThumbnailSize; // Size of thumbnail.
92 unsigned LargestExifOffset; // Last exif data referenced (to check if thumbnail is at end)
93
94 char ThumbnailAtEnd; // Exif header ends with the thumbnail
95 // (we can only modify the thumbnail if its at the end)
96 int ThumbnailSizeOffset;
97
98 int DateTimeOffsets[MAX_DATE_COPIES];
99 int numDateTimeTags;
100
101 int GpsInfoPresent;
102 char GpsLat[31];
103 char GpsLatRaw[31];
104 char GpsLatRef[2];
105 char GpsLong[31];
106 char GpsLongRaw[31];
107 char GpsLongRef[2];
108 char GpsAlt[20];
109}ImageInfo_t;
110
111
112
113#define EXIT_FAILURE 1
114#define EXIT_SUCCESS 0
115
116// jpgfile.c functions
117typedef enum {
118 READ_METADATA = 1,
119 READ_IMAGE = 2,
120 READ_ALL = 3
121}ReadMode_t;
122
123
124typedef struct {
125 unsigned short Tag; // tag value, i.e. TAG_MODEL
126 int Format; // format of data
127 char* Value; // value of data in string format
128 int DataLength; // length of string when format says Value is a string
129 int GpsTag; // bool - the tag is related to GPS info
130} ExifElement_t;
131
132
133typedef struct {
134 unsigned short Tag;
135 char * Desc;
136 int Format;
137 int DataLength; // Number of elements in Format. -1 means any length.
138} TagTable_t;
139
140
141// prototypes for jhead.c functions
142void ErrFatal(char * msg);
143void ErrNonfatal(char * msg, int a1, int a2);
144void FileTimeAsString(char * TimeStr);
145
146// Prototypes for exif.c functions.
147int Exif2tm(struct tm * timeptr, char * ExifTime);
148void process_EXIF (unsigned char * CharBuf, unsigned int length);
149int RemoveThumbnail(unsigned char * ExifSection);
150void ShowImageInfo(int ShowFileInfo);
151void ShowConciseImageInfo(void);
152const char * ClearOrientation(void);
153void PrintFormatNumber(void * ValuePtr, int Format, int ByteCount);
154double ConvertAnyFormat(void * ValuePtr, int Format);
155int Get16u(void * Short);
156unsigned Get32u(void * Long);
157int Get32s(void * Long);
158void Put32u(void * Value, unsigned PutValue);
159void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount);
160int TagNameToValue(const char* tagName);
161
162//--------------------------------------------------------------------------
163// Exif format descriptor stuff
164extern const int BytesPerFormat[];
165#define NUM_FORMATS 12
166
167#define FMT_BYTE 1
168#define FMT_STRING 2
169#define FMT_USHORT 3
170#define FMT_ULONG 4
171#define FMT_URATIONAL 5
172#define FMT_SBYTE 6
173#define FMT_UNDEFINED 7
174#define FMT_SSHORT 8
175#define FMT_SLONG 9
176#define FMT_SRATIONAL 10
177#define FMT_SINGLE 11
178#define FMT_DOUBLE 12
179
180
181// makernote.c prototypes
182extern void ProcessMakerNote(unsigned char * DirStart, int ByteCount,
183 unsigned char * OffsetBase, unsigned ExifLength);
184
185// gpsinfo.c prototypes
186void ProcessGpsInfo(unsigned char * ValuePtr, int ByteCount,
187 unsigned char * OffsetBase, unsigned ExifLength);
188int IsGpsTag(const char* tag);
189int GpsTagToFormatType(unsigned short tag);
190int GpsTagNameToValue(const char* tagName);
191TagTable_t* GpsTagToTagTableEntry(unsigned short tag);
192
193// iptc.c prototpyes
194void show_IPTC (unsigned char * CharBuf, unsigned int length);
195
196// Prototypes for myglob.c module
197extern void MyGlob(const char * Pattern , void (*FileFuncParm)(const char * FileName));
198
199// Prototypes from jpgfile.c
200int ReadJpegSections (FILE * infile, ReadMode_t ReadMode);
201void DiscardData(void);
202void DiscardAllButExif(void);
203int ReadJpegFile(const char * FileName, ReadMode_t ReadMode);
204int ReplaceThumbnail(const char * ThumbFileName);
205int SaveThumbnail(char * ThumbFileName);
206int RemoveSectionType(int SectionType);
207int RemoveUnknownSections(void);
208int WriteJpegFile(const char * FileName);
209Section_t * FindSection(int SectionType);
210Section_t * CreateSection(int SectionType, unsigned char * Data, int size);
211void ResetJpgfile(void);
212
213// Variables from jhead.c used by exif.c
214extern ImageInfo_t ImageInfo;
215extern int ShowTags;
216extern char* formatStr(int format);
217
218//--------------------------------------------------------------------------
219// JPEG markers consist of one or more 0xFF bytes, followed by a marker
220// code byte (which is not an FF). Here are the marker codes of interest
221// in this program. (See jdmarker.c for a more complete list.)
222//--------------------------------------------------------------------------
223
224#define M_SOF0 0xC0 // Start Of Frame N
225#define M_SOF1 0xC1 // N indicates which compression process
226#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use
227#define M_SOF3 0xC3
228#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers
229#define M_SOF6 0xC6
230#define M_SOF7 0xC7
231#define M_SOF9 0xC9
232#define M_SOF10 0xCA
233#define M_SOF11 0xCB
234#define M_SOF13 0xCD
235#define M_SOF14 0xCE
236#define M_SOF15 0xCF
237#define M_SOI 0xD8 // Start Of Image (beginning of datastream)
238#define M_EOI 0xD9 // End Of Image (end of datastream)
239#define M_SOS 0xDA // Start Of Scan (begins compressed data)
240#define M_JFIF 0xE0 // Jfif marker
241#define M_EXIF 0xE1 // Exif marker
242#define M_COM 0xFE // COMment
243#define M_DQT 0xDB
244#define M_DHT 0xC4
245#define M_DRI 0xDD
246#define M_IPTC 0xED // IPTC marker
247
248