public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            byte[] Data = BitmapExtension.ImageToByte(bitmap);
            Width  = (uint)bitmap.Width;
            Height = (uint)bitmap.Height;

            ImageData = DDSCompressor.EncodePixelBlock(Data, bitmap.Width, bitmap.Width, DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
        }
        public GenericBitmapTexture(byte[] FileData, int width, int height)
        {
            Format = TEX_FORMAT.R8G8B8A8_UNORM;
            Width  = (uint)width;
            Height = (uint)height;

            ImageData = DDSCompressor.CompressBlock(FileData, width, height,
                                                    DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
        }
예제 #3
0
        //Method from https://github.com/aboood40091/BNTX-Editor/blob/master/formConv.py
        public static byte[] Decode(byte[] data, int width, int height, TEX_FORMAT format)
        {
            uint bpp  = STGenericTexture.GetBytesPerPixel(format);
            int  size = width * height * 4;

            bpp = (uint)(data.Length / (width * height));

            byte[] output = new byte[size];

            int inPos  = 0;
            int outPos = 0;

            byte[] comp    = new byte[] { 0, 0, 0, 0xFF, 0, 0xFF };
            byte[] compSel = new byte[4] {
                0, 1, 2, 3
            };

            if (format == TEX_FORMAT.LA8)
            {
                compSel = new byte[4] {
                    0, 0, 0, 1
                };
                bpp = 2;
            }
            else if (format == TEX_FORMAT.L8)
            {
                compSel = new byte[4] {
                    0, 0, 0, 5
                }
            }
            ;
            else if (format == TEX_FORMAT.R5G5B5A1_UNORM)
            {
                bpp = 2;
                return(DDSCompressor.DecodePixelBlock(data, (int)width, (int)height, DDS.DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM));
            }

            for (int Y = 0; Y < height; Y++)
            {
                for (int X = 0; X < width; X++)
                {
                    inPos  = (Y * width + X) * (int)bpp;
                    outPos = (Y * width + X) * 4;

                    int pixel = 0;
                    for (int i = 0; i < bpp; i++)
                    {
                        pixel |= data[inPos + i] << (8 * i);
                    }

                    comp = GetComponentsFromPixel(format, pixel, comp);

                    output[outPos + 3] = comp[compSel[3]];
                    output[outPos + 2] = comp[compSel[2]];
                    output[outPos + 1] = comp[compSel[1]];
                    output[outPos + 0] = comp[compSel[0]];
                }
            }

            return(output);
        }