public Tile(int i, byte[] bytes, RbgPFColors colorArray)//Create Char Set Tiles { tbytes = bytes; ColorArray = colorArray; Text = i.ToString("X2"); TMap = CreateBitmap(4, 16, 32); Margin = new Padding(1, 1, 1, 1); Name = i.ToString(); Font = labelFont; Size = new Size(16, 32); }
private static Color GetColorFromValue(RbgPFColors colors, int byteValue, bool bit7) { switch (byteValue & 3) { case 0: return(colors.Colbk); case 1: return(colors.Colpf0); case 2: return(colors.Colpf1); default: // 3 return(bit7 ? colors.Colpf3 : colors.Colpf2); } }
private void CreateImage() { Bitmap tempBitmap = new Bitmap((int)Math.Ceiling(160.0F * zoom), (int)Math.Ceiling(88.0F * zoom)); if (Map != null) { byte[] bytes = Map.MapSet.CharSets.First(set => set.UID == Map.FontID).Data; for (int row = 0; row < 11; row++) { RbgPFColors BLcolor = GetColors(row).ToBLColor(); for (int col = 0; col < 40; col++) { byte tile = Map.MapData[row * 40 + col]; DrawTile(tempBitmap, new Point(col * 4, row * 8), tile, zoom, BLcolor, bytes); } } } CenterPictureBox(pictureBox1, tempBitmap); }
private static void DrawTile(Bitmap tempBitmap, Point topLeft, byte tile, float zoom, RbgPFColors colors, byte[] FntByte) { bool b7 = (tile & 0x80) != 0; for (int i = 0; i < 8; i++) { byte b = FntByte[(tile & 0x7f) * 8 + i]; int minY = (int)Math.Floor((float)(topLeft.Y + i) * zoom); int maxY = (int)Math.Floor((float)(topLeft.Y + i + 1) * zoom); for (int j = 0; j < 4; j++) { Color pfColor = GetColorFromValue(colors, GetValueFromByte(j, b), b7); int minX = (int)Math.Floor((float)(topLeft.X + j) * zoom); int maxX = (int)Math.Floor((float)(topLeft.X + j + 1) * zoom); for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { tempBitmap.SetPixel(x, y, pfColor); } } } } }
private void button1_Click(object sender, EventArgs e) { if (_Ori2ginalImage != null) { using (Bitmap bmp = new Bitmap(_Ori2ginalImage)) { HashSet <Color> colorsSet = ExtractColors(bmp); List <Color> colorsList = new List <Color>(colorsSet); Dictionary <List <byte>, int> charset = new Dictionary <List <byte>, int>(new SequenceComparer <byte>()); List <bool?> bits7 = new List <bool?>(); List <int> map = new List <int>(); PrefillCharset(charset); int PrefillCharsetSize = charset.Keys.Count; int curchar = -1; for (int row = 0; row < _Ori2ginalImage.Height / 8; row++) { for (int col = 0; col < _Ori2ginalImage.Width / 4; col++) { List <byte> bitc = new List <byte>(); bool? bit7 = null; for (int y = 0; y < 8; y++) { int b = 0; for (int x = 0; x < 4; x++) { int colindex = 0; Color customColor = bmp.GetPixel(col * 4 + x, row * 8 + y); if (fiveColorPickerUserControl1.Colbks.Contains(customColor)) { colindex = 0; } else if (fiveColorPickerUserControl1.Colpf0s.Contains(customColor)) { colindex = 1; } else if (fiveColorPickerUserControl1.Colpf1s.Contains(customColor)) { colindex = 2; } else if (fiveColorPickerUserControl1.Colpf2s.Contains(customColor)) { colindex = 3; if (bit7 == true) { MessageBox.Show($"Problem at {col * 4 + x},{row * 8 + y}"); return; } bit7 = false; } else if (fiveColorPickerUserControl1.Colpf3s.Contains(customColor)) { colindex = 3; if (bit7 == false) { MessageBox.Show($"Problem at {col * 4 + x},{row * 8 + y}"); return; } bit7 = true; } b = b * 4 + colindex; } bitc.Add((byte)b); } if (!charset.ContainsKey(bitc)) { while (charset.ContainsValue(curchar)) { curchar--; } charset.Add(bitc, curchar); } map.Add(charset[bitc]); bits7.Add(bit7); } } int[] usedByEngine = { 0x00, // * *Full colbk tile 0x02, // + $80 Exit1 0x03, // + $80 Exit2 0x04, // + $80 Exit3 0x05, // + $80 Exit4 0x06, // + $80 * *Full colpf3 tile = black border tile ** // 0x0F, // + $80 Fatal 0x12, // + $80 Lamp3 Off 0x13, // + $80 Lamp1 0x14, // + $80 Lamp2 0x1E, // + $80 Lamp1 Off 0x1F, // + $80 Lamp2 Off 0x2D, // Only for map $10 - Yin - Yang extra life bonus in the castle 0x2E, // Only for map $10 - Yin - Yang extra life bonus in the castle 0x31, // + $80 Lamp3 /* 0x40, // + $80 Fatal * 0x54, // + $80 Fatal * 0x55, // + $80 Fatal * 0x56, // + $80 Fatal * 0x58, // + $80 Fatal * 0x59, // + $80 Fatal * 0x5A, // + $80 Fatal*/ 0x60, // + $80 Tree 0x62, // Vine ??? /* 0x64, // + $80 Fatal * 0x66, // + $80 Fatal if < Map 10 * 0x72, // + $80 Fatal * 0x73, // + $80 Fatal * 0x74, // + $80 Fatal * 0x75, // + $80 Fatal * 0x76, // + $80 Fatal * 0x77, // + $80 Fatal * 0x78, // + $80 Fatal * 0x79, // + $80 Fatal * 0x7a, // + $80 Fatal * 0x7b, // + $80 Fatal * 0x7C // + $80 Fatal */ }; if (charset.Count - PrefillCharsetSize <= 128 - usedByEngine.Length) { Dictionary <int, int> mapping = new Dictionary <int, int>(); List <int> indexesKO = new List <int>(usedByEngine); List <int> indexes = new List <int>(); int reservedIndex = 128; if (this.radioButtonReserve5.Checked) { reservedIndex -= 5; } else if (this.radioButtonReserve10.Checked) { reservedIndex -= 10; } else if (this.radioButtonReserve15.Checked) { reservedIndex -= 15; } for (int i = 0; i < reservedIndex; i++) { if (!indexesKO.Contains(i)) { indexes.Add(i); } } foreach (KeyValuePair <List <byte>, int> entry in charset) { int c = entry.Value; if (c < 0 && !mapping.ContainsKey(c) && indexes.Count > 0) { int indexe = indexes[0]; indexes.RemoveAt(0); mapping.Add(c, indexe); } } foreach (KeyValuePair <List <byte>, int> entry in charset) { int c = entry.Value; if (c < 0 && mapping.ContainsKey(c)) { int i = mapping[c] * 8; foreach (byte b in entry.Key) { fnt[i++] = b; } } } List <byte> mapByte = new List <byte>(); for (int i = 0; i < map.Count; i++) { int b = map[i]; if (b < 0) { mapByte.Add((byte)(mapping[b] + ((bits7[i] ?? false) ? 0x80 : 0))); } else { mapByte.Add((byte)(b + ((bits7[i] ?? false) ? 0x80 : 0))); } } ReturnCharactedSet = CharacterSet.CreateFromData(fnt); ReturnMap = Map.CreateNewMap(MapSet, ReturnCharactedSet); List <DLI> dlis = new List <DLI>(); RbgPFColors rbgPFColors = new RbgPFColors(fiveColorPickerUserControl1.Colbks[0], fiveColorPickerUserControl1.Colpf3s[0], fiveColorPickerUserControl1.Colpf2s[0], fiveColorPickerUserControl1.Colpf1s[0], fiveColorPickerUserControl1.Colpf0s[0]); AtariPFColors dliColors = rbgPFColors.ToNearestAtariPFColors(); dlis.Add(new DLI(ReturnMap, dliColors, 0, -1)); ReturnMap.DLIS = dlis.ToArray(); ReturnMap.MapData = mapByte.ToArray(); this.DialogResult = DialogResult.OK; } else { MessageBox.Show(String.Format("Too much tiles needed: {0} for {1} maximum", charset.Count, 128 - usedByEngine.Length)); this.DialogResult = DialogResult.Abort; } this.Close(); } } }