exif 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/exif/data.c +240 -90
- data/ext/exif/exif.c +4 -3
- data/ext/exif/exif_entry_to_ivar.c +4 -3
- data/lib/exif/version.rb +1 -1
- metadata +2 -6
- data/ext/exif/libjpeg/jpeg-data.c +0 -490
- data/ext/exif/libjpeg/jpeg-data.h +0 -92
- data/ext/exif/libjpeg/jpeg-marker.c +0 -122
- data/ext/exif/libjpeg/jpeg-marker.h +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33f58a4ce4cca70c469d9d6df0ec65a5ba2709ac
|
4
|
+
data.tar.gz: 4cb22e01351311cc90cca4280e72030d4cefbddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82bb019a423559815f06793736aef8fc6bea78f8cdff7e602ef555087f66cf436d240f5842caad8951e5a9b43eaba16bb2be8bcfd2b53fbb8337e77bbf9d0b77
|
7
|
+
data.tar.gz: 826aa853744d59ec237eeca0c4fc7c57f60f596abf236110d82e4a6aabb6838dbc86e65913a3772d7e5a1121b049ddf5c2bba030aa3863c158ec42c42977769c
|
data/ext/exif/data.c
CHANGED
@@ -1,40 +1,191 @@
|
|
1
1
|
#include "data.h"
|
2
|
-
#include "libjpeg/jpeg-data.h"
|
3
2
|
#include "ruby.h"
|
4
3
|
|
5
4
|
#include <libexif/exif-data.h>
|
6
5
|
#include <libexif/exif-loader.h>
|
7
|
-
#include <time.h>
|
8
6
|
#include <stdint.h>
|
7
|
+
#include <time.h>
|
9
8
|
|
10
9
|
extern VALUE rb_mExif, rb_eNotReadble, rb_eIFDNotFound;
|
11
|
-
extern const char*
|
10
|
+
extern const char *exif_entry_to_ivar(ExifEntry *entry);
|
12
11
|
|
13
12
|
VALUE rb_cExifData;
|
14
|
-
static const char*
|
15
|
-
|
13
|
+
static const char *ifd_name_mapping[] = {"ifd0", "ifd1", "exif", "gps",
|
14
|
+
"interoperability"};
|
15
|
+
static const char *attr_readers[] = {"ifds",
|
16
|
+
"aperture_value",
|
17
|
+
"artist",
|
18
|
+
"battery_level",
|
19
|
+
"bits_per_sample",
|
20
|
+
"brightness_value",
|
21
|
+
"cfa_pattern",
|
22
|
+
"cfa_repeat_pattern_dim",
|
23
|
+
"color_space",
|
24
|
+
"components_configuration",
|
25
|
+
"compressed_bits_per_pixel",
|
26
|
+
"compression",
|
27
|
+
"contrast",
|
28
|
+
"copyright",
|
29
|
+
"custom_rendered",
|
30
|
+
"date_time",
|
31
|
+
"date_time_digitized",
|
32
|
+
"date_time_original",
|
33
|
+
"device_setting_description",
|
34
|
+
"digital_zoom_ratio",
|
35
|
+
"document_name",
|
36
|
+
"exif_ifd_pointer",
|
37
|
+
"exif_version",
|
38
|
+
"exposure_bias_value",
|
39
|
+
"exposure_index",
|
40
|
+
"exposure_mode",
|
41
|
+
"exposure_program",
|
42
|
+
"exposure_time",
|
43
|
+
"file_source",
|
44
|
+
"fill_order",
|
45
|
+
"flash",
|
46
|
+
"flash_energy",
|
47
|
+
"flash_pix_version",
|
48
|
+
"fnumber",
|
49
|
+
"focal_length",
|
50
|
+
"focal_length_in_35mm_film",
|
51
|
+
"focal_plane_resolution_unit",
|
52
|
+
"focal_plane_x_resolution",
|
53
|
+
"focal_plane_y_resolution",
|
54
|
+
"gain_control",
|
55
|
+
"gamma",
|
56
|
+
"gps_altitude",
|
57
|
+
"gps_altitude_ref",
|
58
|
+
"gps_area_information",
|
59
|
+
"gps_date_stamp",
|
60
|
+
"gps_dest_bearing",
|
61
|
+
"gps_dest_bearing_ref",
|
62
|
+
"gps_dest_distance",
|
63
|
+
"gps_dest_distance_ref",
|
64
|
+
"gps_dest_latitude",
|
65
|
+
"gps_dest_latitude_ref",
|
66
|
+
"gps_dest_longitude",
|
67
|
+
"gps_dest_longitude_ref",
|
68
|
+
"gps_differential",
|
69
|
+
"gps_dop",
|
70
|
+
"gps_img_direction",
|
71
|
+
"gps_img_direction_ref",
|
72
|
+
"gps_info_ifd_pointer",
|
73
|
+
"gps_latitude",
|
74
|
+
"gps_latitude_ref",
|
75
|
+
"gps_longitude",
|
76
|
+
"gps_longitude_ref",
|
77
|
+
"gps_map_datum",
|
78
|
+
"gps_measure_mode",
|
79
|
+
"gps_processing_method",
|
80
|
+
"gps_satellites",
|
81
|
+
"gps_speed",
|
82
|
+
"gps_speed_ref",
|
83
|
+
"gps_status",
|
84
|
+
"gps_time_stamp",
|
85
|
+
"gps_track",
|
86
|
+
"gps_track_ref",
|
87
|
+
"gps_version_id",
|
88
|
+
"image_description",
|
89
|
+
"image_length",
|
90
|
+
"image_resources",
|
91
|
+
"image_unique_id",
|
92
|
+
"image_width",
|
93
|
+
"inter_color_profile",
|
94
|
+
"interoperability_ifd_pointer",
|
95
|
+
"interoperability_index",
|
96
|
+
"interoperability_version",
|
97
|
+
"iptc_naa",
|
98
|
+
"iso_speed_ratings",
|
99
|
+
"jpeg_interchange_format",
|
100
|
+
"jpeg_interchange_format_length",
|
101
|
+
"jpeg_proc",
|
102
|
+
"light_source",
|
103
|
+
"make",
|
104
|
+
"maker_note",
|
105
|
+
"max_aperture_value",
|
106
|
+
"metering_mode",
|
107
|
+
"model",
|
108
|
+
"new_cfa_pattern",
|
109
|
+
"new_subfile_type",
|
110
|
+
"oecf",
|
111
|
+
"orientation",
|
112
|
+
"padding",
|
113
|
+
"photometric_interpretation",
|
114
|
+
"pixel_x_dimension",
|
115
|
+
"pixel_y_dimension",
|
116
|
+
"planar_configuration",
|
117
|
+
"primary_chromaticities",
|
118
|
+
"print_image_matching",
|
119
|
+
"reference_black_white",
|
120
|
+
"related_image_file_format",
|
121
|
+
"related_image_length",
|
122
|
+
"related_image_width",
|
123
|
+
"related_sound_file",
|
124
|
+
"resolution_unit",
|
125
|
+
"rows_per_strip",
|
126
|
+
"samples_per_pixel",
|
127
|
+
"saturation",
|
128
|
+
"scene_capture_type",
|
129
|
+
"scene_type",
|
130
|
+
"sensing_method",
|
131
|
+
"sharpness",
|
132
|
+
"shutter_speed_value",
|
133
|
+
"software",
|
134
|
+
"spatial_frequency_response",
|
135
|
+
"spectral_sensitivity",
|
136
|
+
"strip_byte_counts",
|
137
|
+
"strip_offsets",
|
138
|
+
"sub_ifds",
|
139
|
+
"sub_sec_time",
|
140
|
+
"sub_sec_time_digitized",
|
141
|
+
"sub_sec_time_original",
|
142
|
+
"subject_area",
|
143
|
+
"subject_distance",
|
144
|
+
"subject_distance_range",
|
145
|
+
"subject_location",
|
146
|
+
"tiff_ep_standard_id",
|
147
|
+
"time_zone_offset",
|
148
|
+
"transfer_function",
|
149
|
+
"transfer_range",
|
150
|
+
"user_comment",
|
151
|
+
"white_balance",
|
152
|
+
"white_point",
|
153
|
+
"x_resolution",
|
154
|
+
"xml_packet",
|
155
|
+
"xp_author",
|
156
|
+
"xp_comment",
|
157
|
+
"xp_keywords",
|
158
|
+
"xp_subject",
|
159
|
+
"xp_title",
|
160
|
+
"y_resolution",
|
161
|
+
"ycbcr_coefficients",
|
162
|
+
"ycbcr_positioning",
|
163
|
+
"ycbcr_sub_sampling"};
|
16
164
|
|
17
|
-
static VALUE new(VALUE self, VALUE input);
|
165
|
+
static VALUE new (VALUE self, VALUE input);
|
18
166
|
static VALUE dump(VALUE self);
|
19
167
|
static VALUE brackets(VALUE self, VALUE ifd_symbol);
|
20
168
|
static void each_content(ExifContent *ec, void *user_data);
|
21
169
|
static void each_entry(ExifEntry *, void *user_data);
|
22
170
|
static VALUE exif_entry_to_rb_value(ExifEntry *);
|
171
|
+
static VALUE rational_to_num(ExifRational rational);
|
172
|
+
static VALUE srational_to_num(ExifSRational srational);
|
23
173
|
|
24
|
-
void init_data(){
|
174
|
+
void init_data() {
|
25
175
|
int length;
|
26
176
|
|
27
177
|
rb_cExifData = rb_define_class_under(rb_mExif, "Data", rb_cObject);
|
28
|
-
length = sizeof(attr_readers) / sizeof(char*);
|
29
|
-
for(int i = 0; i < length; ++i)
|
178
|
+
length = sizeof(attr_readers) / sizeof(char *);
|
179
|
+
for (int i = 0; i < length; ++i)
|
180
|
+
rb_define_attr(rb_cExifData, attr_readers[i], 1, 0);
|
30
181
|
rb_define_alias(rb_cExifData, "to_h", "ifds");
|
31
182
|
rb_define_singleton_method(rb_cExifData, "new", new, 1);
|
32
183
|
rb_define_method(rb_cExifData, "dump", dump, 0);
|
33
184
|
rb_define_method(rb_cExifData, "[]", brackets, 1);
|
34
185
|
}
|
35
186
|
|
36
|
-
VALUE new(VALUE self, VALUE input){
|
37
|
-
ExifData*
|
187
|
+
VALUE new (VALUE self, VALUE input) {
|
188
|
+
ExifData *ed;
|
38
189
|
VALUE read_data;
|
39
190
|
|
40
191
|
switch (TYPE(input)) {
|
@@ -45,15 +196,17 @@ VALUE new(VALUE self, VALUE input){
|
|
45
196
|
read_data = rb_funcall(input, rb_intern("read"), 0);
|
46
197
|
break;
|
47
198
|
default:
|
48
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or IO)",
|
199
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected String or IO)",
|
200
|
+
rb_obj_classname(input));
|
49
201
|
}
|
50
202
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
203
|
+
ExifLoader *loader = exif_loader_new();
|
204
|
+
exif_loader_write(loader, (unsigned char *)RSTRING_PTR(read_data),
|
205
|
+
RSTRING_LEN(read_data));
|
206
|
+
ed = exif_loader_get_data(loader);
|
207
|
+
exif_loader_unref(loader);
|
208
|
+
if (!ed)
|
209
|
+
rb_raise(rb_eNotReadble, "File not readable or no EXIF data in file.");
|
57
210
|
|
58
211
|
VALUE rb_data = Data_Wrap_Struct(self, NULL, exif_data_free, ed);
|
59
212
|
rb_iv_set(rb_data, "@ifds", rb_hash_new());
|
@@ -61,138 +214,135 @@ VALUE new(VALUE self, VALUE input){
|
|
61
214
|
return rb_data;
|
62
215
|
}
|
63
216
|
|
64
|
-
static VALUE dump(VALUE self){
|
217
|
+
static VALUE dump(VALUE self) {
|
65
218
|
ExifData *ed;
|
66
219
|
Data_Get_Struct(self, ExifData, ed);
|
67
220
|
exif_data_dump(ed);
|
68
221
|
return Qnil;
|
69
222
|
}
|
70
223
|
|
71
|
-
static VALUE brackets(VALUE self, VALUE ifd_symbol){
|
224
|
+
static VALUE brackets(VALUE self, VALUE ifd_symbol) {
|
72
225
|
return rb_hash_aref(rb_iv_get(self, "@ifds"), ifd_symbol);
|
73
226
|
}
|
74
227
|
|
75
|
-
static void each_content(ExifContent *ec, void *self_ptr){
|
228
|
+
static void each_content(ExifContent *ec, void *self_ptr) {
|
76
229
|
VALUE *self;
|
77
230
|
ExifIfd ifd;
|
78
231
|
|
79
232
|
ifd = exif_content_get_ifd(ec);
|
80
|
-
if(ifd == EXIF_IFD_COUNT)
|
81
|
-
|
233
|
+
if (ifd == EXIF_IFD_COUNT)
|
234
|
+
rb_raise(rb_eIFDNotFound, "Con't get IFD.");
|
235
|
+
rb_hash_aset(rb_iv_get(*(VALUE *)self_ptr, "@ifds"),
|
236
|
+
ID2SYM(rb_intern(ifd_name_mapping[ifd])), rb_hash_new());
|
82
237
|
exif_content_foreach_entry(ec, each_entry, self_ptr);
|
83
238
|
}
|
84
239
|
|
85
|
-
static void each_entry(ExifEntry *entry, void *self_ptr){
|
240
|
+
static void each_entry(ExifEntry *entry, void *self_ptr) {
|
86
241
|
VALUE value;
|
87
242
|
const char *ivar_name;
|
88
243
|
|
89
244
|
ivar_name = exif_entry_to_ivar(entry);
|
90
245
|
value = exif_entry_to_rb_value(entry);
|
91
|
-
rb_hash_aset(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
value
|
98
|
-
);
|
99
|
-
if(TYPE(rb_ivar_defined(*(VALUE*)self_ptr, rb_intern(ivar_name))) == T_FALSE){
|
100
|
-
rb_iv_set(*(VALUE*)self_ptr, ivar_name, value);
|
246
|
+
rb_hash_aset(rb_hash_aref(rb_iv_get(*(VALUE *)self_ptr, "@ifds"),
|
247
|
+
ID2SYM(rb_intern(
|
248
|
+
ifd_name_mapping[exif_entry_get_ifd(entry)]))),
|
249
|
+
ID2SYM(rb_intern(ivar_name + 1)), value);
|
250
|
+
if (TYPE(rb_ivar_defined(*(VALUE *)self_ptr, rb_intern(ivar_name))) ==
|
251
|
+
T_FALSE) {
|
252
|
+
rb_iv_set(*(VALUE *)self_ptr, ivar_name, value);
|
101
253
|
}
|
102
254
|
}
|
103
255
|
|
104
|
-
|
105
|
-
|
256
|
+
#define TYPECAST(value1, value2) \
|
257
|
+
do { \
|
258
|
+
if (entry->components > 1) { \
|
259
|
+
ret = rb_ary_new2(entry->components); \
|
260
|
+
for (i = 0; i < entry->components; i++) \
|
261
|
+
rb_ary_push(ret, value1); \
|
262
|
+
} else \
|
263
|
+
ret = value2; \
|
264
|
+
} while (0)
|
265
|
+
|
266
|
+
#define TYPECAST_BYTE(c_to_rb, type) \
|
267
|
+
TYPECAST(c_to_rb((type)entry->data[i]), c_to_rb((type)entry->data[0]))
|
268
|
+
|
269
|
+
#define TYPECAST_EXIF(c_to_rb, exif_get) \
|
270
|
+
TYPECAST(c_to_rb(exif_get_##exif_get(entry->data + i * size, order)), \
|
271
|
+
c_to_rb(exif_get_##exif_get(entry->data, order)))
|
272
|
+
|
273
|
+
static VALUE exif_entry_to_rb_value(ExifEntry *entry) {
|
274
|
+
ExifData *data;
|
106
275
|
ExifByteOrder order;
|
107
276
|
ExifRational rational;
|
108
277
|
ExifSRational srational;
|
109
278
|
VALUE ret;
|
110
279
|
size_t len, i;
|
111
280
|
unsigned char size;
|
112
|
-
struct tm tm = {};
|
113
281
|
|
114
282
|
data = entry->parent->parent;
|
115
283
|
order = exif_data_get_byte_order(data);
|
116
284
|
ret = Qnil;
|
117
285
|
size = exif_format_get_size(entry->format);
|
118
286
|
|
119
|
-
switch(entry->format){
|
287
|
+
switch (entry->format) {
|
120
288
|
case EXIF_FORMAT_UNDEFINED:
|
121
|
-
ret = rb_str_new((const char*)entry->data, entry->size);
|
289
|
+
ret = rb_str_new((const char *)entry->data, entry->size);
|
122
290
|
break;
|
123
291
|
case EXIF_FORMAT_BYTE:
|
124
|
-
|
125
|
-
ret = rb_ary_new2(entry->components);
|
126
|
-
for (i = 0; i < entry->components; i++)
|
127
|
-
rb_ary_push(ret, INT2FIX((uint8_t)entry->data[i]));
|
128
|
-
}else ret = INT2FIX((uint8_t)entry->data[0]);
|
292
|
+
TYPECAST_BYTE(INT2FIX, uint8_t);
|
129
293
|
case EXIF_FORMAT_SBYTE:
|
130
|
-
|
131
|
-
ret = rb_ary_new2(entry->components);
|
132
|
-
for (i = 0; i < entry->components; i++)
|
133
|
-
rb_ary_push(ret, INT2FIX((int8_t)entry->data[i]));
|
134
|
-
}else ret = INT2FIX((int8_t)entry->data[0]);
|
294
|
+
TYPECAST_BYTE(INT2FIX, int8_t);
|
135
295
|
break;
|
136
296
|
case EXIF_FORMAT_SHORT:
|
137
|
-
|
138
|
-
ret = rb_ary_new2(entry->components);
|
139
|
-
for(i = 0; i < entry->components; i++)
|
140
|
-
rb_ary_push(ret, INT2FIX(exif_get_short(entry->data + i*size, order)));
|
141
|
-
}else ret = INT2FIX(exif_get_short(entry->data, order));
|
297
|
+
TYPECAST_EXIF(INT2FIX, short);
|
142
298
|
break;
|
143
299
|
case EXIF_FORMAT_SSHORT:
|
144
|
-
|
145
|
-
ret = rb_ary_new2(entry->components);
|
146
|
-
for(i = 0; i < entry->components; i++)
|
147
|
-
rb_ary_push(ret, INT2FIX(exif_get_sshort(entry->data + i*size, order)));
|
148
|
-
}else ret = INT2FIX(exif_get_sshort(entry->data, order));
|
300
|
+
TYPECAST_EXIF(INT2FIX, sshort);
|
149
301
|
break;
|
150
302
|
case EXIF_FORMAT_LONG:
|
151
|
-
|
152
|
-
ret = rb_ary_new2(entry->components);
|
153
|
-
for(i = 0; i < entry->components; i++)
|
154
|
-
rb_ary_push(ret, ULONG2NUM(exif_get_long(entry->data + i*size, order)));
|
155
|
-
}else ret = ULONG2NUM(exif_get_long(entry->data, order));
|
303
|
+
TYPECAST_EXIF(ULONG2NUM, long);
|
156
304
|
break;
|
157
305
|
case EXIF_FORMAT_SLONG:
|
158
|
-
|
159
|
-
ret = rb_ary_new2(entry->components);
|
160
|
-
for(i = 0; i < entry->components; i++)
|
161
|
-
rb_ary_push(ret, LONG2NUM(exif_get_slong(entry->data + i*size, order)));
|
162
|
-
}else ret = LONG2NUM(exif_get_slong(entry->data, order));
|
306
|
+
TYPECAST_EXIF(LONG2NUM, slong);
|
163
307
|
break;
|
164
308
|
case EXIF_FORMAT_ASCII:
|
165
309
|
ret = rb_str_new2((const char *)entry->data);
|
166
310
|
break;
|
167
311
|
case EXIF_FORMAT_RATIONAL:
|
168
|
-
|
169
|
-
ret = rb_ary_new2(entry->components);
|
170
|
-
for(i = 0; i < entry->components; i++){
|
171
|
-
rational = exif_get_rational(entry->data + i * size, order);
|
172
|
-
rb_ary_push(ret, rb_rational_new(ULONG2NUM(rational.numerator), ULONG2NUM(rational.denominator)));
|
173
|
-
}
|
174
|
-
} else {
|
175
|
-
rational = exif_get_rational(entry->data, order);
|
176
|
-
ret = rb_rational_new(ULONG2NUM(rational.numerator), ULONG2NUM(rational.denominator));
|
177
|
-
}
|
312
|
+
TYPECAST_EXIF(rational_to_num, rational);
|
178
313
|
break;
|
179
314
|
case EXIF_FORMAT_SRATIONAL:
|
180
|
-
|
181
|
-
ret = rb_ary_new2(entry->components);
|
182
|
-
for(int i = 0; i < entry->components; i++){
|
183
|
-
srational = exif_get_srational(entry->data + i * size, order);
|
184
|
-
rb_ary_push(ret, rb_rational_new(LONG2FIX(srational.numerator), LONG2FIX(srational.denominator)));
|
185
|
-
}
|
186
|
-
} else {
|
187
|
-
srational = exif_get_srational(entry->data, order);
|
188
|
-
ret = rb_rational_new(LONG2FIX(srational.numerator), LONG2FIX(srational.denominator));
|
189
|
-
}
|
315
|
+
TYPECAST_EXIF(srational_to_num, srational);
|
190
316
|
break;
|
191
317
|
case EXIF_FORMAT_DOUBLE:
|
192
318
|
case EXIF_FORMAT_FLOAT:
|
193
|
-
ret = rb_float_new(*(double*)entry->data);
|
319
|
+
ret = rb_float_new(*(double *)entry->data);
|
194
320
|
break;
|
195
321
|
}
|
196
322
|
|
197
323
|
return ret;
|
198
324
|
}
|
325
|
+
|
326
|
+
#undef TYPECAST
|
327
|
+
#undef TYPECAST_BYTE
|
328
|
+
#undef TYPECAST_EXIF
|
329
|
+
|
330
|
+
VALUE rational_to_num(ExifRational rational) {
|
331
|
+
if (rational.numerator == 0 && rational.denominator == 0)
|
332
|
+
return DBL2NUM(NAN);
|
333
|
+
else if (rational.denominator == 0)
|
334
|
+
return DBL2NUM(INFINITY);
|
335
|
+
else
|
336
|
+
return rb_rational_new(ULONG2NUM(rational.numerator),
|
337
|
+
ULONG2NUM(rational.denominator));
|
338
|
+
}
|
339
|
+
|
340
|
+
VALUE srational_to_num(ExifSRational srational) {
|
341
|
+
if (srational.numerator == 0 && srational.denominator == 0)
|
342
|
+
return DBL2NUM(NAN);
|
343
|
+
else if (srational.denominator == 0)
|
344
|
+
return DBL2NUM(srational.numerator > 0 ? INFINITY : -INFINITY);
|
345
|
+
else
|
346
|
+
return rb_rational_new(LONG2NUM(srational.numerator),
|
347
|
+
LONG2NUM(srational.denominator));
|
348
|
+
}
|
data/ext/exif/exif.c
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
#include "ruby.h"
|
2
1
|
#include "data.h"
|
2
|
+
#include "ruby.h"
|
3
3
|
|
4
4
|
VALUE rb_mExif, rb_eError, rb_eNotReadble, rb_eIFDNotFound, rb_eUnknownDataType;
|
5
5
|
|
6
|
-
void Init_exif(void){
|
6
|
+
void Init_exif(void) {
|
7
7
|
rb_mExif = rb_define_module("Exif");
|
8
8
|
|
9
9
|
rb_eError = rb_define_class_under(rb_mExif, "Error", rb_eStandardError);
|
10
10
|
rb_eNotReadble = rb_define_class_under(rb_mExif, "NotReadble", rb_eError);
|
11
11
|
rb_eIFDNotFound = rb_define_class_under(rb_mExif, "IFDNotFound", rb_eError);
|
12
|
-
rb_eUnknownDataType =
|
12
|
+
rb_eUnknownDataType =
|
13
|
+
rb_define_class_under(rb_mExif, "UnknownDataType", rb_eError);
|
13
14
|
|
14
15
|
init_data();
|
15
16
|
}
|
@@ -1,15 +1,16 @@
|
|
1
1
|
#include <libexif/exif-entry.h>
|
2
2
|
|
3
|
-
const char*
|
3
|
+
const char *exif_entry_to_ivar(ExifEntry *ee) {
|
4
4
|
ExifIfd ifd;
|
5
5
|
ExifTag tag;
|
6
6
|
|
7
7
|
ifd = exif_entry_get_ifd(ee);
|
8
8
|
tag = ee->tag;
|
9
9
|
|
10
|
-
switch((int)tag){
|
10
|
+
switch ((int)tag) {
|
11
11
|
case EXIF_TAG_INTEROPERABILITY_INDEX: /* EXIF_TAG_GPS_LATITUDE_REF */
|
12
|
-
return ifd == EXIF_IFD_GPS ? "@gps_latitude_ref"
|
12
|
+
return ifd == EXIF_IFD_GPS ? "@gps_latitude_ref"
|
13
|
+
: "@interoperability_index";
|
13
14
|
break;
|
14
15
|
case EXIF_TAG_INTEROPERABILITY_VERSION: /* EXIF_TAG_GPS_LATITUDE */
|
15
16
|
return ifd == EXIF_IFD_GPS ? "@gps_latitude" : "@interoperability_version";
|
data/lib/exif/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jian Weihang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,10 +78,6 @@ files:
|
|
78
78
|
- ext/exif/exif.c
|
79
79
|
- ext/exif/exif_entry_to_ivar.c
|
80
80
|
- ext/exif/extconf.rb
|
81
|
-
- ext/exif/libjpeg/jpeg-data.c
|
82
|
-
- ext/exif/libjpeg/jpeg-data.h
|
83
|
-
- ext/exif/libjpeg/jpeg-marker.c
|
84
|
-
- ext/exif/libjpeg/jpeg-marker.h
|
85
81
|
- lib/exif.rb
|
86
82
|
- lib/exif/version.rb
|
87
83
|
homepage: https://github.com/tonytonyjan/exif
|
@@ -1,490 +0,0 @@
|
|
1
|
-
/* jpeg-data.c
|
2
|
-
*
|
3
|
-
* Copyright � 2001 Lutz M�ller <lutz@users.sourceforge.net>
|
4
|
-
*
|
5
|
-
* This library is free software; you can redistribute it and/or
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
7
|
-
* License as published by the Free Software Foundation; either
|
8
|
-
* version 2 of the License, or (at your option) any later version.
|
9
|
-
*
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
16
|
-
* License along with this library; if not, write to the
|
17
|
-
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
18
|
-
* Boston, MA 02110-1301 USA.
|
19
|
-
*/
|
20
|
-
|
21
|
-
#include "config.h"
|
22
|
-
#include "jpeg-data.h"
|
23
|
-
|
24
|
-
#include <stdlib.h>
|
25
|
-
#include <stdio.h>
|
26
|
-
#include <string.h>
|
27
|
-
|
28
|
-
/* This refers to the exif-i18n.h file from the "exif" package and is
|
29
|
-
* NOT to be confused with the libexif/i18n.h file.
|
30
|
-
*/
|
31
|
-
#include "exif/exif-i18n.h"
|
32
|
-
|
33
|
-
/* realloc that cleans up on memory failure and returns to caller */
|
34
|
-
#define CLEANUP_REALLOC(p,s) { \
|
35
|
-
unsigned char *cleanup_ptr = realloc((p),(s)); \
|
36
|
-
if (!cleanup_ptr) { free(p); (p) = NULL; return; } \
|
37
|
-
(p) = cleanup_ptr; \
|
38
|
-
}
|
39
|
-
|
40
|
-
struct _JPEGDataPrivate
|
41
|
-
{
|
42
|
-
unsigned int ref_count;
|
43
|
-
|
44
|
-
ExifLog *log;
|
45
|
-
};
|
46
|
-
|
47
|
-
JPEGData *
|
48
|
-
jpeg_data_new (void)
|
49
|
-
{
|
50
|
-
JPEGData *data;
|
51
|
-
|
52
|
-
data = malloc (sizeof (JPEGData));
|
53
|
-
if (!data)
|
54
|
-
return (NULL);
|
55
|
-
memset (data, 0, sizeof (JPEGData));
|
56
|
-
data->priv = malloc (sizeof (JPEGDataPrivate));
|
57
|
-
if (!data->priv) {
|
58
|
-
free (data);
|
59
|
-
return (NULL);
|
60
|
-
}
|
61
|
-
memset (data->priv, 0, sizeof (JPEGDataPrivate));
|
62
|
-
data->priv->ref_count = 1;
|
63
|
-
|
64
|
-
return (data);
|
65
|
-
}
|
66
|
-
|
67
|
-
void
|
68
|
-
jpeg_data_append_section (JPEGData *data)
|
69
|
-
{
|
70
|
-
JPEGSection *s;
|
71
|
-
|
72
|
-
if (!data) return;
|
73
|
-
|
74
|
-
if (!data->count)
|
75
|
-
s = malloc (sizeof (JPEGSection));
|
76
|
-
else
|
77
|
-
s = realloc (data->sections,
|
78
|
-
sizeof (JPEGSection) * (data->count + 1));
|
79
|
-
if (!s) {
|
80
|
-
EXIF_LOG_NO_MEMORY (data->priv->log, "jpeg-data",
|
81
|
-
sizeof (JPEGSection) * (data->count + 1));
|
82
|
-
return;
|
83
|
-
}
|
84
|
-
memset(s + data->count, 0, sizeof (JPEGSection));
|
85
|
-
data->sections = s;
|
86
|
-
data->count++;
|
87
|
-
}
|
88
|
-
|
89
|
-
/*! jpeg_data_save_file returns 1 on success, 0 on failure */
|
90
|
-
int
|
91
|
-
jpeg_data_save_file (JPEGData *data, const char *path)
|
92
|
-
{
|
93
|
-
FILE *f;
|
94
|
-
unsigned char *d = NULL;
|
95
|
-
unsigned int size = 0, written;
|
96
|
-
|
97
|
-
jpeg_data_save_data (data, &d, &size);
|
98
|
-
if (!d)
|
99
|
-
return 0;
|
100
|
-
|
101
|
-
remove (path);
|
102
|
-
f = fopen (path, "wb");
|
103
|
-
if (!f) {
|
104
|
-
free (d);
|
105
|
-
return 0;
|
106
|
-
}
|
107
|
-
written = fwrite (d, 1, size, f);
|
108
|
-
fclose (f);
|
109
|
-
free (d);
|
110
|
-
if (written == size) {
|
111
|
-
return 1;
|
112
|
-
}
|
113
|
-
remove(path);
|
114
|
-
return 0;
|
115
|
-
}
|
116
|
-
|
117
|
-
void
|
118
|
-
jpeg_data_save_data (JPEGData *data, unsigned char **d, unsigned int *ds)
|
119
|
-
{
|
120
|
-
unsigned int i, eds = 0;
|
121
|
-
JPEGSection s;
|
122
|
-
unsigned char *ed = NULL;
|
123
|
-
|
124
|
-
if (!data)
|
125
|
-
return;
|
126
|
-
if (!d)
|
127
|
-
return;
|
128
|
-
if (!ds)
|
129
|
-
return;
|
130
|
-
|
131
|
-
for (*ds = i = 0; i < data->count; i++) {
|
132
|
-
s = data->sections[i];
|
133
|
-
|
134
|
-
/* Write the marker */
|
135
|
-
CLEANUP_REALLOC (*d, sizeof (char) * (*ds + 2));
|
136
|
-
(*d)[*ds + 0] = 0xff;
|
137
|
-
(*d)[*ds + 1] = s.marker;
|
138
|
-
*ds += 2;
|
139
|
-
|
140
|
-
switch (s.marker) {
|
141
|
-
case JPEG_MARKER_SOI:
|
142
|
-
case JPEG_MARKER_EOI:
|
143
|
-
break;
|
144
|
-
case JPEG_MARKER_APP1:
|
145
|
-
exif_data_save_data (s.content.app1, &ed, &eds);
|
146
|
-
if (!ed) break;
|
147
|
-
CLEANUP_REALLOC (*d, sizeof (char) * (*ds + 2));
|
148
|
-
(*d)[*ds + 0] = (eds + 2) >> 8;
|
149
|
-
(*d)[*ds + 1] = (eds + 2) >> 0;
|
150
|
-
*ds += 2;
|
151
|
-
CLEANUP_REALLOC (*d, sizeof (char) * (*ds + eds));
|
152
|
-
memcpy (*d + *ds, ed, eds);
|
153
|
-
*ds += eds;
|
154
|
-
free (ed);
|
155
|
-
break;
|
156
|
-
default:
|
157
|
-
CLEANUP_REALLOC (*d, sizeof (char) *
|
158
|
-
(*ds + s.content.generic.size + 2));
|
159
|
-
(*d)[*ds + 0] = (s.content.generic.size + 2) >> 8;
|
160
|
-
(*d)[*ds + 1] = (s.content.generic.size + 2) >> 0;
|
161
|
-
*ds += 2;
|
162
|
-
memcpy (*d + *ds, s.content.generic.data,
|
163
|
-
s.content.generic.size);
|
164
|
-
*ds += s.content.generic.size;
|
165
|
-
|
166
|
-
/* In case of SOS, we need to write the data. */
|
167
|
-
if (s.marker == JPEG_MARKER_SOS) {
|
168
|
-
CLEANUP_REALLOC (*d, *ds + data->size);
|
169
|
-
memcpy (*d + *ds, data->data, data->size);
|
170
|
-
*ds += data->size;
|
171
|
-
}
|
172
|
-
break;
|
173
|
-
}
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
|
-
JPEGData *
|
178
|
-
jpeg_data_new_from_data (const unsigned char *d,
|
179
|
-
unsigned int size)
|
180
|
-
{
|
181
|
-
JPEGData *data;
|
182
|
-
|
183
|
-
data = jpeg_data_new ();
|
184
|
-
jpeg_data_load_data (data, d, size);
|
185
|
-
return (data);
|
186
|
-
}
|
187
|
-
|
188
|
-
void
|
189
|
-
jpeg_data_load_data (JPEGData *data, const unsigned char *d,
|
190
|
-
unsigned int size)
|
191
|
-
{
|
192
|
-
unsigned int i, o, len;
|
193
|
-
JPEGSection *s;
|
194
|
-
JPEGMarker marker;
|
195
|
-
|
196
|
-
if (!data) return;
|
197
|
-
if (!d) return;
|
198
|
-
|
199
|
-
for (o = 0; o < size;) {
|
200
|
-
|
201
|
-
/*
|
202
|
-
* JPEG sections start with 0xff. The first byte that is
|
203
|
-
* not 0xff is a marker (hopefully).
|
204
|
-
*/
|
205
|
-
for (i = 0; i < MIN(7, size - o); i++)
|
206
|
-
if (d[o + i] != 0xff)
|
207
|
-
break;
|
208
|
-
if ((i >= size - o) || !JPEG_IS_MARKER (d[o + i])) {
|
209
|
-
exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "jpeg-data",
|
210
|
-
_("Data does not follow JPEG specification."));
|
211
|
-
return;
|
212
|
-
}
|
213
|
-
marker = d[o + i];
|
214
|
-
|
215
|
-
/* Append this section */
|
216
|
-
jpeg_data_append_section (data);
|
217
|
-
if (!data->count) return;
|
218
|
-
s = &data->sections[data->count - 1];
|
219
|
-
s->marker = marker;
|
220
|
-
o += i + 1;
|
221
|
-
|
222
|
-
switch (s->marker) {
|
223
|
-
case JPEG_MARKER_SOI:
|
224
|
-
case JPEG_MARKER_EOI:
|
225
|
-
break;
|
226
|
-
default:
|
227
|
-
|
228
|
-
/* Read the length of the section */
|
229
|
-
if (2 > size - o) { o = size; break; }
|
230
|
-
len = ((d[o] << 8) | d[o + 1]) - 2;
|
231
|
-
if (len > size) { o = size; break; }
|
232
|
-
o += 2;
|
233
|
-
if (len > size - o) { o = size; break; }
|
234
|
-
|
235
|
-
switch (s->marker) {
|
236
|
-
case JPEG_MARKER_APP1:
|
237
|
-
s->content.app1 = exif_data_new_from_data (
|
238
|
-
d + o - 4, len + 4);
|
239
|
-
break;
|
240
|
-
default:
|
241
|
-
s->content.generic.data =
|
242
|
-
malloc (sizeof (char) * len);
|
243
|
-
if (!s->content.generic.data) {
|
244
|
-
EXIF_LOG_NO_MEMORY (data->priv->log, "jpeg-data", sizeof (char) * len);
|
245
|
-
return;
|
246
|
-
}
|
247
|
-
s->content.generic.size = len;
|
248
|
-
memcpy (s->content.generic.data, &d[o], len);
|
249
|
-
|
250
|
-
/* In case of SOS, image data will follow. */
|
251
|
-
if (s->marker == JPEG_MARKER_SOS) {
|
252
|
-
data->size = size - o - len;
|
253
|
-
if (data->size >= 2) {
|
254
|
-
/* -2 means 'take all but the last 2 bytes which are
|
255
|
-
hoped to be JPEG_MARKER_EOI */
|
256
|
-
data->size -= 2;
|
257
|
-
if (d[o + len + data->size] != 0xFF) {
|
258
|
-
/* A truncated file (i.e. w/o JPEG_MARKER_EOI at the end).
|
259
|
-
Instead of trying to use the last two bytes as marker,
|
260
|
-
touching memory beyond allocated memory and posssibly saving
|
261
|
-
back screwed file, we rather take the rest of the file. */
|
262
|
-
data->size += 2;
|
263
|
-
}
|
264
|
-
}
|
265
|
-
data->data = malloc (
|
266
|
-
sizeof (char) * data->size);
|
267
|
-
if (!data->data) {
|
268
|
-
EXIF_LOG_NO_MEMORY (data->priv->log, "jpeg-data", sizeof (char) * data->size);
|
269
|
-
data->size = 0;
|
270
|
-
return;
|
271
|
-
}
|
272
|
-
memcpy (data->data, d + o + len,
|
273
|
-
data->size);
|
274
|
-
o += data->size;
|
275
|
-
}
|
276
|
-
break;
|
277
|
-
}
|
278
|
-
o += len;
|
279
|
-
break;
|
280
|
-
}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
|
284
|
-
JPEGData *
|
285
|
-
jpeg_data_new_from_file (const char *path)
|
286
|
-
{
|
287
|
-
JPEGData *data;
|
288
|
-
|
289
|
-
data = jpeg_data_new ();
|
290
|
-
jpeg_data_load_file (data, path);
|
291
|
-
return (data);
|
292
|
-
}
|
293
|
-
|
294
|
-
void
|
295
|
-
jpeg_data_load_file (JPEGData *data, const char *path)
|
296
|
-
{
|
297
|
-
FILE *f;
|
298
|
-
unsigned char *d;
|
299
|
-
unsigned int size;
|
300
|
-
|
301
|
-
if (!data) return;
|
302
|
-
if (!path) return;
|
303
|
-
|
304
|
-
f = fopen (path, "rb");
|
305
|
-
if (!f) {
|
306
|
-
exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "jpeg-data",
|
307
|
-
_("Path '%s' invalid."), path);
|
308
|
-
return;
|
309
|
-
}
|
310
|
-
|
311
|
-
/* For now, we read the data into memory. Patches welcome... */
|
312
|
-
fseek (f, 0, SEEK_END);
|
313
|
-
size = ftell (f);
|
314
|
-
fseek (f, 0, SEEK_SET);
|
315
|
-
d = malloc (size);
|
316
|
-
if (!d) {
|
317
|
-
EXIF_LOG_NO_MEMORY (data->priv->log, "jpeg-data", size);
|
318
|
-
fclose (f);
|
319
|
-
return;
|
320
|
-
}
|
321
|
-
if (fread (d, 1, size, f) != size) {
|
322
|
-
free (d);
|
323
|
-
fclose (f);
|
324
|
-
exif_log (data->priv->log, EXIF_LOG_CODE_CORRUPT_DATA, "jpeg-data",
|
325
|
-
_("Could not read '%s'."), path);
|
326
|
-
return;
|
327
|
-
}
|
328
|
-
fclose (f);
|
329
|
-
|
330
|
-
jpeg_data_load_data (data, d, size);
|
331
|
-
free (d);
|
332
|
-
}
|
333
|
-
|
334
|
-
void
|
335
|
-
jpeg_data_ref (JPEGData *data)
|
336
|
-
{
|
337
|
-
if (!data)
|
338
|
-
return;
|
339
|
-
|
340
|
-
data->priv->ref_count++;
|
341
|
-
}
|
342
|
-
|
343
|
-
void
|
344
|
-
jpeg_data_unref (JPEGData *data)
|
345
|
-
{
|
346
|
-
if (!data)
|
347
|
-
return;
|
348
|
-
|
349
|
-
if (data->priv) {
|
350
|
-
data->priv->ref_count--;
|
351
|
-
if (!data->priv->ref_count)
|
352
|
-
jpeg_data_free (data);
|
353
|
-
}
|
354
|
-
}
|
355
|
-
|
356
|
-
void
|
357
|
-
jpeg_data_free (JPEGData *data)
|
358
|
-
{
|
359
|
-
unsigned int i;
|
360
|
-
JPEGSection s;
|
361
|
-
|
362
|
-
if (!data)
|
363
|
-
return;
|
364
|
-
|
365
|
-
if (data->count) {
|
366
|
-
for (i = 0; i < data->count; i++) {
|
367
|
-
s = data->sections[i];
|
368
|
-
switch (s.marker) {
|
369
|
-
case JPEG_MARKER_SOI:
|
370
|
-
case JPEG_MARKER_EOI:
|
371
|
-
break;
|
372
|
-
case JPEG_MARKER_APP1:
|
373
|
-
exif_data_unref (s.content.app1);
|
374
|
-
break;
|
375
|
-
default:
|
376
|
-
free (s.content.generic.data);
|
377
|
-
break;
|
378
|
-
}
|
379
|
-
}
|
380
|
-
free (data->sections);
|
381
|
-
}
|
382
|
-
|
383
|
-
if (data->data)
|
384
|
-
free (data->data);
|
385
|
-
|
386
|
-
if (data->priv) {
|
387
|
-
if (data->priv->log) {
|
388
|
-
exif_log_unref (data->priv->log);
|
389
|
-
data->priv->log = NULL;
|
390
|
-
}
|
391
|
-
free (data->priv);
|
392
|
-
}
|
393
|
-
|
394
|
-
free (data);
|
395
|
-
}
|
396
|
-
|
397
|
-
void
|
398
|
-
jpeg_data_dump (JPEGData *data)
|
399
|
-
{
|
400
|
-
unsigned int i;
|
401
|
-
JPEGContent content;
|
402
|
-
JPEGMarker marker;
|
403
|
-
|
404
|
-
if (!data)
|
405
|
-
return;
|
406
|
-
|
407
|
-
printf ("Dumping JPEG data (%i bytes of data)...\n", data->size);
|
408
|
-
for (i = 0; i < data->count; i++) {
|
409
|
-
marker = data->sections[i].marker;
|
410
|
-
content = data->sections[i].content;
|
411
|
-
printf ("Section %i (marker 0x%x - %s):\n", i, marker,
|
412
|
-
jpeg_marker_get_name (marker));
|
413
|
-
printf (" Description: %s\n",
|
414
|
-
jpeg_marker_get_description (marker));
|
415
|
-
switch (marker) {
|
416
|
-
case JPEG_MARKER_SOI:
|
417
|
-
case JPEG_MARKER_EOI:
|
418
|
-
break;
|
419
|
-
case JPEG_MARKER_APP1:
|
420
|
-
exif_data_dump (content.app1);
|
421
|
-
break;
|
422
|
-
default:
|
423
|
-
printf (" Size: %i\n", content.generic.size);
|
424
|
-
printf (" Unknown content.\n");
|
425
|
-
break;
|
426
|
-
}
|
427
|
-
}
|
428
|
-
}
|
429
|
-
|
430
|
-
static JPEGSection *
|
431
|
-
jpeg_data_get_section (JPEGData *data, JPEGMarker marker)
|
432
|
-
{
|
433
|
-
unsigned int i;
|
434
|
-
|
435
|
-
if (!data)
|
436
|
-
return (NULL);
|
437
|
-
|
438
|
-
for (i = 0; i < data->count; i++)
|
439
|
-
if (data->sections[i].marker == marker)
|
440
|
-
return (&data->sections[i]);
|
441
|
-
return (NULL);
|
442
|
-
}
|
443
|
-
|
444
|
-
ExifData *
|
445
|
-
jpeg_data_get_exif_data (JPEGData *data)
|
446
|
-
{
|
447
|
-
JPEGSection *section;
|
448
|
-
|
449
|
-
if (!data)
|
450
|
-
return NULL;
|
451
|
-
|
452
|
-
section = jpeg_data_get_section (data, JPEG_MARKER_APP1);
|
453
|
-
if (section) {
|
454
|
-
exif_data_ref (section->content.app1);
|
455
|
-
return (section->content.app1);
|
456
|
-
}
|
457
|
-
|
458
|
-
return (NULL);
|
459
|
-
}
|
460
|
-
|
461
|
-
void
|
462
|
-
jpeg_data_set_exif_data (JPEGData *data, ExifData *exif_data)
|
463
|
-
{
|
464
|
-
JPEGSection *section;
|
465
|
-
|
466
|
-
if (!data) return;
|
467
|
-
|
468
|
-
section = jpeg_data_get_section (data, JPEG_MARKER_APP1);
|
469
|
-
if (!section) {
|
470
|
-
jpeg_data_append_section (data);
|
471
|
-
if (data->count < 2) return;
|
472
|
-
memmove (&data->sections[2], &data->sections[1],
|
473
|
-
sizeof (JPEGSection) * (data->count - 2));
|
474
|
-
section = &data->sections[1];
|
475
|
-
} else {
|
476
|
-
exif_data_unref (section->content.app1);
|
477
|
-
}
|
478
|
-
section->marker = JPEG_MARKER_APP1;
|
479
|
-
section->content.app1 = exif_data;
|
480
|
-
exif_data_ref (exif_data);
|
481
|
-
}
|
482
|
-
|
483
|
-
void
|
484
|
-
jpeg_data_log (JPEGData *data, ExifLog *log)
|
485
|
-
{
|
486
|
-
if (!data || !data->priv) return;
|
487
|
-
if (data->priv->log) exif_log_unref (data->priv->log);
|
488
|
-
data->priv->log = log;
|
489
|
-
exif_log_ref (log);
|
490
|
-
}
|
@@ -1,92 +0,0 @@
|
|
1
|
-
/* jpeg-data.h
|
2
|
-
*
|
3
|
-
* Copyright � 2001 Lutz M�ller <lutz@users.sourceforge.net>
|
4
|
-
*
|
5
|
-
* This library is free software; you can redistribute it and/or
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
7
|
-
* License as published by the Free Software Foundation; either
|
8
|
-
* version 2 of the License, or (at your option) any later version.
|
9
|
-
*
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
16
|
-
* License along with this library; if not, write to the
|
17
|
-
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
18
|
-
* Boston, MA 02110-1301 USA.
|
19
|
-
*/
|
20
|
-
|
21
|
-
#ifndef __JPEG_DATA_H__
|
22
|
-
#define __JPEG_DATA_H__
|
23
|
-
|
24
|
-
#include "libjpeg/jpeg-marker.h"
|
25
|
-
|
26
|
-
#include <libexif/exif-data.h>
|
27
|
-
#include <libexif/exif-log.h>
|
28
|
-
|
29
|
-
typedef ExifData * JPEGContentAPP1;
|
30
|
-
|
31
|
-
typedef struct _JPEGContentGeneric JPEGContentGeneric;
|
32
|
-
struct _JPEGContentGeneric
|
33
|
-
{
|
34
|
-
unsigned char *data;
|
35
|
-
unsigned int size;
|
36
|
-
};
|
37
|
-
|
38
|
-
typedef union _JPEGContent JPEGContent;
|
39
|
-
union _JPEGContent
|
40
|
-
{
|
41
|
-
JPEGContentGeneric generic;
|
42
|
-
JPEGContentAPP1 app1;
|
43
|
-
};
|
44
|
-
|
45
|
-
typedef struct _JPEGSection JPEGSection;
|
46
|
-
struct _JPEGSection
|
47
|
-
{
|
48
|
-
JPEGMarker marker;
|
49
|
-
JPEGContent content;
|
50
|
-
};
|
51
|
-
|
52
|
-
typedef struct _JPEGData JPEGData;
|
53
|
-
typedef struct _JPEGDataPrivate JPEGDataPrivate;
|
54
|
-
|
55
|
-
struct _JPEGData
|
56
|
-
{
|
57
|
-
JPEGSection *sections;
|
58
|
-
unsigned int count;
|
59
|
-
|
60
|
-
unsigned char *data;
|
61
|
-
unsigned int size;
|
62
|
-
|
63
|
-
JPEGDataPrivate *priv;
|
64
|
-
};
|
65
|
-
|
66
|
-
JPEGData *jpeg_data_new (void);
|
67
|
-
JPEGData *jpeg_data_new_from_file (const char *path);
|
68
|
-
JPEGData *jpeg_data_new_from_data (const unsigned char *data,
|
69
|
-
unsigned int size);
|
70
|
-
|
71
|
-
void jpeg_data_ref (JPEGData *data);
|
72
|
-
void jpeg_data_unref (JPEGData *data);
|
73
|
-
void jpeg_data_free (JPEGData *data);
|
74
|
-
|
75
|
-
void jpeg_data_load_data (JPEGData *data, const unsigned char *d,
|
76
|
-
unsigned int size);
|
77
|
-
void jpeg_data_save_data (JPEGData *data, unsigned char **d,
|
78
|
-
unsigned int *size);
|
79
|
-
|
80
|
-
void jpeg_data_load_file (JPEGData *data, const char *path);
|
81
|
-
int jpeg_data_save_file (JPEGData *data, const char *path);
|
82
|
-
|
83
|
-
void jpeg_data_set_exif_data (JPEGData *data, ExifData *exif_data);
|
84
|
-
ExifData *jpeg_data_get_exif_data (JPEGData *data);
|
85
|
-
|
86
|
-
void jpeg_data_dump (JPEGData *data);
|
87
|
-
|
88
|
-
void jpeg_data_append_section (JPEGData *data);
|
89
|
-
|
90
|
-
void jpeg_data_log (JPEGData *data, ExifLog *log);
|
91
|
-
|
92
|
-
#endif /* __JPEG_DATA_H__ */
|
@@ -1,122 +0,0 @@
|
|
1
|
-
/* jpeg-marker.c
|
2
|
-
*
|
3
|
-
* Copyright � 2001-2008 Lutz M�ller <lutz@users.sourceforge.net>
|
4
|
-
*
|
5
|
-
* This library is free software; you can redistribute it and/or
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
7
|
-
* License as published by the Free Software Foundation; either
|
8
|
-
* version 2 of the License, or (at your option) any later version.
|
9
|
-
*
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
16
|
-
* License along with this library; if not, write to the
|
17
|
-
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
18
|
-
* Boston, MA 02110-1301 USA.
|
19
|
-
*/
|
20
|
-
#include "config.h"
|
21
|
-
#include "jpeg-marker.h"
|
22
|
-
|
23
|
-
#include <stdlib.h>
|
24
|
-
|
25
|
-
static const struct {
|
26
|
-
JPEGMarker marker;
|
27
|
-
const char *name;
|
28
|
-
const char *description;
|
29
|
-
} JPEGMarkerTable[] = {
|
30
|
-
{JPEG_MARKER_SOF0, "SOF0", "Encoding (baseline)"},
|
31
|
-
{JPEG_MARKER_SOF1, "SOF1", "Encoding (extended sequential)"},
|
32
|
-
{JPEG_MARKER_SOF2, "SOF2", "Encoding (progressive)"},
|
33
|
-
{JPEG_MARKER_SOF3, "SOF3", "Encoding (lossless)"},
|
34
|
-
{JPEG_MARKER_SOF5, "SOF5", "Encoding (differential sequential)"},
|
35
|
-
{JPEG_MARKER_SOF6, "SOF6", "Encoding (differential progressive)"},
|
36
|
-
{JPEG_MARKER_SOF7, "SOF7", "Encoding (differential lossless)"},
|
37
|
-
{JPEG_MARKER_SOF9, "SOF9",
|
38
|
-
"Encoding (extended sequential, arithmetic)"},
|
39
|
-
{JPEG_MARKER_SOF10, "SOF10", "Encoding (progressive, arithmetic)"},
|
40
|
-
{JPEG_MARKER_SOF11, "SOF11", "Encoding (lossless, arithmetic)"},
|
41
|
-
{JPEG_MARKER_SOF13, "SOF13",
|
42
|
-
"Encoding (differential sequential, arithmetic)"},
|
43
|
-
{JPEG_MARKER_SOF14, "SOF14",
|
44
|
-
"Encoding (differential progressive, arithmetic)"},
|
45
|
-
{JPEG_MARKER_SOF15, "SOF15",
|
46
|
-
"Encoding (differential lossless, arithmetic)"},
|
47
|
-
{JPEG_MARKER_SOI, "SOI", "Start of image"},
|
48
|
-
{JPEG_MARKER_EOI, "EOI", "End of image"},
|
49
|
-
{JPEG_MARKER_SOS, "SOS", "Start of scan"},
|
50
|
-
{JPEG_MARKER_COM, "COM", "Comment"},
|
51
|
-
{JPEG_MARKER_DHT, "DHT", "Define Huffman table"},
|
52
|
-
{JPEG_MARKER_JPG, "JPG", "Extension"},
|
53
|
-
{JPEG_MARKER_DAC, "DAC", "Define arithmetic coding conditioning"},
|
54
|
-
{JPEG_MARKER_RST1, "RST1", "Restart 1"},
|
55
|
-
{JPEG_MARKER_RST2, "RST2", "Restart 2"},
|
56
|
-
{JPEG_MARKER_RST3, "RST3", "Restart 3"},
|
57
|
-
{JPEG_MARKER_RST4, "RST4", "Restart 4"},
|
58
|
-
{JPEG_MARKER_RST5, "RST5", "Restart 5"},
|
59
|
-
{JPEG_MARKER_RST6, "RST6", "Restart 6"},
|
60
|
-
{JPEG_MARKER_RST7, "RST7", "Restart 7"},
|
61
|
-
{JPEG_MARKER_DQT, "DQT", "Define quantization table"},
|
62
|
-
{JPEG_MARKER_DNL, "DNL", "Define number of lines"},
|
63
|
-
{JPEG_MARKER_DRI, "DRI", "Define restart interval"},
|
64
|
-
{JPEG_MARKER_DHP, "DHP", "Define hierarchical progression"},
|
65
|
-
{JPEG_MARKER_EXP, "EXP", "Expand reference component"},
|
66
|
-
{JPEG_MARKER_APP0, "APP0", "Application segment 0"},
|
67
|
-
{JPEG_MARKER_APP1, "APP1", "Application segment 1"},
|
68
|
-
{JPEG_MARKER_APP2, "APP2", "Application segment 2"},
|
69
|
-
{JPEG_MARKER_APP3, "APP3", "Application segment 3"},
|
70
|
-
{JPEG_MARKER_APP4, "APP4", "Application segment 4"},
|
71
|
-
{JPEG_MARKER_APP5, "APP5", "Application segment 5"},
|
72
|
-
{JPEG_MARKER_APP6, "APP6", "Application segment 6"},
|
73
|
-
{JPEG_MARKER_APP7, "APP7", "Application segment 7"},
|
74
|
-
{JPEG_MARKER_APP8, "APP8", "Application segment 8"},
|
75
|
-
{JPEG_MARKER_APP9, "APP9", "Application segment 9"},
|
76
|
-
{JPEG_MARKER_APP10, "APP10", "Application segment 10"},
|
77
|
-
{JPEG_MARKER_APP11, "APP11", "Application segment 11"},
|
78
|
-
{JPEG_MARKER_APP12, "APP12", "Application segment 12"},
|
79
|
-
{JPEG_MARKER_APP13, "APP13", "Application segment 13"},
|
80
|
-
{JPEG_MARKER_APP14, "APP14", "Application segment 14"},
|
81
|
-
{JPEG_MARKER_APP15, "APP15", "Application segment 15"},
|
82
|
-
{JPEG_MARKER_JPG0, "JPG0", "Extension 0"},
|
83
|
-
{JPEG_MARKER_JPG1, "JPG1", "Extension 1"},
|
84
|
-
{JPEG_MARKER_JPG2, "JPG2", "Extension 2"},
|
85
|
-
{JPEG_MARKER_JPG3, "JPG3", "Extension 3"},
|
86
|
-
{JPEG_MARKER_JPG4, "JPG4", "Extension 4"},
|
87
|
-
{JPEG_MARKER_JPG5, "JPG5", "Extension 5"},
|
88
|
-
{JPEG_MARKER_JPG6, "JPG6", "Extension 6"},
|
89
|
-
{JPEG_MARKER_JPG7, "JPG7", "Extension 7"},
|
90
|
-
{JPEG_MARKER_JPG8, "JPG8", "Extension 8"},
|
91
|
-
{JPEG_MARKER_JPG9, "JPG9", "Extension 9"},
|
92
|
-
{JPEG_MARKER_JPG10, "JPG10", "Extension 10"},
|
93
|
-
{JPEG_MARKER_JPG11, "JPG11", "Extension 11"},
|
94
|
-
{JPEG_MARKER_JPG12, "JPG12", "Extension 12"},
|
95
|
-
{JPEG_MARKER_JPG13, "JPG13", "Extension 13"},
|
96
|
-
{0, NULL, NULL}
|
97
|
-
};
|
98
|
-
|
99
|
-
const char *
|
100
|
-
jpeg_marker_get_name (JPEGMarker marker)
|
101
|
-
{
|
102
|
-
unsigned int i;
|
103
|
-
|
104
|
-
for (i = 0; JPEGMarkerTable[i].name; i++)
|
105
|
-
if (JPEGMarkerTable[i].marker == marker)
|
106
|
-
break;
|
107
|
-
|
108
|
-
return (JPEGMarkerTable[i].name);
|
109
|
-
}
|
110
|
-
|
111
|
-
const char *
|
112
|
-
jpeg_marker_get_description (JPEGMarker marker)
|
113
|
-
{
|
114
|
-
unsigned int i;
|
115
|
-
|
116
|
-
for (i = 0; JPEGMarkerTable[i].description; i++)
|
117
|
-
if (JPEGMarkerTable[i].marker == marker)
|
118
|
-
break;
|
119
|
-
|
120
|
-
return (JPEGMarkerTable[i].description);
|
121
|
-
}
|
122
|
-
|
@@ -1,103 +0,0 @@
|
|
1
|
-
/* jpeg-marker.h
|
2
|
-
*
|
3
|
-
* Copyright � 2001 Lutz M�ller <lutz@users.sourceforge.net>
|
4
|
-
*
|
5
|
-
* This library is free software; you can redistribute it and/or
|
6
|
-
* modify it under the terms of the GNU Lesser General Public
|
7
|
-
* License as published by the Free Software Foundation; either
|
8
|
-
* version 2 of the License, or (at your option) any later version.
|
9
|
-
*
|
10
|
-
* This library is distributed in the hope that it will be useful,
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
-
* Lesser General Public License for more details.
|
14
|
-
*
|
15
|
-
* You should have received a copy of the GNU Lesser General Public
|
16
|
-
* License along with this library; if not, write to the
|
17
|
-
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
18
|
-
* Boston, MA 02110-1301 USA.
|
19
|
-
*/
|
20
|
-
#ifndef __JPEG_MARKER_H__
|
21
|
-
#define __JPEG_MARKER_H__
|
22
|
-
|
23
|
-
#ifdef __cplusplus
|
24
|
-
extern "C" {
|
25
|
-
#endif /* __cplusplus */
|
26
|
-
|
27
|
-
typedef enum {
|
28
|
-
JPEG_MARKER_SOF0 = 0xc0,
|
29
|
-
JPEG_MARKER_SOF1 = 0xc1,
|
30
|
-
JPEG_MARKER_SOF2 = 0xc2,
|
31
|
-
JPEG_MARKER_SOF3 = 0xc3,
|
32
|
-
JPEG_MARKER_DHT = 0xc4,
|
33
|
-
JPEG_MARKER_SOF5 = 0xc5,
|
34
|
-
JPEG_MARKER_SOF6 = 0xc6,
|
35
|
-
JPEG_MARKER_SOF7 = 0xc7,
|
36
|
-
JPEG_MARKER_JPG = 0xc8,
|
37
|
-
JPEG_MARKER_SOF9 = 0xc9,
|
38
|
-
JPEG_MARKER_SOF10 = 0xca,
|
39
|
-
JPEG_MARKER_SOF11 = 0xcb,
|
40
|
-
JPEG_MARKER_DAC = 0xcc,
|
41
|
-
JPEG_MARKER_SOF13 = 0xcd,
|
42
|
-
JPEG_MARKER_SOF14 = 0xce,
|
43
|
-
JPEG_MARKER_SOF15 = 0xcf,
|
44
|
-
JPEG_MARKER_RST0 = 0xd0,
|
45
|
-
JPEG_MARKER_RST1 = 0xd1,
|
46
|
-
JPEG_MARKER_RST2 = 0xd2,
|
47
|
-
JPEG_MARKER_RST3 = 0xd3,
|
48
|
-
JPEG_MARKER_RST4 = 0xd4,
|
49
|
-
JPEG_MARKER_RST5 = 0xd5,
|
50
|
-
JPEG_MARKER_RST6 = 0xd6,
|
51
|
-
JPEG_MARKER_RST7 = 0xd7,
|
52
|
-
JPEG_MARKER_SOI = 0xd8,
|
53
|
-
JPEG_MARKER_EOI = 0xd9,
|
54
|
-
JPEG_MARKER_SOS = 0xda,
|
55
|
-
JPEG_MARKER_DQT = 0xdb,
|
56
|
-
JPEG_MARKER_DNL = 0xdc,
|
57
|
-
JPEG_MARKER_DRI = 0xdd,
|
58
|
-
JPEG_MARKER_DHP = 0xde,
|
59
|
-
JPEG_MARKER_EXP = 0xdf,
|
60
|
-
JPEG_MARKER_APP0 = 0xe0,
|
61
|
-
JPEG_MARKER_APP1 = 0xe1,
|
62
|
-
JPEG_MARKER_APP2 = 0xe2,
|
63
|
-
JPEG_MARKER_APP3 = 0xe3,
|
64
|
-
JPEG_MARKER_APP4 = 0xe4,
|
65
|
-
JPEG_MARKER_APP5 = 0xe5,
|
66
|
-
JPEG_MARKER_APP6 = 0xe6,
|
67
|
-
JPEG_MARKER_APP7 = 0xe7,
|
68
|
-
JPEG_MARKER_APP8 = 0xe8,
|
69
|
-
JPEG_MARKER_APP9 = 0xe9,
|
70
|
-
JPEG_MARKER_APP10 = 0xea,
|
71
|
-
JPEG_MARKER_APP11 = 0xeb,
|
72
|
-
JPEG_MARKER_APP12 = 0xec,
|
73
|
-
JPEG_MARKER_APP13 = 0xed,
|
74
|
-
JPEG_MARKER_APP14 = 0xee,
|
75
|
-
JPEG_MARKER_APP15 = 0xef,
|
76
|
-
JPEG_MARKER_JPG0 = 0xf0,
|
77
|
-
JPEG_MARKER_JPG1 = 0xf1,
|
78
|
-
JPEG_MARKER_JPG2 = 0xf2,
|
79
|
-
JPEG_MARKER_JPG3 = 0xf3,
|
80
|
-
JPEG_MARKER_JPG4 = 0xf4,
|
81
|
-
JPEG_MARKER_JPG5 = 0xf5,
|
82
|
-
JPEG_MARKER_JPG6 = 0xf6,
|
83
|
-
JPEG_MARKER_JPG7 = 0xf7,
|
84
|
-
JPEG_MARKER_JPG8 = 0xf8,
|
85
|
-
JPEG_MARKER_JPG9 = 0xf9,
|
86
|
-
JPEG_MARKER_JPG10 = 0xfa,
|
87
|
-
JPEG_MARKER_JPG11 = 0xfb,
|
88
|
-
JPEG_MARKER_JPG12 = 0xfc,
|
89
|
-
JPEG_MARKER_JPG13 = 0xfd,
|
90
|
-
JPEG_MARKER_COM = 0xfe
|
91
|
-
} JPEGMarker;
|
92
|
-
|
93
|
-
#define JPEG_IS_MARKER(m) (((m) >= JPEG_MARKER_SOF0) && \
|
94
|
-
((m) <= JPEG_MARKER_COM))
|
95
|
-
|
96
|
-
const char *jpeg_marker_get_name (JPEGMarker marker);
|
97
|
-
const char *jpeg_marker_get_description (JPEGMarker marker);
|
98
|
-
|
99
|
-
#ifdef __cplusplus
|
100
|
-
}
|
101
|
-
#endif /* __cplusplus */
|
102
|
-
|
103
|
-
#endif /* __JPEG_MARKER_H__ */
|