{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Rekognition.Types.BlackFrame
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Rekognition.Types.BlackFrame where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | A filter that allows you to control the black frame detection by
-- specifying the black levels and pixel coverage of black pixels in a
-- frame. As videos can come from multiple sources, formats, and time
-- periods, they may contain different standards and varying noise levels
-- for black frames that need to be accounted for. For more information,
-- see StartSegmentDetection.
--
-- /See:/ 'newBlackFrame' smart constructor.
data BlackFrame = BlackFrame'
  { -- | A threshold used to determine the maximum luminance value for a pixel to
    -- be considered black. In a full color range video, luminance values range
    -- from 0-255. A pixel value of 0 is pure black, and the most strict
    -- filter. The maximum black pixel value is computed as follows:
    -- max_black_pixel_value = minimum_luminance + MaxPixelThreshold
    -- *luminance_range.
    --
    -- For example, for a full range video with BlackPixelThreshold = 0.1,
    -- max_black_pixel_value is 0 + 0.1 * (255-0) = 25.5.
    --
    -- The default value of MaxPixelThreshold is 0.2, which maps to a
    -- max_black_pixel_value of 51 for a full range video. You can lower this
    -- threshold to be more strict on black levels.
    BlackFrame -> Maybe Double
maxPixelThreshold :: Prelude.Maybe Prelude.Double,
    -- | The minimum percentage of pixels in a frame that need to have a
    -- luminance below the max_black_pixel_value for a frame to be considered a
    -- black frame. Luminance is calculated using the BT.709 matrix.
    --
    -- The default value is 99, which means at least 99% of all pixels in the
    -- frame are black pixels as per the @MaxPixelThreshold@ set. You can
    -- reduce this value to allow more noise on the black frame.
    BlackFrame -> Maybe Double
minCoveragePercentage :: Prelude.Maybe Prelude.Double
  }
  deriving (BlackFrame -> BlackFrame -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlackFrame -> BlackFrame -> Bool
$c/= :: BlackFrame -> BlackFrame -> Bool
== :: BlackFrame -> BlackFrame -> Bool
$c== :: BlackFrame -> BlackFrame -> Bool
Prelude.Eq, ReadPrec [BlackFrame]
ReadPrec BlackFrame
Int -> ReadS BlackFrame
ReadS [BlackFrame]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlackFrame]
$creadListPrec :: ReadPrec [BlackFrame]
readPrec :: ReadPrec BlackFrame
$creadPrec :: ReadPrec BlackFrame
readList :: ReadS [BlackFrame]
$creadList :: ReadS [BlackFrame]
readsPrec :: Int -> ReadS BlackFrame
$creadsPrec :: Int -> ReadS BlackFrame
Prelude.Read, Int -> BlackFrame -> ShowS
[BlackFrame] -> ShowS
BlackFrame -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlackFrame] -> ShowS
$cshowList :: [BlackFrame] -> ShowS
show :: BlackFrame -> String
$cshow :: BlackFrame -> String
showsPrec :: Int -> BlackFrame -> ShowS
$cshowsPrec :: Int -> BlackFrame -> ShowS
Prelude.Show, forall x. Rep BlackFrame x -> BlackFrame
forall x. BlackFrame -> Rep BlackFrame x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlackFrame x -> BlackFrame
$cfrom :: forall x. BlackFrame -> Rep BlackFrame x
Prelude.Generic)

-- |
-- Create a value of 'BlackFrame' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'maxPixelThreshold', 'blackFrame_maxPixelThreshold' - A threshold used to determine the maximum luminance value for a pixel to
-- be considered black. In a full color range video, luminance values range
-- from 0-255. A pixel value of 0 is pure black, and the most strict
-- filter. The maximum black pixel value is computed as follows:
-- max_black_pixel_value = minimum_luminance + MaxPixelThreshold
-- *luminance_range.
--
-- For example, for a full range video with BlackPixelThreshold = 0.1,
-- max_black_pixel_value is 0 + 0.1 * (255-0) = 25.5.
--
-- The default value of MaxPixelThreshold is 0.2, which maps to a
-- max_black_pixel_value of 51 for a full range video. You can lower this
-- threshold to be more strict on black levels.
--
-- 'minCoveragePercentage', 'blackFrame_minCoveragePercentage' - The minimum percentage of pixels in a frame that need to have a
-- luminance below the max_black_pixel_value for a frame to be considered a
-- black frame. Luminance is calculated using the BT.709 matrix.
--
-- The default value is 99, which means at least 99% of all pixels in the
-- frame are black pixels as per the @MaxPixelThreshold@ set. You can
-- reduce this value to allow more noise on the black frame.
newBlackFrame ::
  BlackFrame
