private void Pending_ProgressChanged(object sender, MapCreationProgress e) { var pending = (PendingMapsWithID)sender; decimal progress = e.PercentageComplete; foreach (var id in pending.IDs) { ImportZone.SetProgress(id, progress); } }
public static IEnumerable <JavaMap> FromSettings(MapCreationSettings settings, IJavaVersion mapping, IProgress <MapCreationProgress> progress) { Bitmap original = ResizeImg(settings.Original, MAP_WIDTH * settings.SplitW, MAP_HEIGHT * settings.SplitH, settings.InterpMode, !settings.Stretch); LockBitmap final = new LockBitmap((Bitmap)original.Clone()); final.LockBits(); // first index = which map this is var colors = new byte[settings.NumberOfMaps][]; for (int i = 0; i < colors.Length; i++) { colors[i] = new byte[MAP_WIDTH * MAP_HEIGHT]; } var report = new MapCreationProgress(); #region java map algorithm for (int y = 0; y < final.Height; y++) { report.PercentageComplete = ((decimal)y) / final.Height; progress.Report(report); for (int x = 0; x < final.Width; x++) { Color oldpixel = final.GetPixel(x, y); var newpixel = GetBestPixel(oldpixel, settings.Algorithm, mapping); final.SetPixel(x, y, newpixel); if (settings.Dither) { // floyd-steinberg int error_a = oldpixel.A - newpixel.A; int error_r = oldpixel.R - newpixel.R; int error_g = oldpixel.G - newpixel.G; int error_b = oldpixel.B - newpixel.B; GiveError(final, x + 1, y, error_a, error_r, error_g, error_b, 7); GiveError(final, x - 1, y + 1, error_a, error_r, error_g, error_b, 3); GiveError(final, x, y + 1, error_a, error_r, error_g, error_b, 5); GiveError(final, x + 1, y + 1, error_a, error_r, error_g, error_b, 1); } int currentmap = y / MAP_HEIGHT * settings.SplitW + x / MAP_WIDTH; int currentpixel = MAP_WIDTH * (y % MAP_HEIGHT) + (x % MAP_WIDTH); if (newpixel == Color.FromArgb(0, 0, 0, 0)) { colors[currentmap][currentpixel] = 0x00; } else { colors[currentmap][currentpixel] = mapping.ColorToByte(newpixel); } } } #endregion final.UnlockBits(); var maps = new List <JavaMap>(); for (int y = 0; y < settings.SplitH; y++) { for (int x = 0; x < settings.SplitW; x++) { Rectangle crop = new Rectangle( x * original.Width / settings.SplitW, y * original.Height / settings.SplitH, original.Width / settings.SplitW, original.Height / settings.SplitH); var map_image = CropImage(final.GetImage(), crop); maps.Add(new JavaMap( CropImage(original, crop), map_image, colors[settings.SplitW * y + x])); } } return(maps); }