public static byte[] GenerateBFF2(byte[] palette, byte[] data, CGeneric.Compression compressionMethod, int sizeX, int sizeY, string bffName) { //generate header //--> determine GreenAlpha and palette size byte greenAlphaIndex = 0; if (palette.Length > 0) { greenAlphaIndex = CTextureManager.GetGreenAlphaValueIndex(palette, compressionMethod); } //make almost random compressed value.. (10)(because not enought information about it) //set displayedWidth equal pixel width (because not enought information about it) byte[] sizeXB = CGeneric.ConvertIntToByteArray16bits(sizeX); byte[] sizeYB = CGeneric.ConvertIntToByteArray16bits(sizeY); byte[] name = CGeneric.ConvertStringToByteArray(bffName); byte[] nbColors = new byte[0]; if (palette.Length > 0) { nbColors = CGeneric.ConvertIntToByteArray(palette.Length / CTextureManager.GetBytePerPixel(compressionMethod)); } byte[] bff2header = SetHeader(compressionMethod, greenAlphaIndex, 0xE, sizeXB, sizeXB, sizeYB, name, nbColors); //concatenate header, palette and compressed data byte[] finalData = new byte[bff2header.Length + palette.Length + data.Length]; Array.Copy(bff2header, 0, finalData, 0, bff2header.Length); if (palette.Length > 0) { Array.Copy(palette, 0, finalData, bff2header.Length, palette.Length); } Array.Copy(data, 0, finalData, bff2header.Length + palette.Length, data.Length); return(finalData); }
public void Init() { //init header... // take 2 byte : for the fist byte keep only 4 last bit and for the second keep only the 4 first.. byte b1 = rawData[17]; byte b2 = rawData[18]; b1 %= 16; b1 <<= 4; b2 /= 16; b1 += b2; headerBFF2.transparencyPixelIndex = b1; headerBFF2.displayLength = rawData[8]; // check if the data is compressed and if data had indexed color headerBFF2.isCompressedTexture = (rawData[18] % 16 > 7) ? true : false; //copy basic informations.. headerBFF2.textureType = rawData[19]; headerBFF2.nameLength = rawData[35]; headerBFF2.isIndexedColor = (headerBFF2.textureType == 0x32 || headerBFF2.textureType == 0x33) ? true : false; headerBFF2.textureWidth = new byte[2]; headerBFF2.textureHeight = new byte[2]; headerBFF2.name = new byte[headerBFF2.nameLength]; headerBFF2.bytePerPixel = (byte)CTextureManager.GetBytePerPixel((CGeneric.Compression)headerBFF2.textureType); Array.Copy(rawData, 22, headerBFF2.textureWidth, 0, 2); Array.Copy(rawData, 26, headerBFF2.textureHeight, 0, 2); Array.Copy(rawData, 36, headerBFF2.name, 0, headerBFF2.nameLength); //remove last not necessary character if (headerBFF2.name[headerBFF2.nameLength - 1] == 0) { headerBFF2.name = new byte[headerBFF2.nameLength - 1]; Array.Copy(rawData, 36, headerBFF2.name, 0, headerBFF2.nameLength - 1); } headerBFF2.sizeX = CGeneric.ConvertByteArrayToInt(headerBFF2.textureWidth); headerBFF2.sizeY = CGeneric.ConvertByteArrayToInt(headerBFF2.textureHeight); //extract palette int startingData = 0x24 + headerBFF2.nameLength; if (headerBFF2.isIndexedColor) { ExtractPalette(startingData); startingData += headerBFF2.palette.Length + headerBFF2.paletteSize.Length; } headerBFF2.dataCompressed = new Byte[rawData.Length - startingData]; Array.Copy(rawData, startingData, headerBFF2.dataCompressed, 0, headerBFF2.dataCompressed.Length); }