exifr 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGELOG +4 -1
  2. data/Rakefile +1 -1
  3. data/lib/jpeg.rb +1 -1
  4. data/lib/tiff.rb +54 -28
  5. data/tests/test_tiff.rb +20 -1
  6. metadata +3 -3
data/CHANGELOG CHANGED
@@ -1,5 +1,8 @@
1
+ EXIF Reader 0.10.3
2
+ * YAML friendly; can now safely (de)serialize
3
+
1
4
  EXIF Reader 0.10.2
2
- * bug fix (thanks to Alexander Staubo for providing me witb sample data);
5
+ * bug fix (thanks to Alexander Staubo for providing me with sample data);
3
6
  don't fail on out-of-range IFD offsets for Apple Aperture generated JPGs
4
7
 
5
8
  EXIF Reader 0.10.1
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task :default => :test
8
8
 
9
9
  spec = Gem::Specification.new do |s|
10
10
  s.name = 'exifr'
11
- s.version = '0.10.2'
11
+ s.version = '0.10.3'
12
12
  s.author = "R.W. van 't Veer"
13
13
  s.email = 'remco@remvee.net'
14
14
  s.homepage = 'http://exifr.rubyforge.org/'
@@ -35,7 +35,7 @@ module EXIFR
35
35
  !exif.nil?
36
36
  end
37
37
 
38
- # Dispath to EXIF. When no EXIF data is available but the +method+ does exist
38
+ # Dispatch to EXIF. When no EXIF data is available but the +method+ does exist
39
39
  # for EXIF data +nil+ will be returned.
40
40
  def method_missing(method, *args)
41
41
  super unless args.empty?
@@ -12,7 +12,7 @@ module EXIFR
12
12
  # == Orientation
13
13
  # The property <tt>:orientation</tt> describes the subject rotated and/or
14
14
  # mirrored in relation to the camera. It is translated to one of the following
15
- # modules:
15
+ # instances:
16
16
  # * TopLeftOrientation
17
17
  # * TopRightOrientation
18
18
  # * BottomRightOrientation
@@ -22,7 +22,7 @@ module EXIFR
22
22
  # * RightBottomOrientation
23
23
  # * LeftBottomOrientation
24
24
  #
25
- # These modules have two methods:
25
+ # These instances of Orientation have two methods:
26
26
  # * <tt>to_i</tt>; return the original integer
27
27
  # * <tt>transform_rmagick(image)</tt>; transforms the given RMagick::Image
28
28
  # to a viewable version
@@ -33,7 +33,7 @@ module EXIFR
33
33
  # EXIFR::TIFF.new('DSC_0218.TIF').model # => "NIKON D1X"
34
34
  # EXIFR::TIFF.new('DSC_0218.TIF').date_time # => Tue May 23 19:15:32 +0200 2006
35
35
  # EXIFR::TIFF.new('DSC_0218.TIF').exposure_time # => Rational(1, 100)
36
- # EXIFR::TIFF.new('DSC_0218.TIF').orientation # => EXIFR::TIFF::TopLeftOrientation
36
+ # EXIFR::TIFF.new('DSC_0218.TIF').orientation # => EXIFR::TIFF::Orientation
37
37
  class TIFF
38
38
  include Enumerable
39
39
 
@@ -241,28 +241,51 @@ module EXIFR
241
241
  end
242
242
  end
243
243
 
244
+ # The orientation of the image with respect to the rows and columns.
245
+ class Orientation
246
+ def initialize(value, type) # :nodoc:
247
+ @value, @type = value, type
248
+ end
249
+
250
+ # Field value.
251
+ def to_i
252
+ @value
253
+ end
254
+
255
+ # Rotate and/or flip for proper viewing.
256
+ def transform_rmagick(img)
257
+ case @type
258
+ when :TopRight : img.flop
259
+ when :BottomRight : img.rotate(180)
260
+ when :BottomLeft : img.flip
261
+ when :LeftTop : img.rotate(90).flop
262
+ when :RightTop : img.rotate(90)
263
+ when :RightBottom : img.rotate(270).flop
264
+ when :LeftBottom : img.rotate(270)
265
+ else
266
+ img
267
+ end
268
+ end
269
+
270
+ def ==(other) # :nodoc:
271
+ Orientation === other && to_i == other.to_i
272
+ end
273
+ end
274
+
244
275
  ORIENTATIONS = [] # :nodoc:
