parameters: (pngObject, font)
return_statement: return rowStart < height
docstring: Convert a bitmap to characters in the given font
docstring_summary: Convert a bitmap to characters in the given font
docstring_tokens: Convert a bitmap to characters in the given font
function: def bitmapToChars(pngObject, font):
      """
      Convert a bitmap to characters in the given font
      """
      # Just cache the bitmap into a list of lists since random access is paramount
      bitmap = list()
      width = pngObject.asRGBA8()[0]
      height = pngObject.asRGBA8()[1]
      rowGenerator = pngObject.asRGBA8()[2]
      for row in rowGenerator:
          cRow = list()
          irpd = iter(row)
          for r,g,b,a in zip(irpd, irpd, irpd, irpd):
              cRow.append(a << 24 | r << 16 | g << 8 | b)
          bitmap.append(cRow)
  
      rowStart = 0
      while rowStart < height:
          # Find the top of the row
          for i in range(rowStart, height):
              if pixelIsSet(bitmap[rowStart][0]):
                  break
              rowStart += 1
          if rowStart >= height:
              break
  
          # Find the bottom of the row
          rowEnd = rowStart + 1
          for i in range(rowEnd, height):
              if not pixelIsSet(bitmap[rowEnd][0]):
                  rowEnd -= 1
                  break
              rowEnd += 1
  
          # Find the baseline
          baseline = rowStart
          for i in range(rowStart, rowEnd+1):
              if pixelIsSet(bitmap[baseline][1]):
                  break
              baseline += 1
          if baseline > rowEnd:
              sys.stderr.write("No baseline found between rows %d-%d\n" % (rowStart, rowEnd))
              break
  
          # Set or confirm the height
          if font.height == 0:
              font.height = rowEnd - rowStart + 1
              font.yOffs = baseline - rowEnd
          else:
              if font.height != (rowEnd - rowStart + 1):
                  sys.stderr.write("Inconsistent font height at rows %d-%d\n" % (rowStart, rowEnd))
                  break
              if font.yOffs != (baseline - rowEnd):
                  sys.stderr.write("Inconsistent baseline at rows %d-%d\n" % (rowStart, rowEnd))
                  break
  
          # decode the starting character
          chStart = 0
          for x in range(0, 4):
              for y in range(0, 4):
                  chStart = (chStart << 1) | pixelIsSet(bitmap[rowStart+y][2+x])
  
          # Print debug info
          # print("Row %d-%d, baseline %d, character start %X" % (rowStart, rowEnd, baseline, chStart))
  
          # scan the column to find characters
          colStart = 0
          while colStart < width:
              ch = RenderFontChar()
  
              # Find the start of the character
              for i in range(colStart, width):
                  if pixelIsSet(bitmap[rowEnd+2][colStart]):
                      break
                  colStart += 1
              if colStart >= width:
                  break
  
              # Find the end of the character
              colEnd = colStart + 1
              for i in range(colEnd, width):
                  if not pixelIsSet(bitmap[rowEnd+2][colEnd]):
                      colEnd -= 1
                      break
                  colEnd += 1
  
              # Skip char which code is already registered
              if ch.width <= 0:
                  # Print debug info
                  # print "  Character %X - width = %d" % (chStart, colEnd - colStart + 1)
  
                  # Plot the character
                  ch.bitmap = list()
                  for y in range(rowStart, rowEnd+1):
                      ch.bitmap.append(list())
                      for x in range(colStart, colEnd+1):
                          if pixelIsSet(bitmap[y][x]):
                              ch.bitmap[-1].append(0xffffffff)
                          else:
                              ch.bitmap[-1].append(0x00000000)
  
                  # Set the character parameters
                  ch.width = colEnd - colStart + 1
                  ch.xOffs = 0
                  ch.yOffs = font.yOffs
                  ch.bmWidth = len(ch.bitmap[0])
                  ch.bmHeight = len(ch.bitmap)
  
                  # Insert the character into the list
                  font.chars[chStart] = ch
  
              # Next character
              chStart += 1
              colStart = colEnd + 1
  
          # Next row
          rowStart = rowEnd + 1
  
      # Return non-zero if we errored
      return rowStart < height
