Ejemplo n.º 1
0
        public frmMain()
        {
            InitializeComponent();

            ColorCounter CC = getColorCounter(selectedColor);

            for (int i = 0; i < 16; i++)
            {
                for (int y = 0; y < 16; y++)
                {
                    bgColors[i, y] = selectedColor;
                    CC.incAmount();
                }
            }

            updateColorAmounts();


            orderedColors.Add(new KeyValuePair <string, int>("White", 0));
            orderedColors.Add(new KeyValuePair <string, int>("Orange", 1));
            orderedColors.Add(new KeyValuePair <string, int>("Magenta", 2));
            orderedColors.Add(new KeyValuePair <string, int>("LightBlue", 3));
            orderedColors.Add(new KeyValuePair <string, int>("Yellow", 4));
            orderedColors.Add(new KeyValuePair <string, int>("Lime", 5));
            orderedColors.Add(new KeyValuePair <string, int>("Pink", 6));
            orderedColors.Add(new KeyValuePair <string, int>("Gray", 7));
            orderedColors.Add(new KeyValuePair <string, int>("LightGray", 8));
            orderedColors.Add(new KeyValuePair <string, int>("Cyan", 9));
            orderedColors.Add(new KeyValuePair <string, int>("Purple", 10));
            orderedColors.Add(new KeyValuePair <string, int>("Blue", 11));
            orderedColors.Add(new KeyValuePair <string, int>("Brown", 12));
            orderedColors.Add(new KeyValuePair <string, int>("Green", 13));
            orderedColors.Add(new KeyValuePair <string, int>("Red", 14));
            orderedColors.Add(new KeyValuePair <string, int>("Black", 15));
        }
Ejemplo n.º 2
0
    void Start()
    {
        startZoneR       = GameObject.Find("StartZoneRobots");
        countdownRunning = true;

        // Deactivating the countdown script until the game starts
        ((Countdowns)gameObject.GetComponent <Countdowns>()).enabled = false;

        //Texts and Canvas
        _remainingTimeText         = GameObject.Find("GameCountdown").GetComponent <Text>();
        _remainingTimeText.enabled = false;
        _countdownText             = GameObject.Find("StartCountdown").GetComponent <Text>();
        _countdownText.enabled     = false;
        _gameOverText         = GameObject.Find("GameOverText").GetComponent <Text>();
        _gameOverText.enabled = false;
        QuestionCanvas.SetActive(false);
        rectTransform = _gameOverText.GetComponent <RectTransform>();
        rectTransform.localPosition = GameOverStartPosition;

        //Sound Integration
        _throwingSoundRobot = GameObject.Find("Throwing Sound Robot").GetComponent <AudioSource>();
        _throwingSoundCube  = GameObject.Find("Throwing Sound Cube").GetComponent <AudioSource>();
        _fireworkSound      = GameObject.Find("Firework Sound").GetComponent <AudioSource>();
        _fallingSound       = GameObject.Find("Falling Sound").GetComponent <AudioSource>();
        _startSound         = GameObject.Find("Start Sound").GetComponent <AudioSource>();
        _buttonSound        = GameObject.Find("Button Sound").GetComponent <AudioSource>();

        // Script Integration
        ColorCountActivator  = FindObjectOfType <ColorCounter>();
        BallSpawnActivator   = FindObjectOfType <BallSpawner>();
        ColorSwitchActivator = FindObjectOfType <BallColorSwitch>();

        // get lists for start sequence
        scriptM       = GameObject.Find("ScriptManager");
        boxPlayerList = scriptM.GetComponent <CatchingThrowing>().enemyList;
        robotList     = scriptM.GetComponent <RobotEnemyManagement>().enemyList;
        // find ball and player game object
        ball   = GameObject.Find("Ball");
        player = GameObject.Find("Player");
    }
