


'''simple docstring'''






from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
  import PIL


__A   :    Union[str, Any]											= logging.get_logger(__name__)






class   __snake_case			(  _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase  					=   ['pixel_values']

    def __init__(  self       :    Any       ,		lowerCamelCase       :    bool = True       ,		lowerCamelCase       :    Dict[str, int] = None       ,		lowerCamelCase       :    PILImageResampling = PILImageResampling.BICUBIC       ,		lowerCamelCase       :    bool = True       ,		lowerCamelCase       :    Union[int, float] = 1 / 2_55       ,		lowerCamelCase       :    bool = True       ,		lowerCamelCase       :    Optional[Union[float, List[float]]] = None       ,		lowerCamelCase       :    Optional[Union[float, List[float]]] = None       ,		lowerCamelCase       :    bool = True       ,		**lowerCamelCase       :    Union[str, Any]       ,		)  ->    None:
      super().__init__(**lowerCamelCase						)
      lowerCAmelCase_     : Any     =  size if size is not None else {"""height""": 3_84, """width""": 3_84}
      lowerCAmelCase_     : List[str]     =  get_size_dict(lowerCamelCase       ,		default_to_square=lowerCamelCase						)

      lowerCAmelCase_     : Optional[int]     =  do_resize
      lowerCAmelCase_     : Union[str, Any]     =  size
      lowerCAmelCase_     : Tuple     =  resample
      lowerCAmelCase_     : Tuple     =  do_rescale
      lowerCAmelCase_     : Any     =  rescale_factor
      lowerCAmelCase_     : int     =  do_normalize
      lowerCAmelCase_     : Any     =  image_mean if image_mean is not None else OPENAI_CLIP_MEAN
      lowerCAmelCase_     : Tuple     =  image_std if image_std is not None else OPENAI_CLIP_STD
      lowerCAmelCase_     : List[Any]     =  do_convert_rgb

    def __lowercase  (  self       :    Union[str, Any]       ,		lowerCamelCase       :    np.ndarray       ,		lowerCamelCase       :    Dict[str, int]       ,		lowerCamelCase       :    PILImageResampling = PILImageResampling.BICUBIC       ,		lowerCamelCase       :    Optional[Union[str, ChannelDimension]] = None       ,		**lowerCamelCase       :    Union[str, Any]       ,		)  ->    np.ndarray:
      lowerCAmelCase_     : Optional[int]     =  get_size_dict(lowerCamelCase       ,		default_to_square=lowerCamelCase						)
      if "height" not in size or "width" not in size:
        raise ValueError(F'The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'						)
      lowerCAmelCase_     : List[str]     =  (size["""height"""], size["""width"""])
      return resize(lowerCamelCase       ,		size=lowerCamelCase       ,		resample=lowerCamelCase       ,		data_format=lowerCamelCase       ,		**lowerCamelCase						)

    def __lowercase  (  self       :    Any       ,		lowerCamelCase       :    np.ndarray       ,		lowerCamelCase       :    Union[int, float]       ,		lowerCamelCase       :    Optional[Union[str, ChannelDimension]] = None       ,		**lowerCamelCase       :    Union[str, Any]       ,		)  ->    Optional[int]:
      return rescale(lowerCamelCase       ,		scale=lowerCamelCase       ,		data_format=lowerCamelCase       ,		**lowerCamelCase						)

    def __lowercase  (  self       :    int       ,		lowerCamelCase       :    np.ndarray       ,		lowerCamelCase       :    Union[float, List[float]]       ,		lowerCamelCase       :    Union[float, List[float]]       ,		lowerCamelCase       :    Optional[Union[str, ChannelDimension]] = None       ,		**lowerCamelCase       :    List[str]       ,		)  ->    np.ndarray:
      return normalize(lowerCamelCase       ,		mean=lowerCamelCase       ,		std=lowerCamelCase       ,		data_format=lowerCamelCase       ,		**lowerCamelCase						)





    def __lowercase  (  self       :    str       ,		lowerCamelCase       :    ImageInput       ,		lowerCamelCase       :    Optional[bool] = None       ,		lowerCamelCase       :    Optional[Dict[str, int]] = None       ,		lowerCamelCase       :    PILImageResampling = None       ,		lowerCamelCase       :    Optional[bool] = None       ,		lowerCamelCase       :    Optional[float] = None       ,		lowerCamelCase       :    Optional[bool] = None       ,		lowerCamelCase       :    Optional[Union[float, List[float]]] = None       ,		lowerCamelCase       :    Optional[Union[float, List[float]]] = None       ,		lowerCamelCase       :    Optional[Union[str, TensorType]] = None       ,		lowerCamelCase       :    bool = None       ,		lowerCamelCase       :    ChannelDimension = ChannelDimension.FIRST       ,		**lowerCamelCase       :    Union[str, Any]       ,		)  ->    PIL.Image.Image:
      lowerCAmelCase_     : List[str]     =  do_resize if do_resize is not None else self.do_resize
      lowerCAmelCase_     : int     =  resample if resample is not None else self.resample
      lowerCAmelCase_     : Optional[int]     =  do_rescale if do_rescale is not None else self.do_rescale
      lowerCAmelCase_     : Union[str, Any]     =  rescale_factor if rescale_factor is not None else self.rescale_factor
      lowerCAmelCase_     : Dict     =  do_normalize if do_normalize is not None else self.do_normalize
      lowerCAmelCase_     : List[str]     =  image_mean if image_mean is not None else self.image_mean
      lowerCAmelCase_     : Dict     =  image_std if image_std is not None else self.image_std
      lowerCAmelCase_     : Optional[int]     =  do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

      lowerCAmelCase_     : Tuple     =  size if size is not None else self.size
      lowerCAmelCase_     : Dict     =  get_size_dict(lowerCamelCase       ,		default_to_square=lowerCamelCase						)

      lowerCAmelCase_     : Optional[Any]     =  make_list_of_images(lowerCamelCase						)

      if not valid_images(lowerCamelCase						):
        raise ValueError(
            """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
            """torch.Tensor, tf.Tensor or jax.ndarray."""						)

      if do_resize and size is None or resample is None:
        raise ValueError("""Size and resample must be specified if do_resize is True."""						)

      if do_rescale and rescale_factor is None:
        raise ValueError("""Rescale factor must be specified if do_rescale is True."""						)

      if do_normalize and (image_mean is None or image_std is None):
        raise ValueError("""Image mean and std must be specified if do_normalize is True."""						)

      # PIL RGBA images are converted to RGB
      if do_convert_rgb:
        lowerCAmelCase_     : Optional[Any]     =  [convert_to_rgb(lowerCamelCase						) for image in images]

      # All transformations expect numpy arrays.
      lowerCAmelCase_     : int     =  [to_numpy_array(lowerCamelCase						) for image in images]

      if do_resize:
        lowerCAmelCase_     : int     =  [self.resize(image=lowerCamelCase       ,		size=lowerCamelCase       ,		resample=lowerCamelCase						) for image in images]

      if do_rescale:
        lowerCAmelCase_     : str     =  [self.rescale(image=lowerCamelCase       ,		scale=lowerCamelCase						) for image in images]

      if do_normalize:
        lowerCAmelCase_     : int     =  [self.normalize(image=lowerCamelCase       ,		mean=lowerCamelCase       ,		std=lowerCamelCase						) for image in images]

      lowerCAmelCase_     : Any     =  [to_channel_dimension_format(lowerCamelCase       ,		lowerCamelCase						) for image in images]

      lowerCAmelCase_     : Tuple     =  BatchFeature(data={"""pixel_values""": images}       ,		tensor_type=lowerCamelCase						)

      return encoded_outputs







'''simple docstring'''






def 							UpperCamelCase_     (       A__   :  bytes   ):
  '''simple docstring'''





  return "".join([hex(A__   )[2:].zfill(2   ).upper() for byte in list(A__   )]   )







def 							UpperCamelCase_     (       A__   :  str   ):
  '''simple docstring'''





  if (len(A__   ) % 2) != 0:
    raise ValueError(
        """Base16 encoded data is invalid:
Data does not have an even number of hex digits."""   )
  # Check the character set - the standard base16 alphabet
  # is uppercase according to RFC3548 section 6
  if not set(A__   ) <= set("""0123456789ABCDEF"""   ):
    raise ValueError(
        """Base16 encoded data is invalid:
Data is not uppercase hex or it contains invalid characters."""   )
  # For every two hexadecimal digits (= a byte), turn it into an integer.
  # Then, string the result together into bytes, and return it.
  return bytes(int(data[i] + data[i + 1]				,       16   ) for i in range(0				,       len(A__   )				,       2   )   )


if __name__ == "__main__":
  import doctest

  doctest.testmod()



