[Python-modules-commits] [rawkit] 01/02: New upstream version 0.6.0

Antoine Beaupré anarcat at moszumanska.debian.org
Sat Dec 30 17:05:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

anarcat pushed a commit to branch master
in repository rawkit.

commit 3ed61a4899f37d5e20aecdabd4ba8042b1d6b058
Author: Antoine Beaupré <anarcat at debian.org>
Date:   Sat Dec 30 12:00:42 2017 -0500

    New upstream version 0.6.0
---
 .coveragerc                          |  33 ++
 .pre-commit-config.yaml              |  14 +
 LICENSE                              |  21 +
 MANIFEST.in                          |   8 +
 Makefile                             |  76 ++++
 PKG-INFO                             |  59 +++
 README.rst                           |  36 ++
 libraw/__init__.py                   |  13 +
 libraw/bindings.py                   | 208 +++++++++
 libraw/callbacks.py                  |  95 +++++
 libraw/errors.py                     | 171 ++++++++
 libraw/structs_16.py                 | 248 +++++++++++
 libraw/structs_17.py                 | 378 +++++++++++++++++
 libraw/structs_18.py                 | 622 +++++++++++++++++++++++++++
 rawkit.egg-info/PKG-INFO             |  59 +++
 rawkit.egg-info/SOURCES.txt          |  34 ++
 rawkit.egg-info/dependency_links.txt |   1 +
 rawkit.egg-info/requires.txt         |   3 +
 rawkit.egg-info/top_level.txt        |   2 +
 rawkit/__init__.py                   |  24 ++
 rawkit/errors.py                     |  23 +
 rawkit/metadata.py                   |  32 ++
 rawkit/options.py                    | 794 +++++++++++++++++++++++++++++++++++
 rawkit/raw.py                        | 458 ++++++++++++++++++++
 rawkit/util.py                       |  56 +++
 requirements-dev.txt                 |   8 +
 setup.cfg                            |   7 +
 setup.py                             |  39 ++
 tests/__init__.py                    |   0
 tests/unit/__init__.py               |   0
 tests/unit/bindings_test.py          | 107 +++++
 tests/unit/options_test.py           | 150 +++++++
 tests/unit/raw_test.py               | 261 ++++++++++++
 tests/unit/util_test.py              |  29 ++
 tox.ini                              |  13 +
 35 files changed, 4082 insertions(+)

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..3ec3cc0
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,33 @@
+# Coveragerc file stolen from pre-commit
+
+[run]
+branch = True
+source =
+    .
+omit =
+    .tox/*
+    /usr/*
+    */tmp*
+    setup.py
+    # Don't complain if non-runnable code isn't run
+    */__main__.py
+    tests/stress/*
+
+[report]
+exclude_lines =
+    # Have to re-enable the standard pragma
+    \#\s*pragma: no cover
+
+    # Don't complain if tests don't hit defensive assertion code:
+    ^\s*raise AssertionError\b
+    ^\s*raise NotImplementedError\b
+    ^\s*return NotImplemented\b
+    ^\s*raise$
+
+    # Don't complain if non-runnable code isn't run:
+    ^if __name__ == ['"]__main__['"]:$
+
+[html]
+directory = coverage-html
+
+# vim:ft=dosini
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..51570fc
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,14 @@
+-   repo: git://github.com/pre-commit/pre-commit-hooks
+    sha: v0.4.2
+    hooks:
+      -   id: autopep8-wrapper
+          args: ['-i']
+          exclude: 'docs/source/_themes/'
+      -   id: check-json
+      -   id: check-yaml
+      -   id: name-tests-test
+      -   id: debug-statements
+      -   id: end-of-file-fixer
+      -   id: trailing-whitespace
+      -   id: check-case-conflict
+      -   id: check-merge-conflict
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d9237e5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright © 2015 Cameron Paul and Sam Whited
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..c9d3bea
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,8 @@
+include LICENSE
+include *.rst
+include *.txt
+include *.yaml
+include .coveragerc
+include Makefile
+include tox.ini
+recursive-include tests *.py
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..86d31ca
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,76 @@
+REBUILD_FLAG =
+VENV=env
+BIN=$(VENV)/bin
+ACTIVATE=. $(BIN)/activate
+APIDOCS=docs/source/api
+DOCSRC=$(APIDOCS)/modules.rst docs/source/* docs/source/_static/*
+
+.PHONY: all
+all: test build pre-commit
+
+.PHONY: pre-commit
+pre-commit: .git/hooks/pre-commit
+.git/hooks/pre-commit: .pre-commit-config.yaml $(VENV)
+	$(ACTIVATE); pre-commit install
+
+$(VENV): $(VENV)/bin/activate
+
+$(VENV)/bin/activate: requirements-dev.txt
+	test -d $(VENV) || virtualenv -p python3 $(VENV)
+	$(ACTIVATE); pip install -r requirements-dev.txt
+	touch $(BIN)/activate
+
+.PHONY: tox
+tox: $(VENV)
+	$(ACTIVATE); pip install tox
+
+.PHONY: test
+test: $(VENV) tox
+	$(ACTIVATE); tox $(REBUILD_FLAG)
+
+.PHONY: stress-test
+stress-test: $(VENV)
+	$(ACTIVATE); INPUT=$(INPUT) tox -c tox-stress.ini $(REBUILD_FLAG)
+
+dist/*.whl: setup.py rawkit/*.py
+	python setup.py bdist_wheel
+
+dist/*.tar.gz: setup.py rawkit/*.py
+	python setup.py sdist bdist
+
+.PHONY: wheel
+wheel: dist/*.whl
+
+.PHONY: dist
+dist: dist/*.tar.gz
+
+.PHONY: build
+build: pre-commit wheel dist
+
+.PHONY: upload
+upload: clean
+	$(ACTIVATE) python setup.py sdist bdist bdist_wheel upload
+
+.PHONY: clean
+clean:
+	-$(ACTIVATE) 2>/dev/null; $(MAKE) -C docs $@
+	find . -iname '*.pyc' | xargs rm -f
+	find . -iname '__pycache__' -type d | xargs rm -rf
+	rm -rf .tox
+	rm -rf build
+	rm -rf dist
+	rm -rf $(VENV)
+
+.PHONY: docs
+docs: epub html $(VENV)
+
+.PHONY: html
+html: $(DOCSRC) $(VENV)
+	$(ACTIVATE); $(MAKE) -C docs $@
+
+.PHONY: epub
+epub: $(DOCSRC) $(VENV)
+	$(ACTIVATE); $(MAKE) -C docs $@
+
+$(APIDOCS)/modules.rst: rawkit/*.py libraw/*.py $(VENV)
+	$(ACTIVATE); sphinx-apidoc -f -E -M -o $(APIDOCS) -H Contents . docs tests setup.py
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..c16ddc8
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,59 @@
+Metadata-Version: 1.1
+Name: rawkit
+Version: 0.6.0
+Summary: CTypes based LibRaw bindings
+Home-page: https://rawkit.readthedocs.org
+Author: Cameron Paul, Sam Whited
+Author-email: sam at samwhited.com
+License: UNKNOWN
+Description: rawkit
+        ======
+        
+        .. image:: https://badge.fury.io/py/rawkit.svg?
+          :alt: Package Status
+          :target: https://pypi.python.org/pypi/rawkit
+        
+        .. image:: https://readthedocs.org/projects/rawkit/badge/?version=latest
+           :alt: Docs Status
+           :target: https://rawkit.readthedocs.org/en/latest/
+        
+        .. image:: https://secure.travis-ci.org/photoshell/rawkit.svg?branch=master
+           :alt: Build Status
+           :target: https://travis-ci.org/photoshell/rawkit
+        
+        .. image:: https://img.shields.io/coveralls/photoshell/rawkit.svg?style=flat
+           :alt: Test Coverage Status
+           :target: https://coveralls.io/r/photoshell/rawkit
+        
+        ``rawkit`` (pronounced `rocket`) is a ctypes-based LibRaw_ binding for
+        Python inspired by the Wand_ API.
+        
+        .. sourcecode:: python
+        
+            from rawkit.raw import Raw
+            from rawkit.options import WhiteBalance
+        
+            with Raw(filename='some/raw/image.CR2') as raw:
+              raw.options.white_balance = WhiteBalance(camera=False, auto=True)
+              raw.save(filename='some/destination/image.ppm')
+        
+        for more info, see the docs_
+        
+        .. _LibRaw: http://www.libraw.org/
+        .. _Wand: http://docs.wand-py.org
+        .. _docs: https://rawkit.readthedocs.org/en/latest/
+        
+Keywords: encoding,images,photography,libraw,raw,photos
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: Implementation :: PyPy
+Classifier: Development Status :: 3 - Alpha
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: OS Independent
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..9d1b4e3
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,36 @@
+rawkit
+======
+
+.. image:: https://badge.fury.io/py/rawkit.svg?
+  :alt: Package Status
+  :target: https://pypi.python.org/pypi/rawkit
+
+.. image:: https://readthedocs.org/projects/rawkit/badge/?version=latest
+   :alt: Docs Status
+   :target: https://rawkit.readthedocs.org/en/latest/
+
+.. image:: https://secure.travis-ci.org/photoshell/rawkit.svg?branch=master
+   :alt: Build Status
+   :target: https://travis-ci.org/photoshell/rawkit
+
+.. image:: https://img.shields.io/coveralls/photoshell/rawkit.svg?style=flat
+   :alt: Test Coverage Status
+   :target: https://coveralls.io/r/photoshell/rawkit
+
+``rawkit`` (pronounced `rocket`) is a ctypes-based LibRaw_ binding for
+Python inspired by the Wand_ API.
+
+.. sourcecode:: python
+
+    from rawkit.raw import Raw
+    from rawkit.options import WhiteBalance
+
+    with Raw(filename='some/raw/image.CR2') as raw:
+      raw.options.white_balance = WhiteBalance(camera=False, auto=True)
+      raw.save(filename='some/destination/image.ppm')
+
+for more info, see the docs_
+
+.. _LibRaw: http://www.libraw.org/
+.. _Wand: http://docs.wand-py.org
+.. _docs: https://rawkit.readthedocs.org/en/latest/
diff --git a/libraw/__init__.py b/libraw/__init__.py
new file mode 100644
index 0000000..78f3160
--- /dev/null
+++ b/libraw/__init__.py
@@ -0,0 +1,13 @@
+"""Introduction
+~~~~~~~~~~~~~~~
+
+The :mod:`libraw` package contains low-level CTYPES_ based APIs for interfacing
+with LibRaw_ by LibRaw, LLC.
+
+While this library can be used on its own to access the full functionality of
+LibRaw and develop raw photos, we recommend using the higher-level :mod:`rawkit`
+module, which provides a more pythonic interface to LibRaw.
+
+.. _CTYPES: https://docs.python.org/3/library/ctypes.html
+.. _LibRaw: http://www.libraw.org
+"""
diff --git a/libraw/bindings.py b/libraw/bindings.py
new file mode 100644
index 0000000..fbd2e3c
--- /dev/null
+++ b/libraw/bindings.py
@@ -0,0 +1,208 @@
+""":mod:`libraw.bindings` --- Low-level LibRaw bindings
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The :class:`libraw.bindings` module handles linking against the LibRaw binary.
+"""
+
+from ctypes import *  # noqa
+from ctypes import util
+
+from libraw import errors
+from libraw.callbacks import data_callback
+from libraw.callbacks import memory_callback
+from libraw.callbacks import progress_callback
+from libraw.errors import c_error
+from libraw import structs_16
+from libraw import structs_17
+from libraw import structs_18
+
+
+class LibRaw(CDLL):
+
+    """
+    A :class:`ctypes.CDLL` that links against `libraw.so` (or the equivalent on
+    your platform).
+
+    Raises:
+        ImportError: If LibRaw cannot be found on your system, or linking
+                     fails.
+    """
+
+    def __init__(self):  # pragma: no cover
+        libraw = util.find_library('raw')
+        try:
+            if libraw is not None:
+                super(LibRaw, self).__init__(libraw)
+            else:
+                raise ImportError
+        except (ImportError, AttributeError, OSError, IOError):
+            raise ImportError('Cannot find LibRaw on your system!')
+
+        try:
+            structs = {
+                16: structs_16,
+                17: structs_17,
+                18: structs_18,
+            }[self.version_number[1]]
+        except KeyError:
+            raise ImportError(
+                'Unsupported Libraw version: %s.%s.%s.' % self.version_number
+            )
+
+        libraw_data_t = structs.libraw_data_t
+        libraw_decoder_info_t = structs.libraw_decoder_info_t
+        libraw_processed_image_t = structs.libraw_processed_image_t
+
+        # Define arg types
+
+        self.libraw_init.argtypes = [c_int]
+        # enum LibRaw_progress
+        self.libraw_strprogress.argtypes = [c_int]
+        self.libraw_unpack_function_name.argtypes = [POINTER(libraw_data_t)]
+
+        self.libraw_subtract_black.argtypes = [POINTER(libraw_data_t)]
+        self.libraw_open_file.argtypes = [POINTER(libraw_data_t), c_char_p]
+        self.libraw_open_file_ex.argtypes = [
+            POINTER(libraw_data_t),
+            c_char_p,
+            c_int64
+        ]
+        self.libraw_open_buffer.argtypes = [
+            POINTER(libraw_data_t),
+            c_void_p,
+            c_int64
+        ]
+        self.libraw_unpack.argtypes = [POINTER(libraw_data_t)]
+        self.libraw_unpack_thumb.argtypes = [POINTER(libraw_data_t)]
+        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_memerror_handler.argtypes = [
+            POINTER(libraw_data_t),
+            memory_callback,
+            c_void_p,
+        ]
+        self.libraw_set_dataerror_handler.argtypes = [
+            POINTER(libraw_data_t),
+            data_callback,
+            c_void_p,
+        ]
+        self.libraw_set_progress_handler.argtypes = [
+            POINTER(libraw_data_t),
+            progress_callback,
+            c_void_p,
+        ]
+        self.libraw_adjust_sizes_info_only.argtypes = [
+            POINTER(libraw_data_t)
+        ]
+        self.libraw_dcraw_ppm_tiff_writer.argtypes = [
+            POINTER(libraw_data_t),
+            c_char_p
+        ]
+        self.libraw_dcraw_thumb_writer.argtypes = [
+            POINTER(libraw_data_t),
+            c_char_p
+        ]
+        self.libraw_dcraw_process.argtypes = [POINTER(libraw_data_t)]
+        self.libraw_dcraw_make_mem_image.argtypes = [
+            POINTER(libraw_data_t),
+            POINTER(c_int)
+        ]
+        self.libraw_dcraw_make_mem_thumb.argtypes = [
+            POINTER(libraw_data_t),
+            POINTER(c_int)
+        ]
+        self.libraw_dcraw_clear_mem.argtypes = [
+            POINTER(libraw_processed_image_t)
+        ]
+        self.libraw_raw2image.argtypes = [POINTER(libraw_data_t)]
+        self.libraw_free_image.argtypes = [POINTER(libraw_data_t)]
+        self.libraw_get_decoder_info.argtypes = [
+            POINTER(libraw_data_t),
+            POINTER(libraw_decoder_info_t)
+        ]
+        self.libraw_COLOR.argtypes = [
+            POINTER(libraw_data_t),
+            c_int,
+            c_int
+        ]
+
+        # Define return types
+
+        self.libraw_init.restype = POINTER(libraw_data_t)
+        self.libraw_version.restype = c_char_p
+        self.libraw_strprogress.restype = c_char_p
+        self.libraw_versionNumber.restype = c_int
+        self.libraw_cameraCount.restype = c_int
+        self.libraw_cameraList.restype = POINTER(
+            c_char_p * self.libraw_cameraCount()
+        )
+        self.libraw_unpack_function_name.restype = c_char_p
+        self.libraw_subtract_black.restype = POINTER(libraw_data_t)
+        self.libraw_open_file.restype = c_error
+        self.libraw_open_file_ex.restype = c_error
+        self.libraw_open_buffer.restype = c_error
+        self.libraw_unpack.restype = c_error
+        self.libraw_unpack_thumb.restype = c_error
+        self.libraw_adjust_sizes_info_only.restype = c_error
+        self.libraw_dcraw_ppm_tiff_writer.restype = c_error
+        self.libraw_dcraw_thumb_writer.restype = c_error
+        self.libraw_dcraw_process.restype = c_error
+        self.libraw_dcraw_make_mem_image.restype = POINTER(
+            libraw_processed_image_t)
+        self.libraw_dcraw_make_mem_thumb.restype = POINTER(
+            libraw_processed_image_t)
+        self.libraw_raw2image.restype = c_error
+        self.libraw_get_decoder_info.restype = c_error
+        self.libraw_COLOR.restype = c_int
+
+        # Some special Windows-only garbage:
+
+        try:
+            self.libraw_open_wfile.argtypes = [
+                POINTER(libraw_data_t),
+                c_wchar_p
+            ]
+            self.libraw_open_wfile_ex.argtypes = [
+                POINTER(libraw_data_t),
+                c_wchar_p,
+                c_int64
+            ]
+            self.libraw_open_wfile.restype = c_error
+            self.libraw_open_wfile_ex.restype = c_error
+        except AttributeError:
+            pass
+
+    @property
+    def version_number(self):
+        """
+        A numeric representation of the version of LibRaw which we have linked
+        against in ``(Major, Minor, Patch)`` form. eg. ::
+
+            (0, 16, 1)
+
+        Returns:
+            3 tuple: The version number
+        """
+        v = self.libraw_versionNumber()
+        return ((v >> 16) & 0x0000ff, (v >> 8) & 0x0000ff, v & 0x0000ff)
+
+    @property
+    def version(self):
+        """
+        A string representation of the version of LibRaw which we have linked
+        against. eg. ::
+
+            "0.16.1-Release"
+
+        Returns:
+            str: The version
+        """
+        return self.libraw_version().decode('utf-8')
+
+    def __getitem__(self, name):
+        func = super(LibRaw, self).__getitem__(name)
+
+        func.errcheck = errors.check_call
+
+        return func
diff --git a/libraw/callbacks.py b/libraw/callbacks.py
new file mode 100644
index 0000000..7ab4215
--- /dev/null
+++ b/libraw/callbacks.py
@@ -0,0 +1,95 @@
+""":mod:`libraw.callbacks` --- LibRaw callback definitions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Warning:
+
+    You will need to keep a reference to your callback functions for as long as
+    you want to call them from C code, otherwise they may be garbage collected
+    and lead to a segmentation fault.
+"""
+
+from ctypes import *  # noqa
+
+memory_callback = CFUNCTYPE(c_void_p, c_char_p, c_char_p)
+"""
+Creates a callback for use when there are memory errors in LibRaw.
+
+.. sourcecode:: python
+
+    def memory_cb(data, file, where):
+        pass
+
+    cb = memory_callback(memory_cb)
+
+    libraw.libraw_set_memerror_handler(libraw_data, cb, data)
+
+Your callback function should map to the LibRaw C callback definition below:
+
+.. sourcecode:: c
+
+    typedef void (*memory_callback) (
+        void *data, const char *file, const char *where
+    );
+
+Args:
+    callback (function): The Python function to convert to a C callback.
+
+Returns:
+    _ctypes.PyCFuncPtrType: A C callback.
+"""
+
+data_callback = CFUNCTYPE(c_void_p, c_char_p, c_int)
+"""
+A callback for use when there are data errors in LibRaw.
+
+.. sourcecode:: python
+
+    def data_cb(data, file, offset):
+        pass
+
+    cb = data_callback(data_cb)
+
+    libraw.libraw_set_dataerror_handler(libraw_data, cb, data)
+
+Your callback function should map to the LibRaw C callback definition below:
+
+.. sourcecode:: c
+
+    typedef void (*data_callback) (
+        void *data, const char *file, const int offset
+    );
+
+Args:
+    callback (function): The Python function to convert to a C callback.
+
+Returns:
+    _ctypes.PyCFuncPtrType: A C callback.
+"""
+
+progress_callback = CFUNCTYPE(c_void_p, c_int, c_int, c_int)
+"""
+A callback that will be called to alert you to the stages of image processing.
+
+.. sourcecode:: python
+
+    def progress_cb(data, stage, iteration, expected):
+        pass
+
+    cb = progress_callback(progress_cb)
+
+    libraw.libraw_set_progress_handler(libraw_data, cb, data)
+
+Your callback function should map to the LibRaw C callback definition below:
+
+.. sourcecode:: c
+
+    typedef void (*progress_callback) (
+        void *data, enum LibRaw_progress stage, int iterationa, int expected
+    );
+
+Args:
+    callback (function): The Python function to convert to a C callback.
+
+Returns:
+    _ctypes.PyCFuncPtrType: A C callback.
+"""
diff --git a/libraw/errors.py b/libraw/errors.py
new file mode 100644
index 0000000..84e37e0
--- /dev/null
+++ b/libraw/errors.py
@@ -0,0 +1,171 @@
+""":mod:`libraw.errors` --- Pythonic error handling for LibRaw
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"""
+
+from ctypes import c_int
+
+
+class c_error(c_int):
+
+    """
+    An error type for LibRaw (since LibRaw errors are ints and you can't
+    distinguish between functions that return an error and functions that
+    return an int that doesn't code for an error).
+    """
+
+
+class LibRawError(Exception):
+
+    """
+    A base exception class from which all other exceptions that originate in
+    LibRaw inherit.
+    """
+
+
+class UnspecifiedError(LibRawError):
+
+    """
+    Something bad happened, but we don't know what.
+    """
+
+
+class FileUnsupported(LibRawError):
+
+    """
+    The file is not a raw file or is from an unsupported camera.
+    """
+
+
+class RequestForNonexistentImage(LibRawError):
+
+    """
+    The image file directory in the raw file which you are trying to access
+    does not contain an image.
+    """
+
+
+class OutOfOrderCall(LibRawError):
+
+    """
+    A LibRaw function depends on another function being called first and was
+    invoked out of order.
+    """
+
+
+class NoThumbnail(LibRawError):
+
+    """
+    The raw file does not contain a thumbnail.
+    """
+
+
+class UnsupportedThumbnail(LibRawError):
+
+    """
+    The thumbnail format is not supported.
+    """
+
+
+class InputClosed(LibRawError):
+
+    """
+    There is no input stream, or the input stream has been closed.
+    """
+
+
+class InsufficientMemory(LibRawError):
+
+    """
+    Memory allocation failed.
+    """
+
+
+class DataError(LibRawError):
+
+    """
+    Data unpacking failed.
+    """
+
+
+class CanceledByCallback(LibRawError):
+
+    """
+    Image processing was canceled because the progress callback requested it.
+    """
+
+
+class BadCrop(LibRawError):
+
+    """
+    The cropping coordinates specified are invalid (eg. the top left corner of
+    the cropping rectangle is outside the image).
+    """
+
+
+def check_call(exit_code, func, arguments):
+    """
+    Throws a Python error which corresponds to the given LibRaw exit code.
+
+    Args:
+        exit_code (int): An exit code returned by a LibRaw function.
+
+    Raises:
+        UnspecifiedError: We're not sure what happened.
+        FileUnsupported: The file is not a raw file that we recognize.
+        RequestForNonexistentImage: The given IFD does not contain an image.
+        OutOfOrderCall: Something was called out of order (eg. before data was
+                        unpacked)
+        NoThumbnail: The image does not have a thumbnail.
+        UnsupportedThumbnail: The embedded thumbnail format is unsupported.
+        InputClosed: The input stream has been closed.
+        InsufficientMemory: We're out of memory.
+        DataError: The unpacking step failed.
+        IOError: Reading was interrupted (or the file is corrupt).
+        CanceledByCallback: A callback canceled the operation.
+        BadCrop: The crop range was invalid.
+    """
+
+    if func.restype is c_error:
+        raise_if_error(exit_code.value)
+
+    return exit_code
+
+
+def raise_if_error(error_code):
+    """
+    :func:`raise_if_error` raises a meaningful exception that corresponds to the
+    given LibRaw integer return value.
+
+    Args:
+        error_code (int): An exit code returned by a LibRaw function.
+
+    Raises:
+        UnspecifiedError: We're not sure what happened.
+        FileUnsupported: The file is not a raw file that we recognize.
+        RequestForNonexistentImage: The given IFD does not contain an image.
+        OutOfOrderCall: Something was called out of order (eg. before data was
+                        unpacked)
+        NoThumbnail: The image does not have a thumbnail.
+        UnsupportedThumbnail: The embedded thumbnail format is unsupported.
+        InputClosed: The input stream has been closed.
+        InsufficientMemory: We're out of memory.
+        DataError: The unpacking step failed.
+        IOError: Reading was interrupted (or the file is corrupt).
+        CanceledByCallback: A callback canceled the operation.
+        BadCrop: The crop range was invalid.
+    """
+    if error_code != 0:
+        raise {
+            -1: UnspecifiedError,
+            -2: FileUnsupported,
+            -3: RequestForNonexistentImage,
+            -4: OutOfOrderCall,
+            -5: NoThumbnail,
+            -6: UnsupportedThumbnail,
+            -7: InputClosed,
+            -100007: InsufficientMemory,
+            -100008: DataError,
+            -100009: IOError,
+            -100010: CanceledByCallback,
+            -100011: BadCrop
+        }[error_code]
diff --git a/libraw/structs_16.py b/libraw/structs_16.py
new file mode 100644
index 0000000..38157ef
--- /dev/null
+++ b/libraw/structs_16.py
@@ -0,0 +1,248 @@
+""":mod:`libraw.structs` --- LibRaw struct definitions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+"""
+
+from ctypes import *  # noqa
+
+
+class ph1_t(Structure):
+
+    """Contains color data read by Phase One cameras."""
+    _fields_ = [
+        ('format', c_int),
+        ('key_off', c_int),
+        ('t_black', c_int),
+        ('black_off', c_int),
+        ('split_col', c_int),
+        ('tag_21a', c_int),
+        ('tag_210', c_float),
+    ]
+
+
+class libraw_iparams_t(Structure):
+
+    """The primary parameters of the image."""
+    _fields_ = [
+        ('make', c_char * 64),
+        ('model', c_char * 64),
+        ('raw_count', c_uint),
+        ('dng_version', c_uint),
+        ('is_foveon', c_uint),
+        ('colors', c_int),
+        ('filters', c_uint),
+        ('xtrans', c_char * 6 * 6),
+        ('cdesc', c_char * 5),
+    ]
+
+
+class libraw_image_sizes_t(Structure):
+
+    """Describes the size of the image."""
+    _fields_ = [
+        ('raw_height', c_ushort),
+        ('raw_width', c_ushort),
+        ('height', c_ushort),
+        ('width', c_ushort),
+        ('top_margin', c_ushort),
+        ('left_margin', c_ushort),
+        ('iheight', c_ushort),
+        ('iwidth', c_ushort),
+        ('raw_pitch', c_uint),
+        ('pixel_aspect', c_double),
+        ('flip', c_int),
+        ('mask', c_int * 8 * 4),
+    ]
+
+
+class libraw_colordata_t(Structure):
+
+    """Describes all color data of the image."""
+    _fields_ = [
+        ('curve', c_ushort * 0x10000),
+        ('cblack', c_uint * 4),
+        ('black', c_uint),
+        ('data_maximum', c_uint),
+        ('maximum', c_uint),
+        ('white', c_ushort * 8 * 8),
+        ('cam_mul', c_float * 4),
+        ('pre_mul', c_float * 4),
+        ('cmatrix', c_float * 3 * 4),
+        ('rgb_cam', c_float * 3 * 4),
+        ('cam_xyz', c_float * 4 * 3),
+        ('phase_one_data', ph1_t),
+        ('flash_used', c_float),
+        ('canon_ev', c_float),
+        ('model2', c_char * 64),
+        ('profile', c_void_p),
+        ('profile_length', c_uint),
+        ('black_stat', c_uint * 8),
+    ]
+
+
+class libraw_imgother_t(Structure):
+
+    """
+    Information read from the raw file that is unnecessary for raw processing.
+    """
+    _fields_ = [
+        ('iso_speed', c_float),
+        ('shutter', c_float),
+        ('aperture', c_float),
+        ('focal_len', c_float),
+        ('timestamp', c_uint),  # time_t
+        ('shot_order', c_uint),
+        ('gpsdata', c_uint * 32),
+        ('desc', c_char * 512),
+        ('artist', c_char * 64),
+    ]
+
+
+class libraw_thumbnail_t(Structure):
+
+    """Describes the thumbnail image embedded in the raw file."""
+    _fields_ = [
+        ('tformat', c_uint),  # LibRaw_thumbnail_formats
+        ('twidth', c_ushort),
+        ('theight', c_ushort),
+        ('tlength', c_uint),
+        ('tcolors', c_int),
+        ('thumb', POINTER(c_char)),
+    ]
+
+
+class libraw_internal_output_params_t(Structure):
+    _fields_ = [
+        ('mix_green', c_uint),
+        ('raw_color', c_uint),
+        ('zero_is_bad', c_uint),
+        ('shrink', c_ushort),
+        ('fuji_width', c_ushort),
+    ]
+
+
+class libraw_rawdata_t(Structure):
+
+    """
+    Raw image data (after it has been unpacked) and a backup copy of color info
+    used during post processing.
+    """
+    _fields_ = [
+        ('raw_alloc', c_void_p),
+        ('raw_image', POINTER(c_ushort)),
+        ('color4_image', POINTER(c_ushort * 4)),
+        ('color3_image', POINTER(c_ushort * 3)),
+        ('ph1_black', POINTER(c_short * 2)),
+        ('iparams', libraw_iparams_t),
+        ('sizes', libraw_image_sizes_t),
+        ('ioparams', libraw_internal_output_params_t),
+        ('color', libraw_colordata_t),
+    ]
+
+
+class libraw_output_params_t(Structure):
+
+    """Output parameters for processing the image with dcraw."""
+    _fields_ = [
+        ('greybox', c_uint * 4),
+        ('cropbox', c_uint * 4),
+        ('aber', c_double * 4),
+        ('gamm', c_double * 6),
+        ('user_mul', c_float * 4),
+        ('shot_select', c_uint),
... 3330 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/rawkit.git



More information about the Python-modules-commits mailing list