def rldecode(data):
 decoded = []
 i = 0
 while (i < len(data)):
  length = ord(data[i])
  if (length == 128):
   break
  if ((length >= 0) and (length < 128)):
   run = data[(i + 1):((i + 1) + (length + 1))]
   decoded.append(run)
   i = ((i + 1) + (length + 1))
  if (length > 128):
   run = (data[(i + 1)] * (257 - length))
   decoded.append(run)
   i = ((i + 1) + 1)
 return ''.join(decoded)

def rldecode ( data ) : decoded = [ ] i = 0 while ( i < len ( data ) ) : length = ord ( data [ i ] ) if ( length == 128 ) : break if ( ( length >= 0 ) and ( length < 128 ) ) : run = data [ ( i + 1 ) : ( ( i + 1 ) + ( length + 1 ) ) ] decoded . append ( run ) i = ( ( i + 1 ) + ( length + 1 ) ) if ( length > 128 ) : run = ( data [ ( i + 1 ) ] * ( 257 - length ) ) decoded . append ( run ) i = ( ( i + 1 ) + 1 ) return '' . join ( decoded )
runlength decoder implementation based on pdf reference version 1 .