# Path: pyrikura/ipyrikura.py
# class IPyrikuraPlugin(Interface):
# class ITrigger(Interface):
# class IImageProcessor(Interface):
# class IFileOp(Interface):
# class ICamera(Interface):
#     def trigger(self):
#     def process(self):
#     def process(self):
# 
# Path: pyrikura/config.py
# def reload(path):


import subprocess
import os
from zope.interface import implements
from pyrikura import ipyrikura
from pyrikura.config import Config
def execute(cmd):
    subprocess.call(cmd.split())


class ColorTone(object):
    implements(ipyrikura.IFileOp)

    @staticmethod
    def process(filename, color, level, type=0, output=None):
        if output is None:
            output = filename

        if type == 0:
            negate = '-negate'
        else:
            negate = '-negate'

        cmd = 'convert {} \
               -set colorspace RGB \
               ( -clone 0 -fill {} -colorize 100% ) \
               ( -clone 0 -colorspace gray {} ) \
               -compose blend -define compose:args={},{} -composite {}'.format(
            filename, color, negate, level, 100 - level, output
        )

        execute(cmd)
        return output


class Vignette(object):

# Path: pyrikura/ipyrikura.py
# class IPyrikuraPlugin(Interface):
# class ITrigger(Interface):
# class IImageProcessor(Interface):
# class IFileOp(Interface):
# class ICamera(Interface):
#     def trigger(self):
#     def process(self):
#     def process(self):
# 
# Path: pyrikura/config.py
# def reload(path):


# Path: pyrikura/twisted/plugins/composer-plugins/filters.py
import subprocess
import os
from zope.interface import implements
from pyrikura import ipyrikura
from pyrikura.config import Config

def execute(cmd):
    subprocess.call(cmd.split())


class ColorTone(object):
    implements(ipyrikura.IFileOp)

    @staticmethod
    def process(filename, color, level, type=0, output=None):
        if output is None:
            output = filename

        if type == 0:
            negate = '-negate'
        else:
            negate = '-negate'

        cmd = 'convert {} \
               -set colorspace RGB \
               ( -clone 0 -fill {} -colorize 100% ) \
               ( -clone 0 -colorspace gray {} ) \
               -compose blend -define compose:args={},{} -composite {}'.format(
            filename, color, negate, level, 100 - level, output
        )

        execute(cmd)
        return output


class Vignette(object):

    implements(ipyrikura.IFileOp)