Skip to content

Commit

Permalink
Smoothing level selectable.
Browse files Browse the repository at this point in the history
Bugfix in screen size handling.
  • Loading branch information
COMBudda committed Dec 12, 2023
1 parent 0141fa8 commit 9f109e6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 62 deletions.
83 changes: 53 additions & 30 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 48 additions & 32 deletions Form1.cs
Expand Up @@ -68,7 +68,6 @@ public partial class Form1 : Form
UInt32 mSampleRateHz = 24000000;
MLogic mLogic;
MLogic16 mLogic16;
byte mWriteValue = 0;
bool restartRequired = true;

// vsync_polarity handling
Expand All @@ -79,6 +78,7 @@ public partial class Form1 : Form
//Test quality
int hduration = 9999;
bool smoothing = false;
int smoothingLevel = 0;

public Form1()
{
Expand All @@ -104,7 +104,7 @@ private void TShowInfo(object myObject, EventArgs myEventArgs)
screens = 0;
}


private async void TShowPic(object? obj)
{
Bitmap? resized = null;
Expand All @@ -127,7 +127,7 @@ private async void TShowPic(object? obj)
pictureBox1.Image = (Bitmap)resized.Clone();
resized.Dispose();
}
newframe.Dispose();
newframeisready = false;
}
Expand All @@ -137,7 +137,7 @@ private async void TShowPic(object? obj)
}
);
}


// Read input stream to buffer
private async void TBufferInput(object? o)
Expand Down Expand Up @@ -179,7 +179,7 @@ private async void TSaleaeWatchdog(object? o)
{
if (restartRequired)
{
mLogic.ReadStart();
mLogic.ReadStart();
toolStripStatusLabel8.Text = "Connected to Logic with " + mLogic.SampleRateHz + " Hz";
}
restartRequired = false;
Expand Down Expand Up @@ -258,9 +258,9 @@ private async void Form1_Shown(object sender, EventArgs e)

double userfriendlyRate = (double)(newSampleRate / 1000000.0);
string sampleUnit = " MHz";
if (userfriendlyRate < 1) {userfriendlyRate = userfriendlyRate * 1000.0; sampleUnit = " KHz"; }
if (userfriendlyRate < 1) { userfriendlyRate = userfriendlyRate * 1000.0; sampleUnit = " KHz"; }
string rateDescription = userfriendlyRate.ToString() + sampleUnit;
ToolStripItem item = toolStripDropDownButton1.DropDownItems.Add(/*string.Format(sample_rates[i].ToString()*/string.Format("{0,6}",rateDescription, newSampleRate ), null, new EventHandler(SetSamplingRate));
ToolStripItem item = toolStripDropDownButton1.DropDownItems.Add(/*string.Format(sample_rates[i].ToString()*/string.Format("{0,6}", rateDescription, newSampleRate), null, new EventHandler(SetSamplingRate));
item.Tag = newSampleRate;
}

Expand Down Expand Up @@ -366,12 +366,17 @@ public async Task Main(object sender, EventArgs e)

if (newpic != null) // Valid picture received, extract only the area which has data in it
{
RectangleF cloneRect = new RectangleF(0, 0, xposmax_b, yposmax_b);
newframe = (Bitmap)newpic.Clone();
newpic.Dispose();
try
{
RectangleF cloneRect = new RectangleF(0, 0, xposmax_b, yposmax_b);
newframe = (Bitmap)newpic.Clone();

newframeisready = true;
newframeisready = true;
}
catch { };
newpic.Dispose();
}

//Remember bitmap size to use small bitmaps later. This speeds up things.
xposmax_b = xposmax; yposmax_b = yposmax;

Expand All @@ -388,7 +393,7 @@ public async Task Main(object sender, EventArgs e)

private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap((xposmax_b > 10 ? xposmax : 10), (yposmax_b > 10 ? yposmax_b : 10));
Bitmap bmp = new Bitmap((xposmax_b > 10 ? xposmax : 10), (yposmax_b > 10 ? yposmax_b : 10));

