|
| 1 | +using System.Drawing; |
| 2 | +using FortniteOverlay.Properties; |
| 3 | + |
| 4 | +namespace FortniteOverlay |
| 5 | +{ |
| 6 | + internal class ImageProcessing |
| 7 | + { |
| 8 | + public static bool IsPlaying(Bitmap screenshot, PixelPositions positions) |
| 9 | + { |
| 10 | + if (screenshot == null) { return false; } |
| 11 | + var pix = screenshot.GetPixel(positions.ShieldIcon.X, positions.ShieldIcon.Y); |
| 12 | + if (pix.R < 190 || pix.G < 190 || pix.B < 190) |
| 13 | + { |
| 14 | + // debug: Shield indicator not detected (vals: {pix.R},{pix.G},{pix.B}) |
| 15 | + return false; |
| 16 | + } |
| 17 | + |
| 18 | + return true; |
| 19 | + } |
| 20 | + |
| 21 | + public static bool IsSpectating(Bitmap screenshot, PixelPositions positions) |
| 22 | + { |
| 23 | + if (screenshot == null) { return false; }; |
| 24 | + |
| 25 | + var pix = screenshot.GetPixel(positions.SpectatingText[0].X, positions.SpectatingText[0].Y); |
| 26 | + if (pix.R < 255 || pix.G < 255 || pix.B < 255) |
| 27 | + { |
| 28 | + return false; |
| 29 | + } |
| 30 | + |
| 31 | + pix = screenshot.GetPixel(positions.SpectatingText[1].X, positions.SpectatingText[1].Y); |
| 32 | + if (pix.R < 255 || pix.G < 255 || pix.B < 255) |
| 33 | + { |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + // debug: Detected spectating text. |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + public static Bitmap MarkStaleImage(Bitmap bmp) |
| 42 | + { |
| 43 | + using (Graphics g = Graphics.FromImage(bmp)) |
| 44 | + { |
| 45 | + int width = bmp.Width; |
| 46 | + int height = bmp.Height; |
| 47 | + |
| 48 | + Image outdated = Resources.outdated; |
| 49 | + |
| 50 | + Rectangle rect = new Rectangle(0, 0, width, height); |
| 51 | + using (Brush darken = new SolidBrush(Color.FromArgb(96, Color.Black))) |
| 52 | + { |
| 53 | + g.FillRectangle(darken, rect); |
| 54 | + } |
| 55 | + |
| 56 | + var smallestSide = (height < width) ? height : width; |
| 57 | + var leftEdge = (width / 2) - (smallestSide / 2); |
| 58 | + var topEdge = (height / 2) - (smallestSide / 2); |
| 59 | + |
| 60 | + g.DrawImage(outdated, new Rectangle(leftEdge + (int)(smallestSide * 0.05), |
| 61 | + topEdge + (int)(smallestSide * 0.05), |
| 62 | + smallestSide - (int)(smallestSide * 0.10), |
| 63 | + smallestSide - (int)(smallestSide * 0.10))); |
| 64 | + } |
| 65 | + return bmp; |
| 66 | + } |
| 67 | + |
| 68 | + public static Bitmap CropGear(Bitmap bmp, PixelPositions positions) |
| 69 | + { |
| 70 | + int slotSelected = -1; |
| 71 | + for (int i = 0; i < positions.Slots.Length; i++) |
| 72 | + { |
| 73 | + var pix = bmp.GetPixel(positions.Slots[i].X, positions.Slots[i].Y); |
| 74 | + |
| 75 | + if (pix.R < 255 || pix.G < 255 || pix.B < 255) |
| 76 | + { |
| 77 | + // FIXME: wtf is this checking for? |
| 78 | + if (pix.R != 127 || pix.G != 127 || pix.B != 127) |
| 79 | + { |
| 80 | + continue; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + slotSelected = i; |
| 85 | + break; |
| 86 | + } |
| 87 | + |
| 88 | + // debug: Selected slot: {slotSelected} |
| 89 | + |
| 90 | + Bitmap cropped = new Bitmap(positions.SlotSize.Width * 5, positions.SlotSize.Height); |
| 91 | + using (Graphics g = Graphics.FromImage(cropped)) |
| 92 | + { |
| 93 | + for (int i = 0; i < positions.Slots.Length; i++) |
| 94 | + { |
| 95 | + var ofs = (slotSelected == i) ? positions.SelectedSlotOffset : 0; |
| 96 | + g.DrawImage(bmp, |
| 97 | + new Rectangle(i * positions.SlotSize.Width, 0, positions.SlotSize.Width, positions.SlotSize.Height), |
| 98 | + new Rectangle(positions.Slots[i].X, positions.Slots[i].Y + ofs, positions.SlotSize.Width, positions.SlotSize.Height), |
| 99 | + GraphicsUnit.Pixel); |
| 100 | + } |
| 101 | + |
| 102 | + // keys (defunct) |
| 103 | + //g.DrawImage(bmp, |
| 104 | + // new Rectangle(positions.SlotSize.Width * 5, 0, positions.SlotSize.Width, positions.SlotSize.Height), |
| 105 | + // new Rectangle(positions.Keys.X, positions.Keys.Y, positions.SlotSize.Width, positions.SlotSize.Height), |
| 106 | + // GraphicsUnit.Pixel); |
| 107 | + } |
| 108 | + |
| 109 | + return cropped; |
| 110 | + } |
| 111 | + |
| 112 | + public static void RenderDebugMarkers(ref Bitmap blankScreenshot, PixelPositions positions) |
| 113 | + { |
| 114 | + Pen pen = new Pen(Color.Red, 1); |
| 115 | + |
| 116 | + using (Graphics g = Graphics.FromImage(blankScreenshot)) |
| 117 | + { |
| 118 | + for (int i = 0; i < positions.Slots.Length; i++) |
| 119 | + { |
| 120 | + g.DrawRectangle(pen, new Rectangle(positions.Slots[i].X - 1, positions.Slots[i].Y - 1, positions.SlotSize.Width + 1, positions.SlotSize.Height + 1)); |
| 121 | + } |
| 122 | + |
| 123 | + // keys are defunct |
| 124 | + //g.DrawRectangle(pen, new Rectangle(positions.Keys.X - 1, positions.Keys.Y - 1, positions.SlotSize.Width + 1, positions.SlotSize.Height + 1)); |
| 125 | + |
| 126 | + g.DrawEllipse(pen, positions.ShieldIcon.X - 1, positions.ShieldIcon.Y - 1, 2, 2); |
| 127 | + |
| 128 | + g.DrawEllipse(pen, positions.SpectatingText[0].X - 1, positions.SpectatingText[0].Y - 1, 2, 2); |
| 129 | + g.DrawEllipse(pen, positions.SpectatingText[1].X - 1, positions.SpectatingText[1].Y - 1, 2, 2); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments