Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | 16x 16x 16x 235x 470x 470x 470x 470x 470x 470x 235x 235x 232x 232x 232x 232x 232x 232x 232x 16x 192x 192x 28x 192x 192x 3x 192x 192x 192x 16x 9x 4x 5x 4x 4x 1x 16x 4757x 16x 251x 16x 12x 16x 2x 16x 1x 1x 16x 2x 16x 1x 1x 16x 294x 16x 1x 1x 16x 5x 16x 72x 72x 16x 3x 16x 2x 2x 16x 3x 16x 2x 2x 16x 3x 2x 1x 16x 2x 2x 16x 68x 66x 4x 62x 2x 16x 248x 248x 4x 244x 244x 12x 232x 16x 263x 195x 68x 257x 16x | import { Barcode } from "./barcode"; import { SearchArea } from "./searchArea"; import { SymbologySettings } from "./symbologySettings"; /** * @hidden */ type SymbologyParameter = Barcode.Symbology | Barcode.Symbology[] | Set<Barcode.Symbology>; /** * A configuration object for scanning options. * * Modified ScanSettings need to be applied to a scanner via * [[BarcodePicker.applyScanSettings]] or [[Scanner.applyScanSettings]] to take effect. */ export class ScanSettings { private readonly symbologySettings: Map<Barcode.Symbology, SymbologySettings>; private readonly properties: Map<string, number>; private codeDuplicateFilter: number; private maxNumberOfCodesPerFrame: number; private baseSearchArea: SearchArea; private searchArea: SearchArea; private gpuAcceleration: boolean; private blurryRecognition: boolean; /** * Create a ScanSettings instance. * * @param enabledSymbologies <div class="tsd-signature-symbol">Default = []</div> * The single symbology or list/set of symbologies that should be initialized as enabled for recognition. * @param codeDuplicateFilter <div class="tsd-signature-symbol">Default = 0</div> * The duplicate filter specifying how often a code can be scanned. * When the filter is set to -1, each unique code is only scanned once. When set to 0, * duplicate filtering is disabled. Otherwise the duplicate filter specifies an interval in milliseconds. * When the same code (data/symbology) is scanned within the specified interval it is filtered out as a duplicate. * @param maxNumberOfCodesPerFrame <div class="tsd-signature-symbol">Default = 1</div> * The maximum number of barcodes to be recognized every frame. * @param searchArea <div class="tsd-signature-symbol">Default = { x: 0, y: 0, width: 1.0, height: 1.0 }</div> * The area of the image in which barcodes are searched. * @param gpuAcceleration <div class="tsd-signature-symbol">Default = true</div> * Whether to enable/disable GPU support via WebGL, to provide faster and more accurate barcode localization. * The GPU can and will be used only if the browser also supports the needed technologies * ([WebGL](https://caniuse.com/#feat=webgl) and [OffscreenCanvas](https://caniuse.com/#feat=offscreencanvas)). * @param blurryRecognition <div class="tsd-signature-symbol">Default = true</div> * Whether to enable/disable blurry recognition, to allow accurate scanning capabilities for out-of-focus (1D) codes. * If enabled, more advanced algorithms are executed (and more resources/time is spent) every frame in order * to successfully decode/scan difficult codes. */ constructor({ enabledSymbologies = [], codeDuplicateFilter = 0, maxNumberOfCodesPerFrame = 1, searchArea = { x: 0, y: 0, width: 1.0, height: 1.0 }, gpuAcceleration = true, blurryRecognition = true, }: { enabledSymbologies?: SymbologyParameter; codeDuplicateFilter?: number; maxNumberOfCodesPerFrame?: number; searchArea?: SearchArea; gpuAcceleration?: boolean; blurryRecognition?: boolean; } = {}) { this.symbologySettings = new Map<Barcode.Symbology, SymbologySettings>(); this.enableSymbologies(enabledSymbologies); this.codeDuplicateFilter = codeDuplicateFilter; this.maxNumberOfCodesPerFrame = maxNumberOfCodesPerFrame; this.baseSearchArea = { x: 0, y: 0, width: 1.0, height: 1.0 }; this.searchArea = searchArea; this.gpuAcceleration = gpuAcceleration; this.blurryRecognition = blurryRecognition; this.properties = new Map<string, number>(); } /** * @returns The configuration object as a JSON string. */ public toJSONString(): string { const symbologies: { [jsonSymbologyName: string]: SymbologySettings } = {}; this.symbologySettings.forEach((symbologySettings, symbology) => { symbologies[Barcode.Symbology.toJSONName(symbology)] = symbologySettings; }); const properties: { [key: string]: number } = {}; this.properties.forEach((value, key) => { properties[key] = value; }); const combinedSearchArea: SearchArea = { x: Math.min(1, this.baseSearchArea.x + this.searchArea.x * this.baseSearchArea.width), y: Math.min(1, this.baseSearchArea.y + this.searchArea.y * this.baseSearchArea.height), width: Math.min(1, this.baseSearchArea.width * this.searchArea.width), height: Math.min(1, this.baseSearchArea.height * this.searchArea.height), }; const isFullSearchArea: boolean = Math.round(combinedSearchArea.x * 100) === 0 && Math.round(combinedSearchArea.y * 100) === 0 && Math.round(combinedSearchArea.width * 100) === 100 && Math.round(combinedSearchArea.height * 100) === 100; return JSON.stringify({ symbologies, codeDuplicateFilter: this.codeDuplicateFilter, maxNumberOfCodesPerFrame: this.maxNumberOfCodesPerFrame, searchArea: combinedSearchArea, codeLocation1d: isFullSearchArea ? undefined : { area: { x: combinedSearchArea.x, y: combinedSearchArea.y + (combinedSearchArea.height * 0.75) / 2, width: combinedSearchArea.width, height: combinedSearchArea.height * 0.25, }, }, codeLocation2d: isFullSearchArea ? undefined : { area: combinedSearchArea, }, gpuAcceleration: this.gpuAcceleration, blurryRecognition: this.blurryRecognition, properties, }); } /** * Get the configuration object for a symbology (which can then be modified). * * @param symbology The symbology for which to retrieve the configuration. * @returns The symbology configuration object for the specified symbology. */ public getSymbologySettings(symbology: Barcode.Symbology): SymbologySettings { if (this.symbologySettings.has(symbology)) { return <SymbologySettings>this.symbologySettings.get(symbology); } else { if (symbology in Barcode.Symbology || Object.values(Barcode.Symbology).includes(symbology)) { this.symbologySettings.set(symbology, new SymbologySettings(symbology)); return <SymbologySettings>this.symbologySettings.get(symbology); } else { throw new TypeError(`Invalid symbology "${symbology}"`); } } } /** * Get the recognition enabled status for a symbology. * * @param symbology The symbology for which to retrieve the recognition enabled status. * @returns Whether the symbology enabled for recognition. */ public isSymbologyEnabled(symbology: Barcode.Symbology): boolean { return ( this.symbologySettings.has(symbology) && (<SymbologySettings>this.symbologySettings.get(symbology)).isEnabled() ); } /** * Enable recognition of a symbology or list/set of symbologies. * * @param symbology The single symbology or list/set of symbologies to enable. * @returns The updated [[ScanSettings]] object. */ public enableSymbologies(symbology: SymbologyParameter): ScanSettings { return this.setSymbologiesEnabled(symbology, true); } /** * Disable recognition of a symbology or list/set of symbologies. * * @param symbology The single symbology or list/set of symbologies to disable. * @returns The updated [[ScanSettings]] object. */ public disableSymbologies(symbology: SymbologyParameter): ScanSettings { return this.setSymbologiesEnabled(symbology, false); } /** * When the filter is set to -1, each unique code is only scanned once. When set to 0, * duplicate filtering is disabled. Otherwise the duplicate filter specifies an interval in milliseconds. * * @returns The code duplicate filter value. */ public getCodeDuplicateFilter(): number { return this.codeDuplicateFilter; } /** * Set the code duplicate filter value. * * When the filter is set to -1, each unique code is only scanned once. When set to 0, * duplicate filtering is disabled. Otherwise the duplicate filter specifies an interval in milliseconds. * * @param durationMilliseconds The new value (-1, 0, or positive integer). * @returns The updated [[ScanSettings]] object. */ public setCodeDuplicateFilter(durationMilliseconds: number): ScanSettings { this.codeDuplicateFilter = durationMilliseconds; return this; } /** * @returns The maximum number of barcodes to be recognized every frame. */ public getMaxNumberOfCodesPerFrame(): number { return this.maxNumberOfCodesPerFrame; } /** * Set the maximum number of barcodes to be recognized every frame. * * @param limit The new value (non-zero positive integer). * @returns The updated [[ScanSettings]] object. */ public setMaxNumberOfCodesPerFrame(limit: number): ScanSettings { this.maxNumberOfCodesPerFrame = limit; return this; } /** * @returns The area of the image in which barcodes are searched. */ public getSearchArea(): SearchArea { return this.searchArea; } /** * Set the area of the image in which barcodes are searched. * * @param searchArea The new search area. * @returns The updated [[ScanSettings]] object. */ public setSearchArea(searchArea: SearchArea): ScanSettings { this.searchArea = searchArea; return this; } /** * @hidden * * @returns The base area of the image in which barcodes are searched. */ public getBaseSearchArea(): SearchArea { return this.baseSearchArea; } /** * @hidden * * Set the base area of the image in which barcodes are searched, this is set automatically by a [[BarcodePicker]] * and is combined with the searchArea to obtain the final combined search area. * * @param baseSearchArea The new base search area. * @returns The updated [[ScanSettings]] object. */ public setBaseSearchArea(baseSearchArea: SearchArea): ScanSettings { this.baseSearchArea = baseSearchArea; return this; } /** * @returns Whether GPU acceleration is configured to be enabled ot not. * * Note that this refers to the settings: depending on browser capabilities the actual GPU usage might be prevented. */ public isGpuAccelerationEnabled(): boolean { return this.gpuAcceleration; } /** * Enable or disable GPU acceleration. * * Provide faster and more accurate barcode localization. * The GPU can and will be used only if the browser also supports the needed technologies * ([WebGL](https://caniuse.com/#feat=webgl) and [OffscreenCanvas](https://caniuse.com/#feat=offscreencanvas)). * * @param enabled Whether to enable or disable GPU acceleration. * @returns The updated [[ScanSettings]] object. */ public setGpuAccelerationEnabled(enabled: boolean): ScanSettings { this.gpuAcceleration = enabled; return this; } /** * @returns Whether blurry recognition is configured to be enabled ot not. */ public isBlurryRecognitionEnabled(): boolean { return this.blurryRecognition; } /** * Enable or disable blurry recognition. * * Allow accurate scanning capabilities for out-of-focus (1D) codes. * If enabled, more advanced algorithms are executed (and more resources/time is spent) every frame in order * to successfully decode/scan difficult codes. * * @param enabled Whether to enable or disable blurry recognition. * @returns The updated [[ScanSettings]] object. */ public setBlurryRecognitionEnabled(enabled: boolean): ScanSettings { this.blurryRecognition = enabled; return this; } /** * Get a Scandit Engine library property. * * This function is for internal use only and any functionality that can be accessed through it can and will vanish * without public notice from one version to the next. Do not call this function unless you specifically have to. * * @param key The property name. * @returns The property value. For properties not previously set, -1 is returned. */ public getProperty(key: string): number { if (this.properties.has(key)) { return <number>this.properties.get(key); } return -1; } /** * Set a Scandit Engine library property. * * This function is for internal use only and any functionality that can be accessed through it can and will vanish * without public notice from one version to the next. Do not call this function unless you specifically have to. * * @param key The property name. * @param value The property value. * @returns The updated [[ScanSettings]] object. */ public setProperty(key: string, value: number): ScanSettings { this.properties.set(key, value); return this; } private setSingleSymbologyEnabled(symbology: Barcode.Symbology, enabled: boolean): void { if (symbology in Barcode.Symbology || Object.values(Barcode.Symbology).includes(symbology)) { if (this.symbologySettings.has(symbology)) { (<SymbologySettings>this.symbologySettings.get(symbology)).setEnabled(enabled); } else { this.symbologySettings.set(symbology, new SymbologySettings(symbology, enabled)); } } else { throw new TypeError(`Invalid symbology "${symbology}"`); } } private setMultipleSymbologiesEnabled( symbology: Barcode.Symbology[] | Set<Barcode.Symbology>, enabled: boolean ): void { for (const s of symbology) { if (!(s in Barcode.Symbology || Object.values(Barcode.Symbology).includes(s))) { throw new TypeError(`Invalid symbology "${s}"`); } } for (const s of symbology) { if (this.symbologySettings.has(s)) { (<SymbologySettings>this.symbologySettings.get(s)).setEnabled(enabled); } else { this.symbologySettings.set(s, new SymbologySettings(s, enabled)); } } } private setSymbologiesEnabled(symbology: SymbologyParameter, enabled: boolean): ScanSettings { if (typeof symbology === "object") { this.setMultipleSymbologiesEnabled(symbology, enabled); } else { this.setSingleSymbologyEnabled(symbology, enabled); } return this; } } |