    {-# LINE 1 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
    {-# OPTIONS -fno-warn-orphans #-}
    {-# LINE 2 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
    module Graphics.Transform.Magick.FFIHelpers(withExceptions,
                      withExceptions_,
                      setField,
                      (-->),
                      mkImage,
                      setImage,
                      applyImageFn,
                      applyImageFn',
                      applyImageFn1,
                      applyImageFn1',
                      setFilename,
                      getFilename,
                      setPage,
                      doTransform,
                      doTransformIO,
                      doTransformIO_XY,
                      doTransformIO_XY_real,
                      sideEffectingOp,
                      linkImagesTogether,
                      mkNewExceptionInfo,
                      nonFinalizedExceptionInfo,
                      destroyExceptionInfo,
                      withTmpExceptionInfo,
                      mkNewImageInfo,
                      mkFinalizedImageInfo,
                      destroyImageInfo,
                      withTmpImageInfo,
                      toCEnum,
                      hImageRows,
                      hImageColumns,
                      maybeToPtr,
                      mkNewUnloadedImage) where

    {-# LINE 36 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    import Graphics.Transform.Magick.Types
    import Graphics.Transform.Magick.Magick
    import Graphics.Transform.Magick.Errors
    import Graphics.Transform.Magick.Util

    import qualified Foreign.Concurrent as FC (newForeignPtr)

    import Control.Exception
    import Prelude hiding (maximum, minimum)
    import Control.Monad

    -- functions to help with doing FFI

    setImage :: HImage -> Ptr HImage_ -> HImage
    setImage hIm imPtr = unsafePerformIO $ do
        i <- newForeignPtr finalize_image imPtr
        return hIm{ image = i }

    mkImage :: Ptr HImage_ -> ImageNotLoaded -> HImage
    mkImage p info = unsafePerformIO $ do
        i <- newForeignPtr finalize_image p
        return $ HImage { image=i, otherInfo=info }

    -------------- Strings/char arrays
    -- This is really terrible. How to avoid these casts?
    pokeStringIntoCharArray :: Ptr CharArray -> String -> IO ()
    pokeStringIntoCharArray ptr s = go (castPtr ptr) s
                   where go :: Ptr CChar -> String -> IO ()
                         go p [] = poke p nullChar
                         go p (c:cs) = do
                            debug 3 $ "p = " ++ show p ++ " c = " ++ show c
                            poke p (castCharToCChar c)
                            go (p `plusPtr` charSize) cs

    peekStringFromCharArray :: Ptr CharArray -> IO String
    peekStringFromCharArray ptr =
       (debug 3 $ "peekStringFromCharArray: ptr = " ++ show ptr)
       >> go (castPtr ptr) ""
          where go :: Ptr CChar -> String -> IO String
                go p s = do
                  debug 3 $ "p = " ++ show p
                  c <- (liftM castCCharToChar) $ peek p
                  debug 3 $ " c = " ++ show c
                  if c == '\0'
                    then return s
                    else go (p `plusPtr` charSize) (s ++ [c])

    charSize :: Int
    charSize = sizeOf (undefined::CChar)
    nullChar :: CChar
    nullChar = castCharToCChar '\0'

    -------- sets a field in something Storable --------

    class PtrAccessors ptr where
        setField :: Storable a => (a -> a) -> ptr a -> IO ()
        (-->) :: Storable a => ptr a -> (a -> b) -> b

    instance PtrAccessors Ptr where
        setField modify p = peek p >>= ((poke p).modify)
        p --> sel = unsafePerformIO $ peek p >>= (return.sel)

    instance PtrAccessors ForeignPtr where
        setField modify p = withForeignPtr p (setField modify)
        p --> sel = unsafePerformIO $ withForeignPtr p (\fp ->
                      peek fp >>= (return.sel))

    -- setField :: Storable a => (a -> a) -> Ptr a -> IO ()
    -- setField modify p = peek p >>= ((poke p).modify)
    -- (-->) :: Storable a => Ptr a -> (a -> b) -> b
    -- (-->) p sel = unsafePerformIO $ peek p >>= (return.sel)

    ---------------------------------

    -- Function for handling exceptions from GraphicsMagick calls.
    -- Takes an IO action (that's presumably a call to a GraphicsMagick function),
    -- an error message to print if something goes wrong, and a function to
    -- determine whether the result of the call was erroneous, as well as a pointer
    -- to the exception info that the action will set.
    -- The checker function is assumed to return True if there was an error.
    withExceptions :: IO a -> String -> (a -> Bool) -> (ForeignPtr ExceptionInfo) -> IO a
    withExceptions action errMsg checker excPtr_ = withForeignPtr excPtr_ $ \excPtr -> do
      result <- action
      if (checker result)
        then do
           -- this prints out GraphicsMagick's message
           tellUser "hsMagick: caught a GraphicsMagick exception as follows: "
           catch_exception excPtr
           signalException errMsg
        else return result
    -- Same as withExceptions, but throws away the result
    withExceptions_ :: IO a -> String -> (a -> Bool) -> ForeignPtr ExceptionInfo -> IO ()
    withExceptions_ action errMsg checker excPtr =
      withExceptions action errMsg checker excPtr >> return ()

    -- Note: for a plain Image -> Exception -> Image function, we should
    -- call doTransform. For transformations that take extra arguments,
    -- we use doTransformIO.

    applyImageFn :: HImage -> (Ptr HImage_ -> a) -> (a -> IO b) -> IO b
    applyImageFn hImage fn run = withForeignPtr (getImage hImage) $ \i_ptr ->
                                   run $ fn i_ptr

    applyImageFn' :: HImage -> (Ptr HImage_ -> t) -> (t -> Ptr ExceptionInfo -> IO b) -> IO b
    applyImageFn' hImage fn run = withForeignPtr (getImage hImage) $ \i_ptr ->
                                  withForeignPtr (getExceptionInfo hImage) $ \e_ptr ->
                                   run (fn i_ptr) e_ptr

    applyImageFn1 :: HImage -> (Ptr HImage_ -> t -> IO b) -> t -> IO b
    applyImageFn1 hImage fn v = applyImageFn hImage fn $ \f -> f v

    applyImageFn1' :: HImage -> (Ptr HImage_ -> t -> Ptr ExceptionInfo -> IO b) -> t -> IO b
    applyImageFn1' hImage fn v = applyImageFn' hImage fn $ \f -> f v

    -- doTransform takes an image transformation that takes an
    -- image pointer and an exception pointer as arguments, and applies it
    -- to the given HImage.
    -- It's assumed that the transformer returns null if an error occurs,
    -- so this checks for null and looks at the exception field.
    doTransform :: (Ptr HImage_ -> Ptr ExceptionInfo
                                 -> IO (Ptr HImage_)) -> HImage -> HImage
    doTransform transform hImage =
      doTransformIO (applyImageFn hImage transform $ withForeignPtr excInfo)
                    hImage
           where excInfo = getExceptionInfo hImage

    -- doTransformIO takes an arbitrary IO action that returns an HImage_
    -- pointer, and returns a new HImage with the image field of the given
    -- HImage set to it, checking for exceptions.
    -- It's assumed that the IO action returns a null pointer to signal
    -- an exception.
    doTransformIO :: IO (Ptr HImage_) -> HImage -> HImage
    doTransformIO act hImage =
      setImage hImage (unsafePerformIO
                        (withExceptions act
                          -- TODO: better messages
                          "error doing image transformation"
                          (== nullPtr)
                          excInfo))
           where excInfo = getExceptionInfo hImage

    doTransformIO_XY :: (Integral a, Integral b) =>
      (Ptr HImage_ -> a -> a -> Ptr ExceptionInfo -> IO (Ptr HImage_)) ->
      HImage -> b -> b -> HImage
    doTransformIO_XY transform hImage x_ y_ =
      doTransformIO (applyImageFn' hImage transform $ \f ->
                        f (fromIntegral x_) (fromIntegral y_))
          hImage

    -- Ugh.
    doTransformIO_XY_real :: (Real b, Fractional a) =>
      (Ptr HImage_ -> a -> a -> Ptr ExceptionInfo -> IO (Ptr HImage_)) ->
      HImage -> b -> b -> HImage
    doTransformIO_XY_real transform hImage x_ y_ =
      doTransformIO (applyImageFn' hImage transform $ \f -> f (realToFrac x_) (realToFrac y_))
          hImage

    ------------------ creating image sequences -----------
    linkImagesTogether :: [HImage] -> IO ()
    linkImagesTogether [] = signalException $ "internal error: linkImagesTogether:"
                             ++ " empty list"
    linkImagesTogether (img:images) = do
             _ <- foldM (\ bigImage smallImage ->
                           withForeignPtr (getImage bigImage) $ \bi ->
                           withForeignPtr (getImage smallImage) $ \si -> do
                           ((\hsc_ptr -> pokeByteOff hsc_ptr 6580)) bi si
    {-# LINE 204 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                           return smallImage)
                        img
                        images
             debug 3 $ "Checking assertion..."
             -- check that: all images but the last one have a non-null "next"
             -- ptr, and also, the last one has a null "next" ptr
             allGood <- allM nextImageNotNull (butLast images)
             lastNull <- (liftM not) (nextImageNotNull (last images))
             assertM (allGood && lastNull)
                  "flattenImage: internal error: couldn't create sequence"
                 where nextImageNotNull hImage = do
                          -- debug 3 $ "peeking: " ++ show (getImage hImage)
                          nextIm <- withForeignPtr (getImage hImage) $ ((\hsc_ptr -> peekByteOff hsc_ptr 6580))
    {-# LINE 217 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                          debug 3 $ "peeked! " ++ show nextIm
                          return $ nextIm /= nullPtr

    ------------------ instances --------------------------
    --- (should this be in this module? Who knows?)

    instance Storable FilterTypes where
        sizeOf _ = sizeOf (undefined::CUInt)
        alignment _ = alignment (undefined::CUInt)
        peek ptr = do
           -- is this use of cast right?
           (theInt::CUInt) <- peek (castPtr ptr)
           return $ toEnum (fromIntegral theInt)
        poke ptr val = poke (castPtr ptr) (fromEnum val)

    -- TODO:
    -- could this be auto-generated? boilerplate sux...
    -- (fundeps? instance Enum a => Storable a...)
    instance Storable CompositeOp where
        sizeOf _ = sizeOf (undefined::CUInt)
        alignment _ = alignment (undefined::CUInt)
        peek ptr = do
           -- is this use of cast right?
           (theInt::CUInt) <- peek (castPtr ptr)
           return $ toEnum (fromIntegral theInt)
        poke ptr val = poke (castPtr ptr) (fromEnum val)

    instance Storable ImageCharacteristics where
      sizeOf _    = (sizeOf (undefined::CUInt)) * 5
      alignment _ = alignment (undefined::CUInt)
      peek ptr = do
          cmyk'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 250 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          grayscale'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
    {-# LINE 251 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          mONOCHROME' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 252 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          opaque'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
    {-# LINE 253 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          palette'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 254 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ ImageC { cmyk=toEnum cmyk', grayscale=toEnum grayscale',
                            mONOCHROME=toEnum mONOCHROME', opaque=toEnum opaque',
                            palette=toEnum palette'}
      poke ptr i = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (fromEnum$ cmyk i)
    {-# LINE 259 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (fromEnum$ grayscale i)
    {-# LINE 260 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (fromEnum$ mONOCHROME i)
    {-# LINE 261 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (fromEnum$ opaque i)
    {-# LINE 262 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (fromEnum$ palette i)
    {-# LINE 263 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable ImageStatistics where
        sizeOf _    = 4 * sizeOf (undefined::ImageChannelStatistics)
        alignment _ = alignment (undefined::ImageChannelStatistics)
        peek ptr = do
          red'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 269 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          green'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
    {-# LINE 270 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          blue'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) ptr
    {-# LINE 271 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          opacity'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) ptr
    {-# LINE 272 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ ImageS { red_=red', green_=green', blue_=blue', opacity_=opacity' }
        poke ptr i = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (red_ i)
    {-# LINE 275 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr (green_ i)
    {-# LINE 276 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 80)) ptr (blue_ i)
    {-# LINE 277 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 120)) ptr (opacity_ i)
    {-# LINE 278 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable ImageChannelStatistics where
        sizeOf _    = 5 * sizeOf (undefined::CDouble)
        alignment _ = alignment (undefined::CDouble)
        peek ptr = do
          (maximum'::CDouble)            <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 284 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          (minimum'::CDouble)            <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 285 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          (mean'::CDouble)               <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 286 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          (standard_deviation'::CDouble) <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
    {-# LINE 287 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          (variance'::CDouble)           <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr
    {-# LINE 288 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ ImageCS { maximum=realToFrac maximum', minimum=realToFrac minimum',
                             mean=realToFrac mean', standard_deviation=realToFrac standard_deviation',
                             variance=realToFrac variance' }
        poke ptr i = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (maximum i)
    {-# LINE 293 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (minimum i)
    {-# LINE 294 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (mean i)
    {-# LINE 295 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr (standard_deviation i)
    {-# LINE 296 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr (variance i)
    {-# LINE 297 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable ExceptionInfo where
      sizeOf _    = 32 -- TODO
      alignment _ = alignment (undefined::CULong)
      peek ptr = do
          severity'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 304 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          reason'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
    {-# LINE 305 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          description'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 306 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          error_number' <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
    {-# LINE 307 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          mODULE'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 308 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          function'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
    {-# LINE 309 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          line'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
    {-# LINE 310 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          signature__'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
    {-# LINE 311 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ ExceptionInfo { severity=severity',
                                   reason=reason',
                                   description=description',
                                   error_number=error_number',
                                   mODULE=mODULE',
                                   function=function',
                                   line=line',
                                   signature__=signature__'}
      poke ptr e = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (severity e    )
    {-# LINE 321 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (reason e      )
    {-# LINE 322 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (description e )
    {-# LINE 323 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (error_number e)
    {-# LINE 324 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (mODULE e      )
    {-# LINE 325 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr (function e    )
    {-# LINE 326 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr (signature__ e )
    {-# LINE 327 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    -- it's unfortunate that we have to write this twice
    -- (maybe there's some wackier type system feature that
    -- would let us not do so)
    instance Storable (PixelPacket Word8) where
       sizeOf _ = 4*(sizeOf(undefined::Word8))
       alignment _ = alignment (undefined::Word8)
       peek ptr = do
          red'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 2)) ptr
    {-# LINE 336 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          green'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 1)) ptr
    {-# LINE 337 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          blue'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 338 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          opacity' <- ((\hsc_ptr -> peekByteOff hsc_ptr 3)) ptr
    {-# LINE 339 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ PixelPacket{ red=red', green=green',
                                blue=blue', opacity=opacity' }
       poke ptr p = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 2)) ptr (red p)
    {-# LINE 343 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (blue p)
    {-# LINE 344 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 1)) ptr (green p)
    {-# LINE 345 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 3)) ptr (opacity p)
    {-# LINE 346 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable CharArray where
      sizeOf _ = maxTextExtent
      alignment _ = 1
      peek _ = error "CharArray: peek is not implemented"
      poke _ _ = error "CharArray: poke is not implemented"

    instance Storable HImageInfo where
      sizeOf _ = ((8404))
    {-# LINE 355 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
      alignment _ = alignment (undefined::CULong)
      peek ptr = do
        -- again, ugh
          compression' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 359 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          temporary'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
    {-# LINE 360 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          adjoin'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 361 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          antialias'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
    {-# LINE 362 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          subimage'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 363 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          subrange'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
    {-# LINE 364 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          depth'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
    {-# LINE 365 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          size'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
    {-# LINE 366 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          tile'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr
    {-# LINE 367 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          page'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) ptr
    {-# LINE 368 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          interlace'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
    {-# LINE 369 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          endian'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 44)) ptr
    {-# LINE 370 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          units'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) ptr
    {-# LINE 371 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          quality'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 52)) ptr
    {-# LINE 372 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          sampling_factor' <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) ptr
    {-# LINE 373 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          server_name' <- ((\hsc_ptr -> peekByteOff hsc_ptr 60)) ptr
    {-# LINE 374 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          font'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) ptr
    {-# LINE 375 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          texture'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 68)) ptr
    {-# LINE 376 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          density'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) ptr
    {-# LINE 377 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          pointsize'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 76)) ptr
    {-# LINE 378 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          fuzz'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 84)) ptr
    {-# LINE 379 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          pen'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 92)) ptr
    {-# LINE 380 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          background_color' <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) ptr
    {-# LINE 381 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          border_color' <- ((\hsc_ptr -> peekByteOff hsc_ptr 100)) ptr
    {-# LINE 382 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          matte_color' <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) ptr
    {-# LINE 383 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          dither'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 108)) ptr
    {-# LINE 384 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          monochrome'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) ptr
    {-# LINE 385 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          colorspace'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) ptr
    {-# LINE 386 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          tYPE'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 124)) ptr
    {-# LINE 387 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          group'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 128)) ptr
    {-# LINE 388 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          verbose'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 132)) ptr
    {-# LINE 389 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          view'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 136)) ptr
    {-# LINE 390 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          progress'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 116)) ptr
    {-# LINE 391 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          authenticate' <- ((\hsc_ptr -> peekByteOff hsc_ptr 140)) ptr
    {-# LINE 392 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          client_data' <- ((\hsc_ptr -> peekByteOff hsc_ptr 144)) ptr
    {-# LINE 393 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          file'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 148)) ptr
    {-# LINE 394 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          magick'      <- peekStringFromCharArray $ ((\hsc_ptr -> hsc_ptr `plusPtr` 152)) ptr
    {-# LINE 395 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          filename'    <- peekStringFromCharArray $ ((\hsc_ptr -> hsc_ptr `plusPtr` 2205)) ptr
    {-# LINE 396 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          cache'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 4260)) ptr
    {-# LINE 397 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          definitions' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4264)) ptr
    {-# LINE 398 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          attributes'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 4268)) ptr
    {-# LINE 399 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ping'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 4272)) ptr
    {-# LINE 400 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          preview_type' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4276)) ptr
    {-# LINE 401 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          affirm'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 4280)) ptr
    {-# LINE 402 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          blob'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 4284)) ptr
    {-# LINE 403 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          lENGTH'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 4288)) ptr
    {-# LINE 404 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          unique'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 4292)) ptr
    {-# LINE 405 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          zero'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 6345)) ptr
    {-# LINE 406 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          signature'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 8400)) ptr
    {-# LINE 407 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ HImageInfo{compression=compression',
                              temporary=temporary',
                              adjoin=adjoin',
                              antialias=antialias',
                              subimage=subimage',
                              subrange=subrange',
                              depth=depth',
                              size=size',
                              tile=tile',
                              page=page',
                              interlace=interlace',
                              endian=endian',
                              units=units',
                              quality=quality',
                              sampling_factor=sampling_factor',
                              server_name=server_name',
                              font=font',
                              texture=texture',
                              density=density',
                              pointsize=pointsize',
                              fuzz=fuzz',
                              pen=pen',
                              background_color=background_color',
                              border_color=border_color',
                              matte_color=matte_color',
                              dither=dither',
                              monochrome=monochrome',
                              colorspace=colorspace',
                              tYPE=tYPE',
                              group=group',
                              verbose=verbose',
                              view=view',
                              progress=progress',
                              authenticate=authenticate',
                              client_data=client_data',
                              file=file',
                              magick=magick',
                              filename=filename',
                              cache=cache',
                              definitions=definitions',
                              attributes=attributes',
                              ping=ping',
                              preview_type=preview_type',
                              affirm=affirm',
                              blob=blob',
                              lENGTH=lENGTH',
                              unique=unique',
                              zero=zero',
                              signature=signature'}
      poke ptr hImageInfo = do
          -- ugh, boilerplate. is there a way to auto-generate this?
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (compression hImageInfo)
    {-# LINE 459 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (temporary hImageInfo)
    {-# LINE 460 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (adjoin hImageInfo)
    {-# LINE 461 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (antialias  hImageInfo)
    {-# LINE 462 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (subimage hImageInfo)
    {-# LINE 463 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr (subrange hImageInfo)
    {-# LINE 464 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 24))    ptr (depth hImageInfo)
    {-# LINE 465 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 28)) ptr (size  hImageInfo)
    {-# LINE 466 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr (tile hImageInfo)
    {-# LINE 467 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 36)) ptr (page hImageInfo)
    {-# LINE 468 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr (interlace hImageInfo)
    {-# LINE 469 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 44)) ptr (endian hImageInfo)
    {-# LINE 470 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 48)) ptr (units hImageInfo)
    {-# LINE 471 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 52)) ptr (quality hImageInfo    )
    {-# LINE 472 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 56)) ptr (sampling_factor hImageInfo)
    {-# LINE 473 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 60)) ptr (server_name hImageInfo)
    {-# LINE 474 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 64)) ptr (font hImageInfo)
    {-# LINE 475 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 68)) ptr (texture hImageInfo    )
    {-# LINE 476 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 72)) ptr (density hImageInfo    )
    {-# LINE 477 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 76)) ptr (pointsize hImageInfo  )
    {-# LINE 478 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 84)) ptr (fuzz hImageInfo       )
    {-# LINE 479 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 92)) ptr (pen hImageInfo        )
    {-# LINE 480 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 96)) ptr (background_color hImageInfo)
    {-# LINE 481 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 100)) ptr (border_color hImageInfo)
    {-# LINE 482 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 104)) ptr (matte_color hImageInfo)
    {-# LINE 483 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 108)) ptr (dither hImageInfo    )
    {-# LINE 484 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 112)) ptr (monochrome hImageInfo )
    {-# LINE 485 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 120)) ptr (colorspace hImageInfo)
    {-# LINE 486 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 124)) ptr (tYPE hImageInfo       )
    {-# LINE 487 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 128)) ptr (group hImageInfo      )
    {-# LINE 488 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 132)) ptr (verbose hImageInfo   )
    {-# LINE 489 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 136)) ptr (view  hImageInfo     )
    {-# LINE 490 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 140)) ptr (authenticate hImageInfo)
    {-# LINE 491 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 144)) ptr (client_data hImageInfo)
    {-# LINE 492 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 148)) ptr (file hImageInfo       )
    {-# LINE 493 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          -- the two char-array things: magick and filename
          pokeStringIntoCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 152)) ptr) (magick hImageInfo)
    {-# LINE 495 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          pokeStringIntoCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 2205)) ptr) (filename hImageInfo)
    {-# LINE 496 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          --
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4260)) ptr (cache hImageInfo   )
    {-# LINE 498 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4264)) ptr (definitions hImageInfo)
    {-# LINE 499 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4268)) ptr (attributes hImageInfo)
    {-# LINE 500 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4272)) ptr (ping       hImageInfo)
    {-# LINE 501 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4276)) ptr (preview_type hImageInfo)
    {-# LINE 502 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4280)) ptr (affirm hImageInfo)
    {-# LINE 503 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4284)) ptr (blob       hImageInfo)
    {-# LINE 504 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4288)) ptr (lENGTH     hImageInfo)
    {-# LINE 505 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4292)) ptr (unique     hImageInfo)
    {-# LINE 506 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 6345)) ptr (zero       hImageInfo)
    {-# LINE 507 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8400)) ptr (signature  hImageInfo)
    {-# LINE 508 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable HImage_ where
      sizeOf _ = ((6648))
    {-# LINE 511 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
      alignment _ = alignment (undefined::CULong)
      peek ptr = do
          storage_class' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 514 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          colorspace_'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
    {-# LINE 515 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          compression_'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 516 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          dither_'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) ptr
    {-# LINE 517 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          matte'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 518 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          columns'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
    {-# LINE 519 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          rows'          <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
    {-# LINE 520 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          colors'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) ptr
    {-# LINE 521 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          depth_'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr
    {-# LINE 522 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          colormap'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) ptr
    {-# LINE 523 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          background_color_' <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
    {-# LINE 524 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          border_color_' <- ((\hsc_ptr -> peekByteOff hsc_ptr 44)) ptr
    {-# LINE 525 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          matte_color_'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) ptr
    {-# LINE 526 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          gamma'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 52)) ptr
    {-# LINE 527 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          chromaticity'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 60)) ptr
    {-# LINE 528 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          orientation'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 156)) ptr
    {-# LINE 529 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          rendering_intent' <- ((\hsc_ptr -> peekByteOff hsc_ptr 160)) ptr
    {-# LINE 530 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          units_'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 164)) ptr
    {-# LINE 531 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          montage'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 168)) ptr
    {-# LINE 532 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          directory'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 172)) ptr
    {-# LINE 533 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          geometry'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 176)) ptr
    {-# LINE 534 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          offset'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 180)) ptr
    {-# LINE 535 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          x_resolution'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 184)) ptr
    {-# LINE 536 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          y_resolution'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 192)) ptr
    {-# LINE 537 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          page_'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 200)) ptr
    {-# LINE 538 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          tile_info'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 216)) ptr
    {-# LINE 539 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          blur'          <- ((\hsc_ptr -> peekByteOff hsc_ptr 232)) ptr
    {-# LINE 540 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          fuzz_'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 240)) ptr
    {-# LINE 541 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          fILTER'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 248)) ptr
    {-# LINE 542 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          interlace_'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 252)) ptr
    {-# LINE 543 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          endian_'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 256)) ptr
    {-# LINE 544 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          gravity'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 260)) ptr
    {-# LINE 545 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          compose'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 264)) ptr
    {-# LINE 546 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          dispose'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 268)) ptr
    {-# LINE 547 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          scene'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 272)) ptr
    {-# LINE 548 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          delay'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 276)) ptr
    {-# LINE 549 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          iterations'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 280)) ptr
    {-# LINE 550 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          total_colors'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 284)) ptr
    {-# LINE 551 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          start_loop'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 288)) ptr
    {-# LINE 552 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          eRROR'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 292)) ptr
    {-# LINE 553 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          timer'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 316)) ptr
    {-# LINE 554 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          client_data_'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 372)) ptr
    {-# LINE 555 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          filename_'     <- peekStringFromCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 376)) ptr)
    {-# LINE 556 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          magick_filename' <- peekStringFromCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 2429)) ptr)
    {-# LINE 557 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          magick_'       <- peekStringFromCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 4482)) ptr)
    {-# LINE 558 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          magick_rows'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 6540)) ptr
    {-# LINE 559 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          exception'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 6544)) ptr
    {-# LINE 560 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          previous'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 6576)) ptr
    {-# LINE 561 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          next'          <- ((\hsc_ptr -> peekByteOff hsc_ptr 6580)) ptr
    {-# LINE 562 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          profiles'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 6584)) ptr
    {-# LINE 563 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          is_monochrome' <- ((\hsc_ptr -> peekByteOff hsc_ptr 6588)) ptr
    {-# LINE 564 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          is_grayscale'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 6592)) ptr
    {-# LINE 565 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          taint'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 6596)) ptr
    {-# LINE 566 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          clip_mask'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 6600)) ptr
    {-# LINE 567 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          cache_'        <- ((\hsc_ptr -> peekByteOff hsc_ptr 6608)) ptr
    {-# LINE 568 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          attributes_'   <- ((\hsc_ptr -> peekByteOff hsc_ptr 6616)) ptr
    {-# LINE 569 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ascii85'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 6620)) ptr
    {-# LINE 570 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          blob_'         <- ((\hsc_ptr -> peekByteOff hsc_ptr 6624)) ptr
    {-# LINE 571 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          reference_count' <- ((\hsc_ptr -> peekByteOff hsc_ptr 6628)) ptr
    {-# LINE 572 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          semaphore'     <- ((\hsc_ptr -> peekByteOff hsc_ptr 6632)) ptr
    {-# LINE 573 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          logging'       <- ((\hsc_ptr -> peekByteOff hsc_ptr 6636)) ptr
    {-# LINE 574 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          list'          <- ((\hsc_ptr -> peekByteOff hsc_ptr 6640)) ptr
    {-# LINE 575 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          signature_'    <- ((\hsc_ptr -> peekByteOff hsc_ptr 6644)) ptr
    {-# LINE 576 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ HImage_ {
                       storage_class=storage_class',
                       colorspace_=colorspace_',
                       compression_=compression_',
                       dither_=dither_',
                       matte=matte',
                       columns=columns',
                       rows=rows',
                       colors=colors',
                       depth_=depth_',
                       colormap=colormap',
                       background_color_=background_color_',
                       border_color_=border_color_',
                       matte_color_=matte_color_',
                       gamma=gamma',
                       chromaticity=chromaticity',
                       orientation=orientation',
                       rendering_intent=rendering_intent',
                       units_=units_',
                       montage=montage',
                       directory=directory',
                       geometry=geometry',
                       offset=offset',
                       x_resolution=x_resolution',
                       y_resolution=y_resolution',
                       page_=page_',
                       tile_info=tile_info',
                       blur=blur',
                       fuzz_=fuzz_',
                       fILTER=fILTER',
                       interlace_=interlace_',
                       endian_=endian_',
                       gravity=gravity',
                       compose=compose',
                       dispose=dispose',
                       scene=scene',
                       delay=delay',
                       iterations=iterations',
                       total_colors=total_colors',
                       start_loop=start_loop',
                       eRROR=eRROR',
                       timer=timer',
                       client_data_=client_data_',
                       filename_=filename_',
                       magick_filename=magick_filename',
                       magick_=magick_',
                       magick_rows=magick_rows',
                       exception=exception',
                       previous=previous',
                       next=next',
                       profiles=profiles',
                       is_monochrome=is_monochrome',
                       is_grayscale=is_grayscale',
                       taint=taint',
                       clip_mask=clip_mask',
                       cache_=cache_',
                       attributes_=attributes_',
                       ascii85=ascii85',
                       blob_=blob_',
                       reference_count=reference_count',
                       semaphore=semaphore',
                       logging=logging',
                       list=list',
                       signature_=signature_'
                     }
      poke ptr hImage = do
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (storage_class hImage)
    {-# LINE 643 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (colorspace_ hImage)
    {-# LINE 644 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (compression_ hImage)
    {-# LINE 645 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 12)) ptr (dither_ hImage)
    {-# LINE 646 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (matte hImage)
    {-# LINE 647 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 20)) ptr (columns hImage)
    {-# LINE 648 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr (rows hImage)
    {-# LINE 649 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 28)) ptr (colors hImage)
    {-# LINE 650 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr (depth_ hImage)
    {-# LINE 651 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 36)) ptr (colormap hImage)
    {-# LINE 652 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr (background_color_ hImage)
    {-# LINE 653 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 44)) ptr (border_color_ hImage)
    {-# LINE 654 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 48)) ptr (matte_color_ hImage)
    {-# LINE 655 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 52)) ptr (gamma hImage)
    {-# LINE 656 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 60)) ptr (chromaticity hImage)
    {-# LINE 657 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 156)) ptr (orientation hImage)
    {-# LINE 658 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 160)) ptr (rendering_intent hImage)
    {-# LINE 659 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 164)) ptr (units_ hImage)
    {-# LINE 660 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 168)) ptr (montage hImage)
    {-# LINE 661 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 172)) ptr (directory hImage)
    {-# LINE 662 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 176)) ptr (geometry hImage)
    {-# LINE 663 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 180)) ptr (offset hImage)
    {-# LINE 664 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 184)) ptr (x_resolution hImage)
    {-# LINE 665 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 192)) ptr (y_resolution hImage)
    {-# LINE 666 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 200)) ptr (page_ hImage)
    {-# LINE 667 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 216)) ptr (tile_info hImage)
    {-# LINE 668 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 232)) ptr (blur hImage)
    {-# LINE 669 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 240)) ptr (fuzz_ hImage)
    {-# LINE 670 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 248)) ptr (fILTER hImage)
    {-# LINE 671 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 252)) ptr (interlace_ hImage)
    {-# LINE 672 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 256)) ptr (endian_ hImage)
    {-# LINE 673 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 260)) ptr (gravity hImage)
    {-# LINE 674 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 264)) ptr (compose hImage)
    {-# LINE 675 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 268)) ptr (dispose hImage)
    {-# LINE 676 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 272)) ptr (scene hImage)
    {-# LINE 677 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 276)) ptr (delay hImage)
    {-# LINE 678 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 280)) ptr (iterations hImage)
    {-# LINE 679 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 284)) ptr (total_colors hImage)
    {-# LINE 680 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 288)) ptr (start_loop hImage)
    {-# LINE 681 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 292)) ptr (eRROR hImage)
    {-# LINE 682 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 316)) ptr (timer hImage)
    {-# LINE 683 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 372)) ptr (client_data_ hImage)
    {-# LINE 684 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   pokeStringIntoCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 376)) ptr) (filename_ hImage)
    {-# LINE 685 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   pokeStringIntoCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 2429)) ptr) (magick_filename hImage)
    {-# LINE 686 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   pokeStringIntoCharArray (((\hsc_ptr -> hsc_ptr `plusPtr` 4482)) ptr) (magick_ hImage)
    {-# LINE 687 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6540)) ptr (magick_rows hImage)
    {-# LINE 688 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6544)) ptr (exception hImage)
    {-# LINE 689 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6576)) ptr (previous hImage)
    {-# LINE 690 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6580)) ptr (next hImage)
    {-# LINE 691 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6584)) ptr (profiles hImage)
    {-# LINE 692 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6588)) ptr (is_monochrome hImage)
    {-# LINE 693 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6592)) ptr (is_grayscale hImage)
    {-# LINE 694 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6596)) ptr (taint hImage)
    {-# LINE 695 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6600)) ptr (clip_mask hImage)
    {-# LINE 696 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6608)) ptr (cache_ hImage)
    {-# LINE 697 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6616)) ptr (attributes_ hImage)
    {-# LINE 698 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6620)) ptr (ascii85 hImage)
    {-# LINE 699 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6624)) ptr (blob_ hImage)
    {-# LINE 700 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6628)) ptr (reference_count hImage)
    {-# LINE 701 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6632)) ptr (semaphore hImage)
    {-# LINE 702 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6636)) ptr (logging hImage)
    {-# LINE 703 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6640)) ptr (list hImage)
    {-# LINE 704 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
                   ((\hsc_ptr -> pokeByteOff hsc_ptr 6644)) ptr (signature_ hImage)
    {-# LINE 705 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable Rectangle where
       sizeOf _ = (2*(sizeOf(undefined::CUInt))) +
                  (2*(sizeOf(undefined::CInt)))
       alignment _ = alignment (undefined::CInt)
       peek ptr = do
          width'  <- ((\hsc_ptr -> peekByteOff hsc_ptr 0))  ptr
    {-# LINE 712 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          height' <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) ptr
    {-# LINE 713 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          x'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 8))      ptr
    {-# LINE 714 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          y'      <- ((\hsc_ptr -> peekByteOff hsc_ptr 12))      ptr
    {-# LINE 715 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          return $ Rectangle{ width=width', height=height',
                              x=x', y=y'}
       poke ptr rect = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0))  ptr (width rect)
    {-# LINE 719 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 4)) ptr (height rect)
    {-# LINE 720 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8))      ptr (x rect)
    {-# LINE 721 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 12))      ptr (y rect)
    {-# LINE 722 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    instance Storable AffineMatrix where
       sizeOf _ = ((48))
    {-# LINE 725 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
       alignment _ = alignment (undefined::CDouble)
       peek ptr = do
         sx' <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr
    {-# LINE 728 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         rx' <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr
    {-# LINE 729 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         ry' <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
    {-# LINE 730 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         sy' <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
    {-# LINE 731 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         tx' <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr
    {-# LINE 732 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         ty' <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr
    {-# LINE 733 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
         return $ AffineMatrix { sx=sx', rx=rx', ry=ry', sy=sy', tx=tx', ty=ty' }
       poke ptr mat = do
          ((\hsc_ptr -> pokeByteOff hsc_ptr 0)) ptr (sx mat)
    {-# LINE 736 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) ptr (rx mat)
    {-# LINE 737 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) ptr (ry mat)
    {-# LINE 738 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 24)) ptr (sy mat)
    {-# LINE 739 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 32)) ptr (tx mat)
    {-# LINE 740 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 40)) ptr (ty mat)
    {-# LINE 741 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    -- shouldn't really have this magick number here
    maxTextExtent :: Int
    maxTextExtent = 2053

    hImageRows, hImageColumns :: HImage -> Word
    hImageRows    i = unsafePerformIO $ withForeignPtr (getImage i) $ return.fromIntegral.columns.unsafePerformIO.peek
    hImageColumns i = unsafePerformIO $ withForeignPtr (getImage i) $ return.fromIntegral.rows.unsafePerformIO.peek

    --------------- Filename handling

    class HasFilename a where
      setFilename :: a -> FilePath -> IO ()
      getFilename :: a -> FilePath

    instance HasFilename ImageNotLoaded where
       getFilename (ImageNotLoaded{ imageInfo = iInfo}) = iInfo-->filename
       setFilename (ImageNotLoaded{ imageInfo = iInfo}) s =
         setField (\ info -> info{filename=s}) iInfo

    instance HasFilename HImage where
       getFilename(HImage{ image=p, otherInfo=other }) =
          let filename1  = p-->filename_
              filename2  = getFilename other in
            assert (filename1 == filename2) filename1
       setFilename(HImage{ image=p, otherInfo=other }) s =
           setFilename other s >>
           setField (\ im -> im{filename_=s}) p

    ------------- Page setting
    setPage :: HImage -> Rectangle -> IO ()
    setPage hImage rect = applyImageFn hImage ((\hsc_ptr -> pokeByteOff hsc_ptr 200)) $ \f -> f rect
    {-# LINE 773 "Graphics/Transform/Magick/FFIHelpers.hsc" #-}

    ------------- Dealing with side-effecting GraphicsMagick functions
    sideEffectingOp :: (HImage -> IO CUInt) -> HImage -> HImage
    sideEffectingOp impureFun = (\ hImage -> unsafePerformIO $ do
       newImage <- cloneImage hImage
       withExceptions_ (impureFun newImage) "hsMagick: Error doing transformation"
         (== 0) (getExceptionInfo newImage)
       return newImage)

    --------- Utils
    -- The type emphasizes that we're doing something wantonly
    -- non-referentially-transparent

    cloneImageInfo :: ForeignPtr HImageInfo -> IO (ForeignPtr HImageInfo)
    cloneImageInfo fp = withForeignPtr fp $ \p ->
        mkFinalizedImageInfo =<< clone_image_info p

    cloneImage :: HImage -> IO HImage
    cloneImage hImage = do
       clonedImagePtr      <- withForeignPtr (getImage hImage) cloneImagePtr
       clonedImageInfo     <- cloneImageInfo (getImageInfo hImage)
       clonedExceptionInfo <- mkNewExceptionInfo
       return $ mkImage clonedImagePtr (mkUnloadedImage clonedImageInfo clonedExceptionInfo)
                                 -- 0 and 0 say that the cloned image should have the same
                                 -- size as the original. 1 says this should be an orphan
                                 -- image (not part of a list.)
         where cloneImagePtr p = withExceptions (withForeignPtr (getExceptionInfo hImage) $
                                                  clone_image p 0 0 1)
                                           "cloneImagePtr: error cloning image"
                                           (== nullPtr)
                                           (getExceptionInfo hImage)
    ----------- Exceptions

    mkNewExceptionInfo :: IO (ForeignPtr ExceptionInfo)
    mkNewExceptionInfo = mkFinalizedExceptionInfo =<< mkNewExceptionInfo_

    mkFinalizedExceptionInfo :: Ptr ExceptionInfo -> IO (ForeignPtr ExceptionInfo)
    mkFinalizedExceptionInfo p = FC.newForeignPtr p (destroyExceptionInfo p)

    nonFinalizedExceptionInfo :: Ptr ExceptionInfo -> IO (ForeignPtr ExceptionInfo)
    nonFinalizedExceptionInfo = newForeignPtr_

    mkNewExceptionInfo_ :: IO (Ptr ExceptionInfo)
    mkNewExceptionInfo_ = do
      infoPtr <- malloc
      get_exception_info infoPtr
      return infoPtr

    destroyExceptionInfo :: Ptr ExceptionInfo -> IO ()
    destroyExceptionInfo infoPtr = do
        destroy_exception_info infoPtr
        free infoPtr

    withTmpExceptionInfo :: (Ptr ExceptionInfo -> IO a) -> IO a
    withTmpExceptionInfo action = do
      infoPtr <- mkNewExceptionInfo_
      result <- action infoPtr
      result `seq` destroyExceptionInfo infoPtr
      return result

    ----------- Image info

    mkNewImageInfo :: IO (ForeignPtr HImageInfo)
    mkNewImageInfo = mkFinalizedImageInfo =<< mkNewImageInfo_

    mkFinalizedImageInfo :: Ptr HImageInfo -> IO (ForeignPtr HImageInfo)
    mkFinalizedImageInfo = newForeignPtr imageInfoFinalizer

    mkNewImageInfo_ :: IO (Ptr HImageInfo)
    mkNewImageInfo_ = clone_image_info nullPtr

    destroyImageInfo :: Ptr HImageInfo -> IO ()
    destroyImageInfo = destroy_image_info

    foreign import ccall "static magick/api.h &DestroyImageInfo"
        imageInfoFinalizer :: FunPtr (Ptr HImageInfo -> IO ())

    withTmpImageInfo :: (Ptr HImageInfo -> IO a) -> IO a
    withTmpImageInfo action = do
        imgInfo <- mkNewImageInfo_
        result <- action imgInfo
        result `seq` destroy_image_info imgInfo
        return result

    ----------- Both
    mkNewUnloadedImage :: ImageNotLoaded
    mkNewUnloadedImage = unsafePerformIO $ do
      e <- mkNewExceptionInfo
      i <- mkNewImageInfo
      return $ mkUnloadedImage i e
    ----------- Type conversion
    -- meant to convert an integ>ral type to a C enum type
    toCEnum :: (Enum a, Num b) => a -> b
    toCEnum = fromIntegral.fromEnum
    ----------- dealing with pointers whose values may not be present
    maybeToPtr :: Storable a => Maybe a -> Ptr a -> IO (Ptr a)
    maybeToPtr Nothing _      = return nullPtr
    maybeToPtr (Just stuff) p = poke p stuff >> return p