Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public Bitmap ShowTexture()
        {
            byte[] tmpArray = null;
            switch (bytePerPixel)
            {
            case 32:
                tmpArray = rawData;
                break;

            case 16:
                tmpArray = CTextureManager.ConvertByteArrayToRGBA(rawData, CGeneric.Compression.trueColor16Bits);
                break;

            case 8:
                tmpArray = CTextureManager.ConvertByteArrayToRGBA(rawData, CGeneric.Compression.max256Colors, palette, true);
                break;
            }

            return(CTextureManager.ConvertRGBAByteArrayToBitmap(tmpArray, sizeX, sizeY));
        }
Exemplo n.º 4
0
        public void DecompressTexture()
        {
            Byte[] compressedTex;
            compressedTex = new Byte[rawData.Length - 35 + headerBFF2.nameLength];

            Byte[] decompressedTex;

            //if texture is compressed, decompress it.
            if (headerBFF2.isCompressedTexture)
            {
                decompressedTex = CTextureDecompress.DecompressTexture(headerBFF2);
            }
            else
            {
                decompressedTex = headerBFF2.dataCompressed;
            }

            //convert all textures to 32 bit RGBA for display to user.
            decompressedTex = CTextureManager.ConvertByteArrayToRGBA(decompressedTex, (CGeneric.Compression)headerBFF2.textureType, headerBFF2.palette);

            headerBFF2.dataUncompressed = decompressedTex;
        }
Exemplo n.º 5
0
 public static CGeneric.Compression TestBestCompression(Bitmap bmp)
 {
     if (CTextureManager.IsGreyscaleTexture(bmp))
     {
         return(CGeneric.Compression.greyscale);
     }
     else if (!CTextureManager.IsMoreColorThanExpected(bmp, 16))
     {
         return(CGeneric.Compression.max16Colors);
     }
     else if (!CTextureManager.IsMoreColorThanExpected(bmp, 256))
     {
         return(CGeneric.Compression.max256Colors);
     }
     else if (!CTextureManager.IsAlphaVariation(bmp))
     {
         return(CGeneric.Compression.trueColor16Bits);
     }
     else
     {
         return(CGeneric.Compression.trueColor32Bits);
     }
 }
Exemplo n.º 6
0
 public Bitmap GetBmpTexture()
 {
     return(CTextureManager.ConvertRGBAByteArrayToBitmap(headerBFF2.dataUncompressed, headerBFF2.sizeX, headerBFF2.sizeY));
 }