def readPngBitString(pngName, ignore=None):
  '''read a png into a bitstring. if ignore is top, bottom, left or right,
  don't read those bits'''
  bitlist = []
  reader = png.Reader(pngName)
  if ignore is None:
    for line in reader.read()[2]:
      bitlist.append(project.listToString(list(line)))
  elif ignore == 'top' or ignore == 'bottom':
    lines = []  # save all, then delete first or second half
    for line in reader.read()[2]:
      lines.append(line)
    if ignore == 'top':
      keptLines = lines[:len(lines)/2]  # keep the bottom half
    else:  # ignore the bottom or second half
      keptLines = lines[len(lines)/2:]  # keep the top half
    for line in keptLines:
      bitlist.append(project.listToString(list(line)))
  elif ignore == 'left' or ignore == 'right':
    for line in reader.read()[2]:
      listLine = list(line)
      if ignore == 'left':
        bitlist.append(project.listToString(list(line)[len(listLine)/2:]))
      else:   # ignore must be the right half, so keep left
        bitlist.append(project.listToString(list(line)[:len(listLine)/2]))
  bitstring = string.join(bitlist, '')
  return bitstring
Beispiel #2
0
def readPngBitString(pngName, ignore=None):
    '''read a png into a bitstring. if ignore is top, bottom, left or right,
  don't read those bits'''
    bitlist = []
    reader = png.Reader(pngName)
    if ignore is None:
        for line in reader.read()[2]:
            bitlist.append(project.listToString(list(line)))
    elif ignore == 'top' or ignore == 'bottom':
        lines = []  # save all, then delete first or second half
        for line in reader.read()[2]:
            lines.append(line)
        if ignore == 'top':
            keptLines = lines[:len(lines) / 2]  # keep the bottom half
        else:  # ignore the bottom or second half
            keptLines = lines[len(lines) / 2:]  # keep the top half
        for line in keptLines:
            bitlist.append(project.listToString(list(line)))
    elif ignore == 'left' or ignore == 'right':
        for line in reader.read()[2]:
            listLine = list(line)
            if ignore == 'left':
                bitlist.append(
                    project.listToString(list(line)[len(listLine) / 2:]))
            else:  # ignore must be the right half, so keep left
                bitlist.append(
                    project.listToString(list(line)[:len(listLine) / 2]))
    bitstring = string.join(bitlist, '')
    return bitstring
Beispiel #3
0
def readPngBitString(pngName):
  '''read a png into a bitstring'''
  bitlist = []
  reader = png.Reader(pngName)
  for line in reader.read()[2]:
    bitlist.append(project.listToString(list(line)))
  bitstring = string.join(bitlist, '')
  return bitstring