Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
1f08d8cb
Commit
1f08d8cb
authored
Oct 24, 2014
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3367 from akarsakov:ocl_image2d
parents
1fbad26f
237cb931
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
1 deletion
+108
-1
ocl.cpp
modules/core/src/ocl.cpp
+11
-1
test_image2d.cpp
modules/core/test/ocl/test_image2d.cpp
+97
-0
No files found.
modules/core/src/ocl.cpp
View file @
1f08d8cb
...
@@ -4629,6 +4629,9 @@ struct Image2D::Impl
...
@@ -4629,6 +4629,9 @@ struct Image2D::Impl
static
bool
isFormatSupported
(
cl_image_format
format
)
static
bool
isFormatSupported
(
cl_image_format
format
)
{
{
if
(
!
haveOpenCL
())
CV_Error
(
Error
::
OpenCLApiCallError
,
"OpenCL runtime not found!"
);
cl_context
context
=
(
cl_context
)
Context
::
getDefault
().
ptr
();
cl_context
context
=
(
cl_context
)
Context
::
getDefault
().
ptr
();
// Figure out how many formats are supported by this context.
// Figure out how many formats are supported by this context.
cl_uint
numFormats
=
0
;
cl_uint
numFormats
=
0
;
...
@@ -4652,6 +4655,10 @@ struct Image2D::Impl
...
@@ -4652,6 +4655,10 @@ struct Image2D::Impl
void
init
(
const
UMat
&
src
,
bool
norm
,
bool
alias
)
void
init
(
const
UMat
&
src
,
bool
norm
,
bool
alias
)
{
{
if
(
!
haveOpenCL
())
CV_Error
(
Error
::
OpenCLApiCallError
,
"OpenCL runtime not found!"
);
CV_Assert
(
!
src
.
empty
());
CV_Assert
(
ocl
::
Device
::
getDefault
().
imageSupport
());
CV_Assert
(
ocl
::
Device
::
getDefault
().
imageSupport
());
int
err
,
depth
=
src
.
depth
(),
cn
=
src
.
channels
();
int
err
,
depth
=
src
.
depth
(),
cn
=
src
.
channels
();
...
@@ -4661,6 +4668,9 @@ struct Image2D::Impl
...
@@ -4661,6 +4668,9 @@ struct Image2D::Impl
if
(
!
isFormatSupported
(
format
))
if
(
!
isFormatSupported
(
format
))
CV_Error
(
Error
::
OpenCLApiCallError
,
"Image format is not supported"
);
CV_Error
(
Error
::
OpenCLApiCallError
,
"Image format is not supported"
);
if
(
alias
&&
!
src
.
handle
(
ACCESS_RW
))
CV_Error
(
Error
::
OpenCLApiCallError
,
"Incorrect UMat, handle is null"
);
cl_context
context
=
(
cl_context
)
Context
::
getDefault
().
ptr
();
cl_context
context
=
(
cl_context
)
Context
::
getDefault
().
ptr
();
cl_command_queue
queue
=
(
cl_command_queue
)
Queue
::
getDefault
().
ptr
();
cl_command_queue
queue
=
(
cl_command_queue
)
Queue
::
getDefault
().
ptr
();
...
@@ -4745,7 +4755,7 @@ bool Image2D::canCreateAlias(const UMat &m)
...
@@ -4745,7 +4755,7 @@ bool Image2D::canCreateAlias(const UMat &m)
{
{
bool
ret
=
false
;
bool
ret
=
false
;
const
Device
&
d
=
ocl
::
Device
::
getDefault
();
const
Device
&
d
=
ocl
::
Device
::
getDefault
();
if
(
d
.
imageFromBufferSupport
())
if
(
d
.
imageFromBufferSupport
()
&&
!
m
.
empty
()
)
{
{
// This is the required pitch alignment in pixels
// This is the required pitch alignment in pixels
uint
pitchAlign
=
d
.
imagePitchAlignment
();
uint
pitchAlign
=
d
.
imagePitchAlignment
();
...
...
modules/core/test/ocl/test_image2d.cpp
0 → 100644
View file @
1f08d8cb
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Copyright (C) 2014, Itseez, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
#include "../test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
namespace
cvtest
{
namespace
ocl
{
TEST
(
Image2D
,
createAliasEmptyUMat
)
{
if
(
cv
::
ocl
::
haveOpenCL
())
{
UMat
um
;
EXPECT_FALSE
(
cv
::
ocl
::
Image2D
::
canCreateAlias
(
um
));
}
else
std
::
cout
<<
"OpenCL runtime not found. Test skipped."
<<
std
::
endl
;
}
TEST
(
Image2D
,
createImage2DWithEmptyUMat
)
{
if
(
cv
::
ocl
::
haveOpenCL
())
{
UMat
um
;
EXPECT_ANY_THROW
(
cv
::
ocl
::
Image2D
image
(
um
));
}
else
std
::
cout
<<
"OpenCL runtime not found. Test skipped."
<<
std
::
endl
;
}
TEST
(
Image2D
,
createAlias
)
{
if
(
cv
::
ocl
::
haveOpenCL
())
{
const
cv
::
ocl
::
Device
&
d
=
cv
::
ocl
::
Device
::
getDefault
();
int
minor
=
d
.
deviceVersionMinor
(),
major
=
d
.
deviceVersionMajor
();
// aliases is OpenCL 1.2 extension
if
(
1
<
major
||
(
1
==
major
&&
2
<=
minor
))
{
UMat
um
(
128
,
128
,
CV_8UC1
);
bool
isFormatSupported
=
false
,
canCreateAlias
=
false
;
EXPECT_NO_THROW
(
isFormatSupported
=
cv
::
ocl
::
Image2D
::
isFormatSupported
(
CV_8U
,
1
,
false
));
EXPECT_NO_THROW
(
canCreateAlias
=
cv
::
ocl
::
Image2D
::
canCreateAlias
(
um
));
if
(
isFormatSupported
&&
canCreateAlias
)
{
EXPECT_NO_THROW
(
cv
::
ocl
::
Image2D
image
(
um
,
false
,
true
));
}
else
std
::
cout
<<
"Impossible to create alias for selected image. Test skipped."
<<
std
::
endl
;
}
}
else
std
::
cout
<<
"OpenCL runtime not found. Test skipped"
<<
std
::
endl
;
}
TEST
(
Image2D
,
turnOffOpenCL
)
{
if
(
cv
::
ocl
::
haveOpenCL
())
{
// save the current state
bool
useOCL
=
cv
::
ocl
::
useOpenCL
();
bool
isFormatSupported
=
false
;
cv
::
ocl
::
setUseOpenCL
(
true
);
UMat
um
(
128
,
128
,
CV_8UC1
);
cv
::
ocl
::
setUseOpenCL
(
false
);
EXPECT_NO_THROW
(
isFormatSupported
=
cv
::
ocl
::
Image2D
::
isFormatSupported
(
CV_8U
,
1
,
true
));
if
(
isFormatSupported
)
{
EXPECT_NO_THROW
(
cv
::
ocl
::
Image2D
image
(
um
));
}
else
std
::
cout
<<
"CV_8UC1 is not supported for OpenCL images. Test skipped."
<<
std
::
endl
;
// reset state to the previous one
cv
::
ocl
::
setUseOpenCL
(
useOCL
);
}
else
std
::
cout
<<
"OpenCL runtime not found. Test skipped."
<<
std
::
endl
;
}
}
}
// namespace cvtest::ocl
#endif // HAVE_OPENCL
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment