Class: Exif

Inherits:
Object
  • Object
show all
Defined in:
ext/exif.c

Defined Under Namespace

Modules: ByteOrder, IFD Classes: Error, NotExifFormat

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](tagid) ⇒ Object



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'ext/exif.c', line 317

static VALUE
rb_exif_s_get_tag_description(VALUE klass, VALUE tagid)
{
	ExifTag tag;
	VALUE cdr;
	char buf[7];
	switch (TYPE(tagid)){
	  case T_FIXNUM:
	    tag = FIX2INT(tagid);
		if (!exif_tag_get_name(tag))
			rb_raise(eExifError, "invalid tag id: 0x%04x(%d)", 
			         FIX2INT(tagid), FIX2INT(tagid));
		break;
	  case T_STRING:
	    tag = exif_tag_from_string(RSTRING(tagid)->ptr);
		if (!tag || !exif_tag_get_name(tag)) {
			rb_raise(eExifError, "invalid tag: '%s'", RSTRING(tagid)->ptr);
		}
		break;
	  default:
	    rb_raise(rb_eTypeError, "wrong type of an argument");
		break;
	}
	memset(buf, 0, sizeof(buf));
	sprintf(buf, "0x%04x", tag);
	cdr = rb_ary_new();
	rb_ary_push(cdr, rb_str_new2(exif_tag_get_name(tag)));
	rb_ary_push(cdr, rb_str_new2(exif_tag_get_description(tag)));
	rb_ary_push(cdr, rb_str_new2(buf));
	return rb_assoc_new(rb_str_new2(exif_tag_get_title(tag)), cdr);
}

