summaryrefslogtreecommitdiffstats
path: root/iphone/include/ZBarSDK/ZBarCaptureReader.h
blob: e49681902505f52b42f014e45e087e49a36e8937 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//------------------------------------------------------------------------
//  Copyright 2010 (c) Jeff Brown <spadix@users.sourceforge.net>
//
//  This file is part of the ZBar Bar Code Reader.
//
//  The ZBar Bar Code Reader is free software; you can redistribute it
//  and/or modify it under the terms of the GNU Lesser Public License as
//  published by the Free Software Foundation; either version 2.1 of
//  the License, or (at your option) any later version.
//
//  The ZBar Bar Code Reader is distributed in the hope that it will be
//  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser Public License for more details.
//
//  You should have received a copy of the GNU Lesser Public License
//  along with the ZBar Bar Code Reader; if not, write to the Free
//  Software Foundation, Inc., 51 Franklin St, Fifth Floor,
//  Boston, MA  02110-1301  USA
//
//  http://sourceforge.net/projects/zbar
//------------------------------------------------------------------------

#import <CoreGraphics/CoreGraphics.h>
#import "ZBarImageScanner.h"

@class AVCaptureVideoDataOutput, AVCaptureOutput;
@class ZBarCaptureReader, ZBarCVImage;

@protocol ZBarCaptureDelegate <NSObject>

// called when a new barcode is detected.  the image refers to the
// video buffer and must not be retained for long
- (void)captureReader:(ZBarCaptureReader *)captureReader
    didReadNewSymbolsFromImage:(ZBarImage *)image;

@optional
// called when a potential/uncertain barcode is detected.  will also
// be called *after* captureReader:didReadNewSymbolsFromImage:
// when good barcodes are detected
- (void)captureReader:(ZBarCaptureReader *)captureReader
      didTrackSymbols:(ZBarSymbolSet *)symbols;

@end

@interface ZBarCaptureReader : NSObject {
#if !TARGET_IPHONE_SIMULATOR
    AVCaptureVideoDataOutput *captureOutput;
    id<ZBarCaptureDelegate> captureDelegate;
    ZBarImageScanner *scanner;
    CGRect scanCrop;
    CGSize size;
    CGFloat framesPerSecond;
    BOOL enableCache;

    dispatch_queue_t queue;
    ZBarImage *image;
    ZBarCVImage *result;
    volatile uint32_t state;
    int framecnt;
    unsigned width, height;
    uint64_t t_frame, t_fps, t_scan;
    CGFloat dt_frame;
#endif
}

// supply a pre-configured image scanner
- (id)initWithImageScanner:(ZBarImageScanner *)imageScanner;

// this must be called before the session is started
- (void)willStartRunning;

// this must be called *before* the session is stopped
- (void)willStopRunning;

// clear the internal result cache
- (void)flushCache;

// capture the next frame after processing.  the captured image will
// follow the same delegate path as an image with decoded symbols.
- (void)captureFrame;

// the capture output.  add this to an instance of AVCaptureSession
@property (nonatomic, readonly) AVCaptureOutput *captureOutput;

// delegate is notified of decode results and symbol tracking.
@property (nonatomic, assign) id<ZBarCaptureDelegate> captureDelegate;

// access to image scanner for configuration.
@property (nonatomic, readonly) ZBarImageScanner *scanner;

// region of image to scan in normalized coordinates.
// NB horizontal crop currently ignored...
@property (nonatomic, assign) CGRect scanCrop;

// size of video frames.
@property (nonatomic, readonly) CGSize size;

// (quickly) gate the reader function without interrupting the video
// stream.  also flushes the cache when enabled.  defaults to *NO*
@property (nonatomic) BOOL enableReader;

// current frame rate (for debug/optimization).
// only valid when running
@property (nonatomic, readonly) CGFloat framesPerSecond;

@property (nonatomic) BOOL enableCache;

@end