It is currently Thu Sep 24, 2020 3:07 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: ZBAR examples
PostPosted: Wed Apr 03, 2019 1:04 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
Hi,

Anybody got working code of using zbar from PB.

Obviously I can call ZBARCAM from within PB using runprogram, but i'm strugling on how you pipe the value of the barcode / qrcode back to PB.

Failing that, has anybody got a working example of reading barcodes / qrcodes ?

Cheers


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 3:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
so a little experimentation :

Code:
prog_id.i = RunProgram("zbarcam.exe", "", "C:\Program Files (x86)\ZBar\bin\")


works as expected but if i try to pipe anything back using :

Code:
p.i = RunProgram("zbarcam.exe", "", "C:\Program Files (x86)\ZBar\bin\", #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

Debug P

If p

  While ProgramRunning(p)
    If AvailableProgramOutput(p)
        o$+ReadProgramString(p)+#CRLF$
    EndIf
    err$ = ReadProgramError(p)
    If err$
        o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend

  CloseProgram(p)

  Debug o$
EndIf


The program doesn't even run ( by which i mean runprogram returns 0 )

Any ideas ?


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 4:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
This does run, but returns no output

Code:
p.i = RunProgram("zbarimg.exe", "-d " + Chr(34) + "C:\Program Files (x86)\ZBar\examples\barcode.png" + Chr(34), "C:\Program Files (x86)\ZBar\bin\", #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

Debug P

If p

  While ProgramRunning(p)
    If AvailableProgramOutput(p)
        o$+ReadProgramString(p)+#CRLF$
    EndIf
    err$ = ReadProgramError(p)
    If err$
        o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend

  CloseProgram(p)

  Debug o$
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 4:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
Finaly.

Code:
p.i = RunProgram("C:\Windows\System32\cmd.exe", "/C "  + Chr(34) + "C:\Program Files (x86)\ZBar\bin\zbarcam.exe" + Chr(34), "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

Debug P

If p

  While ProgramRunning(p)
    If AvailableProgramOutput(p)
        o$+ReadProgramString(p)+#CRLF$
    EndIf
    err$ = ReadProgramError(p)
    If err$
        o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend

  CloseProgram(p)

  Debug o$
EndIf


This works except there is no real time output, you have to close the cmd window to get any of the output so you have no clue if a read has been successful.


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 4:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
nevermind - forgot to move my debug into the loop :oops:


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 4:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
OK final problem, on a sucsessful read this should close the runprogram, but it doesnt.

Anybody know why this doesnt close as expected ?

Code:
p.i = RunProgram("C:\Windows\System32\cmd.exe", "/C "  + Chr(34) + "C:\Program Files (x86)\ZBar\bin\zbarcam.exe" + Chr(34), "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

Debug P

If p

  While ProgramRunning(p)
    If AvailableProgramOutput(p)
      o$+ReadProgramString(p)+#CRLF$
      Debug o$
      KillProgram(p)
      Delay(3000)
      End
    EndIf
    err$ = ReadProgramError(p)
    If err$
        o$+"<ERR> " + err$ +#CRLF$
    EndIf
  Wend

  CloseProgram(p)

  Debug o$
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 4:57 pm 
Offline
Addict
Addict

Joined: Sat Feb 08, 2014 3:26 pm
Posts: 924
This works.
Code:
Compiler  = RunProgram("C:\Program Files (x86)\ZBar\bin\zbarcam.exe",
                       "",
                       "C:\Program Files (x86)\ZBar\bin\",
                       #PB_Program_Open|#PB_Program_Read|#PB_Program_Error)

Debug "Waiting..."

If Compiler
    While ProgramRunning(Compiler)
        If AvailableProgramOutput(Compiler)
            Output$ + ReadProgramString(Compiler) + Chr(13)
            Debug Output$
            KillProgram(Compiler)
            Debug "Done"
            End
        EndIf
    Wend
EndIf
For RunProgram(), always use the full path for program or do a SetCurrentDirectory() first.
The second parameter (working directory) is not necessarily the launch directory, that's why your first version doesn't work.

:wink:

_________________
(English is not my native language, I use an online translator.)


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Wed Apr 03, 2019 5:43 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4928
Location: Germany
I wrote a wrapper so I can use it inside PB:
Code:
;-demo
CompilerIf #PB_Compiler_IsMainFile
 
 
  Procedure get_data(Filename$, *width, *height, *raw)
   
    Protected ColourByte.a
    Protected.i img, Width, Height, x, y, Ptr, Colour
    Protected *Buffer
   
    img = LoadImage(#PB_Any, Filename$)
    If img
      Width = ImageWidth(img)
      Height = ImageHeight(img)
      *Buffer = AllocateMemory(Width * Height)
      If *Buffer
        StartDrawing(ImageOutput(img))
       
        For y = 0 To Height - 1
          For x = 0 To Width - 1
            Colour = Point(x, y)
            ColourByte = (Colour & $E00000) >> 16 | (Colour & $E000) >> 11 | (Colour & $C0) >> 6
           
;             Debug Hex((Colour & $E00000) >> 16)
;             Debug Hex((Colour & $E000) >> 11)
;             
;             Debug Hex(Colour) + " -> " + Hex(ColourByte)
            PokeA(*Buffer + Ptr, ColourByte)
            Ptr + 1
          Next x
        Next y
       
        StopDrawing()
       
        PokeI(*raw, *Buffer)
        PokeI(*width, Width)
        PokeI(*height, Height)
      EndIf
      FreeImage(img)
    EndIf
   
  EndProcedure
 
 
 
 
  Define Filename$, CodeTyp$, Code$
  Define.l Major, Minor
  Define *scanner
  Define width.i, height.i, *raw
  Define *image.zbar_image_s
  Define n.i, *symbol.zbar_symbol_s, typ.i, *data
 
 
  Filename$ = OpenFileRequester("Choose a bmp with code inside", "", "*.bmp|*.bmp", 0)
  If Filename$
    If ZBar_Init()
     
      ;zbar_version(@Major, @Minor)
      ;Debug "Version: " + Str(Major) + "." + Str(Minor)
     
      ; create a reader
      *scanner = zbar_image_scanner_create()
     
      ; configure the reader
      If zbar_image_scanner_set_config(*scanner, 0, #ZBAR_CFG_ENABLE, 1) <> 0
        Debug "Error: zbar_image_scanner_set_config"
      EndIf
     
      ; obtain image data
      get_data(Filename$, @width, @height, @*raw)
      ;Debug Str(width) + " x " + Str(height) + " @ " + Str(*raw)
     
      ; wrap image data
      *image = zbar_image_create()
      zbar_image_set_format(*image, #Format_Y800)
      zbar_image_set_size(*image, width, height)
      zbar_image_set_data(*image, *raw, width * height, zbar_image_free_data)
     
;       Debug zbar_image_get_width(*image)
;       Debug zbar_image_get_height(*image)
;       Debug Hex(zbar_image_get_format(*image))
     
      ; scan the image For barcodes
      n = zbar_scan_image(*scanner, *image)
      If n = -1
        Debug "Error: zbar_scan_image"
      EndIf
     
      ;extract results
      *symbol = zbar_image_first_symbol(*image)
      While *symbol
        typ = zbar_symbol_get_type(*symbol)
        *data = zbar_symbol_get_data(*symbol)
        CodeTyp$ = PeekS(zbar_get_symbol_name(typ))
        Code$ = PeekS(*Data)
       
        Debug CodeTyp$
        Debug Code$
       
        *symbol = zbar_symbol_next(*symbol)
      Wend
     
      ;clean up
      zbar_image_destroy(*image)
     
    EndIf
  EndIf
 
CompilerEndIf


I also wrote a wrapper for a WebCam :mrgreen:


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Thu Apr 04, 2019 8:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Oct 06, 2006 3:57 pm
Posts: 564
Location: England
Thanks for the help, woorks perfectly now.

Couldn't figure the last be it out at all :oops:


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Thu Apr 04, 2019 12:19 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jan 20, 2014 6:32 pm
Posts: 243
infratec wrote:
I wrote a wrapper so I can use it inside PB:

I also wrote a wrapper for a WebCam :mrgreen:



What do need to make your code work?

I get error on these
Define *image.zbar_image_s
Define n.i, *symbol.zbar_symbol_s, typ.i, *data

Thanks

_________________
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Thu Apr 04, 2019 4:12 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4928
Location: Germany
As I wrote: You need a wrapper for the ZBar dll

After talking to my boss, I'm allowed to post it:
Code:
CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf

#ENABLE_EAN = #True
#ENABLE_I25 = #True
#ENABLE_CODE39 = #True
#ENABLE_CODE128 = #True
#ENABLE_PDF417 = #True
#ENABLE_QRCODE = #True

#NO_STATS = #False

Enumeration zbar_color_e
  #ZBAR_SPACE = 0    ; light area Or space between bars
  #ZBAR_BAR = 1      ; dark area Or colored bar segment
EndEnumeration


Enumeration zbar_symbol_type_e
  #ZBAR_NONE      =      0  ; no symbol decoded
  #ZBAR_PARTIAL   =      1  ; intermediate status
  #ZBAR_EAN8      =      8  ; EAN-8
  #ZBAR_UPCE      =      9  ; UPC-E
  #ZBAR_ISBN10    =     10  ; ISBN-10 (from EAN-13). @since 0.4
  #ZBAR_UPCA      =     12  ; UPC-A
  #ZBAR_EAN13     =     13  ; EAN-13
  #ZBAR_ISBN13    =     14  ; ISBN-13 (from EAN-13). @since 0.4
  #ZBAR_I25       =     25  ; Interleaved 2 of 5. @since 0.4
  #ZBAR_CODE39    =     39  ; Code 39. @since 0.4
  #ZBAR_PDF417    =     57  ; PDF417. @since 0.6
  #ZBAR_QRCODE    =     64  ; QR Code. @since 0.10
  #ZBAR_CODE128   =    128  ; Code 128
  #ZBAR_SYMBOL    =  $00ff  ; mask For base symbol type
  #ZBAR_ADDON2    =  $0200  ; 2-digit add-on flag
  #ZBAR_ADDON5    =  $0500  ; 5-digit add-on flag
  #ZBAR_ADDON     =  $0700  ; add-on flag mask
EndEnumeration


Enumeration zbar_error_e
  #ZBAR_OK                  ; no error
  #ZBAR_ERR_NOMEM           ; out of memory
  #ZBAR_ERR_INTERNAL        ; internal library error
  #ZBAR_ERR_UNSUPPORTED     ; unsupported request
  #ZBAR_ERR_INVALID         ; invalid request
  #ZBAR_ERR_SYSTEM          ; system error
  #ZBAR_ERR_LOCKING         ; locking error
  #ZBAR_ERR_BUSY            ; all resources busy
  #ZBAR_ERR_XDISPLAY        ; X11 display error
  #ZBAR_ERR_XPROTO          ; X11 protocol error
  #ZBAR_ERR_CLOSED          ; output window is closed
  #ZBAR_ERR_WINAPI          ; windows system error
  #ZBAR_ERR_NUM             ; number of error codes
EndEnumeration


Enumeration zbar_config_e
  #ZBAR_CFG_ENABLE          ; enable symbology/feature
  #ZBAR_CFG_ADD_CHECK       ; enable check digit when optional
  #ZBAR_CFG_EMIT_CHECK      ; Return check digit when present
  #ZBAR_CFG_ASCII           ; enable full ASCII character set
  #ZBAR_CFG_NUM             ; number of boolean decoder configs
 
  #ZBAR_CFG_MIN_LEN = $20   ; minimum Data length For valid decode
  #ZBAR_CFG_MAX_LEN         ; maximum Data length For valid decode
 
  #ZBAR_CFG_POSITION = $80  ; enable scanner To collect position Data
 
  #ZBAR_CFG_X_DENSITY = $100; image scanner vertical scan density
  #ZBAR_CFG_Y_DENSITY       ; image scanner horizontal scan density
EndEnumeration


#Format_Y800 = $30303859
#Format_Gray = $59455247



 


Structure point_s Align #PB_Structure_AlignC
  x.l
  y.l
EndStructure


Structure zbar_symbol_set_s Align #PB_Structure_AlignC
  refcnt.l
  nsyms.l         ; number of filtered symbols
  *head           ; first of decoded symbol results
  *tail           ; last of unfiltered symbol results
EndStructure


Structure zbar_symbol_s Align #PB_Structure_AlignC
  type.l          ; symbol type
  data_alloc.l    ; allocation size of data
  datalen.l       ; length of binary symbol data
  *Data           ; symbol data
  pts_alloc.l     ; allocation size of pts
  npts.l          ; number of points in location polygon
  *pts.point_s    ; list of points in location polygon
  refcnt.l        ; reference count
  *Next           ; linked list of results (or siblings)
  *syms.zbar_symbol_set_s ; components of composite result
  time.l          ; relative symbol capture time
  cache_count.l   ; cache state
  quality.l       ; relative symbol reliability metric
EndStructure



#STATE_ADDON = $40  ; scanning add-on
#STATE_IDX = $1f    ; element offset into symbol

Structure ean_pass_s Align #PB_Structure_AlignC
  state.b         ; module position of w[idx] in symbol
  raw.a[7]        ; decode in process
EndStructure



Structure ean_decoder_s Align #PB_Structure_AlignC
  pass.ean_pass_s[4]  ; state of each parallel decode attempt
  left.l          ; current holding buffer contents
  right.l
  addon.l
  s4.l            ; character width
  buf.b[18]       ; holding buffer

  enable.b
  ean13_config.l
  ean8_config.l
  upca_config.l
  upce_config.l
  isbn10_config.l
  isbn13_config.l
EndStructure


#NUM_CFGS = (#ZBAR_CFG_MAX_LEN - #ZBAR_CFG_MIN_LEN + 1)
 


Structure i25_decoder_s Align #PB_Structure_AlignC
  BitField.l
  ;unsigned direction : 1; scan direction: 0=fwd/space, 1=rev/bar
  ;unsigned element : 4; element offset 0-8
  ;int character : 12; character position in symbol
  s10.l           ; current character width
  width.l         ; last character width

  config.l
  configs.l[#NUM_CFGS]  ; int valued configurations
EndStructure



Structure code39_decoder_s Align #PB_Structure_AlignC
  BitField.l
  ;unsigned direction : 1; scan direction: 0=fwd, 1=rev
  ;unsigned element : 4; element offset 0-8
  ;int character : 12; character position in symbol
  s9.l            ; current character width
  width.l         ; last character width

  config.l
  configs.l[#NUM_CFGS]  ; int valued configurations
EndStructure



Structure code128_decoder_s Align #PB_Structure_AlignC
  BitField.l
  ;unsigned direction : 1; scan direction: 0=fwd/space, 1=rev/bar
  ;unsigned element : 3; element offset 0-5
  ;int character : 12; character position in symbol
  s6.l            ; character width
 
  config.l
  configs.l[#NUM_CFGS]  ; int valued configurations
EndStructure



Structure pdf417_decoder_s Align #PB_Structure_AlignC
  BitField.l
  ;unsigned direction : 1; scan direction: 0=fwd/space, 1=rev/bar
  ;unsigned element : 3; element offset 0-7
  ;int character : 12; character position in symbol
  s8.l           ; character width
 
  config.l
  configs.l[#NUM_CFGS]  ; int valued configurations
EndStructure



Structure qr_finder_line Align #PB_Structure_AlignC
  ;The location of the upper/left endpoint of the line.
  ;The left/upper edge of the center section is used, since other lines must
  ;cross in this region.
  pos.l[2]
  ;The length of the center section.
  ;This extends To the right/bottom of the center section, since other lines
  ;must cross in this region.
  len.l
  ;The offset To the midpoint of the upper/left section (part of the outside
  ;ring), Or 0 If we couldn't identify the edge of the beginning section.
  ;We use the midpoint instead of the edge because it can be located more
  ;reliably.
  boffs.l
  ;The offset To the midpoint of the End section (part of the outside ring),
  ;Or 0 If we couldn't identify the edge of the end section.
  ;We use the midpoint instead of the edge because it can be located more
  ;reliably.
  eoffs.l
EndStructure


Structure qr_finder_s Align #PB_Structure_AlignC
  s5.l            ; finder pattern width
  line.qr_finder_line ; position info needed by decoder

  config.l
EndStructure



#DECODE_WINDOW = 16


Structure zbar_decoder_s Align #PB_Structure_AlignC
  idx.a           ; current width index
  w.l[#DECODE_WINDOW];          window of last N bar widths
  type.l          ; type of last decoded data
  lock.l          ; buffer lock
 
  ; everything above here is automatically reset
  buf_alloc.l     ; dynamic buffer allocation
  buflen.l        ; binary data length
  *buf            ; decoded characters
  *userdata       ; application data
  *handler        ; application callback

  ; symbology specific state
CompilerIf #ENABLE_EAN
  ean.ean_decoder_s         ; EAN/UPC parallel decode attempts
CompilerEndIf
CompilerIf #ENABLE_I25
  i25.i25_decoder_s         ; Interleaved 2 of 5 decode state
CompilerEndIf
CompilerIf #ENABLE_CODE39
  code39.code39_decoder_s   ; Code 39 decode state
CompilerEndIf
CompilerIf #ENABLE_CODE128
  code128.code128_decoder_s ; Code 128 decode state
CompilerEndIf
CompilerIf #ENABLE_PDF417
  pdf417.pdf417_decoder_s   ; PDF417 decode state
CompilerEndIf
CompilerIf #ENABLE_QRCODE
  qrf.qr_finder_s           ; QR Code finder state
CompilerEndIf
EndStructure




Structure zbar_scanner_s Align #PB_Structure_AlignC
  *decoder.zbar_decoder_s ; associated bar width decoder
  y1_min_thresh.l ; minimum threshold
  x.l             ; relative scan position of next sample
  y0.l[4]         ; short circular buffer of average intensities
  y1_sign.l       ; slope at last crossing
  y1_thresh.l     ; current slope threshold
  cur_edge.l      ; interpolated position of tracking edge
  last_edge.l     ; interpolated position of last located edge
  width.l         ; last element width
EndStructure


#ISAAC_SZ_LOG = (8)
#ISAAC_SZ = (1<<#ISAAC_SZ_LOG)


Structure isaac_ctx Align #PB_Structure_AlignC
  n.l
  r.l[#ISAAC_SZ]
  m.l[#ISAAC_SZ]
  a.l
  b.l
  c.l
EndStructure


Structure qr_finder_lines Align #PB_Structure_AlignC
  *lines.qr_finder_line
  nlines.l
  clines.l
EndStructure


Structure qr_reader Align #PB_Structure_AlignC
  ;The GF(256) representation used in Reed-Solomon decoding
  ;rs_gf256  gf
  ;The random number generator used by RANSAC.
  isaac.isaac_ctx
  ;current finder state, horizontal And vertical lines
  finder_lines.qr_finder_lines[2]
EndStructure


PrototypeC zbar_image_cleanup_handler(*image)

Structure zbar_image_s Align #PB_Structure_AlignC
  format.l        ; fourcc image format code
  width.l
  height.l        ; image size
  *Data           ; image sample data
  datalen.l       ; allocated/mapped size of data
  *userdata       ; user specified data associated w/image
  cleanup.zbar_image_cleanup_handler        ; cleanup handler
  refcnt.l        ; reference count
  *src            ; originator
  srcidx.l        ; index used by originator
  *Next           ; internal image lists
  seq.l           ; page/frame sequence number
  *syms.zbar_symbol_set_s ; decoded result set
EndStructure




#RECYCLE_BUCKETS = 5
#NUM_SCN_CFGS = (#ZBAR_CFG_Y_DENSITY - #ZBAR_CFG_X_DENSITY + 1)

Structure recycle_bucket_s Align #PB_Structure_AlignC
  nsyms.l
  *head.zbar_symbol_s
EndStructure


Structure zbar_image_scanner_s Align #PB_Structure_AlignC
  *scn.zbar_scanner_s   ; associated linear intensity scanner
  *dcode.zbar_decoder_s ; associated symbol decoder
CompilerIf #ENABLE_QRCODE
  *qr.qr_reader         ; QR Code 2D reader
CompilerEndIf

  *userdata             ; application data
   
  *handler              ; user result callback

  time.l                ; scan start time
  *img.zbar_image_s     ; currently scanning image *root*
  dx.l                  ; current scan direction
  dy.l
  du.l
  umin.l
  v.l
  *syms.zbar_symbol_set_s ; previous decode results
   
  recycle.recycle_bucket_s[#RECYCLE_BUCKETS]  ; recycled symbols in 4^n size buckets

  enable_cache.l          ; current result cache state
  *cache.zbar_symbol_s    ; inter-image result cache entries
 
  config.l                ; config flags
  configs.l[#NUM_SCN_CFGS]; int valued configurations

CompilerIf #NO_STATS
  stat_syms_new.l
  stat_iscn_syms_inuse.l
  stat_iscn_syms_recycle.l
  stat_img_syms_inuse.l
  stat_img_syms_recycle.l
  stat_sym_new.l
  stat_sym_recycle.l[#RECYCLE_BUCKETS];
CompilerEndIf
EndStructure


; retrieve Runtime library version information.
; @param major set To the running major version (unless NULL)
; @param minor set To the running minor version (unless NULL)
; @returns 0
PrototypeC zbar_version(*major, *minor)

; set Global library Debug level.
; @param verbosity desired Debug level.  higher values create more spew
PrototypeC zbar_set_verbosity(verbosity.l)

; increase Global library Debug level.
; eg, For -vvvv
PrototypeC zbar_increase_verbosity()

; retrieve string name For symbol encoding.
; @param sym symbol type encoding
; @returns the Static string name For the specified symbol type,
; Or "UNKNOWN" If the encoding is Not recognized
PrototypeC.i zbar_get_symbol_name(sym.l)

; retrieve string name For addon encoding.
; @param sym symbol type encoding
; @returns Static string name For any addon, Or the empty string
; If no addons were decoded
PrototypeC.i zbar_get_addon_name(sym.l)

; parse a configuration string of the form "[symbology.]config[=value]".
; the config must match one of the recognized names.
; the symbology, If present, must match one of the recognized names.
; If symbology is unspecified, it will be set To 0.
; If value is unspecified it will be set To 1.
; @returns 0 If the config is parsed successfully, 1 otherwise
; @since 0.4
PrototypeC.i zbar_parse_config(*config_string, *symbology, *config, *value)

; @internal type unsafe error API (don't use)
PrototypeC.i _zbar_error_spew(*object, verbosity.l)
PrototypeC.i _zbar_error_string(*object, verbosity.l)
PrototypeC.i _zbar_get_error_code(*object)







PrototypeC.i zbar_decode_width(*decoder, width.l)
PrototypeC.i zbar_decoder_create()
PrototypeC.i zbar_decoder_destroy(*decoder)
PrototypeC.i zbar_decoder_get_color(*decoder)
PrototypeC.i zbar_decoder_get_data(*decoder)
PrototypeC.i zbar_decoder_get_data_length(*decoder)
PrototypeC.i zbar_decoder_get_type(*decoder)
PrototypeC.i zbar_decoder_get_userdata(*decoder)
PrototypeC.i zbar_decoder_new_scan(*decoder)
PrototypeC.i zbar_decoder_reset(*decoder)
PrototypeC.i zbar_decoder_set_config(*decoder, symbology.l, config.l, value.l)
PrototypeC.i zbar_decoder_set_handler(*decoder, *handler)
PrototypeC.i zbar_decoder_set_userdata(*decoder, *userdata)


PrototypeC.i zbar_image_convert(*image.zbar_image_s, format.l)
PrototypeC.i zbar_image_convert_resize(*image.zbar_image_s, format.l, width.l, height.l)
PrototypeC.i zbar_image_copy()
PrototypeC.i zbar_image_create()
PrototypeC.i zbar_image_destroy(*image.zbar_image_s)
PrototypeC.i zbar_image_first_symbol(*image.zbar_image_s)
PrototypeC.i zbar_image_free_data(*image.zbar_image_s)
PrototypeC.i zbar_image_get_data(*image.zbar_image_s)
PrototypeC.i zbar_image_get_data_length(*image.zbar_image_s)
PrototypeC.i zbar_image_get_format(*image.zbar_image_s)
PrototypeC.i zbar_image_get_height(*image.zbar_image_s)
PrototypeC.i zbar_image_get_sequence(*image.zbar_image_s)
PrototypeC.i zbar_image_get_symbols(*image.zbar_image_s)
PrototypeC.i zbar_image_get_userdata(*image.zbar_image_s)
PrototypeC.i zbar_image_get_width(*image.zbar_image_s)
PrototypeC.i zbar_image_ref(*image.zbar_image_s, refs.l)
PrototypeC.i zbar_image_scanner_create()
PrototypeC.i zbar_image_scanner_destroy(*scanner)
PrototypeC.i zbar_image_scanner_enable_cache(*scanner, enable.l)
PrototypeC.i zbar_image_scanner_get_results(*scanner)
PrototypeC.i zbar_image_scanner_recycle_image(*scanner, *image.zbar_image_s)
PrototypeC.i zbar_image_scanner_set_config(*scanner, symbology.l, config.l, value.l)
PrototypeC.i zbar_image_scanner_set_data_handler(*scanner, *handler, *userdata)
PrototypeC.i zbar_image_set_data(*image.zbar_image_s, *data, data_byte_length.l, *cleanup_hndlr)
PrototypeC.i zbar_image_set_format(*image.zbar_image_s, format.l)
PrototypeC.i zbar_image_set_sequence(*image.zbar_image_s, sequence_num.l)
PrototypeC.i zbar_image_set_size(*image.zbar_image_s, width.l, height.l)
PrototypeC.i zbar_image_set_symbols(*image.zbar_image_s, *symbols.zbar_symbol_set_s)
PrototypeC.i zbar_image_set_userdata(*image.zbar_image_s, *userdata)
PrototypeC.i zbar_image_write(*image.zbar_image_s, *filebase)

PrototypeC.i zbar_negotiate_format(*video, *window)
PrototypeC.i zbar_process_image(*processor, *image.zbar_image_s)
PrototypeC.i zbar_process_one(*processor, timeout.l)
PrototypeC.i zbar_processor_create(thread.l)
PrototypeC.i zbar_processor_destroy(*processor)
PrototypeC.i zbar_processor_force_format(*processor, input_format.l, output_format.l)
PrototypeC.i zbar_processor_get_results(*processor)
PrototypeC.i zbar_processor_get_userdata(*processor)
PrototypeC.i zbar_processor_init(*processor, *video_device, enable_display.l)
PrototypeC.i zbar_processor_is_visible(*processor)
PrototypeC.i zbar_processor_request_interface(*processor, version.l)
PrototypeC.i zbar_processor_request_iomode(*processor, iomode.l)
PrototypeC.i zbar_processor_request_size(*processor, width.l, height.l)
PrototypeC.i zbar_processor_set_active(*processor, active.l)
PrototypeC.i zbar_processor_set_config(*processor, symbology.l, config.l, value.l)
PrototypeC.i zbar_processor_set_data_handler(*processor, *handler, *userdata)
PrototypeC.i zbar_processor_set_userdata(*processor, *userdata)
PrototypeC.i zbar_processor_set_visible(*processor, visible.l)
PrototypeC.i zbar_processor_user_wait(*processor, timeout.l)
PrototypeC.i zbar_scan_image(*scanner, *image.zbar_image_s)
PrototypeC.i zbar_scan_y(*scanner, y.l)
PrototypeC.i zbar_scanner_create(*decoder)
PrototypeC.i zbar_scanner_destroy(*scanner)
PrototypeC.i zbar_scanner_flush(*scanner)
PrototypeC.i zbar_scanner_get_color(*scanner)
PrototypeC.i zbar_scanner_get_edge(*scanner, offset.l, prec.l)
PrototypeC.i zbar_scanner_get_state(*scanner)
PrototypeC.i zbar_scanner_get_width(*scanner)
PrototypeC.i zbar_scanner_new_scan(*scanner)
PrototypeC.i zbar_scanner_reset(*scanner)

PrototypeC.i zbar_symbol_first_component()
PrototypeC.i zbar_symbol_get_components(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_get_count(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_get_data(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_get_data_length()
PrototypeC.i zbar_symbol_get_loc_size(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_get_loc_x(*symbol.zbar_symbol_s, index.l)
PrototypeC.i zbar_symbol_get_loc_y(*symbol.zbar_symbol_s, index.l)
PrototypeC.i zbar_symbol_get_quality(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_get_type(*symbol.zbar_symbol_s)
PrototypeC.i zbar_symbol_next(*symbol.zbar_symbol_s)
PrototypeC zbar_symbol_ref(*symbol.zbar_symbol_s, refs.l)
PrototypeC.i zbar_symbol_set_first_symbol(*symbols.zbar_symbol_set_s)
PrototypeC.i zbar_symbol_set_get_size(*symbols.zbar_symbol_set_s)
PrototypeC.i zbar_symbol_set_ref(*symbols.zbar_symbol_set_s, refs.l)
PrototypeC.i zbar_symbol_xml(*symbol.zbar_symbol_s, *buffer, *buflen)

PrototypeC.i zbar_video_create()
PrototypeC.i zbar_video_destroy(*video)
PrototypeC.i zbar_video_enable(*video, enbable.l)
PrototypeC.i zbar_video_get_fd(*video)
PrototypeC.i zbar_video_get_format()
PrototypeC.i zbar_video_get_height(*video)
PrototypeC.i zbar_video_get_width(*video)
PrototypeC.i zbar_video_init(*video, format.l)
PrototypeC.i zbar_video_next_image(*video)
PrototypeC.i zbar_video_open(*video, *device)
PrototypeC.i zbar_video_request_interface(*video, version.l)
PrototypeC.i zbar_video_request_iomode(*video, iomode.l)
PrototypeC.i zbar_video_request_size(*video, width.l, height.l)
PrototypeC.i zbar_window_attach(*window, *x11_display_w32_hwnd, x11_drawable.l)
PrototypeC.i zbar_window_create()
PrototypeC.i zbar_window_destroy(*window)
PrototypeC.i zbar_window_draw(*window, *image.zbar_image_s)
PrototypeC.i zbar_window_get_overlay(*window)
PrototypeC.i zbar_window_redraw(*window)
PrototypeC.i zbar_window_resize(*window, width.l, height.l)
PrototypeC.i zbar_window_set_overlay(*window, level.l)






Global zbar_lib.i


Global _zbar_error_spew._zbar_error_spew
Global _zbar_error_string._zbar_error_string
Global _zbar_get_error_code._zbar_get_error_code
Global zbar_decode_width.zbar_decode_width
Global zbar_decoder_create.zbar_decoder_create
Global zbar_decoder_destroy.zbar_decoder_destroy
Global zbar_decoder_get_color.zbar_decoder_get_color
Global zbar_decoder_get_data.zbar_decoder_get_data
Global zbar_decoder_get_data_length.zbar_decoder_get_data_length
Global zbar_decoder_get_type.zbar_decoder_get_type
Global zbar_decoder_get_userdata.zbar_decoder_get_userdata
Global zbar_decoder_new_scan.zbar_decoder_new_scan
Global zbar_decoder_reset.zbar_decoder_reset
Global zbar_decoder_set_config.zbar_decoder_set_config
Global zbar_decoder_set_handler.zbar_decoder_set_handler
Global zbar_decoder_set_userdata.zbar_decoder_set_userdata
Global _zbar_get_addon_name.zbar_get_addon_name
Global _zbar_get_symbol_name.zbar_get_symbol_name
Global zbar_image_convert.zbar_image_convert
Global zbar_image_convert_resize.zbar_image_convert_resize
Global zbar_image_copy.zbar_image_copy
Global zbar_image_create.zbar_image_create
Global zbar_image_destroy.zbar_image_destroy
Global zbar_image_first_symbol.zbar_image_first_symbol
Global zbar_image_free_data.zbar_image_free_data
Global zbar_image_get_data.zbar_image_get_data
Global zbar_image_get_data_length.zbar_image_get_data_length
Global zbar_image_get_format.zbar_image_get_format
Global zbar_image_get_height.zbar_image_get_height
Global zbar_image_get_sequence.zbar_image_get_sequence
Global zbar_image_get_symbols.zbar_image_get_symbols
Global zbar_image_get_userdata.zbar_image_get_userdata
Global zbar_image_get_width.zbar_image_get_width
Global zbar_image_ref.zbar_image_ref
Global zbar_image_scanner_create.zbar_image_scanner_create
Global zbar_image_scanner_destroy.zbar_image_scanner_destroy
Global zbar_image_scanner_enable_cache.zbar_image_scanner_enable_cache
Global zbar_image_scanner_get_results.zbar_image_scanner_get_results
Global zbar_image_scanner_recycle_image.zbar_image_scanner_recycle_image
Global zbar_image_scanner_set_config.zbar_image_scanner_set_config
Global zbar_image_scanner_set_data_handler.zbar_image_scanner_set_data_handler
Global zbar_image_set_data.zbar_image_set_data
Global zbar_image_set_format.zbar_image_set_format
Global zbar_image_set_sequence.zbar_image_set_sequence
Global zbar_image_set_size.zbar_image_set_size
Global zbar_image_set_symbols.zbar_image_set_symbols
Global zbar_image_set_userdata.zbar_image_set_userdata
Global zbar_image_write.zbar_image_write
Global zbar_increase_verbosity.zbar_increase_verbosity
Global zbar_negotiate_format.zbar_negotiate_format
Global zbar_parse_config.zbar_parse_config
Global zbar_process_image.zbar_process_image
Global zbar_process_one.zbar_process_one
Global zbar_processor_create.zbar_processor_create
Global zbar_processor_destroy.zbar_processor_destroy
Global zbar_processor_force_format.zbar_processor_force_format
Global zbar_processor_get_results.zbar_processor_get_results
Global zbar_processor_get_userdata.zbar_processor_get_userdata
Global zbar_processor_init.zbar_processor_init
Global zbar_processor_is_visible.zbar_processor_is_visible
Global zbar_processor_request_interface.zbar_processor_request_interface
Global zbar_processor_request_iomode.zbar_processor_request_iomode
Global zbar_processor_request_size.zbar_processor_request_size
Global zbar_processor_set_active.zbar_processor_set_active
Global zbar_processor_set_config.zbar_processor_set_config
Global zbar_processor_set_data_handler.zbar_processor_set_data_handler
Global zbar_processor_set_userdata.zbar_processor_set_userdata
Global zbar_processor_set_visible.zbar_processor_set_visible
Global zbar_processor_user_wait.zbar_processor_user_wait
Global zbar_scan_image.zbar_scan_image
Global zbar_scan_y.zbar_scan_y
Global zbar_scanner_create.zbar_scanner_create
Global zbar_scanner_destroy.zbar_scanner_destroy
Global zbar_scanner_flush.zbar_scanner_flush
Global zbar_scanner_get_color.zbar_scanner_get_color
Global zbar_scanner_get_edge.zbar_scanner_get_edge
Global zbar_scanner_get_state.zbar_scanner_get_state
Global zbar_scanner_get_width.zbar_scanner_get_width
Global zbar_scanner_new_scan.zbar_scanner_new_scan
Global zbar_scanner_reset.zbar_scanner_reset
Global zbar_set_verbosity.zbar_set_verbosity
Global zbar_symbol_first_component.zbar_symbol_first_component
Global zbar_symbol_get_components.zbar_symbol_get_components
Global zbar_symbol_get_count.zbar_symbol_get_count
Global _zbar_symbol_get_data.zbar_symbol_get_data
Global zbar_symbol_get_data_length.zbar_symbol_get_data_length
Global zbar_symbol_get_loc_size.zbar_symbol_get_loc_size
Global zbar_symbol_get_loc_x.zbar_symbol_get_loc_x
Global zbar_symbol_get_loc_y.zbar_symbol_get_loc_y
Global zbar_symbol_get_quality.zbar_symbol_get_quality
Global zbar_symbol_get_type.zbar_symbol_get_type
Global zbar_symbol_next.zbar_symbol_next
Global zbar_symbol_ref.zbar_symbol_ref
Global zbar_symbol_set_first_symbol.zbar_symbol_set_first_symbol
Global zbar_symbol_set_get_size.zbar_symbol_set_get_size
Global zbar_symbol_set_ref.zbar_symbol_set_ref
Global zbar_symbol_xml.zbar_symbol_xml
Global zbar_version.zbar_version
Global zbar_video_create.zbar_video_create
Global zbar_video_destroy.zbar_video_destroy
Global zbar_video_enable.zbar_video_enable
Global zbar_video_get_fd.zbar_video_get_fd
Global zbar_video_get_format.zbar_video_get_format
Global zbar_video_get_height.zbar_video_get_height
Global zbar_video_get_width.zbar_video_get_width
Global zbar_video_init.zbar_video_init
Global zbar_video_next_image.zbar_video_next_image
Global zbar_video_open.zbar_video_open
Global zbar_video_request_interface.zbar_video_request_interface
Global zbar_video_request_iomode.zbar_video_request_iomode
Global zbar_video_request_size.zbar_video_request_size
Global zbar_window_attach.zbar_window_attach
Global zbar_window_create.zbar_window_create
Global zbar_window_destroy.zbar_window_destroy
Global zbar_window_draw.zbar_window_draw
Global zbar_window_get_overlay.zbar_window_get_overlay
Global zbar_window_redraw.zbar_window_redraw
Global zbar_window_resize.zbar_window_resize
Global zbar_window_set_overlay.zbar_window_set_overlay


Procedure.s zbar_get_symbol_name(sym.l)
 
  Protected *Ptr
 
  *Ptr = _zbar_get_symbol_name(sym)
 
  ProcedureReturn PeekS(*Ptr, -1, #PB_Ascii)
 
EndProcedure


Procedure.s zbar_symbol_get_data(*symbol)
 
  Protected *Ptr
 
  *Ptr = _zbar_symbol_get_data(*symbol)
 
  ProcedureReturn PeekS(*Ptr, -1, #PB_Ascii)
 
EndProcedure


Procedure.s zbar_get_addon_name(*symbol)
 
  Protected *Ptr
 
  *Ptr = _zbar_get_addon_name(*symbol)
 
  ProcedureReturn PeekS(*Ptr, -1, #PB_Ascii)
 
EndProcedure



Procedure.i zbar_processor_parse_config(*processor, *config_string)
  Protected.l sym, cfg, val
  ProcedureReturn Bool(zbar_parse_config(*config_string, @sym, @cfg, @val) Or zbar_processor_set_config(*processor, sym, cfg, val))
EndProcedure

Procedure.i zbar_processor_error_spew(*processor, verbosity.l)
  ProcedureReturn _zbar_error_spew(*processor, verbosity)
EndProcedure

Procedure.i zbar_processor_error_string(*processor, verbosity.l)
  ProcedureReturn _zbar_error_string(*processor, verbosity)
EndProcedure

Procedure.i zbar_processor_get_error_code(*processor)
  ProcedureReturn _zbar_get_error_code(*processor)
EndProcedure




Procedure.i zbar_video_error_spew(*video, verbosity.l)
  ProcedureReturn _zbar_error_spew(*video, verbosity)
EndProcedure

Procedure.i zbar_video_error_string(*video, verbosity.l)
  ProcedureReturn _zbar_error_string(*video, verbosity)
EndProcedure

Procedure.i zbar_video_get_error_code(*video)
  ProcedureReturn _zbar_get_error_code(*video)
EndProcedure




Procedure.i zbar_window_error_spew(*video, verbosity.l)
  ProcedureReturn _zbar_error_spew(*video, verbosity)
EndProcedure

Procedure.i zbar_window_error_string(*video, verbosity.l)
  ProcedureReturn _zbar_error_string(*video, verbosity)
EndProcedure

Procedure.i zbar_window_get_error_code(*video)
  ProcedureReturn _zbar_get_error_code(*video)
EndProcedure




Procedure.i zbar_scanner_parse_config(*scanner, *config_string)
  Protected.l sym, cfg, val
  ProcedureReturn Bool(zbar_parse_config(*config_string, @sym, @cfg, @val) Or zbar_processor_set_config(*scanner, sym, cfg, val))
EndProcedure




Procedure.i zbar_decoder_parse_config(*decoder, *config_string)
  Protected.l sym, cfg, val
  ProcedureReturn Bool(zbar_parse_config(*config_string, @sym, @cfg, @val) Or zbar_processor_set_config(*decoder, sym, cfg, val))
EndProcedure




Procedure zbar_scan_rgb24(*scanner, *rgb)
  ProcedureReturn zbar_scan_y(*scanner, PeekA(*rgb + 0) + PeekA(*rgb + 1) + PeekA(*rgb + 2))
EndProcedure




Procedure.i zbar_init()
 
  Protected Result.i
 
 
  If zbar_lib = #Null
    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
        zbar_lib = OpenLibrary(#PB_Any, "libzbar-0.dll")
      CompilerCase #PB_OS_Linux
        zbar_lib = OpenLibrary(#PB_Any, "/usr/lib/libzbar.so")
    CompilerEndSelect
     
    If zbar_lib
      _zbar_error_spew = GetFunction(zbar_lib, "_zbar_error_spew")
      _zbar_error_string = GetFunction(zbar_lib, "_zbar_error_string")
      _zbar_get_error_code = GetFunction(zbar_lib, "_zbar_get_error_code")
      zbar_decode_width = GetFunction(zbar_lib, "zbar_decode_width")
      zbar_decoder_create = GetFunction(zbar_lib, "zbar_decoder_create")
      zbar_decoder_destroy = GetFunction(zbar_lib, "zbar_decoder_destroy")
      zbar_decoder_get_color = GetFunction(zbar_lib, "zbar_decoder_get_color")
      zbar_decoder_get_data = GetFunction(zbar_lib, "zbar_decoder_get_data")
      zbar_decoder_get_data_length = GetFunction(zbar_lib, "zbar_decoder_get_data_length")
      zbar_decoder_get_type = GetFunction(zbar_lib, "zbar_decoder_get_type")
      zbar_decoder_get_userdata = GetFunction(zbar_lib, "zbar_decoder_get_userdata")
      zbar_decoder_new_scan = GetFunction(zbar_lib, "zbar_decoder_new_scan")
      zbar_decoder_reset = GetFunction(zbar_lib, "zbar_decoder_reset")
      zbar_decoder_set_config = GetFunction(zbar_lib, "zbar_decoder_set_config")
      zbar_decoder_set_handler = GetFunction(zbar_lib, "zbar_decoder_set_handler")
      zbar_decoder_set_userdata = GetFunction(zbar_lib, "zbar_decoder_set_userdata")
      _zbar_get_addon_name = GetFunction(zbar_lib, "zbar_get_addon_name")
      _zbar_get_symbol_name = GetFunction(zbar_lib, "zbar_get_symbol_name")
      zbar_image_convert = GetFunction(zbar_lib, "zbar_image_convert")
      zbar_image_convert_resize = GetFunction(zbar_lib, "zbar_image_convert_resize")
      zbar_image_copy = GetFunction(zbar_lib, "zbar_image_copy")
      zbar_image_create = GetFunction(zbar_lib, "zbar_image_create")
      zbar_image_destroy = GetFunction(zbar_lib, "zbar_image_destroy")
      zbar_image_first_symbol = GetFunction(zbar_lib, "zbar_image_first_symbol")
      zbar_image_free_data = GetFunction(zbar_lib, "zbar_image_free_data")
      zbar_image_get_data = GetFunction(zbar_lib, "zbar_image_get_data")
      zbar_image_get_data_length = GetFunction(zbar_lib, "zbar_image_get_data_length")
      zbar_image_get_format = GetFunction(zbar_lib, "zbar_image_get_format")
      zbar_image_get_height = GetFunction(zbar_lib, "zbar_image_get_height")
      zbar_image_get_sequence = GetFunction(zbar_lib, "zbar_image_get_sequence")
      zbar_image_get_symbols = GetFunction(zbar_lib, "zbar_image_get_symbols")
      zbar_image_get_userdata = GetFunction(zbar_lib, "zbar_image_get_userdata")
      zbar_image_get_width = GetFunction(zbar_lib, "zbar_image_get_width")
      zbar_image_ref = GetFunction(zbar_lib, "zbar_image_ref")
      zbar_image_scanner_create = GetFunction(zbar_lib, "zbar_image_scanner_create")
      zbar_image_scanner_destroy = GetFunction(zbar_lib, "zbar_image_scanner_destroy")
      zbar_image_scanner_enable_cache = GetFunction(zbar_lib, "zbar_image_scanner_enable_cache")
      zbar_image_scanner_get_results = GetFunction(zbar_lib, "zbar_image_scanner_get_results")
      zbar_image_scanner_recycle_image = GetFunction(zbar_lib, "zbar_image_scanner_recycle_image")
      zbar_image_scanner_set_config = GetFunction(zbar_lib, "zbar_image_scanner_set_config")
      zbar_image_scanner_set_data_handler = GetFunction(zbar_lib, "zbar_image_scanner_set_data_handler")
      zbar_image_set_data = GetFunction(zbar_lib, "zbar_image_set_data")
      zbar_image_set_format = GetFunction(zbar_lib, "zbar_image_set_format")
      zbar_image_set_sequence = GetFunction(zbar_lib, "zbar_image_set_sequence")
      zbar_image_set_size = GetFunction(zbar_lib, "zbar_image_set_size")
      zbar_image_set_symbols = GetFunction(zbar_lib, "zbar_image_set_symbols")
      zbar_image_set_userdata = GetFunction(zbar_lib, "zbar_image_set_userdata")
      zbar_image_write = GetFunction(zbar_lib, "zbar_image_write")
      zbar_increase_verbosity = GetFunction(zbar_lib, "zbar_increase_verbosity")
      zbar_negotiate_format = GetFunction(zbar_lib, "zbar_negotiate_format")
      zbar_parse_config = GetFunction(zbar_lib, "zbar_parse_config")
      zbar_process_image = GetFunction(zbar_lib, "zbar_process_image")
      zbar_process_one = GetFunction(zbar_lib, "zbar_process_one")
      zbar_processor_create = GetFunction(zbar_lib, "zbar_processor_create")
      zbar_processor_destroy = GetFunction(zbar_lib, "zbar_processor_destroy")
      zbar_processor_force_format = GetFunction(zbar_lib, "zbar_processor_force_format")
      zbar_processor_get_results = GetFunction(zbar_lib, "zbar_processor_get_results")
      zbar_processor_get_userdata = GetFunction(zbar_lib, "zbar_processor_get_userdata")
      zbar_processor_init = GetFunction(zbar_lib, "zbar_processor_init")
      zbar_processor_is_visible = GetFunction(zbar_lib, "zbar_processor_is_visible")
      zbar_processor_request_interface = GetFunction(zbar_lib, "zbar_processor_request_interface")
      zbar_processor_request_iomode = GetFunction(zbar_lib, "zbar_processor_request_iomode")
      zbar_processor_request_size = GetFunction(zbar_lib, "zbar_processor_request_size")
      zbar_processor_set_active = GetFunction(zbar_lib, "zbar_processor_set_active")
      zbar_processor_set_config = GetFunction(zbar_lib, "zbar_processor_set_config")
      zbar_processor_set_data_handler = GetFunction(zbar_lib, "zbar_processor_set_data_handler")
      zbar_processor_set_userdata = GetFunction(zbar_lib, "zbar_processor_set_userdata")
      zbar_processor_set_visible = GetFunction(zbar_lib, "zbar_processor_set_visible")
      zbar_processor_user_wait = GetFunction(zbar_lib, "zbar_processor_user_wait")
      zbar_scan_image = GetFunction(zbar_lib, "zbar_scan_image")
      zbar_scan_y = GetFunction(zbar_lib, "zbar_scan_y")
      zbar_scanner_create = GetFunction(zbar_lib, "zbar_scanner_create")
      zbar_scanner_destroy = GetFunction(zbar_lib, "zbar_scanner_destroy")
      zbar_scanner_flush = GetFunction(zbar_lib, "zbar_scanner_flush")
      zbar_scanner_get_color = GetFunction(zbar_lib, "zbar_scanner_get_color")
      zbar_scanner_get_edge = GetFunction(zbar_lib, "zbar_scanner_get_edge")
      zbar_scanner_get_state = GetFunction(zbar_lib, "zbar_scanner_get_state")
      zbar_scanner_get_width = GetFunction(zbar_lib, "zbar_scanner_get_width")
      zbar_scanner_new_scan = GetFunction(zbar_lib, "zbar_scanner_new_scan")
      zbar_scanner_reset = GetFunction(zbar_lib, "zbar_scanner_reset")
      zbar_set_verbosity = GetFunction(zbar_lib, "zbar_set_verbosity")
      zbar_symbol_first_component = GetFunction(zbar_lib, "zbar_symbol_first_component")
      zbar_symbol_get_components = GetFunction(zbar_lib, "zbar_symbol_get_components")
      zbar_symbol_get_count = GetFunction(zbar_lib, "zbar_symbol_get_count")
      _zbar_symbol_get_data = GetFunction(zbar_lib, "zbar_symbol_get_data")
      zbar_symbol_get_data_length = GetFunction(zbar_lib, "zbar_symbol_get_data_length")
      zbar_symbol_get_loc_size = GetFunction(zbar_lib, "zbar_symbol_get_loc_size")
      zbar_symbol_get_loc_x = GetFunction(zbar_lib, "zbar_symbol_get_loc_x")
      zbar_symbol_get_loc_y = GetFunction(zbar_lib, "zbar_symbol_get_loc_y")
      zbar_symbol_get_quality = GetFunction(zbar_lib, "zbar_symbol_get_quality")
      zbar_symbol_get_type = GetFunction(zbar_lib, "zbar_symbol_get_type")
      zbar_symbol_next = GetFunction(zbar_lib, "zbar_symbol_next")
      zbar_symbol_ref = GetFunction(zbar_lib, "zbar_symbol_ref")
      zbar_symbol_set_first_symbol = GetFunction(zbar_lib, "zbar_symbol_set_first_symbol")
      zbar_symbol_set_get_size = GetFunction(zbar_lib, "zbar_symbol_set_get_size")
      zbar_symbol_set_ref = GetFunction(zbar_lib, "zbar_symbol_set_ref")
      zbar_symbol_xml = GetFunction(zbar_lib, "zbar_symbol_xml")
      zbar_version = GetFunction(zbar_lib, "zbar_version")
      zbar_video_create = GetFunction(zbar_lib, "zbar_video_create")
      zbar_video_destroy = GetFunction(zbar_lib, "zbar_video_destroy")
      zbar_video_enable = GetFunction(zbar_lib, "zbar_video_enable")
      zbar_video_get_fd = GetFunction(zbar_lib, "zbar_video_get_fd")
      zbar_video_get_format = GetFunction(zbar_lib, "zbar_video_get_format")
      zbar_video_get_height = GetFunction(zbar_lib, "zbar_video_get_height")
      zbar_video_get_width = GetFunction(zbar_lib, "zbar_video_get_width")
      zbar_video_init = GetFunction(zbar_lib, "zbar_video_init")
      zbar_video_next_image = GetFunction(zbar_lib, "zbar_video_next_image")
      zbar_video_open = GetFunction(zbar_lib, "zbar_video_open")
      zbar_video_request_interface = GetFunction(zbar_lib, "zbar_video_request_interface")
      zbar_video_request_iomode = GetFunction(zbar_lib, "zbar_video_request_iomode")
      zbar_video_request_size = GetFunction(zbar_lib, "zbar_video_request_size")
      zbar_window_attach = GetFunction(zbar_lib, "zbar_window_attach")
      zbar_window_create = GetFunction(zbar_lib, "zbar_window_create")
      zbar_window_destroy = GetFunction(zbar_lib, "zbar_window_destroy")
      zbar_window_draw = GetFunction(zbar_lib, "zbar_window_draw")
      zbar_window_get_overlay = GetFunction(zbar_lib, "zbar_window_get_overlay")
      zbar_window_redraw = GetFunction(zbar_lib, "zbar_window_redraw")
      zbar_window_resize = GetFunction(zbar_lib, "zbar_window_resize")
      zbar_window_set_overlay = GetFunction(zbar_lib, "zbar_window_set_overlay")
     
      Result = zbar_lib
     
    EndIf
   
  EndIf
 
  ProcedureReturn Result
 
EndProcedure


Procedure zbar_close()
  If IsLibrary(zbar_lib)
    CloseLibrary(zbar_lib)
    zbar_lib = #Null
  EndIf
EndProcedure


;-demo
CompilerIf #PB_Compiler_IsMainFile
 
  ProcedureC OwnCleanUp(*image.zbar_image_s)
   
    While *image
      FreeMemory(*image\Data)
      If *image\userdata
        FreeMemory(*image\userdata)
      EndIf
      *image = *image\Next
    Wend
  EndProcedure
 
 
  Procedure get_data(Filename$, *width, *height, *raw)
   
    Protected ColourByte.a
    Protected.i img, Width, Height, x, y, Ptr, Colour
    Protected *Buffer
   
    img = LoadImage(#PB_Any, Filename$)
    If img
      Width = ImageWidth(img)
      Height = ImageHeight(img)
      *Buffer = AllocateMemory(Width * Height)
      If *Buffer
        StartDrawing(ImageOutput(img))
       
        For y = 0 To Height - 1
          For x = 0 To Width - 1
            Colour = Point(x, y)
            ColourByte = (Colour & $E00000) >> 16 | (Colour & $E000) >> 11 | (Colour & $C0) >> 6
           
;             Debug Hex((Colour & $E00000) >> 16)
;             Debug Hex((Colour & $E000) >> 11)
;             
;             Debug Hex(Colour) + " -> " + Hex(ColourByte)
            PokeA(*Buffer + Ptr, ColourByte)
            Ptr + 1
          Next x
        Next y
       
        StopDrawing()
       
        PokeI(*raw, *Buffer)
        PokeL(*width, Width)
        PokeL(*height, Height)
      EndIf
      FreeImage(img)
    EndIf
   
  EndProcedure
 
 
 
 
  Define Filename$
  Define.l Major, Minor
  Define *scanner
  Define width.l, height.l, *raw
  Define *image.zbar_image_s
  Define n.i, *symbol.zbar_symbol_s, typ.i
 
 
  Filename$ = OpenFileRequester("Choose a bmp with code inside", "", "*.bmp|*.bmp", 0)
  If Filename$
    If ZBar_Init()
     
      zbar_version(@Major, @Minor)
      Debug "Version: " + Str(Major) + "." + Str(Minor)
     
      ; create a reader
      *scanner = zbar_image_scanner_create()
     
      ; configure the reader
      If zbar_image_scanner_set_config(*scanner, 0, #ZBAR_CFG_ENABLE, 1) <> 0
        Debug "Error: zbar_image_scanner_set_config"
      EndIf
     
      ; obtain image data
      get_data(Filename$, @width, @height, @*raw)
      Debug Str(width) + " x " + Str(height) + " @ " + Str(*raw)
     
      ; wrap image data
      *image = zbar_image_create()
      zbar_image_set_format(*image, #Format_Y800)
      zbar_image_set_size(*image, width, height)
      ;zbar_image_set_data(*image, *raw, width * height, zbar_image_free_data)
      zbar_image_set_data(*image, *raw, width * height, @OwnCleanUp())
     
;       Debug zbar_image_get_width(*image)
;       Debug zbar_image_get_height(*image)
;       Debug Hex(zbar_image_get_format(*image))
     
      ; scan the image For barcodes
      n = zbar_scan_image(*scanner, *image)
      If n = -1
        Debug "Error: zbar_scan_image"
      EndIf
     
      ;extract results
      *symbol = zbar_image_first_symbol(*image)
      While *symbol
        typ = zbar_symbol_get_type(*symbol)
       
        Debug zbar_get_symbol_name(typ)
        Debug zbar_symbol_get_data(*symbol)
       
        *symbol = zbar_symbol_next(*symbol)
      Wend
     
      ;clean up
      zbar_image_destroy(*image)
     
    EndIf
  EndIf
 
CompilerEndIf


For windows you need:

libzbar-0.dll
libiconv-2.dll


Last edited by infratec on Fri Apr 05, 2019 8:26 am, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Thu Apr 04, 2019 6:17 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jan 20, 2014 6:32 pm
Posts: 243
@infratec: Thank you very much for sharing and to your boss for allowing you to share it.

I just tried to run it however I am running it on linux I think the wrapper is working but I am getting some strange output.

Output:
Code:
Version: 0.22
732 x 300 @ 37345292
佃䕄㌭9佃䕄㤭3佃䕄ㄭ㠲倀䙄ㄴ7剑䌭摯e兓䌭摯e䅅ⵎ5久䉁䕌䔀䥍彔䡃䍅K十䥃I䥍彎䕌N䅍彘䕌N乕䕃呒䥁呎Y佐䥓䥔乏堀䑟久䥓奔夀䑟久䥓奔䄀䑄䍟䕈䭃䜀ㅓ䄀䵉唀P佄乗䰀䙅T䥒䡇T㼼浸l猥 挠畯瑮✽搥'映牯慭㵴戧獡㙥✴氠湥瑧㵨┧❤
㈱㐳㘵㠷〹1


The image I used:
Image

I modified the following line:
Code:
zbar_lib = OpenLibrary(#PB_Any, "/usr/lib/libzbar.so")


also enabled the debug for the version and size info.

Thanks

_________________
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Fri Apr 05, 2019 6:52 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4928
Location: Germany
I corrected the code above.

It was from a time where I compiled the code in ASCII format.
Today we need the #PB_ASCII (or UTF8) flag.

Your image results in:

CODE-39
12345678901


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Fri Apr 05, 2019 8:27 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4928
Location: Germany
Changed some stuff in the listing above:

Now the strings are directly returned.
The original cleanup sometimes results in an IMA
So I use now an own procedure for cleanup.


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Fri Apr 05, 2019 2:16 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jan 20, 2014 6:32 pm
Posts: 243
Thank you again very much it is working perfect in Linux for me...

_________________
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye