public static Palette LoadAP(byte[] img) { Palette Pal = new Palette(); for (int i = 0; i < img.Length / 4; i++) { byte B = img[4 * i]; byte G = img[4 * i + 1]; byte R = img[4 * i + 2]; byte A = img[4 * i + 3]; Colour C = new Colour(R, G, B, A); Pal.Colours.Add(C); } return Pal; }
public HSLColour(Colour Clr) { double R = (double)Clr.R / (double)255; double G = (double)Clr.G / (double)255; double B = (double)Clr.B / (double)255; double Cmax = Math.Max(R, Math.Max(G, B)); double Cmin = Math.Min(R, Math.Min(G, B)); double delta = Cmax - Cmin; H = (ushort)(delta == 0 ? 0 : Cmax == R ? 60 * (((G - B) / delta) % 6) : Cmax == G ? 60 * ((B - R) / delta + 2) : 60 * ((R - G) / delta + 4)); L = (double)((Cmax + Cmin) / 2); S = (double)(delta == 0 ? 0 : delta / (1 - Math.Abs(2 * L - 1))); A = Clr.A; }
public static Tuple<List<PalMap>, Palette> Convert(byte[][] Imgs, int W) { Palette Pal = new Palette(); List<PalMap> PMs = new List<PalMap>(); foreach (byte[] Img in Imgs) { PalMap PM = new PalMap(); PMs.Add(PM); PM.Pixels = new int[Img.Length / W][]; for (int i = 0; i < PM.Pixels.Length; i++) PM.Pixels[i] = new int[W]; for (int i = 0; i < Img.Length / 4; i++) { byte B = Img[4 * i]; byte G = Img[4 * i + 1]; byte R = Img[4 * i + 2]; byte A = Img[4 * i + 3]; Colour C = new Colour(R, G, B, A); if (Pal.Colours.Count == 0) { Pal.Colours.Add(C); PM.Pixels[i / W][i % W] = 0; } else for (int j = 0; j < Pal.Colours.Count; j++) if (Pal.Colours[j].DecCode == C.DecCode) { PM.Pixels[i / W][i % W] = j; break; } else if (j == Pal.Colours.Count - 1) { Pal.Colours.Add(C); PM.Pixels[i / W][i % W] = j + 1; } } } return new Tuple<List<PalMap>, Palette>(PMs, Pal); }