Exemple #1
0
        void HandleAdd(Player p, string[] args)
        {
            if (args.Length != 4)
            {
                Help(p); return;
            }

            ImagePalette palette = ImagePalette.Find(args[1]);

            if (palette == null)
            {
                p.Message("Palette {0} does not exist.", args[1]); return;
            }

            BlockID block;

            if (!CommandParser.GetBlock(p, args[2], out block))
            {
                return;
            }

            ColorDesc rgb = default(ColorDesc);

            if (!CommandParser.GetHex(p, args[3], ref rgb))
            {
                return;
            }
            PaletteEntry entry = new PaletteEntry(rgb.R, rgb.G, rgb.B, block);

            AddEntry(p, palette, entry);
        }
        private void GrowPalette()
        {
            // Decode the indices
            int[] indices = new int[_size];
            for (int i = 0; i < _size; i++)
            {
                indices[i] = (int)_data.GetBits(i * indicesLength, indicesLength).Data;
            }

            // Create a new palette, double the size
            indicesLength = indicesLength << 1;

            PaletteEntry[] newPalette = new PaletteEntry[(int)MathF.Pow(2, indicesLength)];
            int            k          = 0;

            for (int i = 0; i < palette.Length; i++)
            {
                if (palette[i] != null && palette[i].refcount > 0)
                {
                    newPalette[k++] = palette[i];
                }
            }
            palette = newPalette;

            _data = new BitBuffer(_size * indicesLength);

            for (int i = 0; i < indices.Length; i++)
            {
                _data.SetBits(i * indicesLength, indicesLength, new BitArray32((uint)indices[i]));
            }
        }
Exemple #3
0
    private void GrowPalette()
    {
        // decode the indices
        int[] indices = new int[size];
        for (int i = 0; i < indices.Length; i++)
        {
            indices[i] = data.Get(i, indicesLength);
        }

        // Create new palette, doubling it in size
        indicesLength = indicesLength << 1;
        PaletteEntry[] newPalette = new PaletteEntry[indicesLength];
        System.Array.Copy(palette, 0, newPalette, 0, paletteCount);
        palette = newPalette;

        // Allocate new BitBuffer
        data = new BitBuffer(size * newPalette.Length); // this is bits, not bytes!
        Debug.Log("New Palette size: " + newPalette.Length);
        Debug.Log("New ByteBitBuffer size: " + size * newPalette.Length + " bytes");

        // Encode the indices
        for (int i = 0; i < indices.Length; i++)
        {
            data.Set(i, indicesLength, indices[i]);
        }
    }
Exemple #4
0
 static PaletteEntry Multiply(PaletteEntry entry, ColorDesc rgb)
 {
     entry.R = (byte)(entry.R * rgb.R / 255);
     entry.G = (byte)(entry.G * rgb.G / 255);
     entry.B = (byte)(entry.B * rgb.B / 255);
     return(entry);
 }
Exemple #5
0
        void CalcLayerColors()
        {
            PaletteEntry[] front = new PaletteEntry[Palette.Entries.Length];
            PaletteEntry[] back  = new PaletteEntry[Palette.Entries.Length];

            ColorDesc sun, dark, bright;

            if (!Colors.TryParseHex(Level.Config.LightColor, out sun))
            {
                sun = Colors.ParseHex("FFFFFF");
            }
            if (!Colors.TryParseHex(Level.Config.ShadowColor, out dark))
            {
                dark = Colors.ParseHex("9B9B9B");
            }
            bright = Colors.ParseHex("FFFFFF");

            for (int i = 0; i < Palette.Entries.Length; i++)
            {
                PaletteEntry    entry = Palette.Entries[i];
                BlockDefinition def   = Level.GetBlockDef(entry.Block);

                if (def != null && def.FullBright)
                {
                    front[i] = Multiply(entry, bright);
                    back[i]  = Multiply(entry, bright);
                }
                else
                {
                    front[i] = Multiply(entry, sun);
                    back[i]  = Multiply(entry, dark);
                }
            }
            selector.SetPalette(front, back);
        }
        public void ColorTest()
        {
            PaletteEntry paletteEntry = new PaletteEntry(10, Color.FromArgb(128, 10, 20, 30));
            Assert.AreEqual(Color.FromArgb(128, 10, 20, 30), paletteEntry.Color);

            paletteEntry.Color = Colors.Cyan;
            Assert.AreEqual(Colors.Cyan, paletteEntry.Color);
        }
        public void ValueTest()
        {
            PaletteEntry paletteEntry = new PaletteEntry(10, Color.FromArgb(128, 10, 20, 30));
            Assert.AreEqual(10, paletteEntry.Value);

            paletteEntry.Value = -10;
            Assert.AreEqual(-10, paletteEntry.Value);
        }
