@@ -9,6 +9,7 @@ import * as msi from './msi'
99import * as pharmacode from './pharmacode'
1010import { applyAdaptiveThreshold } from './utilities/adaptiveThreshold'
1111import { BARCODE_DECODERS } from './utilities/BARCODE_DECODERS'
12+ import { detectBarcodeRegion , rotateImageData } from './utilities/barcodeDetection'
1213import { combineAllPossible } from './utilities/combineAllPossible'
1314import { getImageDataFromSource } from './utilities/getImageDataFromSource'
1415import { getLines } from './utilities/getLines'
@@ -35,6 +36,8 @@ type JavascriptBarcodeReader = {
3536 options ?: {
3637 useAdaptiveThreshold ?: boolean
3738 singlePass ?: boolean
39+ detectRotation ?: boolean
40+ locateBarcode ?: boolean
3841 }
3942}
4043
@@ -95,10 +98,24 @@ export default async function javascriptBarcodeReader({
9598 }
9699
97100 const useSinglePass = isTestEnv || ( options && options . singlePass ) || false
98- const { data, width, height } = isImageLike ( image ) ? image : await getImageDataFromSource ( image )
101+ const detectRotation = options && options . detectRotation
102+ const locateBarcode = options && options . locateBarcode
103+ let { data, width, height } = isImageLike ( image ) ? image : await getImageDataFromSource ( image )
99104 const channels = data . length / ( width * height )
100105 let finalResult = ''
101106
107+ if ( locateBarcode || detectRotation ) {
108+ const region = detectBarcodeRegion ( data , width , height , channels )
109+ if ( region ) {
110+ if ( detectRotation && region . rotation !== 0 ) {
111+ const rotated = rotateImageData ( data , width , height , region . rotation )
112+ data = rotated . data
113+ width = rotated . width
114+ height = rotated . height
115+ }
116+ }
117+ }
118+
102119 // apply adaptive threshold
103120 if ( options && options . useAdaptiveThreshold ) {
104121 applyAdaptiveThreshold ( data , width , height )
0 commit comments