예제 #1
0
        public static Color GetColorFromHSV(FastPixelHSV pixel)
        {
            int R = 0, G = 0, B = 0;

            HsvToRgb(pixel.GetHue(), pixel.GetSaturation() / 100.0, pixel.GetValue() / 100.0, out R, out G, out B);
            return(Color.FromArgb(R, G, B));
        }
예제 #2
0
        public override bool IsMatching(FastPixelHSV pixel)
        {
            if ((pixel.Monochrome >= MonoMin) && (pixel.Monochrome <= MonoMax))
            {
                int Hue = pixel.GetHue();
                return((Hue >= HueMin) && (Hue <= HueMax));
            }

            return(false);
        }
예제 #3
0
        private float GetActionSlotPixelValue(FastPixelHSV pixel)
        {
            const int hueSteps  = 16;
            const int monoSteps = 16;

            const float monoScale = 1.0f / monoSteps;
            const float hueScale  = monoScale / hueSteps;

            int hueV  = pixel.GetHue() / (360 / hueSteps);
            int monoV = pixel.GetMonochrome() / (256 / monoSteps);

            float pixelV = (hueV * hueScale) + (monoV * monoScale);

            return(pixelV);
        }
예제 #4
0
        protected void GetAverageChestColor(FastBitmapHSV bitmap, Point chestPos, out int avgHue, out int avgSat)
        {
            float scale  = 1.0f / (rectChestArea.Width * rectChestArea.Height);
            float accHue = 0;
            float accSat = 0;

            for (int idxX = 0; idxX < rectChestArea.Width; idxX++)
            {
                for (int idxY = 0; idxY < rectChestArea.Height; idxY++)
                {
                    FastPixelHSV testPx = bitmap.GetPixel(chestPos.X + rectChestArea.X + idxX, chestPos.Y + rectChestArea.Y + idxY);
                    accHue += testPx.GetHue();
                    accSat += testPx.GetSaturation();
                }
            }

            avgHue = (int)(accHue * scale);
            avgSat = (int)(accSat * scale);
        }
예제 #5
0
        public override bool IsMatching(FastPixelHSV pixel)
        {
            int Saturation = pixel.GetSaturation();

            if ((Saturation < SaturationMin) || (Saturation > SaturationMax) ||
                (pixel.Value < ValueMin) || (pixel.Value > ValueMax))
            {
                return(false);
            }

            int Hue = pixel.GetHue();

            if (HueMin < 0 && Hue > 200)
            {
                Hue -= 360;
            }

            return((Hue >= HueMin) && (Hue <= HueMax));
        }
예제 #6
0
        public static FastPixelHSV GetAverageColor(FastBitmapHSV bitmap, Rectangle bounds)
        {
            float hueAcc = 0.0f;
            float satAcc = 0.0f;
            float valAcc = 0.0f;
            float scale  = 1.0f / bounds.Width;

            for (int idx = 0; idx < bounds.Width; idx++)
            {
                FastPixelHSV testPx = bitmap.GetPixel(bounds.X + idx, bounds.Y);
                hueAcc += testPx.GetHue();
                satAcc += testPx.GetSaturation();
                valAcc += testPx.GetValue();
            }

            FastPixelHSV avgPx = new FastPixelHSV();

            avgPx.SetHSV((int)(hueAcc * scale), (int)(satAcc * scale), (int)(valAcc * scale));
            return(avgPx);
        }
예제 #7
0
        protected float[] ExtractStatData(FastBitmapHSV bitmap, Point[] playerPos, int playerIdx, int statIdx)
        {
            // scan area: (9+1)x7
            float[] values   = new float[(11 + 1) * 9];
            int     writeIdx = 0;

            for (int idxY = 0; idxY < 9; idxY++)
            {
                float accHueLine = 0.0f;
                for (int idxX = 0; idxX < 11; idxX++)
                {
                    FastPixelHSV pixel = bitmap.GetPixel(playerPos[playerIdx].X + posStatOffset[statIdx].X + idxX - 1, playerPos[playerIdx].Y + posStatOffset[statIdx].Y + idxY - 1);
                    values[writeIdx] = pixel.GetMonochrome() / 255.0f;
                    accHueLine      += pixel.GetHue() / 360.0f;
                    writeIdx++;
                }

                values[writeIdx] = accHueLine / 11;
                writeIdx++;
            }

            return(values);
        }
