//specific format for BFF header private static byte[] SetHeader(CGeneric.Compression textureType, byte greenAlphaIndex, byte compressedValue, byte[] displayedWidth, byte[] pixelWidth, byte[] displayHeight, byte[] bffName, byte[] colorCount) { //fixedsize = 36 + bffName + 1 if bffName size is not pair + 4 for palette color count byte[] headerBFF2 = new Byte[36 + bffName.Length + bffName.Length % 2 + colorCount.Length]; headerBFF2[8] = 0x8; //write "BFF2" for (int i = 0; i < CGeneric.patternBFF2.Length; i++) { headerBFF2[12 + i] = CGeneric.patternBFF2[i]; } //decompose the next two bytes in nibbles //grab the nibbles of alpha color List <byte> alphaColor = CGeneric.ByteToNibble(greenAlphaIndex); //write two nibbles for the both bytes.. headerBFF2[17] = CGeneric.NibbleToByte(2, alphaColor[0]); headerBFF2[18] = CGeneric.NibbleToByte(alphaColor[1], compressedValue); //write texture type headerBFF2[19] = (byte)textureType; //write displayed width for (int i = 0; i < displayedWidth.Length; i++) { headerBFF2[20 + i] = displayedWidth[i]; } //write pixel width for (int i = 0; i < pixelWidth.Length; i++) { headerBFF2[22 + i] = pixelWidth[i]; } //write display height for (int i = 0; i < displayHeight.Length; i++) { headerBFF2[26 + i] = displayHeight[i]; } //prepare instruction length (depending of the pixelWidth value) double instructionLengthValue = CGeneric.ConvertByteArrayToInt(pixelWidth); switch (textureType) { case CGeneric.Compression.greyscale: instructionLengthValue *= 2; break; case CGeneric.Compression.max16Colors: instructionLengthValue /= 2; break; case CGeneric.Compression.trueColor16Bits: instructionLengthValue *= 2; break; case CGeneric.Compression.trueColor32Bits: instructionLengthValue *= 4; break; } byte[] instructLength = CGeneric.ConvertIntToByteArray((int)Math.Floor(instructionLengthValue)); //write instruction length for (int i = 0; i < instructLength.Length; i++) { headerBFF2[28 + i] = instructLength[i]; } //length of file name if (bffName.Length % 2 == 0) { headerBFF2[35] = (byte)bffName.Length; } else { headerBFF2[35] = (byte)(bffName.Length + 1); } //write bff name for (int i = 0; i < bffName.Length; i++) { headerBFF2[36 + i] = bffName[i]; } for (int i = 0; i < colorCount.Length; i++) { headerBFF2[36 + bffName.Length + bffName.Length % 2 + i] = colorCount[i]; } return(headerBFF2); }