CSNG (File Format): Difference between revisions

Jump to navigation Jump to search
no edit summary
imported>Jackoalan
imported>Jackoalan
No edit summary
Line 170: Line 170:


<syntaxhighlight lang="python" line="1">
<syntaxhighlight lang="python" line="1">
def DecodeDeltaTimeRLE(in):
def DecodeDeltaTimeRLE(streamIn):
     total = 0
     total = 0
     while True:
     while True:
         term = in.ReadU16()
         term = streamIn.ReadU16()
         if term == 0xffff:
         if term == 0xffff:
             total += 0xffff
             total += 0xffff
             dummy = in.ReadU16()
             dummy = streamIn.ReadU16()
             continue
             continue
         total += term
         total += term
Line 249: Line 249:


<syntaxhighlight lang="python" line="1">
<syntaxhighlight lang="python" line="1">
def DecodeRLE(in):
def DecodeRLE(streamIn):
     # high-bit shift-trigger RLE, limited to 2 bytes
     # high-bit shift-trigger RLE, limited to 2 bytes
     term = in.ReadU8()
     term = streamIn.ReadU8()
     total = term & 0x7f
     total = term & 0x7f
     if term & 0x80:
     if term & 0x80:
         total = total * 256 + in.ReadU8()
         total = total * 256 + streamIn.ReadU8()
     return total
     return total


def DecodeContinuousRLE(in, isValue):
def DecodeContinuousRLE(streamIn, isValue):
     total = 0
     total = 0
     while True:
     while True:
         # 1-2 byte RLE accumulated within continuable RLE
         # 1-2 byte RLE accumulated within continuable RLE
         term = DecodeRLE(in)
         term = DecodeRLE(streamIn)
         if term == 0x8000:
         if term == 0x8000:
             total += 0xffff
             total += 0xffff
Anonymous user

Navigation menu