forked from amkovkov/GranuSightSoftware2
feat: CameraService camera image capture
Add GSS2.FrameDecoders project for image decoding realizations Add IFrameDecoder interface and FrameDecoderHelper class Add CameraService.CaptureImage method
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user