コード例 #1
0
        private void CreatePreviewPalette()
        {
            IColorQuantizer quantizer = new PaletteQuantizer();

            //List<Color32> colors;

            if (texturePalette != null)
            {
                Texture2D tp   = GetReadableTexture(texturePalette);
                Color32[] cs32 = tp.GetPixels32();

                if (tp.width == 256 && tp.height == 1)
                {
                    //Don't use quantizer
                    selectedPalette = new List <Color32>();
                    foreach (var c32 in cs32)
                    {
                        selectedPalette.Add(c32);
                    }
                }
                else
                {
                    foreach (var c32 in cs32)
                    {
                        quantizer.AddColor(c32);
                    }
                    selectedPalette = quantizer.GetPalette(255);
                }
            }
            else
            {
                for (int i = 0; i < selectedVoxelInfo.Count; i++)
                {
                    VoxInfo v = selectedVoxelInfo[i];
                    quantizer.AddColor(v.col);
                }
                selectedPalette = quantizer.GetPalette(colorTotal);
            }

            previewPalette            = new Texture2D(8, 32, TextureFormat.ARGB32, false);
            previewPalette.filterMode = FilterMode.Point;

            int xp = 0;
            int yp = 0;

            foreach (var c in selectedPalette)
            {
                previewPalette.SetPixel(xp, yp, c);
                xp++;
                if (xp >= 8)
                {
                    xp = 0;
                    yp++;
                }
            }
            previewPalette.Apply();

            foreach (VoxInfo v in selectedVoxelInfo)
            {
                v.idx = (Byte)(ClosestColor(selectedPalette, v.col) + 1);
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PaletteFrameQuantizer{TPixel}"/> class.
 /// </summary>
 /// <param name="quantizer">The palette quantizer</param>
 public PaletteFrameQuantizer(PaletteQuantizer quantizer)
     : base(quantizer, true)
 {
     this.colors = quantizer.GetPalette <TPixel>();
 }