├── README.md
├── ZBar-iOS.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── fujun.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── fujun.xcuserdatad
│ └── xcschemes
│ ├── ZBar-iOS.xcscheme
│ └── xcschememanagement.plist
├── ZBar-iOS
├── AppDelegate.h
├── AppDelegate.m
├── Base.lproj
│ ├── LaunchScreen.xib
│ └── Main.storyboard
├── Images.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── LaunchImage.launchimage
│ │ └── Contents.json
├── Info.plist
├── ViewController.h
├── ViewController.m
├── ZBarSDK
│ ├── ZBarCVImage.h
│ ├── ZBarCVImage.m
│ ├── ZBarCameraSimulator.h
│ ├── ZBarCameraSimulator.m
│ ├── ZBarCaptureReader.h
│ ├── ZBarCaptureReader.m
│ ├── ZBarHelpController.h
│ ├── ZBarHelpController.m
│ ├── ZBarImage.h
│ ├── ZBarImage.m
│ ├── ZBarImageScanner.h
│ ├── ZBarImageScanner.m
│ ├── ZBarReaderController.h
│ ├── ZBarReaderController.m
│ ├── ZBarReaderView.h
│ ├── ZBarReaderView.m
│ ├── ZBarReaderViewController.h
│ ├── ZBarReaderViewController.m
│ ├── ZBarReaderViewImpl_Capture.m
│ ├── ZBarSDK.h
│ ├── ZBarSymbol.h
│ ├── ZBarSymbol.m
│ ├── config.h
│ ├── iphoneDebug.h
│ ├── prefix.pch
│ ├── zbar.h
│ └── zbar
│ │ ├── config.c
│ │ ├── debug.h
│ │ ├── decoder.c
│ │ ├── decoder.h
│ │ ├── decoder
│ │ ├── codabar.c
│ │ ├── codabar.h
│ │ ├── code128.c
│ │ ├── code128.h
│ │ ├── code39.c
│ │ ├── code39.h
│ │ ├── code93.c
│ │ ├── code93.h
│ │ ├── databar.c
│ │ ├── databar.h
│ │ ├── ean.c
│ │ ├── ean.h
│ │ ├── i25.c
│ │ ├── i25.h
│ │ ├── qr_finder.c
│ │ └── qr_finder.h
│ │ ├── error.c
│ │ ├── error.h
│ │ ├── image.c
│ │ ├── image.h
│ │ ├── img_scanner.c
│ │ ├── img_scanner.h
│ │ ├── qrcode.h
│ │ ├── qrcode
│ │ ├── bch15_5.c
│ │ ├── bch15_5.h
│ │ ├── binarize.c
│ │ ├── binarize.h
│ │ ├── isaac.c
│ │ ├── isaac.h
│ │ ├── qrdec.c
│ │ ├── qrdec.h
│ │ ├── qrdectxt.c
│ │ ├── rs.c
│ │ ├── rs.h
│ │ ├── util.c
│ │ └── util.h
│ │ ├── refcnt.c
│ │ ├── refcnt.h
│ │ ├── scanner.c
│ │ ├── svg.h
│ │ ├── symbol.c
│ │ ├── symbol.h
│ │ └── timer.h
└── main.m
└── ZBar-iOSTests
├── Info.plist
└── ZBar_iOSTests.m
/README.md:
--------------------------------------------------------------------------------
1 | # ZBar-iOS
2 |
3 | [ZBar](https://github.com/ZBar/ZBar)从2012年之后就没有更新过了,所以在iOS上,如果使用ZBar的话,那么ZBar默认提供的只有32位的静态库,当然我们可以直接下载到ZBar的源码,然后编译64位的版本,这很方便。
4 |
5 | 当我们有更深一层的需要的时候,我们可能会要求将ZBar的源码直接嵌入我们的项目中,而这个就是一个被剥离出来的ZBar-iOS部分。可以直接嵌入到项目中。
6 |
7 | 由于历史的悠久,ZBar在64位iOS下编译有大量的警告,我这里将Build Phases中的文件编译flag中加入了一些参数,默认不显示这些类型的警告。
8 |
9 | 由于在剥离后,在64位下编译有一些问题,我修改了部分内容,很少,我这就不写出了,但是并不影响大家使用。
10 |
11 | 当然,都已经是源码了,并且这个项目已死,大家可以直接修改,而不用担心升级更新的问题。
12 |
13 | 步骤:
14 |
15 | 1. 在你的项目中加入下面的库:
16 |
17 | libiconv.dylib
18 | CoreVideo.framework
19 | CoreMedia.framework
20 | AVFoundation.framework
21 |
22 | 2. 将ZBarSDK文件夹拖拽或者拷贝到你的工程目录下面
23 | 3. 参照ZBar官方给的[Demo](https://github.com/ZBar/ZBar/tree/master/iphone/examples)即可正常使用
24 |
--------------------------------------------------------------------------------
/ZBar-iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ZBar-iOS.xcodeproj/project.xcworkspace/xcuserdata/fujun.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Forkong/ZBar-iOS/ff6cf92473afa7ecc2987f0ace3b90e4400e08b7/ZBar-iOS.xcodeproj/project.xcworkspace/xcuserdata/fujun.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/ZBar-iOS.xcodeproj/xcuserdata/fujun.xcuserdatad/xcschemes/ZBar-iOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
44 |
45 |
47 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
68 |
78 |
80 |
86 |
87 |
88 |
89 |
90 |
91 |
97 |
99 |
105 |
106 |
107 |
108 |
110 |
111 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/ZBar-iOS.xcodeproj/xcuserdata/fujun.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | ZBar-iOS.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 794CA6521B42C7E500CE72DB
16 |
17 | primary
18 |
19 |
20 | 794CA66B1B42C7E500CE72DB
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/ZBar-iOS/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // ZBar-iOS
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/ZBar-iOS/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // ZBar-iOS
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/ZBar-iOS/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/ZBar-iOS/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ZBar-iOS/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/ZBar-iOS/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "minimum-system-version" : "7.0",
7 | "subtype" : "retina4",
8 | "scale" : "2x"
9 | },
10 | {
11 | "idiom" : "iphone",
12 | "scale" : "1x",
13 | "orientation" : "portrait"
14 | },
15 | {
16 | "idiom" : "iphone",
17 | "scale" : "2x",
18 | "orientation" : "portrait"
19 | },
20 | {
21 | "orientation" : "portrait",
22 | "idiom" : "iphone",
23 | "subtype" : "retina4",
24 | "scale" : "2x"
25 | },
26 | {
27 | "orientation" : "portrait",
28 | "idiom" : "iphone",
29 | "minimum-system-version" : "7.0",
30 | "scale" : "2x"
31 | }
32 | ],
33 | "info" : {
34 | "version" : 1,
35 | "author" : "xcode"
36 | }
37 | }
--------------------------------------------------------------------------------
/ZBar-iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/ZBar-iOS/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // ZBar-iOS
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/ZBar-iOS/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // ZBar-iOS
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 |
11 | @interface ViewController ()
12 |
13 | @end
14 |
15 | @implementation ViewController
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 | // Do any additional setup after loading the view, typically from a nib.
20 | }
21 |
22 | - (void)didReceiveMemoryWarning {
23 | [super didReceiveMemoryWarning];
24 | // Dispose of any resources that can be recreated.
25 | }
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarCVImage.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarImage.h"
25 | #import
26 |
27 | // ZBarImage referring to a CVPixelBuffer. used internally to handle
28 | // asynchronous conversion to UIImage
29 |
30 | @interface ZBarCVImage
31 | : ZBarImage
32 | {
33 | CVPixelBufferRef pixelBuffer;
34 | void *rgbBuffer;
35 | NSInvocationOperation *conversion;
36 | }
37 |
38 | - (void) waitUntilConverted;
39 |
40 | @property (nonatomic) CVPixelBufferRef pixelBuffer;
41 | @property (nonatomic, readonly) void *rgbBuffer;
42 |
43 | @end
44 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarCVImage.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarCVImage.h"
25 | #define MODULE ZBarCVImage
26 | #import "debug.h"
27 | #import "iphoneDebug.h"
28 | static NSOperationQueue *conversionQueue;
29 |
30 | static const void*
31 | asyncProvider_getBytePointer (void *info)
32 | {
33 | // block until data is available
34 | ZBarCVImage *image = info;
35 | assert(image);
36 | [image waitUntilConverted];
37 | void *buf = image.rgbBuffer;
38 | assert(buf);
39 | return(buf);
40 | }
41 |
42 | static const CGDataProviderDirectCallbacks asyncProvider = {
43 | .version = 0,
44 | .getBytePointer = asyncProvider_getBytePointer,
45 | .releaseBytePointer = NULL,
46 | .getBytesAtPosition = NULL,
47 | .releaseInfo = (void*)CFRelease,
48 | };
49 |
50 | @implementation ZBarCVImage
51 |
52 | @synthesize pixelBuffer, rgbBuffer;
53 |
54 | - (void) dealloc
55 | {
56 | self.pixelBuffer = NULL;
57 | if(rgbBuffer) {
58 | free(rgbBuffer);
59 | rgbBuffer = NULL;
60 | }
61 | [conversion release];
62 | conversion = nil;
63 | [super dealloc];
64 | }
65 |
66 | - (void) setPixelBuffer: (CVPixelBufferRef) newbuf
67 | {
68 | CVPixelBufferRef oldbuf = pixelBuffer;
69 | if(newbuf)
70 | CVPixelBufferRetain(newbuf);
71 | pixelBuffer = newbuf;
72 | if(oldbuf)
73 | CVPixelBufferRelease(oldbuf);
74 | }
75 |
76 | - (void) waitUntilConverted
77 | {
78 | // operation will at least have been queued already
79 | NSOperation *op = [conversion retain];
80 | if(!op)
81 | return;
82 | [op waitUntilFinished];
83 | [op release];
84 | }
85 |
86 | - (UIImage*) UIImageWithOrientation: (UIImageOrientation) orient
87 | {
88 | if(!conversion && !rgbBuffer) {
89 | // start format conversion in separate thread
90 | NSOperationQueue *queue = conversionQueue;
91 | if(!queue) {
92 | queue = conversionQueue = [NSOperationQueue new];
93 | queue.maxConcurrentOperationCount = 1;
94 | }
95 | else
96 | [queue waitUntilAllOperationsAreFinished];
97 |
98 | conversion = [[NSInvocationOperation alloc]
99 | initWithTarget: self
100 | selector: @selector(convertCVtoRGB)
101 | object: nil];
102 | [queue addOperation: conversion];
103 | [conversion release];
104 | }
105 |
106 | // create UIImage before converted data is available
107 | CGSize size = self.size;
108 | int w = size.width;
109 | int h = size.height;
110 |
111 | CGDataProviderRef datasrc =
112 | CGDataProviderCreateDirect([self retain], 3 * w * h, &asyncProvider);
113 | CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
114 | CGImageRef cgimg =
115 | CGImageCreate(w, h, 8, 24, 3 * w, cs,
116 | kCGBitmapByteOrderDefault, datasrc,
117 | NULL, YES, kCGRenderingIntentDefault);
118 | CGColorSpaceRelease(cs);
119 | CGDataProviderRelease(datasrc);
120 |
121 | UIImage *uiimg =
122 | [UIImage imageWithCGImage: cgimg
123 | scale: 1
124 | orientation: orient];
125 | CGImageRelease(cgimg);
126 |
127 | return(uiimg);
128 | }
129 |
130 | // convert video frame to a CGImage compatible RGB format
131 | // FIXME this is temporary until we can find the native way...
132 | - (void) convertCVtoRGB
133 | {
134 | timer_start;
135 | unsigned long format = self.format;
136 | assert(format == zbar_fourcc('C','V','2','P'));
137 | if(format != zbar_fourcc('C','V','2','P'))
138 | return;
139 |
140 | CVPixelBufferLockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
141 | int w = CVPixelBufferGetWidth(pixelBuffer);
142 | int h = CVPixelBufferGetHeight(pixelBuffer);
143 | int dy = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 0);
144 | int duv = CVPixelBufferGetBytesPerRowOfPlane(pixelBuffer, 1);
145 | uint8_t *py = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 0);
146 | uint8_t *puv = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer, 1);
147 | if(!py || !puv || dy < w || duv < w)
148 | goto error;
149 |
150 | int datalen = 3 * w * h;
151 | // Quartz accesses some undocumented amount past allocated data?
152 | // ...allocate extra to compensate
153 | uint8_t *pdst = rgbBuffer = malloc(datalen + 3 * w);
154 | if(!pdst)
155 | goto error;
156 | [self setData: rgbBuffer
157 | withLength: datalen];
158 |
159 | for(int y = 0; y < h; y++) {
160 | const uint8_t *qy = py;
161 | const uint8_t *quv = puv;
162 | for(int x = 0; x < w; x++) {
163 | int Y1 = *(qy++) - 16;
164 | int Cb = *(quv) - 128;
165 | int Cr = *(quv + 1) - 128;
166 | Y1 *= 4769;
167 | quv += (x & 1) << 1;
168 | int r = (Y1 + 6537 * Cr + 2048) / 4096;
169 | int g = (Y1 - 1604 * Cb - 3329 * Cr + 2048) / 4096;
170 | int b = (Y1 + 8263 * Cb + 2048) / 4096;
171 |
172 | r = (r | -!!(r >> 8)) & -((r >> 8) >= 0);
173 | g = (g | -!!(g >> 8)) & -((g >> 8) >= 0);
174 | b = (b | -!!(b >> 8)) & -((b >> 8) >= 0);
175 |
176 | *(pdst++) = r;
177 | *(pdst++) = g;
178 | *(pdst++) = b;
179 | }
180 | py += dy;
181 | if(y & 1)
182 | puv += duv;
183 | }
184 |
185 | error:
186 | CVPixelBufferUnlockBaseAddress(pixelBuffer, kCVPixelBufferLock_ReadOnly);
187 | zlog(@"convert time %gs", timer_elapsed(t_start, timer_now()));
188 |
189 | // release buffer as soon as conversion is complete
190 | self.pixelBuffer = NULL;
191 |
192 | conversion = nil;
193 | }
194 |
195 | @end
196 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarCameraSimulator.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010-2011 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 | #import
24 | #import
25 | @class ZBarReaderView;
26 |
27 | // hack around missing simulator support for AVCapture interfaces
28 |
29 | @interface ZBarCameraSimulator : NSObject
30 |
31 | {
32 | UIViewController *viewController;
33 | ZBarReaderView *readerView;
34 | UIImagePickerController *picker;
35 | UIPopoverController *pickerPopover;
36 | }
37 | - (id) initWithViewController: (UIViewController*) viewController;
38 | - (void) takePicture;
39 |
40 | @property (nonatomic, assign) ZBarReaderView *readerView;
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarCameraSimulator.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010-2011 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarCameraSimulator.h"
25 | #import "ZBarReaderView.h"
26 |
27 | // hack around missing simulator support for AVCapture interfaces
28 |
29 | @implementation ZBarCameraSimulator
30 |
31 | @synthesize readerView;
32 |
33 | - (id) initWithViewController: (UIViewController*) vc
34 | {
35 | if(!TARGET_IPHONE_SIMULATOR) {
36 | [self release];
37 | return(nil);
38 | }
39 | self = [super init];
40 | if(!self)
41 | return(nil);
42 |
43 | viewController = vc;
44 |
45 | return(self);
46 | }
47 |
48 | - (void) dealloc
49 | {
50 | viewController = nil;
51 | readerView = nil;
52 | [picker release];
53 | picker = nil;
54 | [pickerPopover release];
55 | pickerPopover = nil;
56 | [super dealloc];
57 | }
58 |
59 | - (void) setReaderView: (ZBarReaderView*) view
60 | {
61 | ZBarReaderView *oldView = readerView;
62 | readerView = [view retain];
63 | [oldView release];
64 |
65 | UILongPressGestureRecognizer *gesture =
66 | [[UILongPressGestureRecognizer alloc]
67 | initWithTarget: self
68 | action: @selector(didLongPress:)];
69 | gesture.numberOfTouchesRequired = 2;
70 | [view addGestureRecognizer: gesture];
71 | [gesture release];
72 | }
73 |
74 | - (void) didLongPress: (UILongPressGestureRecognizer*) gesture
75 | {
76 | if(gesture.state == UIGestureRecognizerStateBegan)
77 | [self takePicture];
78 | }
79 |
80 | - (void) takePicture
81 | {
82 | if(!picker) {
83 | picker = [UIImagePickerController new];
84 | picker.delegate = self;
85 | }
86 | if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
87 | if(!pickerPopover)
88 | pickerPopover = [[UIPopoverController alloc]
89 | initWithContentViewController: picker];
90 | [pickerPopover presentPopoverFromRect: CGRectZero
91 | inView: readerView
92 | permittedArrowDirections: UIPopoverArrowDirectionAny
93 | animated: YES];
94 | }
95 | else
96 | [viewController presentViewController:picker animated:YES completion:nil];
97 | }
98 |
99 | - (void) imagePickerController: (UIImagePickerController*) _picker
100 | didFinishPickingMediaWithInfo: (NSDictionary*) info
101 | {
102 | UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
103 |
104 | if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
105 | [pickerPopover dismissPopoverAnimated: YES];
106 | else
107 | [_picker dismissViewControllerAnimated:YES completion:nil];
108 |
109 | [readerView performSelector: @selector(scanImage:)
110 | withObject: image
111 | afterDelay: .1];
112 | }
113 |
114 | - (void) imagePickerControllerDidCancel: (UIImagePickerController*) _picker
115 | {
116 | [_picker dismissViewControllerAnimated:YES completion:nil];
117 | }
118 |
119 | @end
120 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarCaptureReader.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "ZBarImageScanner.h"
26 |
27 | @class AVCaptureVideoDataOutput, AVCaptureOutput;
28 | @class ZBarCaptureReader, ZBarCVImage;
29 |
30 | @protocol ZBarCaptureDelegate
31 |
32 | // called when a new barcode is detected. the image refers to the
33 | // video buffer and must not be retained for long
34 | - (void) captureReader: (ZBarCaptureReader*) captureReader
35 | didReadNewSymbolsFromImage: (ZBarImage*) image;
36 |
37 | @optional
38 | // called when a potential/uncertain barcode is detected. will also
39 | // be called *after* captureReader:didReadNewSymbolsFromImage:
40 | // when good barcodes are detected
41 | - (void) captureReader: (ZBarCaptureReader*) captureReader
42 | didTrackSymbols: (ZBarSymbolSet*) symbols;
43 |
44 | @end
45 |
46 | @interface ZBarCaptureReader
47 | : NSObject
48 | {
49 | #if !TARGET_IPHONE_SIMULATOR
50 | AVCaptureVideoDataOutput *captureOutput;
51 | id captureDelegate;
52 | ZBarImageScanner *scanner;
53 | CGRect scanCrop;
54 | CGSize size;
55 | CGFloat framesPerSecond;
56 | BOOL enableCache;
57 |
58 | dispatch_queue_t queue;
59 | ZBarImage *image;
60 | ZBarCVImage *result;
61 | volatile uint32_t state;
62 | int framecnt;
63 | unsigned width, height;
64 | uint64_t t_frame, t_fps, t_scan;
65 | CGFloat dt_frame;
66 | #endif
67 | }
68 |
69 | // supply a pre-configured image scanner
70 | - (id) initWithImageScanner: (ZBarImageScanner*) imageScanner;
71 |
72 | // this must be called before the session is started
73 | - (void) willStartRunning;
74 |
75 | // this must be called *before* the session is stopped
76 | - (void) willStopRunning;
77 |
78 | // clear the internal result cache
79 | - (void) flushCache;
80 |
81 | // capture the next frame after processing. the captured image will
82 | // follow the same delegate path as an image with decoded symbols.
83 | - (void) captureFrame;
84 |
85 | // the capture output. add this to an instance of AVCaptureSession
86 | @property (nonatomic, readonly) AVCaptureOutput *captureOutput;
87 |
88 | // delegate is notified of decode results and symbol tracking.
89 | @property (nonatomic, assign) id captureDelegate;
90 |
91 | // access to image scanner for configuration.
92 | @property (nonatomic, readonly) ZBarImageScanner *scanner;
93 |
94 | // region of image to scan in normalized coordinates.
95 | // NB horizontal crop currently ignored...
96 | @property (nonatomic, assign) CGRect scanCrop;
97 |
98 | // size of video frames.
99 | @property (nonatomic, readonly) CGSize size;
100 |
101 | // (quickly) gate the reader function without interrupting the video
102 | // stream. also flushes the cache when enabled. defaults to *NO*
103 | @property (nonatomic) BOOL enableReader;
104 |
105 | // current frame rate (for debug/optimization).
106 | // only valid when running
107 | @property (nonatomic, readonly) CGFloat framesPerSecond;
108 |
109 | @property (nonatomic) BOOL enableCache;
110 |
111 | @end
112 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarHelpController.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 |
26 | @class ZBarHelpController;
27 |
28 | @protocol ZBarHelpDelegate
29 | @optional
30 |
31 | - (void) helpControllerDidFinish: (ZBarHelpController*) help;
32 |
33 | @end
34 |
35 |
36 | // failure dialog w/a few useful tips
37 |
38 | @interface ZBarHelpController : UIViewController
39 | < UIWebViewDelegate,
40 | UIAlertViewDelegate >
41 | {
42 | NSString *reason;
43 | id delegate;
44 | UIWebView *webView;
45 | UIToolbar *toolbar;
46 | UIBarButtonItem *doneBtn, *backBtn, *space;
47 | NSURL *linkURL;
48 | NSUInteger orientations;
49 | }
50 |
51 | @property (nonatomic, assign) id delegate;
52 |
53 | // designated initializer
54 | - (id) initWithReason: (NSString*) reason;
55 |
56 | - (BOOL) isInterfaceOrientationSupported: (UIInterfaceOrientation) orientation;
57 | - (void) setInterfaceOrientation: (UIInterfaceOrientation) orientation
58 | supported: (BOOL) supported;
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarHelpController.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarHelpController.h"
25 |
26 | #define MODULE ZBarHelpController
27 | #import "debug.h"
28 | #import "iphoneDebug.h"
29 | @implementation ZBarHelpController
30 |
31 | @synthesize delegate;
32 |
33 | - (id) initWithReason: (NSString*) _reason
34 | {
35 | self = [super init];
36 | if(!self)
37 | return(nil);
38 |
39 | if(!_reason)
40 | _reason = @"INFO";
41 | reason = [_reason retain];
42 | return(self);
43 | }
44 |
45 | - (id) init
46 | {
47 | return([self initWithReason: nil]);
48 | }
49 |
50 | - (void) cleanup
51 | {
52 | [toolbar release];
53 | toolbar = nil;
54 | [webView release];
55 | webView = nil;
56 | [doneBtn release];
57 | doneBtn = nil;
58 | [backBtn release];
59 | backBtn = nil;
60 | [space release];
61 | space = nil;
62 | }
63 |
64 | - (void) dealloc
65 | {
66 | [self cleanup];
67 | [reason release];
68 | reason = nil;
69 | [linkURL release];
70 | linkURL = nil;
71 | [super dealloc];
72 | }
73 |
74 | - (void) viewDidLoad
75 | {
76 | [super viewDidLoad];
77 |
78 | UIView *view = self.view;
79 | CGRect bounds = self.view.bounds;
80 | if(!bounds.size.width || !bounds.size.height)
81 | view.frame = bounds = CGRectMake(0, 0, 320, 480);
82 | view.backgroundColor = [UIColor colorWithWhite: .125f
83 | alpha: 1];
84 | view.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
85 | UIViewAutoresizingFlexibleHeight);
86 |
87 | webView = [[UIWebView alloc]
88 | initWithFrame: CGRectMake(0, 0,
89 | bounds.size.width,
90 | bounds.size.height - 44)];
91 | webView.delegate = self;
92 | webView.backgroundColor = [UIColor colorWithWhite: .125f
93 | alpha: 1];
94 | webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
95 | UIViewAutoresizingFlexibleHeight |
96 | UIViewAutoresizingFlexibleBottomMargin);
97 | webView.hidden = YES;
98 | [view addSubview: webView];
99 |
100 | toolbar = [[UIToolbar alloc]
101 | initWithFrame: CGRectMake(0, bounds.size.height - 44,
102 | bounds.size.width, 44)];
103 | toolbar.barStyle = UIBarStyleBlackOpaque;
104 | toolbar.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
105 | UIViewAutoresizingFlexibleHeight |
106 | UIViewAutoresizingFlexibleTopMargin);
107 |
108 | doneBtn = [[UIBarButtonItem alloc]
109 | initWithBarButtonSystemItem: UIBarButtonSystemItemDone
110 | target: self
111 | action: @selector(dismiss)];
112 |
113 | backBtn = [[UIBarButtonItem alloc]
114 | initWithImage: [UIImage imageNamed: @"zbar-back.png"]
115 | style: UIBarButtonItemStylePlain
116 | target: webView
117 | action: @selector(goBack)];
118 |
119 | space = [[UIBarButtonItem alloc]
120 | initWithBarButtonSystemItem:
121 | UIBarButtonSystemItemFlexibleSpace
122 | target: nil
123 | action: nil];
124 |
125 | toolbar.items = [NSArray arrayWithObjects: space, doneBtn, nil];
126 |
127 | [view addSubview: toolbar];
128 |
129 | NSString *path = [[NSBundle mainBundle]
130 | pathForResource: @"zbar-help"
131 | ofType: @"html"];
132 |
133 | NSURLRequest *req = nil;
134 | if(path) {
135 | NSURL *url = [NSURL fileURLWithPath: path
136 | isDirectory: NO];
137 | if(url)
138 | req = [NSURLRequest requestWithURL: url];
139 | }
140 | if(req)
141 | [webView loadRequest: req];
142 | else
143 | NSLog(@"ERROR: unable to load zbar-help.html from bundle");
144 | }
145 |
146 | - (void) viewDidUnload
147 | {
148 | [self cleanup];
149 | [super viewDidUnload];
150 | }
151 |
152 | - (void) viewWillAppear: (BOOL) animated
153 | {
154 | assert(webView);
155 | if(webView.loading)
156 | webView.hidden = YES;
157 | webView.delegate = self;
158 | [super viewWillAppear: animated];
159 | }
160 |
161 | - (void) viewWillDisappear: (BOOL) animated
162 | {
163 | [webView stopLoading];
164 | webView.delegate = nil;
165 | [super viewWillDisappear: animated];
166 | }
167 |
168 | - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orient
169 | {
170 | return([self isInterfaceOrientationSupported: orient]);
171 | }
172 |
173 | - (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) orient
174 | duration: (NSTimeInterval) duration
175 | {
176 | [webView reload];
177 | }
178 |
179 | - (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) orient
180 | {
181 | // zlog(@"frame=%@ webView.frame=%@ toolbar.frame=%@",
182 | // NSStringFromCGRect(self.view.frame),
183 | // NSStringFromCGRect(webView.frame),
184 | // NSStringFromCGRect(toolbar.frame));
185 | }
186 |
187 | - (BOOL) isInterfaceOrientationSupported: (UIInterfaceOrientation) orient
188 | {
189 | UIViewController *parent = self.parentViewController;
190 | if(parent && !orientations)
191 | return([parent shouldAutorotate]);
192 | return((orientations >> orient) & 1);
193 | }
194 |
195 | - (void) setInterfaceOrientation: (UIInterfaceOrientation) orient
196 | supported: (BOOL) supported
197 | {
198 | NSUInteger mask = 1 << orient;
199 | if(supported)
200 | orientations |= mask;
201 | else
202 | orientations &= ~mask;
203 | }
204 |
205 | - (void) dismiss
206 | {
207 | if([delegate respondsToSelector: @selector(helpControllerDidFinish:)])
208 | [delegate helpControllerDidFinish: self];
209 | else
210 | [self dismissViewControllerAnimated:YES completion:nil];
211 | }
212 |
213 | - (void) webViewDidFinishLoad: (UIWebView*) view
214 | {
215 | if(view.hidden) {
216 | [view stringByEvaluatingJavaScriptFromString:
217 | [NSString stringWithFormat:
218 | @"onZBarHelp({reason:\"%@\"});", reason]];
219 | [UIView beginAnimations: @"ZBarHelp"
220 | context: nil];
221 | view.hidden = NO;
222 | [UIView commitAnimations];
223 | }
224 |
225 | BOOL canGoBack = [view canGoBack];
226 | NSArray *items = toolbar.items;
227 | if(canGoBack != ([items objectAtIndex: 0] == backBtn)) {
228 | if(canGoBack)
229 | items = [NSArray arrayWithObjects: backBtn, space, doneBtn, nil];
230 | else
231 | items = [NSArray arrayWithObjects: space, doneBtn, nil];
232 | [toolbar setItems: items
233 | animated: YES];
234 | }
235 | }
236 |
237 | - (BOOL) webView: (UIWebView*) view
238 | shouldStartLoadWithRequest: (NSURLRequest*) req
239 | navigationType: (UIWebViewNavigationType) nav
240 | {
241 | NSURL *url = [req URL];
242 | if([url isFileURL])
243 | return(YES);
244 |
245 | linkURL = [url retain];
246 | UIAlertView *alert =
247 | [[UIAlertView alloc]
248 | initWithTitle: @"Open External Link"
249 | message: @"Close this application and open link in Safari?"
250 | delegate: nil
251 | cancelButtonTitle: @"Cancel"
252 | otherButtonTitles: @"OK", nil];
253 | alert.delegate = self;
254 | [alert show];
255 | [alert release];
256 | return(NO);
257 | }
258 |
259 | - (void) alertView: (UIAlertView*) view
260 | clickedButtonAtIndex: (NSInteger) idx
261 | {
262 | if(idx)
263 | [[UIApplication sharedApplication]
264 | openURL: linkURL];
265 | }
266 |
267 | @end
268 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarImage.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "zbar.h"
26 | #import "ZBarSymbol.h"
27 |
28 | #ifdef __cplusplus
29 | using namespace zbar;
30 | #endif
31 |
32 | // Obj-C wrapper for ZBar image
33 |
34 | @interface ZBarImage : NSObject
35 | {
36 | zbar_image_t *zimg;
37 | double t_convert;
38 | }
39 |
40 | @property (nonatomic) unsigned long format;
41 | @property (nonatomic) unsigned sequence;
42 | @property (nonatomic) CGSize size;
43 | @property (nonatomic) CGRect crop;
44 | @property (readonly, nonatomic) const void *data;
45 | @property (readonly, nonatomic) unsigned long dataLength;
46 | @property (copy, nonatomic) ZBarSymbolSet *symbols;
47 | @property (readonly, nonatomic) zbar_image_t *zbarImage;
48 | @property (readonly, nonatomic) UIImage *UIImage;
49 |
50 | - (id) initWithImage: (zbar_image_t*) image;
51 | - (id) initWithCGImage: (CGImageRef) image;
52 | - (id) initWithCGImage: (CGImageRef) image
53 | size: (CGSize) size;
54 | - (id) initWithCGImage: (CGImageRef) image
55 | crop: (CGRect) crop
56 | size: (CGSize) size;
57 |
58 | - (void) setData: (const void*) data
59 | withLength: (unsigned long) length;
60 | - (UIImage*) UIImageWithOrientation: (UIImageOrientation) imageOrientation;
61 | - (void) cleanup;
62 |
63 | + (unsigned long) fourcc: (NSString*) format;
64 |
65 | #if 0
66 | - convertToFormat: (unsigned long) format;
67 | #endif
68 |
69 | @end
70 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarImage.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "ZBarImage.h"
26 | #import "debug.h"
27 | #import "iphoneDebug.h"
28 |
29 | static void image_cleanup(zbar_image_t *zimg)
30 | {
31 | ZBarImage *image = zbar_image_get_userdata(zimg);
32 | [image cleanup];
33 | }
34 |
35 | @implementation ZBarImage
36 |
37 | @dynamic format, sequence, size, crop, data, dataLength, symbols, zbarImage,
38 | UIImage;
39 |
40 | + (unsigned long) fourcc: (NSString*) format
41 | {
42 | return(zbar_fourcc_parse([format UTF8String]));
43 | }
44 |
45 | - (id) initWithImage: (zbar_image_t*) image
46 | {
47 | if(!image) {
48 | [self release];
49 | return(nil);
50 | }
51 | if(self = [super init]) {
52 | zimg = image;
53 | zbar_image_ref(image, 1);
54 | zbar_image_set_userdata(zimg, self);
55 | }
56 | return(self);
57 | }
58 |
59 | - (id) init
60 | {
61 | zbar_image_t *image = zbar_image_create();
62 | self = [self initWithImage: image];
63 | zbar_image_ref(image, -1);
64 | return(self);
65 | }
66 |
67 | - (void) dealloc
68 | {
69 | if(zimg) {
70 | zbar_image_ref(zimg, -1);
71 | zimg = NULL;
72 | }
73 | [super dealloc];
74 | }
75 |
76 | - (id) initWithCGImage: (CGImageRef) image
77 | crop: (CGRect) crop
78 | size: (CGSize) size
79 | {
80 | if(!(self = [self init]))
81 | return(nil);
82 | uint64_t t_start = timer_now();
83 |
84 | unsigned int w = size.width + 0.5;
85 | unsigned int h = size.height + 0.5;
86 |
87 | unsigned long datalen = w * h;
88 | uint8_t *raw = malloc(datalen);
89 | if(!raw) {
90 | [self release];
91 | return(nil);
92 | }
93 |
94 | zbar_image_set_data(zimg, raw, datalen, zbar_image_free_data);
95 | zbar_image_set_format(zimg, zbar_fourcc('Y','8','0','0'));
96 | zbar_image_set_size(zimg, w, h);
97 |
98 | // scale and crop simultaneously
99 | CGFloat scale = size.width / crop.size.width;
100 | crop.origin.x *= -scale;
101 | crop.size.width = scale * (CGFloat)CGImageGetWidth(image);
102 | scale = size.height / crop.size.height;
103 | CGFloat height = CGImageGetHeight(image);
104 | // compensate for wacky origin
105 | crop.origin.y = height - crop.origin.y - crop.size.height;
106 | crop.origin.y *= -scale;
107 | crop.size.height = scale * height;
108 |
109 | // generate grayscale image data
110 | CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
111 | CGContextRef ctx =
112 | CGBitmapContextCreate(raw, w, h, 8, w, cs, kCGImageAlphaNone);
113 | CGColorSpaceRelease(cs);
114 | CGContextSetAllowsAntialiasing(ctx, 0);
115 |
116 | CGContextDrawImage(ctx, crop, image);
117 |
118 | #if 0
119 | zlog(@"convert image %dx%d: crop %g,%g %gx%g size %gx%g (%dx%d)",
120 | CGImageGetWidth(image), CGImageGetHeight(image),
121 | crop.origin.x, crop.origin.y, crop.size.width, crop.size.height,
122 | size.width, size.height, w, h);
123 | CGImageRef cgdump = CGBitmapContextCreateImage(ctx);
124 | UIImage *uidump = [[UIImage alloc]
125 | initWithCGImage: cgdump];
126 | CGImageRelease(cgdump);
127 | UIImageWriteToSavedPhotosAlbum(uidump, nil, nil, NULL);
128 | [uidump release];
129 | #endif
130 |
131 | CGContextRelease(ctx);
132 |
133 | t_convert = timer_elapsed(t_start, timer_now());
134 | return(self);
135 | }
136 |
137 | - (id) initWithCGImage: (CGImageRef) image
138 | size: (CGSize) size
139 | {
140 | CGRect crop = CGRectMake(0, 0,
141 | CGImageGetWidth(image),
142 | CGImageGetHeight(image));
143 | return([self initWithCGImage: image
144 | crop: crop
145 | size: size]);
146 | }
147 |
148 | - (id) initWithCGImage: (CGImageRef) image
149 | {
150 | CGRect crop = CGRectMake(0, 0,
151 | CGImageGetWidth(image),
152 | CGImageGetHeight(image));
153 | return([self initWithCGImage: image
154 | crop: crop
155 | size: crop.size]);
156 | }
157 |
158 | - (zbar_image_t*) image
159 | {
160 | return(zimg);
161 | }
162 |
163 | - (unsigned long) format
164 | {
165 | return(zbar_image_get_format(zimg));
166 | }
167 |
168 | - (void) setFormat: (unsigned long) format
169 | {
170 | zbar_image_set_format(zimg, format);
171 | }
172 |
173 | - (unsigned) sequence
174 | {
175 | return(zbar_image_get_sequence(zimg));
176 | }
177 |
178 | - (void) setSequence: (unsigned) seq
179 | {
180 | zbar_image_set_sequence(zimg, seq);
181 | }
182 |
183 | - (CGSize) size
184 | {
185 | unsigned w, h;
186 | zbar_image_get_size(zimg, &w, &h);
187 | return(CGSizeMake(w, h));
188 | }
189 |
190 | - (void) setSize: (CGSize) size
191 | {
192 | zbar_image_set_size(zimg, size.width + .5, size.height + .5);
193 | }
194 |
195 | - (CGRect) crop
196 | {
197 | unsigned x, y, w, h;
198 | zbar_image_get_crop(zimg, &x, &y, &w, &h);
199 | return(CGRectMake(x, y, w, h));
200 | }
201 |
202 | - (void) setCrop: (CGRect) crop
203 | {
204 | zbar_image_set_crop(zimg, crop.origin.x + .5, crop.origin.y + .5,
205 | crop.size.width + .5, crop.size.height + .5);
206 | }
207 |
208 | - (ZBarSymbolSet*) symbols
209 | {
210 | return([[[ZBarSymbolSet alloc]
211 | initWithSymbolSet: zbar_image_get_symbols(zimg)]
212 | autorelease]);
213 | }
214 |
215 | - (void) setSymbols: (ZBarSymbolSet*) symbols
216 | {
217 | zbar_image_set_symbols(zimg, [symbols zbarSymbolSet]);
218 | }
219 |
220 | - (const void*) data
221 | {
222 | return(zbar_image_get_data(zimg));
223 | }
224 |
225 | - (unsigned long) dataLength
226 | {
227 | return(zbar_image_get_data_length(zimg));
228 | }
229 |
230 | - (void) setData: (const void*) data
231 | withLength: (unsigned long) length
232 | {
233 | zbar_image_set_data(zimg, data, length, image_cleanup);
234 | }
235 |
236 | - (zbar_image_t*) zbarImage
237 | {
238 | return(zimg);
239 | }
240 |
241 | - (UIImage*) UIImageWithOrientation: (UIImageOrientation) orient
242 | {
243 | unsigned long format = self.format;
244 | size_t bpc, bpp;
245 | switch(format)
246 | {
247 | case zbar_fourcc('R','G','B','3'):
248 | bpc = 8;
249 | bpp = 24;
250 | break;
251 | case zbar_fourcc('R','G','B','4'):
252 | bpc = 8;
253 | bpp = 32;
254 | break;
255 | case zbar_fourcc('R','G','B','Q'):
256 | bpc = 5;
257 | bpp = 16;
258 | break;
259 | default:
260 | NSLog(@"ERROR: format %.4s(%08lx) is unsupported",
261 | (char*)&format, format);
262 | assert(0);
263 | return(nil);
264 | };
265 |
266 | unsigned w = zbar_image_get_width(zimg);
267 | unsigned h = zbar_image_get_height(zimg);
268 | const void *data = zbar_image_get_data(zimg);
269 | size_t datalen = zbar_image_get_data_length(zimg);
270 | CGDataProviderRef datasrc =
271 | CGDataProviderCreateWithData(self, data, datalen, (void*)CFRelease);
272 | CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
273 | CGImageRef cgimg =
274 | CGImageCreate(w, h, bpc, bpp, ((bpp + 7) >> 3) * w, cs,
275 | kCGBitmapByteOrderDefault |
276 | kCGImageAlphaNoneSkipFirst,
277 | datasrc, NULL, YES, kCGRenderingIntentDefault);
278 | CGColorSpaceRelease(cs);
279 | CGDataProviderRelease(datasrc);
280 |
281 | UIImage *uiimg =
282 | [UIImage imageWithCGImage: cgimg
283 | scale: 1
284 | orientation: orient];
285 | CGImageRelease(cgimg);
286 | return(uiimg);
287 | }
288 |
289 | - (UIImage*) UIImage
290 | {
291 | return([self UIImageWithOrientation: UIImageOrientationUp]);
292 | }
293 |
294 | - (void) cleanup
295 | {
296 | }
297 |
298 | #if 0
299 | - (ZBarImage*) convertToFormat: (unsigned long) format
300 | {
301 | zbar_image_t *zdst = zbar_image_convert(zimg, format);
302 | ZBarImage *image = ;
303 | return([[[ZBarImage alloc] initWithImage: zdst] autorelease]);
304 | }
305 | #endif
306 |
307 | @end
308 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarImageScanner.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "zbar.h"
26 | #import "ZBarImage.h"
27 |
28 | #ifdef __cplusplus
29 | using namespace zbar;
30 | #endif
31 |
32 | // Obj-C wrapper for ZBar image scanner
33 |
34 | @interface ZBarImageScanner : NSObject
35 | {
36 | zbar_image_scanner_t *scanner;
37 | }
38 |
39 | @property (nonatomic) BOOL enableCache;
40 | @property (readonly, nonatomic) ZBarSymbolSet *results;
41 |
42 | // decoder configuration
43 | - (void) parseConfig: (NSString*) configStr;
44 | - (void) setSymbology: (zbar_symbol_type_t) symbology
45 | config: (zbar_config_t) config
46 | to: (int) value;
47 |
48 | // image scanning interface
49 | - (NSInteger) scanImage: (ZBarImage*) image;
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarImageScanner.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarImageScanner.h"
25 | #import "debug.h"
26 | #import "iphoneDebug.h"
27 | @implementation ZBarImageScanner
28 |
29 | @dynamic enableCache, results;
30 |
31 | - (id) init
32 | {
33 | if(self = [super init]) {
34 | scanner = zbar_image_scanner_create();
35 | }
36 | return(self);
37 | }
38 |
39 | - (void) dealloc
40 | {
41 | if(scanner) {
42 | zbar_image_scanner_destroy(scanner);
43 | scanner = NULL;
44 | }
45 | [super dealloc];
46 | }
47 |
48 | - (BOOL) enableCache
49 | {
50 | assert(0); // FIXME
51 | return(NO);
52 | }
53 |
54 | - (void) setEnableCache: (BOOL) enable
55 | {
56 | zbar_image_scanner_enable_cache(scanner, enable);
57 | }
58 |
59 | - (ZBarSymbolSet*) results
60 | {
61 | const zbar_symbol_set_t *set = zbar_image_scanner_get_results(scanner);
62 | return([[[ZBarSymbolSet alloc] initWithSymbolSet: set] autorelease]);
63 | }
64 |
65 | // image scanner config wrappers
66 | - (void) parseConfig: (NSString*) cfg
67 | {
68 | zbar_image_scanner_parse_config(scanner, [cfg UTF8String]);
69 | // FIXME throw errors
70 | }
71 |
72 | - (void) setSymbology: (zbar_symbol_type_t) sym
73 | config: (zbar_config_t) cfg
74 | to: (int) val
75 | {
76 | zbar_image_scanner_set_config(scanner, sym, cfg, val);
77 | // FIXME throw errors
78 | }
79 |
80 | - (NSInteger) scanImage: (ZBarImage*) image
81 | {
82 | return(zbar_scan_image(scanner, image.zbarImage));
83 | }
84 |
85 | @end
86 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarReaderController.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "ZBarImageScanner.h"
26 |
27 | #ifdef __cplusplus
28 | using namespace zbar;
29 | #endif
30 |
31 | typedef enum {
32 | // default interface provided by UIImagePickerController - user manually
33 | // captures an image by pressing a button
34 | ZBarReaderControllerCameraModeDefault = 0,
35 |
36 | // automatically scan by taking screenshots with UIGetScreenImage().
37 | // resolution is limited by the screen, so this is inappropriate for
38 | // longer codes
39 | ZBarReaderControllerCameraModeSampling,
40 |
41 | // automatically scan by rapidly taking pictures with takePicture.
42 | // tradeoff resolution with frame rate by adjusting the crop, and size
43 | // properties of the reader along with the density configs of the image
44 | // scanner
45 | ZBarReaderControllerCameraModeSequence,
46 |
47 | } ZBarReaderControllerCameraMode;
48 |
49 |
50 | @class ZBarReaderController, ZBarHelpController;
51 |
52 | @protocol ZBarReaderDelegate
53 | @optional
54 |
55 | // called when no barcode is found in an image selected by the user.
56 | // if retry is NO, the delegate *must* dismiss the controller
57 | - (void) readerControllerDidFailToRead: (ZBarReaderController*) reader
58 | withRetry: (BOOL) retry;
59 |
60 | @end
61 |
62 |
63 | @interface ZBarReaderController
64 | : UIImagePickerController
65 | < UINavigationControllerDelegate,
66 | UIImagePickerControllerDelegate >
67 | {
68 | ZBarImageScanner *scanner;
69 | ZBarHelpController *help;
70 | UIView *overlay, *boxView;
71 | CALayer *boxLayer;
72 |
73 | UIToolbar *toolbar;
74 | UIBarButtonItem *cancelBtn, *scanBtn, *space[3];
75 | UIButton *infoBtn;
76 |
77 | id readerDelegate;
78 | BOOL showsZBarControls, showsHelpOnFail, takesPicture, enableCache;
79 | ZBarReaderControllerCameraMode cameraMode;
80 | CGRect scanCrop;
81 | NSInteger maxScanDimension;
82 |
83 | BOOL hasOverlay, sampling;
84 | uint64_t t_frame;
85 | double dt_frame;
86 |
87 | ZBarSymbol *symbol;
88 | }
89 |
90 | // access to configure image scanner
91 | @property (readonly, nonatomic) ZBarImageScanner *scanner;
92 |
93 | // barcode result recipient (NB don't use delegate)
94 | @property (nonatomic, assign) id readerDelegate;
95 |
96 | // whether to use alternate control set
97 | @property (nonatomic) BOOL showsZBarControls;
98 |
99 | // whether to display helpful information when decoding fails
100 | @property (nonatomic) BOOL showsHelpOnFail;
101 |
102 | // how to use the camera (when sourceType == Camera)
103 | @property (nonatomic) ZBarReaderControllerCameraMode cameraMode;
104 |
105 | // whether to outline symbols with the green tracking box.
106 | @property (nonatomic) BOOL tracksSymbols;
107 |
108 | // whether to automatically take a full picture when a barcode is detected
109 | // (when cameraMode == Sampling)
110 | @property (nonatomic) BOOL takesPicture;
111 |
112 | // whether to use the "cache" for realtime modes (default YES). this can be
113 | // used to safely disable the inter-frame consistency and duplicate checks,
114 | // speeding up recognition, iff:
115 | // 1. the controller is dismissed when a barcode is read and
116 | // 2. unreliable symbologies are disabled (all EAN/UPC variants and I2/5)
117 | @property (nonatomic) BOOL enableCache;
118 |
119 | // crop images for scanning. the original image will be cropped to this
120 | // rectangle before scanning. the rectangle is normalized to the image size
121 | // and aspect ratio; useful values will place the rectangle between 0 and 1
122 | // on each axis, where the x-axis corresponds to the image major axis.
123 | // defaults to the full image (0, 0, 1, 1).
124 | @property (nonatomic) CGRect scanCrop;
125 |
126 | // scale image to scan. after cropping, the image will be scaled if
127 | // necessary, such that neither of its dimensions exceed this value.
128 | // defaults to 640.
129 | @property (nonatomic) NSInteger maxScanDimension;
130 |
131 | // display the built-in help browser. for use with custom overlays if
132 | // you don't also want to create your own help view. only send this
133 | // message when the reader is displayed. the argument will be passed
134 | // to the onZBarHelp() javascript function.
135 | - (void) showHelpWithReason: (NSString*) reason;
136 |
137 | // direct scanner interface - scan UIImage and return something enumerable
138 | - (id ) scanImage: (CGImageRef) image;
139 |
140 | @end
141 |
142 | extern NSString* const ZBarReaderControllerResults;
143 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarReaderView.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "ZBarImageScanner.h"
26 |
27 | @class AVCaptureSession, AVCaptureDevice;
28 | @class CALayer;
29 | @class ZBarImageScanner, ZBarCaptureReader, ZBarReaderView;
30 |
31 | // delegate is notified of decode results.
32 |
33 | @protocol ZBarReaderViewDelegate < NSObject >
34 |
35 | - (void) readerView: (ZBarReaderView*) readerView
36 | didReadSymbols: (ZBarSymbolSet*) symbols
37 | fromImage: (UIImage*) image;
38 |
39 | @optional
40 | - (void) readerViewDidStart: (ZBarReaderView*) readerView;
41 | - (void) readerView: (ZBarReaderView*) readerView
42 | didStopWithError: (NSError*) error;
43 |
44 | @end
45 |
46 | // read barcodes from the displayed video preview. the view maintains
47 | // a complete video capture session feeding a ZBarCaptureReader and
48 | // presents the associated preview with symbol tracking annotations.
49 |
50 | @interface ZBarReaderView
51 | : UIView
52 | {
53 | id readerDelegate;
54 | ZBarCaptureReader *captureReader;
55 | CGRect scanCrop, effectiveCrop;
56 | CGAffineTransform previewTransform;
57 | CGFloat zoom, zoom0, maxZoom;
58 | UIColor *trackingColor;
59 | BOOL tracksSymbols, showsFPS;
60 | NSInteger torchMode;
61 | UIInterfaceOrientation interfaceOrientation;
62 | NSTimeInterval animationDuration;
63 |
64 | CALayer *preview, *overlay, *tracking, *cropLayer;
65 | UIView *fpsView;
66 | UILabel *fpsLabel;
67 | UIPinchGestureRecognizer *pinch;
68 | CGFloat imageScale;
69 | CGSize imageSize;
70 | BOOL started, running, locked;
71 | }
72 |
73 | // supply a pre-configured image scanner.
74 | - (id) initWithImageScanner: (ZBarImageScanner*) imageScanner;
75 |
76 | // start the video stream and barcode reader.
77 | - (void) start;
78 |
79 | // stop the video stream and barcode reader.
80 | - (void) stop;
81 |
82 | // clear the internal result cache
83 | - (void) flushCache;
84 |
85 | // compensate for device/camera/interface orientation
86 | - (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) orient
87 | duration: (NSTimeInterval) duration;
88 |
89 | // delegate is notified of decode results.
90 | @property (nonatomic, assign) id readerDelegate;
91 |
92 | // access to image scanner for configuration.
93 | @property (nonatomic, readonly) ZBarImageScanner *scanner;
94 |
95 | // whether to display the tracking annotation for uncertain barcodes
96 | // (default YES).
97 | @property (nonatomic) BOOL tracksSymbols;
98 |
99 | // color of the tracking box (default green)
100 | @property (nonatomic, retain) UIColor *trackingColor;
101 |
102 | // enable pinch gesture recognition for zooming the preview/decode
103 | // (default YES).
104 | @property (nonatomic) BOOL allowsPinchZoom;
105 |
106 | // torch mode to set automatically (default Auto).
107 | @property (nonatomic) NSInteger torchMode;
108 |
109 | // whether to display the frame rate for debug/configuration
110 | // (default NO).
111 | @property (nonatomic) BOOL showsFPS;
112 |
113 | // zoom scale factor applied to video preview *and* scanCrop.
114 | // also updated by pinch-zoom gesture. clipped to range [1,maxZoom],
115 | // defaults to 1.25
116 | @property (nonatomic) CGFloat zoom;
117 | - (void) setZoom: (CGFloat) zoom
118 | animated: (BOOL) animated;
119 |
120 | // maximum settable zoom factor.
121 | @property (nonatomic) CGFloat maxZoom;
122 |
123 | // the region of the image that will be scanned. normalized coordinates.
124 | @property (nonatomic) CGRect scanCrop;
125 |
126 | // additional transform applied to video preview.
127 | // (NB *not* applied to scan crop)
128 | @property (nonatomic) CGAffineTransform previewTransform;
129 |
130 | // specify an alternate capture device.
131 | @property (nonatomic, retain) AVCaptureDevice *device;
132 |
133 | // direct access to the capture session. warranty void if opened...
134 | @property (nonatomic, readonly) AVCaptureSession *session;
135 | @property (nonatomic, readonly) ZBarCaptureReader *captureReader;
136 |
137 | // this flag still works, but its use is deprecated
138 | @property (nonatomic) BOOL enableCache;
139 |
140 | @end
141 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarReaderViewController.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import "ZBarReaderController.h"
26 |
27 | // orientation set support
28 | #define ZBarOrientationMask(orient) (1 << orient)
29 | #define ZBarOrientationMaskAll \
30 | (ZBarOrientationMask(UIInterfaceOrientationPortrait) | \
31 | ZBarOrientationMask(UIInterfaceOrientationPortraitUpsideDown) | \
32 | ZBarOrientationMask(UIInterfaceOrientationLandscapeLeft) | \
33 | ZBarOrientationMask(UIInterfaceOrientationLandscapeRight))
34 |
35 | @class ZBarReaderView, ZBarCameraSimulator;
36 |
37 | // drop in video scanning replacement for ZBarReaderController.
38 | // this is a thin controller around a ZBarReaderView that adds the UI
39 | // controls and select functionality offered by ZBarReaderController.
40 | // Automatically falls back to a ZBarReaderController if video APIs
41 | // are unavailable (eg for OS < 4.0)
42 |
43 | @interface ZBarReaderViewController
44 | : UIViewController
45 | {
46 | ZBarImageScanner *scanner;
47 | id readerDelegate;
48 | ZBarReaderView *readerView;
49 | UIView *cameraOverlayView;
50 | CGAffineTransform cameraViewTransform;
51 | CGRect scanCrop;
52 | NSUInteger supportedOrientationsMask;
53 | UIImagePickerControllerCameraDevice cameraDevice;
54 | UIImagePickerControllerCameraFlashMode cameraFlashMode;
55 | UIImagePickerControllerQualityType videoQuality;
56 | BOOL showsZBarControls, tracksSymbols, enableCache;
57 |
58 | ZBarHelpController *helpController;
59 | UIView *controls, *shutter;
60 | BOOL didHideStatusBar, rotating;
61 | ZBarCameraSimulator *cameraSim;
62 | }
63 |
64 | // access to configure image scanner
65 | @property (nonatomic, readonly) ZBarImageScanner *scanner;
66 |
67 | // barcode result recipient
68 | @property (nonatomic, assign) id readerDelegate;
69 |
70 | // whether to use alternate control set
71 | @property (nonatomic) BOOL showsZBarControls;
72 |
73 | // whether to show the green tracking box. note that, even when
74 | // enabled, the box will only be visible when scanning EAN and I2/5.
75 | @property (nonatomic) BOOL tracksSymbols;
76 |
77 | // interface orientation support. bit-mask of accepted orientations.
78 | // see eg ZBarOrientationMask() and ZBarOrientationMaskAll
79 | @property (nonatomic) NSUInteger supportedOrientationsMask;
80 |
81 | // crop images for scanning. the image will be cropped to this
82 | // rectangle before scanning. the rectangle is normalized to the
83 | // image size and aspect ratio; useful values will place the rectangle
84 | // between 0 and 1 on each axis, where the x-axis corresponds to the
85 | // image major axis. defaults to the full image (0, 0, 1, 1).
86 | @property (nonatomic) CGRect scanCrop;
87 |
88 | // provide a custom overlay. note that this can be used with
89 | // showsZBarControls enabled (but not if you want backward compatibility)
90 | @property (nonatomic, retain) UIView *cameraOverlayView;
91 |
92 | // transform applied to the preview image.
93 | @property (nonatomic) CGAffineTransform cameraViewTransform;
94 |
95 | // display the built-in help browser. the argument will be passed to
96 | // the onZBarHelp() javascript function.
97 | - (void) showHelpWithReason: (NSString*) reason;
98 |
99 | // capture the next frame and send it over the usual delegate path.
100 | - (void) takePicture;
101 |
102 | - (void) initControls;
103 | // these attempt to emulate UIImagePickerController
104 | + (BOOL) isCameraDeviceAvailable: (UIImagePickerControllerCameraDevice) cameraDevice;
105 | + (BOOL) isFlashAvailableForCameraDevice: (UIImagePickerControllerCameraDevice) cameraDevice;
106 | + (NSArray*) availableCaptureModesForCameraDevice: (UIImagePickerControllerCameraDevice) cameraDevice;
107 | @property(nonatomic) UIImagePickerControllerCameraDevice cameraDevice;
108 | @property(nonatomic) UIImagePickerControllerCameraFlashMode cameraFlashMode;
109 | @property(nonatomic) UIImagePickerControllerCameraCaptureMode cameraCaptureMode;
110 | @property(nonatomic) UIImagePickerControllerQualityType videoQuality;
111 |
112 | // direct access to the ZBarReaderView
113 | @property (nonatomic, readonly) ZBarReaderView *readerView;
114 |
115 | // this flag still works, but its use is deprecated
116 | @property (nonatomic) BOOL enableCache;
117 |
118 | // these are present only for backward compatibility.
119 | // they will error if inappropriate/unsupported values are set
120 | @property (nonatomic) UIImagePickerControllerSourceType sourceType; // Camera
121 | @property (nonatomic) BOOL allowsEditing; // NO
122 | @property (nonatomic) BOOL allowsImageEditing; // NO
123 | @property (nonatomic) BOOL showsCameraControls; // NO
124 | @property (nonatomic) BOOL showsHelpOnFail; // ignored
125 | @property (nonatomic) ZBarReaderControllerCameraMode cameraMode; // Sampling
126 | @property (nonatomic) BOOL takesPicture; // NO
127 | @property (nonatomic) NSInteger maxScanDimension; // ignored
128 |
129 | + (BOOL) isSourceTypeAvailable: (UIImagePickerControllerSourceType) sourceType;
130 |
131 | @end
132 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarSDK.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #import "zbar.h"
25 |
26 | #import "ZBarSymbol.h"
27 | #import "ZBarImage.h"
28 | #import "ZBarImageScanner.h"
29 | #import "ZBarReaderView.h"
30 | #import "ZBarReaderViewController.h"
31 | #import "ZBarReaderController.h"
32 | #import "ZBarCaptureReader.h"
33 | #import "ZBarHelpController.h"
34 | #import "ZBarCameraSimulator.h"
35 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarSymbol.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import
25 | #import
26 | #import "zbar.h"
27 |
28 | #ifdef __cplusplus
29 | using namespace zbar;
30 | #endif
31 |
32 | // Obj-C wrapper for ZBar result types
33 |
34 | @interface ZBarSymbolSet
35 | : NSObject
36 | {
37 | const zbar_symbol_set_t *set;
38 | BOOL filterSymbols;
39 | }
40 |
41 | @property (readonly, nonatomic) int count;
42 | @property (readonly, nonatomic) const zbar_symbol_set_t *zbarSymbolSet;
43 | @property (nonatomic) BOOL filterSymbols;
44 |
45 | - (id) initWithSymbolSet: (const zbar_symbol_set_t*) set;
46 |
47 | @end
48 |
49 |
50 | @interface ZBarSymbol : NSObject
51 | {
52 | const zbar_symbol_t *symbol;
53 | }
54 |
55 | @property (readonly, nonatomic) zbar_symbol_type_t type;
56 | @property (readonly, nonatomic) NSString *typeName;
57 | @property (readonly, nonatomic) NSUInteger configMask;
58 | @property (readonly, nonatomic) NSUInteger modifierMask;
59 | @property (readonly, nonatomic) NSString *data;
60 | @property (readonly, nonatomic) int quality;
61 | @property (readonly, nonatomic) int count;
62 | @property (readonly, nonatomic) zbar_orientation_t orientation;
63 | @property (readonly, nonatomic) ZBarSymbolSet *components;
64 | @property (readonly, nonatomic) const zbar_symbol_t *zbarSymbol;
65 | @property (readonly, nonatomic) CGRect bounds;
66 |
67 | - (id) initWithSymbol: (const zbar_symbol_t*) symbol;
68 |
69 | + (NSString*) nameForType: (zbar_symbol_type_t) type;
70 |
71 | @end
72 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/ZBarSymbol.m:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009-2010 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #import "ZBarSymbol.h"
25 |
26 | @implementation ZBarSymbol
27 |
28 | @dynamic type, typeName, configMask, modifierMask, data, quality, count,
29 | zbarSymbol;
30 |
31 | + (NSString*) nameForType: (zbar_symbol_type_t) type
32 | {
33 | return([NSString stringWithUTF8String: zbar_get_symbol_name(type)]);
34 | }
35 |
36 | - (id) initWithSymbol: (const zbar_symbol_t*) sym
37 | {
38 | if(self = [super init]) {
39 | symbol = sym;
40 | zbar_symbol_ref(sym, 1);
41 | }
42 | return(self);
43 | }
44 |
45 | - (void) dealloc
46 | {
47 | if(symbol) {
48 | zbar_symbol_ref(symbol, -1);
49 | symbol = NULL;
50 | }
51 | [super dealloc];
52 | }
53 |
54 | - (zbar_symbol_type_t) type
55 | {
56 | return(zbar_symbol_get_type(symbol));
57 | }
58 |
59 | - (NSString*) typeName
60 | {
61 | return([[self class] nameForType: zbar_symbol_get_type(symbol)]);
62 | }
63 |
64 | - (NSUInteger) configMask
65 | {
66 | return(zbar_symbol_get_configs(symbol));
67 | }
68 |
69 | - (NSUInteger) modifierMask
70 | {
71 | return(zbar_symbol_get_modifiers(symbol));
72 | }
73 |
74 | - (NSString*) data
75 | {
76 | return([NSString stringWithUTF8String: zbar_symbol_get_data(symbol)]);
77 | }
78 |
79 | - (int) quality
80 | {
81 | return(zbar_symbol_get_quality(symbol));
82 | }
83 |
84 | - (int) count
85 | {
86 | return(zbar_symbol_get_count(symbol));
87 | }
88 |
89 | - (zbar_orientation_t) orientation
90 | {
91 | return(zbar_symbol_get_orientation(symbol));
92 | }
93 |
94 | - (const zbar_symbol_t*) zbarSymbol
95 | {
96 | return(symbol);
97 | }
98 |
99 | - (ZBarSymbolSet*) components
100 | {
101 | return([[[ZBarSymbolSet alloc]
102 | initWithSymbolSet: zbar_symbol_get_components(symbol)]
103 | autorelease]);
104 | }
105 |
106 | - (CGRect) bounds
107 | {
108 | int n = zbar_symbol_get_loc_size(symbol);
109 | if(!n)
110 | return(CGRectNull);
111 |
112 | int xmin = INT_MAX, xmax = INT_MIN;
113 | int ymin = INT_MAX, ymax = INT_MIN;
114 |
115 | for(int i = 0; i < n; i++) {
116 | int t = zbar_symbol_get_loc_x(symbol, i);
117 | if(xmin > t) xmin = t;
118 | if(xmax < t) xmax = t;
119 | t = zbar_symbol_get_loc_y(symbol, i);
120 | if(ymin > t) ymin = t;
121 | if(ymax < t) ymax = t;
122 | }
123 | return(CGRectMake(xmin, ymin, xmax - xmin, ymax - ymin));
124 | }
125 |
126 | @end
127 |
128 |
129 | @implementation ZBarSymbolSet
130 |
131 | @dynamic count, zbarSymbolSet;
132 | @synthesize filterSymbols;
133 |
134 | - (id) initWithSymbolSet: (const zbar_symbol_set_t*) s
135 | {
136 | if(!s) {
137 | [self release];
138 | return(nil);
139 | }
140 | if(self = [super init]) {
141 | set = s;
142 | zbar_symbol_set_ref(s, 1);
143 | filterSymbols = YES;
144 | }
145 | return(self);
146 | }
147 |
148 | - (void) dealloc
149 | {
150 | if(set) {
151 | zbar_symbol_set_ref(set, -1);
152 | set = NULL;
153 | }
154 | [super dealloc];
155 | }
156 |
157 | - (int) count
158 | {
159 | if(filterSymbols)
160 | return(zbar_symbol_set_get_size(set));
161 |
162 | int n = 0;
163 | const zbar_symbol_t *sym = zbar_symbol_set_first_unfiltered(set);
164 | for(; sym; sym = zbar_symbol_next(sym))
165 | n++;
166 | return(n);
167 | }
168 |
169 | - (const zbar_symbol_set_t*) zbarSymbolSet
170 | {
171 | return(set);
172 | }
173 |
174 | - (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState*) state
175 | objects: (id*) stackbuf
176 | count: (NSUInteger) len
177 | {
178 | const zbar_symbol_t *sym = (void*)state->state; // FIXME
179 | if(sym)
180 | sym = zbar_symbol_next(sym);
181 | else if(set && filterSymbols)
182 | sym = zbar_symbol_set_first_symbol(set);
183 | else if(set)
184 | sym = zbar_symbol_set_first_unfiltered(set);
185 |
186 | if(sym)
187 | *stackbuf = [[[ZBarSymbol alloc]
188 | initWithSymbol: sym]
189 | autorelease];
190 |
191 | state->state = (unsigned long)sym; // FIXME
192 | state->itemsPtr = stackbuf;
193 | state->mutationsPtr = (void*)self;
194 | return((sym) ? 1 : 0);
195 | }
196 |
197 | @end
198 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/config.h:
--------------------------------------------------------------------------------
1 | /* manually customized for iPhone platform */
2 |
3 | /* whether to build support for Code 128 symbology */
4 | #define ENABLE_CODE128 1
5 |
6 | /* whether to build support for Code 93 symbology */
7 | #define ENABLE_CODE93 1
8 |
9 | /* whether to build support for Code 39 symbology */
10 | #define ENABLE_CODE39 1
11 |
12 | /* whether to build support for Codabar symbology */
13 | #define ENABLE_CODABAR 1
14 |
15 | /* whether to build support for DataBar symbology */
16 | #define ENABLE_DATABAR 1
17 |
18 | /* whether to build support for EAN symbologies */
19 | #define ENABLE_EAN 1
20 |
21 | /* whether to build support for Interleaved 2 of 5 symbology */
22 | #define ENABLE_I25 1
23 |
24 | /* whether to build support for PDF417 symbology */
25 | #undef ENABLE_PDF417
26 |
27 | /* whether to build support for QR Code */
28 | #define ENABLE_QRCODE 1
29 |
30 | /* Define to 1 if you have the `atexit' function. */
31 | #undef HAVE_ATEXIT
32 |
33 | /* Define to 1 if you have the header file. */
34 | #undef HAVE_DLFCN_H
35 |
36 | /* Define to 1 if you have the header file. */
37 | #undef HAVE_FCNTL_H
38 |
39 | /* Define to 1 if you have the header file. */
40 | #undef HAVE_FEATURES_H
41 |
42 | /* Define to 1 if you have the `getpagesize' function. */
43 | #undef HAVE_GETPAGESIZE
44 |
45 | /* Define if you have the iconv() function and it works. */
46 | #undef HAVE_ICONV
47 |
48 | /* Define to 1 if you have the header file. */
49 | #define HAVE_INTTYPES_H 1
50 |
51 | /* Define to 1 if you have the header file. */
52 | #undef HAVE_JPEGLIB_H
53 |
54 | /* Define to 1 if you have the `jpeg' library (-ljpeg). */
55 | #undef HAVE_LIBJPEG
56 |
57 | /* Define to 1 if you have the `pthread' library (-lpthread). */
58 | #undef HAVE_LIBPTHREAD
59 |
60 | /* Define to 1 if you have the header file. */
61 | #undef HAVE_LINUX_VIDEODEV2_H
62 |
63 | /* Define to 1 if you have the header file. */
64 | #undef HAVE_LINUX_VIDEODEV_H
65 |
66 | /* Define to 1 if you have the header file. */
67 | #undef HAVE_MEMORY_H
68 |
69 | /* Define to 1 if you have the `memset' function. */
70 | #define HAVE_MEMSET 1
71 |
72 | /* Define to 1 if you have a working `mmap' system call. */
73 | #undef HAVE_MMAP
74 |
75 | /* Define to 1 if you have the header file. */
76 | #undef HAVE_POLL_H
77 |
78 | /* Define to 1 if you have the header file. */
79 | #undef HAVE_PTHREAD_H
80 |
81 | /* Define to 1 if you have the `setenv' function. */
82 | #undef HAVE_SETENV
83 |
84 | /* Define to 1 if you have the header file. */
85 | #define HAVE_STDINT_H 1
86 |
87 | /* Define to 1 if you have the header file. */
88 | #define HAVE_STDLIB_H 1
89 |
90 | /* Define to 1 if you have the header file. */
91 | #define HAVE_STRINGS_H 1
92 |
93 | /* Define to 1 if you have the header file. */
94 | #define HAVE_STRING_H 1
95 |
96 | /* Define to 1 if you have the header file. */
97 | #undef HAVE_SYS_IOCTL_H
98 |
99 | /* Define to 1 if you have the header file. */
100 | #undef HAVE_SYS_IPC_H
101 |
102 | /* Define to 1 if you have the header file. */
103 | #undef HAVE_SYS_MMAN_H
104 |
105 | /* Define to 1 if you have the header file. */
106 | #undef HAVE_SYS_SHM_H
107 |
108 | /* Define to 1 if you have the header file. */
109 | #define HAVE_SYS_STAT_H 1
110 |
111 | /* Define to 1 if you have the header file. */
112 | #define HAVE_SYS_TIMES_H 1
113 |
114 | /* Define to 1 if you have the header file. */
115 | #define HAVE_SYS_TIME_H 1
116 |
117 | /* Define to 1 if you have the header file. */
118 | #define HAVE_SYS_TYPES_H 1
119 |
120 | /* Define to 1 if the system has the type `uintptr_t'. */
121 | #define HAVE_UINTPTR_T 1
122 |
123 | /* Define to 1 if you have the header file. */
124 | #define HAVE_UNISTD_H 1
125 |
126 | /* Define to 1 if you have the header file. */
127 | #undef HAVE_VFW_H
128 |
129 | /* Define to 1 if you have the header file. */
130 | #undef HAVE_X11_EXTENSIONS_XSHM_H
131 |
132 | /* Define to 1 if you have the header file. */
133 | #undef HAVE_X11_EXTENSIONS_XVLIB_H
134 |
135 | /* Define as const if the declaration of iconv() needs const. */
136 | #undef ICONV_CONST
137 |
138 | /* Library major version */
139 | #define LIB_VERSION_MAJOR 0
140 |
141 | /* Library minor version */
142 | #define LIB_VERSION_MINOR 2
143 |
144 | /* Library revision */
145 | #define LIB_VERSION_REVISION 0
146 |
147 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
148 | */
149 | #undef LT_OBJDIR
150 |
151 | /* Define to 1 if assertions should be disabled. */
152 | #define NDEBUG 0
153 |
154 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */
155 | #undef NO_MINUS_C_MINUS_O
156 |
157 | /* Name of package */
158 | #define PACKAGE "zbar"
159 |
160 | /* Define to the address where bug reports for this package should be sent. */
161 | #define PACKAGE_BUGREPORT "spadix@users.sourceforge.net"
162 |
163 | /* Define to the full name of this package. */
164 | #define PACKAGE_NAME "zbar"
165 |
166 | /* Define to the full name and version of this package. */
167 | #define PACKAGE_STRING "zbar 0.10"
168 |
169 | /* Define to the one symbol short name of this package. */
170 | #define PACKAGE_TARNAME "zbar"
171 |
172 | /* Define to the version of this package. */
173 | #define PACKAGE_VERSION "0.10"
174 |
175 | /* Define to 1 if you have the ANSI C header files. */
176 | #define STDC_HEADERS 1
177 |
178 | /* Version number of package */
179 | #define VERSION "0.10"
180 |
181 | /* Define to 1 if the X Window System is missing or not being used. */
182 | #define X_DISPLAY_MISSING 1
183 |
184 | /* Program major version (before the '.') as a number */
185 | #define ZBAR_VERSION_MAJOR 0
186 |
187 | /* Program minor version (after '.') as a number */
188 | #define ZBAR_VERSION_MINOR 10
189 |
190 | /* Define for Solaris 2.5.1 so the uint32_t typedef from ,
191 | , or is not used. If the typedef were allowed, the
192 | #define below would cause a syntax error. */
193 | #undef _UINT32_T
194 |
195 | /* Define for Solaris 2.5.1 so the uint8_t typedef from ,
196 | , or is not used. If the typedef were allowed, the
197 | #define below would cause a syntax error. */
198 | #undef _UINT8_T
199 |
200 | /* Minimum Windows API version */
201 | #undef _WIN32_WINNT
202 |
203 | /* used only for pthread debug attributes */
204 | #undef __USE_UNIX98
205 |
206 | /* Define to empty if `const' does not conform to ANSI C. */
207 | #undef const
208 |
209 | /* Define to `__inline__' or `__inline' if that's what the C compiler
210 | calls it, or to nothing if 'inline' is not supported under any name. */
211 | #ifndef __cplusplus
212 | #undef inline
213 | #endif
214 |
215 | /* Define to the type of a signed integer type of width exactly 32 bits if
216 | such a type exists and the standard includes do not define it. */
217 | #undef int32_t
218 |
219 | /* Define to the type of an unsigned integer type of width exactly 32 bits if
220 | such a type exists and the standard includes do not define it. */
221 | #undef uint32_t
222 |
223 | /* Define to the type of an unsigned integer type of width exactly 8 bits if
224 | such a type exists and the standard includes do not define it. */
225 | #undef uint8_t
226 |
227 | /* Define to the type of an unsigned integer type wide enough to hold a
228 | pointer, if such a type exists, and if the system does not define it. */
229 | #undef uintptr_t
230 |
231 | #ifndef X_DISPLAY_MISSING
232 | # define HAVE_X
233 | #endif
234 |
235 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/iphoneDebug.h:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------
2 | // Copyright 2009 (c) Jeff Brown
3 | //
4 | // This file is part of the ZBar Bar Code Reader.
5 | //
6 | // The ZBar Bar Code Reader is free software; you can redistribute it
7 | // and/or modify it under the terms of the GNU Lesser Public License as
8 | // published by the Free Software Foundation; either version 2.1 of
9 | // the License, or (at your option) any later version.
10 | //
11 | // The ZBar Bar Code Reader is distributed in the hope that it will be
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU Lesser Public License for more details.
15 | //
16 | // You should have received a copy of the GNU Lesser Public License
17 | // along with the ZBar Bar Code Reader; if not, write to the Free
18 | // Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | // Boston, MA 02110-1301 USA
20 | //
21 | // http://sourceforge.net/projects/zbar
22 | //------------------------------------------------------------------------
23 |
24 | #include
25 | #define xNSSTR(s) @#s
26 | #define NSSTR(s) xNSSTR(s)
27 |
28 | #ifdef DEBUG_OBJC
29 | # ifndef MODULE
30 | # define MODULE ZBarReaderController
31 | # endif
32 | # define zlog(fmt, ...) \
33 | NSLog(NSSTR(MODULE) @": " fmt , ##__VA_ARGS__)
34 |
35 | #define timer_start \
36 | uint64_t t_start = timer_now();
37 |
38 | #else
39 | # define zlog(...) while(0)
40 | # define timer_start
41 | #endif
42 |
43 | static inline uint64_t timer_now ()
44 | {
45 | return(mach_absolute_time());
46 | }
47 |
48 | static inline double timer_elapsed (uint64_t start, uint64_t end)
49 | {
50 | mach_timebase_info_data_t info;
51 | mach_timebase_info(&info);
52 | return((double)(end - start) * info.numer / (info.denom * 1000000000.));
53 | }
54 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/prefix.pch:
--------------------------------------------------------------------------------
1 | #ifdef __OBJC__
2 | # import
3 | # import
4 | # import
5 | # import
6 | # import
7 | # import
8 | # import
9 | # import
10 | #endif
11 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/config.c:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2008-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #include "config.h"
25 | #include /* strtol */
26 | #include /* strchr, strncmp, strlen */
27 | #ifdef HAVE_ERRNO_H
28 | # include
29 | #endif
30 |
31 | #include "zbar.h"
32 |
33 | int zbar_parse_config (const char *cfgstr,
34 | zbar_symbol_type_t *sym,
35 | zbar_config_t *cfg,
36 | int *val)
37 | {
38 | const char *dot, *eq;
39 | int len;
40 | char negate;
41 | if(!cfgstr)
42 | return(1);
43 |
44 | dot = strchr(cfgstr, '.');
45 | if(dot) {
46 | int len = dot - cfgstr;
47 | if(!len || (len == 1 && !strncmp(cfgstr, "*", len)))
48 | *sym = 0;
49 | else if(len < 2)
50 | return(1);
51 | else if(!strncmp(cfgstr, "qrcode", len))
52 | *sym = ZBAR_QRCODE;
53 | else if(!strncmp(cfgstr, "db", len))
54 | *sym = ZBAR_DATABAR;
55 | else if(len < 3)
56 | return(1);
57 | else if(!strncmp(cfgstr, "upca", len))
58 | *sym = ZBAR_UPCA;
59 | else if(!strncmp(cfgstr, "upce", len))
60 | *sym = ZBAR_UPCE;
61 | else if(!strncmp(cfgstr, "ean13", len))
62 | *sym = ZBAR_EAN13;
63 | else if(!strncmp(cfgstr, "ean8", len))
64 | *sym = ZBAR_EAN8;
65 | else if(!strncmp(cfgstr, "ean5", len))
66 | *sym = ZBAR_EAN5;
67 | else if(!strncmp(cfgstr, "ean2", len))
68 | *sym = ZBAR_EAN2;
69 | else if(!strncmp(cfgstr, "composite", len))
70 | *sym = ZBAR_COMPOSITE;
71 | else if(!strncmp(cfgstr, "i25", len))
72 | *sym = ZBAR_I25;
73 | else if(len < 4)
74 | return(1);
75 | else if(!strncmp(cfgstr, "scanner", len))
76 | *sym = ZBAR_PARTIAL; /* FIXME lame */
77 | else if(!strncmp(cfgstr, "isbn13", len))
78 | *sym = ZBAR_ISBN13;
79 | else if(!strncmp(cfgstr, "isbn10", len))
80 | *sym = ZBAR_ISBN10;
81 | else if(!strncmp(cfgstr, "db-exp", len))
82 | *sym = ZBAR_DATABAR_EXP;
83 | else if(!strncmp(cfgstr, "codabar", len))
84 | *sym = ZBAR_CODABAR;
85 | else if(len < 6)
86 | return(1);
87 | else if(!strncmp(cfgstr, "code93", len))
88 | *sym = ZBAR_CODE93;
89 | else if(!strncmp(cfgstr, "code39", len))
90 | *sym = ZBAR_CODE39;
91 | else if(!strncmp(cfgstr, "pdf417", len))
92 | *sym = ZBAR_PDF417;
93 | else if(len < 7)
94 | return(1);
95 | else if(!strncmp(cfgstr, "code128", len))
96 | *sym = ZBAR_CODE128;
97 | else if(!strncmp(cfgstr, "databar", len))
98 | *sym = ZBAR_DATABAR;
99 | else if(!strncmp(cfgstr, "databar-exp", len))
100 | *sym = ZBAR_DATABAR_EXP;
101 | else
102 | return(1);
103 | cfgstr = dot + 1;
104 | }
105 | else
106 | *sym = 0;
107 |
108 | len = strlen(cfgstr);
109 | eq = strchr(cfgstr, '=');
110 | if(eq)
111 | len = eq - cfgstr;
112 | else
113 | *val = 1; /* handle this here so we can override later */
114 | negate = 0;
115 |
116 | if(len > 3 && !strncmp(cfgstr, "no-", 3)) {
117 | negate = 1;
118 | cfgstr += 3;
119 | len -= 3;
120 | }
121 |
122 | if(len < 1)
123 | return(1);
124 | else if(!strncmp(cfgstr, "y-density", len))
125 | *cfg = ZBAR_CFG_Y_DENSITY;
126 | else if(!strncmp(cfgstr, "x-density", len))
127 | *cfg = ZBAR_CFG_X_DENSITY;
128 | else if(len < 2)
129 | return(1);
130 | else if(!strncmp(cfgstr, "enable", len))
131 | *cfg = ZBAR_CFG_ENABLE;
132 | else if(len < 3)
133 | return(1);
134 | else if(!strncmp(cfgstr, "disable", len)) {
135 | *cfg = ZBAR_CFG_ENABLE;
136 | negate = !negate; /* no-disable ?!? */
137 | }
138 | else if(!strncmp(cfgstr, "min-length", len))
139 | *cfg = ZBAR_CFG_MIN_LEN;
140 | else if(!strncmp(cfgstr, "max-length", len))
141 | *cfg = ZBAR_CFG_MAX_LEN;
142 | else if(!strncmp(cfgstr, "ascii", len))
143 | *cfg = ZBAR_CFG_ASCII;
144 | else if(!strncmp(cfgstr, "add-check", len))
145 | *cfg = ZBAR_CFG_ADD_CHECK;
146 | else if(!strncmp(cfgstr, "emit-check", len))
147 | *cfg = ZBAR_CFG_EMIT_CHECK;
148 | else if(!strncmp(cfgstr, "uncertainty", len))
149 | *cfg = ZBAR_CFG_UNCERTAINTY;
150 | else if(!strncmp(cfgstr, "position", len))
151 | *cfg = ZBAR_CFG_POSITION;
152 | else
153 | return(1);
154 |
155 | if(eq) {
156 | #ifdef HAVE_ERRNO_H
157 | errno = 0;
158 | #endif
159 | *val = strtol(eq + 1, NULL, 0);
160 | #ifdef HAVE_ERRNO_H
161 | if(errno)
162 | return(1);
163 | #endif
164 | }
165 | if(negate)
166 | *val = !*val;
167 |
168 | return(0);
169 | }
170 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/debug.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | /* varargs variations on compile time debug spew */
25 |
26 | # include
27 |
28 | #ifndef DEBUG_LEVEL
29 |
30 | # ifdef __GNUC__
31 | /* older versions of gcc (< 2.95) require a named varargs parameter */
32 | # define dbprintf(args...) while(0)
33 | # else
34 | /* unfortunately named vararg parameter is a gcc-specific extension */
35 | # define dbprintf(...) while(0)
36 | # endif
37 |
38 | #else
39 |
40 | # ifdef __GNUC__
41 | # define dbprintf(level, args...) do { \
42 | if((level) <= DEBUG_LEVEL) \
43 | fprintf(stderr, args); \
44 | } while(0)
45 | # else
46 | # define dbprintf(level, ...) do { \
47 | if((level) <= DEBUG_LEVEL) \
48 | fprintf(stderr, __VA_ARGS__); \
49 | } while(0)
50 | # endif
51 |
52 | #endif /* DEBUG_LEVEL */
53 |
54 | /* spew warnings for non-fatal assertions.
55 | * returns specified error code if assertion fails.
56 | * NB check/return is still performed for NDEBUG
57 | * only the message is inhibited
58 | * FIXME don't we need varargs hacks here?
59 | */
60 | #if NDEBUG
61 |
62 | # include
63 |
64 | #if __STDC_VERSION__ < 199901L && !defined(__func__)
65 | # if __GNUC__ >= 2
66 | # define __func__ __FUNCTION__
67 | # else
68 | # define __func__ ""
69 | # endif
70 | #endif
71 |
72 | # define zassert(condition, retval, format, ...) do { \
73 | if(!(condition)) { \
74 | fprintf(stderr, "WARNING: %s:%d: %s:" \
75 | " Assertion \"%s\" failed.\n\t" format, \
76 | __FILE__, __LINE__, __func__, #condition , \
77 | ##__VA_ARGS__); \
78 | return(retval); \
79 | } \
80 | } while(0)
81 |
82 | #else
83 |
84 | # define zassert(condition, retval, format, ...) do { \
85 | if(!(condition)) \
86 | return(retval); \
87 | } while(0)
88 |
89 | #endif
90 |
91 |
92 | //#include
93 | //#define xNSSTR(s) @#s
94 | //#define NSSTR(s) xNSSTR(s)
95 | //
96 | //#ifdef DEBUG_OBJC
97 | //# ifndef MODULE
98 | //# define MODULE ZBarReaderController
99 | //# endif
100 | //# define zlog(fmt, ...) \
101 | //NSLog(NSSTR(MODULE) @": " fmt , ##__VA_ARGS__)
102 | //
103 | //#define timer_start \
104 | //uint64_t t_start = timer_now();
105 | //
106 | //#else
107 | //# define zlog(...) while(0)
108 | //# define timer_start
109 | //#endif
110 | //
111 | //static inline uint64_t timer_now ()
112 | //{
113 | // return(mach_absolute_time());
114 | //}
115 | //
116 | //static inline double timer_elapsed (uint64_t start, uint64_t end)
117 | //{
118 | // mach_timebase_info_data_t info;
119 | // mach_timebase_info(&info);
120 | // return((double)(end - start) * info.numer / (info.denom * 1000000000.));
121 | //}
122 |
123 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _DECODER_H_
24 | #define _DECODER_H_
25 |
26 | #include "config.h"
27 | #include /* realloc */
28 | #include
29 |
30 | #include "zbar.h"
31 |
32 | #include "debug.h"
33 |
34 | #define NUM_CFGS (ZBAR_CFG_MAX_LEN - ZBAR_CFG_MIN_LEN + 1)
35 |
36 | #ifdef ENABLE_EAN
37 | # include "decoder/ean.h"
38 | #endif
39 | #ifdef ENABLE_I25
40 | # include "decoder/i25.h"
41 | #endif
42 | #ifdef ENABLE_DATABAR
43 | # include "decoder/databar.h"
44 | #endif
45 | #ifdef ENABLE_CODABAR
46 | # include "decoder/codabar.h"
47 | #endif
48 | #ifdef ENABLE_CODE39
49 | # include "decoder/code39.h"
50 | #endif
51 | #ifdef ENABLE_CODE93
52 | # include "decoder/code93.h"
53 | #endif
54 | #ifdef ENABLE_CODE128
55 | # include "decoder/code128.h"
56 | #endif
57 | #ifdef ENABLE_PDF417
58 | # include "decoder/pdf417.h"
59 | #endif
60 | #ifdef ENABLE_QRCODE
61 | # include "decoder/qr_finder.h"
62 | #endif
63 |
64 | /* size of bar width history (implementation assumes power of two) */
65 | #ifndef DECODE_WINDOW
66 | # define DECODE_WINDOW 16
67 | #endif
68 |
69 | /* initial data buffer allocation */
70 | #ifndef BUFFER_MIN
71 | # define BUFFER_MIN 0x20
72 | #endif
73 |
74 | /* maximum data buffer allocation
75 | * (longer symbols are rejected)
76 | */
77 | #ifndef BUFFER_MAX
78 | # define BUFFER_MAX 0x100
79 | #endif
80 |
81 | /* buffer allocation increment */
82 | #ifndef BUFFER_INCR
83 | # define BUFFER_INCR 0x10
84 | #endif
85 |
86 | #define CFG(dcode, cfg) ((dcode).configs[(cfg) - ZBAR_CFG_MIN_LEN])
87 | #define TEST_CFG(config, cfg) (((config) >> (cfg)) & 1)
88 | #define MOD(mod) (1 << (mod))
89 |
90 | /* symbology independent decoder state */
91 | struct zbar_decoder_s {
92 | unsigned char idx; /* current width index */
93 | unsigned w[DECODE_WINDOW]; /* window of last N bar widths */
94 | zbar_symbol_type_t type; /* type of last decoded data */
95 | zbar_symbol_type_t lock; /* buffer lock */
96 | unsigned modifiers; /* symbology modifier */
97 | int direction; /* direction of last decoded data */
98 | unsigned s6; /* 6-element character width */
99 |
100 | /* everything above here is automatically reset */
101 | unsigned buf_alloc; /* dynamic buffer allocation */
102 | unsigned buflen; /* binary data length */
103 | unsigned char *buf; /* decoded characters */
104 | void *userdata; /* application data */
105 | zbar_decoder_handler_t *handler; /* application callback */
106 |
107 | /* symbology specific state */
108 | #ifdef ENABLE_EAN
109 | ean_decoder_t ean; /* EAN/UPC parallel decode attempts */
110 | #endif
111 | #ifdef ENABLE_I25
112 | i25_decoder_t i25; /* Interleaved 2 of 5 decode state */
113 | #endif
114 | #ifdef ENABLE_DATABAR
115 | databar_decoder_t databar; /* DataBar decode state */
116 | #endif
117 | #ifdef ENABLE_CODABAR
118 | codabar_decoder_t codabar; /* Codabar decode state */
119 | #endif
120 | #ifdef ENABLE_CODE39
121 | code39_decoder_t code39; /* Code 39 decode state */
122 | #endif
123 | #ifdef ENABLE_CODE93
124 | code93_decoder_t code93; /* Code 93 decode state */
125 | #endif
126 | #ifdef ENABLE_CODE128
127 | code128_decoder_t code128; /* Code 128 decode state */
128 | #endif
129 | #ifdef ENABLE_PDF417
130 | pdf417_decoder_t pdf417; /* PDF417 decode state */
131 | #endif
132 | #ifdef ENABLE_QRCODE
133 | qr_finder_t qrf; /* QR Code finder state */
134 | #endif
135 | };
136 |
137 | /* return current element color */
138 | static inline char get_color (const zbar_decoder_t *dcode)
139 | {
140 | return(dcode->idx & 1);
141 | }
142 |
143 | /* retrieve i-th previous element width */
144 | static inline unsigned get_width (const zbar_decoder_t *dcode,
145 | unsigned char offset)
146 | {
147 | return(dcode->w[(dcode->idx - offset) & (DECODE_WINDOW - 1)]);
148 | }
149 |
150 | /* retrieve bar+space pair width starting at offset i */
151 | static inline unsigned pair_width (const zbar_decoder_t *dcode,
152 | unsigned char offset)
153 | {
154 | return(get_width(dcode, offset) + get_width(dcode, offset + 1));
155 | }
156 |
157 | /* calculate total character width "s"
158 | * - start of character identified by context sensitive offset
159 | * (<= DECODE_WINDOW - n)
160 | * - size of character is n elements
161 | */
162 | static inline unsigned calc_s (const zbar_decoder_t *dcode,
163 | unsigned char offset,
164 | unsigned char n)
165 | {
166 | /* FIXME check that this gets unrolled for constant n */
167 | unsigned s = 0;
168 | while(n--)
169 | s += get_width(dcode, offset++);
170 | return(s);
171 | }
172 |
173 | /* fixed character width decode assist
174 | * bar+space width are compared as a fraction of the reference dimension "x"
175 | * - +/- 1/2 x tolerance
176 | * - measured total character width (s) compared to symbology baseline (n)
177 | * (n = 7 for EAN/UPC, 11 for Code 128)
178 | * - bar+space *pair width* "e" is used to factor out bad "exposures"
179 | * ("blooming" or "swelling" of dark or light areas)
180 | * => using like-edge measurements avoids these issues
181 | * - n should be > 3
182 | */
183 | static inline int decode_e (unsigned e,
184 | unsigned s,
185 | unsigned n)
186 | {
187 | /* result is encoded number of units - 2
188 | * (for use as zero based index)
189 | * or -1 if invalid
190 | */
191 | unsigned char E = ((e * n * 2 + 1) / s - 3) / 2;
192 | return((E >= n - 3) ? -1 : E);
193 | }
194 |
195 | /* sort three like-colored elements and return ordering
196 | */
197 | static inline unsigned decode_sort3 (zbar_decoder_t *dcode,
198 | int i0)
199 | {
200 | unsigned w0 = get_width(dcode, i0);
201 | unsigned w2 = get_width(dcode, i0 + 2);
202 | unsigned w4 = get_width(dcode, i0 + 4);
203 | if(w0 < w2) {
204 | if(w2 < w4)
205 | return((i0 << 8) | ((i0 + 2) << 4) | (i0 + 4));
206 | if(w0 < w4)
207 | return((i0 << 8) | ((i0 + 4) << 4) | (i0 + 2));
208 | return(((i0 + 4) << 8) | (i0 << 4) | (i0 + 2));
209 | }
210 | if(w4 < w2)
211 | return(((i0 + 4) << 8) | ((i0 + 2) << 4) | i0);
212 | if(w0 < w4)
213 | return(((i0 + 2) << 8) | (i0 << 4) | (i0 + 4));
214 | return(((i0 + 2) << 8) | ((i0 + 4) << 4) | i0);
215 | }
216 |
217 | /* sort N like-colored elements and return ordering
218 | */
219 | static inline unsigned decode_sortn (zbar_decoder_t *dcode,
220 | int n,
221 | int i0)
222 | {
223 | unsigned mask = 0, sort = 0;
224 | int i;
225 | for(i = n - 1; i >= 0; i--) {
226 | unsigned wmin = UINT_MAX;
227 | int jmin = -1, j;
228 | for(j = n - 1; j >= 0; j--) {
229 | if((mask >> j) & 1)
230 | continue;
231 | unsigned w = get_width(dcode, i0 + j * 2);
232 | if(wmin >= w) {
233 | wmin = w;
234 | jmin = j;
235 | }
236 | }
237 | zassert(jmin >= 0, 0, "sortn(%d,%d) jmin=%d",
238 | n, i0, jmin);
239 | sort <<= 4;
240 | mask |= 1 << jmin;
241 | sort |= i0 + jmin * 2;
242 | }
243 | return(sort);
244 | }
245 |
246 | /* acquire shared state lock */
247 | static inline char acquire_lock (zbar_decoder_t *dcode,
248 | zbar_symbol_type_t req)
249 | {
250 | if(dcode->lock) {
251 | dbprintf(2, " [locked %d]\n", dcode->lock);
252 | return(1);
253 | }
254 | dcode->lock = req;
255 | return(0);
256 | }
257 |
258 | /* check and release shared state lock */
259 | static inline char release_lock (zbar_decoder_t *dcode,
260 | zbar_symbol_type_t req)
261 | {
262 | zassert(dcode->lock == req, 1, "lock=%d req=%d\n",
263 | dcode->lock, req);
264 | dcode->lock = 0;
265 | return(0);
266 | }
267 |
268 | /* ensure output buffer has sufficient allocation for request */
269 | static inline char size_buf (zbar_decoder_t *dcode,
270 | unsigned len)
271 | {
272 | unsigned char *buf;
273 | if(len <= BUFFER_MIN)
274 | return(0);
275 | if(len < dcode->buf_alloc)
276 | /* FIXME size reduction heuristic? */
277 | return(0);
278 | if(len > BUFFER_MAX)
279 | return(1);
280 | if(len < dcode->buf_alloc + BUFFER_INCR) {
281 | len = dcode->buf_alloc + BUFFER_INCR;
282 | if(len > BUFFER_MAX)
283 | len = BUFFER_MAX;
284 | }
285 | buf = realloc(dcode->buf, len);
286 | if(!buf)
287 | return(1);
288 | dcode->buf = buf;
289 | dcode->buf_alloc = len;
290 | return(0);
291 | }
292 |
293 | extern const char *_zbar_decoder_buf_dump (unsigned char *buf,
294 | unsigned int buflen);
295 |
296 | #endif
297 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/codabar.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2011 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _CODABAR_H_
24 | #define _CODABAR_H_
25 |
26 | /* Codabar specific decode state */
27 | typedef struct codabar_decoder_s {
28 | unsigned direction : 1; /* scan direction: 0=fwd, 1=rev */
29 | unsigned element : 4; /* element offset 0-7 */
30 | int character : 12; /* character position in symbol */
31 | unsigned s7; /* current character width */
32 | unsigned width; /* last character width */
33 | unsigned char buf[6]; /* initial scan buffer */
34 |
35 | unsigned config;
36 | int configs[NUM_CFGS]; /* int valued configurations */
37 | } codabar_decoder_t;
38 |
39 | /* reset Codabar specific state */
40 | static inline void codabar_reset (codabar_decoder_t *codabar)
41 | {
42 | codabar->direction = 0;
43 | codabar->element = 0;
44 | codabar->character = -1;
45 | codabar->s7 = 0;
46 | }
47 |
48 | /* decode Codabar symbols */
49 | zbar_symbol_type_t _zbar_decode_codabar(zbar_decoder_t *dcode);
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/code128.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _CODE128_H_
24 | #define _CODE128_H_
25 |
26 | /* Code 128 specific decode state */
27 | typedef struct code128_decoder_s {
28 | unsigned direction : 1; /* scan direction: 0=fwd/space, 1=rev/bar */
29 | unsigned element : 3; /* element offset 0-5 */
30 | int character : 12; /* character position in symbol */
31 | unsigned char start; /* start character */
32 | unsigned s6; /* character width */
33 | unsigned width; /* last character width */
34 |
35 | unsigned config;
36 | int configs[NUM_CFGS]; /* int valued configurations */
37 | } code128_decoder_t;
38 |
39 | /* reset Code 128 specific state */
40 | static inline void code128_reset (code128_decoder_t *dcode128)
41 | {
42 | dcode128->direction = 0;
43 | dcode128->element = 0;
44 | dcode128->character = -1;
45 | dcode128->s6 = 0;
46 | }
47 |
48 | /* decode Code 128 symbols */
49 | zbar_symbol_type_t _zbar_decode_code128(zbar_decoder_t *dcode);
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/code39.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2008-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _CODE39_H_
24 | #define _CODE39_H_
25 |
26 | /* Code 39 specific decode state */
27 | typedef struct code39_decoder_s {
28 | unsigned direction : 1; /* scan direction: 0=fwd, 1=rev */
29 | unsigned element : 4; /* element offset 0-8 */
30 | int character : 12; /* character position in symbol */
31 | unsigned s9; /* current character width */
32 | unsigned width; /* last character width */
33 |
34 | unsigned config;
35 | int configs[NUM_CFGS]; /* int valued configurations */
36 | } code39_decoder_t;
37 |
38 | /* reset Code 39 specific state */
39 | static inline void code39_reset (code39_decoder_t *dcode39)
40 | {
41 | dcode39->direction = 0;
42 | dcode39->element = 0;
43 | dcode39->character = -1;
44 | dcode39->s9 = 0;
45 | }
46 |
47 | /* decode Code 39 symbols */
48 | zbar_symbol_type_t _zbar_decode_code39(zbar_decoder_t *dcode);
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/code93.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _CODE93_H_
24 | #define _CODE93_H_
25 |
26 | /* Code 93 specific decode state */
27 | typedef struct code93_decoder_s {
28 | unsigned direction : 1; /* scan direction: 0=fwd/space, 1=rev/bar */
29 | unsigned element : 3; /* element offset 0-5 */
30 | int character : 12; /* character position in symbol */
31 | unsigned width; /* last character width */
32 | unsigned char buf; /* first character */
33 |
34 | unsigned config;
35 | int configs[NUM_CFGS]; /* int valued configurations */
36 | } code93_decoder_t;
37 |
38 | /* reset Code 93 specific state */
39 | static inline void code93_reset (code93_decoder_t *dcode93)
40 | {
41 | dcode93->direction = 0;
42 | dcode93->element = 0;
43 | dcode93->character = -1;
44 | }
45 |
46 | /* decode Code 93 symbols */
47 | zbar_symbol_type_t _zbar_decode_code93(zbar_decoder_t *dcode);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/databar.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _DATABAR_H_
24 | #define _DATABAR_H_
25 |
26 | #define DATABAR_MAX_SEGMENTS 32
27 |
28 | /* active DataBar (partial) segment entry */
29 | typedef struct databar_segment_s {
30 | signed finder : 5; /* finder pattern */
31 | unsigned exp : 1; /* DataBar expanded finder */
32 | unsigned color : 1; /* finder coloring */
33 | unsigned side : 1; /* data character side of finder */
34 |
35 | unsigned partial : 1; /* unpaired partial segment */
36 | unsigned count : 7; /* times encountered */
37 | unsigned epoch : 8; /* age, in characters scanned */
38 | unsigned check : 8; /* bar checksum */
39 | signed short data; /* decoded character data */
40 | unsigned short width; /* measured width of finder (14 modules) */
41 | } databar_segment_t;
42 |
43 | /* DataBar specific decode state */
44 | typedef struct databar_decoder_s {
45 | unsigned config; /* decoder configuration flags */
46 | unsigned config_exp;
47 |
48 | unsigned csegs : 8; /* allocated segments */
49 | unsigned epoch : 8; /* current scan */
50 |
51 | databar_segment_t *segs; /* active segment list */
52 | signed char chars[16]; /* outstanding character indices */
53 | } databar_decoder_t;
54 |
55 | /* reset DataBar segment decode state */
56 | static inline void databar_new_scan (databar_decoder_t *db)
57 | {
58 | int i;
59 | for(i = 0; i < 16; i++)
60 | if(db->chars[i] >= 0) {
61 | databar_segment_t *seg = db->segs + db->chars[i];
62 | if(seg->partial)
63 | seg->finder = -1;
64 | db->chars[i] = -1;
65 | }
66 | }
67 |
68 | /* reset DataBar accumulated segments */
69 | static inline void databar_reset (databar_decoder_t *db)
70 | {
71 | int i, n = db->csegs;
72 | databar_new_scan(db);
73 | for(i = 0; i < n; i++)
74 | db->segs[i].finder = -1;
75 | }
76 |
77 | /* decode DataBar symbols */
78 | zbar_symbol_type_t _zbar_decode_databar(zbar_decoder_t *dcode);
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/ean.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _EAN_H_
24 | #define _EAN_H_
25 |
26 | /* state of each parallel decode attempt */
27 | typedef struct ean_pass_s {
28 | signed char state; /* module position of w[idx] in symbol */
29 | #define STATE_REV 0x80 /* scan direction reversed */
30 | #define STATE_ADDON 0x40 /* scanning add-on */
31 | #define STATE_IDX 0x3f /* element offset into symbol */
32 | unsigned width; /* width of last character */
33 | unsigned char raw[7]; /* decode in process */
34 | } ean_pass_t;
35 |
36 | /* EAN/UPC specific decode state */
37 | typedef struct ean_decoder_s {
38 | ean_pass_t pass[4]; /* state of each parallel decode attempt */
39 | zbar_symbol_type_t left; /* current holding buffer contents */
40 | zbar_symbol_type_t right;
41 | int direction; /* scan direction */
42 | unsigned s4, width; /* character width */
43 | signed char buf[18]; /* holding buffer */
44 |
45 | signed char enable;
46 | unsigned ean13_config;
47 | unsigned ean8_config;
48 | unsigned upca_config;
49 | unsigned upce_config;
50 | unsigned isbn10_config;
51 | unsigned isbn13_config;
52 | unsigned ean5_config;
53 | unsigned ean2_config;
54 | } ean_decoder_t;
55 |
56 | /* reset EAN/UPC pass specific state */
57 | static inline void ean_new_scan (ean_decoder_t *ean)
58 | {
59 | ean->pass[0].state = ean->pass[1].state = -1;
60 | ean->pass[2].state = ean->pass[3].state = -1;
61 | ean->s4 = 0;
62 | }
63 |
64 | /* reset all EAN/UPC state */
65 | static inline void ean_reset (ean_decoder_t *ean)
66 | {
67 | ean_new_scan(ean);
68 | ean->left = ean->right = ZBAR_NONE;
69 | }
70 |
71 | static inline unsigned ean_get_config (ean_decoder_t *ean,
72 | zbar_symbol_type_t sym)
73 | {
74 | switch(sym) {
75 | case ZBAR_EAN2: return(ean->ean2_config);
76 | case ZBAR_EAN5: return(ean->ean5_config);
77 | case ZBAR_EAN8: return(ean->ean8_config);
78 | case ZBAR_UPCE: return(ean->upce_config);
79 | case ZBAR_ISBN10: return(ean->isbn10_config);
80 | case ZBAR_UPCA: return(ean->upca_config);
81 | case ZBAR_EAN13: return(ean->ean13_config);
82 | case ZBAR_ISBN13: return(ean->isbn13_config);
83 | default: return(0);
84 | }
85 | }
86 |
87 | /* decode EAN/UPC symbols */
88 | zbar_symbol_type_t _zbar_decode_ean(zbar_decoder_t *dcode);
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/i25.c:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2008-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #include "config.h"
25 | #include /* memmove */
26 |
27 | #include "zbar.h"
28 |
29 | #ifdef DEBUG_I25
30 | # define DEBUG_LEVEL (DEBUG_I25)
31 | #endif
32 | #include "debug.h"
33 | #include "decoder.h"
34 |
35 | static inline unsigned char i25_decode1 (unsigned char enc,
36 | unsigned e,
37 | unsigned s)
38 | {
39 | unsigned char E = decode_e(e, s, 45);
40 | if(E > 7)
41 | return(0xff);
42 | enc <<= 1;
43 | if(E > 2)
44 | enc |= 1;
45 | return(enc);
46 | }
47 |
48 | static inline unsigned char i25_decode10 (zbar_decoder_t *dcode,
49 | unsigned char offset)
50 | {
51 | i25_decoder_t *dcode25 = &dcode->i25;
52 | dbprintf(2, " s=%d", dcode25->s10);
53 | if(dcode25->s10 < 10)
54 | return(0xff);
55 |
56 | /* threshold bar width ratios */
57 | unsigned char enc = 0, par = 0;
58 | signed char i;
59 | for(i = 8; i >= 0; i -= 2) {
60 | unsigned char j = offset + ((dcode25->direction) ? i : 8 - i);
61 | enc = i25_decode1(enc, get_width(dcode, j), dcode25->s10);
62 | if(enc == 0xff)
63 | return(0xff);
64 | if(enc & 1)
65 | par++;
66 | }
67 |
68 | dbprintf(2, " enc=%02x par=%x", enc, par);
69 |
70 | /* parity check */
71 | if(par != 2) {
72 | dbprintf(2, " [bad parity]");
73 | return(0xff);
74 | }
75 |
76 | /* decode binary weights */
77 | enc &= 0xf;
78 | if(enc & 8) {
79 | if(enc == 12)
80 | enc = 0;
81 | else if(--enc > 9) {
82 | dbprintf(2, " [invalid encoding]");
83 | return(0xff);
84 | }
85 | }
86 |
87 | dbprintf(2, " => %x", enc);
88 | return(enc);
89 | }
90 |
91 | static inline signed char i25_decode_start (zbar_decoder_t *dcode)
92 | {
93 | i25_decoder_t *dcode25 = &dcode->i25;
94 | if(dcode25->s10 < 10)
95 | return(ZBAR_NONE);
96 |
97 | unsigned char enc = 0;
98 | unsigned char i = 10;
99 | enc = i25_decode1(enc, get_width(dcode, i++), dcode25->s10);
100 | enc = i25_decode1(enc, get_width(dcode, i++), dcode25->s10);
101 | enc = i25_decode1(enc, get_width(dcode, i++), dcode25->s10);
102 |
103 | if((get_color(dcode) == ZBAR_BAR)
104 | ? enc != 4
105 | : (enc = i25_decode1(enc, get_width(dcode, i++), dcode25->s10))) {
106 | dbprintf(4, " i25: s=%d enc=%x [invalid]\n", dcode25->s10, enc);
107 | return(ZBAR_NONE);
108 | }
109 |
110 | /* check leading quiet zone - spec is 10n(?)
111 | * we require 5.25n for w=2n to 6.75n for w=3n
112 | * (FIXME should really factor in w:n ratio)
113 | */
114 | unsigned quiet = get_width(dcode, i);
115 | if(quiet && quiet < dcode25->s10 * 3 / 8) {
116 | dbprintf(3, " i25: s=%d enc=%x q=%d [invalid qz]\n",
117 | dcode25->s10, enc, quiet);
118 | return(ZBAR_NONE);
119 | }
120 |
121 | dcode25->direction = get_color(dcode);
122 | dcode25->element = 1;
123 | dcode25->character = 0;
124 | return(ZBAR_PARTIAL);
125 | }
126 |
127 | static inline int i25_acquire_lock (zbar_decoder_t *dcode)
128 | {
129 | int i;
130 | /* lock shared resources */
131 | if(acquire_lock(dcode, ZBAR_I25)) {
132 | dcode->i25.character = -1;
133 | return(1);
134 | }
135 |
136 | /* copy holding buffer */
137 | for(i = 4; --i >= 0; )
138 | dcode->buf[i] = dcode->i25.buf[i];
139 | return(0);
140 | }
141 |
142 | static inline signed char i25_decode_end (zbar_decoder_t *dcode)
143 | {
144 | i25_decoder_t *dcode25 = &dcode->i25;
145 |
146 | /* check trailing quiet zone */
147 | unsigned quiet = get_width(dcode, 0);
148 | if((quiet && quiet < dcode25->width * 3 / 8) ||
149 | decode_e(get_width(dcode, 1), dcode25->width, 45) > 2 ||
150 | decode_e(get_width(dcode, 2), dcode25->width, 45) > 2) {
151 | dbprintf(3, " i25: s=%d q=%d [invalid qz]\n",
152 | dcode25->width, quiet);
153 | return(ZBAR_NONE);
154 | }
155 |
156 | /* check exit condition */
157 | unsigned char E = decode_e(get_width(dcode, 3), dcode25->width, 45);
158 | if((!dcode25->direction)
159 | ? E - 3 > 4
160 | : (E > 2 ||
161 | decode_e(get_width(dcode, 4), dcode25->width, 45) > 2))
162 | return(ZBAR_NONE);
163 |
164 | if(dcode25->character <= 4 &&
165 | i25_acquire_lock(dcode))
166 | return(ZBAR_PARTIAL);
167 |
168 | dcode->direction = 1 - 2 * dcode25->direction;
169 | if(dcode25->direction) {
170 | /* reverse buffer */
171 | dbprintf(2, " (rev)");
172 | int i;
173 | for(i = 0; i < dcode25->character / 2; i++) {
174 | unsigned j = dcode25->character - 1 - i;
175 | char c = dcode->buf[i];
176 | dcode->buf[i] = dcode->buf[j];
177 | dcode->buf[j] = c;
178 | }
179 | }
180 |
181 | if(dcode25->character < CFG(*dcode25, ZBAR_CFG_MIN_LEN) ||
182 | (CFG(*dcode25, ZBAR_CFG_MAX_LEN) > 0 &&
183 | dcode25->character > CFG(*dcode25, ZBAR_CFG_MAX_LEN))) {
184 | dbprintf(2, " [invalid len]\n");
185 | release_lock(dcode, ZBAR_I25);
186 | dcode25->character = -1;
187 | return(ZBAR_NONE);
188 | }
189 |
190 | zassert(dcode25->character < dcode->buf_alloc, ZBAR_NONE, "i=%02x %s\n",
191 | dcode25->character,
192 | _zbar_decoder_buf_dump(dcode->buf, dcode25->character));
193 | dcode->buflen = dcode25->character;
194 | dcode->buf[dcode25->character] = '\0';
195 | dcode->modifiers = 0;
196 | dbprintf(2, " [valid end]\n");
197 | dcode25->character = -1;
198 | return(ZBAR_I25);
199 | }
200 |
201 | zbar_symbol_type_t _zbar_decode_i25 (zbar_decoder_t *dcode)
202 | {
203 | i25_decoder_t *dcode25 = &dcode->i25;
204 |
205 | /* update latest character width */
206 | dcode25->s10 -= get_width(dcode, 10);
207 | dcode25->s10 += get_width(dcode, 0);
208 |
209 | if(dcode25->character < 0 &&
210 | !i25_decode_start(dcode))
211 | return(ZBAR_NONE);
212 |
213 | if(--dcode25->element == 6 - dcode25->direction)
214 | return(i25_decode_end(dcode));
215 | else if(dcode25->element)
216 | return(ZBAR_NONE);
217 |
218 | /* FIXME check current character width against previous */
219 | dcode25->width = dcode25->s10;
220 |
221 | dbprintf(2, " i25[%c%02d+%x]",
222 | (dcode25->direction) ? '<' : '>',
223 | dcode25->character, dcode25->element);
224 |
225 | if(dcode25->character == 4 && i25_acquire_lock(dcode))
226 | return(ZBAR_PARTIAL);
227 |
228 | unsigned char c = i25_decode10(dcode, 1);
229 | dbprintf(2, " c=%x", c);
230 | if(c > 9) {
231 | dbprintf(2, " [aborted]\n");
232 | goto reset;
233 | }
234 |
235 | if(size_buf(dcode, dcode25->character + 3)) {
236 | dbprintf(2, " [overflow]\n");
237 | goto reset;
238 | }
239 |
240 | unsigned char *buf;
241 | if(dcode25->character >= 4)
242 | buf = dcode->buf;
243 | else
244 | buf = dcode25->buf;
245 | buf[dcode25->character++] = c + '0';
246 |
247 | c = i25_decode10(dcode, 0);
248 | dbprintf(2, " c=%x", c);
249 | if(c > 9) {
250 | dbprintf(2, " [aborted]\n");
251 | goto reset;
252 | }
253 | else
254 | dbprintf(2, "\n");
255 |
256 | buf[dcode25->character++] = c + '0';
257 | dcode25->element = 10;
258 | return((dcode25->character == 2) ? ZBAR_PARTIAL : ZBAR_NONE);
259 |
260 | reset:
261 | if(dcode25->character >= 4)
262 | release_lock(dcode, ZBAR_I25);
263 | dcode25->character = -1;
264 | return(ZBAR_NONE);
265 | }
266 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/i25.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2008-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _I25_H_
24 | #define _I25_H_
25 |
26 | /* interleaved 2 of 5 specific decode state */
27 | typedef struct i25_decoder_s {
28 | unsigned direction : 1; /* scan direction: 0=fwd/space, 1=rev/bar */
29 | unsigned element : 4; /* element offset 0-8 */
30 | int character : 12; /* character position in symbol */
31 | unsigned s10; /* current character width */
32 | unsigned width; /* last character width */
33 | unsigned char buf[4]; /* initial scan buffer */
34 |
35 | unsigned config;
36 | int configs[NUM_CFGS]; /* int valued configurations */
37 | } i25_decoder_t;
38 |
39 | /* reset interleaved 2 of 5 specific state */
40 | static inline void i25_reset (i25_decoder_t *i25)
41 | {
42 | i25->direction = 0;
43 | i25->element = 0;
44 | i25->character = -1;
45 | i25->s10 = 0;
46 | }
47 |
48 | /* decode interleaved 2 of 5 symbols */
49 | zbar_symbol_type_t _zbar_decode_i25(zbar_decoder_t *dcode);
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/qr_finder.c:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2009-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #include "config.h"
25 | #include
26 |
27 | #include "zbar.h"
28 |
29 | #ifdef DEBUG_QR_FINDER
30 | # define DEBUG_LEVEL (DEBUG_QR_FINDER)
31 | #endif
32 | #include "debug.h"
33 | #include "decoder.h"
34 |
35 | /* at this point lengths are all decode unit offsets from the decode edge
36 | * NB owned by finder
37 | */
38 | qr_finder_line *_zbar_decoder_get_qr_finder_line (zbar_decoder_t *dcode)
39 | {
40 | return(&dcode->qrf.line);
41 | }
42 |
43 | zbar_symbol_type_t _zbar_find_qr (zbar_decoder_t *dcode)
44 | {
45 | qr_finder_t *qrf = &dcode->qrf;
46 | unsigned s, qz, w;
47 | int ei;
48 |
49 | /* update latest finder pattern width */
50 | qrf->s5 -= get_width(dcode, 6);
51 | qrf->s5 += get_width(dcode, 1);
52 | s = qrf->s5;
53 |
54 | /*TODO: The 2005 standard allows reflectance-reversed codes (light on dark
55 | instead of dark on light).
56 | If we find finder patterns with the opposite polarity, we should invert
57 | the final binarized image and use them to search for QR codes in that.*/
58 | if(get_color(dcode) != ZBAR_SPACE || s < 7)
59 | return(0);
60 |
61 | dbprintf(2, " qrf: s=%d", s);
62 |
63 | ei = decode_e(pair_width(dcode, 1), s, 7);
64 | dbprintf(2, " %d", ei);
65 | if(ei)
66 | goto invalid;
67 |
68 | ei = decode_e(pair_width(dcode, 2), s, 7);
69 | dbprintf(2, "%d", ei);
70 | if(ei != 2)
71 | goto invalid;
72 |
73 | ei = decode_e(pair_width(dcode, 3), s, 7);
74 | dbprintf(2, "%d", ei);
75 | if(ei != 2)
76 | goto invalid;
77 |
78 | ei = decode_e(pair_width(dcode, 4), s, 7);
79 | dbprintf(2, "%d", ei);
80 | if(ei)
81 | goto invalid;
82 |
83 | /* valid QR finder symbol
84 | * mark positions needed by decoder
85 | */
86 | qz = get_width(dcode, 0);
87 | w = get_width(dcode, 1);
88 | qrf->line.eoffs = qz + (w + 1) / 2;
89 | qrf->line.len = qz + w + get_width(dcode, 2);
90 | qrf->line.pos[0] = qrf->line.len + get_width(dcode, 3);
91 | qrf->line.pos[1] = qrf->line.pos[0];
92 | w = get_width(dcode, 5);
93 | qrf->line.boffs = qrf->line.pos[0] + get_width(dcode, 4) + (w + 1) / 2;
94 |
95 | dbprintf(2, " boff=%d pos=%d len=%d eoff=%d [valid]\n",
96 | qrf->line.boffs, qrf->line.pos[0], qrf->line.len,
97 | qrf->line.eoffs);
98 |
99 | dcode->direction = 0;
100 | dcode->buflen = 0;
101 | return(ZBAR_QRCODE);
102 |
103 | invalid:
104 | dbprintf(2, " [invalid]\n");
105 | return(0);
106 | }
107 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/decoder/qr_finder.h:
--------------------------------------------------------------------------------
1 | #ifndef _DECODER_QR_FINDER_H_
2 | #define _DECODER_QR_FINDER_H_
3 |
4 | #include "qrcode.h"
5 |
6 | /* QR Code symbol finder state */
7 | typedef struct qr_finder_s {
8 | unsigned s5; /* finder pattern width */
9 | qr_finder_line line; /* position info needed by decoder */
10 |
11 | unsigned config;
12 | } qr_finder_t;
13 |
14 | /* reset QR finder specific state */
15 | static inline void qr_finder_reset (qr_finder_t *qrf)
16 | {
17 | qrf->s5 = 0;
18 | }
19 |
20 | /* find QR Code symbols */
21 | zbar_symbol_type_t _zbar_find_qr (zbar_decoder_t *dcode);
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/error.c:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #include "error.h"
25 | #include
26 |
27 | int _zbar_verbosity = 0;
28 |
29 | static const char * const sev_str[] = {
30 | "FATAL ERROR", "ERROR", "OK", "WARNING", "NOTE"
31 | };
32 | #define SEV_MAX (strlen(sev_str[0]))
33 |
34 | static const char * const mod_str[] = {
35 | "processor", "video", "window", "image scanner", ""
36 | };
37 | #define MOD_MAX (strlen(mod_str[ZBAR_MOD_IMAGE_SCANNER]))
38 |
39 | static const char * const err_str[] = {
40 | "no error", /* OK */
41 | "out of memory", /* NOMEM */
42 | "internal library error", /* INTERNAL */
43 | "unsupported request", /* UNSUPPORTED */
44 | "invalid request", /* INVALID */
45 | "system error", /* SYSTEM */
46 | "locking error", /* LOCKING */
47 | "all resources busy", /* BUSY */
48 | "X11 display error", /* XDISPLAY */
49 | "X11 protocol error", /* XPROTO */
50 | "output window is closed", /* CLOSED */
51 | "windows system error", /* WINAPI */
52 | "unknown error" /* NUM */
53 | };
54 | #define ERR_MAX (strlen(err_str[ZBAR_ERR_CLOSED]))
55 |
56 | int zbar_version (unsigned *major,
57 | unsigned *minor)
58 | {
59 | if(major)
60 | *major = ZBAR_VERSION_MAJOR;
61 | if(minor)
62 | *minor = ZBAR_VERSION_MINOR;
63 | return(0);
64 | }
65 |
66 | void zbar_set_verbosity (int level)
67 | {
68 | _zbar_verbosity = level;
69 | }
70 |
71 | void zbar_increase_verbosity ()
72 | {
73 | if(!_zbar_verbosity)
74 | _zbar_verbosity++;
75 | else
76 | _zbar_verbosity <<= 1;
77 | }
78 |
79 | int _zbar_error_spew (const void *container,
80 | int verbosity)
81 | {
82 | const errinfo_t *err = container;
83 | assert(err->magic == ERRINFO_MAGIC);
84 | fprintf(stderr, "%s", _zbar_error_string(err, verbosity));
85 | return(-err->sev);
86 | }
87 |
88 | zbar_error_t _zbar_get_error_code (const void *container)
89 | {
90 | const errinfo_t *err = container;
91 | assert(err->magic == ERRINFO_MAGIC);
92 | return(err->type);
93 | }
94 |
95 | /* ERROR: zbar video in v4l1_set_format():
96 | * system error: blah[: blah]
97 | */
98 |
99 | const char *_zbar_error_string (const void *container,
100 | int verbosity)
101 | {
102 | static const char basefmt[] = "%s: zbar %s in %s():\n %s: ";
103 | errinfo_t *err = (errinfo_t*)container;
104 | const char *sev, *mod, *func, *type;
105 | int len;
106 |
107 | assert(err->magic == ERRINFO_MAGIC);
108 |
109 | if(err->sev >= SEV_FATAL && err->sev <= SEV_NOTE)
110 | sev = sev_str[err->sev + 2];
111 | else
112 | sev = sev_str[1];
113 |
114 | if(err->module >= ZBAR_MOD_PROCESSOR &&
115 | err->module < ZBAR_MOD_UNKNOWN)
116 | mod = mod_str[err->module];
117 | else
118 | mod = mod_str[ZBAR_MOD_UNKNOWN];
119 |
120 | func = (err->func) ? err->func : "";
121 |
122 | if(err->type >= 0 && err->type < ZBAR_ERR_NUM)
123 | type = err_str[err->type];
124 | else
125 | type = err_str[ZBAR_ERR_NUM];
126 |
127 | len = SEV_MAX + MOD_MAX + ERR_MAX + strlen(func) + sizeof(basefmt);
128 | err->buf = realloc(err->buf, len);
129 | len = sprintf(err->buf, basefmt, sev, mod, func, type);
130 | if(len <= 0)
131 | return("");
132 |
133 | if(err->detail) {
134 | int newlen = len + strlen(err->detail) + 1;
135 | if(strstr(err->detail, "%s")) {
136 | if(!err->arg_str)
137 | err->arg_str = strdup(">");
138 | err->buf = realloc(err->buf, newlen + strlen(err->arg_str));
139 | len += sprintf(err->buf + len, err->detail, err->arg_str);
140 | }
141 | else if(strstr(err->detail, "%d") || strstr(err->detail, "%x")) {
142 | err->buf = realloc(err->buf, newlen + 32);
143 | len += sprintf(err->buf + len, err->detail, err->arg_int);
144 | }
145 | else {
146 | err->buf = realloc(err->buf, newlen);
147 | len += sprintf(err->buf + len, "%s", err->detail);
148 | }
149 | if(len <= 0)
150 | return("");
151 | }
152 |
153 | #ifdef HAVE_ERRNO_H
154 | if(err->type == ZBAR_ERR_SYSTEM) {
155 | static const char sysfmt[] = ": %s (%d)\n";
156 | const char *syserr = strerror(err->errnum);
157 | err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr));
158 | len += sprintf(err->buf + len, sysfmt, syserr, err->errnum);
159 | }
160 | #endif
161 | #ifdef _WIN32
162 | else if(err->type == ZBAR_ERR_WINAPI) {
163 | char *syserr = NULL;
164 | if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
165 | FORMAT_MESSAGE_ALLOCATE_BUFFER |
166 | FORMAT_MESSAGE_IGNORE_INSERTS,
167 | NULL, err->errnum, 0, (LPTSTR)&syserr, 1, NULL) &&
168 | syserr) {
169 | char sysfmt[] = ": %s (%d)\n";
170 | err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr));
171 | len += sprintf(err->buf + len, sysfmt, syserr, err->errnum);
172 | LocalFree(syserr);
173 | }
174 | }
175 | #endif
176 | else {
177 | err->buf = realloc(err->buf, len + 2);
178 | len += sprintf(err->buf + len, "\n");
179 | }
180 | return(err->buf);
181 | }
182 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/error.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _ERROR_H_
24 | #define _ERROR_H_
25 |
26 | #include "config.h"
27 | #ifdef HAVE_INTTYPES_H
28 | # include
29 | #endif
30 | #include
31 | #include
32 | #include
33 | #ifdef HAVE_ERRNO_H
34 | # include
35 | #endif
36 | #include
37 |
38 | #include "zbar.h"
39 |
40 | #ifdef _WIN32
41 | # include
42 | #endif
43 |
44 | #if __STDC_VERSION__ < 199901L
45 | # if __GNUC__ >= 2
46 | # define __func__ __FUNCTION__
47 | # else
48 | # define __func__ ""
49 | # endif
50 | #endif
51 |
52 | #define ERRINFO_MAGIC (0x5252457a) /* "zERR" (LE) */
53 |
54 | typedef enum errsev_e {
55 | SEV_FATAL = -2, /* application must terminate */
56 | SEV_ERROR = -1, /* might be able to recover and continue */
57 | SEV_OK = 0,
58 | SEV_WARNING = 1, /* unexpected condition */
59 | SEV_NOTE = 2, /* fyi */
60 | } errsev_t;
61 |
62 | typedef enum errmodule_e {
63 | ZBAR_MOD_PROCESSOR,
64 | ZBAR_MOD_VIDEO,
65 | ZBAR_MOD_WINDOW,
66 | ZBAR_MOD_IMAGE_SCANNER,
67 | ZBAR_MOD_UNKNOWN,
68 | } errmodule_t;
69 |
70 | typedef struct errinfo_s {
71 | uint32_t magic; /* just in case */
72 | errmodule_t module; /* reporting module */
73 | char *buf; /* formatted and passed to application */
74 | int errnum; /* errno for system errors */
75 |
76 | errsev_t sev;
77 | zbar_error_t type;
78 | const char *func; /* reporting function */
79 | const char *detail; /* description */
80 | char *arg_str; /* single string argument */
81 | int arg_int; /* single integer argument */
82 | } errinfo_t;
83 |
84 | extern int _zbar_verbosity;
85 |
86 | /* FIXME don't we need varargs hacks here? */
87 |
88 | #ifdef _WIN32
89 | # define ZFLUSH fflush(stderr);
90 | #else
91 | # define ZFLUSH
92 | #endif
93 |
94 | #ifdef ZNO_MESSAGES
95 |
96 | # ifdef __GNUC__
97 | /* older versions of gcc (< 2.95) require a named varargs parameter */
98 | # define zprintf(args...)
99 | # else
100 | /* unfortunately named vararg parameter is a gcc-specific extension */
101 | # define zprintf(...)
102 | # endif
103 |
104 | #else
105 |
106 | # ifdef __GNUC__
107 | # define zprintf(level, format, args...) do { \
108 | if(_zbar_verbosity >= level) { \
109 | fprintf(stderr, "%s: " format, __func__ , ##args); \
110 | ZFLUSH \
111 | } \
112 | } while(0)
113 | # else
114 | # define zprintf(level, format, ...) do { \
115 | if(_zbar_verbosity >= level) { \
116 | fprintf(stderr, "%s: " format, __func__ , ##__VA_ARGS__); \
117 | ZFLUSH \
118 | } \
119 | } while(0)
120 | # endif
121 |
122 | #endif
123 |
124 | static inline int err_copy (void *dst_c,
125 | void *src_c)
126 | {
127 | errinfo_t *dst = dst_c;
128 | errinfo_t *src = src_c;
129 | assert(dst->magic == ERRINFO_MAGIC);
130 | assert(src->magic == ERRINFO_MAGIC);
131 |
132 | dst->errnum = src->errnum;
133 | dst->sev = src->sev;
134 | dst->type = src->type;
135 | dst->func = src->func;
136 | dst->detail = src->detail;
137 | dst->arg_str = src->arg_str;
138 | src->arg_str = NULL; /* unused at src, avoid double free */
139 | dst->arg_int = src->arg_int;
140 | return(-1);
141 | }
142 |
143 | static inline int err_capture (const void *container,
144 | errsev_t sev,
145 | zbar_error_t type,
146 | const char *func,
147 | const char *detail)
148 | {
149 | errinfo_t *err = (errinfo_t*)container;
150 | assert(err->magic == ERRINFO_MAGIC);
151 | #ifdef HAVE_ERRNO_H
152 | if(type == ZBAR_ERR_SYSTEM)
153 | err->errnum = errno;
154 | #endif
155 | #ifdef _WIN32
156 | if(type == ZBAR_ERR_WINAPI)
157 | err->errnum = GetLastError();
158 | #endif
159 | err->sev = sev;
160 | err->type = type;
161 | err->func = func;
162 | err->detail = detail;
163 | if(_zbar_verbosity >= 1)
164 | _zbar_error_spew(err, 0);
165 | return(-1);
166 | }
167 |
168 | static inline int err_capture_str (const void *container,
169 | errsev_t sev,
170 | zbar_error_t type,
171 | const char *func,
172 | const char *detail,
173 | const char *arg)
174 | {
175 | errinfo_t *err = (errinfo_t*)container;
176 | assert(err->magic == ERRINFO_MAGIC);
177 | if(err->arg_str)
178 | free(err->arg_str);
179 | err->arg_str = strdup(arg);
180 | return(err_capture(container, sev, type, func, detail));
181 | }
182 |
183 | static inline int err_capture_int (const void *container,
184 | errsev_t sev,
185 | zbar_error_t type,
186 | const char *func,
187 | const char *detail,
188 | int arg)
189 | {
190 | errinfo_t *err = (errinfo_t*)container;
191 | assert(err->magic == ERRINFO_MAGIC);
192 | err->arg_int = arg;
193 | return(err_capture(container, sev, type, func, detail));
194 | }
195 |
196 | static inline int err_capture_num (const void *container,
197 | errsev_t sev,
198 | zbar_error_t type,
199 | const char *func,
200 | const char *detail,
201 | int num)
202 | {
203 | errinfo_t *err = (errinfo_t*)container;
204 | assert(err->magic == ERRINFO_MAGIC);
205 | err->errnum = num;
206 | return(err_capture(container, sev, type, func, detail));
207 | }
208 |
209 | static inline void err_init (errinfo_t *err,
210 | errmodule_t module)
211 | {
212 | err->magic = ERRINFO_MAGIC;
213 | err->module = module;
214 | }
215 |
216 | static inline void err_cleanup (errinfo_t *err)
217 | {
218 | assert(err->magic == ERRINFO_MAGIC);
219 | if(err->buf) {
220 | free(err->buf);
221 | err->buf = NULL;
222 | }
223 | if(err->arg_str) {
224 | free(err->arg_str);
225 | err->arg_str = NULL;
226 | }
227 | }
228 |
229 | #endif
230 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/image.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _IMAGE_H_
24 | #define _IMAGE_H_
25 |
26 | #include "config.h"
27 | #ifdef HAVE_INTTYPES_H
28 | # include
29 | #endif
30 | #include
31 | #include
32 |
33 | #include "zbar.h"
34 | #include "error.h"
35 | #include "symbol.h"
36 | #include "refcnt.h"
37 |
38 | #define fourcc zbar_fourcc
39 |
40 | /* unpack size/location of component */
41 | #define RGB_SIZE(c) ((c) >> 5)
42 | #define RGB_OFFSET(c) ((c) & 0x1f)
43 |
44 | /* coarse image format categorization.
45 | * to limit conversion variations
46 | */
47 | typedef enum zbar_format_group_e {
48 | ZBAR_FMT_GRAY,
49 | ZBAR_FMT_YUV_PLANAR,
50 | ZBAR_FMT_YUV_PACKED,
51 | ZBAR_FMT_RGB_PACKED,
52 | ZBAR_FMT_YUV_NV,
53 | ZBAR_FMT_JPEG,
54 |
55 | /* enum size */
56 | ZBAR_FMT_NUM
57 | } zbar_format_group_t;
58 |
59 |
60 | struct zbar_image_s {
61 | uint32_t format; /* fourcc image format code */
62 | unsigned width, height; /* image size */
63 | const void *data; /* image sample data */
64 | unsigned long datalen; /* allocated/mapped size of data */
65 | unsigned crop_x, crop_y; /* crop rectangle */
66 | unsigned crop_w, crop_h;
67 | void *userdata; /* user specified data associated w/image */
68 |
69 | /* cleanup handler */
70 | zbar_image_cleanup_handler_t *cleanup;
71 | refcnt_t refcnt; /* reference count */
72 | zbar_video_t *src; /* originator */
73 | int srcidx; /* index used by originator */
74 | zbar_image_t *next; /* internal image lists */
75 |
76 | unsigned seq; /* page/frame sequence number */
77 | zbar_symbol_set_t *syms; /* decoded result set */
78 | };
79 |
80 | /* description of an image format */
81 | typedef struct zbar_format_def_s {
82 | uint32_t format; /* fourcc */
83 | zbar_format_group_t group; /* coarse categorization */
84 | union {
85 | uint8_t gen[4]; /* raw bytes */
86 | struct {
87 | uint8_t bpp; /* bits per pixel */
88 | uint8_t red, green, blue; /* size/location a la RGB_BITS() */
89 | } rgb;
90 | struct {
91 | uint8_t xsub2, ysub2; /* chroma subsampling in each axis */
92 | uint8_t packorder; /* channel ordering flags
93 | * bit0: 0=UV, 1=VU
94 | * bit1: 0=Y/chroma, 1=chroma/Y
95 | */
96 | } yuv;
97 | uint32_t cmp; /* quick compare equivalent formats */
98 | } p;
99 | } zbar_format_def_t;
100 |
101 |
102 | extern int _zbar_best_format(uint32_t, uint32_t*, const uint32_t*);
103 | extern const zbar_format_def_t *_zbar_format_lookup(uint32_t);
104 | extern void _zbar_image_free(zbar_image_t*);
105 |
106 | #ifdef DEBUG_SVG
107 | extern int zbar_image_write_png(const zbar_image_t*, const char*);
108 | #else
109 | # define zbar_image_write_png(...)
110 | #endif
111 |
112 | static inline void _zbar_image_refcnt (zbar_image_t *img,
113 | int delta)
114 | {
115 | if(!_zbar_refcnt(&img->refcnt, delta) && delta <= 0) {
116 | if(img->cleanup)
117 | img->cleanup(img);
118 | if(!img->src)
119 | _zbar_image_free(img);
120 | }
121 | }
122 |
123 | static inline void _zbar_image_swap_symbols (zbar_image_t *a,
124 | zbar_image_t *b)
125 | {
126 | zbar_symbol_set_t *tmp = a->syms;
127 | a->syms = b->syms;
128 | b->syms = tmp;
129 | }
130 |
131 | static inline void _zbar_image_copy_size (zbar_image_t *dst,
132 | const zbar_image_t *src)
133 | {
134 | dst->width = src->width;
135 | dst->height = src->height;
136 | dst->crop_x = src->crop_x;
137 | dst->crop_y = src->crop_y;
138 | dst->crop_w = src->crop_w;
139 | dst->crop_h = src->crop_h;
140 | }
141 |
142 | #endif
143 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/img_scanner.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _IMG_SCANNER_H_
24 | #define _IMG_SCANNER_H_
25 |
26 | #include "zbar.h"
27 |
28 | /* internal image scanner APIs for 2D readers */
29 |
30 | extern zbar_symbol_t *_zbar_image_scanner_alloc_sym(zbar_image_scanner_t*,
31 | zbar_symbol_type_t,
32 | int);
33 | extern void _zbar_image_scanner_add_sym(zbar_image_scanner_t*,
34 | zbar_symbol_t*);
35 | extern void _zbar_image_scanner_recycle_syms(zbar_image_scanner_t*,
36 | zbar_symbol_t*);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode.h:
--------------------------------------------------------------------------------
1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
2 | You can redistribute this library and/or modify it under the terms of the
3 | GNU Lesser General Public License as published by the Free Software
4 | Foundation; either version 2.1 of the License, or (at your option) any later
5 | version.*/
6 | #ifndef _QRCODE_H_
7 | #define _QRCODE_H_
8 |
9 | #include "zbar.h"
10 |
11 | typedef struct qr_reader qr_reader;
12 |
13 | typedef int qr_point[2];
14 | typedef struct qr_finder_line qr_finder_line;
15 |
16 | /*The number of bits of subpel precision to store image coordinates in.
17 | This helps when estimating positions in low-resolution images, which may have
18 | a module pitch only a pixel or two wide, making rounding errors matter a
19 | great deal.*/
20 | #define QR_FINDER_SUBPREC (2)
21 |
22 | /*A line crossing a finder pattern.
23 | Whether the line is horizontal or vertical is determined by context.
24 | The offsts to various parts of the finder pattern are as follows:
25 | |*****| |*****|*****|*****| |*****|
26 | |*****| |*****|*****|*****| |*****|
27 | ^ ^ ^ ^
28 | | | | |
29 | | | | pos[v]+len+eoffs
30 | | | pos[v]+len
31 | | pos[v]
32 | pos[v]-boffs
33 | Here v is 0 for horizontal and 1 for vertical lines.*/
34 | struct qr_finder_line {
35 | /*The location of the upper/left endpoint of the line.
36 | The left/upper edge of the center section is used, since other lines must
37 | cross in this region.*/
38 | qr_point pos;
39 | /*The length of the center section.
40 | This extends to the right/bottom of the center section, since other lines
41 | must cross in this region.*/
42 | int len;
43 | /*The offset to the midpoint of the upper/left section (part of the outside
44 | ring), or 0 if we couldn't identify the edge of the beginning section.
45 | We use the midpoint instead of the edge because it can be located more
46 | reliably.*/
47 | int boffs;
48 | /*The offset to the midpoint of the end section (part of the outside ring),
49 | or 0 if we couldn't identify the edge of the end section.
50 | We use the midpoint instead of the edge because it can be located more
51 | reliably.*/
52 | int eoffs;
53 | };
54 |
55 | qr_reader *_zbar_qr_create(void);
56 | void _zbar_qr_destroy(qr_reader *reader);
57 | void _zbar_qr_reset(qr_reader *reader);
58 |
59 | int _zbar_qr_found_line(qr_reader *reader,
60 | int direction,
61 | const qr_finder_line *line);
62 | int _zbar_qr_decode(qr_reader *reader,
63 | zbar_image_scanner_t *iscn,
64 | zbar_image_t *img);
65 |
66 | #endif
67 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode/bch15_5.c:
--------------------------------------------------------------------------------
1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
2 | You can redistribute this library and/or modify it under the terms of the
3 | GNU Lesser General Public License as published by the Free Software
4 | Foundation; either version 2.1 of the License, or (at your option) any later
5 | version.*/
6 | #include "bch15_5.h"
7 |
8 | /*A cycle in GF(2**4) generated by alpha=(x**4+x+1).
9 | It is extended an extra 16 entries to avoid some expensive mod operations.*/
10 | static const unsigned char gf16_exp[31]={
11 | 1,2,4,8,3,6,12,11,5,10,7,14,15,13,9,1,2,4,8,3,6,12,11,5,10,7,14,15,13,9,1
12 | };
13 |
14 | /*The location of each integer 1...16 in the cycle.*/
15 | static const signed char gf16_log[16]={
16 | -1,0,1,4,2,8,5,10,3,14,9,7,6,13,11,12
17 | };
18 |
19 | /*Multiplication in GF(2**4) using logarithms.*/
20 | static unsigned gf16_mul(unsigned _a,unsigned _b){
21 | return _a==0||_b==0?0:gf16_exp[gf16_log[_a]+gf16_log[_b]];
22 | }
23 |
24 | /*Division in GF(2**4) using logarithms.
25 | The result when dividing by zero is undefined.*/
26 | static unsigned gf16_div(unsigned _a,unsigned _b){
27 | return _a==0?0:gf16_exp[gf16_log[_a]+15-gf16_log[_b]];
28 | }
29 |
30 | /*Multiplication in GF(2**4) when the second argument is known to be non-zero
31 | (proven by representing it by its logarithm).*/
32 | static unsigned gf16_hmul(unsigned _a,unsigned _logb){
33 | return _a==0?0:gf16_exp[gf16_log[_a]+_logb];
34 | }
35 |
36 | /*The syndrome normally has five values, S_1 ... S_5.
37 | We only calculate and store the odd ones in _s, since S_2=S_1**2 and
38 | S_4=S_2**2.
39 | Returns zero iff all the syndrome values are zero.*/
40 | static int bch15_5_calc_syndrome(unsigned _s[3],unsigned _y){
41 | unsigned p;
42 | int i;
43 | int j;
44 | p=0;
45 | for(i=0;i<15;i++)if(_y&1<0&&!_o[d-1];d--);
70 | return d;
71 | }
72 |
73 | /*Find the roots of the error polynomial.
74 | Returns the number of roots found, or a negative value if the polynomial did
75 | not have enough roots, indicating a decoding error.*/
76 | static int bch15_5_calc_epos(unsigned _epos[3],unsigned _s[3]){
77 | unsigned o[3];
78 | int nerrors;
79 | int d;
80 | int i;
81 | d=bch15_5_calc_omega(o,_s);
82 | nerrors=0;
83 | if(d==1)_epos[nerrors++]=gf16_log[o[0]];
84 | else if(d>0){
85 | for(i=0;i<15;i++){
86 | int i2;
87 | i2=gf16_log[gf16_exp[i<<1]];
88 | if(!(gf16_exp[i+i2]^gf16_hmul(o[0],i2)^gf16_hmul(o[1],i)^o[2])){
89 | _epos[nerrors++]=i;
90 | }
91 | }
92 | if(nerrors0){
107 | /*If we had a non-zero syndrome value, we should always find at least one
108 | error location, or we've got a decoding error.*/
109 | for(i=0;i>10)==y){
115 | /*Decoding succeeded.*/
116 | *_y=y;
117 | return nerrors;
118 | }
119 | }
120 | /*Decoding failed due to too many bit errors.*/
121 | return -1;
122 | }
123 |
124 | unsigned bch15_5_encode(unsigned _x){
125 | return (-(_x&1)&0x0537)^(-(_x>>1&1)&0x0A6E)^(-(_x>>2&1)&0x11EB)^
126 | (-(_x>>3&1)&0x23D6)^(-(_x>>4&1)&0x429B);
127 | }
128 |
129 | #if 0
130 | #include
131 |
132 | static unsigned codes[32];
133 |
134 | static int hamming(int _a,int _b){
135 | int d;
136 | int n;
137 | d=_a^_b;
138 | for(n=0;d;n++)d&=d-1;
139 | return n;
140 | }
141 |
142 | static int closest(int _y){
143 | int min_i;
144 | int min_d;
145 | int i;
146 | int d;
147 | min_i=0;
148 | min_d=hamming(_y,codes[0]);
149 | for(i=1;i<32;i++){
150 | d=hamming(_y,codes[i]);
151 | if(dFailed\n",i);
175 | if(hamming(i,z)<=3)printf("Error: 0x%04X should map to 0x%04X\n",i,z);
176 | }
177 | else{
178 | printf("0x%04X->0x%04X\n",i,y);
179 | if(z!=y)printf("Error: 0x%04X should map to 0x%04X\n",i,z);
180 | }
181 | }
182 | return 0;
183 | }
184 | #endif
185 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode/bch15_5.h:
--------------------------------------------------------------------------------
1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
2 | You can redistribute this library and/or modify it under the terms of the
3 | GNU Lesser General Public License as published by the Free Software
4 | Foundation; either version 2.1 of the License, or (at your option) any later
5 | version.*/
6 | #if !defined(_bch15_5_H)
7 | # define _bch15_5_H (1)
8 |
9 | /*Encodes a raw 5-bit value _x into a 15-bit BCH(15,5) code.
10 | This is capable of correcting up to 3 bit errors, and detecting as many as
11 | 5 bit errors in some cases.*/
12 | unsigned bch15_5_encode(unsigned _x);
13 |
14 | /*Corrects the received code *_y, if possible.
15 | The original data is located in the top five bits.
16 | Returns the number of errors corrected, or a negative value if decoding
17 | failed due to too many bit errors, in which case *_y is left unchanged.*/
18 | int bch15_5_correct(unsigned *_y);
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode/binarize.h:
--------------------------------------------------------------------------------
1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
2 | You can redistribute this library and/or modify it under the terms of the
3 | GNU Lesser General Public License as published by the Free Software
4 | Foundation; either version 2.1 of the License, or (at your option) any later
5 | version.*/
6 | #if !defined(_qrcode_binarize_H)
7 | # define _qrcode_binarize_H (1)
8 |
9 | void qr_image_cross_masking_median_filter(unsigned char *_img,
10 | int _width,int _height);
11 |
12 | void qr_wiener_filter(unsigned char *_img,int _width,int _height);
13 |
14 | /*Binarizes a grayscale image.*/
15 | unsigned char *qr_binarize(const unsigned char *_img,int _width,int _height);
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode/isaac.c:
--------------------------------------------------------------------------------
1 | /*Written by Timothy B. Terriberry (tterribe@xiph.org) 1999-2009 public domain.
2 | Based on the public domain implementation by Robert J. Jenkins Jr.*/
3 | #include
4 | #include
5 | #include
6 | #include "isaac.h"
7 |
8 |
9 |
10 | #define ISAAC_MASK (0xFFFFFFFFU)
11 |
12 |
13 |
14 | static void isaac_update(isaac_ctx *_ctx){
15 | unsigned *m;
16 | unsigned *r;
17 | unsigned a;
18 | unsigned b;
19 | unsigned x;
20 | unsigned y;
21 | int i;
22 | m=_ctx->m;
23 | r=_ctx->r;
24 | a=_ctx->a;
25 | b=_ctx->b+(++_ctx->c)&ISAAC_MASK;
26 | for(i=0;i>2]+a+b&ISAAC_MASK;
30 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
31 | x=m[++i];
32 | a=(a^a>>6)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
33 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
34 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
35 | x=m[++i];
36 | a=(a^a<<2)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
37 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
38 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
39 | x=m[++i];
40 | a=(a^a>>16)+m[i+ISAAC_SZ/2]&ISAAC_MASK;
41 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
42 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
43 | }
44 | for(i=ISAAC_SZ/2;i>2]+a+b&ISAAC_MASK;
48 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
49 | x=m[++i];
50 | a=(a^a>>6)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
51 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
52 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
53 | x=m[++i];
54 | a=(a^a<<2)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
55 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
56 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
57 | x=m[++i];
58 | a=(a^a>>16)+m[i-ISAAC_SZ/2]&ISAAC_MASK;
59 | m[i]=y=m[(x&ISAAC_SZ-1<<2)>>2]+a+b&ISAAC_MASK;
60 | r[i]=b=m[y>>ISAAC_SZ_LOG+2&ISAAC_SZ-1]+x&ISAAC_MASK;
61 | }
62 | _ctx->b=b;
63 | _ctx->a=a;
64 | _ctx->n=ISAAC_SZ;
65 | }
66 |
67 | static void isaac_mix(unsigned _x[8]){
68 | static const unsigned char SHIFT[8]={11,2,8,16,10,4,8,9};
69 | int i;
70 | for(i=0;i<8;i++){
71 | _x[i]^=_x[i+1&7]<>SHIFT[i];
76 | _x[i+3&7]+=_x[i];
77 | _x[i+1&7]+=_x[i+2&7];
78 | }
79 | }
80 |
81 |
82 | void isaac_init(isaac_ctx *_ctx,const void *_seed,int _nseed){
83 | const unsigned char *seed;
84 | unsigned *m;
85 | unsigned *r;
86 | unsigned x[8];
87 | int i;
88 | int j;
89 | _ctx->a=_ctx->b=_ctx->c=0;
90 | m=_ctx->m;
91 | r=_ctx->r;
92 | x[0]=x[1]=x[2]=x[3]=x[4]=x[5]=x[6]=x[7]=0x9E3779B9;
93 | for(i=0;i<4;i++)isaac_mix(x);
94 | if(_nseed>ISAAC_SEED_SZ_MAX)_nseed=ISAAC_SEED_SZ_MAX;
95 | seed=(const unsigned char *)_seed;
96 | for(i=0;i<_nseed>>2;i++){
97 | r[i]=seed[i<<2|3]<<24|seed[i<<2|2]<<16|seed[i<<2|1]<<8|seed[i<<2];
98 | }
99 | if(_nseed&3){
100 | r[i]=seed[i<<2];
101 | for(j=1;j<(_nseed&3);j++)r[i]+=seed[i<<2|j]<<(j<<3);
102 | i++;
103 | }
104 | memset(r+i,0,(ISAAC_SZ-i)*sizeof(*r));
105 | for(i=0;in)isaac_update(_ctx);
120 | return _ctx->r[--_ctx->n];
121 | }
122 |
123 | /*Returns a uniform random integer less than the given maximum value.
124 | _n: The upper bound on the range of numbers returned (not inclusive).
125 | This must be strictly less than 2**32.
126 | Return: An integer uniformly distributed between 0 (inclusive) and _n
127 | (exclusive).*/
128 | unsigned isaac_next_uint(isaac_ctx *_ctx,unsigned _n){
129 | unsigned r;
130 | unsigned v;
131 | unsigned d;
132 | do{
133 | r=isaac_next_uint32(_ctx);
134 | v=r%_n;
135 | d=r-v;
136 | }
137 | while((d+_n-1&ISAAC_MASK)
7 | #include "util.h"
8 |
9 | /*Computes floor(sqrt(_val)) exactly.*/
10 | unsigned qr_isqrt(unsigned _val){
11 | unsigned g;
12 | unsigned b;
13 | int bshift;
14 | /*Uses the second method from
15 | http://www.azillionmonkeys.com/qed/sqroot.html
16 | The main idea is to search for the largest binary digit b such that
17 | (g+b)*(g+b) <= _val, and add it to the solution g.*/
18 | g=0;
19 | b=0x8000;
20 | for(bshift=16;bshift-->0;){
21 | unsigned t;
22 | t=(g<<1)+b<>=1;
28 | }
29 | return g;
30 | }
31 |
32 | /*Computes sqrt(_x*_x+_y*_y) using CORDIC.
33 | This implementation is valid for all 32-bit inputs and returns a result
34 | accurate to about 27 bits of precision.
35 | It has been tested for all postiive 16-bit inputs, where it returns correctly
36 | rounded results in 99.998% of cases and the maximum error is
37 | 0.500137134862598032 (for _x=48140, _y=63018).
38 | Very nearly all results less than (1<<16) are correctly rounded.
39 | All Pythagorean triples with a hypotenuse of less than ((1<<27)-1) evaluate
40 | correctly, and the total bias over all Pythagorean triples is -0.04579, with
41 | a relative RMS error of 7.2864E-10 and a relative peak error of 7.4387E-9.*/
42 | unsigned qr_ihypot(int _x,int _y){
43 | unsigned x;
44 | unsigned y;
45 | int mask;
46 | int shift;
47 | int u;
48 | int v;
49 | int i;
50 | x=_x=abs(_x);
51 | y=_y=abs(_y);
52 | mask=-(x>y)&(_x^_y);
53 | x^=mask;
54 | y^=mask;
55 | _y^=mask;
56 | shift=31-qr_ilog(y);
57 | shift=QR_MAXI(shift,0);
58 | x=(unsigned)((x<>32);
59 | _y=(int)((_y<>32);
60 | u=x;
61 | mask=-(_y<0);
62 | x+=_y+mask^mask;
63 | _y-=u+mask^mask;
64 | u=x+1>>1;
65 | v=_y+1>>1;
66 | mask=-(_y<0);
67 | x+=v+mask^mask;
68 | _y-=u+mask^mask;
69 | for(i=1;i<16;i++){
70 | int r;
71 | u=x+1>>2;
72 | r=(1<<2*i)>>1;
73 | v=_y+r>>2*i;
74 | mask=-(_y<0);
75 | x+=v+mask^mask;
76 | _y=_y-(u+mask^mask)<<1;
77 | }
78 | return x+((1U<>1)>>shift;
79 | }
80 |
81 | #if defined(__GNUC__) && defined(HAVE_FEATURES_H)
82 | # include
83 | # if __GNUC_PREREQ(3,4)
84 | # include
85 | # if INT_MAX>=2147483647
86 | # define QR_CLZ0 sizeof(unsigned)*CHAR_BIT
87 | # define QR_CLZ(_x) (__builtin_clz(_x))
88 | # elif LONG_MAX>=2147483647L
89 | # define QR_CLZ0 sizeof(unsigned long)*CHAR_BIT
90 | # define QR_CLZ(_x) (__builtin_clzl(_x))
91 | # endif
92 | # endif
93 | #endif
94 |
95 | int qr_ilog(unsigned _v){
96 | #if defined(QR_CLZ)
97 | /*Note that __builtin_clz is not defined when _x==0, according to the gcc
98 | documentation (and that of the x86 BSR instruction that implements it), so
99 | we have to special-case it.*/
100 | return QR_CLZ0-QR_CLZ(_v)&-!!_v;
101 | #else
102 | int ret;
103 | int m;
104 | m=!!(_v&0xFFFF0000)<<4;
105 | _v>>=m;
106 | ret=m;
107 | m=!!(_v&0xFF00)<<3;
108 | _v>>=m;
109 | ret|=m;
110 | m=!!(_v&0xF0)<<2;
111 | _v>>=m;
112 | ret|=m;
113 | m=!!(_v&0xC)<<1;
114 | _v>>=m;
115 | ret|=m;
116 | ret|=!!(_v&0x2);
117 | return ret + !!_v;
118 | #endif
119 | }
120 |
121 | #if defined(QR_TEST_SQRT)
122 | #include
123 | #include
124 |
125 | /*Exhaustively test the integer square root function.*/
126 | int main(void){
127 | unsigned u;
128 | u=0;
129 | do{
130 | unsigned r;
131 | unsigned s;
132 | r=qr_isqrt(u);
133 | s=(int)sqrt(u);
134 | if(r!=s)printf("%u: %u!=%u\n",u,r,s);
135 | u++;
136 | }
137 | while(u);
138 | return 0;
139 | }
140 | #endif
141 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/qrcode/util.h:
--------------------------------------------------------------------------------
1 | /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org)
2 | You can redistribute this library and/or modify it under the terms of the
3 | GNU Lesser General Public License as published by the Free Software
4 | Foundation; either version 2.1 of the License, or (at your option) any later
5 | version.*/
6 | #if !defined(_qrcode_util_H)
7 | # define _qrcode_util_H (1)
8 |
9 | #define QR_MAXI(_a,_b) ((_a)-((_a)-(_b)&-((_b)>(_a))))
10 | #define QR_MINI(_a,_b) ((_a)+((_b)-(_a)&-((_b)<(_a))))
11 | #define QR_SIGNI(_x) (((_x)>0)-((_x)<0))
12 | #define QR_SIGNMASK(_x) (-((_x)<0))
13 | /*Unlike copysign(), simply inverts the sign of _a if _b is negative.*/
14 | #define QR_FLIPSIGNI(_a,_b) ((_a)+QR_SIGNMASK(_b)^QR_SIGNMASK(_b))
15 | #define QR_COPYSIGNI(_a,_b) QR_FLIPSIGNI(abs(_a),_b)
16 | /*Divides a signed integer by a positive value with exact rounding.*/
17 | #define QR_DIVROUND(_x,_y) (((_x)+QR_FLIPSIGNI(_y>>1,_x))/(_y))
18 | #define QR_CLAMPI(_a,_b,_c) (QR_MAXI(_a,QR_MINI(_b,_c)))
19 | #define QR_CLAMP255(_x) ((unsigned char)((((_x)<0)-1)&((_x)|-((_x)>255))))
20 | #define QR_SWAP2I(_a,_b) \
21 | do{ \
22 | int t__; \
23 | t__=(_a); \
24 | (_a)=(_b); \
25 | (_b)=t__; \
26 | } \
27 | while(0)
28 | /*Swaps two integers _a and _b if _a>_b.*/
29 | #define QR_SORT2I(_a,_b) \
30 | do{ \
31 | int t__; \
32 | t__=QR_MINI(_a,_b)^(_a); \
33 | (_a)^=t__; \
34 | (_b)^=t__; \
35 | } \
36 | while(0)
37 | #define QR_ILOG0(_v) (!!((_v)&0x2))
38 | #define QR_ILOG1(_v) (((_v)&0xC)?2+QR_ILOG0((_v)>>2):QR_ILOG0(_v))
39 | #define QR_ILOG2(_v) (((_v)&0xF0)?4+QR_ILOG1((_v)>>4):QR_ILOG1(_v))
40 | #define QR_ILOG3(_v) (((_v)&0xFF00)?8+QR_ILOG2((_v)>>8):QR_ILOG2(_v))
41 | #define QR_ILOG4(_v) (((_v)&0xFFFF0000)?16+QR_ILOG3((_v)>>16):QR_ILOG3(_v))
42 | /*Computes the integer logarithm of a (positive, 32-bit) constant.*/
43 | #define QR_ILOG(_v) ((int)QR_ILOG4((unsigned)(_v)))
44 |
45 | /*Multiplies 32-bit numbers _a and _b, adds (possibly 64-bit) number _r, and
46 | takes bits [_s,_s+31] of the result.*/
47 | #define QR_FIXMUL(_a,_b,_r,_s) ((int)((_a)*(long long)(_b)+(_r)>>(_s)))
48 | /*Multiplies 32-bit numbers _a and _b, adds (possibly 64-bit) number _r, and
49 | gives all 64 bits of the result.*/
50 | #define QR_EXTMUL(_a,_b,_r) ((_a)*(long long)(_b)+(_r))
51 |
52 | unsigned qr_isqrt(unsigned _val);
53 | unsigned qr_ihypot(int _x,int _y);
54 | int qr_ilog(unsigned _val);
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/refcnt.c:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 |
24 | #include "refcnt.h"
25 |
26 | #if !defined(_WIN32) && !defined(TARGET_OS_MAC) && defined(HAVE_LIBPTHREAD)
27 |
28 | pthread_once_t initialized = PTHREAD_ONCE_INIT;
29 | pthread_mutex_t _zbar_reflock;
30 |
31 | static void initialize (void)
32 | {
33 | pthread_mutex_init(&_zbar_reflock, NULL);
34 | }
35 |
36 | void _zbar_refcnt_init ()
37 | {
38 | pthread_once(&initialized, initialize);
39 | }
40 |
41 |
42 | #else
43 |
44 | void _zbar_refcnt_init ()
45 | {
46 | }
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/refcnt.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _REFCNT_H_
24 | #define _REFCNT_H_
25 |
26 | #include "config.h"
27 | #include
28 |
29 | #if defined(_WIN32)
30 | # include
31 |
32 | typedef LONG refcnt_t;
33 |
34 | static inline int _zbar_refcnt (refcnt_t *cnt,
35 | int delta)
36 | {
37 | int rc = -1;
38 | if(delta > 0)
39 | while(delta--)
40 | rc = InterlockedIncrement(cnt);
41 | else if(delta < 0)
42 | while(delta++)
43 | rc = InterlockedDecrement(cnt);
44 | assert(rc >= 0);
45 | return(rc);
46 | }
47 |
48 | #elif defined(TARGET_OS_MAC)
49 | # include
50 |
51 | typedef int32_t refcnt_t;
52 |
53 | static inline int _zbar_refcnt (refcnt_t *cnt,
54 | int delta)
55 | {
56 | int rc = OSAtomicAdd32Barrier(delta, cnt);
57 | assert(rc >= 0);
58 | return(rc);
59 | }
60 |
61 | #elif defined(HAVE_LIBPTHREAD)
62 | # include
63 |
64 | typedef int refcnt_t;
65 |
66 | extern pthread_mutex_t _zbar_reflock;
67 |
68 | static inline int _zbar_refcnt (refcnt_t *cnt,
69 | int delta)
70 | {
71 | pthread_mutex_lock(&_zbar_reflock);
72 | int rc = (*cnt += delta);
73 | pthread_mutex_unlock(&_zbar_reflock);
74 | assert(rc >= 0);
75 | return(rc);
76 | }
77 |
78 |
79 | #else
80 |
81 | typedef int refcnt_t;
82 |
83 | static inline int _zbar_refcnt (refcnt_t *cnt,
84 | int delta)
85 | {
86 | int rc = (*cnt += delta);
87 | assert(rc >= 0);
88 | return(rc);
89 | }
90 |
91 | #endif
92 |
93 |
94 | void _zbar_refcnt_init(void);
95 |
96 | #endif
97 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/svg.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2009 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _SVG_H_
24 | #define _SVG_H_
25 |
26 | #ifdef DEBUG_SVG
27 |
28 | typedef enum { SVG_REL, SVG_ABS } svg_absrel_t;
29 |
30 | void svg_open(const char *name, double x, double y, double w, double h);
31 | void svg_close(void);
32 |
33 | void svg_commentf(const char *format, ...);
34 | void svg_image(const char *name, double width, double height);
35 |
36 | void svg_group_start(const char *cls, double rotate,
37 | double scalex, double scaley,
38 | double x, double y);
39 | void svg_group_end(void);
40 |
41 | void svg_path_start(const char *cls, double scale, double x, double y);
42 | void svg_path_end(void);
43 | void svg_path_close(void);
44 | void svg_path_moveto(svg_absrel_t abs, double x, double y);
45 | void svg_path_lineto(svg_absrel_t abs, double x, double y);
46 |
47 | #else
48 |
49 | # define svg_open(...)
50 | # define svg_close(...)
51 |
52 | # define svg_image(...)
53 |
54 | # define svg_group_start(...)
55 | # define svg_group_end(...)
56 |
57 | # define svg_path_start(...)
58 | # define svg_path_end(...)
59 | # define svg_path_moveto(...)
60 | # define svg_path_lineto(...)
61 | # define svg_path_close(...)
62 |
63 | #endif
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/symbol.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _SYMBOL_H_
24 | #define _SYMBOL_H_
25 |
26 | #include
27 | #include "zbar.h"
28 | #include "refcnt.h"
29 |
30 | #define NUM_SYMS 20
31 |
32 | typedef struct point_s {
33 | int x, y;
34 | } point_t;
35 |
36 | struct zbar_symbol_set_s {
37 | refcnt_t refcnt;
38 | int nsyms; /* number of filtered symbols */
39 | zbar_symbol_t *head; /* first of decoded symbol results */
40 | zbar_symbol_t *tail; /* last of unfiltered symbol results */
41 | };
42 |
43 | struct zbar_symbol_s {
44 | zbar_symbol_type_t type; /* symbol type */
45 | unsigned int configs; /* symbology boolean config bitmask */
46 | unsigned int modifiers; /* symbology modifier bitmask */
47 | unsigned int data_alloc; /* allocation size of data */
48 | unsigned int datalen; /* length of binary symbol data */
49 | char *data; /* symbol data */
50 |
51 | unsigned pts_alloc; /* allocation size of pts */
52 | unsigned npts; /* number of points in location polygon */
53 | point_t *pts; /* list of points in location polygon */
54 | zbar_orientation_t orient; /* coarse orientation */
55 |
56 | refcnt_t refcnt; /* reference count */
57 | zbar_symbol_t *next; /* linked list of results (or siblings) */
58 | zbar_symbol_set_t *syms; /* components of composite result */
59 | unsigned long time; /* relative symbol capture time */
60 | int cache_count; /* cache state */
61 | int quality; /* relative symbol reliability metric */
62 | };
63 |
64 | extern int _zbar_get_symbol_hash(zbar_symbol_type_t);
65 |
66 | extern void _zbar_symbol_free(zbar_symbol_t*);
67 |
68 | extern zbar_symbol_set_t *_zbar_symbol_set_create(void);
69 | extern void _zbar_symbol_set_free(zbar_symbol_set_t*);
70 |
71 | static inline void sym_add_point (zbar_symbol_t *sym,
72 | int x,
73 | int y)
74 | {
75 | int i = sym->npts;
76 | if(++sym->npts >= sym->pts_alloc)
77 | sym->pts = realloc(sym->pts, ++sym->pts_alloc * sizeof(point_t));
78 | sym->pts[i].x = x;
79 | sym->pts[i].y = y;
80 | }
81 |
82 | static inline void _zbar_symbol_refcnt (zbar_symbol_t *sym,
83 | int delta)
84 | {
85 | if(!_zbar_refcnt(&sym->refcnt, delta) && delta <= 0)
86 | _zbar_symbol_free(sym);
87 | }
88 |
89 | static inline void _zbar_symbol_set_add (zbar_symbol_set_t *syms,
90 | zbar_symbol_t *sym)
91 | {
92 | sym->next = syms->head;
93 | syms->head = sym;
94 | syms->nsyms++;
95 |
96 | _zbar_symbol_refcnt(sym, 1);
97 | }
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/ZBar-iOS/ZBarSDK/zbar/timer.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------
2 | * Copyright 2007-2010 (c) Jeff Brown
3 | *
4 | * This file is part of the ZBar Bar Code Reader.
5 | *
6 | * The ZBar Bar Code Reader is free software; you can redistribute it
7 | * and/or modify it under the terms of the GNU Lesser Public License as
8 | * published by the Free Software Foundation; either version 2.1 of
9 | * the License, or (at your option) any later version.
10 | *
11 | * The ZBar Bar Code Reader is distributed in the hope that it will be
12 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser Public License
17 | * along with the ZBar Bar Code Reader; if not, write to the Free
18 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 | * Boston, MA 02110-1301 USA
20 | *
21 | * http://sourceforge.net/projects/zbar
22 | *------------------------------------------------------------------------*/
23 | #ifndef _ZBAR_TIMER_H_
24 | #define _ZBAR_TIMER_H_
25 |
26 | #include
27 | #ifdef HAVE_SYS_TIME_H
28 | # include /* gettimeofday */
29 | #endif
30 |
31 | /* platform timer abstraction
32 | *
33 | * zbar_timer_t stores the absolute expiration of a delay from
34 | * when the timer was initialized.
35 | *
36 | * _zbar_timer_init() initialized timer with specified ms delay.
37 | * returns timer or NULL if timeout < 0 (no/infinite timeout)
38 | * _zbar_timer_check() returns ms remaining until expiration.
39 | * will be <= 0 if timer has expired
40 | */
41 |
42 | #if _POSIX_TIMERS > 0
43 |
44 | typedef struct timespec zbar_timer_t;
45 |
46 | static inline int _zbar_timer_now ()
47 | {
48 | struct timespec now;
49 | clock_gettime(CLOCK_REALTIME, &now);
50 | return(now.tv_sec * 1000 + now.tv_nsec / 1000000);
51 | }
52 |
53 | static inline zbar_timer_t *_zbar_timer_init (zbar_timer_t *timer,
54 | int delay)
55 | {
56 | if(delay < 0)
57 | return(NULL);
58 |
59 | clock_gettime(CLOCK_REALTIME, timer);
60 | timer->tv_nsec += (delay % 1000) * 1000000;
61 | timer->tv_sec += (delay / 1000) + (timer->tv_nsec / 1000000000);
62 | timer->tv_nsec %= 1000000000;
63 | return(timer);
64 | }
65 |
66 | static inline int _zbar_timer_check (zbar_timer_t *timer)
67 | {
68 | struct timespec now;
69 | int delay;
70 | if(!timer)
71 | return(-1);
72 |
73 | clock_gettime(CLOCK_REALTIME, &now);
74 | delay = ((timer->tv_sec - now.tv_sec) * 1000 +
75 | (timer->tv_nsec - now.tv_nsec) / 1000000);
76 | return((delay >= 0) ? delay : 0);
77 | }
78 |
79 |
80 | #elif defined(_WIN32)
81 |
82 | # include
83 |
84 | typedef DWORD zbar_timer_t;
85 |
86 | static inline int _zbar_timer_now ()
87 | {
88 | return(timeGetTime());
89 | }
90 |
91 | static inline zbar_timer_t *_zbar_timer_init (zbar_timer_t *timer,
92 | int delay)
93 | {
94 | if(delay < 0)
95 | return(NULL);
96 |
97 | *timer = timeGetTime() + delay;
98 | return(timer);
99 | }
100 |
101 | static inline int _zbar_timer_check (zbar_timer_t *timer)
102 | {
103 | int delay;
104 | if(!timer)
105 | return(INFINITE);
106 |
107 | delay = *timer - timeGetTime();
108 | return((delay >= 0) ? delay : 0);
109 | }
110 |
111 |
112 | #elif defined(HAVE_SYS_TIME_H)
113 |
114 | typedef struct timeval zbar_timer_t;
115 |
116 | static inline int _zbar_timer_now ()
117 | {
118 | struct timeval now;
119 | gettimeofday(&now, NULL);
120 | return(now.tv_sec * 1000 + now.tv_usec / 1000);
121 | }
122 |
123 | static inline zbar_timer_t *_zbar_timer_init (zbar_timer_t *timer,
124 | int delay)
125 | {
126 | if(delay < 0)
127 | return(NULL);
128 |
129 | gettimeofday(timer, NULL);
130 | timer->tv_usec += (delay % 1000) * 1000;
131 | timer->tv_sec += (delay / 1000) + (timer->tv_usec / 1000000);
132 | timer->tv_usec %= 1000000;
133 | return(timer);
134 | }
135 |
136 | static inline int _zbar_timer_check (zbar_timer_t *timer)
137 | {
138 | struct timeval now;
139 | if(!timer)
140 | return(-1);
141 |
142 | gettimeofday(&now, NULL);
143 | return((timer->tv_sec - now.tv_sec) * 1000 +
144 | (timer->tv_usec - now.tv_usec) / 1000);
145 | }
146 |
147 | #else
148 | # error "unable to find a timer interface"
149 | #endif
150 |
151 | #endif
152 |
--------------------------------------------------------------------------------
/ZBar-iOS/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // ZBar-iOS
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ZBar-iOSTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ZBar-iOSTests/ZBar_iOSTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // ZBar_iOSTests.m
3 | // ZBar-iOSTests
4 | //
5 | // Created by Fujun on 15/6/30.
6 | // Copyright (c) 2015年 Fujun. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface ZBar_iOSTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation ZBar_iOSTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------