Skip to content

Commit

Permalink
Merge pull request opencv#4072 from vladimir-dudnik:opencl-opencv-int…
Browse files Browse the repository at this point in the history
…erop
  • Loading branch information
alalek committed Jun 19, 2015
2 parents 6ab9df5 + 217dd63 commit 59ed7d0
Show file tree
Hide file tree
Showing 7 changed files with 1,423 additions and 18 deletions.
74 changes: 72 additions & 2 deletions modules/core/include/opencv2/core/directx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,28 @@ using namespace cv::ocl;
//! @{

// TODO static functions in the Context class
//! @brief Creates OpenCL context from D3D11 device
//
//! @param pD3D11Device - pointer to D3D11 device
//! @return Returns reference to OpenCL Context
CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);

//! @brief Creates OpenCL context from D3D10 device
//
//! @param pD3D10Device - pointer to D3D10 device
//! @return Returns reference to OpenCL Context
CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);

//! @brief Creates OpenCL context from Direct3DDevice9Ex device
//
//! @param pDirect3DDevice9Ex - pointer to Direct3DDevice9Ex device
//! @return Returns reference to OpenCL Context
CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);

//! @brief Creates OpenCL context from Direct3DDevice9 device
//
//! @param pDirect3DDevice9 - pointer to Direct3Device9 device
//! @return Returns reference to OpenCL Context
CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);

//! @}
Expand All @@ -83,19 +102,70 @@ CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDire
//! @addtogroup core_directx
//! @{

//! @brief Converts InputArray to ID3D11Texture2D
//
//! @note Note: function does memory copy from src to
//! pD3D11Texture2D
//
//! @param src - source InputArray
//! @param pD3D11Texture2D - destination D3D11 texture
CV_EXPORTS void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D);

//! @brief Converts ID3D11Texture2D to OutputArray
//
//! @note Note: function does memory copy from pD3D11Texture2D
//! to dst
//
//! @param pD3D11Texture2D - source D3D11 texture
//! @param dst - destination OutputArray
CV_EXPORTS void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst);

//! @brief Converts InputArray to ID3D10Texture2D
//
//! @note Note: function does memory copy from src to
//! pD3D10Texture2D
//
//! @param src - source InputArray
//! @param pD3D10Texture2D - destination D3D10 texture
CV_EXPORTS void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D);

//! @brief Converts ID3D10Texture2D to OutputArray
//
//! @note Note: function does memory copy from pD3D10Texture2D
//! to dst
//
//! @param pD3D10Texture2D - source D3D10 texture
//! @param dst - destination OutputArray
CV_EXPORTS void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst);

//! @brief Converts InputArray to IDirect3DSurface9
//
//! @note Note: function does memory copy from src to
//! pDirect3DSurface9
//
//! @param src - source InputArray
//! @param pDirect3DSurface9 - destination D3D10 texture
//! @param surfaceSharedHandle - shared handle
CV_EXPORTS void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurface9, void* surfaceSharedHandle = NULL);

//! @brief Converts IDirect3DSurface9 to OutputArray
//
//! @note Note: function does memory copy from pDirect3DSurface9
//! to dst
//
//! @param pDirect3DSurface9 - source D3D10 texture
//! @param dst - destination OutputArray
//! @param surfaceSharedHandle - shared handle
CV_EXPORTS void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArray dst, void* surfaceSharedHandle = NULL);

// Get OpenCV type from DirectX type, return -1 if there is no equivalent
//! @brief Get OpenCV type from DirectX type
//! @param iDXGI_FORMAT - enum DXGI_FORMAT for D3D10/D3D11
//! @return OpenCV type or -1 if there is no equivalent
CV_EXPORTS int getTypeFromDXGI_FORMAT(const int iDXGI_FORMAT); // enum DXGI_FORMAT for D3D10/D3D11

// Get OpenCV type from DirectX type, return -1 if there is no equivalent
//! @brief Get OpenCV type from DirectX type
//! @param iD3DFORMAT - enum D3DTYPE for D3D9
//! @return OpenCV type or -1 if there is no equivalent
CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D3D9

//! @}
Expand Down
52 changes: 52 additions & 0 deletions modules/core/include/opencv2/core/ocl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,58 @@ class CV_EXPORTS Platform
Impl* p;
};

/*
//! @brief Attaches OpenCL context to OpenCV
//
//! @note Note:
// OpenCV will check if available OpenCL platform has platformName name,
// then assign context to OpenCV and call clRetainContext function.
// The deviceID device will be used as target device and new command queue
// will be created.
//
// Params:
//! @param platformName - name of OpenCL platform to attach,
//! this string is used to check if platform is available
//! to OpenCV at runtime
//! @param platfromID - ID of platform attached context was created for
//! @param context - OpenCL context to be attached to OpenCV
//! @param deviceID - ID of device, must be created from attached context
*/
CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID);

/*
//! @brief Convert OpenCL buffer to UMat
//
//! @note Note:
// OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV.
// Memory content is not copied from clBuffer to UMat. Instead, buffer handle assigned
// to UMat and clRetainMemObject is called.
//
// Params:
//! @param cl_mem_buffer - source clBuffer handle
//! @param step - num of bytes in single row
//! @param rows - number of rows
//! @param cols - number of cols
//! @param type - OpenCV type of image
//! @param dst - destination UMat
*/
CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst);

/*
//! @brief Convert OpenCL image2d_t to UMat
//
//! @note Note:
// OpenCL image2d_t (cl_mem_image), should be compatible with OpenCV
// UMat formats.
// Memory content is copied from image to UMat with
// clEnqueueCopyImageToBuffer function.
//
// Params:
//! @param cl_mem_image - source image2d_t handle
//! @param dst - destination UMat
*/
CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst);

// TODO Move to internal header
void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);

Expand Down
Loading

0 comments on commit 59ed7d0

Please sign in to comment.