Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read and save xml file text updated for SaveXmlFileFromCamera method … #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GigeVision.Core/GigeVision.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ItemGroup>
<PackageReference Include="GenICam" Version="2.1.5.1" />
<PackageReference Include="Stira.WpfCore" Version="1.2.2" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.IO.Pipelines" Version="6.0.3" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion GigeVision.Core/Interfaces/IGvcp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public interface IGvcp
Task<bool> ReadXmlFileAsync(string ip = null);

/// <summary>
/// Reads xml file
/// Read and Save xml file
/// </summary>
/// <param name="path">path</param>
/// <param name="ip">Camera IP</param>
Expand Down
60 changes: 59 additions & 1 deletion GigeVision.Core/Services/CameraStreamReceiverPipeline.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Drawing;
using System.IO;
using System.IO.Pipelines;
using System.Net.Sockets;
using System.Threading.Tasks;
Expand All @@ -23,8 +25,13 @@ protected override async void Receiver()

private async Task DisplayStreamPipe(PipeReader reader)
{
int pixel = 0;
var greenColor = 0;
var redColor = 0;
var blueColor = 0;
packetSize = GvspInfo.PayloadSize + GvspInfo.PayloadOffset;
var buffer = new byte[GvspInfo.FinalPacketID * packetSize];
byte[] colorImageBytes = new byte[GvspInfo.FinalPacketID * packetSize * 3];
int startPos = 0;
int totalPacketsInFrame = 0;

Expand Down Expand Up @@ -75,7 +82,58 @@ private async Task DisplayStreamPipe(PipeReader reader)
{
if (packetId - totalPacketsInFrame <= MissingPacketTolerance)
{
FrameReady?.Invoke(totalPacketsInFrame, buffer);
for (int row = 1; row < GvspInfo.Height - 1; row++)
{
for (int column = 1; column < GvspInfo.Width - 1; column += 3)
{
pixel = row * GvspInfo.Width + column;
if (row % 2 == 0 && column % 2 == 0)
{
redColor = buffer[pixel];
greenColor = ((buffer[row * GvspInfo.Width + (column - 1)]) + (buffer[row * GvspInfo.Width + (column + 1)])
+ (buffer[(row - 1) * GvspInfo.Width + (column)]) + (buffer[(row + 1) * GvspInfo.Width + column])) / 4;
blueColor = ((buffer[(row - 1) * GvspInfo.Width + (column - 1)]) + (buffer[(row - 1) * GvspInfo.Width + (column + 1)])
+ (buffer[(row + 1) * GvspInfo.Width + (column - 1)]) + (buffer[(row + 1) * GvspInfo.Width + (column + 1)])) / 4;
colorImageBytes[pixel] = (byte)greenColor;
colorImageBytes[pixel + 1] = (byte)redColor;
colorImageBytes[pixel + 2] = (byte)blueColor;

}
else if (row % 2 != 0 && column % 2 != 0)
{
blueColor = buffer[pixel];
greenColor = ((buffer[row * GvspInfo.Width + (column - 1)]) + (buffer[row * GvspInfo.Width + (column + 1)])
+ (buffer[(row - 1) * GvspInfo.Width + (column)]) + (buffer[(row + 1) * GvspInfo.Width + column])) / 4;
redColor = ((buffer[(row - 1) * GvspInfo.Width + (column - 1)]) + (buffer[(row - 1) * GvspInfo.Width + (column + 1)])
+ (buffer[(row + 1) * GvspInfo.Width + (column - 1)]) + (buffer[(row + 1) * GvspInfo.Width + (column + 1)])) / 4;
colorImageBytes[pixel] = (byte)greenColor;
colorImageBytes[pixel + 1] = (byte)redColor;
colorImageBytes[pixel + 2] = (byte)blueColor;

}
else if (row % 2 == 0 && column % 2 != 0)
{
greenColor = buffer[pixel];
redColor = ((buffer[row * GvspInfo.Width + (column - 1)]) + (buffer[row * GvspInfo.Width + (column + 1)])) / 2;
blueColor = ((buffer[(row - 1) * GvspInfo.Width + column]) + (buffer[(row + 1) * GvspInfo.Width + column])) / 2;
colorImageBytes[pixel] = (byte)greenColor;
colorImageBytes[pixel + 1] = (byte)redColor;
colorImageBytes[pixel + 2] = (byte)blueColor;

}
else if (row % 2 != 0 && column % 2 == 0)
{
greenColor = buffer[pixel];
blueColor = ((buffer[row * GvspInfo.Width + (column - 1)]) + (buffer[row * GvspInfo.Width + (column + 1)])) / 2;
redColor = ((buffer[(row - 1) * GvspInfo.Width + column]) + (buffer[(row + 1) * GvspInfo.Width + column])) / 2;
colorImageBytes[pixel] = (byte)greenColor;
colorImageBytes[pixel + 1] = (byte)redColor;
colorImageBytes[pixel + 2] = (byte)blueColor;

}
}
}
FrameReady?.Invoke(totalPacketsInFrame, colorImageBytes);
totalPacketsInFrame = 0;
}
}
Expand Down