From aea20224a1a32ee5709c1b9229cae9d84505c3a8 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 31 Oct 2016 09:56:59 +0100 Subject: [PATCH] opencl: Clean handling of lmask32, rmask32 Both arrays are only used in openclwrapper.cpp, so move them into that file. The first element of both arrays was unused. Remove it and fix the code which reads the array elements accordingly. Sort this code, too. These changes reduce the code size a little bit: text data bss dec hex filename 2461743 6676 2742784 5211203 4f8443 1/api/tesseract (old) 2461599 6676 2742784 5211059 4f83b3 2/api/tesseract (new) Signed-off-by: Stefan Weil --- opencl/openclwrapper.cpp | 30 ++++++++++++++++++++++++++---- opencl/openclwrapper.h | 20 -------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/opencl/openclwrapper.cpp b/opencl/openclwrapper.cpp index 106db04966..d0aab27ffe 100644 --- a/opencl/openclwrapper.cpp +++ b/opencl/openclwrapper.cpp @@ -47,6 +47,28 @@ ds_device OpenclDevice::selectedDevice; int OpenclDevice::isInited = 0; +static const l_uint32 lmask32[] = { + 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, + 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, + 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, + 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, + 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, + 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, + 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, + 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff +}; + +static const l_uint32 rmask32[] = { + 0x00000001, 0x00000003, 0x00000007, 0x0000000f, + 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, + 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, + 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, + 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff, + 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff, + 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff, + 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff +}; + struct tiff_transform { int vflip; /* if non-zero, image needs a vertical fip */ int hflip; /* if non-zero, image needs a horizontal flip */ @@ -1474,8 +1496,8 @@ pixErodeCL_55(l_int32 wpl, l_int32 h) l_uint32 fwmask, lwmask; size_t localThreads[2]; - lwmask = lmask32[32 - 2]; - fwmask = rmask32[32 - 2]; + lwmask = lmask32[31 - 2]; + fwmask = rmask32[31 - 2]; //Horizontal pass gsize = (wpl*h + GROUPSIZE_HMORX - 1)/ GROUPSIZE_HMORX * GROUPSIZE_HMORX; @@ -1765,8 +1787,8 @@ pixErodeCL(l_int32 hsize, l_int32 vsize, l_uint32 wpl, l_uint32 h) return status; } - rwmask = rmask32[32 - (xp & 31)]; - lwmask = lmask32[32 - (xn & 31)]; + lwmask = lmask32[31 - (xn & 31)]; + rwmask = rmask32[31 - (xp & 31)]; //global and local work dimensions for Horizontal pass gsize = (wpl + GROUPSIZE_X - 1)/ GROUPSIZE_X * GROUPSIZE_X; diff --git a/opencl/openclwrapper.h b/opencl/openclwrapper.h index e422a09e53..85672067b5 100644 --- a/opencl/openclwrapper.h +++ b/opencl/openclwrapper.h @@ -174,26 +174,6 @@ typedef int ( *cl_kernel_function )( void **userdata, KernelEnv *kenv ); static l_int32 MORPH_BC = ASYMMETRIC_MORPH_BC; -static const l_uint32 lmask32[] = {0x0, - 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, - 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, - 0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, - 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, - 0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, - 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, - 0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, - 0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff}; - -static const l_uint32 rmask32[] = {0x0, - 0x00000001, 0x00000003, 0x00000007, 0x0000000f, - 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, - 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, - 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff, - 0x0001ffff, 0x0003ffff, 0x0007ffff, 0x000fffff, - 0x001fffff, 0x003fffff, 0x007fffff, 0x00ffffff, - 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff, - 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff}; - #define CHECK_OPENCL(status,name) \ if( status != CL_SUCCESS ) \ { \