blob: b3909911f8525db04dcab2140bdad7381c901d86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
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;
/// <summary>
/// Initializes a new instance of the <see cref="TurboJpegEncoder"/> class.
/// </summary>
/// <param name="frame">The frame.</param>
public TurboJpegEncoder(IFrame frame) : base(frame)
{
_compressor = new TJCompressor();
}
/// <summary>
/// Returns a stream containing the encoded frame.
/// </summary>
/// <returns></returns>
public override MemoryStream ToStream()
{
return ToStream(100);
}
/// <summary>
/// Returns a byte array containing the encoded frame.
/// </summary>
/// <returns></returns>
public override byte[] ToArray()
{
return ToArray(100);
}
/// <summary>
/// Returns a stream containing the encoded frame with the specified quality.
/// </summary>
/// <param name="quality">The quality.</param>
/// <returns></returns>
public virtual MemoryStream ToStream(int quality)
{
return new MemoryStream(ToArray(quality));
}
/// <summary>
/// Returns a byte array containing the encoded frame with the specified quality.
/// </summary>
/// <param name="quality">The quality.</param>
/// <returns></returns>
public byte[] ToArray(int quality)
{
return _compressor.Compress(Frame.ToBitmap(), TJSubsamplingOption.Chrominance411, quality, TJFlags.None);
}
}
}
|