/usr/lib/hugs/packages/OpenGL/Graphics/Rendering/OpenGL/GL/PixelRectangles/Convolution.hs is in libhugs-opengl-bundled 98.200609.21-5.4+b3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | --------------------------------------------------------------------------------
-- |
-- Module : Graphics.Rendering.OpenGL.GL.PixelRectangles.Convolution
-- Copyright : (c) Sven Panne 2002-2005
-- License : BSD-style (see the file libraries/OpenGL/LICENSE)
--
-- Maintainer : sven.panne@aedion.de
-- Stability : provisional
-- Portability : portable
--
-- This module corresponds to a part of section 3.6.1 (Pixel Storage Modes) of
-- the OpenGL 1.5 specs.
--
--------------------------------------------------------------------------------
module Graphics.Rendering.OpenGL.GL.PixelRectangles.Convolution (
ConvolutionTarget(..), convolution,
convolutionFilter1D, getConvolutionFilter1D,
convolutionFilter2D, getConvolutionFilter2D,
separableFilter2D, getSeparableFilter2D,
copyConvolutionFilter1D, copyConvolutionFilter2D,
convolutionWidth, convolutionHeight,
maxConvolutionWidth, maxConvolutionHeight,
ConvolutionBorderMode(..), convolutionBorderMode,
convolutionFilterScale, convolutionFilterBias,
) where
import Foreign.Marshal.Alloc ( alloca )
import Foreign.Marshal.Utils ( with )
import Foreign.Ptr ( Ptr, nullPtr )
import Foreign.Storable ( Storable(..) )
import Graphics.Rendering.OpenGL.GL.Capability (
EnableCap(CapConvolution1D, CapConvolution2D,CapSeparable2D),
makeCapability )
import Graphics.Rendering.OpenGL.GL.BasicTypes (
GLenum, GLint, GLsizei, GLfloat, Capability )
import Graphics.Rendering.OpenGL.GL.CoordTrans ( Position(..), Size(..) )
import Graphics.Rendering.OpenGL.GL.Extensions (
FunPtr, unsafePerformIO, Invoker, getProcAddress )
import Graphics.Rendering.OpenGL.GL.PeekPoke ( peek1 )
import Graphics.Rendering.OpenGL.GL.PixelRectangles.ColorTable (
PixelInternalFormat )
import Graphics.Rendering.OpenGL.GL.PixelRectangles.Rasterization (
PixelData(..) )
import Graphics.Rendering.OpenGL.GL.PixelData ( withPixelData )
import Graphics.Rendering.OpenGL.GL.Texturing.PixelInternalFormat (
marshalPixelInternalFormat' )
import Graphics.Rendering.OpenGL.GL.StateVar (
GettableStateVar, makeGettableStateVar, StateVar, makeStateVar )
import Graphics.Rendering.OpenGL.GL.VertexSpec ( Color4(..) )
import Graphics.Rendering.OpenGL.GLU.ErrorsInternal (
recordInvalidValue )
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
data ConvolutionTarget =
Convolution1D
| Convolution2D
| Separable2D
deriving ( Eq, Ord, Show )
marshalConvolutionTarget :: ConvolutionTarget -> GLenum
marshalConvolutionTarget x = case x of
Convolution1D -> 0x8010
Convolution2D -> 0x8011
Separable2D -> 0x8012
convolutionTargetToEnableCap :: ConvolutionTarget -> EnableCap
convolutionTargetToEnableCap x = case x of
Convolution1D -> CapConvolution1D
Convolution2D -> CapConvolution2D
Separable2D -> CapSeparable2D
--------------------------------------------------------------------------------
convolution :: ConvolutionTarget -> StateVar Capability
convolution = makeCapability . convolutionTargetToEnableCap
--------------------------------------------------------------------------------
convolutionFilter1D :: PixelInternalFormat -> GLsizei -> PixelData a -> IO ()
convolutionFilter1D int w pd =
withPixelData pd $
glConvolutionFilter1D
(marshalConvolutionTarget Convolution1D)
(marshalPixelInternalFormat' int) w
foreign import ccall unsafe "dynamic" dyn_glConvolutionFilter1D :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO ()) ; glConvolutionFilter1D :: (GLenum -> GLenum -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO ()) ; glConvolutionFilter1D = dyn_glConvolutionFilter1D ptr_glConvolutionFilter1D ; ptr_glConvolutionFilter1D :: FunPtr a ; ptr_glConvolutionFilter1D = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glConvolutionFilter1D")) ; {-# NOINLINE ptr_glConvolutionFilter1D #-}
--------------------------------------------------------------------------------
getConvolutionFilter1D :: PixelData a -> IO ()
getConvolutionFilter1D = getConvolutionFilter Convolution1D
getConvolutionFilter :: ConvolutionTarget -> PixelData a -> IO ()
getConvolutionFilter t pd =
withPixelData pd $ glGetConvolutionFilter (marshalConvolutionTarget t)
foreign import ccall unsafe "dynamic" dyn_glGetConvolutionFilter :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLenum -> Ptr a -> IO ()) ; glGetConvolutionFilter :: (GLenum -> GLenum -> GLenum -> Ptr a -> IO ()) ; glGetConvolutionFilter = dyn_glGetConvolutionFilter ptr_glGetConvolutionFilter ; ptr_glGetConvolutionFilter :: FunPtr a ; ptr_glGetConvolutionFilter = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glGetConvolutionFilter")) ; {-# NOINLINE ptr_glGetConvolutionFilter #-}
--------------------------------------------------------------------------------
convolutionFilter2D :: PixelInternalFormat -> Size -> PixelData a -> IO ()
convolutionFilter2D int (Size w h) pd =
withPixelData pd $
glConvolutionFilter2D
(marshalConvolutionTarget Convolution2D)
(marshalPixelInternalFormat' int) w h
foreign import ccall unsafe "dynamic" dyn_glConvolutionFilter2D :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO ()) ; glConvolutionFilter2D :: (GLenum -> GLenum -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> IO ()) ; glConvolutionFilter2D = dyn_glConvolutionFilter2D ptr_glConvolutionFilter2D ; ptr_glConvolutionFilter2D :: FunPtr a ; ptr_glConvolutionFilter2D = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glConvolutionFilter2D")) ; {-# NOINLINE ptr_glConvolutionFilter2D #-}
--------------------------------------------------------------------------------
getConvolutionFilter2D :: PixelData a -> IO ()
getConvolutionFilter2D = getConvolutionFilter Convolution2D
--------------------------------------------------------------------------------
separableFilter2D ::
PixelInternalFormat -> Size -> PixelData a -> PixelData a -> IO ()
separableFilter2D int (Size w h) pdRow pdCol =
withPixelData pdRow $ \f1 d1 p1 ->
withPixelData pdCol $ \f2 d2 p2 ->
if f1 == f2 && d1 == d2
then glSeparableFilter2D
(marshalConvolutionTarget Separable2D)
(marshalPixelInternalFormat' int) w h f1 d1 p1 p2
else recordInvalidValue
foreign import ccall unsafe "dynamic" dyn_glSeparableFilter2D :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> Ptr a -> IO ()) ; glSeparableFilter2D :: (GLenum -> GLenum -> GLsizei -> GLsizei -> GLenum -> GLenum -> Ptr a -> Ptr a -> IO ()) ; glSeparableFilter2D = dyn_glSeparableFilter2D ptr_glSeparableFilter2D ; ptr_glSeparableFilter2D :: FunPtr a ; ptr_glSeparableFilter2D = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glSeparableFilter2D")) ; {-# NOINLINE ptr_glSeparableFilter2D #-}
--------------------------------------------------------------------------------
getSeparableFilter2D :: PixelData a -> PixelData a -> IO ()
getSeparableFilter2D pdRow pdCol =
withPixelData pdRow $ \f1 d1 p1 ->
withPixelData pdCol $ \f2 d2 p2 ->
if f1 == f2 && d1 == d2
then glGetSeparableFilter
(marshalConvolutionTarget Separable2D) f1 d1 p1 p2 nullPtr
else recordInvalidValue
foreign import ccall unsafe "dynamic" dyn_glGetSeparableFilter :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLenum -> Ptr a -> Ptr a -> Ptr a -> IO ()) ; glGetSeparableFilter :: (GLenum -> GLenum -> GLenum -> Ptr a -> Ptr a -> Ptr a -> IO ()) ; glGetSeparableFilter = dyn_glGetSeparableFilter ptr_glGetSeparableFilter ; ptr_glGetSeparableFilter :: FunPtr a ; ptr_glGetSeparableFilter = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glGetSeparableFilter")) ; {-# NOINLINE ptr_glGetSeparableFilter #-}
--------------------------------------------------------------------------------
copyConvolutionFilter1D :: PixelInternalFormat -> Position -> GLsizei -> IO ()
copyConvolutionFilter1D int (Position x y) =
glCopyConvolutionFilter1D
(marshalConvolutionTarget Convolution1D) (marshalPixelInternalFormat' int)
x y
foreign import ccall unsafe "dynamic" dyn_glCopyConvolutionFilter1D :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLint -> GLint -> GLsizei -> IO ()) ; glCopyConvolutionFilter1D :: (GLenum -> GLenum -> GLint -> GLint -> GLsizei -> IO ()) ; glCopyConvolutionFilter1D = dyn_glCopyConvolutionFilter1D ptr_glCopyConvolutionFilter1D ; ptr_glCopyConvolutionFilter1D :: FunPtr a ; ptr_glCopyConvolutionFilter1D = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glCopyConvolutionFilter1D")) ; {-# NOINLINE ptr_glCopyConvolutionFilter1D #-}
--------------------------------------------------------------------------------
copyConvolutionFilter2D :: PixelInternalFormat -> Position -> Size -> IO ()
copyConvolutionFilter2D int (Position x y) (Size w h) =
glCopyConvolutionFilter2D
(marshalConvolutionTarget Convolution2D) (marshalPixelInternalFormat' int)
x y w h
foreign import ccall unsafe "dynamic" dyn_glCopyConvolutionFilter2D :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLint -> GLint -> GLsizei -> GLsizei -> IO ()) ; glCopyConvolutionFilter2D :: (GLenum -> GLenum -> GLint -> GLint -> GLsizei -> GLsizei -> IO ()) ; glCopyConvolutionFilter2D = dyn_glCopyConvolutionFilter2D ptr_glCopyConvolutionFilter2D ; ptr_glCopyConvolutionFilter2D :: FunPtr a ; ptr_glCopyConvolutionFilter2D = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glCopyConvolutionFilter2D")) ; {-# NOINLINE ptr_glCopyConvolutionFilter2D #-}
--------------------------------------------------------------------------------
data ConvolutionParameter =
ConvolutionBorderColor
| ConvolutionBorderMode
| ConvolutionFilterScale
| ConvolutionFilterBias
| ConvolutionFormat
| ConvolutionWidth
| ConvolutionHeight
| MaxConvolutionWidth
| MaxConvolutionHeight
deriving ( Eq, Ord, Show )
marshalConvolutionParameter :: ConvolutionParameter -> GLenum
marshalConvolutionParameter x = case x of
ConvolutionBorderColor -> 0x8154
ConvolutionBorderMode -> 0x8013
ConvolutionFilterScale -> 0x8014
ConvolutionFilterBias -> 0x8015
ConvolutionFormat -> 0x8017
ConvolutionWidth -> 0x8018
ConvolutionHeight -> 0x8019
MaxConvolutionWidth -> 0x801a
MaxConvolutionHeight -> 0x801b
--------------------------------------------------------------------------------
convolutionWidth :: ConvolutionTarget -> GettableStateVar GLsizei
convolutionWidth t = convolutionParameteri t ConvolutionWidth
convolutionHeight :: ConvolutionTarget -> GettableStateVar GLsizei
convolutionHeight t = convolutionParameteri t ConvolutionHeight
maxConvolutionWidth :: ConvolutionTarget -> GettableStateVar GLsizei
maxConvolutionWidth t = convolutionParameteri t MaxConvolutionWidth
maxConvolutionHeight :: ConvolutionTarget -> GettableStateVar GLsizei
maxConvolutionHeight t = convolutionParameteri t MaxConvolutionHeight
convolutionParameteri ::
ConvolutionTarget -> ConvolutionParameter -> GettableStateVar GLsizei
convolutionParameteri t p =
makeGettableStateVar (getConvolutionParameteri fromIntegral t p)
getConvolutionParameteri ::
(GLint -> a) -> ConvolutionTarget -> ConvolutionParameter -> IO a
getConvolutionParameteri f t p =
alloca $ \buf -> do
glGetConvolutionParameteriv
(marshalConvolutionTarget t) (marshalConvolutionParameter p) buf
peek1 f buf
foreign import ccall unsafe "dynamic" dyn_glGetConvolutionParameteriv :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> Ptr GLint -> IO ()) ; glGetConvolutionParameteriv :: (GLenum -> GLenum -> Ptr GLint -> IO ()) ; glGetConvolutionParameteriv = dyn_glGetConvolutionParameteriv ptr_glGetConvolutionParameteriv ; ptr_glGetConvolutionParameteriv :: FunPtr a ; ptr_glGetConvolutionParameteriv = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glGetConvolutionParameteriv")) ; {-# NOINLINE ptr_glGetConvolutionParameteriv #-}
--------------------------------------------------------------------------------
data ConvolutionBorderMode' =
Reduce'
| ConstantBorder'
| ReplicateBorder'
marshalConvolutionBorderMode' :: ConvolutionBorderMode' -> GLint
marshalConvolutionBorderMode' x = case x of
Reduce' -> 0x8016
ConstantBorder' -> 0x8151
ReplicateBorder' -> 0x8153
unmarshalConvolutionBorderMode' :: GLint -> ConvolutionBorderMode'
unmarshalConvolutionBorderMode' x
| x == 0x8016 = Reduce'
| x == 0x8151 = ConstantBorder'
| x == 0x8153 = ReplicateBorder'
| otherwise = error ("unmarshalConvolutionBorderMode': illegal value " ++ show x)
--------------------------------------------------------------------------------
data ConvolutionBorderMode =
Reduce
| ConstantBorder (Color4 GLfloat)
| ReplicateBorder
deriving ( Eq, Ord, Show )
--------------------------------------------------------------------------------
convolutionBorderMode :: ConvolutionTarget -> StateVar ConvolutionBorderMode
convolutionBorderMode t =
makeStateVar (getConvolutionBorderMode t) (setConvolutionBorderMode t)
getConvolutionBorderMode :: ConvolutionTarget -> IO ConvolutionBorderMode
getConvolutionBorderMode t = do
mode <- getConvolutionParameteri
unmarshalConvolutionBorderMode' t ConvolutionBorderMode
case mode of
Reduce' -> return Reduce
ConstantBorder' -> do
c <- getConvolutionParameterC4f t ConvolutionBorderColor
return $ ConstantBorder c
ReplicateBorder' -> return ReplicateBorder
setConvolutionBorderMode :: ConvolutionTarget -> ConvolutionBorderMode -> IO ()
setConvolutionBorderMode t mode = do
let setBM = setConvolutionParameteri
marshalConvolutionBorderMode' t ConvolutionBorderMode
case mode of
Reduce -> setBM Reduce'
ConstantBorder c -> do
setBM ConstantBorder'
convolutionParameterC4f t ConvolutionBorderColor c
ReplicateBorder -> setBM ReplicateBorder'
setConvolutionParameteri ::
(a -> GLint) -> ConvolutionTarget -> ConvolutionParameter -> a -> IO ()
setConvolutionParameteri f t p x =
glConvolutionParameteri
(marshalConvolutionTarget t) (marshalConvolutionParameter p) (f x)
foreign import ccall unsafe "dynamic" dyn_glConvolutionParameteri :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> GLint -> IO ()) ; glConvolutionParameteri :: (GLenum -> GLenum -> GLint -> IO ()) ; glConvolutionParameteri = dyn_glConvolutionParameteri ptr_glConvolutionParameteri ; ptr_glConvolutionParameteri :: FunPtr a ; ptr_glConvolutionParameteri = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glConvolutionParameteri")) ; {-# NOINLINE ptr_glConvolutionParameteri #-}
--------------------------------------------------------------------------------
convolutionFilterScale :: ConvolutionTarget -> StateVar (Color4 GLfloat)
convolutionFilterScale = convolutionC4f ConvolutionFilterScale
convolutionFilterBias :: ConvolutionTarget -> StateVar (Color4 GLfloat)
convolutionFilterBias = convolutionC4f ConvolutionFilterBias
convolutionC4f ::
ConvolutionParameter -> ConvolutionTarget -> StateVar (Color4 GLfloat)
convolutionC4f p t =
makeStateVar (getConvolutionParameterC4f t p) (convolutionParameterC4f t p)
getConvolutionParameterC4f ::
ConvolutionTarget -> ConvolutionParameter -> IO (Color4 GLfloat)
getConvolutionParameterC4f t p =
alloca $ \buf -> do
glGetConvolutionParameterfv
(marshalConvolutionTarget t) (marshalConvolutionParameter p) buf
peek buf
foreign import ccall unsafe "dynamic" dyn_glGetConvolutionParameterfv :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()) ; glGetConvolutionParameterfv :: (GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()) ; glGetConvolutionParameterfv = dyn_glGetConvolutionParameterfv ptr_glGetConvolutionParameterfv ; ptr_glGetConvolutionParameterfv :: FunPtr a ; ptr_glGetConvolutionParameterfv = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glGetConvolutionParameterfv")) ; {-# NOINLINE ptr_glGetConvolutionParameterfv #-}
convolutionParameterC4f ::
ConvolutionTarget -> ConvolutionParameter -> Color4 GLfloat -> IO ()
convolutionParameterC4f t p c =
with c $
glConvolutionParameterfv
(marshalConvolutionTarget t) (marshalConvolutionParameter p)
foreign import ccall unsafe "dynamic" dyn_glConvolutionParameterfv :: Graphics.Rendering.OpenGL.GL.Extensions.Invoker (GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()) ; glConvolutionParameterfv :: (GLenum -> GLenum -> Ptr (Color4 GLfloat) -> IO ()) ; glConvolutionParameterfv = dyn_glConvolutionParameterfv ptr_glConvolutionParameterfv ; ptr_glConvolutionParameterfv :: FunPtr a ; ptr_glConvolutionParameterfv = unsafePerformIO (Graphics.Rendering.OpenGL.GL.Extensions.getProcAddress ("GL_ARB_imaging") ("glConvolutionParameterfv")) ; {-# NOINLINE ptr_glConvolutionParameterfv #-}
|