Exemple #8
0
    // Shrink the palette (and thus the BitBuffer) every now and then.
    // You may need to apply heuristics to determine when to do this.
    public void FitPalette()
    {
        // Remove old entries...
        for (int i = 0; i < palette.Length; i++)
        {
            if (palette[i].refcount == 0)
            {
                palette[i].blockID = 0;
                paletteCount      -= 1;
            }
        }

        // Is the palette less than half of its closest power-of-two?
        if (paletteCount > Mathf.Pow(paletteCount, 2f) / 2)
        {
            // NO: The palette cannot be shrunk!
            return;
        }

        // decode all indices
        int[] indices = new int[size];
        for (int i = 0; i < indices.Length; i++)
        {
            indices[i] = data.Get(i, indicesLength);
        }

        // Create new palette, halfing it in size
        indicesLength = indicesLength >> 1;
        PaletteEntry[] newPalette = new PaletteEntry[Mathf.FloorToInt(Mathf.Pow(2f, (float)indicesLength))];

        // We gotta compress the palette entries!
        int paletteCounter = 0;

        for (int pi = 0; pi < palette.Length; pi++, paletteCounter++)
        {
            PaletteEntry entry = newPalette[paletteCounter] = palette[pi];

            // Re-encode the indices (find and replace; with limit)
            for (int di = 0, fc = 0; di < indices.Length && fc < entry.refcount; di++)
            {
                if (pi == indices[di])
                {
                    indices[di] = paletteCounter;
                    fc         += 1;
                }
            }
        }

        // Allocate new BitBuffer
        data = new BitBuffer(size * newPalette.Length); // this is bits, not bytes!

        // Encode the indices
        for (int i = 0; i < indices.Length; i++)
        {
            data.Set(i, indicesLength, indices[i]);
        }
    }
 public BlockStorage(int size)
 {
     this._size         = size;
     this.indicesLength = 1;
     this.paletteCount  = 0;
     this.palette       = new PaletteEntry[1 << indicesLength];
     this._data         = new BitBuffer(size * indicesLength);
     palette[0]         = new PaletteEntry(size, 0);
 }
 public void ToStringTest()
 {
     PaletteEntry paletteEntry1 = new PaletteEntry();
     PaletteEntry paletteEntry2 = new PaletteEntry(1, Colors.Black);
     string s1 = paletteEntry1.ToString();
     string s2 = paletteEntry2.ToString();
     Assert.IsNotNull(s1);
     Assert.IsNotNull(s2);
     Assert.AreNotEqual(s1, s2);
 }
        public void GetHashCodeTest()
        {
            PaletteEntry paletteEntry = new PaletteEntry();
            PaletteEntry paletteEntry2 = new PaletteEntry(0, Colors.Black);
            PaletteEntry paletteEntry3 = new PaletteEntry(1, new Color());

            Assert.AreNotEqual(paletteEntry.GetHashCode(), paletteEntry2.GetHashCode());
            Assert.AreNotEqual(paletteEntry.GetHashCode(), paletteEntry3.GetHashCode());
            Assert.AreNotEqual(paletteEntry2.GetHashCode(), paletteEntry3.GetHashCode());
        }
        public void ConstructorTest2()
        {
            PaletteEntry paletteEntry = new PaletteEntry(0, new Color());
            Assert.AreEqual(0, paletteEntry.Value);
            Assert.AreEqual(new Color(), paletteEntry.Color);

            paletteEntry = new PaletteEntry(1, Colors.Red);
            Assert.AreEqual(1, paletteEntry.Value);
            Assert.AreEqual(Colors.Red, paletteEntry.Color);
        }
Exemple #13
0
        Color GetSeriesColor(Series series, ChartControl chartControl)
        {
            int          seriesIndex    = chartControl.Series.IndexOf(series);
            string       paletteName    = chartControl.PaletteName;
            Palette      currentPalette = chartControl.PaletteRepository[paletteName];
            PaletteEntry paletteEntryAccordingToSeries = currentPalette[seriesIndex];
            Color        result = paletteEntryAccordingToSeries.Color;

            return(result);
        }
