Beispiel #1
0
        public int GetCpNum()
        {
            ColorCompare left  = RecognitionTools.CompareColors(LUB, LUF);
            ColorCompare front = RecognitionTools.CompareColors(FUL, FUR);

            if (left == ColorCompare.Same && front == ColorCompare.Same)
            {
                return(5);
            }
            else if (left == ColorCompare.Opposite && front == ColorCompare.Opposite)
            {
                return(4);
            }
            else if (left == ColorCompare.Same)
            {
                return(1);
            }
            else if (left == ColorCompare.Opposite)
            {
                return(0);
            }
            else if (front == ColorCompare.Same)
            {
                return(3);
            }
            else
            {
                return(2);
            }
        }
Beispiel #2
0
        public FunctionCall waitforarea(string arg_txt)
        {
            string[]        args              = arg_txt.Split(',');
            int             x1                = Int32.Parse(args[0]);
            int             y1                = Int32.Parse(args[1]);
            int             x2                = Int32.Parse(args[2]);
            int             y2                = Int32.Parse(args[3]);
            byte            tolerance         = byte.Parse(args[4]);
            int             pixel_requirement = Int32.Parse(args[5]);
            NumberGenerator timeout_ms        = (args.Length > 6 ? NumberGenerator.Parse(args[6]) : new StaticNumber(0));
            string          file_path         = (args.Length > 7 ? args[7] : null);

            return(delegate()
            {
                if (!screen_color_detector.WaitForAreaChange(Rectangle.FromLTRB(
                                                                 x1 + script.XRef, y1 + script.YRef,
                                                                 x2 + script.XRef, y2 + script.YRef
                                                                 ), pixel_requirement, timeout_ms.GetInt(),
                                                             ColorCompare.TolerantWithin(tolerance)))
                {
                    // timed out
                    return ExecFileBreakable(file_path);
                }
                return FunctionResult.Continue;
            });
        }
Beispiel #3
0
        /// <summary>
        /// From 3 consecutive side colors, in counter-clockwise order, assuming white is on bottom, determine if there is an odd number of swaps.
        /// A normal color scheme is Red Green Orange Blue.  Works cor corners or edges.
        /// </summary>
        /// <returns></returns>
        public static bool IsParity(ColorCompare c1, ColorCompare c2, ColorCompare c3)
        {
            bool cornerParity;
            Dictionary <ColorCompare, int> colors = new Dictionary <ColorCompare, int>()
            {
                { ColorCompare.Same, 0 }, { ColorCompare.Opposite, 0 }, { ColorCompare.Left, 0 }, { ColorCompare.Right, 0 }
            };

            colors[c1]++;
            colors[c2]++;
            colors[c3]++;
            int numLR = colors[ColorCompare.Left] + colors[ColorCompare.Right];

            if (numLR == 0)
            {
                if (colors[ColorCompare.Opposite] == 3 || colors[ColorCompare.Same] == 3)
                {
                    cornerParity = false;
                }
                else
                {
                    cornerParity = true;
                }
            }
            else if (numLR == 1)
            {
                if (colors[ColorCompare.Same] == 1)
                {
                    cornerParity = false;
                }
                else
                {
                    cornerParity = true;
                }
            }
            else if (numLR == 2)
            {
                if (colors[ColorCompare.Left] == 1)
                {
                    cornerParity = true;
                }
                else
                {
                    cornerParity = false;
                }
            }
            else
            {
                if (colors[ColorCompare.Left] == 3 || colors[ColorCompare.Right] == 3)
                {
                    cornerParity = true;
                }
                else
                {
                    cornerParity = false;
                }
            }
            return(cornerParity);
        }
