private static Color[] ShiftHue(Color[] colorArray, Color targetColor, int count, Color averageColor) { Color[] shiftedColors = new Color[count]; float targetHue = targetColor.GetHue(); float hueRotation = targetHue - averageColor.GetHue(); float averageBrightness = averageColor.GetBrightness(); float averageSaturation = averageColor.GetSaturation(); for (int i = 0; i < count; i++) { float hue = colorArray[i].GetHue(); float brightness = colorArray[i].GetBrightness(); float saturation = colorArray[i].GetSaturation(); brightness -= averageBrightness; saturation -= averageSaturation; brightness += targetColor.GetBrightness(); saturation += targetColor.GetSaturation(); hue += hueRotation; ColorUtils.ValidateHSB(ref hue, ref saturation, ref brightness); float hueDifference = Math.Abs(targetHue - hue); if (hueDifference >= 90f) { hue = targetHue; } shiftedColors[i] = ColorUtils.FromAHSB(colorArray[i].A, hue, saturation, brightness); } return(shiftedColors); }
public static void ApplyHack(string path, string name) { BinaryReader hack_file = new BinaryReader(File.Open(Path.Combine(path, name), FileMode.Open)); int hack_len = (int)hack_file.BaseStream.Length; byte[] hack_content = new byte[hack_len]; hack_file.Read(hack_content, 0, hack_len); hack_file.Close(); if (name.EndsWith("title-screen")) { Random R = new Random(); int rot = R.Next(360); Color l; float h; for (int i = 0; i < 144 * 64; i++) { int p = (i * 4) + 8; l = Color.FromArgb(hack_content[p + 3], hack_content[p], hack_content[p + 1], hack_content[p + 2]); h = l.GetHue(); h += rot; h %= 360f; l = ColorUtils.FromAHSB(l.A, h, l.GetSaturation(), l.GetBrightness()); hack_content[p] = l.R; hack_content[p + 1] = l.G; hack_content[p + 2] = l.B; hack_content[p + 3] = l.A; } l = Color.FromArgb(hack_content[0x1FE72], hack_content[0x1FE73], hack_content[0x1FE76]); h = l.GetHue(); h += rot; h %= 360f; l = ColorUtils.FromAHSB(255, h, l.GetSaturation(), l.GetBrightness()); hack_content[0x1FE72] = l.R; hack_content[0x1FE73] = l.G; hack_content[0x1FE76] = l.B; } int addr = 0; while (hack_content[addr] != 0xFF) { //Debug.WriteLine(addr.ToString("X4")); uint dest = ReadWriteUtils.Arr_ReadU32(hack_content, addr); addr += 4; uint len = ReadWriteUtils.Arr_ReadU32(hack_content, addr); addr += 4; int f = RomUtils.GetFileIndexForWriting((int)dest); dest -= (uint)RomData.MMFileList[f].Addr; ReadWriteUtils.Arr_Insert(hack_content, addr, (int)len, RomData.MMFileList[f].Data, (int)dest); addr += (int)len; } }
private static Color[] ShiftHue(Color[] colorArray, Color targetColor, int count, bool isZora, bool isGradient, bool isFierceDeity) { Color[] shiftedColors = new Color[count]; Color averageColor; if (isZora && !isGradient) { averageColor = ColorUtils.GetAverageColour(colorArray, 16); } else { averageColor = ColorUtils.GetAverageColour(colorArray, count); } float hueRotation = targetColor.GetHue() - averageColor.GetHue(); float averageBrightness = averageColor.GetBrightness(); float averageSaturation = averageColor.GetSaturation(); for (int i = 0; i < count; i++) { if ((i == 12) && (count == 14)) { shiftedColors[i] = colorArray[i]; continue; } float hue = colorArray[i].GetHue(); float brightness = colorArray[i].GetBrightness(); float saturation = colorArray[i].GetSaturation(); brightness -= averageBrightness; saturation -= averageSaturation; brightness += targetColor.GetBrightness(); saturation += targetColor.GetSaturation(); hue += hueRotation; if (isFierceDeity) { saturation = targetColor.GetSaturation(); hue = targetColor.GetHue(); } if (isZora && isGradient) { if (i > 351) { float x0 = colorArray[352].GetBrightness(); float x1 = colorArray[511].GetBrightness(); float x = colorArray[i].GetBrightness(); hue = targetColor.GetHue(); saturation = targetColor.GetSaturation(); brightness = Interpolate(targetColor.GetBrightness(), colorArray[511].GetBrightness(), x0, x1, x); } } ColorUtils.ValidateHSB(ref hue, ref saturation, ref brightness); shiftedColors[i] = ColorUtils.FromAHSB(colorArray[i].A, hue, saturation, brightness); //this code is a mess if (isZora && isGradient) { if (i < 96) { shiftedColors[i] = colorArray[i]; } else if (i < 352) { float x0 = colorArray[95].GetBrightness(); float x1 = colorArray[352].GetBrightness(); float x = colorArray[i].GetBrightness(); int rr = (int)Interpolate(colorArray[95].R, targetColor.R, x0, x1, x); int gg = (int)Interpolate(colorArray[95].G, targetColor.G, x0, x1, x); int bb = (int)Interpolate(colorArray[95].B, targetColor.B, x0, x1, x); ColorUtils.ValidateRGB(ref rr, ref gg, ref bb); shiftedColors[i] = Color.FromArgb(rr, gg, bb); } } else if (isZora) { if (i > 15) { float x0 = colorArray[14].GetBrightness(); float x1 = colorArray[31].GetBrightness(); float x = colorArray[i].GetBrightness(); int rr = (int)Interpolate(shiftedColors[14].R, colorArray[31].R, x0, x1, x); int gg = (int)Interpolate(shiftedColors[14].G, colorArray[31].G, x0, x1, x); int bb = (int)Interpolate(shiftedColors[14].B, colorArray[31].B, x0, x1, x); ColorUtils.ValidateRGB(ref rr, ref gg, ref bb); shiftedColors[i] = Color.FromArgb(rr, gg, bb); } } } return(shiftedColors); }
private static Color[] ShiftHue(Color[] c, Color target, int count, bool zora, bool grad, bool fd) { Color[] s = new Color[count]; Color a; if (zora && !grad) { a = GetAverageColour(c, 16); } else { a = GetAverageColour(c, count); } float rot = target.GetHue() - a.GetHue(); float avgb = a.GetBrightness(); float avgs = a.GetSaturation(); for (int i = 0; i < count; i++) { if ((i == 12) && (count == 14)) { s[i] = c[i]; continue; } float h = c[i].GetHue(); float b = c[i].GetBrightness(); float sat = c[i].GetSaturation(); b -= avgb; sat -= avgs; b += target.GetBrightness(); sat += target.GetSaturation(); h += rot; if (fd) { sat = target.GetSaturation(); h = target.GetHue(); } if (zora && grad) { if (i > 351) { float x0 = c[352].GetBrightness(); float x1 = c[511].GetBrightness(); float x = c[i].GetBrightness(); h = target.GetHue(); sat = target.GetSaturation(); b = Interpolate(target.GetBrightness(), c[511].GetBrightness(), x0, x1, x); } } h %= 360f; if (h < 0f) { h += 360f; } if (b < 0.0f) { b = 0.0f; } if (b > 1.0f) { b = 1.0f; } if (sat < 0.0f) { sat = 0.0f; } if (sat > 1.0f) { sat = 1.0f; } s[i] = ColorUtils.FromAHSB(c[i].A, h, sat, b); //this code is a mess if (zora && grad) { if (i < 96) { s[i] = c[i]; } else if (i < 352) { float x0 = c[95].GetBrightness(); float x1 = c[352].GetBrightness(); float x = c[i].GetBrightness(); int rr = (int)Interpolate(c[95].R, target.R, x0, x1, x); int gg = (int)Interpolate(c[95].G, target.G, x0, x1, x); int bb = (int)Interpolate(c[95].B, target.B, x0, x1, x); if (rr < 0) { rr = 0; } if (rr > 255) { rr = 255; } if (gg < 0) { gg = 0; } if (gg > 255) { gg = 255; } if (bb < 0) { bb = 0; } if (bb > 255) { bb = 255; } s[i] = Color.FromArgb(rr, gg, bb); } } else if (zora) { if (i > 15) { float x0 = c[14].GetBrightness(); float x1 = c[31].GetBrightness(); float x = c[i].GetBrightness(); int rr = (int)Interpolate(s[14].R, c[31].R, x0, x1, x); int gg = (int)Interpolate(s[14].G, c[31].G, x0, x1, x); int bb = (int)Interpolate(s[14].B, c[31].B, x0, x1, x); if (rr < 0) { rr = 0; } if (rr > 255) { rr = 255; } if (gg < 0) { gg = 0; } if (gg > 255) { gg = 255; } if (bb < 0) { bb = 0; } if (bb > 255) { bb = 255; } s[i] = Color.FromArgb(rr, gg, bb); } } } return(s); }