motion-ocr 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +10 -0
- data/LICENSE +28 -0
- data/README.md +22 -0
- data/Rakefile +17 -0
- data/app/app_delegate.rb +2 -0
- data/lib/motion-ocr.rb +26 -0
- data/lib/motion-ocr/version.rb +3 -0
- data/motion-ocr.gemspec +20 -0
- data/resources/tessdata/configs/nodict +3 -0
- data/resources/tessdata/eng.traineddata +0 -0
- data/spec/motion_ocr_spec.rb +23 -0
- data/spec/support/phototest.gif +0 -0
- data/vendor/MotionOCR/MotionOCR.bridgesupport +14722 -0
- data/vendor/MotionOCR/MotionOCR.xcodeproj/project.pbxproj +390 -0
- data/vendor/MotionOCR/MotionOCR.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/vendor/MotionOCR/MotionOCR.xcodeproj/project.xcworkspace/xcuserdata/fer.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/vendor/MotionOCR/MotionOCR.xcodeproj/xcuserdata/fer.xcuserdatad/xcschemes/MotionOCR.xcscheme +59 -0
- data/vendor/MotionOCR/MotionOCR.xcodeproj/xcuserdata/fer.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/vendor/MotionOCR/MotionOCR/MotionOCR-Prefix.pch +7 -0
- data/vendor/MotionOCR/MotionOCR/MotionOCR.h +22 -0
- data/vendor/MotionOCR/MotionOCR/MotionOCR.mm +89 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/allheaders.h +32 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/alltypes.h +49 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/array.h +125 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/arrayaccess.h +194 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bbuffer.h +46 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bmf.h +51 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/bmp.h +74 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/ccbord.h +103 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/dewarp.h +57 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/endianness.h +11 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/environ.h +281 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/freetype.h +23 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/gplot.h +77 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/heap.h +73 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/imageio.h +153 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/jbclass.h +122 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/leptprotos.h +2058 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/leptwin.h +34 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/list.h +76 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/morph.h +218 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/pix.h +945 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/ptra.h +80 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/queue.h +63 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/readbarcode.h +220 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/regutils.h +122 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/stack.h +55 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/sudoku.h +62 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/watershed.h +52 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/apitypes.h +31 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/baseapi.h +664 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/errcode.h +104 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/genericvector.h +763 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/helpers.h +139 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/host.h +180 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/ndminx.h +31 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/ocrclass.h +335 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/platform.h +48 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/publictypes.h +202 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/tesscallback.h +1238 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/thresholder.h +170 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/tesseract/unichar.h +85 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/lib/liblept.a +0 -0
- data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/lib/libtesseract_all.a +0 -0
- metadata +113 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>MotionOCR.xcscheme</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
<key>SuppressBuildableAutocreation</key>
|
|
14
|
+
<dict>
|
|
15
|
+
<key>C15B347A16979EDE00FB5EFE</key>
|
|
16
|
+
<dict>
|
|
17
|
+
<key>primary</key>
|
|
18
|
+
<true/>
|
|
19
|
+
</dict>
|
|
20
|
+
</dict>
|
|
21
|
+
</dict>
|
|
22
|
+
</plist>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MotionOCR.h
|
|
3
|
+
// MotionOCR
|
|
4
|
+
//
|
|
5
|
+
// Created by Fernando Espinosa on 05/01/13.
|
|
6
|
+
// Copyright (c) 2013 com.ferdev. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
#import <UIKit/UIKit.h>
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
|
|
11
|
+
namespace tesseract {
|
|
12
|
+
class TessBaseAPI;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@interface MotionOCR : NSObject
|
|
16
|
+
{
|
|
17
|
+
tesseract::TessBaseAPI *tesseract;
|
|
18
|
+
uint32_t *pixels;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
- (NSString *)scan:(id)image;
|
|
22
|
+
@end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MotionOCR.m
|
|
3
|
+
// MotionOCR
|
|
4
|
+
//
|
|
5
|
+
// Created by Fernando Espinosa on 05/01/13.
|
|
6
|
+
// Copyright (c) 2013 com.ferdev. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "MotionOCR.h"
|
|
10
|
+
|
|
11
|
+
#include "baseapi.h"
|
|
12
|
+
|
|
13
|
+
#include "environ.h"
|
|
14
|
+
#import "pix.h"
|
|
15
|
+
|
|
16
|
+
@implementation MotionOCR
|
|
17
|
+
|
|
18
|
+
- (id)init {
|
|
19
|
+
self = [super init];
|
|
20
|
+
|
|
21
|
+
if (self) {
|
|
22
|
+
// Set up the tessdata path. This is included in the application bundle
|
|
23
|
+
// but is copied to the Documents directory on the first run.
|
|
24
|
+
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
25
|
+
NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
|
|
26
|
+
|
|
27
|
+
NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
|
|
28
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
29
|
+
// If the expected store doesn't exist, copy the default store.
|
|
30
|
+
if (![fileManager fileExistsAtPath:dataPath]) {
|
|
31
|
+
// get the path to the app bundle (with the tessdata dir)
|
|
32
|
+
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
|
|
33
|
+
NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
|
|
34
|
+
if (tessdataPath) {
|
|
35
|
+
[fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
|
|
40
|
+
|
|
41
|
+
tesseract = new tesseract::TessBaseAPI();
|
|
42
|
+
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng");
|
|
43
|
+
}
|
|
44
|
+
return self;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (void)dealloc {
|
|
48
|
+
delete tesseract;
|
|
49
|
+
tesseract = nil;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (NSString *)scan:(id)image
|
|
53
|
+
{
|
|
54
|
+
[self setTesseractImage:(CGImageRef)image];
|
|
55
|
+
|
|
56
|
+
tesseract->Recognize(NULL);
|
|
57
|
+
char* utf8Text = tesseract->GetUTF8Text();
|
|
58
|
+
NSString *result = [NSString stringWithUTF8String:utf8Text];
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (void)setTesseractImage:(CGImageRef)image
|
|
64
|
+
{
|
|
65
|
+
free(pixels);
|
|
66
|
+
|
|
67
|
+
size_t width = CGImageGetWidth(image);
|
|
68
|
+
size_t height = CGImageGetHeight(image);
|
|
69
|
+
|
|
70
|
+
if (width <= 0 || height <= 0)
|
|
71
|
+
return;
|
|
72
|
+
|
|
73
|
+
pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t));
|
|
74
|
+
memset(pixels, 0, width * height * sizeof(uint32_t));
|
|
75
|
+
|
|
76
|
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
77
|
+
|
|
78
|
+
CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace,
|
|
79
|
+
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
|
|
80
|
+
|
|
81
|
+
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
|
|
82
|
+
|
|
83
|
+
CGContextRelease(context);
|
|
84
|
+
CGColorSpaceRelease(colorSpace);
|
|
85
|
+
|
|
86
|
+
tesseract->SetImage((const unsigned char *) pixels, width, height, sizeof(uint32_t), width * sizeof(uint32_t));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@end
|
data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/allheaders.h
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*====================================================================*
|
|
2
|
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
|
3
|
+
- This software is distributed in the hope that it will be
|
|
4
|
+
- useful, but with NO WARRANTY OF ANY KIND.
|
|
5
|
+
- No author or distributor accepts responsibility to anyone for the
|
|
6
|
+
- consequences of using this software, or for whether it serves any
|
|
7
|
+
- particular purpose or works at all, unless he or she says so in
|
|
8
|
+
- writing. Everyone is granted permission to copy, modify and
|
|
9
|
+
- redistribute this source code, for commercial or non-commercial
|
|
10
|
+
- purposes, with the following restrictions: (1) the origin of this
|
|
11
|
+
- source code must not be misrepresented; (2) modified versions must
|
|
12
|
+
- be plainly marked as such; and (3) this notice may not be removed
|
|
13
|
+
- or altered from any source or modified source distribution.
|
|
14
|
+
*====================================================================*/
|
|
15
|
+
|
|
16
|
+
#ifndef LEPTONICA_ALLHEADERS_H
|
|
17
|
+
#define LEPTONICA_ALLHEADERS_H
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#define LIBLEPT_MAJOR_VERSION 1
|
|
21
|
+
#define LIBLEPT_MINOR_VERSION 68
|
|
22
|
+
|
|
23
|
+
#include "alltypes.h"
|
|
24
|
+
|
|
25
|
+
#ifndef NO_PROTOS
|
|
26
|
+
#include "leptprotos.h"
|
|
27
|
+
#endif /* NO_PROTOS */
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
#endif /* LEPTONICA_ALLHEADERS_H */
|
|
31
|
+
|
|
32
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*====================================================================*
|
|
2
|
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
|
3
|
+
- This software is distributed in the hope that it will be
|
|
4
|
+
- useful, but with NO WARRANTY OF ANY KIND.
|
|
5
|
+
- No author or distributor accepts responsibility to anyone for the
|
|
6
|
+
- consequences of using this software, or for whether it serves any
|
|
7
|
+
- particular purpose or works at all, unless he or she says so in
|
|
8
|
+
- writing. Everyone is granted permission to copy, modify and
|
|
9
|
+
- redistribute this source code, for commercial or non-commercial
|
|
10
|
+
- purposes, with the following restrictions: (1) the origin of this
|
|
11
|
+
- source code must not be misrepresented; (2) modified versions must
|
|
12
|
+
- be plainly marked as such; and (3) this notice may not be removed
|
|
13
|
+
- or altered from any source or modified source distribution.
|
|
14
|
+
*====================================================================*/
|
|
15
|
+
|
|
16
|
+
#ifndef LEPTONICA_ALLTYPES_H
|
|
17
|
+
#define LEPTONICA_ALLTYPES_H
|
|
18
|
+
|
|
19
|
+
/* Standard */
|
|
20
|
+
#include <stdio.h>
|
|
21
|
+
#include <stdlib.h>
|
|
22
|
+
|
|
23
|
+
/* General and configuration defs */
|
|
24
|
+
#include "environ.h"
|
|
25
|
+
|
|
26
|
+
/* Imaging */
|
|
27
|
+
#include "array.h"
|
|
28
|
+
#include "arrayaccess.h"
|
|
29
|
+
#include "bbuffer.h"
|
|
30
|
+
#include "bmf.h"
|
|
31
|
+
#include "ccbord.h"
|
|
32
|
+
#include "dewarp.h"
|
|
33
|
+
#include "gplot.h"
|
|
34
|
+
#include "heap.h"
|
|
35
|
+
#include "imageio.h"
|
|
36
|
+
#include "jbclass.h"
|
|
37
|
+
#include "list.h"
|
|
38
|
+
#include "morph.h"
|
|
39
|
+
#include "pix.h"
|
|
40
|
+
#include "ptra.h"
|
|
41
|
+
#include "queue.h"
|
|
42
|
+
#include "regutils.h"
|
|
43
|
+
#include "sudoku.h"
|
|
44
|
+
#include "stack.h"
|
|
45
|
+
#include "watershed.h"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
#endif /* LEPTONICA_ALLTYPES_H */
|
|
49
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*====================================================================*
|
|
2
|
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
|
3
|
+
- This software is distributed in the hope that it will be
|
|
4
|
+
- useful, but with NO WARRANTY OF ANY KIND.
|
|
5
|
+
- No author or distributor accepts responsibility to anyone for the
|
|
6
|
+
- consequences of using this software, or for whether it serves any
|
|
7
|
+
- particular purpose or works at all, unless he or she says so in
|
|
8
|
+
- writing. Everyone is granted permission to copy, modify and
|
|
9
|
+
- redistribute this source code, for commercial or non-commercial
|
|
10
|
+
- purposes, with the following restrictions: (1) the origin of this
|
|
11
|
+
- source code must not be misrepresented; (2) modified versions must
|
|
12
|
+
- be plainly marked as such; and (3) this notice may not be removed
|
|
13
|
+
- or altered from any source or modified source distribution.
|
|
14
|
+
*====================================================================*/
|
|
15
|
+
|
|
16
|
+
#ifndef LEPTONICA_ARRAY_H
|
|
17
|
+
#define LEPTONICA_ARRAY_H
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Contains the following structs:
|
|
21
|
+
* struct Numa
|
|
22
|
+
* struct Numaa
|
|
23
|
+
* struct Numa2d
|
|
24
|
+
* struct NumaHash
|
|
25
|
+
* struct Sarray
|
|
26
|
+
* struct L_Bytea
|
|
27
|
+
*
|
|
28
|
+
* Contains definitions for:
|
|
29
|
+
* Numa interpolation flags
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/*------------------------------------------------------------------------*
|
|
34
|
+
* Array Structs *
|
|
35
|
+
*------------------------------------------------------------------------*/
|
|
36
|
+
|
|
37
|
+
#define NUMA_VERSION_NUMBER 1
|
|
38
|
+
|
|
39
|
+
/* Number array: an array of floats */
|
|
40
|
+
struct Numa
|
|
41
|
+
{
|
|
42
|
+
l_int32 nalloc; /* size of allocated number array */
|
|
43
|
+
l_int32 n; /* number of numbers saved */
|
|
44
|
+
l_int32 refcount; /* reference count (1 if no clones) */
|
|
45
|
+
l_float32 startx; /* x value assigned to array[0] */
|
|
46
|
+
l_float32 delx; /* change in x value as i --> i + 1 */
|
|
47
|
+
l_float32 *array; /* number array */
|
|
48
|
+
};
|
|
49
|
+
typedef struct Numa NUMA;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/* Array of number arrays */
|
|
53
|
+
struct Numaa
|
|
54
|
+
{
|
|
55
|
+
l_int32 nalloc; /* size of allocated ptr array */
|
|
56
|
+
l_int32 n; /* number of Numa saved */
|
|
57
|
+
struct Numa **numa; /* array of Numa */
|
|
58
|
+
};
|
|
59
|
+
typedef struct Numaa NUMAA;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/* Sparse 2-dimensional array of number arrays */
|
|
64
|
+
struct Numa2d
|
|
65
|
+
{
|
|
66
|
+
l_int32 nrows; /* number of rows allocated for ptr array */
|
|
67
|
+
l_int32 ncols; /* number of cols allocated for ptr array */
|
|
68
|
+
l_int32 initsize; /* initial size of each numa that is made */
|
|
69
|
+
struct Numa ***numa; /* 2D array of Numa */
|
|
70
|
+
};
|
|
71
|
+
typedef struct Numa2d NUMA2D;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/* A hash table of Numas */
|
|
75
|
+
struct NumaHash
|
|
76
|
+
{
|
|
77
|
+
l_int32 nbuckets;
|
|
78
|
+
l_int32 initsize; /* initial size of each numa that is made */
|
|
79
|
+
struct Numa **numa;
|
|
80
|
+
};
|
|
81
|
+
typedef struct NumaHash NUMAHASH;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#define SARRAY_VERSION_NUMBER 1
|
|
85
|
+
|
|
86
|
+
/* String array: an array of C strings */
|
|
87
|
+
struct Sarray
|
|
88
|
+
{
|
|
89
|
+
l_int32 nalloc; /* size of allocated ptr array */
|
|
90
|
+
l_int32 n; /* number of strings allocated */
|
|
91
|
+
l_int32 refcount; /* reference count (1 if no clones) */
|
|
92
|
+
char **array; /* string array */
|
|
93
|
+
};
|
|
94
|
+
typedef struct Sarray SARRAY;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/* Byte array (analogous to C++ "string") */
|
|
98
|
+
struct L_Bytea
|
|
99
|
+
{
|
|
100
|
+
size_t nalloc; /* number of bytes allocated in data array */
|
|
101
|
+
size_t size; /* number of bytes presently used */
|
|
102
|
+
l_int32 refcount; /* reference count (1 if no clones) */
|
|
103
|
+
l_uint8 *data; /* data array */
|
|
104
|
+
};
|
|
105
|
+
typedef struct L_Bytea L_BYTEA;
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/*------------------------------------------------------------------------*
|
|
109
|
+
* Array flags *
|
|
110
|
+
*------------------------------------------------------------------------*/
|
|
111
|
+
|
|
112
|
+
/* Flags for interpolation in Numa */
|
|
113
|
+
enum {
|
|
114
|
+
L_LINEAR_INTERP = 1, /* linear */
|
|
115
|
+
L_QUADRATIC_INTERP = 2 /* quadratic */
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/* Flags for added borders in Numa */
|
|
119
|
+
enum {
|
|
120
|
+
L_EXTENDED_BORDER = 1, /* extended with same value */
|
|
121
|
+
L_MIRRORED_BORDER = 2 /* mirrored */
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
#endif /* LEPTONICA_ARRAY_H */
|
data/vendor/MotionOCR/MotionOCR/build_dependencies/dependencies/include/leptonica/arrayaccess.h
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/*====================================================================*
|
|
2
|
+
- Copyright (C) 2001 Leptonica. All rights reserved.
|
|
3
|
+
- This software is distributed in the hope that it will be
|
|
4
|
+
- useful, but with NO WARRANTY OF ANY KIND.
|
|
5
|
+
- No author or distributor accepts responsibility to anyone for the
|
|
6
|
+
- consequences of using this software, or for whether it serves any
|
|
7
|
+
- particular purpose or works at all, unless he or she says so in
|
|
8
|
+
- writing. Everyone is granted permission to copy, modify and
|
|
9
|
+
- redistribute this source code, for commercial or non-commercial
|
|
10
|
+
- purposes, with the following restrictions: (1) the origin of this
|
|
11
|
+
- source code must not be misrepresented; (2) modified versions must
|
|
12
|
+
- be plainly marked as such; and (3) this notice may not be removed
|
|
13
|
+
- or altered from any source or modified source distribution.
|
|
14
|
+
*====================================================================*/
|
|
15
|
+
|
|
16
|
+
#ifndef LEPTONICA_ARRAY_ACCESS_H
|
|
17
|
+
#define LEPTONICA_ARRAY_ACCESS_H
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* arrayaccess.h
|
|
21
|
+
*
|
|
22
|
+
* 1, 2, 4, 8, 16 and 32 bit data access within an array of 32-bit words
|
|
23
|
+
*
|
|
24
|
+
* This is used primarily to access 1, 2, 4, 8, 16 and 32 bit pixels
|
|
25
|
+
* in a line of image data, represented as an array of 32-bit words.
|
|
26
|
+
*
|
|
27
|
+
* pdata: pointer to first 32-bit word in the array
|
|
28
|
+
* n: index of the pixel in the array
|
|
29
|
+
*
|
|
30
|
+
* Function calls for these accessors are defined in arrayaccess.c.
|
|
31
|
+
*
|
|
32
|
+
* However, for efficiency we use the inline macros for all accesses.
|
|
33
|
+
* Even though the 2 and 4 bit set* accessors are more complicated,
|
|
34
|
+
* they are about 10% faster than the function calls.
|
|
35
|
+
*
|
|
36
|
+
* The 32 bit access is just a cast and ptr arithmetic. We include
|
|
37
|
+
* it so that the input ptr can be void*.
|
|
38
|
+
*
|
|
39
|
+
* At the end of this file is code for invoking the function calls
|
|
40
|
+
* instead of inlining.
|
|
41
|
+
*
|
|
42
|
+
* The macro SET_DATA_BIT_VAL(pdata, n, val) is a bit slower than
|
|
43
|
+
* if (val == 0)
|
|
44
|
+
* CLEAR_DATA_BIT(pdata, n);
|
|
45
|
+
* else
|
|
46
|
+
* SET_DATA_BIT(pdata, n);
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/* Use the inline accessors (except with _MSC_VER), because they
|
|
51
|
+
* are faster. */
|
|
52
|
+
#define USE_INLINE_ACCESSORS 1
|
|
53
|
+
|
|
54
|
+
#if USE_INLINE_ACCESSORS
|
|
55
|
+
#ifndef _MSC_VER
|
|
56
|
+
|
|
57
|
+
/*--------------------------------------------------*
|
|
58
|
+
* 1 bit access *
|
|
59
|
+
*--------------------------------------------------*/
|
|
60
|
+
#define GET_DATA_BIT(pdata, n) \
|
|
61
|
+
((*((l_uint32 *)(pdata) + ((n) >> 5)) >> (31 - ((n) & 31))) & 1)
|
|
62
|
+
|
|
63
|
+
#define SET_DATA_BIT(pdata, n) \
|
|
64
|
+
(*((l_uint32 *)(pdata) + ((n) >> 5)) |= (0x80000000 >> ((n) & 31)))
|
|
65
|
+
|
|
66
|
+
#define CLEAR_DATA_BIT(pdata, n) \
|
|
67
|
+
(*((l_uint32 *)(pdata) + ((n) >> 5)) &= ~(0x80000000 >> ((n) & 31)))
|
|
68
|
+
|
|
69
|
+
#define SET_DATA_BIT_VAL(pdata, n, val) \
|
|
70
|
+
({l_uint32 *_TEMP_WORD_PTR_; \
|
|
71
|
+
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 5); \
|
|
72
|
+
*_TEMP_WORD_PTR_ &= ~(0x80000000 >> ((n) & 31)); \
|
|
73
|
+
*_TEMP_WORD_PTR_ |= ((val) << (31 - ((n) & 31))); \
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/*--------------------------------------------------*
|
|
78
|
+
* 2 bit access *
|
|
79
|
+
*--------------------------------------------------*/
|
|
80
|
+
#define GET_DATA_DIBIT(pdata, n) \
|
|
81
|
+
((*((l_uint32 *)(pdata) + ((n) >> 4)) >> (2 * (15 - ((n) & 15)))) & 3)
|
|
82
|
+
|
|
83
|
+
#define SET_DATA_DIBIT(pdata, n, val) \
|
|
84
|
+
({l_uint32 *_TEMP_WORD_PTR_; \
|
|
85
|
+
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 4); \
|
|
86
|
+
*_TEMP_WORD_PTR_ &= ~(0xc0000000 >> (2 * ((n) & 15))); \
|
|
87
|
+
*_TEMP_WORD_PTR_ |= (((val) & 3) << (30 - 2 * ((n) & 15))); \
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
#define CLEAR_DATA_DIBIT(pdata, n) \
|
|
91
|
+
(*((l_uint32 *)(pdata) + ((n) >> 4)) &= ~(0xc0000000 >> (2 * ((n) & 15))))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/*--------------------------------------------------*
|
|
95
|
+
* 4 bit access *
|
|
96
|
+
*--------------------------------------------------*/
|
|
97
|
+
#define GET_DATA_QBIT(pdata, n) \
|
|
98
|
+
((*((l_uint32 *)(pdata) + ((n) >> 3)) >> (4 * (7 - ((n) & 7)))) & 0xf)
|
|
99
|
+
|
|
100
|
+
#define SET_DATA_QBIT(pdata, n, val) \
|
|
101
|
+
({l_uint32 *_TEMP_WORD_PTR_; \
|
|
102
|
+
_TEMP_WORD_PTR_ = (l_uint32 *)(pdata) + ((n) >> 3); \
|
|
103
|
+
*_TEMP_WORD_PTR_ &= ~(0xf0000000 >> (4 * ((n) & 7))); \
|
|
104
|
+
*_TEMP_WORD_PTR_ |= (((val) & 15) << (28 - 4 * ((n) & 7))); \
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
#define CLEAR_DATA_QBIT(pdata, n) \
|
|
108
|
+
(*((l_uint32 *)(pdata) + ((n) >> 3)) &= ~(0xf0000000 >> (4 * ((n) & 7))))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/*--------------------------------------------------*
|
|
112
|
+
* 8 bit access *
|
|
113
|
+
*--------------------------------------------------*/
|
|
114
|
+
#ifdef L_BIG_ENDIAN
|
|
115
|
+
#define GET_DATA_BYTE(pdata, n) \
|
|
116
|
+
(*((l_uint8 *)(pdata) + (n)))
|
|
117
|
+
#else /* L_LITTLE_ENDIAN */
|
|
118
|
+
#define GET_DATA_BYTE(pdata, n) \
|
|
119
|
+
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3))
|
|
120
|
+
#endif /* L_BIG_ENDIAN */
|
|
121
|
+
|
|
122
|
+
#ifdef L_BIG_ENDIAN
|
|
123
|
+
#define SET_DATA_BYTE(pdata, n, val) \
|
|
124
|
+
(*((l_uint8 *)(pdata) + (n)) = (val))
|
|
125
|
+
#else /* L_LITTLE_ENDIAN */
|
|
126
|
+
#define SET_DATA_BYTE(pdata, n, val) \
|
|
127
|
+
(*(l_uint8 *)((l_uintptr_t)((l_uint8 *)(pdata) + (n)) ^ 3) = (val))
|
|
128
|
+
#endif /* L_BIG_ENDIAN */
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
/*--------------------------------------------------*
|
|
132
|
+
* 16 bit access *
|
|
133
|
+
*--------------------------------------------------*/
|
|
134
|
+
#ifdef L_BIG_ENDIAN
|
|
135
|
+
#define GET_DATA_TWO_BYTES(pdata, n) \
|
|
136
|
+
(*((l_uint16 *)(pdata) + (n)))
|
|
137
|
+
#else /* L_LITTLE_ENDIAN */
|
|
138
|
+
#define GET_DATA_TWO_BYTES(pdata, n) \
|
|
139
|
+
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2))
|
|
140
|
+
#endif /* L_BIG_ENDIAN */
|
|
141
|
+
|
|
142
|
+
#ifdef L_BIG_ENDIAN
|
|
143
|
+
#define SET_DATA_TWO_BYTES(pdata, n, val) \
|
|
144
|
+
(*((l_uint16 *)(pdata) + (n)) = (val))
|
|
145
|
+
#else /* L_LITTLE_ENDIAN */
|
|
146
|
+
#define SET_DATA_TWO_BYTES(pdata, n, val) \
|
|
147
|
+
(*(l_uint16 *)((l_uintptr_t)((l_uint16 *)(pdata) + (n)) ^ 2) = (val))
|
|
148
|
+
#endif /* L_BIG_ENDIAN */
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/*--------------------------------------------------*
|
|
152
|
+
* 32 bit access *
|
|
153
|
+
*--------------------------------------------------*/
|
|
154
|
+
#define GET_DATA_FOUR_BYTES(pdata, n) \
|
|
155
|
+
(*((l_uint32 *)(pdata) + (n)))
|
|
156
|
+
|
|
157
|
+
#define SET_DATA_FOUR_BYTES(pdata, n, val) \
|
|
158
|
+
(*((l_uint32 *)(pdata) + (n)) = (val))
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
#endif /* ! _MSC_VER */
|
|
162
|
+
#endif /* USE_INLINE_ACCESSORS */
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
/*--------------------------------------------------*
|
|
167
|
+
* Slower, using function calls for all accessors *
|
|
168
|
+
*--------------------------------------------------*/
|
|
169
|
+
#if !USE_INLINE_ACCESSORS || defined(_MSC_VER)
|
|
170
|
+
#define GET_DATA_BIT(pdata, n) l_getDataBit(pdata, n)
|
|
171
|
+
#define SET_DATA_BIT(pdata, n) l_setDataBit(pdata, n)
|
|
172
|
+
#define CLEAR_DATA_BIT(pdata, n) l_clearDataBit(pdata, n)
|
|
173
|
+
#define SET_DATA_BIT_VAL(pdata, n, val) l_setDataBitVal(pdata, n, val)
|
|
174
|
+
|
|
175
|
+
#define GET_DATA_DIBIT(pdata, n) l_getDataDibit(pdata, n)
|
|
176
|
+
#define SET_DATA_DIBIT(pdata, n, val) l_setDataDibit(pdata, n, val)
|
|
177
|
+
#define CLEAR_DATA_DIBIT(pdata, n) l_clearDataDibit(pdata, n)
|
|
178
|
+
|
|
179
|
+
#define GET_DATA_QBIT(pdata, n) l_getDataQbit(pdata, n)
|
|
180
|
+
#define SET_DATA_QBIT(pdata, n, val) l_setDataQbit(pdata, n, val)
|
|
181
|
+
#define CLEAR_DATA_QBIT(pdata, n) l_clearDataQbit(pdata, n)
|
|
182
|
+
|
|
183
|
+
#define GET_DATA_BYTE(pdata, n) l_getDataByte(pdata, n)
|
|
184
|
+
#define SET_DATA_BYTE(pdata, n, val) l_setDataByte(pdata, n, val)
|
|
185
|
+
|
|
186
|
+
#define GET_DATA_TWO_BYTES(pdata, n) l_getDataTwoBytes(pdata, n)
|
|
187
|
+
#define SET_DATA_TWO_BYTES(pdata, n, val) l_setDataTwoBytes(pdata, n, val)
|
|
188
|
+
|
|
189
|
+
#define GET_DATA_FOUR_BYTES(pdata, n) l_getDataFourBytes(pdata, n)
|
|
190
|
+
#define SET_DATA_FOUR_BYTES(pdata, n, val) l_setDataFourBytes(pdata, n, val)
|
|
191
|
+
#endif /* !USE_INLINE_ACCESSORS || _MSC_VER */
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
#endif /* LEPTONICA_ARRAY_ACCESS_H */
|