diff --git a/GSS2.FrameDecoders/BGGR_PISP_COMP1_RAW_FrameDecoder.cs b/GSS2.FrameDecoders/BGGR_PISP_COMP1_RAW_FrameDecoder.cs index 7fe3b06..2976cd0 100644 --- a/GSS2.FrameDecoders/BGGR_PISP_COMP1_RAW_FrameDecoder.cs +++ b/GSS2.FrameDecoders/BGGR_PISP_COMP1_RAW_FrameDecoder.cs @@ -115,7 +115,7 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1 } } - public uint Fourcc => 0x32525942; // BYR2 + public uint Fourcc => 0x32525942; // BYR2 // Модификатор 0xC00000000000001 в соответствии с libcamera является PISP_FORMAT_MOD_COMPRESS_MODE1 // https://github.com/raspberrypi/libcamera/blob/f0e40f1c50bd0afe65727d6e407d0dcb42666ada/include/linux/drm_fourcc.h#L1692 // Режимы компрессии Raspberry Pi PiSP описаны в документации ядра linux: @@ -159,8 +159,13 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1 int idx = y * width + x; double value = unpackedAvg[idx]; + // Коррекция уровня чёрного value = Math.Max(0, value - blackLevel); + // Коррекция пересвета + // value = value * FlatFieldCorrectionCoefficient(x, y, width, height); + + // Коррекция цветовой температуры bool isBlue = (y % 2 == 0) && (x % 2 == 0); bool isRed = (y % 2 == 1) && (x % 2 == 1); @@ -180,4 +185,19 @@ public class BGGR_PISP_COMP1_RAW_FrameDecoder : IFrameDecoder // BGGR_PISP_COMP1 return bgr; } + + private static float FlatFieldCorrectionCoefficient(int x, int y, int width, int height) + { + var centerXShift = -0.01125904f; + var centerYShift = 0.00997807f; + var alpha = 2.0f; + var beta = 1.0f; + + var centerX = width / 2.0f + width * centerXShift; + var centerY = height / 2.0f + height * centerYShift; + + var distance = MathF.Sqrt(MathF.Pow(centerX - x, 2) + MathF.Pow(centerY - y, 2)); + distance /= MathF.Sqrt(MathF.Pow(width, 2) + MathF.Pow(height, 2)); + return alpha * distance + beta; + } }