Skip to content

Commit

Permalink
opencl: Clean handling of lmask32, rmask32
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stweil committed Oct 31, 2016
1 parent 610b2d2 commit aea2022
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
30 changes: 26 additions & 4 deletions opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions opencl/openclwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) \
{ \
Expand Down

0 comments on commit aea2022

Please sign in to comment.