コード例 #1
0
        private static byte[] IndexToColor(ACE.DatLoader.FileTypes.Texture texture, bool isClipMap = false, PaletteChanges paletteChanges = null)
        {
            var colors = GetColors(texture);

            var palette = DatManager.PortalDat.ReadFromDat <Palette>((uint)texture.DefaultPaletteId);

            // Make a copy of the Palette Colors, so we don't inadvertently save them back to the dat File Cache
            var paletteColors = palette.Colors.ToList();

            // Apply any custom palette colors, if any, to our loaded palette (note, this may be all of them!)
            if (paletteChanges != null)
            {
                for (var i = 0; i < paletteChanges.CloSubPalettes.Count; i++)
                {
                    var subpalette = paletteChanges.CloSubPalettes[i];

                    var newPalette = DatManager.PortalDat.ReadFromDat <Palette>(paletteChanges.PaletteIds[i]);

                    foreach (var range in subpalette.Ranges)
                    {
                        var offset    = (int)range.Offset;
                        var numColors = (int)range.NumColors;

                        for (var j = 0; j < numColors; j++)
                        {
                            paletteColors[j + offset] = newPalette.Colors[j + offset];
                        }
                    }
                }
            }

            var output = new byte[texture.Width * texture.Height * 4];

            for (int i = 0; i < texture.Height; i++)
            {
                for (int j = 0; j < texture.Width; j++)
                {
                    int idx          = (i * texture.Width) + j;
                    var color        = colors[idx];
                    var paletteColor = paletteColors[color];

                    byte a = Convert.ToByte((paletteColor & 0xFF000000) >> 24);
                    byte r = Convert.ToByte((paletteColor & 0xFF0000) >> 16);
                    byte g = Convert.ToByte((paletteColor & 0xFF00) >> 8);
                    byte b = Convert.ToByte(paletteColor & 0xFF);

                    if (isClipMap && color < 8)
                    {
                        r = g = b = a = 0;
                    }

                    output[idx * 4]     = r;
                    output[idx * 4 + 1] = g;
                    output[idx * 4 + 2] = b;
                    output[idx * 4 + 3] = a;
                }
            }
            return(output);
        }
コード例 #2
0
ファイル: TextureCache.cs プロジェクト: havalina1/ACViewer
        private static List <int> GetColors(ACE.DatLoader.FileTypes.Texture texture)
        {
            var colors = new List <int>();

            using (BinaryReader reader = new BinaryReader(new MemoryStream(texture.SourceData)))
            {
                for (uint y = 0; y < texture.Height; y++)
                {
                    for (uint x = 0; x < texture.Width; x++)
                    {
                        colors.Add(reader.ReadInt16());
                    }
                }
            }
            return(colors);
        }
コード例 #3
0
ファイル: TextureCache.cs プロジェクト: havalina1/ACViewer
        private static byte[] IndexToColor(ACE.DatLoader.FileTypes.Texture texture, bool isClipMap = false)
        {
            var colors  = GetColors(texture);
            var palette = DatManager.PortalDat.ReadFromDat <Palette>((uint)texture.DefaultPaletteId);

            // Apply any custom palette colors, if any, to our loaded palette (note, this may be all of them!)
            if (texture.CustomPaletteColors.Count > 0)
            {
                foreach (var entry in texture.CustomPaletteColors)
                {
                    if (entry.Key <= palette.Colors.Count)
                    {
                        palette.Colors[entry.Key] = entry.Value;
                    }
                }
            }

            var output = new byte[texture.Width * texture.Height * 4];

            for (int i = 0; i < texture.Height; i++)
            {
                for (int j = 0; j < texture.Width; j++)
                {
                    int idx          = (i * texture.Width) + j;
                    var color        = colors[idx];
                    var paletteColor = palette.Colors[color];

                    byte a = Convert.ToByte((paletteColor & 0xFF000000) >> 24);
                    byte r = Convert.ToByte((paletteColor & 0xFF0000) >> 16);
                    byte g = Convert.ToByte((paletteColor & 0xFF00) >> 8);
                    byte b = Convert.ToByte(paletteColor & 0xFF);

                    if (isClipMap && color < 8)
                    {
                        r = g = b = a = 0;
                    }

                    output[idx * 4]     = r;
                    output[idx * 4 + 1] = g;
                    output[idx * 4 + 2] = b;
                    output[idx * 4 + 3] = a;
                }
            }

            return(output);
        }