@@ -89,37 +89,16 @@ function initCanvas() {
89
89
if ( _config . useWorker || typeof document === 'undefined' ) {
90
90
return ;
91
91
}
92
-
93
- try {
94
- _canvasContainer . dom . binary = document . createElement ( 'canvas' ) ;
95
- _canvasContainer . dom . binary . className = 'binaryBuffer' ;
96
- if ( ENV . development && _config . debug . showCanvas === true ) {
97
- const debugElement = document . querySelector ( '#debug' ) ;
98
- if ( debugElement ) {
99
- debugElement . appendChild ( _canvasContainer . dom . binary ) ;
100
- }
101
- }
102
- const willReadFrequently = ! ! _config . willReadFrequently ;
103
- console . warn ( '* initCanvas willReadFrequently' , willReadFrequently , _config ) ;
104
- _canvasContainer . ctx . binary = _canvasContainer . dom . binary . getContext ( '2d' , { willReadFrequently } ) ;
105
-
106
- // Test if canvas context is working by trying a basic operation
107
- if ( _canvasContainer . ctx . binary ) {
108
- _canvasContainer . ctx . binary . fillStyle = 'black' ;
109
- } else {
110
- console . warn ( '* Canvas context creation failed - likely headless environment issue' ) ;
111
- }
112
- } catch ( error ) {
113
- console . warn ( '* Canvas creation failed in headless environment:' , error ) ;
114
- // Gracefully continue without canvas - barcode detection can still work without debug canvas
115
- _canvasContainer . dom . binary = null ;
116
- _canvasContainer . ctx . binary = null ;
117
- }
118
-
119
- if ( _canvasContainer . dom . binary ) {
120
- _canvasContainer . dom . binary . width = _binaryImageWrapper . size . x ;
121
- _canvasContainer . dom . binary . height = _binaryImageWrapper . size . y ;
92
+ _canvasContainer . dom . binary = document . createElement ( 'canvas' ) ;
93
+ _canvasContainer . dom . binary . className = 'binaryBuffer' ;
94
+ if ( ENV . development && _config . debug . showCanvas === true ) {
95
+ document . querySelector ( '#debug' ) . appendChild ( _canvasContainer . dom . binary ) ;
122
96
}
97
+ const willReadFrequently = ! ! _config . willReadFrequently ;
98
+ console . warn ( '* initCanvas willReadFrequently' , willReadFrequently , _config ) ;
99
+ _canvasContainer . ctx . binary = _canvasContainer . dom . binary . getContext ( '2d' , { willReadFrequently } ) ;
100
+ _canvasContainer . dom . binary . width = _binaryImageWrapper . size . x ;
101
+ _canvasContainer . dom . binary . height = _binaryImageWrapper . size . y ;
123
102
}
124
103
125
104
/**
@@ -144,7 +123,7 @@ function boxFromPatches(patches) {
144
123
for ( i = 0 ; i < patches . length ; i ++ ) {
145
124
patch = patches [ i ] ;
146
125
overAvg += patch . rad ;
147
- if ( ENV . development && _config . debug . showPatches && _canvasContainer . ctx . binary ) {
126
+ if ( ENV . development && _config . debug . showPatches ) {
148
127
ImageDebug . drawRect ( patch . pos , _subImageWrapper . size , _canvasContainer . ctx . binary , { color : 'red' } ) ;
149
128
}
150
129
}
@@ -165,7 +144,7 @@ function boxFromPatches(patches) {
165
144
vec2 . transformMat2 ( patch . box [ j ] , patch . box [ j ] , transMat ) ;
166
145
}
167
146
168
- if ( ENV . development && _config . debug . boxFromPatches . showTransformed && _canvasContainer . ctx . binary ) {
147
+ if ( ENV . development && _config . debug . boxFromPatches . showTransformed ) {
169
148
ImageDebug . drawPath ( patch . box , { x : 0 , y : 1 } , _canvasContainer . ctx . binary , { color : '#99ff00' , lineWidth : 2 } ) ;
170
149
}
171
150
}
@@ -191,7 +170,7 @@ function boxFromPatches(patches) {
191
170
192
171
box = [ [ minx , miny ] , [ maxx , miny ] , [ maxx , maxy ] , [ minx , maxy ] ] ;
193
172
194
- if ( ENV . development && _config . debug . boxFromPatches . showTransformedBox && _canvasContainer . ctx . binary ) {
173
+ if ( ENV . development && _config . debug . boxFromPatches . showTransformedBox ) {
195
174
ImageDebug . drawPath ( box , { x : 0 , y : 1 } , _canvasContainer . ctx . binary , { color : '#ff0000' , lineWidth : 2 } ) ;
196
175
}
197
176
@@ -219,7 +198,7 @@ function boxFromPatches(patches) {
219
198
function binarizeImage ( ) {
220
199
otsuThreshold ( _currentImageWrapper , _binaryImageWrapper ) ;
221
200
_binaryImageWrapper . zeroBorder ( ) ;
222
- if ( ENV . development && _config . debug . showCanvas && _canvasContainer . dom . binary ) {
201
+ if ( ENV . development && _config . debug . showCanvas ) {
223
202
_binaryImageWrapper . show ( _canvasContainer . dom . binary , 255 ) ;
224
203
}
225
204
}
0 commit comments