using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TurboJpegWrapper;
namespace Tango.RemoteDesktop.Encoders
{
public class TurboJpegEncoder : FrameEncoder
{
private TJCompressor _compressor;
///
/// Initializes a new instance of the class.
///
/// The frame.
public TurboJpegEncoder(IFrame frame) : base(frame)
{
_compressor = new TJCompressor();
}
///
/// Returns a stream containing the encoded frame.
///
///
public override MemoryStream ToStream()
{
return ToStream(100);
}
///
/// Returns a byte array containing the encoded frame.
///
///
public override byte[] ToArray()
{
return ToArray(100);
}
///
/// Returns a stream containing the encoded frame with the specified quality.
///
/// The quality.
///
public virtual MemoryStream ToStream(int quality)
{
return new MemoryStream(ToArray(quality));
}
///
/// Returns a byte array containing the encoded frame with the specified quality.
///
/// The quality.
///
public byte[] ToArray(int quality)
{
return _compressor.Compress(Frame.ToBitmap(), TJSubsamplingOption.Chrominance411, quality, TJFlags.None);
}
}
}