Ejemplo n.º 3
0
        private void decrementColor(Color c)
        {
            bool found = false;



            foreach (ColorCounter CC in usedColors)
            {
                if (CC.color == c)
                {
                    CC.decAmount();
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                ColorCounter colorC = new ColorCounter(c, 0);
                usedColors.Add(colorC);
            }
        }
Ejemplo n.º 4
0
        internal static void TestWrite()
        {
            ColorCounter c1 = new ColorCounter();

            c1[Color.Red]++;
            ColorCounter c2 = new ColorCounter();

            c2[Color.Green]++;
            c2[Color.Blue]++;

            Player[] players =
            {
                new Player("Hans",  new CardStack(new Card[] { new Card(3, Color.Red),   new Card(6, Color.Red)  }), c1),
                new Player("Peter", new CardStack(new Card[] { new Card(2, Color.Green), new Card(7, Color.Blue) }), c2)
            };
            GameLog g = new GameLog(2, 3, players);

            g.Turns.Add(new Turn(0, 1, Color.Green,
                                 new Card[] {
                new Card(2, Color.Green),
                new Card(3, Color.Red)
            }));
            g.SaveLog();
        }
Ejemplo n.º 5
0
 public Player(WizzardExtreme.Player player)
 {
     Name   = player.Name;
     Hand   = new CardStack(player.Hand);
     Tricks = new ColorCounter(player.Tricks);
 }
Ejemplo n.º 6
0
 public Player(string name, CardStack hand, ColorCounter tricks)
 {
     Name   = name;
     Hand   = hand;
     Tricks = tricks;
 }
Ejemplo n.º 7
0
        static unsafe int Main(string[] astrArgs)
        {
            // Command-line argument processing

            if (astrArgs.Length == 0) {
                PrintHelp();
                return 0;
            }

            for (int i = 0; i < astrArgs.Length; i++) {
                switch (astrArgs[i]) {
                case "-?":
                    PrintHelp();
                    return 0;

                case "-i":
                    giclrInsert = Int32.Parse(astrArgs[++i]);
                    break;

                case "-p":
                    gcPaletteEntries = Int32.Parse(astrArgs[++i]);
                    break;

                case "-c":
                    gcColorEntries = Int32.Parse(astrArgs[++i]);
                    break;

                case "-t":
                    gfEliminateTransparentColor = true;
                    break;

                case "-s":
                    gfEliminateShadowColor = true;
                    break;

                case "-v":
                    gfVerbose = true;
                    break;

                case "-u":
                    gfPrintColorUsers = true;
                    break;

                case "-6":
                    gf6bitRGB = true;
                    break;

                case "-h":
                    gfPrintHistogram = true;
                    break;

                case "-a":
                    gfAnalyse = true;
                    break;

                case "-n":
                    gfPhotoshopPad = true;
                    break;

                case "-f":
                    AddFilesFromFile(astrArgs[++i]);
                    break;

                case "-o":
                    if (i + 1 >= astrArgs.Length) {
                        Console.WriteLine("Error: -o command requires a filename argument");
                        return -1;
                    }
                    gstrOutputFileName = astrArgs[++i];
                    break;

                default:
                    if (astrArgs[i][0] == '-') {
                        Console.WriteLine("Error: invalid flag '{0}'", astrArgs[i]);
                        return -1;
                    }

                    // Assume all 'unassociated' arguments are input filenames (potentially wildcarded)

                    AddFiles(astrArgs[i]);
                    break;
                }
            }

            if (gstrcFileNames.Count == 0) {
                Console.WriteLine("Error: no files specified");
                return -1;
            }

            // Build a list of the colors used and count of uses for each bitmap

            ArrayList alstBitmapColorInfos = new ArrayList();

            foreach (string strFileName in gstrcFileNames) {

                BitmapColorInfo bci = new BitmapColorInfo();
                bci.strFileName = strFileName;
                bci.htColorCount = new Hashtable();

                // Handle .PALs

                if (strFileName.ToLower().EndsWith(".pal")) {
                    Palette pal = new Palette(strFileName);

                    int i = 0;
                    foreach (Color clr in pal.Colors) {
                        Color clrT = clr;
                        if (gf6bitRGB)
                            clrT = Color.FromArgb(clr.R & 0xfc, clr.G & 0xfc, clr.B & 0xfc);

                        // This hack causes the .PAL colors to be sorted at the head of the
                        // combined palette while retaining the order they were found in the .PAL.

                        if (!bci.htColorCount.Contains(clrT))
                            bci.htColorCount[clrT] = (Int32.MaxValue / 2) - i++;
                    }

                // Handle everything else (bitmaps)

                } else {
                    Bitmap bm = null;
                    try {
                        bm = new Bitmap(strFileName);
                    } catch {
                        Console.WriteLine("Error: {0} is not a recognized bitmap or palette file", strFileName);
                        continue;
                    }

                    // Prep to filter out the transparent color

                    Color clrTransparent = Color.GhostWhite;
                    if (gfEliminateTransparentColor)
                        clrTransparent = bm.GetPixel(0, 0);

                    // Prep to filter out the shadow color

                    Color clrShadow = Color.GhostWhite;
                    if (gfEliminateShadowColor)
                        clrShadow = Color.FromArgb(156, 212, 248);

                    // Keep a per-bitmap list of unique colors and how many times they're used

                    Hashtable ht = bci.htColorCount;

                    // Lock down bits for speed

                    Rectangle rc = new Rectangle(0, 0, bm.Width, bm.Height);
                    BitmapData bmd = bm.LockBits(rc, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    byte *pbBase = (byte *)bmd.Scan0.ToPointer();

                    for (int y = 0; y < bm.Height; y++) {
                        for (int x = 0; x < bm.Width; x++) {
                            byte *pb = pbBase + y * bmd.Stride + x * 3;
                            Color clr = Color.FromArgb(pb[2], pb[1], pb[0]);
                            if (gfEliminateTransparentColor && clr == clrTransparent)
                                continue;

                            if (gfEliminateShadowColor && clr == clrShadow)
                                continue;

                            if (gf6bitRGB)
                                clr = Color.FromArgb(clr.R & 0xfc, clr.G & 0xfc, clr.B & 0xfc);

                            object obT = ht[clr];
                            if (obT == null)
                                ht[clr] = 1;
                            else
                                ht[clr] = 1 + (int)obT;
                        }
                    }
                    bm.UnlockBits(bmd);
                }

                if (gfVerbose)
                    Console.WriteLine("{0} uses {1} colors", strFileName, bci.htColorCount.Count);

                if (gfPrintHistogram && gfVerbose) {
                    foreach (DictionaryEntry de in bci.htColorCount) {
                        Color clr = (Color)de.Key;
                        Console.WriteLine("{0},{1},{2} : {3} occurances", clr.R, clr.G, clr.B, (int)de.Value);
                    }
                    Console.WriteLine();
                }

                alstBitmapColorInfos.Add(bci);
            }

            if (alstBitmapColorInfos.Count == 0) {
                Console.WriteLine("Error: no valid bitmap files to process, terminating");
                return -1;
            }

            // Combine all the color tables and count data

            Hashtable htCombined = new Hashtable();

            foreach (BitmapColorInfo bci in alstBitmapColorInfos) {
                foreach (DictionaryEntry de in bci.htColorCount) {
                    Color clr = (Color)de.Key;
                    ColorCounter clrc = (ColorCounter)htCombined[clr];
                    if (clrc == null) {
                        clrc = new ColorCounter();
                        clrc.cclr = (int)de.Value;
                        htCombined[clr] = clrc;
                    } else {
                        int nAdd = (int)de.Value;
                        if (nAdd > Int32.MaxValue / 3)
                            clrc.cclr = (int)de.Value;
                        else if (clrc.cclr < Int32.MaxValue / 3)
                            clrc.cclr += nAdd;
                    }
                    clrc.alBitmaps.Add(bci.strFileName);
                }
            }

            int cclrCombined = htCombined.Count;
            Console.WriteLine("Combined palette has {0} unique colors", cclrCombined);

            // Sort everything by # colors used

            ColorCounter[] aclrcSorted = new ColorCounter[cclrCombined];
            //			int i = 0;
            //			foreach (ColorCounter clrc in htCombined.Values)
            //				acOccurancesSorted[i++] = clrc.cclr;
            htCombined.Values.CopyTo(aclrcSorted, 0);
            Color[] aclrSorted = new Color[cclrCombined];
            htCombined.Keys.CopyTo(aclrSorted, 0);

            Array.Sort(aclrcSorted, aclrSorted);

            // Reverse so most-used colors come first
            // OPT: could do this inside the Sort above by specifying a custom IComparer

            Array.Reverse(aclrcSorted);
            Array.Reverse(aclrSorted);

            if (gfPrintHistogram || gfPrintColorUsers) {
                for (int i = 0; i < cclrCombined; i++) {
                    Color clr = aclrSorted[i];
                    int cOccurances = aclrcSorted[i].cclr;
                    if (cOccurances >= Int32.MaxValue / 3)
                        Console.WriteLine("{0},{1},{2} : preloaded", clr.R, clr.G, clr.B);
                    else
                        Console.WriteLine("{0},{1},{2} : {3} occurances", clr.R, clr.G, clr.B, cOccurances);

                    if (gfPrintColorUsers) {
                        foreach (string strFileName in aclrcSorted[i].alBitmaps) {
                            Console.WriteLine("    {0}", strFileName);
                        }
                    }
                }
            }

            // Print warning if # of unique colors is greater than the desired palette size
            // Truncate to match the requested size since other tools depend on this

            if (cclrCombined > gcColorEntries) {
                Console.WriteLine("Warning! {0} unique colors, {1} palette entries reserved. Truncating...",  cclrCombined, gcColorEntries);
                Color[] aclrSortedT = new Color[gcColorEntries];
                Array.Copy(aclrSorted, 0, aclrSortedT, 0, gcColorEntries);
                aclrSorted = aclrSortedT;
                ColorCounter[] aclrcSortedT = new ColorCounter[gcColorEntries];
                Array.Copy(aclrcSorted, 0, aclrcSortedT, 0, gcColorEntries);
                aclrcSorted = aclrcSortedT;
                cclrCombined = gcColorEntries;
            }

            // Create the palette. Presorted colors start at 0. New colors start at giclrInsert.
            // giclrInsert == -1 means new colors are simply appended to the presorted colors.

            Color[] aclrPalette = aclrSorted;

            if (giclrInsert != -1) {
                // Init to transparent

                aclrPalette = new Color[gcColorEntries];
                for (int i = 0; i < aclrPalette.Length; i++)
                    aclrPalette[i] = Color.FromArgb(255, 0, 255);

                // Insert new colors appropriately

                int iclrBase = -1;
                for (int i = 0; i < cclrCombined; i++) {
                    if (aclrcSorted[i].cclr >= Int32.MaxValue / 3) {
                        aclrPalette[i] = aclrSorted[i];
                        continue;
                    }
                    if (iclrBase == -1)
                        iclrBase = i;
                    int iclrNew = giclrInsert + (i - iclrBase);
                    if (iclrNew < aclrPalette.Length)
                        aclrPalette[iclrNew] = aclrSorted[i];
                }
            }

            // Write the output palette file, if requested

            if (gstrOutputFileName != null) {
                Palette pal = new Palette(aclrPalette);
                if (gfPhotoshopPad)
                    pal.Pad(gcPaletteEntries, pal[pal.Length - 1]);
                else
                    pal.Pad(gcPaletteEntries, Color.FromArgb(255, 0, 255));
                pal.SaveJasc(gstrOutputFileName);
            }

            if (gfAnalyse) {
                Palette pal = new Palette(aclrPalette);

                // For each color find the nearest color in RGB space and print
                // the pair as well as the distance between them.

                for (int iclrA = 0; iclrA < aclrPalette.Length; iclrA++) {
                    Color clrA = aclrPalette[iclrA];

                    // Find the entry, the long way

                    int nLowest = 256 * 256 * 3;
                    int iLowest = 0;
                    for (int iclr = 0; iclr < aclrPalette.Length; iclr++) {
                        if (iclr == iclrA)
                            continue;

                        Color clrPal = aclrPalette[iclr];
                        int dR = clrPal.R - clrA.R;
                        int dG = clrPal.G - clrA.G;
                        int dB = clrPal.B - clrA.B;
                        int nD = dR * dR + dG * dG + dB * dB;
                        if (nD < nLowest) {
                            nLowest = nD;
                            iLowest = iclr;
                        }
                    }

                    Color clrB = aclrPalette[iLowest];
                    double n = Math.Sqrt(nLowest);
                    Console.WriteLine("{8:#.##}\t[{3}] {0},{1},{2} \t[{7}] {4},{5},{6}",
                            clrA.R, clrA.G, clrA.B, iclrA, clrB.R, clrB.G, clrB.B, iLowest, n);
                }
            }

            return 0;
        }
Ejemplo n.º 8
0
        static unsafe int Main(string[] astrArgs)
        {
            // Command-line argument processing

            if (astrArgs.Length == 0)
            {
                PrintHelp();
                return(0);
            }

            for (int i = 0; i < astrArgs.Length; i++)
            {
                switch (astrArgs[i])
                {
                case "-?":
                    PrintHelp();
                    return(0);

                case "-i":
                    giclrInsert = Int32.Parse(astrArgs[++i]);
                    break;

                case "-p":
                    gcPaletteEntries = Int32.Parse(astrArgs[++i]);
                    break;

                case "-c":
                    gcColorEntries = Int32.Parse(astrArgs[++i]);
                    break;

                case "-t":
                    gfEliminateTransparentColor = true;
                    break;

                case "-s":
                    gfEliminateShadowColor = true;
                    break;

                case "-v":
                    gfVerbose = true;
                    break;

                case "-u":
                    gfPrintColorUsers = true;
                    break;

                case "-6":
                    gf6bitRGB = true;
                    break;

                case "-h":
                    gfPrintHistogram = true;
                    break;

                case "-a":
                    gfAnalyse = true;
                    break;

                case "-n":
                    gfPhotoshopPad = true;
                    break;

                case "-f":
                    AddFilesFromFile(astrArgs[++i]);
                    break;

                case "-o":
                    if (i + 1 >= astrArgs.Length)
                    {
                        Console.WriteLine("Error: -o command requires a filename argument");
                        return(-1);
                    }
                    gstrOutputFileName = astrArgs[++i];
                    break;

                default:
                    if (astrArgs[i][0] == '-')
                    {
                        Console.WriteLine("Error: invalid flag '{0}'", astrArgs[i]);
                        return(-1);
                    }

                    // Assume all 'unassociated' arguments are input filenames (potentially wildcarded)

                    AddFiles(astrArgs[i]);
                    break;
                }
            }

            if (gstrcFileNames.Count == 0)
            {
                Console.WriteLine("Error: no files specified");
                return(-1);
            }

            // Build a list of the colors used and count of uses for each bitmap

            ArrayList alstBitmapColorInfos = new ArrayList();

            foreach (string strFileName in gstrcFileNames)
            {
                BitmapColorInfo bci = new BitmapColorInfo();
                bci.strFileName  = strFileName;
                bci.htColorCount = new Hashtable();

                // Handle .PALs

                if (strFileName.ToLower().EndsWith(".pal"))
                {
                    Palette pal = new Palette(strFileName);

                    int i = 0;
                    foreach (Color clr in pal.Colors)
                    {
                        Color clrT = clr;
                        if (gf6bitRGB)
                        {
                            clrT = Color.FromArgb(clr.R & 0xfc, clr.G & 0xfc, clr.B & 0xfc);
                        }

                        // This hack causes the .PAL colors to be sorted at the head of the
                        // combined palette while retaining the order they were found in the .PAL.

                        if (!bci.htColorCount.Contains(clrT))
                        {
                            bci.htColorCount[clrT] = (Int32.MaxValue / 2) - i++;
                        }
                    }

                    // Handle everything else (bitmaps)
                }
                else
                {
                    Bitmap bm = null;
                    try {
                        bm = new Bitmap(strFileName);
                    } catch {
                        Console.WriteLine("Error: {0} is not a recognized bitmap or palette file", strFileName);
                        continue;
                    }

                    // Prep to filter out the transparent color

                    Color clrTransparent = Color.GhostWhite;
                    if (gfEliminateTransparentColor)
                    {
                        clrTransparent = bm.GetPixel(0, 0);
                    }

                    // Prep to filter out the shadow color

                    Color clrShadow = Color.GhostWhite;
                    if (gfEliminateShadowColor)
                    {
                        clrShadow = Color.FromArgb(156, 212, 248);
                    }

                    // Keep a per-bitmap list of unique colors and how many times they're used

                    Hashtable ht = bci.htColorCount;

                    // Lock down bits for speed

                    Rectangle  rc     = new Rectangle(0, 0, bm.Width, bm.Height);
                    BitmapData bmd    = bm.LockBits(rc, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    byte *     pbBase = (byte *)bmd.Scan0.ToPointer();

                    for (int y = 0; y < bm.Height; y++)
                    {
                        for (int x = 0; x < bm.Width; x++)
                        {
                            byte *pb  = pbBase + y * bmd.Stride + x * 3;
                            Color clr = Color.FromArgb(pb[2], pb[1], pb[0]);
                            if (gfEliminateTransparentColor && clr == clrTransparent)
                            {
                                continue;
                            }

                            if (gfEliminateShadowColor && clr == clrShadow)
                            {
                                continue;
                            }

                            if (gf6bitRGB)
                            {
                                clr = Color.FromArgb(clr.R & 0xfc, clr.G & 0xfc, clr.B & 0xfc);
                            }

                            object obT = ht[clr];
                            if (obT == null)
                            {
                                ht[clr] = 1;
                            }
                            else
                            {
                                ht[clr] = 1 + (int)obT;
                            }
                        }
                    }
                    bm.UnlockBits(bmd);
                }

                if (gfVerbose)
                {
                    Console.WriteLine("{0} uses {1} colors", strFileName, bci.htColorCount.Count);
                }

                if (gfPrintHistogram && gfVerbose)
                {
                    foreach (DictionaryEntry de in bci.htColorCount)
                    {
                        Color clr = (Color)de.Key;
                        Console.WriteLine("{0},{1},{2} : {3} occurances", clr.R, clr.G, clr.B, (int)de.Value);
                    }
                    Console.WriteLine();
                }

                alstBitmapColorInfos.Add(bci);
            }

            if (alstBitmapColorInfos.Count == 0)
            {
                Console.WriteLine("Error: no valid bitmap files to process, terminating");
                return(-1);
            }

            // Combine all the color tables and count data

            Hashtable htCombined = new Hashtable();

            foreach (BitmapColorInfo bci in alstBitmapColorInfos)
            {
                foreach (DictionaryEntry de in bci.htColorCount)
                {
                    Color        clr  = (Color)de.Key;
                    ColorCounter clrc = (ColorCounter)htCombined[clr];
                    if (clrc == null)
                    {
                        clrc            = new ColorCounter();
                        clrc.cclr       = (int)de.Value;
                        htCombined[clr] = clrc;
                    }
                    else
                    {
                        int nAdd = (int)de.Value;
                        if (nAdd > Int32.MaxValue / 3)
                        {
                            clrc.cclr = (int)de.Value;
                        }
                        else if (clrc.cclr < Int32.MaxValue / 3)
                        {
                            clrc.cclr += nAdd;
                        }
                    }
                    clrc.alBitmaps.Add(bci.strFileName);
                }
            }

            int cclrCombined = htCombined.Count;

            Console.WriteLine("Combined palette has {0} unique colors", cclrCombined);

            // Sort everything by # colors used

            ColorCounter[] aclrcSorted = new ColorCounter[cclrCombined];
//			int i = 0;
//			foreach (ColorCounter clrc in htCombined.Values)
//				acOccurancesSorted[i++] = clrc.cclr;
            htCombined.Values.CopyTo(aclrcSorted, 0);
            Color[] aclrSorted = new Color[cclrCombined];
            htCombined.Keys.CopyTo(aclrSorted, 0);

            Array.Sort(aclrcSorted, aclrSorted);

            // Reverse so most-used colors come first
            // OPT: could do this inside the Sort above by specifying a custom IComparer

            Array.Reverse(aclrcSorted);
            Array.Reverse(aclrSorted);

            if (gfPrintHistogram || gfPrintColorUsers)
            {
                for (int i = 0; i < cclrCombined; i++)
                {
                    Color clr         = aclrSorted[i];
                    int   cOccurances = aclrcSorted[i].cclr;
                    if (cOccurances >= Int32.MaxValue / 3)
                    {
                        Console.WriteLine("{0},{1},{2} : preloaded", clr.R, clr.G, clr.B);
                    }
                    else
                    {
                        Console.WriteLine("{0},{1},{2} : {3} occurances", clr.R, clr.G, clr.B, cOccurances);
                    }

                    if (gfPrintColorUsers)
                    {
                        foreach (string strFileName in aclrcSorted[i].alBitmaps)
                        {
                            Console.WriteLine("    {0}", strFileName);
                        }
                    }
                }
            }

            // Print warning if # of unique colors is greater than the desired palette size
            // Truncate to match the requested size since other tools depend on this

            if (cclrCombined > gcColorEntries)
            {
                Console.WriteLine("Warning! {0} unique colors, {1} palette entries reserved. Truncating...", cclrCombined, gcColorEntries);
                Color[] aclrSortedT = new Color[gcColorEntries];
                Array.Copy(aclrSorted, 0, aclrSortedT, 0, gcColorEntries);
                aclrSorted = aclrSortedT;
                ColorCounter[] aclrcSortedT = new ColorCounter[gcColorEntries];
                Array.Copy(aclrcSorted, 0, aclrcSortedT, 0, gcColorEntries);
                aclrcSorted  = aclrcSortedT;
                cclrCombined = gcColorEntries;
            }

            // Create the palette. Presorted colors start at 0. New colors start at giclrInsert.
            // giclrInsert == -1 means new colors are simply appended to the presorted colors.

            Color[] aclrPalette = aclrSorted;

            if (giclrInsert != -1)
            {
                // Init to transparent

                aclrPalette = new Color[gcColorEntries];
                for (int i = 0; i < aclrPalette.Length; i++)
                {
                    aclrPalette[i] = Color.FromArgb(255, 0, 255);
                }

                // Insert new colors appropriately

                int iclrBase = -1;
                for (int i = 0; i < cclrCombined; i++)
                {
                    if (aclrcSorted[i].cclr >= Int32.MaxValue / 3)
                    {
                        aclrPalette[i] = aclrSorted[i];
                        continue;
                    }
                    if (iclrBase == -1)
                    {
                        iclrBase = i;
                    }
                    int iclrNew = giclrInsert + (i - iclrBase);
                    if (iclrNew < aclrPalette.Length)
                    {
                        aclrPalette[iclrNew] = aclrSorted[i];
                    }
                }
            }

            // Write the output palette file, if requested

            if (gstrOutputFileName != null)
            {
                Palette pal = new Palette(aclrPalette);
                if (gfPhotoshopPad)
                {
                    pal.Pad(gcPaletteEntries, pal[pal.Length - 1]);
                }
                else
                {
                    pal.Pad(gcPaletteEntries, Color.FromArgb(255, 0, 255));
                }
                pal.SaveJasc(gstrOutputFileName);
            }

            if (gfAnalyse)
            {
                Palette pal = new Palette(aclrPalette);

                // For each color find the nearest color in RGB space and print
                // the pair as well as the distance between them.

                for (int iclrA = 0; iclrA < aclrPalette.Length; iclrA++)
                {
                    Color clrA = aclrPalette[iclrA];

                    // Find the entry, the long way

                    int nLowest = 256 * 256 * 3;
                    int iLowest = 0;
                    for (int iclr = 0; iclr < aclrPalette.Length; iclr++)
                    {
                        if (iclr == iclrA)
                        {
                            continue;
                        }

                        Color clrPal = aclrPalette[iclr];
                        int   dR     = clrPal.R - clrA.R;
                        int   dG     = clrPal.G - clrA.G;
                        int   dB     = clrPal.B - clrA.B;
                        int   nD     = dR * dR + dG * dG + dB * dB;
                        if (nD < nLowest)
                        {
                            nLowest = nD;
                            iLowest = iclr;
                        }
                    }

                    Color  clrB = aclrPalette[iLowest];
                    double n    = Math.Sqrt(nLowest);
                    Console.WriteLine("{8:#.##}\t[{3}] {0},{1},{2} \t[{7}] {4},{5},{6}",
                                      clrA.R, clrA.G, clrA.B, iclrA, clrB.R, clrB.G, clrB.B, iLowest, n);
                }
            }

            return(0);
        }