Пример #1
0
        private static byte[] DecodeData(byte[] data, uint width, uint height, TextureFormats format)
        {
            switch (format)
            {
            case TextureFormats.I4:
                return(ImageDataFormat.I4.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.I8:
                return(ImageDataFormat.I8.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.IA4:
                return(ImageDataFormat.IA4.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.IA8:
                return(ImageDataFormat.IA8.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.RGB565:
                return(ImageDataFormat.RGB565.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.RGB5A3:
                return(ImageDataFormat.RGB5A3.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.RGBA32:
                return(ImageDataFormat.Rgba32.ConvertFrom(data, (int)width, (int)height));

            case TextureFormats.CMPR:
                return(ImageDataFormat.Cmpr.ConvertFrom(data, (int)width, (int)height));

            default:
                return(new byte[0]);
                // throw new Exception(string.Format("Unsupported Binary Texture Image format {0}, unable to decode!", format.ToString()));
            }
        }
Пример #2
0
        public static Tuple <List <byte[]>, ushort[]> GenerateMipList(Bitmap Image, uint TexWidth, uint TexHeight,
                                                                      uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat)
        {
            ushort[] paletteData = new ushort[0];

            List <byte[]> mipmaps = new List <byte[]>();

            for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
            {
                int MipWidth  = Math.Max(1, (int)TexWidth >> mipLevel);
                int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel);

                if (mipLevel != 0)
                {
                    Image = BitmapExtension.Resize(Image, MipWidth, MipHeight);
                }

                var EncodedData = Decode_Gamecube.EncodeData(BitmapExtension.ImageToByte(Image), Format, PaletteFormat, MipWidth, MipHeight);

                mipmaps.Add(EncodedData.Item1);

                if (mipLevel == 0) //Set palette data once
                {
                    paletteData = EncodedData.Item2;
                }
            }
            Image.Dispose();

            return(Tuple.Create(mipmaps, paletteData));
        }
Пример #3
0
        public static Tuple <List <byte[]>, ushort[]> GenerateMipList(byte[] uncompressedData, uint TexWidth, uint TexHeight,
                                                                      uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat)
        {
            Bitmap Image = BitmapExtension.CreateBitmap(uncompressedData, (int)TexWidth, (int)TexHeight);

            return(GenerateMipList(Image, TexWidth, TexHeight, MipCount, Format, PaletteFormat));
        }
Пример #4
0
        //Code from https://github.com/Sage-of-Mirrors/SuperBMD/blob/ce1061e9b5f57de112f1d12f6459b938594664a0/SuperBMDLib/source/Materials/BinaryTextureImage.cs
        //Adjusted for proper editing in ST

        #region Data Types

        public static TEX_FORMAT ToGenericFormat(TextureFormats Format)
        {
            switch (Format)
            {
            case TextureFormats.C14X2: return(TEX_FORMAT.C14X2);

            case TextureFormats.C4: return(TEX_FORMAT.C4);

            case TextureFormats.C8: return(TEX_FORMAT.C8);

            case TextureFormats.CMPR: return(TEX_FORMAT.CMPR);

            case TextureFormats.I4: return(TEX_FORMAT.I4);

            case TextureFormats.I8: return(TEX_FORMAT.I8);

            case TextureFormats.IA4: return(TEX_FORMAT.IA4);

            case TextureFormats.IA8: return(TEX_FORMAT.IA8);

            case TextureFormats.RGB565: return(TEX_FORMAT.RGB565);

            case TextureFormats.RGB5A3: return(TEX_FORMAT.RGB5A3);

            case TextureFormats.RGBA32: return(TEX_FORMAT.RGBA32);

            default:
                throw new Exception("Unknown Format " + Format);
            }
        }
        public static byte[] EncodeData(Bitmap bmp, uint width, uint height, TextureFormats format)
        {
            switch (format)
            {
            case TextureFormats.I4:
                return(EncodeI4(bmp, width, height));

            default:
                return(new byte[0]);
            }
        }
Пример #6
0
 public static int GetDataSize(TextureFormats Format, int Width, int Height)
 {
     while ((Width % TileSizeW[(uint)Format]) != 0)
     {
         Width++;
     }
     while ((Height % TileSizeH[(uint)Format]) != 0)
     {
         Height++;
     }
     return(Width * Height * GetBpp(Format) / 8);
 }
Пример #7
0
        private static byte[] DecodeData(byte[] data, uint width, uint height, TextureFormats format, Palette imagePalette, PaletteFormats paletteFormat)
        {
            switch (format)
            {
            case TextureFormats.C4:
                return(DecodeC4(new FileReader(data), width, height, imagePalette, paletteFormat));

            case TextureFormats.C8:
                return(DecodeC8(new FileReader(data), width, height, imagePalette, paletteFormat));

            default:
                return(DecodeData(data, width, height, format));
            }
        }
Пример #8
0
 public static int GetDataSize(TextureFormats Format, int Width, int Height, bool adjjustByTileSize = true)
 {
     if (adjjustByTileSize)
     {
         while ((Width % TileSizeW[(uint)Format]) != 0)
         {
             Width++;
         }
         while ((Height % TileSizeH[(uint)Format]) != 0)
         {
             Height++;
         }
     }
     return(Width * Height * GetBpp(Format) / 8);
 }
Пример #9
0
        private string CreateJSON()
        {
            JSONClass JSON = new JSONClass();

            string[] ObjectNamesArray = new string[Objects.Count];

            for (int i = 0; i < Objects.Count; i++)
            {
                ObjectNamesArray[i] = this.Objects[i].Name;
            }

            int[][] RandomizationGroupsArray = new int[RandomizationGroups.Count][];

            for (int i = 0; i < RandomizationGroups.Count; i++)
            {
                int[] Group = RandomizationGroups[i].ToArray();
                RandomizationGroupsArray[i] = Group;
            }

            object[][] TilesArray = new object[765][];

            for (int i = 0; i < 765; i++)
            {
                TilesArray[i] = new object[3] {
                    Tiles[i].ID, Tiles[i].FlipX, Tiles[i].FlipY
                }
            }
            ;

            JSON.object_names         = ObjectNamesArray;
            JSON.randomization_groups = RandomizationGroupsArray;
            JSON.tiles           = TilesArray;
            JSON.textures        = Textures.ToArray();
            JSON.version         = Version;
            JSON.texture_formats = TextureFormats.ToArray();

            var    Serializer = new DataContractJsonSerializer(typeof(JSONClass));
            string JSONString = "";

            using (var MS = new MemoryStream())
            {
                Serializer.WriteObject(MS, JSON);
                JSONString = Encoding.Default.GetString(MS.ToArray());
            }

            return(JSONString);
        }
Пример #10
0
        private void ot_importImage_Click(object sender, EventArgs e)
        {
            if (ot_info_RomAddress.Text.Contains("N/A") || ot_info_RomAddress.Text.Contains("null"))
            {
                MessageBox.Show("Importing over compressed MIO0 data is not currently supported in this version. You will need to use an extended ROM file.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }
            string filename = LoadImage();

            if (filename != null)
            {
                Bitmap newImg =
                    new Bitmap(Image.FromFile(filename), new Size(ot_bitmap_preview.BackgroundImage.Width, ot_bitmap_preview.BackgroundImage.Height));
                byte format =
                    TextureFormats.ConvertStringToFormat(ot_info_Format.Text.Substring(ot_info_Format.Text.LastIndexOf(" ") + 1));
                byte[] data =
                    TextureFormats.encodeTexture(format, newImg);

                if (data != null)
                {
                    uint rom_offset =
                        uint.Parse(ot_info_RomAddress.Text.Substring(ot_info_RomAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    uint seg_offset =
                        uint.Parse(ot_info_SegAddress.Text.Substring(ot_info_SegAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    ROM.Instance.writeByteArray(rom_offset, data);
                    ROM.Instance.writeByteArrayToSegment(seg_offset, data);
                    Bitmap newImage = TextureFormats.decodeTexture(
                        format,
                        data,
                        ot_bitmap_preview.BackgroundImage.Width,
                        ot_bitmap_preview.BackgroundImage.Height,
                        null,
                        false
                        );
                    ot_bitmap_preview.BackgroundImage = newImage;
                    ReplaceButtonImage(ref ot_buttons[ot_list_index], newImage);
                    needToUpdateLevel = true;
                }
            }
        }
Пример #11
0
        private static byte[] DecodeData(FileReader stream, uint width, uint height, TextureFormats format, Palette imagePalette, PaletteFormats paletteFormat)
        {
            stream.SetByteOrder(true);

            switch (format)
            {
            case TextureFormats.I4:
                return(DecodeI4(stream, width, height));

            case TextureFormats.I8:
                return(DecodeI8(stream, width, height));

            case TextureFormats.IA4:
                return(DecodeIA4(stream, width, height));

            case TextureFormats.IA8:
                return(DecodeIA8(stream, width, height));

            case TextureFormats.RGB565:
                return(DecodeRgb565(stream, width, height));

            case TextureFormats.RGB5A3:
                return(DecodeRgb5A3(stream, width, height));

            case TextureFormats.RGBA32:
                return(DecodeRgba32(stream, width, height));

            case TextureFormats.C4:
                return(DecodeC4(stream, width, height, imagePalette, paletteFormat));

            case TextureFormats.C8:
                return(DecodeC8(stream, width, height, imagePalette, paletteFormat));

            case TextureFormats.CMPR:
                return(DecodeCmpr(stream, width, height));

            case TextureFormats.C14X2:
            default:
                Console.WriteLine("Unsupported Binary Texture Image format {0}, unable to decode!", format);
                return(new byte[0]);
            }
        }
Пример #12
0
        public static Tuple <byte[], ushort[]> EncodeData(byte[] m_rgbaImageData, TextureFormats Format, PaletteFormats PaletteFormat, int Width, int Height)
        {
            switch (Format)
            {
            case TextureFormats.I4:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.I4.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.I8:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.I8.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.IA4:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.IA4.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.IA8:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.IA8.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.RGB565:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.RGB565.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.RGB5A3:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.RGB5A3.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.RGBA32:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.Rgba32.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            case TextureFormats.C4:
                return(EncodeC4(PaletteFormat, m_rgbaImageData, Width, Height));

            case TextureFormats.C8:
                return(EncodeC8(PaletteFormat, m_rgbaImageData, Width, Height));

            case TextureFormats.CMPR:
                return(new Tuple <byte[], ushort[]>(ImageDataFormat.Cmpr.ConvertTo(m_rgbaImageData, Width, Height, null), new ushort[0]));

            default:
                return(new Tuple <byte[], ushort[]>(new byte[0], new ushort[0]));
            }
        }
Пример #13
0
        private void lt_importImage_Click(object sender, EventArgs e)
        {
            if (info_Format.Text.EndsWith("CI4") || info_Format.Text.EndsWith("CI8"))
            {
                MessageBox.Show("CI texture importing is not currently supported in this version.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }
            if (info_Address.Text.Contains("N/A") || info_Address.Text.Contains("null"))
            {
                MessageBox.Show("Importing over compressed MIO0 data is not currently supported in this version. You will need to use an extended ROM file.",
                                "Notice",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return;
            }

            string filename = LoadImage();

            if (filename != null)
            {
                Bitmap newImg = new Bitmap(Image.FromFile(filename), new Size(info_bitmapImage.BackgroundImage.Width, info_bitmapImage.BackgroundImage.Height));
                byte   format = TextureFormats.ConvertStringToFormat(info_Format.Text.Substring(info_Format.Text.LastIndexOf(" ") + 1));
                byte[] data   = TextureFormats.encodeTexture(format, newImg);

                if (data != null)
                {
                    uint rom_offset = uint.Parse(info_Address.Text.Substring(info_Address.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    uint seg_offset = uint.Parse(info_SegmentAddress.Text.Substring(info_SegmentAddress.Text.LastIndexOf(" ") + 1), System.Globalization.NumberStyles.HexNumber);
                    ROM.Instance.writeByteArray(rom_offset, data);
                    ROM.Instance.writeByteArrayToSegment(seg_offset, data);
                    Bitmap newImage = TextureFormats.decodeTexture(
                        format,
                        data,
                        info_bitmapImage.BackgroundImage.Width,
                        info_bitmapImage.BackgroundImage.Height,
                        null,
                        false
                        );
                    info_bitmapImage.BackgroundImage = newImage;

                    switch (lt_list_index)
                    {
                    case 0:
                        if (!ReplaceButtonImage(ref lt_levelButtons, newImage))
                        {
                            ReplaceButtonImage(ref lt_modelButtons, newImage);
                        }
                        break;

                    case 1:
                        ReplaceButtonImage(ref lt_levelButtons, newImage);
                        break;

                    case 2:
                        ReplaceButtonImage(ref lt_modelButtons, newImage);
                        break;

                    case 3:
                        ReplaceButtonImage(ref lt_objectButtons, newImage);
                        break;
                    }
                    needToUpdateLevel = true;
                }
            }
        }
Пример #14
0
 public static int GetDataSizeWithMips(TextureFormats format, uint Width, uint Height, uint MipCount)
 {
     return(GetDataSizeWithMips((uint)format, Width, Height, MipCount));
 }
Пример #15
0
 public static int GetBpp(TextureFormats Format)
 {
     return(Bpp[(uint)Format]);
 }
Пример #16
0
        public static byte[] GetMipLevel(byte[] ImageData, uint Width, uint Height, uint MipCount, uint MipLevel, TextureFormats format)
        {
            uint offset = 0;

            for (int m = 0; m < MipCount; m++)
            {
                uint width  = (uint)Math.Max(1, Width >> m);
                uint height = (uint)Math.Max(1, Height >> m);

                uint size = (uint)Decode_Gamecube.GetDataSize(format, (int)width, (int)height);

                if (MipLevel == m)
                {
                    return(Utils.SubArray(ImageData, offset, size));
                }

                offset += size;
            }

            return(ImageData);
        }
Пример #17
0
        private static byte[] DecodeData(EndianBinaryReader stream, uint width, uint height, TextureFormats format, Palette imagePalette, PaletteFormats paletteFormat)
        {
            switch (format)
            {
            case TextureFormats.I4:
                return(DecodeI4(stream, width, height));

            case TextureFormats.I8:
                return(DecodeI8(stream, width, height));

            case TextureFormats.IA4:
                return(DecodeIA4(stream, width, height));

            case TextureFormats.IA8:
                return(DecodeIA8(stream, width, height));

            case TextureFormats.RGB565:
                return(DecodeRgb565(stream, width, height));

            case TextureFormats.RGB5A3:
                return(DecodeRgb5A3(stream, width, height));

            case TextureFormats.RGBA32:
                return(DecodeRgba32(stream, width, height));

            case TextureFormats.C4:
                return(DecodeC4(stream, width, height, imagePalette, paletteFormat));

            case TextureFormats.C8:
                return(DecodeC8(stream, width, height, imagePalette, paletteFormat));

            case TextureFormats.CMPR:
                return(DecodeCmpr(stream, width, height));

            case TextureFormats.C14X2:
            default:
                WLog.Warning(LogCategory.Textures, null, "Unsupported Binary Texture Image format {0}, unable to decode!", format);
                return(new byte[0]);
            }
        }
Пример #18
0
        public static Tuple <byte[], ushort[]> EncodeFromBitmap(System.Drawing.Bitmap bitmap, TextureFormats Format, PaletteFormats PaletteFormat = PaletteFormats.RGB565)
        {
            byte[] m_rgbaImageData = new byte[bitmap.Width * bitmap.Height * 4];

            int width  = bitmap.Width;
            int height = bitmap.Height;

            BitmapData dat = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            Marshal.Copy(dat.Scan0, m_rgbaImageData, 0, m_rgbaImageData.Length);
            bitmap.UnlockBits(dat);
            bitmap.Dispose();

            return(EncodeData(m_rgbaImageData, Format, PaletteFormat, width, height));
        }
Пример #19
0
        private List <RadioButtonWithInfo> parseOtherListJSON(JArray array, out string blockName)
        {
            ROM rom = ROM.Instance;

            blockName = "Unknown";
            List <RadioButtonWithInfo> list   = new List <RadioButtonWithInfo>();
            uint segmentAddressForLoadingData = 0;

            byte[][] tempSegments        = new byte[0x20][];
            uint[]   tempSegmentStarts   = new uint[0x20];
            bool[]   tempSegmentsAreMIO0 = new bool[0x20];

            foreach (JObject obj in array.Children())
            {
                if (obj["Block Name"] != null)
                {
                    blockName = obj["Block Name"].ToString();
                    segmentAddressForLoadingData = 0; // Reset for every new block
                }
                else if (obj["UseSegmentAddressesFromLevelScriptStartingFrom"] != null)
                {
                    segmentAddressForLoadingData = uint.Parse(obj["UseSegmentAddressesFromLevelScriptStartingFrom"].ToString(), NumberStyles.HexNumber);
                    for (int i = 0; i < 0x20; i++)
                    {
                        tempSegments[i]        = new byte[0]; // reset segments
                        tempSegmentsAreMIO0[i] = false;
                        tempSegmentStarts[i]   = 0;
                    }
                    tempSegments[0x00]        = rom.Bytes;
                    tempSegments[0x15]        = rom.cloneSegment(0x15, (byte)level.CurrentAreaID);
                    tempSegmentStarts[0x15]   = Globals.seg15_location[0];
                    tempSegments[0x02]        = rom.cloneSegment(0x02, (byte)level.CurrentAreaID);
                    tempSegmentStarts[0x02]   = Globals.seg02_location[0];
                    tempSegmentsAreMIO0[0x02] = !rom.Seg02_isFakeMIO0;
                    //Console.WriteLine("SegOff:0x{0}", segmentAddressForLoadingData.ToString("X8"));
                    parseLevelScriptTemporarlyForSegments(tempSegments, tempSegmentStarts, tempSegmentsAreMIO0, (byte)(segmentAddressForLoadingData >> 24), segmentAddressForLoadingData & 0xFFFFFF);
                }
                else
                {
                    if (checkForValidEntry(obj))
                    {
                        int    width    = int.Parse(obj["Width"].ToString());
                        int    height   = int.Parse(obj["Height"].ToString());
                        byte   format   = TextureFormats.ConvertStringToFormat(obj["Format"].ToString());
                        uint   dataSize = (uint)((TextureFormats.getNumberOfBitsForFormat(format) * width * height) / 8);
                        byte[] data;
                        if (obj["FromSegmentAddress"] != null)
                        {
                            uint segOffset = uint.Parse(obj["FromSegmentAddress"].ToString(), NumberStyles.HexNumber);
                            if (segmentAddressForLoadingData == 0)
                            {
                                data = rom.getDataFromSegmentAddress_safe(segOffset, dataSize, (byte)level.CurrentAreaID);
                            }
                            else
                            {
                                byte segment     = (byte)(segOffset >> 24);
                                uint segment_off = segOffset & 0x00FFFFFF;
                                data = rom.getSubArray_safe(tempSegments[segment], segment_off, dataSize);
                            }
                        }
                        else
                        {
                            if (rom.Type == ROM_Type.VANILLA && obj["ForExtendedROM"] != null)
                            {
                                string forExtendedROM = obj["ForExtendedROM"].ToString().ToLower();
                                if (forExtendedROM.Equals("true"))
                                {
                                    continue;
                                }
                            }
                            uint romOff = uint.Parse(obj["FromROMAddress"].ToString(), NumberStyles.HexNumber);
                            data = rom.getSubArray_safe(rom.Bytes, romOff, dataSize);
                        }
                        Bitmap   image = TextureFormats.decodeTexture(format, data, width, height, null, true);
                        string[] tags  = (string[])image.Tag;
                        Array.Resize(ref tags, tags.Length + 3);
                        uint segOff = 0;
                        if (obj["FromSegmentAddress"] != null)
                        {
                            segOff = uint.Parse(obj["FromSegmentAddress"].ToString(), NumberStyles.HexNumber);


                            if (segmentAddressForLoadingData == 0)
                            {
                                if (!rom.isSegmentMIO0((byte)(segOff >> 24), (byte)level.CurrentAreaID))
                                {
                                    tags[tags.Length - 3] = "ROM Address: " + rom.decodeSegmentAddress(segOff, (byte)level.CurrentAreaID).ToString("X");
                                }
                                else
                                {
                                    tags[tags.Length - 3] = "ROM Address: N/A";
                                }
                            }
                            else
                            {
                                byte seg_temp        = (byte)(segOff >> 24);
                                uint seg_temp_offset = segOff & 0x00FFFFFF;
                                if (tempSegmentsAreMIO0[seg_temp])
                                {
                                    tags[tags.Length - 3] = "ROM Address: N/A";
                                }
                                else
                                {
                                    tags[tags.Length - 3] = "ROM Address: " + (tempSegmentStarts[seg_temp] + seg_temp_offset).ToString("X");
                                }
                            }

                            tags[tags.Length - 2] = "Seg Addr: " + obj["FromSegmentAddress"];
                        }
                        else
                        {
                            tags[tags.Length - 3] = "ROM Address: " + obj["FromROMAddress"];
                            tags[tags.Length - 2] = "Seg Addr: N/A";
                        }
                        tags[tags.Length - 1] = "Name: " + obj["Name"];
                        image.Tag             = tags;

                        AddNewImage(ref list, image, segOff, ot_RadioButtonWithInfo_Click);

                        //Console.WriteLine("Added Other Image: " + obj["Name"]);
                    }
                    //Bitmap image = TextureFormats.decodeTexture();
                    //AddNewImage(ref list, level.ModelIDs[modelID].builder.TextureImages[i], address, ot_RadioButtonWithInfo_Click);
                }
                //Console.WriteLine(obj.ToString());
            }
            return(list);
        }
 public static byte[] EncodeData(Bitmap bmp, uint width, uint height, TextureFormats format)
 {
     switch (format)
     {
         case TextureFormats.I4:
             return EncodeI4(bmp, width, height);
         default:
             return new byte[0];
     }
 }
Пример #21
0
 public static System.Drawing.Bitmap DecodeDataToBitmap(byte[] ImageData, ushort[] PaletteData, uint width, uint height, TextureFormats format, PaletteFormats palleteFormat)
 {
     return(BitmapExtension.GetBitmap(DecodeData(ImageData, PaletteData, width, height, format, palleteFormat),
                                      (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb));
 }
Пример #22
0
        public static byte[] DecodeData(byte[] ImageData, byte[] PaletteData, uint width, uint height, TextureFormats format, PaletteFormats palleteFormat)
        {
            Palette Palette = new Palette();

            Palette.Load(PaletteData);

            return(DecodeData(new FileReader(ImageData), width, height, format, Palette, palleteFormat));
        }
Пример #23
0
 public void SetTextureFormat(TextureFormats format)
 {
     TextureFormat = format;
     Unbind();
 }
Пример #24
0
 private static byte[] DecodeData(EndianBinaryReader stream, uint width, uint height, TextureFormats format, Palette imagePalette, PaletteFormats paletteFormat)
 {
     switch (format)
     {
         case TextureFormats.I4:
             return DecodeI4(stream, width, height);
         case TextureFormats.I8:
             return DecodeI8(stream, width, height);
         case TextureFormats.IA4:
             return DecodeIA4(stream, width, height);
         case TextureFormats.IA8:
             return DecodeIA8(stream, width, height);
         case TextureFormats.RGB565:
             return DecodeRgb565(stream, width, height);
         case TextureFormats.RGB5A3:
             return DecodeRgb5A3(stream, width, height);
         case TextureFormats.RGBA32:
             return DecodeRgba32(stream, width, height);
         case TextureFormats.C4:
             return DecodeC4(stream, width, height, imagePalette, paletteFormat);
         case TextureFormats.C8:
             return DecodeC8(stream, width, height, imagePalette, paletteFormat);
         case TextureFormats.CMPR:
             return DecodeCmpr(stream, width, height);
         case TextureFormats.C14X2:
         default:
             WLog.Warning(LogCategory.Textures, null, "Unsupported Binary Texture Image format {0}, unable to decode!", format);
             return new byte[0];
     }
 }
Пример #25
0
            private Wavefront.Material GenerateMaterial(Wavefront.Model Model)
            {
                Wavefront.MaterialFilter Kd    = default(Wavefront.MaterialFilter);
                Wavefront.MaterialMap    map_d = default(Wavefront.MaterialMap);

                if (material.HasMaterialColor)
                {
                    var color = (Color4b)material.light.Light1.Color;

                    Kd = new Wavefront.MaterialFilter(color.r, color.g, color.b);
                }
                Wavefront.Image image = null;
                if (material.HasTexture)
                {
                    byte[] pixels = new byte[(texture.Width * texture.Height) << 2];
                    GL.GetTextureImage(texture.ID, 0, PixelFormat.Rgba, PixelType.UnsignedInt8888, pixels.Length, pixels);
                    for (int i = (texture.Width * texture.Height) - 1; i >= 0; i--)
                    {
                        byte r = pixels[(i << 2) | 1];
                        byte g = pixels[(i << 2) | 2];
                        byte b = pixels[(i << 2) | 3];
                        byte a = pixels[(i << 2) | 0];

                        pixels[(i << 2) | 0] = r;
                        pixels[(i << 2) | 1] = g;
                        pixels[(i << 2) | 2] = b;
                        pixels[(i << 2) | 3] = a;
                    }
                    image = Model.Images[new Wavefront.Image(pixels, (ushort)texture.Width, (ushort)texture.Height)];

                    map_d = new Wavefront.MaterialMap(
                        image,
                        Clamp: (material.HasClampUV) ? true : (bool?)null,
                        AutoTexRes: true);
                }

                var map_Ka = map_d;

                if (!map_d.IsOmitted)
                {
                    if (
                        TextureFormats.GetFormat(material.format).AlphaDepth == 0 ||
                        (!image.AlphaVariance && image.AlphaValue == 255))
                    {
                        map_d = default(Wavefront.MaterialMap);
                    }
                    else
                    {
                        map_d = new Wavefront.MaterialMap(ref map_d,
                                                          Channel: Wavefront.TextureChannel.Matte);
                    }
                }

                return(Model.Materials[new Wavefront.Material(
                                           Kd: Kd,
                                           Ka: Kd,
                                           map_Ka: map_Ka,
                                           map_Kd: map_Ka,
                                           map_d: map_d,
                                           d: map_d.IsOmitted ? default(Wavefront.MaterialD) : (Wavefront.MaterialD) 0.0,
                                           illum: material.CalcuateDefaultIlluminationMode(image == (object)null ? true : (!image.AlphaVariance && image.AlphaValue == 255))
                                           )]);
            }