Exemple #14
0
 public void Set(int index, byte r, byte g, byte b, int priority) {
     _entries[index] = new PaletteEntry();
     _entries[index].Index = index;
     _entries[index].Color.A = 255;
     _entries[index].Color.R = r;
     _entries[index].Color.G = g;
     _entries[index].Color.B = b;
     _entries[index].Priority = priority;
     _isCompiled = false;
 }
Exemple #15
0
        private static void CreateStudyProgressPalette()
        {
            var entry1 = new PaletteEntry(Color.FromArgb(124, 186, 180), Color.FromArgb(127, 192, 185));
            var entry2 = new PaletteEntry(Color.FromArgb(146, 199, 226), Color.FromArgb(117, 181, 214));
            var entry3 = new PaletteEntry(Color.FromArgb(183, 140, 155), Color.FromArgb(200, 164, 176));
            var entry4 = new PaletteEntry(Color.FromArgb(242, 202, 132), Color.FromArgb(246, 211, 149));
            var entry5 = new PaletteEntry(Color.FromArgb(167, 202, 116), Color.FromArgb(172, 206, 118));

            studyProgressPalette = new Palette(StudyProgressPaletteName,
                                               new[] { entry1, entry2, entry3, entry4, entry5 });
        }
        private static void CreateStudyProgressPalette()
        {
            var entry1 = new PaletteEntry(Color.FromArgb(124, 186, 180), Color.FromArgb(127, 192, 185));
            var entry2 = new PaletteEntry(Color.FromArgb(146, 199, 226), Color.FromArgb(117, 181, 214));
            var entry3 = new PaletteEntry(Color.FromArgb(183, 140, 155), Color.FromArgb(200, 164, 176));
            var entry4 = new PaletteEntry(Color.FromArgb(242, 202, 132), Color.FromArgb(246, 211, 149));
            var entry5 = new PaletteEntry(Color.FromArgb(167, 202, 116), Color.FromArgb(172, 206, 118));

            studyProgressPalette = new Palette(StudyProgressPaletteName,
                new[] {entry1, entry2, entry3, entry4, entry5});
        }
        // Shrink the palette because it may be too big (old entries removed)
        private void FitPalette()
        {
            for (int i = 0; i < palette.Length; i++)
            {
                // Remove old entries
                if (palette[i] != null && palette[i].refcount == 0)
                {
                    palette[i]    = null;
                    paletteCount -= 1;
                }
            }


            if (paletteCount > PowerOfTwo(paletteCount) / 2)
            {
                // Cannot shrink palette
                return;
            }

            int[] indices = new int[_size];
            for (int i = 0; i < _size; i++)
            {
                indices[i] = (int)_data.GetBits(i * indicesLength, indicesLength).Data;
            }

            indicesLength = indicesLength >> 1;
            PaletteEntry[] newPalette = new PaletteEntry[(int)MathF.Pow(2, indicesLength)];

            int paletteCounter = 0;

            for (int pi = 0; pi < palette.Length; pi++, paletteCounter++)
            {
                PaletteEntry entry = newPalette[paletteCounter] = palette[pi];

                for (int di = 0, fc = 0; di < indicesLength && fc < entry.refcount; di++)
                {
                    if (pi == indices[di])
                    {
                        indices[di] = paletteCounter;
                        fc         += 1;
                    }
                }
            }

            // allocate a new bitbuffer
            _data = new BitBuffer(_size * indicesLength);

            // Reencode indices
            for (int i = 0; i < indices.Length; i++)
            {
                _data.SetBits(i * indicesLength, indicesLength, new BitArray32((uint)indices[i]));
            }
        }
