Skip to content

Commit 9909f69

Browse files
committed
Windows: New and improved icon editor
1 parent 501ab16 commit 9909f69

File tree

6 files changed

+994
-324
lines changed

6 files changed

+994
-324
lines changed

MemcardRex.Core/Support/BmpBuilder.cs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public byte[] BuildBmp(byte[] RawImageData)
7373
/// <returns></returns>
7474
public byte[] BuildBmp(Color[] RawImageData)
7575
{
76-
byte[] argbBmpHeader = new byte[] // All values are little-endian
76+
byte[] ArgbBmpHeader = new byte[] // All values are little-endian
7777
{
7878
0x42, 0x4D, // Signature 'BM'
7979
0x8a, 0x40, 0x00, 0x00, // Size: 1162 bytes
@@ -114,40 +114,35 @@ public byte[] BuildBmp(Color[] RawImageData)
114114
0x00, 0x00, 0x00, 0x00, // Unknown
115115
};
116116

117-
byte[] bmpImage = new byte[1162];
117+
const int totalSize = 1162;
118+
const int width = 16;
119+
const int dataOffset = 138;
118120

119-
//Copy BMP header to bmp data array
120-
Array.Copy(argbBmpHeader, bmpImage, argbBmpHeader.Length);
121+
byte[] bmpImage = new byte[totalSize];
121122

122-
Color[] FlippedRawImageData = new Color[RawImageData.Length];
123+
// Copy BMP header
124+
Buffer.BlockCopy(ArgbBmpHeader, 0, bmpImage, 0, ArgbBmpHeader.Length);
123125

124-
//Y flip color data for compatibility with BMP
125-
for (int y = 0; y < 8; y++)
126+
// Flip Y-axis directly when writing data
127+
for (int y = 0; y < width; y++)
126128
{
127-
for (int x = 0; x < 16; x++)
128-
{
129-
// Convert 2D (y, x) to 1D index
130-
int indexTop = y * 16 + x; // Current position
131-
int indexBottom = (15 - y) * 16 + x; // Mirrored position
129+
int srcRowStart = y * width;
130+
int destRowStart = dataOffset + (width - 1 - y) * width * 4;
132131

133-
// Swap the colors
134-
FlippedRawImageData[indexTop] = RawImageData[indexBottom];
135-
FlippedRawImageData[indexBottom] = RawImageData[indexTop];
132+
for (int x = 0; x < width; x++)
133+
{
134+
Color pixel = RawImageData[srcRowStart + x];
135+
int destIndex = destRowStart + x * 4;
136+
137+
// Write BGRA format directly (little-endian for BMP)
138+
bmpImage[destIndex] = pixel.B;
139+
bmpImage[destIndex + 1] = pixel.G;
140+
bmpImage[destIndex + 2] = pixel.R;
141+
bmpImage[destIndex + 3] = pixel.A;
136142
}
137143
}
138144

139-
int index = 255;
140-
for (int i = 0; i < 256 * 4; i += 4)
141-
{
142-
bmpImage[bmpImage.Length - i - 1] = FlippedRawImageData[index].A;
143-
bmpImage[bmpImage.Length - i - 2] = FlippedRawImageData[index].R;
144-
bmpImage[bmpImage.Length - i - 3] = FlippedRawImageData[index].G;
145-
bmpImage[bmpImage.Length - i - 4] = FlippedRawImageData[index].B;
146-
index--;
147-
}
148-
149145
return bmpImage;
150-
151146
}
152147
}
153148
}

MemcardRex.Core/Support/ProgramSettings.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ public class ProgramSettings
1313
public string CommunicationPort = "COM1"; //Communication port for Hardware interfaces
1414
public int LastSaveFormat = 0; //Last used format to save memory card
1515
public int LastExportFormat = 0; //Last used format to export save
16-
public string RemoteCommAddress = "192.168.4.1"; // Address / hostname of the remote serial bridge host
17-
public int RemoteCommPort = 23; // Port to open a socket for the remote serial bridge
16+
public string RemoteCommAddress = "192.168.4.1"; //Address / hostname of the remote serial bridge host
17+
public int RemoteCommPort = 23; //Port to open a socket for the remote serial bridge
1818
public int CardSlot = 0; //Active card slot for reading data from PS1CardLink or Unirom
1919
public int ActiveInterface = 0; //Currently active hardware interface
2020
public int WarningMessages = 1; //Show warning messages for dangerous tasks
21+
public int WindowPositionX = 0; //Saved window X coordinate
22+
public int WindowPositionY = 0; //Saved window Y coordinate
23+
public int GridColorValue = 128; //Saved grid value for icon editor
24+
public int IconGridEnabled = 1; //Show grid in icon editor
2125

2226
private const string settingsFilename = "Settings.xml";
2327

@@ -55,6 +59,10 @@ public void LoadSettings(string directory)
5559

5660
RestoreWindowPosition = xmlAppSettings.readXmlEntryInt("RestoreWindowPosition", 0, 1);
5761

62+
WindowPositionX = xmlAppSettings.readXmlEntryInt("WindowPositionX", -65535, 65535);
63+
64+
WindowPositionY = xmlAppSettings.readXmlEntryInt("WindowPositionY", -65535, 65535);
65+
5866
FormatType = xmlAppSettings.readXmlEntryInt("HardwareFormatType", 0, 1);
5967

6068
FixCorruptedCards = xmlAppSettings.readXmlEntryInt("FixCorruptedCards", 0, 1);
@@ -68,6 +76,10 @@ public void LoadSettings(string directory)
6876
ActiveInterface = xmlAppSettings.readXmlEntryInt("ActiveInterface", 0, 10);
6977

7078
WarningMessages = xmlAppSettings.readXmlEntryInt("WarningMessages", 0, 1);
79+
80+
GridColorValue = xmlAppSettings.readXmlEntryInt("GridColorValue", 0, 255);
81+
82+
IconGridEnabled = xmlAppSettings.readXmlEntryInt("IconGridEnabled", 0, 1);
7183
}
7284

7385
/// <summary>
@@ -96,6 +108,10 @@ public void SaveSettings(string directory, string appName, string appVersion)
96108

97109
xmlAppSettings.writeXmlEntry("RestoreWindowPosition", RestoreWindowPosition.ToString());
98110

111+
xmlAppSettings.writeXmlEntry("WindowPositionX", WindowPositionX.ToString());
112+
113+
xmlAppSettings.writeXmlEntry("WindowPositionY", WindowPositionY.ToString());
114+
99115
xmlAppSettings.writeXmlEntry("HardwareFormatType", FormatType.ToString());
100116

101117
xmlAppSettings.writeXmlEntry("FixCorruptedCards", FixCorruptedCards.ToString());
@@ -110,6 +126,10 @@ public void SaveSettings(string directory, string appName, string appVersion)
110126

111127
xmlAppSettings.writeXmlEntry("WarningMessages", WarningMessages.ToString());
112128

129+
xmlAppSettings.writeXmlEntry("GridColorValue", GridColorValue.ToString());
130+
131+
xmlAppSettings.writeXmlEntry("IconGridEnabled", IconGridEnabled.ToString());
132+
113133
xmlAppSettings.closeXmlWriter();
114134
}
115135
}

0 commit comments

Comments
 (0)