forked from amkovkov/GranuSightSoftware2
63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using GSS2.FrameDecoders;
|
|
|
|
using LibCameraSharp;
|
|
|
|
public static class FrameDecoderHelper
|
|
{
|
|
private static readonly IReadOnlyList<IFrameDecoder> _decoders;
|
|
|
|
static FrameDecoderHelper()
|
|
{
|
|
_decoders = LoadDecoders();
|
|
}
|
|
|
|
private static IReadOnlyList<IFrameDecoder> LoadDecoders()
|
|
{
|
|
var decoderInterface = typeof(IFrameDecoder);
|
|
var assembly = decoderInterface.Assembly;
|
|
|
|
var decoders = assembly
|
|
.GetTypes()
|
|
.Where(t =>
|
|
!t.IsAbstract &&
|
|
!t.IsInterface &&
|
|
decoderInterface.IsAssignableFrom(t))
|
|
.Select(CreateDecoderInstance)
|
|
.Where(d => d is not null)
|
|
.Cast<IFrameDecoder>()
|
|
.ToList();
|
|
|
|
return decoders;
|
|
}
|
|
private static IFrameDecoder? CreateDecoderInstance(Type type)
|
|
{
|
|
if (type.GetConstructor(Type.EmptyTypes) is null)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
return (IFrameDecoder?)Activator.CreateInstance(type);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static IFrameDecoder? FindDecoder(
|
|
uint fourcc,
|
|
ulong modifier,
|
|
ColorSpace.PrimariesEnum? primariesEnum,
|
|
ColorSpace.TransferFunctionEnum? transferFunctionEnum,
|
|
ColorSpace.YcbcrEncodingEnum? ycbcrEncodingEnum,
|
|
ColorSpace.RangeEnum? rangeEnum)
|
|
{
|
|
return _decoders.FirstOrDefault(d =>
|
|
d.Fourcc == fourcc &&
|
|
d.Modifier == modifier &&
|
|
d.PrimariesEnum == primariesEnum &&
|
|
d.TransferFunctionEnum == transferFunctionEnum &&
|
|
d.YcbcrEncodingEnum == ycbcrEncodingEnum &&
|
|
d.RangeEnum == rangeEnum);
|
|
}
|
|
} |