예제 #8
0
        protected EElementType ScanElementType(FastBitmapHSV bitmap, Rectangle bounds)
        {
            EElementType element    = EElementType.Unknown;
            int          countElemR = 0;
            int          countElemG = 0;
            int          countElemB = 0;
            int          countTotal = 0;

            const int hueDrift = 30;
            const int hueB     = 180;
            const int hueG     = 130;
            const int hueR     = 15;

            foreach (var sampleBounds in rectActionElements)
            {
                for (int idxY = 0; idxY < sampleBounds.Height; idxY++)
                {
                    for (int idxX = 0; idxX < sampleBounds.Width; idxX++)
                    {
                        FastPixelHSV testPx = bitmap.GetPixel(bounds.X + sampleBounds.X + idxX, bounds.Y + sampleBounds.Y + idxY);
                        countTotal++;

                        int testMono = testPx.GetMonochrome();
                        if (testMono < 210)
                        {
                            int testHue = testPx.GetHue();
                            countElemR += ((testHue > (hueR + 360 - hueDrift)) || (testHue < (hueR + hueDrift))) ? 1 : 0;
                            countElemG += ((testHue > (hueG - hueDrift)) && (testHue < (hueG + hueDrift))) ? 1 : 0;
                            countElemB += ((testHue > (hueB - hueDrift)) && (testHue < (hueB + hueDrift))) ? 1 : 0;
                        }
                    }
                }
            }

            int minThr = countTotal * 30 / 100;

            if ((countElemR > minThr) && (countElemR > countElemG) && (countElemR > countElemB))
            {
                element = EElementType.Fire;
            }
            else if ((countElemG > minThr) && (countElemG > countElemR) && (countElemG > countElemB))
            {
                element = EElementType.Wind;
            }
            else if ((countElemB > minThr) && (countElemB > countElemR) && (countElemB > countElemG))
            {
                element = EElementType.Water;
            }

            if (element == EElementType.Unknown)
            {
                countElemR = 0;
                countElemG = 0;
                countElemB = 0;

                for (int idxY = 0; idxY < bounds.Height; idxY++)
                {
                    for (int idxX = 0; idxX < bounds.Width; idxX++)
                    {
                        FastPixelHSV testPx = bitmap.GetPixel(bounds.X + idxX, bounds.Y + idxY);

                        int testMono = testPx.GetMonochrome();
                        if (testMono < 210)
                        {
                            int testHue = testPx.GetHue();
                            countElemR += ((testHue > (hueR + 360 - hueDrift)) || (testHue < (hueR + hueDrift))) ? 1 : 0;
                            countElemG += ((testHue > (hueG - hueDrift)) && (testHue < (hueG + hueDrift))) ? 1 : 0;
                            countElemB += ((testHue > (hueB - hueDrift)) && (testHue < (hueB + hueDrift))) ? 1 : 0;
                        }
                    }
                }

                countTotal = bounds.Width * bounds.Height;

                minThr = countTotal * 30 / 100;
                if ((countElemR > minThr) && (countElemR > countElemG) && (countElemR > countElemB))
                {
                    element = EElementType.Fire;
                }
                else if ((countElemG > minThr) && (countElemG > countElemR) && (countElemG > countElemB))
                {
                    element = EElementType.Wind;
                }
                else if ((countElemB > minThr) && (countElemB > countElemR) && (countElemB > countElemG))
                {
                    element = EElementType.Water;
                }
            }

            if (DebugLevel >= EDebugLevel.Verbose)
            {
                Console.WriteLine(">> elem counters: R:{0}, G:{1}, B:{2} => {3}", countElemR, countElemG, countElemB, element);
            }
            return(element);
        }