Exemple #18
0
    public void SetBlock(int index, int blockID)
    {
        int paletteIndex = data.Get(index, indicesLength /*, true*/);

        if (paletteIndex < 0 || paletteIndex > palette.Length - 1)
        {
            Debug.LogError("paletteIndex: " + paletteIndex);
            return;
        }
        PaletteEntry current = palette[paletteIndex];

        // Whatever block is there will cease to exist in but a moment...
        current.refcount -= 1;

        // The following steps/choices *must* be ordered like they are.

        // --- Is the block-type already in the palette?
        int currentPaletteIndex = System.Array.FindIndex <PaletteEntry>(palette, entry => { return(entry.blockID.Equals(blockID)); });

        if (currentPaletteIndex != -1)
        {
            //Debug.LogError("Already in palette: " + type.ToString());
            // YES: Use the existing palette entry.
            data.Set(index, indicesLength, currentPaletteIndex);
            palette[currentPaletteIndex].refcount += 1;
            return;
        }

        // --- Can we overwrite the current palette entry?
        if (current.refcount == 0)
        {
            Debug.Log("Overwrite current palette entry");
            // YES, we can!
            current.blockID  = blockID;
            current.refcount = 1;
            return;
        }

        Debug.Log("Add new Palette:" + blockID.ToString());
        // --- A new palette entry is needed!

        // Get the first free palette entry, possibly growing the palette!
        int newEntry = NewPaletteEntry();

        palette[newEntry] = new PaletteEntry {
            refcount = 1, blockID = blockID
        };
        data.Set(index, indicesLength, newEntry /*, true*/);
        paletteCount += 1;
    }
Exemple #19
0
        /// <summary>
        /// Returns a PaletteEntry array from a quantized image
        /// </summary>
        /// <typeparam name="TPixel"></typeparam>
        /// <param name="quantized">Quantized image</param>
        /// <returns>Array of Palette Entries</returns>
        private PaletteEntry[] GetPalette <TPixel>(IndexedImageFrame <TPixel> quantized) where TPixel : unmanaged, IPixel <TPixel>
        {
            ReadOnlySpan <TPixel> sourcePalette = quantized.Palette.Span;
            int paletteLength = sourcePalette.Length;

            PaletteEntry[] destinationPalette = new PaletteEntry[paletteLength];
            for (int i = 0; i < paletteLength; i++)
            {
                Rgba32 rgba = new Rgba32();
                sourcePalette[i].ToRgba32(ref rgba);
                destinationPalette[i] = new PaletteEntry(rgba.A, rgba.R, rgba.G, rgba.B);
            }
            return(destinationPalette);
        }
        public void EqualsTest()
        {
            PaletteEntry paletteEntry = new PaletteEntry();
            PaletteEntry paletteEntry2 = new PaletteEntry(0, Colors.Black);
            PaletteEntry paletteEntry3 = new PaletteEntry(1, new Color());

            Assert.IsTrue(paletteEntry.Equals(paletteEntry));
            Assert.IsTrue(paletteEntry.Equals((object)paletteEntry));
            Assert.IsFalse(paletteEntry.Equals(paletteEntry2));
            Assert.IsFalse(paletteEntry.Equals(paletteEntry3));
            Assert.IsFalse(paletteEntry2.Equals(paletteEntry3));

            Assert.IsFalse(paletteEntry.Equals(null));
            Assert.IsFalse(paletteEntry.Equals(new Color()));
        }