int readchar, readFail;
int rawdata = 0;
Expand Down Expand Up @@ -417,6 +422,9 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
int stride = data.Stride;
//experiment

//??? Real max value for consitent frame size
xposmax = 0;

await Task.Run(() =>
{
while (loop && !endofstream)
Expand Down Expand Up @@ -593,15 +601,18 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
if (hsyncc) // Just coming from a hsync signal, new line
{
// expectation setting and limiter
xposmax = xpos;
//Real x-max value for consitent frame size
if (xpos > xposmax) { xposmax = xpos; }
// new line and reset horizontal
if (ypos < height) ypos++;
xpos = 0;
//Quality
//Filter for vsync in the composite mixed sync signal
if (hsync_p < (hduration * 3))
//IF-Then as a filter for vsync in the composite mixed sync signal
if (hsync_p < (hduration * 3) && true)
{
// Accomodate signal change if required
if (hsync_p > (hduration + 1)) hduration = hsync_p;
Expand All @@ -617,7 +628,7 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
}
else // No sync and no recent changes: Set horizontal pixels
{
if (xpos > 0 && xpos < width && xpos < xposmax_b && ypos < yposmax_b ) // Within defined bitmap ?
if (xpos > 0 && xpos < width && xpos < xposmax_b && ypos < yposmax_b) // Within defined bitmap ?
{
byte setblue = blue;
byte setgreen = green;
Expand All @@ -629,9 +640,9 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
if (smoothing)
{
if (!(blue == bline[xpos , ypos])) setblue = bline[xpos , ypos];
if (!(green == gline[xpos , ypos])) setgreen = gline[xpos , ypos];
if (!(red == rline[xpos , ypos])) setred = rline[xpos , ypos];
if (!(blue == bline[xpos, ypos])) setblue = bline[xpos, ypos];
if (!(green == gline[xpos, ypos])) setgreen = gline[xpos, ypos];
if (!(red == rline[xpos, ypos])) setred = rline[xpos, ypos];
}
ptr[(xpos * 3) + ypos * stride] = setblue;
Expand All @@ -641,9 +652,9 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
if (smoothing)
{
bline[xpos, ypos] = (byte)((setblue * 2 + blue) / 3);
gline[xpos, ypos] = (byte)((setgreen * 2 + green) / 3);
rline[xpos, ypos] = (byte)((setred * 2 + red) / 3);
bline[xpos, ypos] = (byte)((setblue * smoothingLevel + blue) / (smoothingLevel + 1));
gline[xpos, ypos] = (byte)((setgreen * smoothingLevel + green) / (smoothingLevel + 1));
rline[xpos, ypos] = (byte)((setred * smoothingLevel + red) / (smoothingLevel + 1));
}
xpos++;
}
Expand All @@ -663,7 +674,7 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)
// Visualize parameters
TB1 = xposmax_b;
TB2 = yposmax_b;

if (xposmax_b < 10 || yposmax_b < 10 || endofstream) return null; // received frame is too small or stream stopped, discard
else
{
Expand All @@ -673,7 +684,7 @@ private async Task<Bitmap> CreatePicture(object sender, EventArgs e)

return bmp;
}


}

Expand Down Expand Up @@ -791,12 +802,6 @@ private void button1_Click(object sender, EventArgs e)
endofstream = true;
}

private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
smoothing = !smoothing;
checkBox5.Checked = smoothing;
}

private void SetSamplingRate(object sender, EventArgs e)
{
ToolStripItem item = (ToolStripItem)sender;
Expand All @@ -806,6 +811,17 @@ private void SetSamplingRate(object sender, EventArgs e)
mLogic.SampleRateHz = newRate;
restartRequired = true;
}
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
smoothingLevel = comboBox1.SelectedIndex;
if (smoothingLevel == 0) { smoothing = false; } else smoothing = true;
}

private void label1_Click(object sender, EventArgs e)
{

}
}

}

0 comments on commit 9f109e6

Please sign in to comment.