ruby-exiv2 0.3 → 0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/Makefile +15 -12
- data/lib/exif.cpp +45 -10
- data/lib/exiv2.cpp +1 -1
- data/lib/exiv2.hpp +2 -1
- data/lib/image.cpp +41 -2
- data/test/image.rb +10 -0
- metadata +4 -3
data/lib/Makefile
CHANGED
@@ -4,7 +4,7 @@ SHELL = /bin/sh
|
|
4
4
|
#### Start of system configuration section. ####
|
5
5
|
|
6
6
|
srcdir = .
|
7
|
-
topdir = /opt/local/lib/ruby/1.8/
|
7
|
+
topdir = /opt/local/lib/ruby/1.8/powerpc-darwin8.8.0
|
8
8
|
hdrdir = $(topdir)
|
9
9
|
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
10
|
prefix = $(DESTDIR)/opt/local
|
@@ -36,8 +36,10 @@ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
|
36
36
|
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
37
37
|
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
38
38
|
|
39
|
+
RUBY_EXTCONF_H =
|
39
40
|
CFLAGS = -fno-common -O -pipe -I/opt/local/include -fno-common -pipe -fno-common
|
40
|
-
|
41
|
+
INCFLAGS = -I. -I. -I/opt/local/lib/ruby/1.8/powerpc-darwin8.8.0 -I.
|
42
|
+
CPPFLAGS = -O -pipe -I/opt/local/include -Wall -I/usr/local/include/exiv2 -I/usr/include/exiv2
|
41
43
|
CXXFLAGS = $(CFLAGS)
|
42
44
|
DLDFLAGS = -L/opt/local/lib -lstdc++
|
43
45
|
LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
|
@@ -46,9 +48,9 @@ EXEEXT =
|
|
46
48
|
|
47
49
|
RUBY_INSTALL_NAME = ruby
|
48
50
|
RUBY_SO_NAME = ruby
|
49
|
-
arch =
|
50
|
-
sitearch =
|
51
|
-
vendorarch =
|
51
|
+
arch = powerpc-darwin8.8.0
|
52
|
+
sitearch = powerpc-darwin8.8.0
|
53
|
+
vendorarch = powerpc-darwin8.8.0
|
52
54
|
ruby_version = 1.8
|
53
55
|
ruby = /opt/local/bin/ruby
|
54
56
|
RUBY = $(ruby)
|
@@ -74,11 +76,12 @@ extout =
|
|
74
76
|
extout_prefix =
|
75
77
|
target_prefix =
|
76
78
|
LOCAL_LIBS =
|
77
|
-
LIBS = $(LIBRUBYARG_SHARED)
|
79
|
+
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
|
78
80
|
SRCS = exif.cpp exiv2.cpp image.cpp
|
79
81
|
OBJS = exif.o exiv2.o image.o
|
80
82
|
TARGET = exiv2
|
81
83
|
DLLIB = $(TARGET).bundle
|
84
|
+
EXTSTATIC =
|
82
85
|
STATIC_LIB =
|
83
86
|
|
84
87
|
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
@@ -96,7 +99,7 @@ clean:
|
|
96
99
|
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
97
100
|
|
98
101
|
distclean: clean
|
99
|
-
@-$(RM) Makefile
|
102
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
100
103
|
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
101
104
|
|
102
105
|
realclean: distclean
|
@@ -120,19 +123,19 @@ site-install-rb: install-rb
|
|
120
123
|
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
121
124
|
|
122
125
|
.cc.o:
|
123
|
-
$(CXX) $(
|
126
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
124
127
|
|
125
128
|
.cxx.o:
|
126
|
-
$(CXX) $(
|
129
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
127
130
|
|
128
131
|
.cpp.o:
|
129
|
-
$(CXX) $(
|
132
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
130
133
|
|
131
134
|
.C.o:
|
132
|
-
$(CXX) $(
|
135
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
133
136
|
|
134
137
|
.c.o:
|
135
|
-
$(CC) $(
|
138
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
136
139
|
|
137
140
|
$(DLLIB): $(OBJS)
|
138
141
|
@-$(RM) $@
|
data/lib/exif.cpp
CHANGED
@@ -102,8 +102,14 @@ static VALUE exiv2_exif_get(VALUE self, VALUE key) {
|
|
102
102
|
* then I will just set apropreciated hash entry to this casted value
|
103
103
|
*/
|
104
104
|
static bool marshall_value(Exiv2::ExifData &exifData, const char* key, VALUE value) {
|
105
|
-
Exiv2::
|
106
|
-
|
105
|
+
Exiv2::TypeId type_id;
|
106
|
+
try {
|
107
|
+
Exiv2::ExifKey exif_key(key);
|
108
|
+
type_id = Exiv2::ExifTags::tagType(exif_key.tag(), exif_key.ifdId());
|
109
|
+
}
|
110
|
+
catch(Exiv2::Error& e) {
|
111
|
+
rb_raise(eError, "Cannot set tag %s because it doesn't exists. Look at http://www.exiv2.org/tags.html for list of supported tags", key);
|
112
|
+
}
|
107
113
|
switch(type_id) {
|
108
114
|
case Exiv2::invalidTypeId:
|
109
115
|
{
|
@@ -167,17 +173,12 @@ static VALUE exiv2_exif_set(VALUE self, VALUE key, VALUE value) {
|
|
167
173
|
Data_Get_Struct(self, rbImage, image);
|
168
174
|
|
169
175
|
VALUE strkey = rb_funcall(key, rb_intern("to_s"), 0);
|
170
|
-
|
171
|
-
{
|
172
|
-
Exiv2::ExifData &exifData = image->image->exifData();
|
176
|
+
Exiv2::ExifData &exifData = image->image->exifData();
|
173
177
|
|
174
|
-
|
175
|
-
}
|
176
|
-
|
177
|
-
if(!marshalled) {
|
178
|
+
if(!marshall_value(exifData, STR(strkey), value)) {
|
178
179
|
THROW("Couldn't write %s", STR(strkey));
|
179
180
|
}
|
180
|
-
|
181
|
+
|
181
182
|
image->dirty = true;
|
182
183
|
return value;
|
183
184
|
__NIL_END
|
@@ -287,6 +288,36 @@ static VALUE exiv2_exif_empty(VALUE self) {
|
|
287
288
|
}
|
288
289
|
|
289
290
|
|
291
|
+
/*
|
292
|
+
static void tag_leave(Exiv2::TagInfo* info) {
|
293
|
+
|
294
|
+
}
|
295
|
+
|
296
|
+
static VALUE create_exiv2_tag(VALUE exif, Exiv2::TagInfo* info) {
|
297
|
+
VALUE tag_info = Data_Wrap_Struct(cTag, 0, tag_leave, info);
|
298
|
+
rb_iv_set(tag_info, "@exif", exif);
|
299
|
+
return tag_info;
|
300
|
+
}
|
301
|
+
static VALUE exiv2_exif_tags_each(VALUE self) {
|
302
|
+
for (int i=0; Exiv2::ifdTagInfo[i].tag_ != 0xffff; ++i) {
|
303
|
+
rb_yield(create_exiv2_tag(self, Exiv2::ifdTagInfo + i));
|
304
|
+
}
|
305
|
+
for (int i=0; Exiv2::exifTagInfo[i].tag_ != 0xffff; ++i) {
|
306
|
+
rb_yield(create_exiv2_tag(self, Exiv2::exifTagInfo + i));
|
307
|
+
}
|
308
|
+
for (int i=0; Exiv2::iopTagInfo[i].tag_ != 0xffff; ++i) {
|
309
|
+
rb_yield(create_exiv2_tag(self, Exiv2::iopTagInfo + i));
|
310
|
+
}
|
311
|
+
for (int i=0; Exiv2::gpsTagInfo[i].tag_ != 0xffff; ++i) {
|
312
|
+
rb_yield(create_exiv2_tag(self, Exiv2::gpsTagInfo + i));
|
313
|
+
}
|
314
|
+
return self;
|
315
|
+
}
|
316
|
+
|
317
|
+
static VALUE exiv2_iptc_tags_each(VALUE self) {
|
318
|
+
|
319
|
+
}
|
320
|
+
*/
|
290
321
|
|
291
322
|
void Init_exif() {
|
292
323
|
cExif = rb_define_class_under(mExiv2, "Exif", rb_cObject);
|
@@ -297,4 +328,8 @@ void Init_exif() {
|
|
297
328
|
rb_define_method(cExif, "clear", VALUEFUNC(exiv2_exif_clear), 0);
|
298
329
|
rb_define_method(cExif, "count", VALUEFUNC(exiv2_exif_count), 0);
|
299
330
|
rb_define_method(cExif, "empty?", VALUEFUNC(exiv2_exif_empty), 0);
|
331
|
+
// rb_define_singleton_method(cExif, "exif_tags_each", VALUEFUNC(exiv2_exif_tags_each), 0);
|
332
|
+
// rb_define_singleton_method(cExif, "iptc_tags_each", VALUEFUNC(exiv2_iptc_tags_each), 0);
|
333
|
+
|
334
|
+
cTag = rb_define_class_under(mExiv2, "Tag", rb_cObject);
|
300
335
|
}
|
data/lib/exiv2.cpp
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
#include "exiv2.hpp"
|
30
30
|
|
31
31
|
|
32
|
-
VALUE mExiv2, cImage, cExif, cIptc, cThumbnail, eError;
|
32
|
+
VALUE mExiv2, cImage, cExif, cTag, cIptc, cThumbnail, eError;
|
33
33
|
|
34
34
|
void rb_exiv2_throw(const char *file, long unsigned int line, const char *fmt, ...) {
|
35
35
|
char* message;
|
data/lib/exiv2.hpp
CHANGED
@@ -43,6 +43,7 @@
|
|
43
43
|
#include <cstring>
|
44
44
|
#include <cassert>
|
45
45
|
|
46
|
+
#include <stdarg.h>
|
46
47
|
|
47
48
|
|
48
49
|
#include "ruby.h"
|
@@ -88,7 +89,7 @@ void rb_exiv2_throw(const char* file, long unsigned int line, const char *fmt, .
|
|
88
89
|
extern "C" {
|
89
90
|
#endif
|
90
91
|
void Init_exiv2(void);
|
91
|
-
extern VALUE mExiv2, cImage, cExif, cIptc, eError;
|
92
|
+
extern VALUE mExiv2, cImage, cExif, cTag, cIptc, eError;
|
92
93
|
|
93
94
|
#if defined(__cplusplus)
|
94
95
|
} /* extern "C" { */
|
data/lib/image.cpp
CHANGED
@@ -132,14 +132,53 @@ static VALUE exiv2_image_exif(VALUE self) {
|
|
132
132
|
__END
|
133
133
|
}
|
134
134
|
|
135
|
+
|
136
|
+
/*
|
137
|
+
* Dump thumbnail to file.
|
138
|
+
* @img.thumbnail("my_image")
|
139
|
+
*/
|
140
|
+
static VALUE exiv2_image_thumbnail(VALUE self, VALUE file_name) {
|
141
|
+
__BEGIN
|
142
|
+
Check_Type(file_name, T_STRING);
|
143
|
+
|
144
|
+
rbImage* image;
|
145
|
+
Data_Get_Struct(self, rbImage, image);
|
146
|
+
|
147
|
+
Exiv2::ExifData &exifData = image->image->exifData();
|
148
|
+
exifData.writeThumbnail(STR(file_name));
|
149
|
+
if(rb_block_given_p()) {
|
150
|
+
rb_yield(file_name);
|
151
|
+
}
|
152
|
+
return self;
|
153
|
+
__END
|
154
|
+
}
|
155
|
+
|
156
|
+
/*
|
157
|
+
* Set image thumbnail to contents of passed file
|
158
|
+
* @img.thumbnail = "my_image.jpg"
|
159
|
+
*/
|
160
|
+
static VALUE exiv2_image_thumbnail_set(VALUE self, VALUE file_name) {
|
161
|
+
__BEGIN
|
162
|
+
Check_Type(file_name, T_STRING);
|
163
|
+
|
164
|
+
rbImage* image;
|
165
|
+
Data_Get_Struct(self, rbImage, image);
|
166
|
+
|
167
|
+
Exiv2::ExifData &exifData = image->image->exifData();
|
168
|
+
exifData.setJpegThumbnail(STR(file_name));
|
169
|
+
return self;
|
170
|
+
__END
|
171
|
+
}
|
172
|
+
|
173
|
+
|
135
174
|
void Init_image() {
|
136
175
|
cImage = rb_define_class_under(mExiv2, "Image", rb_cObject);
|
137
176
|
rb_define_alloc_func(cImage, exiv2_image_s_allocate);
|
138
177
|
rb_define_method(cImage, "initialize", VALUEFUNC(exiv2_image_initialize), 1);
|
139
178
|
rb_define_method(cImage, "exif", VALUEFUNC(exiv2_image_exif), 0);
|
140
179
|
|
141
|
-
|
142
|
-
|
180
|
+
rb_define_method(cImage, "thumbnail", VALUEFUNC(exiv2_image_thumbnail), 1);
|
181
|
+
rb_define_method(cImage, "thumbnail=", VALUEFUNC(exiv2_image_thumbnail_set), 1);
|
143
182
|
|
144
183
|
rb_define_method(cImage, "save", VALUEFUNC(exiv2_image_save), 0);
|
145
184
|
rb_define_method(cImage, "clear", VALUEFUNC(exiv2_image_clear), 0);
|
data/test/image.rb
CHANGED
@@ -27,6 +27,9 @@ class ImageTest < Test::Unit::TestCase
|
|
27
27
|
assert @img = Exiv2::Image.new(image_file), "Image should be opened from IO::File"
|
28
28
|
assert_equal "FinePixS2Pro", @img.exif["Exif.Image.Model"]
|
29
29
|
assert_equal nil, @img.exif["zeze"]
|
30
|
+
assert_raise(Exiv2::Error, "Setting of invalid tag should raise an exception") do
|
31
|
+
@img.exif["zeze"] = "lala"
|
32
|
+
end
|
30
33
|
assert_equal 3024, @img.exif["Exif.Photo.PixelXDimension"]
|
31
34
|
end
|
32
35
|
end
|
@@ -125,4 +128,11 @@ class ImageTest < Test::Unit::TestCase
|
|
125
128
|
assert_equal 16, i
|
126
129
|
end
|
127
130
|
end
|
131
|
+
|
132
|
+
def __test_thumbnail
|
133
|
+
open_test_file "exiv2-fujifilm-finepix-s2pro.jpg" do |filename|
|
134
|
+
assert @img = Exiv2::Image.new(filename)
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
128
138
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-exiv2
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2006-11-
|
6
|
+
version: "0.4"
|
7
|
+
date: 2006-11-09 00:00:00 +03:00
|
8
8
|
summary: Exiv2 (exif image tags handling) library driver
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
25
25
|
platform: ruby
|
26
26
|
signing_key:
|
27
27
|
cert_chain:
|
28
|
+
post_install_message:
|
28
29
|
authors:
|
29
30
|
- Max Lapshin
|
30
31
|
files:
|