Exemple #21
0
        static void AddEntry(Player p, ImagePalette palette, PaletteEntry entry)
        {
            PaletteEntry[]      entries    = palette.Entries;
            List <PaletteEntry> newEntries = new List <PaletteEntry>();

            if (entries != null)
            {
                newEntries.AddRange(entries);
            }

            newEntries.Add(entry);
            palette.Entries = newEntries.ToArray();
            palette.Save();
            p.Message("Added block to entries of palette {0}", palette.Name);
        }
        private RadCartesianChartView createChart()
        {
            //Create the Chart View
            RadCartesianChartView chart = new RadCartesianChartView(this.Activity);

            LinearAxis verticalAxis = new LinearAxis();

            //The values in the linear axis will not have values after the decimal point.
            verticalAxis.LabelFormat = "%.0f";
            CategoricalAxis horizontalAxis = new CategoricalAxis();

            chart.VerticalAxis   = verticalAxis;
            chart.HorizontalAxis = horizontalAxis;


            for (int i = 0; i < 3; i++)
            {
                //Create the bar series and attach axes and value bindings.
                AreaSeries areaSeries = new AreaSeries();

                //We want to stack the different area series.
                areaSeries.CombineMode = ChartSeriesCombineMode.Stack;

                areaSeries.ValueBinding    = new ValueBinding();
                areaSeries.CategoryBinding = new CategoryBinding();

                //Bind series to data
                areaSeries.Data = this.getData();

                //Add series to chart
                chart.Series.Add(areaSeries);
            }

            ChartPalette defaultPaletteClone = new ChartPalette(chart.Palette);

            // We acquire the palette entry containing the settings for the third series in the chart setup.
            PaletteEntry areaSeriesEntry = defaultPaletteClone.GetEntry(ChartPalette.AreaFamily, 2);

            //We set the fill color of the third series to be cyan.
            areaSeriesEntry.Fill = Color.Cyan;

            //We reset the chart palette by applying the new one.
            chart.Palette = defaultPaletteClone;

            return(chart);
        }
        private static PaletteEntry GetClosestPaletteEntry(PaletteEntry[] palette, HdrColor color)
        {
            PaletteEntry closestEntry    = null;
            var          closestDistance = double.PositiveInfinity;

            for (var palleteIndex = 0; palleteIndex < palette.Length; palleteIndex++)
            {
                var currentEntry    = palette[palleteIndex];
                var currentDistance = (currentEntry.Color - color).Length;

                if (currentDistance < closestDistance)
                {
                    closestEntry    = currentEntry;
                    closestDistance = currentDistance;
                }
            }

            return(closestEntry);
        }
        // Setting the wrong bit :eyesBlur:
        public void SetBlock(int index, int blockType)
        {
            // Get the type of block at that position
            int          paletteIndex = (int)_data.GetBits(index * indicesLength, indicesLength).Data;
            PaletteEntry current      = palette[paletteIndex];

            // That block at the position no longer exists, so one less reference of the block in the palette
            current.refcount -= 1;

            // Is the block type already in the palette
            int replace = -1;

            for (int i = 0; i < palette.Length; i++)
            {
                if (palette[i] != null && palette[i].type == blockType)
                {
                    replace = i;
                    break;
                }
            }
            if (replace != -1)
            {
                _data.SetBits(index * indicesLength, indicesLength, new BitArray32((uint)replace));
                palette[replace].refcount += 1;
                return;
            }

            // Otherwise if we can overwrite the current palette entry
            if (current.refcount == 0)
            {
                current.type     = blockType;
                current.refcount = 1;
                return;
            }

            // A new palette entry is needed!
            int newEntry = NewPaletteEntry();

            palette[newEntry] = new PaletteEntry(1, blockType);
            _data.SetBits(index * indicesLength, indicesLength, new BitArray32((uint)newEntry));
            paletteCount += 1;
        }
        private static PaletteEntry[] GeneratePalette(HdrColor[] subPixelColors)
        {
            var palette = new PaletteEntry[1 << subPixelColors.Length];

            for (var paletteIndex = 0; paletteIndex < palette.Length; paletteIndex++)
            {
                var currentColor = new HdrColor();
                var outputColor  = new bool[subPixelColors.Length];

                for (var subPixelIndex = 0; subPixelIndex < subPixelColors.Length; subPixelIndex++)
                {
                    if (((paletteIndex >> subPixelIndex) & 1) == 1)
                    {
                        currentColor += subPixelColors[subPixelIndex];
                        outputColor[subPixelIndex] = true;
                    }
                }

                palette[paletteIndex] = new PaletteEntry(currentColor, outputColor);
            }

            return(palette);
        }
Exemple #26
0
        void CalcLayerColors()
        {
            PaletteEntry[] front = new PaletteEntry[Palette.Entries.Length];
            PaletteEntry[] back  = new PaletteEntry[Palette.Entries.Length];

            ColorDesc sun  = Colors.ParseHex("FFFFFF");
            ColorDesc dark = Colors.ParseHex("9B9B9B");

            if (Utils.IsValidHex(Level.Config.LightColor))
            {
                sun = Colors.ParseHex(Level.Config.LightColor);
            }
            if (Utils.IsValidHex(Level.Config.ShadowColor))
            {
                dark = Colors.ParseHex(Level.Config.ShadowColor);
            }

            for (int i = 0; i < Palette.Entries.Length; i++)
            {
                PaletteEntry    entry = Palette.Entries[i];
                ExtBlock        block = ExtBlock.FromRaw(entry.Raw);
                BlockDefinition def   = Level.GetBlockDef(block);

                if (def != null && def.FullBright)
                {
                    front[i] = Multiply(entry, Colors.ParseHex("FFFFFF"));
                    back[i]  = Multiply(entry, Colors.ParseHex("FFFFFF"));
                }
                else
                {
                    front[i] = Multiply(entry, sun);
                    back[i]  = Multiply(entry, dark);
                }
            }
            selector.SetPalette(front, back);
        }
Exemple #27
0
 static string FormatEntry(PaletteEntry e, Player p)
 {
     return(Block.GetName(p, e.Block) + " - " + Utils.Hex(e.R, e.G, e.B));
 }
 public void ConstructorTest()
 {
     PaletteEntry paletteEntry = new PaletteEntry();
     Assert.AreEqual(0, paletteEntry.Value);
     Assert.AreEqual(new Color(), paletteEntry.Color);
 }
