public void Finish(Guid id, int[] iframe) { ComputationRequest request = null; lock (_Sync) { if (_Package == null) { return; } request = _Package.Finish(id, iframe); if (request == null) { return; } byte[] buffer = new byte[iframe.Length * sizeof(int)]; Buffer.BlockCopy(iframe, 0, buffer, 0, buffer.Length); File.WriteAllBytes(GetPartialFramePath(Name, _FrameCount, request), buffer); } if (_Package.IsDone) { FrameFinished?.Invoke(this, _Package.Frame); } else { FrameChanged?.Invoke(this, new EventArgs()); } }
public void SetCropRequest(int zoomWidth, int zoomHeight, int offsetX, int offsetY) { lock (_Sync) { _CropRequest = new ComputationRequest(_Package.Min, _Package.Max, Width, Height, zoomWidth, zoomHeight, _NUMBER_LENGTH, offsetX, offsetY, ComputationType.Crop); _Package = null; } }
public ComputationPackage(Complex min, Complex max, int width, int height, int partialWidth, int partialHeight, uint limit, int cols, int rows, int threads) : this(min, max, width, height) { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { ComputationRequest request = new ComputationRequest(min, max, width, height, partialWidth, partialHeight, limit, c, r, ComputationType.Render); _Available.Add(request); } } }
public static Project Load(string name) { string json = File.ReadAllText(GetProjectFile(name)); Project proj = JsonConvert.DeserializeObject <Project>(json); proj.Name = name; proj.Palette = InitializePalette(); int latestFrame = Directory .GetDirectories(GetProjectBasePath(name)) .Select(f => { if (int.TryParse(Path.GetFileName(f), out int val)) { return(val); } return(-1); }) .Max(); string framePath = Path.Combine(GetProjectBasePath(name), latestFrame.ToString()); Tuple <Complex, Complex> bounds = JsonConvert.DeserializeObject <Tuple <Complex, Complex> >(File.ReadAllText(Path.Combine(framePath, "_bounds.json"))); proj._FrameCount = latestFrame; proj._Package = new ComputationPackage(bounds.Item1, bounds.Item2, proj.Width, proj.Height); IEnumerable <string> dats = Directory.GetFiles(framePath, "*.dat").Select(f => Path.GetFileName(f)); for (int row = 0; row < proj.Rows; row++) { for (int col = 0; col < proj.Cols; col++) { if (dats.Contains($"{col}.{row}.dat")) { byte[] raw = File.ReadAllBytes(Path.Combine(framePath, $"{col}.{row}.dat")); int[] partialFrame = new int[proj.PartialWidth * proj.PartialWidth]; Buffer.BlockCopy(raw, 0, partialFrame, 0, raw.Length); proj._Package.MapPartialFrame(partialFrame, proj.PartialWidth, proj.PartialHeight, col, row); } else { ComputationRequest request = new ComputationRequest(bounds.Item1, bounds.Item2, proj.Width, proj.Height, proj.PartialWidth, proj.PartialHeight, (uint)proj.Palette.Length - 1, col, row, ComputationType.Render); proj._Package.AddRequest(request); } } } return(proj); }
public ComputationRequest Next() { lock (_Sync) { if (_Available.Count == 0) { return(null); } ComputationRequest request = _Available.First(); _Available.Remove(request); _Pending.Add(request); return(request); } }
public ComputationRequest Finish(Guid id, int[] iframe) { lock (_Sync) { ComputationRequest request = _Pending.FirstOrDefault(r => r.Id == id); if (request == null) { return(null); } _Pending.Remove(request); _Done.Add(request); MapPartialFrame(iframe, request.PartialWidth, request.PartialHeight, request.Col, request.Row); return(request); } }
public ComputationRequest Request() { lock (_Sync) { if (_CropRequest != null) { ComputationRequest tmp = _CropRequest; _CropRequest = null; return(tmp); } if (_Package != null) { return(_Package.Next()); } return(null); } }
private static string GetPartialFramePath(string name, int frameCount, ComputationRequest request) { return(Path.Combine(GetProjectBasePath(name), frameCount.ToString(), $"{request.Col}.{request.Row}.dat")); }
public void AddRequest(ComputationRequest request) { _Available.Add(request); }