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
fd90efc9
Commit
fd90efc9
authored
Apr 11, 2014
by
Andrey Pavlenko
Committed by
OpenCV Buildbot
Apr 11, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2593 from arkunze:pullreq/140319-color
parents
6bfbcf02
785acc18
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
418 additions
and
158 deletions
+418
-158
color.cpp
modules/imgproc/src/color.cpp
+40
-25
cvtcolor.cl
modules/imgproc/src/opencl/cvtcolor.cl
+378
-133
No files found.
modules/imgproc/src/color.cpp
View file @
fd90efc9
...
@@ -2716,6 +2716,8 @@ struct mRGBA2RGBA
...
@@ -2716,6 +2716,8 @@ struct mRGBA2RGBA
#ifdef HAVE_OPENCL
#ifdef HAVE_OPENCL
#define DIVUP(total, grain) (((total) + (grain) - 1) / (grain))
static
bool
ocl_cvtColor
(
InputArray
_src
,
OutputArray
_dst
,
int
code
,
int
dcn
)
static
bool
ocl_cvtColor
(
InputArray
_src
,
OutputArray
_dst
,
int
code
,
int
dcn
)
{
{
bool
ok
=
false
;
bool
ok
=
false
;
...
@@ -2729,6 +2731,17 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2729,6 +2731,17 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
if
(
depth
!=
CV_8U
&&
depth
!=
CV_16U
&&
depth
!=
CV_32F
)
if
(
depth
!=
CV_8U
&&
depth
!=
CV_16U
&&
depth
!=
CV_32F
)
return
false
;
return
false
;
cv
::
String
opts
=
format
(
"-D depth=%d -D scn=%d "
,
depth
,
scn
);
ocl
::
Device
dev
=
ocl
::
Device
::
getDefault
();
int
pxPerWIy
=
1
;
if
(
dev
.
isIntel
()
&&
(
dev
.
type
()
&
ocl
::
Device
::
TYPE_GPU
))
{
pxPerWIy
=
4
;
}
globalsize
[
1
]
=
DIVUP
(
globalsize
[
1
],
pxPerWIy
);
opts
+=
format
(
"-D PIX_PER_WI_Y=%d "
,
pxPerWIy
);
switch
(
code
)
switch
(
code
)
{
{
case
COLOR_BGR2BGRA
:
case
COLOR_RGB2BGRA
:
case
COLOR_BGRA2BGR
:
case
COLOR_BGR2BGRA
:
case
COLOR_RGB2BGRA
:
case
COLOR_BGRA2BGR
:
...
@@ -2738,7 +2751,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2738,7 +2751,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dcn
=
code
==
COLOR_BGR2BGRA
||
code
==
COLOR_RGB2BGRA
||
code
==
COLOR_BGRA2RGBA
?
4
:
3
;
dcn
=
code
==
COLOR_BGR2BGRA
||
code
==
COLOR_RGB2BGRA
||
code
==
COLOR_BGRA2RGBA
?
4
:
3
;
bool
reverse
=
!
(
code
==
COLOR_BGR2BGRA
||
code
==
COLOR_BGRA2BGR
);
bool
reverse
=
!
(
code
==
COLOR_BGR2BGRA
||
code
==
COLOR_BGRA2BGR
);
k
.
create
(
"RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=%d -D bidx=0 -D %s"
,
depth
,
scn
,
dcn
,
opts
+
format
(
"-D dcn=%d -D bidx=0 -D %s"
,
dcn
,
reverse
?
"REVERSE"
:
"ORDER"
));
reverse
?
"REVERSE"
:
"ORDER"
));
break
;
break
;
}
}
...
@@ -2752,7 +2765,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2752,7 +2765,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
int
greenbits
=
code
==
COLOR_BGR5652BGR
||
code
==
COLOR_BGR5652RGB
||
int
greenbits
=
code
==
COLOR_BGR5652BGR
||
code
==
COLOR_BGR5652RGB
||
code
==
COLOR_BGR5652BGRA
||
code
==
COLOR_BGR5652RGBA
?
6
:
5
;
code
==
COLOR_BGR5652BGRA
||
code
==
COLOR_BGR5652RGBA
?
6
:
5
;
k
.
create
(
"RGB5x52RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB5x52RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=2 -D dcn=%d -D bidx=%d -D greenbits=%d"
,
depth
,
dcn
,
bidx
,
greenbits
));
opts
+
format
(
"-D dcn=%d -D bidx=%d -D greenbits=%d"
,
dcn
,
bidx
,
greenbits
));
break
;
break
;
}
}
case
COLOR_BGR2BGR565
:
case
COLOR_BGR2BGR555
:
case
COLOR_RGB2BGR565
:
case
COLOR_RGB2BGR555
:
case
COLOR_BGR2BGR565
:
case
COLOR_BGR2BGR555
:
case
COLOR_RGB2BGR565
:
case
COLOR_RGB2BGR555
:
...
@@ -2765,7 +2778,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2765,7 +2778,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
code
==
COLOR_BGRA2BGR565
||
code
==
COLOR_RGBA2BGR565
?
6
:
5
;
code
==
COLOR_BGRA2BGR565
||
code
==
COLOR_RGBA2BGR565
?
6
:
5
;
dcn
=
2
;
dcn
=
2
;
k
.
create
(
"RGB2RGB5x5"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB2RGB5x5"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=2 -D bidx=%d -D greenbits=%d"
,
depth
,
scn
,
bidx
,
greenbits
));
opts
+
format
(
"-D dcn=2 -D bidx=%d -D greenbits=%d"
,
bidx
,
greenbits
));
break
;
break
;
}
}
case
COLOR_BGR5652GRAY
:
case
COLOR_BGR5552GRAY
:
case
COLOR_BGR5652GRAY
:
case
COLOR_BGR5552GRAY
:
...
@@ -2774,7 +2787,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2774,7 +2787,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dcn
=
1
;
dcn
=
1
;
int
greenbits
=
code
==
COLOR_BGR5652GRAY
?
6
:
5
;
int
greenbits
=
code
==
COLOR_BGR5652GRAY
?
6
:
5
;
k
.
create
(
"BGR5x52Gray"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"BGR5x52Gray"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=2 -D dcn=1 -D bidx=0 -D greenbits=%d"
,
depth
,
greenbits
));
opts
+
format
(
"-D dcn=1 -D bidx=0 -D greenbits=%d"
,
greenbits
));
break
;
break
;
}
}
case
COLOR_GRAY2BGR565
:
case
COLOR_GRAY2BGR555
:
case
COLOR_GRAY2BGR565
:
case
COLOR_GRAY2BGR555
:
...
@@ -2783,7 +2796,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2783,7 +2796,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dcn
=
2
;
dcn
=
2
;
int
greenbits
=
code
==
COLOR_GRAY2BGR565
?
6
:
5
;
int
greenbits
=
code
==
COLOR_GRAY2BGR565
?
6
:
5
;
k
.
create
(
"Gray2BGR5x5"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"Gray2BGR5x5"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=1 -D dcn=2 -D bidx=0 -D greenbits=%d"
,
depth
,
greenbits
));
opts
+
format
(
"-D dcn=2 -D bidx=0 -D greenbits=%d"
,
greenbits
));
break
;
break
;
}
}
case
COLOR_BGR2GRAY
:
case
COLOR_BGRA2GRAY
:
case
COLOR_BGR2GRAY
:
case
COLOR_BGRA2GRAY
:
...
@@ -2793,8 +2806,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2793,8 +2806,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
bidx
=
code
==
COLOR_BGR2GRAY
||
code
==
COLOR_BGRA2GRAY
?
0
:
2
;
bidx
=
code
==
COLOR_BGR2GRAY
||
code
==
COLOR_BGRA2GRAY
?
0
:
2
;
dcn
=
1
;
dcn
=
1
;
k
.
create
(
"RGB2Gray"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB2Gray"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d
-D dcn=1 -D bidx=%d -D STRIPE_SIZE=%d"
,
opts
+
format
(
"
-D dcn=1 -D bidx=%d -D STRIPE_SIZE=%d"
,
depth
,
scn
,
bidx
,
stripeSize
));
bidx
,
stripeSize
));
globalsize
[
0
]
=
(
src
.
cols
+
stripeSize
-
1
)
/
stripeSize
;
globalsize
[
0
]
=
(
src
.
cols
+
stripeSize
-
1
)
/
stripeSize
;
break
;
break
;
}
}
...
@@ -2804,7 +2817,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2804,7 +2817,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
CV_Assert
(
scn
==
1
);
CV_Assert
(
scn
==
1
);
dcn
=
code
==
COLOR_GRAY2BGRA
?
4
:
3
;
dcn
=
code
==
COLOR_GRAY2BGRA
?
4
:
3
;
k
.
create
(
"Gray2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"Gray2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D bidx=0 -D scn=1 -D dcn=%d"
,
depth
,
dcn
));
opts
+
format
(
"-D bidx=0 -D dcn=%d"
,
dcn
));
break
;
break
;
}
}
case
COLOR_BGR2YUV
:
case
COLOR_BGR2YUV
:
...
@@ -2814,7 +2827,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2814,7 +2827,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
bidx
=
code
==
COLOR_RGB2YUV
?
0
:
2
;
bidx
=
code
==
COLOR_RGB2YUV
?
0
:
2
;
dcn
=
3
;
dcn
=
3
;
k
.
create
(
"RGB2YUV"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB2YUV"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d"
,
depth
,
scn
,
bidx
));
opts
+
format
(
"-D dcn=3 -D bidx=%d"
,
bidx
));
break
;
break
;
}
}
case
COLOR_YUV2BGR
:
case
COLOR_YUV2BGR
:
...
@@ -2824,7 +2837,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2824,7 +2837,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
CV_Assert
(
dcn
==
3
||
dcn
==
4
);
CV_Assert
(
dcn
==
3
||
dcn
==
4
);
bidx
=
code
==
COLOR_YUV2RGB
?
0
:
2
;
bidx
=
code
==
COLOR_YUV2RGB
?
0
:
2
;
k
.
create
(
"YUV2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"YUV2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=3 -D dcn=%d -D bidx=%d"
,
depth
,
dcn
,
bidx
));
opts
+
format
(
"-D dcn=%d -D bidx=%d"
,
dcn
,
bidx
));
break
;
break
;
}
}
case
COLOR_YUV2RGB_NV12
:
case
COLOR_YUV2BGR_NV12
:
case
COLOR_YUV2RGB_NV12
:
case
COLOR_YUV2BGR_NV12
:
...
@@ -2837,7 +2850,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2837,7 +2850,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dstSz
=
Size
(
sz
.
width
,
sz
.
height
*
2
/
3
);
dstSz
=
Size
(
sz
.
width
,
sz
.
height
*
2
/
3
);
k
.
create
(
"YUV2RGB_NV12"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"YUV2RGB_NV12"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=0 -D scn=1
-D dcn=%d -D bidx=%d"
,
dcn
,
bidx
));
opts
+
format
(
"
-D dcn=%d -D bidx=%d"
,
dcn
,
bidx
));
break
;
break
;
}
}
case
COLOR_BGR2YCrCb
:
case
COLOR_BGR2YCrCb
:
...
@@ -2847,7 +2860,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2847,7 +2860,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
bidx
=
code
==
COLOR_BGR2YCrCb
?
0
:
2
;
bidx
=
code
==
COLOR_BGR2YCrCb
?
0
:
2
;
dcn
=
3
;
dcn
=
3
;
k
.
create
(
"RGB2YCrCb"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB2YCrCb"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d"
,
depth
,
scn
,
bidx
));
opts
+
format
(
"-D dcn=3 -D bidx=%d"
,
bidx
));
break
;
break
;
}
}
case
COLOR_YCrCb2BGR
:
case
COLOR_YCrCb2BGR
:
...
@@ -2858,7 +2871,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2858,7 +2871,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
CV_Assert
(
scn
==
3
&&
(
dcn
==
3
||
dcn
==
4
));
CV_Assert
(
scn
==
3
&&
(
dcn
==
3
||
dcn
==
4
));
bidx
=
code
==
COLOR_YCrCb2BGR
?
0
:
2
;
bidx
=
code
==
COLOR_YCrCb2BGR
?
0
:
2
;
k
.
create
(
"YCrCb2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"YCrCb2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=%d -D bidx=%d"
,
depth
,
scn
,
dcn
,
bidx
));
opts
+
format
(
"-D dcn=%d -D bidx=%d"
,
dcn
,
bidx
));
break
;
break
;
}
}
case
COLOR_BGR2XYZ
:
case
COLOR_RGB2XYZ
:
case
COLOR_BGR2XYZ
:
case
COLOR_RGB2XYZ
:
...
@@ -2904,7 +2917,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2904,7 +2917,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dst
=
_dst
.
getUMat
();
dst
=
_dst
.
getUMat
();
k
.
create
(
"RGB2XYZ"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"RGB2XYZ"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=%d -D dcn=3 -D bidx=%d"
,
depth
,
scn
,
bidx
));
opts
+
format
(
"-D dcn=3 -D bidx=%d"
,
bidx
));
if
(
k
.
empty
())
if
(
k
.
empty
())
return
false
;
return
false
;
k
.
args
(
ocl
::
KernelArg
::
ReadOnlyNoSize
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrReadOnly
(
c
));
k
.
args
(
ocl
::
KernelArg
::
ReadOnlyNoSize
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrReadOnly
(
c
));
...
@@ -2955,7 +2968,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -2955,7 +2968,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dst
=
_dst
.
getUMat
();
dst
=
_dst
.
getUMat
();
k
.
create
(
"XYZ2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"XYZ2RGB"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D scn=3 -D dcn=%d -D bidx=%d"
,
depth
,
dcn
,
bidx
));
opts
+
format
(
"-D dcn=%d -D bidx=%d"
,
dcn
,
bidx
));
if
(
k
.
empty
())
if
(
k
.
empty
())
return
false
;
return
false
;
k
.
args
(
ocl
::
KernelArg
::
ReadOnlyNoSize
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrReadOnly
(
c
));
k
.
args
(
ocl
::
KernelArg
::
ReadOnlyNoSize
(
src
),
ocl
::
KernelArg
::
WriteOnly
(
dst
),
ocl
::
KernelArg
::
PtrReadOnly
(
c
));
...
@@ -3010,8 +3023,9 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3010,8 +3023,9 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst
.
create
(
dstSz
,
CV_8UC3
);
_dst
.
create
(
dstSz
,
CV_8UC3
);
dst
=
_dst
.
getUMat
();
dst
=
_dst
.
getUMat
();
k
.
create
(
"RGB2HSV"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D hrange=%d -D bidx=%d -D dcn=3 -D scn=%d"
,
k
.
create
(
"RGB2HSV"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
depth
,
hrange
,
bidx
,
scn
));
opts
+
format
(
"-D hrange=%d -D bidx=%d -D dcn=3"
,
hrange
,
bidx
));
if
(
k
.
empty
())
if
(
k
.
empty
())
return
false
;
return
false
;
...
@@ -3023,7 +3037,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3023,7 +3037,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
}
}
else
else
k
.
create
(
kernelName
.
c_str
(),
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
kernelName
.
c_str
(),
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D hscale=%ff -D bidx=%d -D scn=%d -D dcn=3"
,
depth
,
hrange
*
(
1.
f
/
360.
f
),
bidx
,
scn
));
opts
+
format
(
"-D hscale=%ff -D bidx=%d -D dcn=3"
,
hrange
*
(
1.
f
/
360.
f
),
bidx
));
break
;
break
;
}
}
case
COLOR_HSV2BGR
:
case
COLOR_HSV2RGB
:
case
COLOR_HSV2BGR_FULL
:
case
COLOR_HSV2RGB_FULL
:
case
COLOR_HSV2BGR
:
case
COLOR_HSV2RGB
:
case
COLOR_HSV2BGR_FULL
:
case
COLOR_HSV2RGB_FULL
:
...
@@ -3041,8 +3056,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3041,8 +3056,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
String
kernelName
=
String
(
is_hsv
?
"HSV"
:
"HLS"
)
+
"2RGB"
;
String
kernelName
=
String
(
is_hsv
?
"HSV"
:
"HLS"
)
+
"2RGB"
;
k
.
create
(
kernelName
.
c_str
(),
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
kernelName
.
c_str
(),
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D dcn=%d -D scn=3
-D bidx=%d -D hrange=%d -D hscale=%ff"
,
opts
+
format
(
"-D dcn=%d
-D bidx=%d -D hrange=%d -D hscale=%ff"
,
depth
,
dcn
,
bidx
,
hrange
,
6.
f
/
hrange
));
dcn
,
bidx
,
hrange
,
6.
f
/
hrange
));
break
;
break
;
}
}
case
COLOR_RGBA2mRGBA
:
case
COLOR_mRGBA2RGBA
:
case
COLOR_RGBA2mRGBA
:
case
COLOR_mRGBA2RGBA
:
...
@@ -3051,7 +3066,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3051,7 +3066,7 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dcn
=
4
;
dcn
=
4
;
k
.
create
(
code
==
COLOR_RGBA2mRGBA
?
"RGBA2mRGBA"
:
"mRGBA2RGBA"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
code
==
COLOR_RGBA2mRGBA
?
"RGBA2mRGBA"
:
"mRGBA2RGBA"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D dcn=4 -D scn=4 -D bidx=3"
,
depth
)
);
opts
+
"-D dcn=4 -D bidx=3"
);
break
;
break
;
}
}
case
CV_BGR2Lab
:
case
CV_RGB2Lab
:
case
CV_LBGR2Lab
:
case
CV_LRGB2Lab
:
case
CV_BGR2Lab
:
case
CV_RGB2Lab
:
case
CV_LBGR2Lab
:
case
CV_LRGB2Lab
:
...
@@ -3063,8 +3078,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3063,8 +3078,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
dcn
=
3
;
dcn
=
3
;
k
.
create
(
"BGR2Lab"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"BGR2Lab"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D dcn=3 -D scn=%d
-D bidx=%d%s"
,
opts
+
format
(
"-D dcn=3
-D bidx=%d%s"
,
depth
,
scn
,
bidx
,
srgb
?
" -D SRGB"
:
""
));
bidx
,
srgb
?
" -D SRGB"
:
""
));
if
(
k
.
empty
())
if
(
k
.
empty
())
return
false
;
return
false
;
...
@@ -3165,8 +3180,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
...
@@ -3165,8 +3180,8 @@ static bool ocl_cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
bool
srgb
=
code
==
CV_Lab2BGR
||
code
==
CV_Lab2RGB
;
bool
srgb
=
code
==
CV_Lab2BGR
||
code
==
CV_Lab2RGB
;
k
.
create
(
"Lab2BGR"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
k
.
create
(
"Lab2BGR"
,
ocl
::
imgproc
::
cvtcolor_oclsrc
,
format
(
"-D depth=%d -D dcn=%d -D scn=3
-D bidx=%d%s"
,
opts
+
format
(
"-D dcn=%d
-D bidx=%d%s"
,
depth
,
dcn
,
bidx
,
srgb
?
" -D SRGB"
:
""
));
dcn
,
bidx
,
srgb
?
" -D SRGB"
:
""
));
if
(
k
.
empty
())
if
(
k
.
empty
())
return
false
;
return
false
;
...
...
modules/imgproc/src/opencl/cvtcolor.cl
View file @
fd90efc9
...
@@ -99,56 +99,70 @@ enum
...
@@ -99,56 +99,70 @@ enum
#
define
hrange
0
#
define
hrange
0
#
endif
#
endif
#
if
bidx
==
0
#
define
R_COMP
z
#
define
G_COMP
y
#
define
B_COMP
x
#
elif
bidx
==
2
#
define
R_COMP
x
#
define
G_COMP
y
#
define
B_COMP
z
#
elif
bidx
==
3
//
The
only
kernel
that
uses
bidx
==
3
doesn
't
use
these
macros.
//
But
we
still
need
to
make
the
compiler
happy.
#
define
R_COMP
w
#
define
G_COMP
w
#
define
B_COMP
w
#
endif
#
define
__CAT
(
x,
y
)
x##y
#
define
CAT
(
x,
y
)
__CAT
(
x,
y
)
#
define
DATA_TYPE_4
CAT
(
DATA_TYPE,
4
)
/////////////////////////////////////
RGB
<->
GRAY
//////////////////////////////////////
/////////////////////////////////////
RGB
<->
GRAY
//////////////////////////////////////
__kernel
void
RGB2Gray
(
__global
const
uchar*
srcptr,
int
srcstep,
int
srcoffset,
__kernel
void
RGB2Gray
(
__global
const
uchar*
srcptr,
int
srcstep,
int
srcoffset,
__global
uchar*
dstptr,
int
dststep,
int
dstoffset,
__global
uchar*
dstptr,
int
dststep,
int
dstoffset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
#
if
1
int
x
=
get_global_id
(
0
)
;
const
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
const
int
y
=
get_global_id
(
1
)
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
dst[0]
=
src[bidx]
*
0.114f
+
src[1]
*
0.587f
+
src[
(
bidx^2
)
]
*
0.299f
;
dst[0]
=
src_pix.B_COMP
*
0.114f
+
src_pix.G_COMP
*
0.587f
+
src_pix.R_COMP
*
0.299f
;
#
else
#
else
dst[0]
=
(
DATA_TYPE
)
CV_DESCALE
((
src[bidx]
*
B2Y
+
src[1]
*
G2Y
+
src[
(
bidx^2
)
]
*
R2Y
)
,
yuv_shift
)
;
dst[0]
=
(
DATA_TYPE
)
CV_DESCALE
((
src_pix.B_COMP
*
B2Y
+
src_pix.G_COMP
*
G2Y
+
src_pix.R_COMP
*
R2Y
)
,
yuv_shift
)
;
#
endif
#
endif
}
}
#
else
++y
;
const
int
x_min
=
get_global_id
(
0
)
*STRIPE_SIZE
;
}
const
int
x_max
=
min
(
x_min
+
STRIPE_SIZE,
cols
)
;
const
int
y
=
get_global_id
(
1
)
;
if
(
y
<
rows
)
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
))
+
x_min*scn
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
))
;
int
x
;
for
(
x
=
x_min
; x < x_max; x++, src += scn )
#
ifdef
DEPTH_5
dst[x]
=
src[bidx]
*
0.114f
+
src[1]
*
0.587f
+
src[
(
bidx^2
)
]
*
0.299f
;
#
else
dst[x]
=
(
DATA_TYPE
)(
mad24
(
src[bidx],
B2Y,
mad24
(
src[1],
G2Y,
mad24
(
src[
(
bidx^2
)
],
R2Y,
1
<<
(
yuv_shift-1
))))
>>
yuv_shift
)
;
#
endif
}
}
#
endif
}
}
__kernel
void
Gray2RGB
(
__global
const
uchar*
srcptr,
int
srcstep,
int
srcoffset,
__kernel
void
Gray2RGB
(
__global
const
uchar*
srcptr,
int
srcstep,
int
srcoffset,
__global
uchar*
dstptr,
int
dststep,
int
dstoffset,
__global
uchar*
dstptr,
int
dststep,
int
dstoffset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
const
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
const
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
...
@@ -158,6 +172,9 @@ __kernel void Gray2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
...
@@ -158,6 +172,9 @@ __kernel void Gray2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
dst[3]
=
MAX_NUM
;
dst[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
/////////////////////////////////////
RGB
<->
YUV
//////////////////////////////////////
/////////////////////////////////////
RGB
<->
YUV
//////////////////////////////////////
...
@@ -170,13 +187,19 @@ __kernel void RGB2YUV(__global const uchar* srcptr, int srcstep, int srcoffset,
...
@@ -170,13 +187,19 @@ __kernel void RGB2YUV(__global const uchar* srcptr, int srcstep, int srcoffset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
DATA_TYPE
b=src[bidx],
g=src[1],
r=src[bidx^2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
DATA_TYPE
b=src_pix.B_COMP,
g=src_pix.G_COMP,
r=src_pix.R_COMP
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
__constant
float
*
coeffs
=
c_RGB2YUVCoeffs_f
;
__constant
float
*
coeffs
=
c_RGB2YUVCoeffs_f
;
...
@@ -195,6 +218,9 @@ __kernel void RGB2YUV(__global const uchar* srcptr, int srcstep, int srcoffset,
...
@@ -195,6 +218,9 @@ __kernel void RGB2YUV(__global const uchar* srcptr, int srcstep, int srcoffset,
dst[1]
=
SAT_CAST
(
U
)
;
dst[1]
=
SAT_CAST
(
U
)
;
dst[2]
=
SAT_CAST
(
V
)
;
dst[2]
=
SAT_CAST
(
V
)
;
}
}
++y
;
}
}
}
}
__constant
float
c_YUV2RGBCoeffs_f[5]
=
{
2.032f,
-0.395f,
-0.581f,
1.140f
}
;
__constant
float
c_YUV2RGBCoeffs_f[5]
=
{
2.032f,
-0.395f,
-0.581f,
1.140f
}
;
...
@@ -205,13 +231,19 @@ __kernel void YUV2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
...
@@ -205,13 +231,19 @@ __kernel void YUV2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
DATA_TYPE
Y
=
src[0],
U
=
src[1],
V
=
src[2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
DATA_TYPE
Y
=
src_pix.x,
U
=
src_pix.y,
V
=
src_pix.z
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
__constant
float
*
coeffs
=
c_YUV2RGBCoeffs_f
;
__constant
float
*
coeffs
=
c_YUV2RGBCoeffs_f
;
...
@@ -232,6 +264,9 @@ __kernel void YUV2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
...
@@ -232,6 +264,9 @@ __kernel void YUV2RGB(__global const uchar* srcptr, int srcstep, int srcoffset,
dst[3]
=
MAX_NUM
;
dst[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
__constant
int
ITUR_BT_601_CY
=
1220542
;
__constant
int
ITUR_BT_601_CY
=
1220542
;
...
@@ -246,9 +281,14 @@ __kernel void YUV2RGB_NV12(__global const uchar* srcptr, int srcstep, int srcoff
...
@@ -246,9 +281,14 @@ __kernel void YUV2RGB_NV12(__global const uchar* srcptr, int srcstep, int srcoff
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
/
2
&&
x
<
cols
/
2
)
if
(
x
<
cols
/
2
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
/
2
)
{
{
__global
const
uchar*
ysrc
=
srcptr
+
mad24
(
y
<<
1
,
srcstep,
(
x
<<
1
)
+
srcoffset
)
;
__global
const
uchar*
ysrc
=
srcptr
+
mad24
(
y
<<
1
,
srcstep,
(
x
<<
1
)
+
srcoffset
)
;
__global
const
uchar*
usrc
=
srcptr
+
mad24
(
rows
+
y,
srcstep,
(
x
<<
1
)
+
srcoffset
)
;
__global
const
uchar*
usrc
=
srcptr
+
mad24
(
rows
+
y,
srcstep,
(
x
<<
1
)
+
srcoffset
)
;
...
@@ -299,6 +339,9 @@ __kernel void YUV2RGB_NV12(__global const uchar* srcptr, int srcstep, int srcoff
...
@@ -299,6 +339,9 @@ __kernel void YUV2RGB_NV12(__global const uchar* srcptr, int srcstep, int srcoff
dst2[7]
=
255
;
dst2[7]
=
255
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
/////////////////////////////////////
RGB
<->
YCrCb
//////////////////////////////////////
/////////////////////////////////////
RGB
<->
YCrCb
//////////////////////////////////////
...
@@ -311,13 +354,19 @@ __kernel void RGB2YCrCb(__global const uchar* srcptr, int srcstep, int srcoffset
...
@@ -311,13 +354,19 @@ __kernel void RGB2YCrCb(__global const uchar* srcptr, int srcstep, int srcoffset
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
const
DATA_TYPE*
src
=
(
__global
const
DATA_TYPE*
)(
srcptr
+
mad24
(
y,
srcstep,
srcoffset
+
x
*
scnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
__global
DATA_TYPE*
dst
=
(
__global
DATA_TYPE*
)(
dstptr
+
mad24
(
y,
dststep,
dstoffset
+
x
*
dcnbytes
))
;
DATA_TYPE
b=src[bidx],
g=src[1],
r=src[bidx^2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
DATA_TYPE
b=src_pix.B_COMP,
g=src_pix.G_COMP,
r=src_pix.R_COMP
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
__constant
float
*
coeffs
=
c_RGB2YCrCbCoeffs_f
;
__constant
float
*
coeffs
=
c_RGB2YCrCbCoeffs_f
;
...
@@ -336,6 +385,9 @@ __kernel void RGB2YCrCb(__global const uchar* srcptr, int srcstep, int srcoffset
...
@@ -336,6 +385,9 @@ __kernel void RGB2YCrCb(__global const uchar* srcptr, int srcstep, int srcoffset
dst[1]
=
SAT_CAST
(
Cr
)
;
dst[1]
=
SAT_CAST
(
Cr
)
;
dst[2]
=
SAT_CAST
(
Cb
)
;
dst[2]
=
SAT_CAST
(
Cb
)
;
}
}
++y
;
}
}
}
}
__constant
float
c_YCrCb2RGBCoeffs_f[4]
=
{
1.403f,
-0.714f,
-0.344f,
1.773f
}
;
__constant
float
c_YCrCb2RGBCoeffs_f[4]
=
{
1.403f,
-0.714f,
-0.344f,
1.773f
}
;
...
@@ -346,16 +398,22 @@ __kernel void YCrCb2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -346,16 +398,22 @@ __kernel void YCrCb2RGB(__global const uchar* src, int src_step, int src_offset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
__global
const
DATA_TYPE
*
srcptr
=
(
__global
const
DATA_TYPE*
)(
src
+
src_idx
)
;
__global
const
DATA_TYPE
*
srcptr
=
(
__global
const
DATA_TYPE*
)(
src
+
src_idx
)
;
__global
DATA_TYPE
*
dstptr
=
(
__global
DATA_TYPE*
)(
dst
+
dst_idx
)
;
__global
DATA_TYPE
*
dstptr
=
(
__global
DATA_TYPE*
)(
dst
+
dst_idx
)
;
DATA_TYPE
y
=
srcptr[0],
cr
=
srcptr[1],
cb
=
srcptr[2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
srcptr
)
;
DATA_TYPE
y
=
src_pix.x,
cr
=
src_pix.y,
cb
=
src_pix.z
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
__constant
float
*
coeff
=
c_YCrCb2RGBCoeffs_f
;
__constant
float
*
coeff
=
c_YCrCb2RGBCoeffs_f
;
...
@@ -376,6 +434,9 @@ __kernel void YCrCb2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -376,6 +434,9 @@ __kernel void YCrCb2RGB(__global const uchar* src, int src_step, int src_offset,
dstptr[3]
=
MAX_NUM
;
dstptr[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
/////////////////////////////////////
RGB
<->
XYZ
//////////////////////////////////////
/////////////////////////////////////
RGB
<->
XYZ
//////////////////////////////////////
...
@@ -385,9 +446,14 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -385,9 +446,14 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
int
rows,
int
cols,
__constant
COEFF_TYPE
*
coeffs
)
int
rows,
int
cols,
__constant
COEFF_TYPE
*
coeffs
)
{
{
int
dx
=
get_global_id
(
0
)
;
int
dx
=
get_global_id
(
0
)
;
int
dy
=
get_global_id
(
1
)
;
int
dy
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
dy
<
rows
&&
dx
<
cols
)
if
(
dx
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
dy
<
rows
)
{
{
int
src_idx
=
mad24
(
dy,
src_step,
src_offset
+
dx
*
scnbytes
)
;
int
src_idx
=
mad24
(
dy,
src_step,
src_offset
+
dx
*
scnbytes
)
;
int
dst_idx
=
mad24
(
dy,
dst_step,
dst_offset
+
dx
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
dy,
dst_step,
dst_offset
+
dx
*
dcnbytes
)
;
...
@@ -395,7 +461,8 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -395,7 +461,8 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
DATA_TYPE
r
=
src[0],
g
=
src[1],
b
=
src[2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
DATA_TYPE
r
=
src_pix.x,
g
=
src_pix.y,
b
=
src_pix.z
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
float
x
=
r
*
coeffs[0]
+
g
*
coeffs[1]
+
b
*
coeffs[2]
;
float
x
=
r
*
coeffs[0]
+
g
*
coeffs[1]
+
b
*
coeffs[2]
;
...
@@ -410,6 +477,9 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -410,6 +477,9 @@ __kernel void RGB2XYZ(__global const uchar * srcptr, int src_step, int src_offse
dst[1]
=
SAT_CAST
(
y
)
;
dst[1]
=
SAT_CAST
(
y
)
;
dst[2]
=
SAT_CAST
(
z
)
;
dst[2]
=
SAT_CAST
(
z
)
;
}
}
++dy
;
}
}
}
}
__kernel
void
XYZ2RGB
(
__global
const
uchar
*
srcptr,
int
src_step,
int
src_offset,
__kernel
void
XYZ2RGB
(
__global
const
uchar
*
srcptr,
int
src_step,
int
src_offset,
...
@@ -417,9 +487,14 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -417,9 +487,14 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
int
rows,
int
cols,
__constant
COEFF_TYPE
*
coeffs
)
int
rows,
int
cols,
__constant
COEFF_TYPE
*
coeffs
)
{
{
int
dx
=
get_global_id
(
0
)
;
int
dx
=
get_global_id
(
0
)
;
int
dy
=
get_global_id
(
1
)
;
int
dy
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
dy
<
rows
&&
dx
<
cols
)
if
(
dx
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
dy
<
rows
)
{
{
int
src_idx
=
mad24
(
dy,
src_step,
src_offset
+
dx
*
scnbytes
)
;
int
src_idx
=
mad24
(
dy,
src_step,
src_offset
+
dx
*
scnbytes
)
;
int
dst_idx
=
mad24
(
dy,
dst_step,
dst_offset
+
dx
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
dy,
dst_step,
dst_offset
+
dx
*
dcnbytes
)
;
...
@@ -427,7 +502,8 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -427,7 +502,8 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
DATA_TYPE
x
=
src[0],
y
=
src[1],
z
=
src[2]
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
DATA_TYPE
x
=
src_pix.x,
y
=
src_pix.y,
z
=
src_pix.z
;
#
ifdef
DEPTH_5
#
ifdef
DEPTH_5
float
b
=
x
*
coeffs[0]
+
y
*
coeffs[1]
+
z
*
coeffs[2]
;
float
b
=
x
*
coeffs[0]
+
y
*
coeffs[1]
+
z
*
coeffs[2]
;
...
@@ -445,6 +521,9 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -445,6 +521,9 @@ __kernel void XYZ2RGB(__global const uchar * srcptr, int src_step, int src_offse
dst[3]
=
MAX_NUM
;
dst[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++dy
;
}
}
}
}
/////////////////////////////////////
RGB[A]
<->
BGR[A]
//////////////////////////////////////
/////////////////////////////////////
RGB[A]
<->
BGR[A]
//////////////////////////////////////
...
@@ -454,24 +533,30 @@ __kernel void RGB(__global const uchar* srcptr, int src_step, int src_offset,
...
@@ -454,24 +533,30 @@ __kernel void RGB(__global const uchar* srcptr, int src_step, int src_offset,
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
const
DATA_TYPE
*
src
=
(
__global
const
DATA_TYPE
*
)(
srcptr
+
src_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
__global
DATA_TYPE
*
dst
=
(
__global
DATA_TYPE
*
)(
dstptr
+
dst_idx
)
;
DATA_TYPE_4
src_pix
=
vload4
(
0
,
src
)
;
#
ifdef
REVERSE
#
ifdef
REVERSE
dst[0]
=
src[2]
;
dst[0]
=
src_pix.z
;
dst[1]
=
src[1]
;
dst[1]
=
src_pix.y
;
dst[2]
=
src[0]
;
dst[2]
=
src_pix.x
;
#
else
#
else
dst[0]
=
src[0]
;
dst[0]
=
src_pix.x
;
dst[1]
=
src[1]
;
dst[1]
=
src_pix.y
;
dst[2]
=
src[2]
;
dst[2]
=
src_pix.z
;
#
endif
#
endif
#
if
dcn
==
4
#
if
dcn
==
4
...
@@ -482,6 +567,9 @@ __kernel void RGB(__global const uchar* srcptr, int src_step, int src_offset,
...
@@ -482,6 +567,9 @@ __kernel void RGB(__global const uchar* srcptr, int src_step, int src_offset,
#
endif
#
endif
#
endif
#
endif
}
}
++y
;
}
}
}
}
/////////////////////////////////////
RGB5x5
<->
RGB
//////////////////////////////////////
/////////////////////////////////////
RGB5x5
<->
RGB
//////////////////////////////////////
...
@@ -491,9 +579,14 @@ __kernel void RGB5x52RGB(__global const uchar* src, int src_step, int src_offset
...
@@ -491,9 +579,14 @@ __kernel void RGB5x52RGB(__global const uchar* src, int src_step, int src_offset
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
...
@@ -517,6 +610,9 @@ __kernel void RGB5x52RGB(__global const uchar* src, int src_step, int src_offset
...
@@ -517,6 +610,9 @@ __kernel void RGB5x52RGB(__global const uchar* src, int src_step, int src_offset
#
endif
#
endif
#
endif
#
endif
}
}
++y
;
}
}
}
}
__kernel
void
RGB2RGB5x5
(
__global
const
uchar*
src,
int
src_step,
int
src_offset,
__kernel
void
RGB2RGB5x5
(
__global
const
uchar*
src,
int
src_step,
int
src_offset,
...
@@ -524,22 +620,31 @@ __kernel void RGB2RGB5x5(__global const uchar* src, int src_step, int src_offset
...
@@ -524,22 +620,31 @@ __kernel void RGB2RGB5x5(__global const uchar* src, int src_step, int src_offset
int
rows,
int
cols
)
int
rows,
int
cols
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
uchar4
src_pix
=
vload4
(
0
,
src
+
src_idx
)
;
#
if
greenbits
==
6
#
if
greenbits
==
6
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src[src_idx
+
bidx]
>>
3
)
|((src[src_idx + 1]&~3) << 3)|
((
src[src_idx
+
(
bidx^2
)
]
&~7
)
<<
8
))
;
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src_pix.B_COMP
>>
3
)
|((src_pix.G_COMP&~3) << 3)|
((
src_pix.R_COMP
&~7
)
<<
8
))
;
#
elif
scn
==
3
#
elif
scn
==
3
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src[src_idx
+
bidx]
>>
3
)
|((src[src_idx + 1]&~7) << 2)|
((
src[src_idx
+
(
bidx^2
)
]
&~7
)
<<
7
))
;
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src_pix.B_COMP
>>
3
)
|((src_pix.G_COMP&~7) << 2)|
((
src_pix.R_COMP
&~7
)
<<
7
))
;
#
else
#
else
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src[src_idx
+
bidx]
>>
3
)
|((src[src_idx + 1]
&~7) << 2)|
*
((
__global
ushort*
)(
dst
+
dst_idx
))
=
(
ushort
)((
src_pix.B_COMP
>>
3
)
|((src_pix.G_COMP
&~7) << 2)|
((
src[src_idx
+
(
bidx^2
)
]&~7
)
<<
7
)
|(src[src_idx + 3]
? 0x8000 : 0));
((
src_pix.R_COMP&~7
)
<<
7
)
|(src_pix.w
? 0x8000 : 0));
#endif
#endif
}
}
++y;
}
}
}
}
///////////////////////////////////// RGB5x5 <-> Gray //////////////////////////////////////
///////////////////////////////////// RGB5x5 <-> Gray //////////////////////////////////////
...
@@ -549,9 +654,14 @@ __kernel void BGR5x52Gray(__global const uchar* src, int src_step, int src_offse
...
@@ -549,9 +654,14 @@ __kernel void BGR5x52Gray(__global const uchar* src, int src_step, int src_offse
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x);
int dst_idx = mad24(y, dst_step, dst_offset + x);
...
@@ -567,6 +677,9 @@ __kernel void BGR5x52Gray(__global const uchar* src, int src_step, int src_offse
...
@@ -567,6 +677,9 @@ __kernel void BGR5x52Gray(__global const uchar* src, int src_step, int src_offse
((t >> 7) & 0xf8)*R2Y, yuv_shift);
((t >> 7) & 0xf8)*R2Y, yuv_shift);
#endif
#endif
}
}
++y;
}
}
}
}
__kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offset,
__kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offset,
...
@@ -574,9 +687,14 @@ __kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offse
...
@@ -574,9 +687,14 @@ __kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offse
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x);
int src_idx = mad24(y, src_step, src_offset + x);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
...
@@ -589,6 +707,9 @@ __kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offse
...
@@ -589,6 +707,9 @@ __kernel void Gray2BGR5x5(__global const uchar* src, int src_step, int src_offse
*((__global ushort*)(dst + dst_idx)) = (ushort)(t|
(
t
<<
5
)
|(t << 10));
*((__global ushort*)(dst + dst_idx)) = (ushort)(t|
(
t
<<
5
)
|(t << 10));
#endif
#endif
}
}
++y;
}
}
}
}
//////////////////////////////////// RGB <-> HSV //////////////////////////////////////
//////////////////////////////////// RGB <-> HSV //////////////////////////////////////
...
@@ -608,14 +729,20 @@ __kernel void RGB2HSV(__global const uchar* src, int src_step, int src_offset,
...
@@ -608,14 +729,20 @@ __kernel void RGB2HSV(__global const uchar* src, int src_step, int src_offset,
__constant int * sdiv_table, __constant int * hdiv_table)
__constant int * sdiv_table, __constant int * hdiv_table)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
uchar4 src_pix = vload4(0, src + src_idx);
int b = src[src_idx + bidx], g = src[src_idx + 1], r = src[src_idx + (bidx^2)]
;
int b = src_pix.B_COMP, g = src_pix.G_COMP, r = src_pix.R_COMP
;
int h, s, v = b;
int h, s, v = b;
int vmin = b, diff;
int vmin = b, diff;
int vr, vg;
int vr, vg;
...
@@ -639,6 +766,9 @@ __kernel void RGB2HSV(__global const uchar* src, int src_step, int src_offset,
...
@@ -639,6 +766,9 @@ __kernel void RGB2HSV(__global const uchar* src, int src_step, int src_offset,
dst[dst_idx + 1] = (uchar)s;
dst[dst_idx + 1] = (uchar)s;
dst[dst_idx + 2] = (uchar)v;
dst[dst_idx + 2] = (uchar)v;
}
}
++y;
}
}
}
}
__kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
__kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -646,14 +776,20 @@ __kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -646,14 +776,20 @@ __kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
uchar4 src_pix = vload4(0, src + src_idx);
float h = src[src_idx], s = src[src_idx + 1]*(1/255.f), v = src[src_idx + 2]
*(1/255.f);
float h = src_pix.x, s = src_pix.y*(1/255.f), v = src_pix.z
*(1/255.f);
float b, g, r;
float b, g, r;
if (s != 0)
if (s != 0)
...
@@ -692,6 +828,9 @@ __kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -692,6 +828,9 @@ __kernel void HSV2RGB(__global const uchar* src, int src_step, int src_offset,
dst[dst_idx + 3] = MAX_NUM;
dst[dst_idx + 3] = MAX_NUM;
#endif
#endif
}
}
++y;
}
}
}
}
#elif defined DEPTH_5
#elif defined DEPTH_5
...
@@ -701,17 +840,23 @@ __kernel void RGB2HSV(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -701,17 +840,23 @@ __kernel void RGB2HSV(__global const uchar* srcptr, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
float4 src_pix = vload4(0, src);
float b = src[bidx], g = src[1], r = src[bidx^2]
;
float b = src_pix.B_COMP, g = src_pix.G_COMP, r = src_pix.R_COMP
;
float h, s, v;
float h, s, v;
float vmin, diff;
float vmin, diff;
...
@@ -738,6 +883,9 @@ __kernel void RGB2HSV(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -738,6 +883,9 @@ __kernel void RGB2HSV(__global const uchar* srcptr, int src_step, int src_offset
dst[1] = s;
dst[1] = s;
dst[2] = v;
dst[2] = v;
}
}
++y;
}
}
}
}
__kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset,
__kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset,
...
@@ -745,17 +893,23 @@ __kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -745,17 +893,23 @@ __kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
float4 src_pix = vload4(0, src);
float h = src[0], s = src[1], v = src[2]
;
float h = src_pix.x, s = src_pix.y, v = src_pix.z
;
float b, g, r;
float b, g, r;
if (s != 0)
if (s != 0)
...
@@ -794,6 +948,9 @@ __kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -794,6 +948,9 @@ __kernel void HSV2RGB(__global const uchar* srcptr, int src_step, int src_offset
dst[3] = MAX_NUM;
dst[3] = MAX_NUM;
#endif
#endif
}
}
++y;
}
}
}
}
#endif
#endif
...
@@ -807,14 +964,20 @@ __kernel void RGB2HLS(__global const uchar* src, int src_step, int src_offset,
...
@@ -807,14 +964,20 @@ __kernel void RGB2HLS(__global const uchar* src, int src_step, int src_offset,
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
uchar4 src_pix = vload4(0, src + src_idx);
float b = src[src_idx + bidx]*(1/255.f), g = src[src_idx + 1]*(1/255.f), r = src[src_idx + (bidx^2)]
*(1/255.f);
float b = src_pix.B_COMP*(1/255.f), g = src_pix.G_COMP*(1/255.f), r = src_pix.R_COMP
*(1/255.f);
float h = 0.f, s = 0.f, l;
float h = 0.f, s = 0.f, l;
float vmin, vmax, diff;
float vmin, vmax, diff;
...
@@ -846,6 +1009,9 @@ __kernel void RGB2HLS(__global const uchar* src, int src_step, int src_offset,
...
@@ -846,6 +1009,9 @@ __kernel void RGB2HLS(__global const uchar* src, int src_step, int src_offset,
dst[dst_idx + 1] = convert_uchar_sat_rte(l*255.f);
dst[dst_idx + 1] = convert_uchar_sat_rte(l*255.f);
dst[dst_idx + 2] = convert_uchar_sat_rte(s*255.f);
dst[dst_idx + 2] = convert_uchar_sat_rte(s*255.f);
}
}
++y;
}
}
}
}
__kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
__kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -853,14 +1019,20 @@ __kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -853,14 +1019,20 @@ __kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
uchar4 src_pix = vload4(0, src + src_idx);
float h = src[src_idx], l = src[src_idx + 1]*(1.f/255.f), s = src[src_idx + 2]
*(1.f/255.f);
float h = src_pix.x, l = src_pix.y*(1.f/255.f), s = src_pix.z
*(1.f/255.f);
float b, g, r;
float b, g, r;
if (s != 0)
if (s != 0)
...
@@ -898,6 +1070,9 @@ __kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
...
@@ -898,6 +1070,9 @@ __kernel void HLS2RGB(__global const uchar* src, int src_step, int src_offset,
dst[dst_idx + 3] = MAX_NUM;
dst[dst_idx + 3] = MAX_NUM;
#endif
#endif
}
}
++y;
}
}
}
}
#elif defined DEPTH_5
#elif defined DEPTH_5
...
@@ -907,17 +1082,23 @@ __kernel void RGB2HLS(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -907,17 +1082,23 @@ __kernel void RGB2HLS(__global const uchar* srcptr, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
float4 src_pix = vload4(0, src);
float b = src[bidx], g = src[1], r = src[bidx^2]
;
float b = src_pix.B_COMP, g = src_pix.G_COMP, r = src_pix.R_COMP
;
float h = 0.f, s = 0.f, l;
float h = 0.f, s = 0.f, l;
float vmin, vmax, diff;
float vmin, vmax, diff;
...
@@ -949,6 +1130,9 @@ __kernel void RGB2HLS(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -949,6 +1130,9 @@ __kernel void RGB2HLS(__global const uchar* srcptr, int src_step, int src_offset
dst[1] = l;
dst[1] = l;
dst[2] = s;
dst[2] = s;
}
}
++y;
}
}
}
}
__kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset,
__kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset,
...
@@ -956,17 +1140,23 @@ __kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -956,17 +1140,23 @@ __kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (y < rows && x < cols)
if (x < cols)
{
#pragma unroll
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
{
if (y < rows)
{
{
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int src_idx = mad24(y, src_step, src_offset + x * scnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
int dst_idx = mad24(y, dst_step, dst_offset + x * dcnbytes);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global const float * src = (__global const float *)(srcptr + src_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
__global float * dst = (__global float *)(dstptr + dst_idx);
float4 src_pix = vload4(0, src);
float h = src[0], l = src[1], s = src[2]
;
float h = src_pix.x, l = src_pix.y, s = src_pix.z
;
float b, g, r;
float b, g, r;
if (s != 0)
if (s != 0)
...
@@ -1005,6 +1195,9 @@ __kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset
...
@@ -1005,6 +1195,9 @@ __kernel void HLS2RGB(__global const uchar* srcptr, int src_step, int src_offset
dst[3] = MAX_NUM;
dst[3] = MAX_NUM;
#endif
#endif
}
}
++y;
}
}
}
}
#endif
#endif
...
@@ -1018,22 +1211,30 @@ __kernel void RGBA2mRGBA(__global const uchar* src, int src_step, int src_offset
...
@@ -1018,22 +1211,30 @@ __kernel void RGBA2mRGBA(__global const uchar* src, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (
y < rows &&
x < cols)
if (x < cols)
{
{
x <<= 2;
#pragma unroll
int src_idx = mad24(y, src_step, src_offset + x);
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
int dst_idx = mad24(y, dst_step, dst_offset + x);
{
if (y < rows)
{
int src_idx = mad24(y, src_step, src_offset + (x << 2));
int dst_idx = mad24(y, dst_step, dst_offset + (x << 2));
uchar4 src_pix = vload4(0, src + src_idx);
uchar v0 = src[src_idx], v1 = src[src_idx + 1]
;
uchar v0 = src_pix.x, v1 = src_pix.y
;
uchar v2 = src[src_idx + 2], v3 = src[src_idx + 3]
;
uchar v2 = src_pix.z, v3 = src_pix.w
;
dst[dst_idx] = (v0 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx] = (v0 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx + 1] = (v1 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx + 1] = (v1 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx + 2] = (v2 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx + 2] = (v2 * v3 + HALF_MAX) / MAX_NUM;
dst[dst_idx + 3] = v3;
dst[dst_idx + 3] = v3;
}
}
++y;
}
}
}
}
__kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset,
__kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset,
...
@@ -1041,16 +1242,21 @@ __kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset
...
@@ -1041,16 +1242,21 @@ __kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset
int rows, int cols)
int rows, int cols)
{
{
int x = get_global_id(0);
int x = get_global_id(0);
int y = get_global_id(1);
int y = get_global_id(1)
* PIX_PER_WI_Y
;
if (
y < rows &&
x < cols)
if (x < cols)
{
{
x <<= 2;
#pragma unroll
int src_idx = mad24(y, src_step, src_offset + x);
for (int cy = 0; cy < PIX_PER_WI_Y; ++cy)
int dst_idx = mad24(y, dst_step, dst_offset + x);
{
if (y < rows)
{
int src_idx = mad24(y, src_step, src_offset + (x << 2));
int dst_idx = mad24(y, dst_step, dst_offset + (x << 2));
uchar4 src_pix = vload4(0, src + src_idx);
uchar v0 = src[src_idx], v1 = src[src_idx + 1]
;
uchar v0 = src_pix.x, v1 = src_pix.y
;
uchar v2 = src[src_idx + 2], v3 = src[src_idx + 3]
;
uchar v2 = src_pix.z, v3 = src_pix.w
;
uchar v3_half = v3 / 2;
uchar v3_half = v3 / 2;
dst[dst_idx] = v3 == 0 ? 0 : (v0 * MAX_NUM + v3_half) / v3;
dst[dst_idx] = v3 == 0 ? 0 : (v0 * MAX_NUM + v3_half) / v3;
...
@@ -1058,6 +1264,9 @@ __kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset
...
@@ -1058,6 +1264,9 @@ __kernel void mRGBA2RGBA(__global const uchar* src, int src_step, int src_offset
dst[dst_idx + 2] = v3 == 0 ? 0 : (v2 * MAX_NUM + v3_half) / v3;
dst[dst_idx + 2] = v3 == 0 ? 0 : (v2 * MAX_NUM + v3_half) / v3;
dst[dst_idx + 3] = v3;
dst[dst_idx + 3] = v3;
}
}
++y;
}
}
}
}
#endif
#endif
...
@@ -1086,21 +1295,27 @@ __kernel void BGR2Lab(__global const uchar * src, int src_step, int src_offset,
...
@@ -1086,21 +1295,27 @@ __kernel void BGR2Lab(__global const uchar * src, int src_step, int src_offset,
__constant
int
*
coeffs,
int
Lscale,
int
Lshift
)
__constant
int
*
coeffs,
int
Lscale,
int
Lshift
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
src
+=
src_idx
;
__global
const
uchar*
src_ptr
=
src
+
src_idx
;
dst
+=
dst_idx
;
__global
uchar*
dst_ptr
=
dst
+
dst_idx
;
uchar4
src_pix
=
vload4
(
0
,
src_ptr
)
;
int
C0
=
coeffs[0],
C1
=
coeffs[1],
C2
=
coeffs[2],
int
C0
=
coeffs[0],
C1
=
coeffs[1],
C2
=
coeffs[2],
C3
=
coeffs[3],
C4
=
coeffs[4],
C5
=
coeffs[5],
C3
=
coeffs[3],
C4
=
coeffs[4],
C5
=
coeffs[5],
C6
=
coeffs[6],
C7
=
coeffs[7],
C8
=
coeffs[8]
;
C6
=
coeffs[6],
C7
=
coeffs[7],
C8
=
coeffs[8]
;
int
R
=
gammaTab[src[0]],
G
=
gammaTab[src[1]],
B
=
gammaTab[src[2]
]
;
int
R
=
gammaTab[src_pix.x],
G
=
gammaTab[src_pix.y],
B
=
gammaTab[src_pix.z
]
;
int
fX
=
LabCbrtTab_b[CV_DESCALE
(
R*C0
+
G*C1
+
B*C2,
lab_shift
)
]
;
int
fX
=
LabCbrtTab_b[CV_DESCALE
(
R*C0
+
G*C1
+
B*C2,
lab_shift
)
]
;
int
fY
=
LabCbrtTab_b[CV_DESCALE
(
R*C3
+
G*C4
+
B*C5,
lab_shift
)
]
;
int
fY
=
LabCbrtTab_b[CV_DESCALE
(
R*C3
+
G*C4
+
B*C5,
lab_shift
)
]
;
int
fZ
=
LabCbrtTab_b[CV_DESCALE
(
R*C6
+
G*C7
+
B*C8,
lab_shift
)
]
;
int
fZ
=
LabCbrtTab_b[CV_DESCALE
(
R*C6
+
G*C7
+
B*C8,
lab_shift
)
]
;
...
@@ -1109,9 +1324,12 @@ __kernel void BGR2Lab(__global const uchar * src, int src_step, int src_offset,
...
@@ -1109,9 +1324,12 @@ __kernel void BGR2Lab(__global const uchar * src, int src_step, int src_offset,
int
a
=
CV_DESCALE
(
500*
(
fX
-
fY
)
+
128*
(
1
<<
lab_shift2
)
,
lab_shift2
)
;
int
a
=
CV_DESCALE
(
500*
(
fX
-
fY
)
+
128*
(
1
<<
lab_shift2
)
,
lab_shift2
)
;
int
b
=
CV_DESCALE
(
200*
(
fY
-
fZ
)
+
128*
(
1
<<
lab_shift2
)
,
lab_shift2
)
;
int
b
=
CV_DESCALE
(
200*
(
fY
-
fZ
)
+
128*
(
1
<<
lab_shift2
)
,
lab_shift2
)
;
dst[0]
=
SAT_CAST
(
L
)
;
dst_ptr[0]
=
SAT_CAST
(
L
)
;
dst[1]
=
SAT_CAST
(
a
)
;
dst_ptr[1]
=
SAT_CAST
(
a
)
;
dst[2]
=
SAT_CAST
(
b
)
;
dst_ptr[2]
=
SAT_CAST
(
b
)
;
}
++y
;
}
}
}
}
}
...
@@ -1125,23 +1343,29 @@ __kernel void BGR2Lab(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -1125,23 +1343,29 @@ __kernel void BGR2Lab(__global const uchar * srcptr, int src_step, int src_offse
__constant
float
*
coeffs,
float
_1_3,
float
_a
)
__constant
float
*
coeffs,
float
_1_3,
float
_a
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
__global
const
float
*
src
=
(
__global
const
float
*
)(
srcptr
+
src_idx
)
;
__global
const
float
*
src
=
(
__global
const
float
*
)(
srcptr
+
src_idx
)
;
__global
float
*
dst
=
(
__global
float
*
)(
dstptr
+
dst_idx
)
;
__global
float
*
dst
=
(
__global
float
*
)(
dstptr
+
dst_idx
)
;
float4
src_pix
=
vload4
(
0
,
src
)
;
float
C0
=
coeffs[0],
C1
=
coeffs[1],
C2
=
coeffs[2],
float
C0
=
coeffs[0],
C1
=
coeffs[1],
C2
=
coeffs[2],
C3
=
coeffs[3],
C4
=
coeffs[4],
C5
=
coeffs[5],
C3
=
coeffs[3],
C4
=
coeffs[4],
C5
=
coeffs[5],
C6
=
coeffs[6],
C7
=
coeffs[7],
C8
=
coeffs[8]
;
C6
=
coeffs[6],
C7
=
coeffs[7],
C8
=
coeffs[8]
;
float
R
=
clamp
(
src[0]
,
0.0f,
1.0f
)
;
float
R
=
clamp
(
src_pix.x
,
0.0f,
1.0f
)
;
float
G
=
clamp
(
src[1]
,
0.0f,
1.0f
)
;
float
G
=
clamp
(
src_pix.y
,
0.0f,
1.0f
)
;
float
B
=
clamp
(
src[2]
,
0.0f,
1.0f
)
;
float
B
=
clamp
(
src_pix.z
,
0.0f,
1.0f
)
;
#
ifdef
SRGB
#
ifdef
SRGB
R
=
splineInterpolate
(
R
*
GammaTabScale,
gammaTab,
GAMMA_TAB_SIZE
)
;
R
=
splineInterpolate
(
R
*
GammaTabScale,
gammaTab,
GAMMA_TAB_SIZE
)
;
...
@@ -1165,6 +1389,9 @@ __kernel void BGR2Lab(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -1165,6 +1389,9 @@ __kernel void BGR2Lab(__global const uchar * srcptr, int src_step, int src_offse
dst[1]
=
a
;
dst[1]
=
a
;
dst[2]
=
b
;
dst[2]
=
b
;
}
}
++y
;
}
}
}
}
#
endif
#
endif
...
@@ -1225,20 +1452,26 @@ __kernel void Lab2BGR(__global const uchar * src, int src_step, int src_offset,
...
@@ -1225,20 +1452,26 @@ __kernel void Lab2BGR(__global const uchar * src, int src_step, int src_offset,
__constant
float
*
coeffs,
float
lThresh,
float
fThresh
)
__constant
float
*
coeffs,
float
lThresh,
float
fThresh
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
src
+=
src_idx
;
__global
const
uchar*
src_ptr
=
src
+
src_idx
;
dst
+=
dst_idx
;
__global
uchar*
dst_ptr
=
dst
+
dst_idx
;
uchar4
src_pix
=
vload4
(
0
,
src_ptr
)
;
float
srcbuf[3],
dstbuf[3]
;
float
srcbuf[3],
dstbuf[3]
;
srcbuf[0]
=
src[0]
*
(
100.f/255.f
)
;
srcbuf[0]
=
src_pix.x
*
(
100.f/255.f
)
;
srcbuf[1]
=
convert_float
(
src[1]
-
128
)
;
srcbuf[1]
=
convert_float
(
src_pix.y
-
128
)
;
srcbuf[2]
=
convert_float
(
src[2]
-
128
)
;
srcbuf[2]
=
convert_float
(
src_pix.z
-
128
)
;
Lab2BGR_f
(
&srcbuf[0],
&dstbuf[0],
Lab2BGR_f
(
&srcbuf[0],
&dstbuf[0],
#
ifdef
SRGB
#
ifdef
SRGB
...
@@ -1246,13 +1479,16 @@ __kernel void Lab2BGR(__global const uchar * src, int src_step, int src_offset,
...
@@ -1246,13 +1479,16 @@ __kernel void Lab2BGR(__global const uchar * src, int src_step, int src_offset,
#
endif
#
endif
coeffs,
lThresh,
fThresh
)
;
coeffs,
lThresh,
fThresh
)
;
dst
[0]
=
SAT_CAST
(
dstbuf[0]
*
255.0f
)
;
dst_ptr
[0]
=
SAT_CAST
(
dstbuf[0]
*
255.0f
)
;
dst
[1]
=
SAT_CAST
(
dstbuf[1]
*
255.0f
)
;
dst_ptr
[1]
=
SAT_CAST
(
dstbuf[1]
*
255.0f
)
;
dst
[2]
=
SAT_CAST
(
dstbuf[2]
*
255.0f
)
;
dst_ptr
[2]
=
SAT_CAST
(
dstbuf[2]
*
255.0f
)
;
#
if
dcn
==
4
#
if
dcn
==
4
dst
[3]
=
MAX_NUM
;
dst_ptr
[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
#
elif
defined
DEPTH_5
#
elif
defined
DEPTH_5
...
@@ -1265,18 +1501,24 @@ __kernel void Lab2BGR(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -1265,18 +1501,24 @@ __kernel void Lab2BGR(__global const uchar * srcptr, int src_step, int src_offse
__constant
float
*
coeffs,
float
lThresh,
float
fThresh
)
__constant
float
*
coeffs,
float
lThresh,
float
fThresh
)
{
{
int
x
=
get_global_id
(
0
)
;
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
int
y
=
get_global_id
(
1
)
*
PIX_PER_WI_Y
;
if
(
y
<
rows
&&
x
<
cols
)
if
(
x
<
cols
)
{
#
pragma
unroll
for
(
int
cy
=
0
; cy < PIX_PER_WI_Y; ++cy)
{
if
(
y
<
rows
)
{
{
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
src_idx
=
mad24
(
y,
src_step,
src_offset
+
x
*
scnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
int
dst_idx
=
mad24
(
y,
dst_step,
dst_offset
+
x
*
dcnbytes
)
;
__global
const
float
*
src
=
(
__global
const
float
*
)(
srcptr
+
src_idx
)
;
__global
const
float
*
src
=
(
__global
const
float
*
)(
srcptr
+
src_idx
)
;
__global
float
*
dst
=
(
__global
float
*
)(
dstptr
+
dst_idx
)
;
__global
float
*
dst
=
(
__global
float
*
)(
dstptr
+
dst_idx
)
;
float4
src_pix
=
vload4
(
0
,
src
)
;
float
srcbuf[3],
dstbuf[3]
;
float
srcbuf[3],
dstbuf[3]
;
srcbuf[0]
=
src[0],
srcbuf[1]
=
src[1],
srcbuf[2]
=
src[2]
;
srcbuf[0]
=
src_pix.x,
srcbuf[1]
=
src_pix.y,
srcbuf[2]
=
src_pix.z
;
Lab2BGR_f
(
&srcbuf[0],
&dstbuf[0],
Lab2BGR_f
(
&srcbuf[0],
&dstbuf[0],
#
ifdef
SRGB
#
ifdef
SRGB
...
@@ -1289,6 +1531,9 @@ __kernel void Lab2BGR(__global const uchar * srcptr, int src_step, int src_offse
...
@@ -1289,6 +1531,9 @@ __kernel void Lab2BGR(__global const uchar * srcptr, int src_step, int src_offse
dst[3]
=
MAX_NUM
;
dst[3]
=
MAX_NUM
;
#
endif
#
endif
}
}
++y
;
}
}
}
}
#
endif
#
endif
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