summaryrefslogtreecommitdiff
path: root/src/jpeg-utils.h
blob: b73576bfc688b4b785a025f50c7c52e7aba831cc (plain)
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
/*   Cataract - Static web photo gallery generator
 *   Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
 *
 *   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 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#ifndef __CGG__JPEG_UTILS_H__
#define __CGG__JPEG_UTILS_H__

#include <glib.h>
#include "setup.h"
#include "items.h"

G_BEGIN_DECLS


#define CROP_SIMPLE_SHAVE_AMOUNT 0  /* percent */

/*  EXIF data known keys  */
/*  Exiv2 Tag Reference can be found at http://exiv2.org/metadata.html  */
#define EXIF_APERTURE           "Exif.Photo.FNumber"
#define EXIF_CAMERA_MODEL       "Exif.Image.Model"
#define EXIF_DATETIME           "Exif.Photo.DateTimeOriginal"
#define EXIF_EXPOSURE           "Exif.Photo.ExposureTime"
#define EXIF_FLASH              "Exif.Photo.Flash"
#define EXIF_FOCAL_LENGTH       "Exif.Photo.FocalLength"
#define EXIF_ISO                "Exif.Photo.ISOSpeedRatings"
#define EXIF_IMAGE_DESCRIPTION  "Exif.Image.ImageDescription"
#define EXIF_ARTIST             "Exif.Image.Artist"
#define EXIF_COPYRIGHT          "Exif.Image.Copyright"
#define EXIF_COMMENT            "Exif.Photo.UserComment"
#define EXIF_CANON_CAMERA_TEMP  "Exif.CanonSi.CameraTemperature"
#define IPTC_COPYRIGHT          "Iptc.Application2.Copyright"
#define IPTC_CAPTION            "Iptc.Application2.Caption"
#define IPTC_AUTHOR             "Iptc.Application2.Byline"
#define JPEG_COMMENT            "Jpeg.Comment"


typedef struct ExifDataPrivate ExifDataPrivate;

typedef struct {
  ExifDataPrivate *priv;

  gchar *override_copyright;
  int timezone_shift;
  time_t override_datetime;
  double override_aperture;
  double override_focal_length;
  gchar *override_artist_name;
  gchar *external_exif_data;
  const gchar *datetime_format;
  TCropStyle thumbnail_crop_style;
  TCropHint thumbnail_crop_hint;
  int shave_amount;
} ExifData;


/*
 *   Thread-safe ImageMagick and exiv2 libraries initialization and cleanup
 */
void init_jpeg_utils (void);
void destroy_jpeg_utils (void);

/*
 *   EXIF and IPTC info retrieval, keeps the source file open until freed
 */
ExifData * read_exif (const gchar *filename);
ExifData * exif_data_new_empty ();
void exif_data_free (ExifData *data);

/*
 *   Retrieves the value of the specified key or NULL if the key does not exist.
 *   The key argument belongs to Exiv2 namespace - see http://exiv2.org/tags.html
 *
 *   The get_exif_data_fixed() function does some pretty printing for selected keys.
 */
gchar * get_exif_data (ExifData *exif, const gchar *key);
gchar * get_exif_data_fixed (ExifData *exif, const gchar *key);

/*
 *   Returns TRUE if the image contains the key specified
 */
gboolean exif_has_key (ExifData *exif, const gchar *key);


/*
 *   resize_image: resize image pointed by src and save result to dst
 *                 - setting thumbnail flag will remove all profiles and optimize for size
 */
gboolean resize_image (const gchar *src, const gchar *dst,
                       unsigned long size_x, unsigned long size_y,
                       int quality,
                       gboolean thumbnail,
                       gboolean autorotate,
                       gboolean hidpi_strict_dimensions,
                       ExifData *exif,
                       gchar *resize_opts);

/*
 *   get_image_sizes: retrieve image dimensions
 */
void get_image_sizes (const gchar *img,
                      unsigned long *width, unsigned long *height,
                      int *quality,
                      gboolean autorotate);

/*
 *   calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio
 */
void calculate_sizes (const unsigned long max_width, const unsigned long max_height,
                      unsigned long *width, unsigned long *height);

/*
 *   modify_exif: - strip thumbnail stored in EXIF table
 *                - write down overriden keys
 */
void modify_exif (const gchar *filename, ExifData *exif, gboolean strip_thumbnail, gboolean strip_xmp);


G_END_DECLS

#endif /* __CGG__JPEG_UTILS_H__ */