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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FFmpeg.AutoGen" Version="7.1.1" />
|
||||
<PackageReference Include="OpenCvSharp4" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="LibCameraSharp" Version="0.5.2-20251028" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
using LibCameraSharp;
|
||||
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace GSS2.FrameDecoders;
|
||||
|
||||
public interface IFrameDecoder
|
||||
{
|
||||
public uint Fourcc { get; }
|
||||
public ulong Modifier { get; }
|
||||
public ColorSpace.PrimariesEnum PrimariesEnum { get; }
|
||||
public ColorSpace.TransferFunctionEnum TransferFunctionEnum { get; }
|
||||
public ColorSpace.YcbcrEncodingEnum YcbcrEncodingEnum { get; }
|
||||
public ColorSpace.RangeEnum RangeEnum { get; }
|
||||
|
||||
public Mat Decode(int width, int height, int stride, List<Memory<byte>> planes);
|
||||
}
|
||||
Reference in New Issue
Block a user