"Fossies" - the Fresh Open Source Software Archive

Member "jhead-3.04/jhead.h" (22 Nov 2019, 8370 Bytes) of package /linux/privat/jhead-3.04.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "jhead.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.03_vs_3.04.

    1 //--------------------------------------------------------------------------
    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 #include <stdio.h>
   10 #include <stdlib.h>
   11 #include <string.h>
   12 #include <time.h>
   13 #include <errno.h>
   14 #include <ctype.h>
   15 
   16 //--------------------------------------------------------------------------
   17 
   18 #ifdef _WIN32
   19     #include <sys/utime.h>
   20 
   21     // Make the Microsoft Visual c 10 deprecate warnings go away.
   22     // The _CRT_SECURE_NO_DEPRECATE doesn't do the trick like it should.
   23     #define unlink _unlink
   24     #define chmod _chmod
   25     #define access _access
   26     #define mktemp _mktemp
   27     
   28     #if _MSC_VER && _MSC_VER <= 1500
   29         // The 2007 vintage compiler I use on windows doesn't have snprintf
   30         #define snprintf(dest, len, format,...) sprintf (dest, format, __VA_ARGS__)
   31     #endif
   32 #else
   33     #include <utime.h>
   34     #include <sys/types.h>
   35     #include <unistd.h>
   36     #include <errno.h>
   37     #include <limits.h>
   38 #endif
   39 
   40 
   41 typedef unsigned char uchar;
   42 
   43 #ifndef TRUE
   44     #define TRUE 1
   45     #define FALSE 0
   46 #endif
   47 
   48 #define MAX_COMMENT_SIZE 16000
   49 
   50 #ifdef _WIN32
   51     #define PATH_MAX _MAX_PATH
   52     #define SLASH '\\'
   53 #else
   54     #ifndef PATH_MAX
   55         #define PATH_MAX 1024
   56     #endif
   57     #define SLASH '/'
   58 #endif
   59 
   60 
   61 //--------------------------------------------------------------------------
   62 // This structure is used to store jpeg file sections in memory.
   63 typedef struct {
   64     uchar *  Data;
   65     int      Type;
   66     unsigned Size;
   67 }Section_t;
   68 
   69 extern int ExifSectionIndex;
   70 
   71 extern int DumpExifMap;
   72 
   73 #define MAX_DATE_COPIES 10
   74 
   75 //--------------------------------------------------------------------------
   76 // This structure stores Exif header image elements in a simple manner
   77 // Used to store camera data as extracted from the various ways that it can be
   78 // stored in an exif header
   79 typedef struct {
   80     char  FileName     [PATH_MAX+1];
   81     time_t FileDateTime;
   82 
   83     struct {
   84         // Info in the jfif header.
   85         // This info is not used much - jhead used to just replace it with default
   86         // values, and over 10 years, only two people pointed this out.
   87         char  Present;
   88         char  ResolutionUnits;
   89         short XDensity;
   90         short YDensity;
   91     }JfifHeader;
   92 
   93     unsigned FileSize;
   94     char  CameraMake   [32];
   95     char  CameraModel  [40];
   96     char  DateTime     [20];
   97     unsigned Height, Width;
   98     int   Orientation;
   99     int   IsColor;
  100     int   Process;
  101     int   FlashUsed;
  102     float FocalLength;
  103     float ExposureTime;
  104     float ApertureFNumber;
  105     float Distance;
  106     float CCDWidth;
  107     float ExposureBias;
  108     float DigitalZoomRatio;
  109     int   FocalLength35mmEquiv; // Exif 2.2 tag - usually not present.
  110     int   Whitebalance;
  111     int   MeteringMode;
  112     int   ExposureProgram;
  113     int   ExposureMode;
  114     int   ISOequivalent;
  115     int   LightSource;
  116     int   DistanceRange;
  117 
  118     float xResolution;
  119     float yResolution;
  120     int   ResolutionUnit;
  121 
  122     char  Comments[MAX_COMMENT_SIZE];
  123     int   CommentWidthchars; // If nonzero, widechar comment, indicates number of chars.
  124 
  125     int   ThumbnailOffset;          // Exif offset to thumbnail
  126     int   ThumbnailSize;            // Size of thumbnail.
  127     int   LargestExifOffset;        // Last exif data referenced (to check if thumbnail is at end)
  128 
  129     char  ThumbnailAtEnd;              // Exif header ends with the thumbnail
  130                                        // (we can only modify the thumbnail if its at the end)
  131     int   ThumbnailSizeOffset;
  132 
  133     int  DateTimeOffsets[MAX_DATE_COPIES];
  134     int  numDateTimeTags;
  135 
  136     int GpsInfoPresent;
  137     char GpsLat[31];
  138     char GpsLong[31];
  139     char GpsAlt[20];
  140 
  141     int  QualityGuess;
  142 }ImageInfo_t;
  143 
  144 
  145 #ifndef EXIT_FAILURE
  146 #define EXIT_FAILURE  1
  147 #endif
  148 #define EXIT_SUCCESS  0
  149 
  150 // jpgfile.c functions
  151 typedef enum {
  152     READ_METADATA = 1,
  153     READ_IMAGE = 2,
  154     READ_ALL = 3,
  155     READ_ANY = 5        // Don't abort on non-jpeg files.
  156 }ReadMode_t;
  157 
  158 
  159 // prototypes for jhead.c functions
  160 void ErrFatal(const char * msg);
  161 void ErrNonfatal(const char * msg, int a1, int a2);
  162 void FileTimeAsString(char * TimeStr);
  163 
  164 // Prototypes for exif.c functions.
  165 int Exif2tm(struct tm * timeptr, char * ExifTime);
  166 void Clear_EXIF();
  167 void process_EXIF (unsigned char * CharBuf, int length);
  168 void ShowImageInfo(int ShowFileInfo);
  169 void ShowConciseImageInfo(void);
  170 const char * ClearOrientation(void);
  171 void PrintFormatNumber(void * ValuePtr, int Format, int ByteCount);
  172 double ConvertAnyFormat(void * ValuePtr, int Format);
  173 int Get16u(void * Short);
  174 unsigned Get32u(void * Long);
  175 int Get32s(void * Long);
  176 void Put32u(void * Value, unsigned PutValue);
  177 void create_EXIF(void);
  178 
  179 //--------------------------------------------------------------------------
  180 // Exif format descriptor stuff
  181 extern const int BytesPerFormat[];
  182 #define NUM_FORMATS 12
  183 
  184 #define FMT_BYTE       1 
  185 #define FMT_STRING     2
  186 #define FMT_USHORT     3
  187 #define FMT_ULONG      4
  188 #define FMT_URATIONAL  5
  189 #define FMT_SBYTE      6
  190 #define FMT_UNDEFINED  7
  191 #define FMT_SSHORT     8
  192 #define FMT_SLONG      9
  193 #define FMT_SRATIONAL 10
  194 #define FMT_SINGLE    11
  195 #define FMT_DOUBLE    12
  196 
  197 
  198 // makernote.c prototypes
  199 extern void ProcessMakerNote(unsigned char * DirStart, int ByteCount,
  200                  unsigned char * OffsetBase, unsigned ExifLength);
  201 
  202 // gpsinfo.c prototypes
  203 void ProcessGpsInfo(unsigned char * ValuePtr,  
  204                 unsigned char * OffsetBase, unsigned ExifLength);
  205 
  206 // iptc.c prototpyes
  207 void show_IPTC (unsigned char * CharBuf, unsigned int length);
  208 void ShowXmp(Section_t XmpSection);
  209 
  210 // Prototypes for myglob.c module
  211 #ifdef _WIN32
  212 void MyGlob(const char * Pattern , void (*FileFuncParm)(const char * FileName));
  213 void SlashToNative(char * Path);
  214 #endif
  215 
  216 // Prototypes for paths.c module
  217 int EnsurePathExists(const char * FileName);
  218 void CatPath(char * BasePath, const char * FilePath);
  219 
  220 // Prototypes from jpgfile.c
  221 int ReadJpegSections (FILE * infile, ReadMode_t ReadMode);
  222 void DiscardData(void);
  223 void DiscardAllButExif(void);
  224 int ReadJpegFile(const char * FileName, ReadMode_t ReadMode);
  225 int ReplaceThumbnail(const char * ThumbFileName);
  226 int SaveThumbnail(char * ThumbFileName);
  227 int RemoveSectionType(int SectionType);
  228 int RemoveUnknownSections(void);
  229 void WriteJpegFile(const char * FileName);
  230 Section_t * FindSection(int SectionType);
  231 Section_t * CreateSection(int SectionType, unsigned char * Data, int size);
  232 void ResetJpgfile(void);
  233 
  234 // Prototypes from jpgqguess.c
  235 void process_DQT (const uchar * Data, int length);
  236 void process_DHT (const uchar * Data, int length);
  237 
  238 // Variables from jhead.c used by exif.c
  239 extern ImageInfo_t ImageInfo;
  240 extern int ShowTags;
  241 
  242 //--------------------------------------------------------------------------
  243 // JPEG markers consist of one or more 0xFF bytes, followed by a marker
  244 // code byte (which is not an FF).  Here are the marker codes of interest
  245 // in this program.  (See jdmarker.c for a more complete list.)
  246 //--------------------------------------------------------------------------
  247 
  248 #define M_SOF0  0xC0          // Start Of Frame N
  249 #define M_SOF1  0xC1          // N indicates which compression process
  250 #define M_SOF2  0xC2          // Only SOF0-SOF2 are now in common use
  251 #define M_SOF3  0xC3
  252 #define M_SOF5  0xC5          // NB: codes C4 and CC are NOT SOF markers
  253 #define M_SOF6  0xC6
  254 #define M_SOF7  0xC7
  255 #define M_SOF9  0xC9
  256 #define M_SOF10 0xCA
  257 #define M_SOF11 0xCB
  258 #define M_SOF13 0xCD
  259 #define M_SOF14 0xCE
  260 #define M_SOF15 0xCF
  261 #define M_SOI   0xD8          // Start Of Image (beginning of datastream)
  262 #define M_EOI   0xD9          // End Of Image (end of datastream)
  263 #define M_SOS   0xDA          // Start Of Scan (begins compressed data)
  264 #define M_JFIF  0xE0          // Jfif marker
  265 #define M_EXIF  0xE1          // Exif marker.  Also used for XMP data!
  266 #define M_XMP   0x10E1        // Not a real tag (same value in file as Exif!)
  267 #define M_COM   0xFE          // COMment 
  268 #define M_DQT   0xDB          // Define Quantization Table
  269 #define M_DHT   0xC4          // Define Huffmann Table
  270 #define M_DRI   0xDD
  271 #define M_IPTC  0xED          // IPTC marker