    {-# LANGUAGE CPP #-}
    {-# LANGUAGE TypeFamilies #-}
    module Codec.Picture.Jpg.Internal.FastDct( referenceDct, fastDctLibJpeg ) where

    #if !MIN_VERSION_base(4,8,0)
    import Control.Applicative( (<$>) )
    #endif

    import Data.Int( Int16, Int32 )
    import Data.Bits( unsafeShiftR, unsafeShiftL )
    import Control.Monad.ST( ST )

    import qualified Data.Vector.Storable.Mutable as M

    import Codec.Picture.Jpg.Internal.Types
    import Control.Monad( forM, forM_ )

    -- | Reference implementation of the DCT, directly implementing the formula

    -- of ITU-81. It's slow as hell, perform to many operations, but is accurate

    -- and a good reference point.

    referenceDct :: MutableMacroBlock s Int32
                 -> MutableMacroBlock s Int16
                 -> ST s (MutableMacroBlock s Int32)
    referenceDct :: MutableMacroBlock s Int32
    -> MutableMacroBlock s Int16 -> ST s (MutableMacroBlock s Int32)
    referenceDct workData :: MutableMacroBlock s Int32
    workData block :: MutableMacroBlock s Int16
    block = do
      [(Int, Int)] -> ((Int, Int) -> ST s ()) -> ST s ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    t a -> (a -> m b) -> m ()
    forM_ [(Int
    u, Int
    v) | Int
    u <- [0 :: Int .. Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1], Int
    v <- [0..Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1]] (((Int, Int) -> ST s ()) -> ST s ())
    -> ((Int, Int) -> ST s ()) -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ \(u :: Int
    u,v :: Int
    v) -> do
        Float
    val <- (Int, Int) -> ST s Float
    at (Int
    u,Int
    v)
        (MutableMacroBlock s Int32
    MVector (PrimState (ST s)) Int32
    workData MVector (PrimState (ST s)) Int32 -> Int -> Int32 -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    `M.unsafeWrite` (Int
    v Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    u)) (Int32 -> ST s ()) -> (Float -> Int32) -> Float -> ST s ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Float -> Int32
    forall a b. (RealFrac a, Integral b) => a -> b
    truncate (Float -> ST s ()) -> Float -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ (1 Float -> Float -> Float
    forall a. Fractional a => a -> a -> a
    / 4) Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a p. (Eq a, Num a, Floating p) => a -> p
    c Int
    u Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a p. (Eq a, Num a, Floating p) => a -> p
    c Int
    v Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Float
    val

      MutableMacroBlock s Int32 -> ST s (MutableMacroBlock s Int32)
    forall (m :: * -> *) a. Monad m => a -> m a
    return MutableMacroBlock s Int32
    workData
     where -- at :: (Int, Int) -> ST s Float

       at :: (Int, Int) -> ST s Float
    at (u :: Int
    u,v :: Int
    v) = do
         [Float]
    toSum <-
            [(Int, Int)] -> ((Int, Int) -> ST s Float) -> ST s [Float]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    t a -> (a -> m b) -> m (t b)
    forM [(Int
    x,Int
    y) | Int
    x <- [0..Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1], Int
    y <- [0..Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1 :: Int]] (((Int, Int) -> ST s Float) -> ST s [Float])
    -> ((Int, Int) -> ST s Float) -> ST s [Float]
    forall a b. (a -> b) -> a -> b
    $ \(x :: Int
    x,y :: Int
    y) -> do
                Float
    sample <- Int16 -> Float
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int16 -> Float) -> ST s Int16 -> ST s Float
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (MutableMacroBlock s Int16
    MVector (PrimState (ST s)) Int16
    block MVector (PrimState (ST s)) Int16 -> Int -> ST s Int16
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> m a
    `M.unsafeRead` (Int
    y Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    x))
                Float -> ST s Float
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Float -> ST s Float) -> Float -> ST s Float
    forall a b. (a -> b) -> a -> b
    $ Float
    sample Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Float -> Float
    forall a. Floating a => a -> a
    cos ((2 Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    x Float -> Float -> Float
    forall a. Num a => a -> a -> a
    + 1) Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    u Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * (Float
    forall a. Floating a => a
    pi :: Float)Float -> Float -> Float
    forall a. Fractional a => a -> a -> a
    / 16)
                                Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Float -> Float
    forall a. Floating a => a -> a
    cos ((2 Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    y Float -> Float -> Float
    forall a. Num a => a -> a -> a
    + 1) Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Int -> Float
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Int
    v Float -> Float -> Float
    forall a. Num a => a -> a -> a
    * Float
    forall a. Floating a => a
    pi Float -> Float -> Float
    forall a. Fractional a => a -> a -> a
    / 16)
         Float -> ST s Float
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Float -> ST s Float) -> Float -> ST s Float
    forall a b. (a -> b) -> a -> b
    $ [Float] -> Float
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    sum [Float]
    toSum

       c :: a -> p
    c 0 = 1 p -> p -> p
    forall a. Fractional a => a -> a -> a
    / p -> p
    forall a. Floating a => a -> a
    sqrt 2
       c _ = 1

    pASS1_BITS, cONST_BITS :: Int
    cONST_BITS :: Int
    cONST_BITS = 13
    pASS1_BITS :: Int
    pASS1_BITS =  2

    fIX_0_298631336, fIX_0_390180644, fIX_0_541196100,
        fIX_0_765366865, fIX_0_899976223, fIX_1_175875602,
        fIX_1_501321110, fIX_1_847759065, fIX_1_961570560,
        fIX_2_053119869, fIX_2_562915447, fIX_3_072711026 :: Int32
    fIX_0_298631336 :: Int32
    fIX_0_298631336 = 2446    -- FIX(0.298631336) */

    fIX_0_390180644 :: Int32
    fIX_0_390180644 = 3196    -- FIX(0.390180644) */

    fIX_0_541196100 :: Int32
    fIX_0_541196100 = 4433    -- FIX(0.541196100) */

    fIX_0_765366865 :: Int32
    fIX_0_765366865 = 6270    -- FIX(0.765366865) */

    fIX_0_899976223 :: Int32
    fIX_0_899976223 = 7373    -- FIX(0.899976223) */

    fIX_1_175875602 :: Int32
    fIX_1_175875602 = 9633    -- FIX(1.175875602) */

    fIX_1_501321110 :: Int32
    fIX_1_501321110 = 12299    -- FIX(1.501321110) */

    fIX_1_847759065 :: Int32
    fIX_1_847759065 = 15137    -- FIX(1.847759065) */

    fIX_1_961570560 :: Int32
    fIX_1_961570560 = 16069    -- FIX(1.961570560) */

    fIX_2_053119869 :: Int32
    fIX_2_053119869 = 16819    -- FIX(2.053119869) */

    fIX_2_562915447 :: Int32
    fIX_2_562915447 = 20995    -- FIX(2.562915447) */

    fIX_3_072711026 :: Int32
    fIX_3_072711026 = 25172    -- FIX(3.072711026) */

    cENTERJSAMPLE :: Int32
    cENTERJSAMPLE :: Int32
    cENTERJSAMPLE = 128

    -- | Fast DCT extracted from libjpeg

    fastDctLibJpeg :: MutableMacroBlock s Int32
            -> MutableMacroBlock s Int16
            -> ST s (MutableMacroBlock s Int32)
    fastDctLibJpeg :: MutableMacroBlock s Int32
    -> MutableMacroBlock s Int16 -> ST s (MutableMacroBlock s Int32)
    fastDctLibJpeg workData :: MutableMacroBlock s Int32
    workData sample_block :: MutableMacroBlock s Int16
    sample_block = do
     MutableMacroBlock s Int32 -> Int -> ST s ()
    firstPass MutableMacroBlock s Int32
    workData  0
     MutableMacroBlock s Int32 -> Int -> ST s ()
    forall s. STVector s Int32 -> Int -> ST s ()
    secondPass MutableMacroBlock s Int32
    workData 7
     {-_ <- mutate (\_ a -> a `quot` 8) workData-}
     MutableMacroBlock s Int32 -> ST s (MutableMacroBlock s Int32)
    forall (m :: * -> *) a. Monad m => a -> m a
    return MutableMacroBlock s Int32
    workData
      where -- Pass 1: process rows.

            -- Note results are scaled up by sqrt(8) compared to a true DCT;

            -- furthermore, we scale the results by 2**PASS1_BITS.

            firstPass :: MutableMacroBlock s Int32 -> Int -> ST s ()
    firstPass         _ i :: Int
    i | Int
    i Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == Int
    forall a. Num a => a
    dctBlockSize = () -> ST s ()
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
            firstPass dataBlock :: MutableMacroBlock s Int32
    dataBlock i :: Int
    i = do
                let baseIdx :: Int
    baseIdx = Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    forall a. Num a => a
    dctBlockSize
                    readAt :: Int -> ST s Int32
    readAt idx :: Int
    idx = Int16 -> Int32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int16 -> Int32) -> ST s Int16 -> ST s Int32
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MutableMacroBlock s Int16
    MVector (PrimState (ST s)) Int16
    sample_block MVector (PrimState (ST s)) Int16 -> Int -> ST s Int16
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> m a
    `M.unsafeRead` (Int
    baseIdx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    idx)
                    mult :: Int32 -> Int32 -> Int32
    mult = Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    (*)
                    writeAt :: Int -> Int32 -> ST s ()
    writeAt idx :: Int
    idx = MutableMacroBlock s Int32
    MVector (PrimState (ST s)) Int32
    dataBlock MVector (PrimState (ST s)) Int32 -> Int -> Int32 -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    `M.unsafeWrite` (Int
    baseIdx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    idx)
                    writeAtPos :: Int -> Int32 -> ST s ()
    writeAtPos idx :: Int
    idx n :: Int32
    n = (MutableMacroBlock s Int32
    MVector (PrimState (ST s)) Int32
    dataBlock MVector (PrimState (ST s)) Int32 -> Int -> Int32 -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    `M.unsafeWrite` (Int
    baseIdx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    idx))
                                        (Int32
    n Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftR` (Int
    cONST_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    pASS1_BITS))

                Int32
    blk0 <- Int -> ST s Int32
    readAt 0
                Int32
    blk1 <- Int -> ST s Int32
    readAt 1
                Int32
    blk2 <- Int -> ST s Int32
    readAt 2
                Int32
    blk3 <- Int -> ST s Int32
    readAt 3
                Int32
    blk4 <- Int -> ST s Int32
    readAt 4
                Int32
    blk5 <- Int -> ST s Int32
    readAt 5
                Int32
    blk6 <- Int -> ST s Int32
    readAt 6
                Int32
    blk7 <- Int -> ST s Int32
    readAt 7

                let tmp0 :: Int32
    tmp0 = Int32
    blk0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk7
                    tmp1 :: Int32
    tmp1 = Int32
    blk1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk6
                    tmp2 :: Int32
    tmp2 = Int32
    blk2 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk5
                    tmp3 :: Int32
    tmp3 = Int32
    blk3 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk4

                    tmp10 :: Int32
    tmp10 = Int32
    tmp0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3
                    tmp12 :: Int32
    tmp12 = Int32
    tmp0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp3
                    tmp11 :: Int32
    tmp11 = Int32
    tmp1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2
                    tmp13 :: Int32
    tmp13 = Int32
    tmp1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp2

                    tmp0' :: Int32
    tmp0' = Int32
    blk0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk7
                    tmp1' :: Int32
    tmp1' = Int32
    blk1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk6
                    tmp2' :: Int32
    tmp2' = Int32
    blk2 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk5
                    tmp3' :: Int32
    tmp3' = Int32
    blk3 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk4

                -- Stage 4 and output

                Int -> Int32 -> ST s ()
    writeAt 0 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ (Int32
    tmp10 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    forall a. Num a => a
    dctBlockSize Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    * Int32
    cENTERJSAMPLE) Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` Int
    pASS1_BITS
                Int -> Int32 -> ST s ()
    writeAt 4 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ (Int32
    tmp10 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp11) Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` Int
    pASS1_BITS

                let z1 :: Int32
    z1 = Int32 -> Int32 -> Int32
    mult (Int32
    tmp12 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13) Int32
    fIX_0_541196100
                         Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + (1 Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` (Int
    cONST_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    pASS1_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1))

                Int -> Int32 -> ST s ()
    writeAtPos 2 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    z1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32 -> Int32 -> Int32
    mult Int32
    tmp12 Int32
    fIX_0_765366865
                Int -> Int32 -> ST s ()
    writeAtPos 6 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    z1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32 -> Int32 -> Int32
    mult Int32
    tmp13 Int32
    fIX_1_847759065

                let tmp10' :: Int32
    tmp10' = Int32
    tmp0' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3'
                    tmp11' :: Int32
    tmp11' = Int32
    tmp1' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2'
                    tmp12' :: Int32
    tmp12' = Int32
    tmp0' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2'
                    tmp13' :: Int32
    tmp13' = Int32
    tmp1' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3'
                    z1' :: Int32
    z1' = Int32 -> Int32 -> Int32
    mult (Int32
    tmp12' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13') Int32
    fIX_1_175875602 --  c3 */

                            -- Add fudge factor here for final descale. */

                            Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + (1 Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` (Int
    cONST_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    pASS1_BITSInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1))
                    tmp0'' :: Int32
    tmp0'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp0' Int32
    fIX_1_501321110
                    tmp1'' :: Int32
    tmp1'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp1' Int32
    fIX_3_072711026
                    tmp2'' :: Int32
    tmp2'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp2' Int32
    fIX_2_053119869
                    tmp3'' :: Int32
    tmp3'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp3' Int32
    fIX_0_298631336

                    tmp10'' :: Int32
    tmp10'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp10' (- Int32
    fIX_0_899976223)
                    tmp11'' :: Int32
    tmp11'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp11' (- Int32
    fIX_2_562915447)
                    tmp12'' :: Int32
    tmp12'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp12' (- Int32
    fIX_0_390180644) Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    z1'
                    tmp13'' :: Int32
    tmp13'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp13' (- Int32
    fIX_1_961570560) Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    z1'

                Int -> Int32 -> ST s ()
    writeAtPos 1 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp0'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp10'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp12''
                Int -> Int32 -> ST s ()
    writeAtPos 3 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp1'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13''
                Int -> Int32 -> ST s ()
    writeAtPos 5 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp2'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp12''
                Int -> Int32 -> ST s ()
    writeAtPos 7 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp3'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp10'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13''

                MutableMacroBlock s Int32 -> Int -> ST s ()
    firstPass MutableMacroBlock s Int32
    dataBlock (Int -> ST s ()) -> Int -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 1

            -- Pass 2: process columns.

            -- We remove the PASS1_BITS scaling, but leave the results scaled up

            -- by an overall factor of 8.

            secondPass :: M.STVector s Int32 -> Int -> ST s ()
            secondPass :: STVector s Int32 -> Int -> ST s ()
    secondPass _     (-1) = () -> ST s ()
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
            secondPass block :: STVector s Int32
    block i :: Int
    i = do
                let readAt :: Int -> ST s Int32
    readAt idx :: Int
    idx = STVector s Int32
    MVector (PrimState (ST s)) Int32
    block MVector (PrimState (ST s)) Int32 -> Int -> ST s Int32
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> m a
    `M.unsafeRead` ((7 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    i) Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    idx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    forall a. Num a => a
    dctBlockSize)
                    mult :: Int32 -> Int32 -> Int32
    mult = Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    (*)
                    writeAt :: Int -> Int32 -> ST s ()
    writeAt idx :: Int
    idx = STVector s Int32
    MVector (PrimState (ST s)) Int32
    block MVector (PrimState (ST s)) Int32 -> Int -> Int32 -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    `M.unsafeWrite` (Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    idx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + (7 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    i))
                    writeAtPos :: Int -> Int32 -> ST s ()
    writeAtPos idx :: Int
    idx n :: Int32
    n = (STVector s Int32
    MVector (PrimState (ST s)) Int32
    block MVector (PrimState (ST s)) Int32 -> Int -> Int32 -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Storable a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    `M.unsafeWrite` (Int
    forall a. Num a => a
    dctBlockSize Int -> Int -> Int
    forall a. Num a => a -> a -> a
    * Int
    idx Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + (7 Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    i))) (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    n Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftR` (Int
    cONST_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    pASS1_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 3)
                Int32
    blk0 <- Int -> ST s Int32
    readAt 0
                Int32
    blk1 <- Int -> ST s Int32
    readAt 1
                Int32
    blk2 <- Int -> ST s Int32
    readAt 2
                Int32
    blk3 <- Int -> ST s Int32
    readAt 3
                Int32
    blk4 <- Int -> ST s Int32
    readAt 4
                Int32
    blk5 <- Int -> ST s Int32
    readAt 5
                Int32
    blk6 <- Int -> ST s Int32
    readAt 6
                Int32
    blk7 <- Int -> ST s Int32
    readAt 7

                let tmp0 :: Int32
    tmp0 = Int32
    blk0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk7
                    tmp1 :: Int32
    tmp1 = Int32
    blk1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk6
                    tmp2 :: Int32
    tmp2 = Int32
    blk2 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk5
                    tmp3 :: Int32
    tmp3 = Int32
    blk3 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    blk4

                    -- Add fudge factor here for final descale. */

                    tmp10 :: Int32
    tmp10 = Int32
    tmp0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + (1 Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` (Int
    pASS1_BITSInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1))
                    tmp12 :: Int32
    tmp12 = Int32
    tmp0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp3
                    tmp11 :: Int32
    tmp11 = Int32
    tmp1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2
                    tmp13 :: Int32
    tmp13 = Int32
    tmp1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp2

                    tmp0' :: Int32
    tmp0' = Int32
    blk0 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk7
                    tmp1' :: Int32
    tmp1' = Int32
    blk1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk6
                    tmp2' :: Int32
    tmp2' = Int32
    blk2 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk5
                    tmp3' :: Int32
    tmp3' = Int32
    blk3 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    blk4

                Int -> Int32 -> ST s ()
    writeAt 0 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ (Int32
    tmp10 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11) Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftR` (Int
    pASS1_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 3)
                Int -> Int32 -> ST s ()
    writeAt 4 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ (Int32
    tmp10 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32
    tmp11) Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftR` (Int
    pASS1_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + 3)

                let z1 :: Int32
    z1 = Int32 -> Int32 -> Int32
    mult (Int32
    tmp12 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13) Int32
    fIX_0_541196100
                        Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + (1 Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` (Int
    cONST_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    pASS1_BITS Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1))

                Int -> Int32 -> ST s ()
    writeAtPos 2 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    z1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32 -> Int32 -> Int32
    mult Int32
    tmp12 Int32
    fIX_0_765366865
                Int -> Int32 -> ST s ()
    writeAtPos 6 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    z1 Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    - Int32 -> Int32 -> Int32
    mult Int32
    tmp13 Int32
    fIX_1_847759065

                let tmp10' :: Int32
    tmp10' = Int32
    tmp0' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3'
                    tmp11' :: Int32
    tmp11' = Int32
    tmp1' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2'
                    tmp12' :: Int32
    tmp12' = Int32
    tmp0' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp2'
                    tmp13' :: Int32
    tmp13' = Int32
    tmp1' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp3'

                    z1' :: Int32
    z1' = Int32 -> Int32 -> Int32
    mult (Int32
    tmp12' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13') Int32
    fIX_1_175875602
                        -- Add fudge factor here for final descale. */

                       Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + 1 Int32 -> Int -> Int32
    forall a. Bits a => a -> Int -> a
    `unsafeShiftL` (Int
    cONST_BITSInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +Int
    pASS1_BITSInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1);

                    tmp0'' :: Int32
    tmp0''  = Int32 -> Int32 -> Int32
    mult Int32
    tmp0'    Int32
    fIX_1_501321110
                    tmp1'' :: Int32
    tmp1''  = Int32 -> Int32 -> Int32
    mult Int32
    tmp1'    Int32
    fIX_3_072711026
                    tmp2'' :: Int32
    tmp2''  = Int32 -> Int32 -> Int32
    mult Int32
    tmp2'    Int32
    fIX_2_053119869
                    tmp3'' :: Int32
    tmp3''  = Int32 -> Int32 -> Int32
    mult Int32
    tmp3'    Int32
    fIX_0_298631336
                    tmp10'' :: Int32
    tmp10'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp10' (- Int32
    fIX_0_899976223)
                    tmp11'' :: Int32
    tmp11'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp11' (- Int32
    fIX_2_562915447)
                    tmp12'' :: Int32
    tmp12'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp12' (- Int32
    fIX_0_390180644)
                                Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    z1'
                    tmp13'' :: Int32
    tmp13'' = Int32 -> Int32 -> Int32
    mult Int32
    tmp13' (- Int32
    fIX_1_961570560)
                                Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    z1'
                Int -> Int32 -> ST s ()
    writeAtPos 1 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp0'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp10'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp12''
                Int -> Int32 -> ST s ()
    writeAtPos 3 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp1'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13''
                Int -> Int32 -> ST s ()
    writeAtPos 5 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp2'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp11'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp12''
                Int -> Int32 -> ST s ()
    writeAtPos 7 (Int32 -> ST s ()) -> Int32 -> ST s ()
    forall a b. (a -> b) -> a -> b
    $ Int32
    tmp3'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp10'' Int32 -> Int32 -> Int32
    forall a. Num a => a -> a -> a
    + Int32
    tmp13''

                STVector s Int32 -> Int -> ST s ()
    forall s. STVector s Int32 -> Int -> ST s ()
    secondPass STVector s Int32
    block (Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - 1)

    {-# ANN module "HLint: ignore Use camelCase" #-}
    {-# ANN module "HLint: ignore Reduce duplication" #-}