def unpackGRADIENT(data): dataBits = bitstruct.bytesToBits([data[0]]) spreadMode = ["Pad", "Reflect", "Repeat", False][bitstruct.bitsToUInt(dataBits[0:2])] interpolationMode = ["Normal", "Linear", False, False][bitstruct.bitsToUInt(dataBits[2:4])] numGradients = bitstruct.bitsToUInt(dataBits[4:]) gradientRecords = [] for index in range(numGradients): gradientRecords += [{"Ratio":data[index * 4 + 1], "R":data[index * 4 + 2], "G":data[index * 4 + 3], "B":data[index * 4 + 4]}] return numGradients * 4 + 1, {"SpreadMode":spreadMode, "InterpolationMode":interpolationMode, "GradientRecords":gradientRecords}
def parseDefineSound(tagData): #DefineSound - Stores audio data, either uncompressed or compressed characterId = struct.unpack("<H", tagData[0:2])[0] formatRateSizeType = bitstruct.bytesToBits([tagData[2]]) soundFormat = bitstruct.bitsToUInt(formatRateSizeType[0:4]) soundRate = bitstruct.bitsToUInt(formatRateSizeType[4:6]) if formatRateSizeType[6]: soundSize = 16 else: soundSize = 8 soundStereo = formatRateSizeType[7] # #TODO: Save audio, at least as raw data. # return {"CharacterId": characterId, "SoundFormat": soundFormat, "SampleRate": [5512, 11025, 22050, 44100][soundRate], "SampleSize": soundSize, "Stereo":soundStereo }