@@ -85,7 +85,9 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
8585 fn = fn_or_im
8686 file_uris .append (pathlib .Path (fn ).absolute ().as_uri ())
8787
88- cmd = [self .java , '-cp' , self .classpath , self .cls ] + file_uris
88+ cmd = [self .java , '-cp' , self .classpath , self .cls ]
89+ if self .zxing_version_info and self .zxing_version_info >= (3 , 5 , 0 ):
90+ cmd .append ('--raw' )
8991 if try_harder :
9092 cmd .append ('--try_harder' )
9193 if pure_barcode :
@@ -95,6 +97,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod
9597 if possible_formats :
9698 for pf in possible_formats :
9799 cmd += ['--possible_formats' , pf ]
100+ cmd += file_uris
98101
99102 try :
100103 p = sp .Popen (cmd , stdout = sp .PIPE , stderr = sp .STDOUT , universal_newlines = False )
@@ -152,14 +155,15 @@ class CLROutputBlock(Enum):
152155 RAW = 1
153156 PARSED = 2
154157 POINTS = 3
158+ RAW_BITS = 4
155159
156160
157161class BarCode (object ):
158162 @classmethod
159163 def parse (cls , zxing_output ):
160164 block = CLROutputBlock .UNKNOWN
161165 uri = format = type = None
162- raw = parsed = b''
166+ raw = parsed = raw_bits = b''
163167 points = []
164168
165169 for l in zxing_output .splitlines (True ):
@@ -177,25 +181,34 @@ def parse(cls, zxing_output):
177181 else :
178182 raw += l
179183 elif block == CLROutputBlock .PARSED :
180- if re .match (rb"Found\s+\d+\s+result\s+points?" , l ):
184+ if l .startswith (b"Raw bits:" ):
185+ block = CLROutputBlock .RAW_BITS
186+ elif re .match (rb"Found\s+\d+\s+result\s+points?" , l ):
181187 block = CLROutputBlock .POINTS
182188 else :
183189 parsed += l
190+ elif block == CLROutputBlock .RAW_BITS :
191+ if re .match (rb"Found\s+\d+\s+result\s+points?" , l ):
192+ block = CLROutputBlock .POINTS
193+ else :
194+ raw_bits += l
184195 elif block == CLROutputBlock .POINTS :
185196 m = re .match (rb"\s*Point\s*\d+:\s*\(([\d.]+),([\d.]+)\)" , l )
186197 if m :
187198 points .append ((float (m .group (1 )), float (m .group (2 ))))
188199
189- raw = raw [:- 1 ].decode ()
190200 parsed = parsed [:- 1 ].decode ()
191- return cls (uri , format , type , raw , parsed , points )
201+ raw = raw [:- 1 ].decode ()
202+ raw_bits = bytes .fromhex (raw_bits [:- 1 ].decode ())
203+ return cls (uri , format , type , raw , parsed , raw_bits , points )
192204
193205 def __bool__ (self ):
194206 return bool (self .raw )
195207
196- def __init__ (self , uri , format = None , type = None , raw = None , parsed = None , points = None ):
208+ def __init__ (self , uri , format = None , type = None , raw = None , parsed = None , raw_bits = None , points = None ):
197209 self .raw = raw
198210 self .parsed = parsed
211+ self .raw_bits = raw_bits
199212 self .uri = uri
200213 self .format = format
201214 self .type = type
@@ -209,7 +222,7 @@ def path(self):
209222 pass
210223
211224 def __repr__ (self ):
212- return '{}(raw={!r}, parsed={!r}, {}={!r}, format={!r}, type={!r}, points={!r})' .format (
213- self .__class__ .__name__ , self .raw , self .parsed ,
225+ return '{}(raw={!r}, parsed={!r}, raw_bits={!r:x}, {}={!r}, format={!r}, type={!r}, points={!r})' .format (
226+ self .__class__ .__name__ , self .raw , self .parsed , self . raw_bits ,
214227 'path' if self .path else 'uri' , self .path or self .uri ,
215228 self .format , self .type , self .points )
0 commit comments