Beispiel #4
0
 public static CubeColor GetRelativeColor(CubeColor col, ColorCompare rel)
 {
     if (!(col == CubeColor.Orange || col == CubeColor.Blue || col == CubeColor.Green || col == CubeColor.Red))
     {
         throw new ArgumentException("invalid cube color");
     }
     if (rel == ColorCompare.Same)
     {
         return(col);
     }
     if (rel == ColorCompare.Opposite)
     {
         if (col == CubeColor.Blue)
         {
             return(CubeColor.Green);
         }
         if (col == CubeColor.Green)
         {
             return(CubeColor.Blue);
         }
         if (col == CubeColor.Red)
         {
             return(CubeColor.Orange);
         }
         return(CubeColor.Red);
     }
     if (rel == ColorCompare.Right)
     {
         if (col == CubeColor.Orange)
         {
             return(CubeColor.Blue);
         }
         if (col == CubeColor.Blue)
         {
             return(CubeColor.Red);
         }
         if (col == CubeColor.Red)
         {
             return(CubeColor.Green);
         }
         return(CubeColor.Orange);
     }
     if (col == CubeColor.Orange)
     {
         return(CubeColor.Green);
     }
     if (col == CubeColor.Green)
     {
         return(CubeColor.Red);
     }
     if (col == CubeColor.Red)
     {
         return(CubeColor.Blue);
     }
     return(CubeColor.Orange);
 }
Beispiel #5
0
        /// <summary>
        /// Gets the number of the PLL on this cube if there is an adjacent corner swap, idnoring location of the swap
        /// </summary>
        /// <returns></returns>
        public int GetAdjSwapNum()
        {
            ColorCompare left  = RecognitionTools.CompareColors(LUB, LU);
            ColorCompare front = RecognitionTools.CompareColors(FUL, FU);

            if (left == ColorCompare.Same)
            {
                if (front == ColorCompare.Same)
                {
                    return(8);
                }
                if (front == ColorCompare.Opposite)
                {
                    return(3);
                }
                return(9);
            }
            if (left == ColorCompare.Opposite)
            {
                if (front == ColorCompare.Same)
                {
                    return(2);
                }
                if (front == ColorCompare.Opposite)
                {
                    return(4);
                }
                return(7);
            }
            if (left == ColorCompare.Right)
            {
                if (front == ColorCompare.Right)
                {
                    return(1);
                }
                if (front == ColorCompare.Left)
                {
                    return(10);
                }
                return(6);
            }
            if (front == ColorCompare.Right)
            {
                return(5);
            }
            if (front == ColorCompare.Left)
            {
                return(0);
            }
            return(11);
        }
Beispiel #6
0
        /// <summary>
        /// Gets the number of the PLL position on this cube if there is no corner swap
        /// </summary>
        /// <returns></returns>
        public int GetEpllNum()
        {
            ColorCompare front = RecognitionTools.CompareColors(FUR, FU);
            ColorCompare right = RecognitionTools.CompareColors(RUF, RU);

            if (front == ColorCompare.Same)
            {
                if (right == ColorCompare.Same)
                {
                    return(61);
                }
                if (right == ColorCompare.Opposite)
                {
                    return(66);
                }
                return(68);
            }
            if (front == ColorCompare.Opposite)
            {
                if (right == ColorCompare.Same)
                {
                    return(71);
                }
                if (right == ColorCompare.Opposite)
                {
                    return(60);
                }
                return(67);
            }
            if (front == ColorCompare.Right)
            {
                if (right == ColorCompare.Right)
                {
                    return(69);
                }
                if (right == ColorCompare.Left)
                {
                    return(63);
                }
                return(70);
            }
            if (right == ColorCompare.Right)
            {
                return(62);
            }
            if (right == ColorCompare.Left)
            {
                return(64);
            }
            return(65);
        }
Beispiel #7
0
        /// <summary>
        /// Gets the numbr of a PLL position if there is a diagonal corner swap
        /// </summary>
        /// <returns></returns>
        public int GetDiagSwapNum()
        {
            ColorCompare front = RecognitionTools.CompareColors(FUL, FU);
            ColorCompare right = RecognitionTools.CompareColors(RUF, RU);

            if (front == ColorCompare.Same)
            {
                if (right == ColorCompare.Same)
                {
                    return(51);
                }
                if (right == ColorCompare.Opposite)
                {
                    return(56);
                }
                return(52);
            }
            if (front == ColorCompare.Opposite)
            {
                if (right == ColorCompare.Same)
                {
                    return(55);
                }
                if (right == ColorCompare.Opposite)
                {
                    return(50);
                }
                return(57);
            }
            if (front == ColorCompare.Right)
            {
                if (right == ColorCompare.Right)
                {
                    return(58);
                }
                if (right == ColorCompare.Left)
                {
                    return(48);
                }
                return(59);
            }
            if (right == ColorCompare.Right)
            {
                return(49);
            }
            if (right == ColorCompare.Left)
            {
                return(53);
            }
            return(54);
        }
