#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Conversion Process
==================
Defines the conversion process objects:
- :func:`convert_raw_files_to_dng_files`
- :func:`convert_dng_files_to_intermediate_files`
"""
from __future__ import division, unicode_literals
import logging
import os
import platform
import re
import shlex
import subprocess
from colour_hdri.utilities import path_exists
__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2015 - Colour Developers'
__license__ = 'New BSD License - http://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = 'colour-science@googlegroups.com'
__status__ = 'Production'
__all__ = ['RAW_CONVERTER',
'RAW_CONVERSION_ARGUMENTS',
'RAW_D_CONVERSION_ARGUMENTS',
'DNG_CONVERTER',
'DNG_CONVERSION_ARGUMENTS',
'convert_raw_files_to_dng_files',
'convert_dng_files_to_intermediate_files']
LOGGER = logging.getLogger(__name__)
RAW_CONVERTER = 'dcraw'
"""
Command line raw conversion application, usually Dave Coffin's *dcraw*.
RAW_CONVERTER : unicode
"""
RAW_CONVERSION_ARGUMENTS = '-t 0 -D -W -4 -T "{0}"'
"""
Arguments for the command line raw conversion application for non demosaiced
linear *tiff* file format output.
RAW_CONVERSION_ARGUMENTS : unicode
"""
RAW_D_CONVERSION_ARGUMENTS = '-t 0 -H 1 -r 1 1 1 1 -4 -q 3 -o 0 -T "{0}"'
"""
Arguments for the command line raw conversion application for demosaiced
linear *tiff* file format output.
RAW_D_CONVERSION_ARGUMENTS : unicode
"""
if platform.system() in ('Windows', 'Microsoft'):
DNG_CONVERTER = 'C:\\Program Files (x86)\\Adobe\\Adobe DNG Converter.exe'
"""
Command line *DNG* conversion application, usually *Adobe DNG Converter*.
DNG_CONVERTER : unicode
"""
elif platform.system() == 'Darwin':
DNG_CONVERTER = ('/Applications/Adobe DNG Converter.app/Contents/'
'MacOS/Adobe DNG Converter')
"""
Command line *dng* conversion application, usually *Adobe DNG Converter*.
DNG_CONVERTER : unicode
"""
else:
DNG_CONVERTER = None
"""
Command line *dng* conversion application, usually *Adobe DNG Converter*.
DNG_CONVERTER : unicode
"""
DNG_CONVERSION_ARGUMENTS = '-e -d "{0}" "{1}"'
"""
Arguments for the command line *dng* conversion application.
DNG_CONVERSION_ARGUMENTS : unicode
"""
[docs]def convert_raw_files_to_dng_files(raw_files, output_directory):
"""
Converts given raw files to *dng* files using given output directory.
Parameters
----------
raw_files : array_like
Raw files to convert to *dng* files.
output_directory : unicode
Output directory.
Returns
-------
list
*dng* files.
"""
dng_files = []
for raw_file in raw_files:
raw_file_extension = os.path.splitext(raw_file)[1]
dng_file = os.path.join(output_directory, os.path.basename(
re.sub('{0}$'.format(raw_file_extension), '.dng', raw_file)))
path_exists(dng_file) and os.remove(dng_file)
LOGGER.info(
'Converting "{0}" file to "{1}" file.'.format(raw_file, dng_file))
command = [DNG_CONVERTER] + shlex.split(
DNG_CONVERSION_ARGUMENTS.format(output_directory, raw_file),
posix=(False
if platform.system() in ("Windows", "Microsoft") else
True))
subprocess.call(command)
dng_files.append(dng_file)
return dng_files