|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ocr engine thread definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef OCRTHREAD_H |
|
20 #define OCRTHREAD_H |
|
21 |
|
22 // INCLUDES FILES |
|
23 #include "ocrsharedata.h" |
|
24 |
|
25 class CFbsBitmap; |
|
26 |
|
27 /** Global function type definitions */ |
|
28 typedef TBool (*IsCanceled)( void ); |
|
29 typedef TBool (*RecogProgress)(TUint aPercentage); |
|
30 |
|
31 /** Internal error code definition */ |
|
32 const TInt KErrEngineOK ( 0 ); //no error |
|
33 const TInt KErrEngineBadImage ( -1001 ); //bad image or unsupported format |
|
34 const TInt KErrEngineBadLanguage ( -1002 ); //unsupported language |
|
35 const TInt KErrEngineBadRgn ( -1003 ); //bad layout region |
|
36 const TInt KErrEngineNoMemory ( -1004 ); //no enough memory |
|
37 const TInt KErrEngineBadParam ( -1005 ); //wrong parameter |
|
38 const TInt KErrEngineNotSetLang ( -1006 ); //not set any language |
|
39 const TInt KErrEngineBadDicFile ( -1007 ); //bad dictionary files |
|
40 const TInt KErrEngineGeneral ( -1100 ); //the other errors |
|
41 |
|
42 /** Number of interfaces defined in the engine DLLs */ |
|
43 const TInt KNumOfInterfaces ( 14 ); |
|
44 |
|
45 /** Implementation interfaces definitions */ |
|
46 enum TImplementationIds |
|
47 { |
|
48 EExitEngine = 1, |
|
49 EFreeBinImage, |
|
50 EFreeBlocks, |
|
51 EGetInstalledLanguages, |
|
52 EGetVersion, |
|
53 EInitEngine, |
|
54 ELayoutAnalysis, |
|
55 ERecognizeWithLayout, |
|
56 ERecognizeBlock, |
|
57 ERefresh, |
|
58 ESetActiveLanguage, |
|
59 ERecognizeSpecialRegion, |
|
60 EIsLanguageSupported, |
|
61 EFreeTextRgns |
|
62 }; |
|
63 |
|
64 /** |
|
65 * Version of 3rd party ocr engines |
|
66 * |
|
67 * @lib ocrsrv.lib |
|
68 * @since S60 v3.1 |
|
69 */ |
|
70 class TEngineVersion |
|
71 { |
|
72 public: |
|
73 |
|
74 /** |
|
75 * Major version |
|
76 */ |
|
77 TInt8 iMajor; |
|
78 |
|
79 /** |
|
80 * Minor version |
|
81 */ |
|
82 TInt8 iMinor; |
|
83 |
|
84 /** |
|
85 * Build number |
|
86 */ |
|
87 TInt16 iBuild; |
|
88 }; |
|
89 |
|
90 /** type definition of the interfaces */ |
|
91 typedef TInt (*TLibFuncInitEngine)(IsCanceled aFuncIsCanceled, TAny* aParam); |
|
92 typedef void (*TLibFuncExitEngine)( void ); |
|
93 |
|
94 typedef TInt (*TLibFuncLayout)(const CFbsBitmap* aImage, const TOCRLayoutSetting aSettings, HBufC8** aBinImage, TOCRBlockInfo** aBlock, TInt* aBlockCount); |
|
95 typedef TInt (*TLibFuncRecognize)(HBufC8* aBinImage, const TOCRRecognizeSetting aSettings, TOCRBlockInfo* aBlock, const TInt aBlockCount, TOCRTextRgnInfo** aTextRgn, RecogProgress aFuncRecogProgress); |
|
96 |
|
97 typedef void (*TLibFuncFreeBinImage)(HBufC8* aBinImage); |
|
98 typedef void (*TLibFuncFreeBlocks)(TOCRBlockInfo* aBlock); |
|
99 typedef void (*TLibFuncFreeTextRgns)(TOCRTextRgnInfo *aTextRgn,const TInt aBlockCount); |
|
100 |
|
101 typedef TEngineVersion (*TLibFuncGetVersion)( void ); |
|
102 typedef TInt (*TLibFuncSetActiveLanguage)(RArray<TInt> iLanguages); |
|
103 typedef TInt (*TLibFuncGetInstalledLanguages)(RArray<TInt>& aLanguages); |
|
104 typedef TInt (*TLibFuncRefresh)( void ); |
|
105 typedef TBool (*TLibFuncIsLanguageSupported)(const TLanguage aLanguage); |
|
106 |
|
107 typedef TInt (*TLibFuncRecognizeBlock)(const CFbsBitmap* aImage, TOCRLayoutBlockInfo aLayoutInfo, TOCRTextRgnInfo** aTextRgn, RecogProgress aFuncRecogProgress); |
|
108 typedef TInt (*TLibFuncRecognizeSpecialRegion)(const CFbsBitmap* aImage, TRegionInfo aRegionInfo, TOCRTextRgnInfo** aTextRgn, RecogProgress aFuncRecogProgress); |
|
109 |
|
110 // CLASS DECLARATION |
|
111 |
|
112 /** |
|
113 * Thread for Ocr process |
|
114 * |
|
115 * Definition of the child thread of the engine |
|
116 * |
|
117 * @lib ocrsrv.lib |
|
118 * @since S60 v3.1 |
|
119 */ |
|
120 class EngineThread |
|
121 { |
|
122 public: |
|
123 |
|
124 /** |
|
125 * Thread entry function |
|
126 * @since S60 v3.1 |
|
127 * @param aData Thread parameter |
|
128 * @return KErrNone if no error |
|
129 */ |
|
130 static TInt ThreadFunction(TAny* aData); |
|
131 |
|
132 private: |
|
133 |
|
134 /** |
|
135 * Request Processor |
|
136 * @since S60 v3.1 |
|
137 * @param aShareData Pointer to the shared data |
|
138 * @return None |
|
139 */ |
|
140 static void ProcessRequestL(CShareData* aShareData); |
|
141 |
|
142 /** |
|
143 * Inform main thread that request is completed |
|
144 * @since S60 v3.1 |
|
145 * @param aShareData Pointer to the shared data |
|
146 * @param aCmd A specified command |
|
147 * @param aErrCode An error code |
|
148 * @return None |
|
149 */ |
|
150 static void CompleteRequest(CShareData* aShareData, TEngineCmd aCmd, TInt aErrCode); |
|
151 |
|
152 /** |
|
153 * Reset the vendor engine and release all memory allocated |
|
154 * @since S60 v3.1 |
|
155 * @param aShareData Pointer to the shared data |
|
156 * @param aLibrary A reference to the loaded library |
|
157 * @return None |
|
158 */ |
|
159 static void ResetVendorEngine(CShareData* aShareData, const RLibrary& aLibrary); |
|
160 |
|
161 /** |
|
162 * Get the cancel flag |
|
163 * @since S60 v3.1 |
|
164 * @return ETrue if cancal flag is on; otherwise EFalse |
|
165 */ |
|
166 static TBool GetCancelFlag(); |
|
167 |
|
168 /** |
|
169 * Get the progress information from the engine |
|
170 * @since S60 v3.1 |
|
171 * @param aPercentage A percentage of recognition progress |
|
172 * @return KErrNone if no error |
|
173 */ |
|
174 static TInt RecognizeProgress(TUint aPercentage); |
|
175 |
|
176 /** |
|
177 * Check and convert the engine error to system level error msg |
|
178 * @since S60 v3.1 |
|
179 * @param aError Vendor error code |
|
180 * @return None |
|
181 */ |
|
182 static void CheckError(TInt& aError); |
|
183 |
|
184 /** |
|
185 * Handle engine command |
|
186 * @since S60 v3.1 |
|
187 * @param aLibrary A handle to the engine library |
|
188 * @param aCommand A command to be handled |
|
189 * @param aData Pointer to the shared data |
|
190 * @return None |
|
191 */ |
|
192 static TBool HandleCommandL(const RLibrary& aLibrary, TEngineCmd aCommand, CShareData* aData); |
|
193 |
|
194 /** |
|
195 * Handle engine command - Layout Analysis |
|
196 * @since S60 v3.1 |
|
197 * @param aLibrary A handle to the engine library |
|
198 * @param aCommand A command to be handled |
|
199 * @param aData Pointer to the shared data |
|
200 * @return None |
|
201 */ |
|
202 static void HandleLayoutAnalysis(const RLibrary& aLibrary, CShareData* aData); |
|
203 |
|
204 /** |
|
205 * Handle engine command - Recognition |
|
206 * @since S60 v3.1 |
|
207 * @param aLibrary A handle to the engine library |
|
208 * @param aCommand A command to be handled |
|
209 * @param aData Pointer to the shared data |
|
210 * @return None |
|
211 */ |
|
212 static void HandleRecognition(const RLibrary& aLibrary, CShareData* aData); |
|
213 |
|
214 /** |
|
215 * Handle engine command - Block Recognition |
|
216 * @since S60 v3.1 |
|
217 * @param aLibrary A handle to the engine library |
|
218 * @param aCommand A command to be handled |
|
219 * @param aData Pointer to the shared data |
|
220 * @return None |
|
221 */ |
|
222 static void HandleBlockRecognition(const RLibrary& aLibrary, CShareData* aData); |
|
223 |
|
224 /** |
|
225 * Handle engine command - Special Region Recognition |
|
226 * @since S60 v3.1 |
|
227 * @param aLibrary A handle to the engine library |
|
228 * @param aCommand A command to be handled |
|
229 * @param aData Pointer to the shared data |
|
230 * @return None |
|
231 */ |
|
232 static void HandleSpecialRegionRecognition(const RLibrary& aLibrary, CShareData* aData); |
|
233 |
|
234 /** |
|
235 * Handle engine command - Getting Language |
|
236 * @since S60 v3.1 |
|
237 * @param aLibrary A handle to the engine library |
|
238 * @param aCommand A command to be handled |
|
239 * @param aData Pointer to the shared data |
|
240 * @return None |
|
241 */ |
|
242 static void HandleGettingLanguage(const RLibrary& aLibrary, CShareData* aData); |
|
243 |
|
244 /** |
|
245 * Handle engine command - Setting Language |
|
246 * @since S60 v3.1 |
|
247 * @param aLibrary A handle to the engine library |
|
248 * @param aCommand A command to be handled |
|
249 * @param aData Pointer to the shared data |
|
250 * @return None |
|
251 */ |
|
252 static void HandleSettingLanguage(const RLibrary& aLibrary, CShareData* aData); |
|
253 |
|
254 /** |
|
255 * Handle engine command - Refresh Database |
|
256 * @since S60 v3.1 |
|
257 * @param aLibrary A handle to the engine library |
|
258 * @param aCommand A command to be handled |
|
259 * @param aData Pointer to the shared data |
|
260 * @return None |
|
261 */ |
|
262 static void HandleRefreshDatabase(const RLibrary& aLibrary, CShareData* aData); |
|
263 }; |
|
264 |
|
265 #endif // OCRTHREAD_H |
|
266 |
|
267 // End of File |