Page 2 of 2

Re: QR Code decoder library ported to PB

Posted: Mon Feb 01, 2021 12:00 am
by infratec
I changed the second part of the listing above.

Or please replace Procedure.i ImageToGrayScaleBuffer(Img.i) with:

Code: Select all

Procedure.i ImageToGrayScaleBuffer(Img.i)
  
  Structure rgba
    b.a
    g.a
    r.a
    alpha.a
  EndStructure
  
  
  Protected.i ImgWidth, ImgHeight, PixelBytes, LinePadBytes, X, Y
  Protected *Buffer, *BufferPos.Ascii, *ImgPos.rgba
  
  
  If IsImage(Img)
    
    If StartDrawing(ImageOutput(Img))
      
      ImgWidth = ImageWidth(Img)
      ImgHeight = ImageHeight(Img)
      
      *Buffer = AllocateMemory(ImgWidth * ImgHeight, #PB_Memory_NoClear)
      If *Buffer
        PixelBytes = 3
        *ImgPos = DrawingBuffer()
        
        If DrawingBufferPixelFormat() & #PB_PixelFormat_32Bits_RGB : PixelBytes = 4 : EndIf
        If DrawingBufferPixelFormat() & #PB_PixelFormat_32Bits_BGR : PixelBytes = 4 : EndIf
        LinePadBytes = DrawingBufferPitch() - (ImgWidth * PixelBytes)
        
        Debug "PixelBytes: " + Str(PixelBytes)
        
        ImgWidth - 1
        ImgHeight - 1
        
        *BufferPos = *Buffer
        
        For Y = 0 To ImgHeight
          For X = 0 To ImgWidth
            ;Debug Hex(*ImgPos\a) + " " + Hex(*ImgPos\r) + " " + Hex(*ImgPos\g) + " " + Hex(*ImgPos\b)
            If PixelBytes = 3
              *BufferPos\a = (*ImgPos\r + *ImgPos\g  + *ImgPos\b) / 3
            Else
              If *ImgPos\alpha > 127
                *BufferPos\a = (*ImgPos\r + *ImgPos\g  + *ImgPos\b) / 3
              Else
                *BufferPos\a = $FF
              EndIf
            EndIf
            ;*BufferPos\a = 0.2990 * *ImgPos\r + 0.5870 * *ImgPos\g  + 0.1140 * *ImgPos\b ; TV
            ;*BufferPos\a = 0.2126 * *ImgPos\r + 0.7152 * *ImgPos\g  + 0.0722 * *ImgPos\b ; ITU-R BT.709 HDTV and CIE 1931 sRGB
            ;*BufferPos\a = 0.2627 * *ImgPos\r + 0.6780 * *ImgPos\g  + 0.0593 * *ImgPos\b ; ITU-R BT.2100 HDR
            *BufferPos + 1
            *ImgPos + PixelBytes
          Next X
          *ImgPos + LinePadBytes
        Next Y
        
      EndIf
      StopDrawing()
    EndIf
    
  EndIf
  
  ProcedureReturn *Buffer
  
EndProcedure
Then the image from wikipedia works.
This image is strange. It uses only black color (0 0 0) and it only sets the transparency.

Re: QR Code decoder library ported to PB

Posted: Mon Feb 01, 2021 4:50 pm
by skywalk
Thanks! It works now for the wiki image and your previous qr-make lib creations. 8)

Re: QR Code decoder library ported to PB

Posted: Tue Feb 02, 2021 9:57 am
by infratec
Made a module out of it, to avoid naming conflicts.

Re: QR Code decoder library ported to PB

Posted: Mon Jan 24, 2022 3:47 pm
by infratec
Updated the listings in the first two postings to the current git version of quirc: 8 Oct 2021

Re: QR Code decoder library ported to PB

Posted: Wed May 25, 2022 10:53 am
by Thorsten1867
QRCode - Module (Encoding/Decoding/Gadget)