Beispiel #8
0
 /// <summary>
 /// Gets the PLL number of a PLL position
 /// </summary>
 /// <returns></returns>
 public int GetPllNum()
 {
     try
     {
         ColorCompare left  = RecognitionTools.CompareColors(LUB, LUF);
         ColorCompare front = RecognitionTools.CompareColors(FUL, FUR);
         if (left == ColorCompare.Same && front == ColorCompare.Same)
         {
             return(GetEpllNum());
         }
         else if (left == ColorCompare.Opposite && front == ColorCompare.Opposite)
         {
             return(GetDiagSwapNum());
         }
         else if (left == ColorCompare.Same)
         {
             return(GetAdjSwapNum());
         }
         else if (left == ColorCompare.Opposite)
         {
             U2();
             int num = GetAdjSwapNum();
             U2();
             return(num + 24);
         }
         else if (front == ColorCompare.Same)
         {
             U();
             int num = GetAdjSwapNum();
             Ui();
             return(num + 36);
         }
         else
         {
             Ui();
             int num = GetAdjSwapNum();
             U();
             return(num + 12);
         }
     }
     catch (ArgumentException)
     {
         return(-1);
     }
 }
Beispiel #9
0
        public void SortImage()
        {
            //grab the image from box 2
            Image ModImage = picture2.Image;
            //save the image into a bitmap for editing
            Bitmap ImagePix = new Bitmap(ModImage);
            //set the dimentions
            int height = ImagePix.Height;
            int width  = ImagePix.Width;
            //number of times the loop needs to complete
            List <Color> pixel = new List <Color>();



            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (x + 1 < width && y + 1 < height)
                    {
                        pixel.Add(ImagePix.GetPixel(x, y));
                    }
                }
            }
            ColorCompare Cc = new ColorCompare();
            //pixel.Sort(Cc);

            int L = 0;
            int a = -1;


            List <Color> design = new List <Color>();

            design.Capacity = pixel.Capacity;
            foreach (Color bleh in pixel)
            {
                design.Add(Color.Beige);
            }
            //change this for different looks
            int counter = 0;
            int IndexA  = 0;

            //int IndexB = (design.Count - 1) / 2;
            foreach (Color color in pixel)
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = counter; y < height; y++)
                    {
                    }
                }
            }
            /////////////
            for (int x = 0; x < pixel.Count; x++)
            {
                a++;
                ImagePix.SetPixel(a, L, design[x]);
                if ((x % (width - 1)) == 0)
                {
                    L++;
                    a = -1;
                }
            }


            //update the image
            picture2.Image = ImagePix;
            //update the box2

            Console.WriteLine("done");
        }
        private void GetPngFiles()
        {
            List <Texture> imgs = new List <Texture>();
            bool           log  = true;

            using (var fbd = new FolderBrowserDialog()) {
                DialogResult result = fbd.ShowDialog();

                if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
                {
                    string[] files = Directory.GetFiles(fbd.SelectedPath);

                    string extension = "Png";
                    for (int f = 0; f < files.Length; f++)
                    {
                        string file = files[f];
                        if (Path.GetExtension(file).ToLower() != "." + extension.ToLower())
                        {
                            continue;
                        }

                        Image image1 = Image.FromFile(file);

                        Bitmap bmp2 = new Bitmap(image1);

                        List <Color> palette = new List <Color>();

                        List <Color> completeColors = new List <Color>();

                        Console.WriteLine(bmp2.PixelFormat);

                        string logContent = "";

                        for (int y = 0; y < bmp2.Height; y++)
                        {
                            for (int x = 0; x < bmp2.Width; x++)
                            {
                                Color c = bmp2.GetPixel(x, y);
                                if (palette.IndexOf(c) == -1)
                                {
                                    if (palette.Count < 256)
                                    {
                                        palette.Add(c);
                                    }
                                }
                                if (completeColors.IndexOf(c) == -1)
                                {
                                    completeColors.Add(c);
                                }
                            }
                        }

                        logContent += "Saved " + palette.Count + " colors out of " + completeColors.Count + "\n";

                        //TODO: Replace with logger
                        if (log)
                        {
                            Texture tex = images.Find(x => x.Name == Path.GetFileNameWithoutExtension(file));
                            if (tex != null)
                            {
                                logContent += tex.Name + " original colors info:\n";
                                for (int ci = 0; ci < tex.Colors.Count; ci++)
                                {
                                    Color c = tex.Colors[ci];
                                    if (palette.IndexOf(c) == -1)
                                    {
                                        logContent += "Color removed: " + c.ToString() + "\n";
                                    }
                                    else
                                    {
                                        logContent += "Color saved: " + c.ToString() + "\n";
                                    }
                                }
                            }
                        }
                        logContent += "\n\n";

                        while (palette.Count < 16)
                        {
                            palette.Insert(0, Color.FromArgb(0, 0, 0, 0));
                        }

                        if (palette.Count > 16)
                        {
                            while (palette.Count < 256)
                            {
                                palette.Insert(0, Color.FromArgb(0, 0, 0, 0));
                            }
                        }

                        palette.Sort((x, y) => x.A.CompareTo(y.A));

                        if (log)
                        {
                            logContent += "New palette:\n";
                            for (int ci = 0; ci < palette.Count; ci++)
                            {
                                Color c = palette[ci];
                                logContent += ci + ": " + c.ToString() + "\n";
                            }
                        }
                        logContent += "\n\n";

                        byte[] paletteBinary = new byte[(palette.Count) * 4];

                        for (int i = 0; i < palette.Count; i++)
                        {
                            paletteBinary[i * 4]     = palette[i].R;
                            paletteBinary[i * 4 + 1] = palette[i].G;
                            paletteBinary[i * 4 + 2] = palette[i].B;
                            paletteBinary[i * 4 + 3] = palette[i].A;
                        }
                        Console.WriteLine("Total color count: " + palette.Count);

                        Texture texture = new Texture(bmp2.Width, bmp2.Height);
                        texture.BitsPerPixel = palette.Count <= 16 ? 4 : 8;
                        texture.Colors       = palette;
                        texture.Palette      = paletteBinary;
                        texture.Bitmap       = bmp2;
                        texture.Name         = Path.GetFileNameWithoutExtension(file);

                        int BitMultiplier = 8 / texture.BitsPerPixel;
                        int DataSize      = (texture.Width * texture.Height) / BitMultiplier;

                        byte[] Unswizzled = new byte[DataSize];
                        int    dataIndex  = 0;
                        for (int y = 0; y < bmp2.Height; y++)
                        {
                            for (int x = 0; x < bmp2.Width; x++)
                            {
                                Color c          = bmp2.GetPixel(x, y);
                                int   colorIndex = texture.Colors.IndexOf(c);
                                if (colorIndex == -1)
                                {
                                    colorIndex  = ColorCompare.GetClosest(texture.Colors, c);
                                    logContent += "Could not find: " + c.ToString() + "\n";
                                    logContent += "Replaced with: " + texture.Colors[colorIndex].ToString() + "\n";
                                }
                                if (texture.BitsPerPixel == 4)
                                {
                                    if (dataIndex % 2 == 0)
                                    {
                                        Unswizzled[dataIndex / 2] = (byte)colorIndex;
                                    }
                                    else
                                    {
                                        Unswizzled[(dataIndex - 1) / 2] |= (byte)((byte)colorIndex << 4 & 0xf0);
                                    }
                                }
                                else
                                {
                                    Unswizzled[dataIndex] = (byte)colorIndex;
                                }
                                dataIndex++;
                            }
                        }
                        if (log)
                        {
                            File.WriteAllText(file + ".log.txt", logContent);
                        }

                        texture.Unswizzled = Unswizzled;
                        texture.Binary     = SwizzleService.Swizzle(texture);
                        imgs.Add(texture);
                    }
                }
            }
            TextureConverter.SaveTexFile(imgs);
        }