Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Exif/Discover fix #82

Merged
merged 2 commits into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions libraw/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ctypes import util

from libraw import errors
from libraw.callbacks import data_callback, exif_parser_callback, memory_callback, progress_callback
from libraw.callbacks import data_callback, memory_callback, progress_callback
from libraw.errors import c_error
from libraw.structs import libraw_data_t, libraw_decoder_info_t, libraw_processed_image_t

Expand Down Expand Up @@ -54,11 +54,6 @@ def __init__(self): # pragma: no cover
self.libraw_recycle_datastream.argtypes = [POINTER(libraw_data_t)]
self.libraw_recycle.argtypes = [POINTER(libraw_data_t)]
self.libraw_close.argtypes = [POINTER(libraw_data_t)]
self.libraw_set_exifparser_handler.argtypes = [
POINTER(libraw_data_t),
exif_parser_callback,
c_void_p,
]
self.libraw_set_memerror_handler.argtypes = [
POINTER(libraw_data_t),
memory_callback,
Expand Down
31 changes: 0 additions & 31 deletions libraw/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,6 @@

from ctypes import * # noqa

exif_parser_callback = CFUNCTYPE(
c_void_p, c_int, c_int, c_int, c_int, c_void_p
)
"""
Creates a callback for use by the EXIF parser.

.. sourcecode:: python

def exif_cb(context, tag, type, len, ord, ifp):
pass

cb = exif_parser_callback(exif_cb)

libraw.libraw_set_exifparser_handler(libraw_data, cb, data)

Your callback function should map to the LibRaw C callback definition below:

.. sourcecode:: c

typedef void (*exif_parser_callback) (
void *context, int tag, int type, int len, unsigned int ord, void *ifp
);


Args:
callback (function): The Python function to convert to a C callback.

Returns:
_ctypes.PyCFuncPtrType: A C callback.
"""

memory_callback = CFUNCTYPE(c_void_p, c_char_p, c_char_p)
"""
Creates a callback for use when there are memory errors in LibRaw.
Expand Down
11 changes: 8 additions & 3 deletions rawkit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os

from libraw.bindings import LibRaw
from libraw.errors import FileUnsupported


def discover(path):
Expand All @@ -26,9 +27,13 @@ def discover(path):
for root, _, files in os.walk(path):
for file_name in files:
file_path = os.path.join(root, file_name).encode('ascii')
if libraw.libraw_open_file(raw, file_path) == 0:
file_list.append(file_path)
libraw.libraw_recycle(raw)
try:
libraw.libraw_open_file(raw, file_path)
except FileUnsupported:
continue
finally:
libraw.libraw_recycle(raw)
file_list.append(file_path)

libraw.libraw_close(raw)
return file_list
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

from rawkit import util
from libraw.errors import FileUnsupported


@pytest.yield_fixture
Expand All @@ -17,7 +18,7 @@ def test_discover(libraw):
'rawkit.util.os.walk',
return_value=(('', None, ('foo.CR2', 'foo.jpg')),)
):
libraw.libraw_open_file.side_effect = [0, 1]
libraw.libraw_open_file.side_effect = [0, FileUnsupported()]
files = util.discover('')
assert files == ['foo.CR2'.encode('ascii')]

Expand Down