245
276
  [
246
277
  nil,
247
- [:TopLeft, 'img'],
248
- [:TopRight, 'img.flop'],
249
- [:BottomRight, 'img.rotate(180)'],
250
- [:BottomLeft, 'img.flip'],
251
- [:LeftTop, 'img.rotate(90).flop'],
252
- [:RightTop, 'img.rotate(90)'],
253
- [:RightBottom, 'img.rotate(270).flop'],
254
- [:LeftBottom, 'img.rotate(270)'],
255
- ].each_with_index do |tuple,index|
256
- next unless tuple
257
- name, rmagic_code = *tuple
258
-
259
- eval <<-EOS
260
- module #{name}Orientation
261
- def self.to_i; #{index}; end
262
- def self.transform_rmagick(img); #{rmagic_code}; end
263
- end
264
- ORIENTATIONS[#{index}] = #{name}Orientation
265
- EOS
278
+ :TopLeft,
279
+ :TopRight,
280
+ :BottomRight,
281
+ :BottomLeft,
282
+ :LeftTop,
283
+ :RightTop,
284
+ :RightBottom,
285
+ :LeftBottom,
286
+ ].each_with_index do |type,index|
287
+ next unless type
288
+ const_set("#{type}Orientation", ORIENTATIONS[index] = Orientation.new(index, type))
266
289
  end
267
290
 
268
291
  ADAPTERS = Hash.new { proc { |v| v } } # :nodoc:
@@ -278,21 +301,21 @@ module EXIFR
278
301
 
279
302
  # +file+ is a filename or an IO object.
280
303
  def initialize(file)
281
- @data = file.respond_to?(:read) ? file.read : File.open(file, 'rb') { |io| io.read }
304
+ data = file.respond_to?(:read) ? file.read : File.open(file, 'rb') { |io| io.read }
282
305
 
283
- class << @data
306
+ class << data
284
307
  attr_accessor :short, :long
285
308
  def readshort(pos); self[pos..(pos + 1)].unpack(@short)[0]; end
286
309
  def readlong(pos); self[pos..(pos + 3)].unpack(@long)[0]; end
287
310
  end
288
311
 
289
- case @data[0..1]
290
- when 'II'; @data.short, @data.long = 'v', 'V'
291
- when 'MM'; @data.short, @data.long = 'n', 'N'
312
+ case data[0..1]
313
+ when 'II'; data.short, data.long = 'v', 'V'
314
+ when 'MM'; data.short, data.long = 'n', 'N'
292
315
  else; raise 'no II or MM marker found'
293
316
  end
294
317
 
295
- @ifds = [IFD.new(@data)]
318
+ @ifds = [IFD.new(data)]
296
319
  while ifd = @ifds.last.next; @ifds << ifd; end
297
320
  end
298
321
 
@@ -384,6 +407,9 @@ module EXIFR
384
407
  IFD.new(@data, @offset_next) unless @offset_next == 0 || @offset_next >= @data.size
385
408
  end
386
409
 
410
+ def to_yaml_properties
411
+ '@fields'
412
+ end
387
413
  private
388
414
  def add_field(field)
389
415
  return unless tag = TAG_MAPPING[@type][field.tag]
@@ -64,7 +64,16 @@ class TestTIFF < Test::Unit::TestCase
64
64
  all_test_exifs.each do |fname|
65
65
  orientation = TIFF.new(fname).orientation
66
66
  if orientation
67
- assert_kind_of Module, orientation
67
+ assert [
68
+ TIFF::TopLeftOrientation,
69
+ TIFF::TopRightOrientation,
70
+ TIFF::BottomRightOrientation,
71
+ TIFF::BottomLeftOrientation,
72
+ TIFF::LeftTopOrientation,
73
+ TIFF::RightTopOrientation,
74
+ TIFF::RightBottomOrientation,
75
+ TIFF::LeftBottomOrientation
76
+ ].any? { |c| orientation == c }, 'not an orientation'
68
77
  assert orientation.respond_to?(:to_i)
69
78
  assert orientation.respond_to?(:transform_rmagick)
70
79
  tested += 1
@@ -117,4 +126,14 @@ class TestTIFF < Test::Unit::TestCase
117
126
  assert_not_nil @t[:f_number]
118
127
  end
119
128
  end
129
+
130
+ def test_yaml_dump_and_load
131
+ require 'yaml'
132
+
133
+ all_test_tiffs.each do |fname|
134
+ t = TIFF.new(fname)
135
+ y = YAML.dump(t)
136
+ assert_equal t.to_hash, YAML.load(y).to_hash
137
+ end
138
+ end
120
139
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: exifr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.10.2
7
- date: 2007-05-01 00:00:00 +02:00
6
+ version: 0.10.3
7
+ date: 2007-10-23 00:00:00 +02:00
8
8
  summary: EXIF Reader is a module to read EXIF from JPEG images.
9
9
  require_paths:
10
10
  - lib