newBlackFrame :: BlackFrame
newBlackFrame =
  BlackFrame'
    { $sel:maxPixelThreshold:BlackFrame' :: Maybe Double
maxPixelThreshold = forall a. Maybe a
Prelude.Nothing,
      $sel:minCoveragePercentage:BlackFrame' :: Maybe Double
minCoveragePercentage = forall a. Maybe a
Prelude.Nothing
    }

-- | A threshold used to determine the maximum luminance value for a pixel to
-- be considered black. In a full color range video, luminance values range
-- from 0-255. A pixel value of 0 is pure black, and the most strict
-- filter. The maximum black pixel value is computed as follows:
-- max_black_pixel_value = minimum_luminance + MaxPixelThreshold
-- *luminance_range.
--
-- For example, for a full range video with BlackPixelThreshold = 0.1,
-- max_black_pixel_value is 0 + 0.1 * (255-0) = 25.5.
--
-- The default value of MaxPixelThreshold is 0.2, which maps to a
-- max_black_pixel_value of 51 for a full range video. You can lower this
-- threshold to be more strict on black levels.
blackFrame_maxPixelThreshold :: Lens.Lens' BlackFrame (Prelude.Maybe Prelude.Double)
blackFrame_maxPixelThreshold :: Lens' BlackFrame (Maybe Double)
blackFrame_maxPixelThreshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlackFrame' {Maybe Double
maxPixelThreshold :: Maybe Double
$sel:maxPixelThreshold:BlackFrame' :: BlackFrame -> Maybe Double
maxPixelThreshold} -> Maybe Double
maxPixelThreshold) (\s :: BlackFrame
s@BlackFrame' {} Maybe Double
a -> BlackFrame
s {$sel:maxPixelThreshold:BlackFrame' :: Maybe Double
maxPixelThreshold = Maybe Double
a} :: BlackFrame)

-- | The minimum percentage of pixels in a frame that need to have a
-- luminance below the max_black_pixel_value for a frame to be considered a
-- black frame. Luminance is calculated using the BT.709 matrix.
--
-- The default value is 99, which means at least 99% of all pixels in the
-- frame are black pixels as per the @MaxPixelThreshold@ set. You can
-- reduce this value to allow more noise on the black frame.
blackFrame_minCoveragePercentage :: Lens.Lens' BlackFrame (Prelude.Maybe Prelude.Double)
blackFrame_minCoveragePercentage :: Lens' BlackFrame (Maybe Double)
blackFrame_minCoveragePercentage = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlackFrame' {Maybe Double
minCoveragePercentage :: Maybe Double
$sel:minCoveragePercentage:BlackFrame' :: BlackFrame -> Maybe Double
minCoveragePercentage} -> Maybe Double
minCoveragePercentage) (\s :: BlackFrame
s@BlackFrame' {} Maybe Double
a -> BlackFrame
s {$sel:minCoveragePercentage:BlackFrame' :: Maybe Double
minCoveragePercentage = Maybe Double
a} :: BlackFrame)

instance Prelude.Hashable BlackFrame where
  hashWithSalt :: Int -> BlackFrame -> Int
hashWithSalt Int
_salt BlackFrame' {Maybe Double
minCoveragePercentage :: Maybe Double
maxPixelThreshold :: Maybe Double
$sel:minCoveragePercentage:BlackFrame' :: BlackFrame -> Maybe Double
$sel:maxPixelThreshold:BlackFrame' :: BlackFrame -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
maxPixelThreshold
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
minCoveragePercentage

instance Prelude.NFData BlackFrame where
  rnf :: BlackFrame -> ()
rnf BlackFrame' {Maybe Double
minCoveragePercentage :: Maybe Double
maxPixelThreshold :: Maybe Double
$sel:minCoveragePercentage:BlackFrame' :: BlackFrame -> Maybe Double
$sel:maxPixelThreshold:BlackFrame' :: BlackFrame -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
maxPixelThreshold
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
minCoveragePercentage

instance Data.ToJSON BlackFrame where
  toJSON :: BlackFrame -> Value
toJSON BlackFrame' {Maybe Double
minCoveragePercentage :: Maybe Double
maxPixelThreshold :: Maybe Double
$sel:minCoveragePercentage:BlackFrame' :: BlackFrame -> Maybe Double
$sel:maxPixelThreshold:BlackFrame' :: BlackFrame -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"MaxPixelThreshold" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
maxPixelThreshold,
            (Key
"MinCoveragePercentage" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
minCoveragePercentage
          ]
      )