function_tokens: def bitmapToChars ( pngObject , font ) : # Just cache the bitmap into a list of lists since random access is paramount bitmap = list ( ) width = pngObject . asRGBA8 ( ) [ 0 ] height = pngObject . asRGBA8 ( ) [ 1 ] rowGenerator = pngObject . asRGBA8 ( ) [ 2 ] for row in rowGenerator : cRow = list ( ) irpd = iter ( row ) for r , g , b , a in zip ( irpd , irpd , irpd , irpd ) : cRow . append ( a << 24 | r << 16 | g << 8 | b ) bitmap . append ( cRow ) rowStart = 0 while rowStart < height : # Find the top of the row for i in range ( rowStart , height ) : if pixelIsSet ( bitmap [ rowStart ] [ 0 ] ) : break rowStart += 1 if rowStart >= height : break # Find the bottom of the row rowEnd = rowStart + 1 for i in range ( rowEnd , height ) : if not pixelIsSet ( bitmap [ rowEnd ] [ 0 ] ) : rowEnd -= 1 break rowEnd += 1 # Find the baseline baseline = rowStart for i in range ( rowStart , rowEnd + 1 ) : if pixelIsSet ( bitmap [ baseline ] [ 1 ] ) : break baseline += 1 if baseline > rowEnd : sys . stderr . write ( "No baseline found between rows %d-%d\n" % ( rowStart , rowEnd ) ) break # Set or confirm the height if font . height == 0 : font . height = rowEnd - rowStart + 1 font . yOffs = baseline - rowEnd else : if font . height != ( rowEnd - rowStart + 1 ) : sys . stderr . write ( "Inconsistent font height at rows %d-%d\n" % ( rowStart , rowEnd ) ) break if font . yOffs != ( baseline - rowEnd ) : sys . stderr . write ( "Inconsistent baseline at rows %d-%d\n" % ( rowStart , rowEnd ) ) break # decode the starting character chStart = 0 for x in range ( 0 , 4 ) : for y in range ( 0 , 4 ) : chStart = ( chStart << 1 ) | pixelIsSet ( bitmap [ rowStart + y ] [ 2 + x ] ) # Print debug info # print("Row %d-%d, baseline %d, character start %X" % (rowStart, rowEnd, baseline, chStart)) # scan the column to find characters colStart = 0 while colStart < width : ch = RenderFontChar ( ) # Find the start of the character for i in range ( colStart , width ) : if pixelIsSet ( bitmap [ rowEnd + 2 ] [ colStart ] ) : break colStart += 1 if colStart >= width : break # Find the end of the character colEnd = colStart + 1 for i in range ( colEnd , width ) : if not pixelIsSet ( bitmap [ rowEnd + 2 ] [ colEnd ] ) : colEnd -= 1 break colEnd += 1 # Skip char which code is already registered if ch . width <= 0 : # Print debug info # print "  Character %X - width = %d" % (chStart, colEnd - colStart + 1) # Plot the character ch . bitmap = list ( ) for y in range ( rowStart , rowEnd + 1 ) : ch . bitmap . append ( list ( ) ) for x in range ( colStart , colEnd + 1 ) : if pixelIsSet ( bitmap [ y ] [ x ] ) : ch . bitmap [ - 1 ] . append ( 0xffffffff ) else : ch . bitmap [ - 1 ] . append ( 0x00000000 ) # Set the character parameters ch . width = colEnd - colStart + 1 ch . xOffs = 0 ch . yOffs = font . yOffs ch . bmWidth = len ( ch . bitmap [ 0 ] ) ch . bmHeight = len ( ch . bitmap ) # Insert the character into the list font . chars [ chStart ] = ch # Next character chStart += 1 colStart = colEnd + 1 # Next row rowStart = rowEnd + 1 # Return non-zero if we errored return rowStart < height