Exemple #29
0
        public static void Render(Stream s)
        {
            using (BinaryReader r = new BinaryReader(s)) {
                byte flags = r.ReadByte();

                byte width  = r.ReadByte();
                byte height = r.ReadByte();

                byte           paletteCount = r.ReadByte();
                PaletteEntry[] palette      = new PaletteEntry[paletteCount];
                for (int k = 0; k < paletteCount; k++)
                {
                    char character  = r.ReadChar();
                    byte attributes = r.ReadByte();
                    palette[k] = new PaletteEntry {
                        Character = character, Attributes = attributes
                    };
                }

                byte   frameCount  = r.ReadByte();
                ushort frameLength = (ushort)(width * height);

                // Load image into memory buffer
                int[] indices = new int[frameLength];
                int   i       = 0;
                while (r.BaseStream.Position < r.BaseStream.Length)
                {
                    byte n = r.ReadByte();
                    if (n == 0)   // New frame - not supported
                    {
                        return;
                    }
                    else
                    {
                        byte paletteIndex = r.ReadByte();

                        for (int k = 0; k < n; k++)
                        {
                            if (i >= frameLength)
                            {
                                return;
                            }

                            indices[i] = paletteIndex;
                            i++;
                        }
                    }
                }

                // Render to console (multi-platform)
                ConsoleColor originalForeground = Console.ForegroundColor;
                ConsoleColor originalBackground = Console.BackgroundColor;

                int cursorLeft = ((Console.BufferWidth - width) >> 1);
                for (int y = 0; y < height; y++)
                {
                    Console.CursorLeft = cursorLeft;

                    for (int x = 0; x < width; x++)
                    {
                        ref PaletteEntry entry = ref palette[indices[x + y * width]];
                        Console.ForegroundColor = (ConsoleColor)(entry.Attributes & 0x0F);
                        Console.BackgroundColor = (ConsoleColor)((entry.Attributes >> 4) & 0x0F);
                        Console.Write(entry.Character);
                    }

                    Console.CursorTop++;
                }

                Console.SetCursorPosition(0, Console.CursorTop + 1);

                Console.ForegroundColor = originalForeground;
                Console.BackgroundColor = originalBackground;
                Console.ResetColor();
            }
Exemple #30
0
 /// <summary>
 /// Saves a texture to a file.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="format">The format.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>A <see cref="SharpDX.Result" /> object describing the result of the operation.</returns>
 /// <unmanaged>HRESULT D3DXSaveTextureToFileW([In] const wchar_t* pDestFile,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DBaseTexture9* pSrcTexture,[In, Buffer] const PALETTEENTRY* pSrcPalette)</unmanaged>
 public static void ToFile(BaseTexture texture, string fileName, ImageFileFormat format, PaletteEntry[] palette)
 {
     D3DX9.SaveTextureToFileW(fileName, format, texture, palette);            
 }
Exemple #31
0
 /// <summary>
 /// Saves a texture to a stream.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="format">The format.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>A <see cref="DataStream"/> containing the saved texture.</returns>
 /// <unmanaged>HRESULT D3DXSaveTextureToFileInMemory([Out] ID3DXBuffer** ppDestBuf,[In] D3DXIMAGE_FILEFORMAT DestFormat,[In] IDirect3DBaseTexture9* pSrcTexture,[In, Buffer] const PALETTEENTRY* pSrcPalette)</unmanaged>
 public static DataStream ToStream(BaseTexture texture, ImageFileFormat format, PaletteEntry[] palette)
 {
     return new DataStream(D3DX9.SaveTextureToFileInMemory(format, texture, palette));
 }
Exemple #32
0
 /// <summary>
 /// Filters mipmap levels of a texture.
 /// </summary>
 /// <param name="sourceLevel">The source level.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="palette">The palette.</param>
 /// <returns>
 /// A <see cref="SharpDX.Result"/> object describing the result of the operation.
 /// </returns>
 /// <unmanaged>HRESULT D3DXFilterTexture([In] IDirect3DBaseTexture9* pBaseTexture,[In, Buffer] const PALETTEENTRY* pPalette,[In] unsigned int SrcLevel,[In] D3DX_FILTER Filter)</unmanaged>	
 public void FilterTexture(int sourceLevel, Filter filter, PaletteEntry[] palette)
 {
     D3DX9.FilterTexture(this, palette, sourceLevel, filter);
 }
Exemple #33
0
        static string FormatEntry(PaletteEntry e, Level lvl)
        {
            ExtBlock block = ExtBlock.FromRaw(e.Raw);

            return(lvl.BlockName(block) + " - " + Utils.Hex(e.R, e.G, e.B));
        }
    void Export()
    {
        string path = EditorUtility.SaveFilePanelInProject("Export structure...", "struct_file", "json", "Export...");

        if (path.Length == 0)
        {
            return;
        }

        JsonStructure toExport = new JsonStructure();

        if (structure.structureUID == string.Empty)
        {
            Debug.LogError("Missing Structure ID! Check Structure Details category.");
            return;
        }
        toExport.uniqueName = structure.structureUID;
        toExport.width      = (int)size.x;
        toExport.height     = (int)size.y;
        toExport.length     = (int)size.z;

        toExport.palette = new List <JsonPaletteEntry>();
        foreach (PaletteEntry entry in structure.palette)
        {
            if (!entry.isValid)
            {
                Debug.LogError("Invalid palette entry! Check Palette category.");
                return;
            }
            toExport.palette.Add(new JsonPaletteEntry(entry.isOreDict? "ore" : entry.mod, entry.name, entry.identifier, entry.meta));
        }

        Block master = structure.validFullBlocks.FirstOrDefault(x => x.pos == structure.masterPos);

        if (master == null)
        {
            Debug.LogError("Master block not set or missing palette value! Check Composition category.");
            return;
        }

        PaletteEntry masterPaletteEntry = structure.palette.FirstOrDefault(x => x.identifier == master.paletteValue);

        if (masterPaletteEntry == null)
        {
            Debug.LogError("Master block is missing valid palette value! Check Composition and Palette categories.");
            return;
        }

        toExport.master = new JsonMaster(
            calculator.BlockPosToLocalX(master.pos),
            calculator.BlockPosToLocalY(master.pos),
            calculator.BlockPosToLocalZ(master.pos),
            masterPaletteEntry.isOreDict ? "ore" :
            masterPaletteEntry.mod, masterPaletteEntry.name, masterPaletteEntry.meta);

        toExport.pointsOfInterest = new List <JsonPoI>();
        foreach (PoI poi in structure.pointsOfInterest)
        {
            if (structure.ignoredPositions2.Contains(poi.pos) || !structure.validFullBlocks.Any(x => x.pos == poi.pos))
            {
                continue;
            }
            toExport.pointsOfInterest.Add(new JsonPoI()
            {
                position = poi.pos, name = poi.id, facing = poi.facing
            });
        }

        int firstDimension  = AABBGenerator.FirstDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder);
        int secondDimension = AABBGenerator.SecondDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder);
        int thirdDimension  = AABBGenerator.ThirdDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder);

        toExport.structure = new List <string>();
        string emptyLine = new string(' ', firstDimension);

        for (int line = 0; line < secondDimension * thirdDimension; line++)
        {
            toExport.structure.Add(emptyLine);
        }
        foreach (Block block in structure.validFullBlocks)
        {
            if (structure.ignoredPositions2.Contains(block.pos))
            {
                continue;
            }
            if (block.IsInvalid())
            {
                Debug.LogError(string.Format("Block {0} is missing valid palette value! Check Composition and Palette categories.", block.pos));
                return;
            }
            int firstPos  = AABBGenerator.RelativeX(block.pos, editorSettings.axisOrder, size);
            int secondPos = AABBGenerator.RelativeZ(block.pos, editorSettings.axisOrder, size);
            int thirdPos  = AABBGenerator.RelativeY(block.pos, editorSettings.axisOrder, size);
            //Debug.Log(string.Format("{0}, {1}, {2}, {3}, {4}", firstPos, secondPos, thirdPos, toExport.structure[thirdPos * secondDimension + secondPos].Length, block.paletteValue));
            toExport.structure[thirdPos * secondDimension + secondPos] = ReplaceAt(toExport.structure[thirdPos * secondDimension + secondPos], firstPos, block.paletteValue);
        }

        toExport.AABB = new List <byte>();
        List <Box>[] orderedList = new List <Box> [(int)(size.x * size.y * size.z)];

        foreach (BlockPosition aabb in structure.allSubAABBs)
        {
            if (orderedList[aabb.pos] == null)
            {
                orderedList[aabb.pos] = new List <Box>();
            }
            orderedList[aabb.pos].Add(aabb.normalizedBox);
        }

        Box fullBox = new Box(0, 0, 0, 16, 16, 16);

        StringBuilder builder = new StringBuilder();

        for (int index = 0; index < orderedList.Length; index++)
        {
            if (structure.ignoredPositions2.Contains(index) || orderedList[index] == null)  //no collision boxes
            {
                builder.Append("null");
            }
            else if (orderedList[index].Count == 1 && orderedList[index][0] == fullBox)     //full collision box
            {
                builder.Append("[]");
            }
            else     //partial collision boxes
            {
                List <string> floats = new List <string>();
                foreach (Box box in orderedList[index])
                {
                    floats.Add(box.ToString(editorSettings.outputFormat));
                }
                builder.Append("[" + string.Join(",", floats) + "]");
            }
            builder.Append(",");
        }

        builder.Length -= 1;

        string json = JsonUtility.ToJson(toExport, false);

        json = json.Insert(json.LastIndexOf('[') + 1, builder.ToString());

        using (StreamWriter writer = new StreamWriter(path)) {
            writer.Write(json);
            writer.Flush();
            writer.Close();
        }
    }
        private RadPieChartView createChart()
        {
            InitChartData();

            RadPieChartView pieChartView = new RadPieChartView(this);

            CustomPieSeries pieSeries = new CustomPieSeries();

            pieSeries.ValueBinding = new MonthResultDataBinding("Result");
            pieSeries.Data         = (Java.Lang.IIterable) this.monthResults;
            pieSeries.ShowLabels   = true;
            pieSeries.LabelValueToStringConverter = new ValueToStringConverter();
            pieSeries.LabelOffset = -50;

            ChartPalette customPalette = pieChartView.Palette;

            PaletteEntry paid = customPalette.GetEntry(ChartPalette.PieFamily, 0);

            paid.Fill = Color.ParseColor("#00757D");

            PaletteEntry remaining = customPalette.GetEntry(ChartPalette.PieFamily, 1);

            remaining.Fill = Color.ParseColor("#75c283");

            PaletteEntry overdue = customPalette.GetEntry(ChartPalette.PieFamily, 2);

            overdue.Fill = Color.ParseColor("#f14844");

            //pieChartView.Palette  = customPalette;


            SliceStyle blueStyle = new SliceStyle();

            blueStyle.FillColor   = Color.ParseColor("#00757D");
            blueStyle.StrokeColor = Color.ParseColor("#00757D");
            blueStyle.StrokeWidth = 2;
            blueStyle.ArcColor    = Color.White;
            blueStyle.ArcWidth    = 2;

            SliceStyle greenStyle = new SliceStyle();

            greenStyle.FillColor   = Color.ParseColor("#75c283");
            greenStyle.StrokeColor = Color.ParseColor("#75c283");
            greenStyle.StrokeWidth = 2;
            greenStyle.ArcColor    = Color.White;
            greenStyle.ArcWidth    = 2;

            SliceStyle redStyle = new SliceStyle();

            redStyle.FillColor   = Color.ParseColor("#f14844");
            redStyle.StrokeColor = Color.ParseColor("#f14844");
            redStyle.StrokeWidth = 2;
            redStyle.ArcColor    = Color.White;
            redStyle.ArcWidth    = 2;

            List <SliceStyle> styles = new List <SliceStyle>();


            if (this.IsBlue && this.IsGreen && this.IsRed)
            {
                styles.Add(blueStyle);
                styles.Add(greenStyle);
                styles.Add(redStyle);
            }
            else if (this.IsBlue && this.IsGreen)
            {
                styles.Add(blueStyle);
                styles.Add(greenStyle);
            }
            else if (this.IsBlue && this.IsRed)
            {
                styles.Add(blueStyle);
                styles.Add(redStyle);
            }
            else if (this.IsGreen && this.IsRed)
            {
                styles.Add(greenStyle);
                styles.Add(redStyle);
            }
            else if (this.IsBlue)
            {
                styles.Add(blueStyle);
            }
            else if (this.IsGreen)
            {
                styles.Add(greenStyle);
            }
            else if (this.IsRed)
            {
                styles.Add(redStyle);
            }

            pieSeries.SliceStyles = styles;

            pieChartView.Series.Add(pieSeries);
            return(pieChartView);
        }