//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageProcessorCore.Processors
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
///
/// Allows the application of processors to images.
///
/// The pixel format.
/// The packed format. uint, long, float.
public abstract class ImageProcessor : IImageProcessor
where TColor : IPackedVector
where TPacked : struct
{
///
/// Gets or sets the number of rows processed by a derived class.
///
protected int NumRowsProcessed;
///
public event ProgressEventHandler OnProgress;
///
public virtual ParallelOptions ParallelOptions { get; set; } = Bootstrapper.Instance.ParallelOptions;
///
public virtual bool Compand { get; set; } = false;
///
/// Gets or sets the total number of rows that will be processed by a derived class.
///
protected int TotalRows { get; set; }
///
/// Must be called by derived classes after processing a single row.
///
protected void OnRowProcessed()
{
if (this.OnProgress != null)
{
int currThreadNumRows = Interlocked.Add(ref this.NumRowsProcessed, 1);
// Multi-pass filters process multiple times more rows than totalRows, so update totalRows on the fly
if (currThreadNumRows > this.TotalRows)
{
this.TotalRows = currThreadNumRows;
}
// Report progress. This may be on the client's thread, or on a Task library thread.
this.OnProgress(this, new ProgressEventArgs { RowsProcessed = currThreadNumRows, TotalRows = this.TotalRows });
}
}
}
}