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

Add --flashed flag for screenshot generation #17

Merged
merged 1 commit into from
Oct 29, 2022
Merged
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
2 changes: 1 addition & 1 deletion CommandLine/Commands/ScreenshotCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static bool WriteScreenToDisk(string fileName, ArraySegment<byte> memory, Screen
{
var newFileName = Path.Combine(settings.OutputFolder, Path.ChangeExtension(Path.GetFileName(fileName), "png"));
Out.Write($" Dumping {fileName} @ {address} to {newFileName}");
using var bitmap = SpectrumDisplay.GetBitmap(memory.ToArray(), address);
using var bitmap = SpectrumDisplay.GetBitmap(memory.ToArray(), address, settings.Flashed);
bitmap.Save(newFileName, ImageFormat.Png);
}

Expand Down
6 changes: 5 additions & 1 deletion CommandLine/Commands/Settings/ScreenshotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public class ScreenshotSettings : RequiredSettings
public bool Png { get; set; }

[CommandOption("--scr")]
[Description("Write a .scr version of the screenshot.")]
[Description("Write a .scr version of the screenshot (default).")]
public bool Scr { get; set; }

[CommandOption("--flashed")]
[Description("Write png with the alternate flashed attribute state.")]
public bool Flashed { get; set; }
}
}
4 changes: 2 additions & 2 deletions CommandLine/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"profiles": {
"CommandLine": {
"commandName": "Project",
"commandLineArgs": "chead *.ch8 test",
"workingDirectory": "d:\\zxo\\_Ports\\Micropack"
"commandLineArgs": "screenshot *.z80 --png --flashed",
"workingDirectory": "c:\\temp"
}
}
}
66 changes: 34 additions & 32 deletions Common/Display/SpectrumDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,44 @@ static SpectrumDisplay()
{
UInt16 pos = 0;
for (var third = 0; third < 3; third++)
for (var line = 0; line < 8; line++)
for (var y = 0; y < 63; y += 8)
{
lookupY[y + line + third * 64] = pos;
pos += 32;
}
for (var line = 0; line < 8; line++)
for (var y = 0; y < 63; y += 8)
{
lookupY[y + line + third * 64] = pos;
pos += 32;
}
}

public static bool IsBlank(byte[] buffer, int offset)
{
return buffer.Skip(offset).Take(768).All(b => b == 0);
}

public static Bitmap GetBitmap(byte[] buffer, int offset)
public static Bitmap GetBitmap(byte[] buffer, int offset, bool altFlashFrame = false)
{
var bitmap = new Bitmap(PixelWidth, PixelHeight);

for (var ay = 0; ay < AttributeHeight; ay++)
for (var ax = 0; ax < AttributeWidth; ax++)
{
var attribute = buffer[offset + ay * AttributeWidth + AttributeOffset + ax];
var bright = (Byte) ((attribute & 64) >> 3);
var foreColor = palette[(attribute & 7) | bright];
var backColor = palette[((attribute & 56) >> 3) | bright];
for (var py = 0; py < 8; py++)
for (var ax = 0; ax < AttributeWidth; ax++)
{
var y = ay * 8 + py;
var pixels = buffer[offset + lookupY[y] + ax];
for (var px = 0; px < 8; px++)
var attribute = buffer[offset + ay * AttributeWidth + AttributeOffset + ax];
var bright = (Byte)((attribute & 64) >> 3);
var foreColor = palette[(attribute & 7) | bright];
var backColor = palette[((attribute & 56) >> 3) | bright];
if (altFlashFrame && (attribute & 128) == 128)
(backColor, foreColor) = (foreColor, backColor);
for (var py = 0; py < 8; py++)
{
var a = 128 >> px;
var x = ax * 8 + px;
bitmap.SetPixel(x, y, (pixels & a) != 0 ? foreColor : backColor);
var y = ay * 8 + py;
var pixels = buffer[offset + lookupY[y] + ax];
for (var px = 0; px < 8; px++)
{
var a = 128 >> px;
var x = ax * 8 + px;
bitmap.SetPixel(x, y, (pixels & a) != 0 ? foreColor : backColor);
}
}
}
}

return bitmap;
}
Expand All @@ -71,17 +73,17 @@ public static byte[][] GetCandidates(byte[] buffer, int offset)
var uniques = new HashSet<byte[]>(new ByteArrayEqualityComparer());

for (var ay = 0; ay < AttributeHeight; ay++)
for (var ax = 0; ax < AttributeWidth; ax++)
{
var block = new byte[8];
for (var py = 0; py < 8; py++)
for (var ax = 0; ax < AttributeWidth; ax++)
{
var y = ay * 8 + py;
block[py] = buffer[offset + lookupY[y] + ax];
}
var block = new byte[8];
for (var py = 0; py < 8; py++)
{
var y = ay * 8 + py;
block[py] = buffer[offset + lookupY[y] + ax];
}

uniques.Add(block);
}
uniques.Add(block);
}

// Empty and full blocks match too many things and slow things down
uniques.Remove(emptyChar);
Expand All @@ -90,7 +92,7 @@ public static byte[][] GetCandidates(byte[] buffer, int offset)
return uniques.ToArray();
}

private static readonly byte[] emptyChar = {0, 0, 0, 0, 0, 0, 0, 0};
private static readonly byte[] fullChar = {255, 255, 255, 255, 255, 255, 255, 255};
private static readonly byte[] emptyChar = { 0, 0, 0, 0, 0, 0, 0, 0 };
private static readonly byte[] fullChar = { 255, 255, 255, 255, 255, 255, 255, 255 };
}
}