# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------------------------
# - Generated by tools/entrypoint_compiler.py: do not edit by hand
"""
PixelExtractor
"""

__all__ = ["PixelExtractor"]


from ....entrypoints.transforms_imagepixelextractor import \
    transforms_imagepixelextractor
from ....utils.utils import trace
from ...base_pipeline_item import BasePipelineItem, DefaultSignature


class PixelExtractor(BasePipelineItem, DefaultSignature):
    """

    Extracts the pixel values from an image.

    .. remarks::
        ``PixelExtractor`` extracts the pixel values from an image. The input
        variables
        are images of the same size, typically the output of a ``Resizer``
        transform. The
        output are pixel data in vector form that are typically used as
        features for a learner.

    :param use_alpha: Specifies whether to use alpha channel. The default
        value is ``False``.

    :param use_red: Specifies whether to use red channel. The default value
        is ``True``.

    :param use_green: Specifies whether to use green channel. The default
        value is ``True``.

    :param use_blue: Specifies whether to use blue channel. The default value
        is ``True``.

    :param order: Order of colors.

    :param interleave: Whether to separate each channel or
        interleave in ARGB order. This might be important, for example, if
        you are training
        a convolutional neural network, since this would affect the shape of
        the kernel, stride etc.

    :param convert: Whether to convert to floating point. The default value
        is ``False``.

    :param offset: Specifies the offset (pre-scale). This requires ``convert
        = True``.
        The default value is `None`.

    :param scale: Specifies the scale factor. This requires ``convert =
        True``.
        The default value is `None`.

    :param params: Additional arguments sent to compute engine.

    .. seealso::
        :py:class:`Loader <nimbusml.feature_extraction.image.Loader>`,
        :py:class:`Resizer <nimbusml.feature_extraction.image.Resizer>`.

    .. index:: transform, image

    Example:
       .. literalinclude:: /../nimbusml/examples/Image.py
              :language: python
    """

    @trace
    def __init__(
            self,
            use_alpha=False,
            use_red=True,
            use_green=True,
            use_blue=True,
            order='ARGB',
            interleave=False,
            convert=True,
            offset=None,
            scale=None,
            **params):
        BasePipelineItem.__init__(
            self, type='transform', **params)

        self.use_alpha = use_alpha
        self.use_red = use_red
        self.use_green = use_green
        self.use_blue = use_blue
        self.order = order
        self.interleave = interleave
        self.convert = convert
        self.offset = offset
        self.scale = scale

    @property
    def _entrypoint(self):
        return transforms_imagepixelextractor

    @trace
    def _get_node(self, **all_args):

        input_columns = self.input
        if input_columns is None and 'input' in all_args:
            input_columns = all_args['input']
        if 'input' in all_args:
            all_args.pop('input')

        output_columns = self.output
        if output_columns is None and 'output' in all_args:
            output_columns = all_args['output']
        if 'output' in all_args:
            all_args.pop('output')

        # validate input
        if input_columns is None:
            raise ValueError(
                "'None' input passed when it cannot be none.")

        if not isinstance(input_columns, list):
            raise ValueError(
                "input has to be a list of strings, instead got %s" %
                type(input_columns))

        # validate output
        if output_columns is None:
            output_columns = input_columns

        if not isinstance(output_columns, list):
            raise ValueError(
                "output has to be a list of strings, instead got %s" %
                type(output_columns))

        algo_args = dict(
            column=[
                dict(
                    Source=i,
                    Name=o) for i,
                o in zip(
                    input_columns,
                    output_columns)] if input_columns else None,
            use_alpha=self.use_alpha,
            use_red=self.use_red,
            use_green=self.use_green,
            use_blue=self.use_blue,
            order=self.order,
            interleave=self.interleave,
            convert=self.convert,
            offset=self.offset,
            scale=self.scale)

        all_args.update(algo_args)
        return self._entrypoint(**all_args)