.new(*args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/exif.c', line 47

static VALUE
rb_exif_s_new(int argc, VALUE *argv, VALUE klass)
{
	VALUE obj;
	Exif *exif;
	exif = ALLOC(Exif);
	exif->ed = NULL;
	exif->ifd = IFD_RB_DEFAULT;
	obj =  Data_Wrap_Struct(klass, 0, rb_exif_free, exif);
	rb_obj_call_init(obj, argc, argv);
	return obj;
}

Instance Method Details

#[](tagid) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'ext/exif.c', line 211

static VALUE
rb_exif_get_tag(VALUE obj, VALUE tagid)
{
	Exif *exif;
	ExifTag tag;
	ExifEntry *e;
	const char *found;
	int i;
	char value[1024];

	Get_Exif(obj, exif);
	switch (TYPE(tagid)) {
	  case T_STRING:
		tag = exif_tag_from_string(RSTRING(tagid)->ptr);
		if (!tag){
			rb_raise(eExifError, "invalid tag: '%s'", RSTRING(tagid)->ptr);
		}
		break;
	  case T_FIXNUM:
		tag = exif_tag_from_tagid(FIX2INT(tagid));
		if (!tag){
			rb_raise(eExifError, "invalid tag: 0x%04x", tagid);
		}
		break;
	  default:
		rb_raise(rb_eTypeError, "wrong type of arguments");
		break;
	}
	if (exif->ifd >= 0){
		e = exif_content_get_entry(exif->ed->ifd[exif->ifd], tag);
		if (!e){
			rb_raise(eExifTagNotFound, 
			"IFD '%s' does not contain tag '%s'(0x%04x)",
			exif_ifd_get_name(exif->ifd), exif_tag_get_title(tag), tag);
		}
		return rb_str_new2(exif_entry_get_value(e, value, sizeof(value)));
	}
	for (i = 0; i < EXIF_IFD_COUNT; i++){
		e = exif_content_get_entry(exif->ed->ifd[i], tag);
		if (e)
			break;
	}
	found = exif_entry_get_value(e, value, sizeof(value));
	return found ? rb_str_new2(found) : Qnil;
}

#[]=(tagid, val) ⇒ Object

exif_entry_dump(e, 1);



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'ext/exif.c', line 266

static VALUE
rb_exif_set_tag(VALUE obj, VALUE tagid, VALUE val)
{
	Exif *exif;
	ExifTag tag;
	ExifEntry *e;
	
	rb_raise(rb_eNotImpError, "soryy, not yet implemented");
	Check_Type(tagid, T_STRING);
	Check_Type(val, T_STRING);
	Get_Exif(obj, exif);
	tag = exif_tag_from_string(RSTRING(tagid)->ptr);
	if (!tag || !exif_tag_get_name(tag)){
		rb_raise(eExifError, "invalid tag: '%s'", RSTRING(tagid)->ptr);
	}
	e = exif_content_get_entry(exif->ed->ifd[exif->ifd], tag);
	if (!e){
		e = exif_entry_new();
		exif_content_add_entry(exif->ed->ifd[exif->ifd], e);
		exif_entry_initialize(e, tag);
	}
	rb_exif_set_tag_0(exif->ed, e, val);
	return obj;
}

#byte_orderObject



115
116
117
118
119
120
121
# File 'ext/exif.c', line 115

static VALUE
rb_exif_get_byte_order(VALUE obj)
{
	Exif *exif;
	Get_Exif(obj, exif);
	return FIX2INT(exif_data_get_byte_order(exif->ed));
}

#byte_order=(byteorder) ⇒ Object



123
124
125
126
127
128
129
130
# File 'ext/exif.c', line 123

static VALUE
rb_exif_set_byte_order(VALUE obj, VALUE byteorder)
{
	Exif *exif;
	Get_Exif(obj, exif);
	exif_data_set_byte_order(exif->ed, FIX2INT(byteorder));
	return obj;
}

#data=(str) ⇒ Object Also known as: <<



106
107
108
109
110
111
112
113
# File 'ext/exif.c', line 106

static VALUE
rb_exif_set_data(VALUE obj, VALUE str)
{
	Exif *exif;
	Data_Get_Struct(obj, Exif, exif);
	rb_exif_data_new_from_data(exif->ed, str);
	return obj;
}

#each_entry(*args) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'ext/exif.c', line 153

static VALUE
rb_exif_each(int argc, VALUE *argv, VALUE obj)
{
	Exif *exif;
	VALUE use_tag_id;
	unsigned char ids = 0;
	if (rb_scan_args(argc, argv, "01", &use_tag_id) == 1){
		ids = FIX2UINT(use_tag_id);	
	}
	Get_Exif(obj, exif);
	exif_data_foreach_content(exif->ed, rb_exif_data_foreach_content_func, &ids);
	return obj;
}

#extract_thumbnail(dest) ⇒ Object Also known as: thumbnail



349
350
351
352
353
354
355
356
357
358
# File 'ext/exif.c', line 349

static VALUE
rb_exif_extract_thumbnail(VALUE obj, VALUE dest)
{
	Exif *exif;
	Get_Exif(obj, exif);
	if (!exif->ed->data)
		rb_raise(eExifThumbnailNotFound, "thumbnail not found");
	rb_funcall(dest, rb_intern("<<"), 1, rb_str_new((char *)exif->ed->data, exif->ed->size));
	return obj;
}

#ifdObject



196
197
198
199
200
201
202
203
204
205
206
# File 'ext/exif.c', line 196

static VALUE
rb_exif_get_ifd(VALUE obj)
{
	Exif *exif;
	const char *name;
	Get_Exif(obj, exif);
	name = exif_ifd_get_name(exif->ifd);
	if (!name)
		return Qnil;
	return rb_str_new2(name);
}

#ifd=(ifd) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/exif.c', line 169

static VALUE
rb_exif_set_ifd(VALUE obj, VALUE ifd)
{
	Exif *exif;
	int i;
	Get_Exif(obj, exif);
	switch(TYPE(ifd)){
	  case T_FIXNUM:
		i = FIX2INT(ifd);
		if (i < IFD_RB_DEFAULT || i > EXIF_IFD_INTEROPERABILITY){
			rb_raise(rb_eRuntimeError, "wrong constant");
		}
		break;
	  case T_STRING:
		i = exif_ifd_from_string(RSTRING(ifd)->ptr);
		if (i == -1){
			rb_raise(rb_eRuntimeError, "unknown IFD: '%s'", RSTRING(ifd)->ptr);
		}
		break;
	  default:
		rb_raise(rb_eTypeError, "wrong type of an argument");
		break;
	}
	exif->ifd = i;
	return obj;
}

#list_tags(ifd) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/exif.c', line 290

static VALUE
rb_exif_list_tags_at_ifd(VALUE obj, VALUE ifd)
{
	Exif *exif;
	unsigned int tag;
	int i;
	const char *name;
	char buf[7];
	VALUE ret = rb_ary_new();
	i = FIX2INT(ifd);
	if (i < EXIF_IFD_0 || i > EXIF_IFD_INTEROPERABILITY){
			rb_raise(rb_eRuntimeError, "wrong constant");
	}
	Get_Exif(obj, exif);
	for (tag = 0; tag < 0xffff; tag++) {
		name = exif_tag_get_title(tag);
		if (!name)
			continue;
		if (exif_content_get_entry(exif->ed->ifd[i], tag)){
			memset(buf, 0, sizeof(buf));
			sprintf(buf, "0x%04x", tag);
			rb_ary_push(ret, rb_assoc_new(rb_str_new2(name), rb_str_new2(buf)));
		}
	}
	return ret;
}

#thumbnail=(src) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'ext/exif.c', line 360

static VALUE
rb_exif_set_thumbnail(VALUE obj, VALUE src)
{
	Exif *exif;
	Get_Exif(obj, exif);
	if (exif->ed->data){
		free(exif->ed->data);
		exif->ed->data = NULL;
		exif->ed->size = 0;
	}
	Check_Type(src, T_STRING);
	exif->ed->size = RSTRING(src)->len;
	exif->ed->data = xmalloc(sizeof(char)*exif->ed->size);
	MEMMOVE(exif->ed->data, RSTRING(src)->ptr, char, exif->ed->size);
	return obj;
}