public async Task GrayscaleAsync() { using (RawDataManager = new RawDataConverter(ProcessedImage, Ratios)) { int totalLength = ProcessedImage.Height * ProcessedImage.Width; int chunkLength = totalLength / TasksCount; int numberOfTasks = TasksCount; if (ProcessedImage.Height < TasksCount) { numberOfTasks = 1; } Task[] tasks = new Task[numberOfTasks]; for (int i = 0; i < TasksCount; i++) { int startIndex = i * chunkLength; int length; if (i == TasksCount - 1) { length = totalLength - startIndex; } else { length = chunkLength; } tasks[i] = Task.Run(() => ProcessSegment(startIndex, length)); } await Task.WhenAll(tasks); } }
public void Grayscale() { using (RawDataManager = new RawDataConverter(ProcessedImage, Ratios)) { int totalLength = ProcessedImage.Height * ProcessedImage.Width; ProcessSegment(0, totalLength); } }