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

Commit

Permalink
Support Libraw 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWhited committed Sep 20, 2018
1 parent 7f4706f commit 515a781
Show file tree
Hide file tree
Showing 4 changed files with 761 additions and 6 deletions.
9 changes: 5 additions & 4 deletions docs/source/index.rst
Expand Up @@ -48,7 +48,7 @@ Requirements
- Python

- CPython 2.7+
- CPython 3.4+
- CPython 3.5+
- PyPy 2.5+
- PyPy3 2.4+

Expand All @@ -57,15 +57,16 @@ Requirements
- LibRaw 0.16.x
- LibRaw 0.17.x
- LibRaw 0.18.x
- LibRaw 0.19.x

Installing rawkit
-----------------

First, you'll need to install LibRaw:

- `libraw` on Arch_
- `LibRaw` on Fedora_ 21+
- `libraw10` on Ubuntu_ Utopic+
- `LibRaw` on Fedora_ 21+ and EPEL 6
- `libraw-bin` on Ubuntu_ trusty+
- `libraw-bin` on Debian_ Jessie+

Now you can fetch rawkit from PyPi_:
Expand All @@ -76,7 +77,7 @@ Now you can fetch rawkit from PyPi_:

.. _Arch: https://www.archlinux.org/packages/extra/x86_64/libraw/
.. _Fedora: https://apps.fedoraproject.org/packages/LibRaw
.. _Ubuntu: http://packages.ubuntu.com/utopic/libraw10
.. _Ubuntu: https://packages.ubuntu.com/bionic/libraw-bin
.. _Debian: https://packages.debian.org/stable/graphics/libraw-bin
.. _PyPi: https://pypi.python.org/pypi/rawkit

Expand Down
13 changes: 11 additions & 2 deletions libraw/bindings.py
Expand Up @@ -19,6 +19,7 @@
from libraw import structs_16
from libraw import structs_17
from libraw import structs_18
from libraw import structs_19


class LibRaw(CDLL):
Expand All @@ -39,8 +40,10 @@ def __init__(self): # pragma: no cover
libraw = util.find_library('libraw')
if libraw is None:
# Attempt to guess manually (See #116)
shared_lib_ext = {'Linux':'.so', 'Darwin':'.dylib', 'Windows':'.dll'}
libraw = os.path.join(sys.prefix, 'lib', 'libraw' + shared_lib_ext[platform.system()])
shared_lib_ext = {'Linux': '.so',
'Darwin': '.dylib', 'Windows': '.dll'}
libraw = os.path.join(
sys.prefix, 'lib', 'libraw' + shared_lib_ext[platform.system()])

try:
if libraw is not None:
Expand All @@ -55,6 +58,7 @@ def __init__(self): # pragma: no cover
16: structs_16,
17: structs_17,
18: structs_18,
19: structs_19,
}[self.version_number[1]]
except KeyError:
raise ImportError(
Expand Down Expand Up @@ -89,6 +93,11 @@ 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
30 changes: 30 additions & 0 deletions libraw/callbacks.py
Expand Up @@ -93,3 +93,33 @@ def progress_cb(data, stage, iteration, expected):
Returns:
_ctypes.PyCFuncPtrType: A C callback.
"""

exif_parser_callback = CFUNCTYPE(
c_void_p, c_int, c_int, c_int, c_uint, c_void_p)
"""
A callback that will be called to alert you when EXIF data is parsed.
.. 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 defintion 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.
"""

0 comments on commit 515a781

Please sign in to comment.