private int[,] DistortInternal(RawPalette palette, int offset, int outWidth, int outHeight) { var iter = palette.Distortions.GetEnumerator(); if (!iter.MoveNext()) { return DistortInternal(palette.Data, outWidth, outHeight, a => 0, a => 0); } var dist = iter.Current; var map = dist.DistortMapId; var type = dist.Type; var output = DistortInternal(palette.Data, dist.Rate, offset, outWidth, outHeight, map, type); while (iter.MoveNext()) { dist = iter.Current; var input = output; map = dist.DistortMapId; type = dist.Type; output = DistortInternal(input, dist.Rate, offset, outWidth, outHeight, map, type); } return output; }
public DistortedPalette Distort(RawPalette palette, int offset, int outWidth, int outHeight) { BeginTrack(nameof(Distort), "Distorting palette"); var dist = DistortInternal(palette, offset, outWidth, outHeight); EndTrack(nameof(Distort), "Distorted palette"); return new DistortedPalette(palette.Name, dist); }
public static void Main() { var p = new RawPalette("test", 256, 256, RawPalette.LoadRaw(@"C:\Users\Scott\Documents\Mabinogi\212\color\cloth.raw")); p.ToImage().Save("test.png"); p.Distortions.Add(new DistortionParameters(1, 1, 1, .5)); p.Distortions.Add(new DistortionParameters(1, 2, 1, .3)); p.Distortions.Add(new DistortionParameters(1, 1, 1, .2)); p.Distortions.Add(new DistortionParameters(1, 2, 1, .03)); var map = new DistortionMap(1, File.ReadAllBytes(@"C:\Users\Scott\Documents\Mabinogi\212\color\displace\displace_2.raw")); var dst = new DistortionEngine(new [] { map }); var b = dst.Distort(p, 0, 256, 256); b.ToImage().Save("test_dist.png"); var diff = new DifferenceEngine(); var cm = diff.Calculate(new Rgb {R=255, G=255, B=255}.To<Lab>(), b.LabPalette); cm.ToImage().Save("test_map.png"); var fm = cm.Filter(0); fm.ToImage().Save("test_filter.png"); var picker = new Picker(new[] {new Point(0, 0), new Point(-11, -11), new Point(10, -11), new Point(-11, 10), new Point(10, 10) }); var matches = new MatchingEngine().Match(b, cm, fm, picker); //foreach (var m in matches.OrderByDescending(m => m.NumberOfSuccess).ThenBy(m => m.Score)) //Console.WriteLine(m); }