Skip to content

Commit

Permalink
Return :arw as format for Sony ARW files (#164)
Browse files Browse the repository at this point in the history
Add detection for Sony ARW files and return :arw in the format property for those files.

Closes #159
  • Loading branch information
nitika080289 authored Sep 15, 2020
1 parent 3212b3d commit dbb5ab2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.24.0
* The TIFF parser will now return :arw as format for Sony ARW files insted of :tif so that the caller can decide whether it
wants to deal with RAW processing or not

## 0.23.1
* Updated gem exifr to fix problems related to jpeg files from Olympos microscopes, which often have bad thumbnail data

Expand Down
2 changes: 1 addition & 1 deletion lib/format_parser/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FormatParser
VERSION = '0.23.1'
VERSION = '0.24.0'
end
8 changes: 7 additions & 1 deletion lib/parsers/tiff_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def call(io)
h = exif_data.height || exif_data.pixel_y_dimension

FormatParser::Image.new(
format: :tif,
format: arw?(exif_data) ? :arw : :tif, # Specify format as arw for Sony ARW format images, else tif
width_px: w,
height_px: h,
display_width_px: exif_data.rotated? ? h : w,
Expand All @@ -43,5 +43,11 @@ def cr2?(io)
safe_read(io, 2) == 'CR'
end

# Similar to how exiftool determines the image type as ARW, we are implementing a check here
# https://github.com/exiftool/exiftool/blob/e969456372fbaf4b980fea8bb094d71033ac8bf7/lib/Image/ExifTool/Exif.pm#L929
def arw?(exif_data)
exif_data.compression == 6 && exif_data.new_subfile_type == 1 && exif_data.make == 'SONY'
end

FormatParser.register_parser new, natures: :image, formats: :tif
end
5 changes: 4 additions & 1 deletion spec/parsers/tiff_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@
expect(parsed.intrinsics[:exif]).not_to be_nil
end

it 'correctly extracts dimensions for a Sony ARW fixture' do
it 'parses Sony ARW fixture as arw format file' do
arw_path = fixtures_dir + '/ARW/RAW_SONY_ILCE-7RM2.ARW'

parsed = subject.call(File.open(arw_path, 'rb'))

expect(parsed).not_to be_nil
expect(parsed.nature).to eq(:image)
expect(parsed.format).to eq(:arw)

expect(parsed.width_px).to eq(7952)
expect(parsed.height_px).to eq(5304)
expect(parsed.intrinsics[:exif]).not_to be_nil
Expand Down

0 comments on commit dbb5ab2

Please sign in to comment.