Merge pull request #44 from Mixone-FinallyHere/spriteEditorFixes

Finalized setup of sprite editor in DSPRE formats
This commit is contained in:
Miguel 2025-07-29 11:24:58 +02:00 committed by GitHub
commit a1ffc44078
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 1123 additions and 858 deletions

View File

@ -160,6 +160,7 @@
<Compile Include="Editors\HeadbuttEncounterEditorTab.Designer.cs">
<DependentUpon>HeadbuttEncounterEditorTab.cs</DependentUpon>
</Compile>
<Compile Include="Editors\Utils\IndexedBitmapHandler.cs" />
<Compile Include="Editors\ItemEditor.cs">
<SubType>Form</SubType>
</Compile>
@ -187,7 +188,12 @@
<Compile Include="Editors\NsbtxEditor.Designer.cs">
<DependentUpon>NsbtxEditor.cs</DependentUpon>
</Compile>
<Compile Include="Editors\PokemonSpriteEditor.cs" />
<Compile Include="Editors\PokemonSpriteEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Editors\PokemonSpriteEditor.Designer.cs">
<DependentUpon>PokemonSpriteEditor.cs</DependentUpon>
</Compile>
<Compile Include="Editors\SafariZoneEditor.cs">
<SubType>UserControl</SubType>
</Compile>
@ -242,6 +248,8 @@
<Compile Include="Editors\TrainerEditor.Designer.cs">
<DependentUpon>TrainerEditor.cs</DependentUpon>
</Compile>
<Compile Include="Editors\Utils\NarcReader.cs" />
<Compile Include="Editors\Utils\SpriteSet.cs" />
<Compile Include="EventFileImport.cs">
<SubType>Form</SubType>
</Compile>
@ -513,6 +521,9 @@
<EmbeddedResource Include="Editors\NsbtxEditor.resx">
<DependentUpon>NsbtxEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Editors\PokemonSpriteEditor.resx">
<DependentUpon>PokemonSpriteEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Editors\SafariZoneEditor.resx">
<DependentUpon>SafariZoneEditor.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,364 @@
using DSPRE.Editors.Utils;
using System.Drawing;
using System.Windows.Forms;
using static DSPRE.RomInfo;
namespace DSPRE.Editors
{
partial class PokemonSpriteEditor
{
private System.ComponentModel.IContainer components = null;
private ComboBox IndexBox;
private ComboBox SaveBox;
private ComboBox BasePalette;
private ComboBox ShinyPalette;
private Button OpenPngs;
private Button LoadSheet;
private Button SaveSingle;
private Button MakeShiny;
private Button OpenOther;
private Button SaveChanges;
private Label lblMale;
private Label lblFemale;
private Label BackN;
private Label BackS;
private Label FrontN;
private Label FrontS;
private Label lblNormal;
private Label lblShiny;
private void InitializeComponent()
{
this.OpenPngs = new System.Windows.Forms.Button();
this.LoadSheet = new System.Windows.Forms.Button();
this.SaveSingle = new System.Windows.Forms.Button();
this.MakeShiny = new System.Windows.Forms.Button();
this.OpenOther = new System.Windows.Forms.Button();
this.SaveChanges = new System.Windows.Forms.Button();
this.lblMale = new System.Windows.Forms.Label();
this.lblFemale = new System.Windows.Forms.Label();
this.BackN = new System.Windows.Forms.Label();
this.BackS = new System.Windows.Forms.Label();
this.FrontN = new System.Windows.Forms.Label();
this.FrontS = new System.Windows.Forms.Label();
this.lblNormal = new System.Windows.Forms.Label();
this.lblShiny = new System.Windows.Forms.Label();
this.IndexBox = new System.Windows.Forms.ComboBox();
this.BasePalette = new System.Windows.Forms.ComboBox();
this.ShinyPalette = new System.Windows.Forms.ComboBox();
this.SaveBox = new System.Windows.Forms.ComboBox();
this.femaleBackNormalPic = new System.Windows.Forms.PictureBox();
this.maleBackNormalPic = new System.Windows.Forms.PictureBox();
this.femaleFrontNormalPic = new System.Windows.Forms.PictureBox();
this.maleFrontNormalPic = new System.Windows.Forms.PictureBox();
this.maleBackShinyPic = new System.Windows.Forms.PictureBox();
this.femaleBackShinyPic = new System.Windows.Forms.PictureBox();
this.maleFrontShinyPic = new System.Windows.Forms.PictureBox();
this.femaleFrontShinyPic = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.femaleBackNormalPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maleBackNormalPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.femaleFrontNormalPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maleFrontNormalPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maleBackShinyPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.femaleBackShinyPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maleFrontShinyPic)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.femaleFrontShinyPic)).BeginInit();
this.SuspendLayout();
//
// OpenPngs
//
this.OpenPngs.Enabled = false;
this.OpenPngs.Location = new System.Drawing.Point(475, 8);
this.OpenPngs.Name = "OpenPngs";
this.OpenPngs.Size = new System.Drawing.Size(100, 25);
this.OpenPngs.TabIndex = 3;
this.OpenPngs.Text = "Load Sprite Set";
//
// LoadSheet
//
this.LoadSheet.Location = new System.Drawing.Point(369, 8);
this.LoadSheet.Name = "LoadSheet";
this.LoadSheet.Size = new System.Drawing.Size(100, 25);
this.LoadSheet.TabIndex = 9;
this.LoadSheet.Text = "Load Sprite Sheet";
this.LoadSheet.Click += new System.EventHandler(this.btnLoadSheet_Click);
//
// SaveSingle
//
this.SaveSingle.Location = new System.Drawing.Point(674, 728);
this.SaveSingle.Name = "SaveSingle";
this.SaveSingle.Size = new System.Drawing.Size(70, 21);
this.SaveSingle.TabIndex = 10;
this.SaveSingle.Text = "Save PNG";
this.SaveSingle.Click += new System.EventHandler(this.SaveSingle_Click);
//
// MakeShiny
//
this.MakeShiny.Location = new System.Drawing.Point(12, 728);
this.MakeShiny.Name = "MakeShiny";
this.MakeShiny.Size = new System.Drawing.Size(120, 21);
this.MakeShiny.TabIndex = 11;
this.MakeShiny.Text = "Create Shiny Palette";
//
// OpenOther
//
this.OpenOther.Location = new System.Drawing.Point(12, 8);
this.OpenOther.Name = "OpenOther";
this.OpenOther.Size = new System.Drawing.Size(100, 25);
this.OpenOther.TabIndex = 12;
this.OpenOther.Text = "Open Forms";
this.OpenOther.Visible = false;
this.OpenOther.Click += new System.EventHandler(this.btnOpenOther_Click);
//
// SaveChanges
//
this.SaveChanges.Location = new System.Drawing.Point(642, 12);
this.SaveChanges.Name = "SaveChanges";
this.SaveChanges.Size = new System.Drawing.Size(100, 21);
this.SaveChanges.TabIndex = 13;
this.SaveChanges.Text = "Save Changes";
this.SaveChanges.Click += new System.EventHandler(this.SaveChanges_Click);
//
// lblMale
//
this.lblMale.Location = new System.Drawing.Point(564, 36);
this.lblMale.Name = "lblMale";
this.lblMale.Size = new System.Drawing.Size(100, 23);
this.lblMale.TabIndex = 1;
this.lblMale.Text = "Male";
//
// lblFemale
//
this.lblFemale.Location = new System.Drawing.Point(232, 36);
this.lblFemale.Name = "lblFemale";
this.lblFemale.Size = new System.Drawing.Size(100, 23);
this.lblFemale.TabIndex = 0;
this.lblFemale.Text = "Female";
//
// BackN
//
this.BackN.Location = new System.Drawing.Point(52, 126);
this.BackN.Name = "BackN";
this.BackN.Size = new System.Drawing.Size(56, 23);
this.BackN.TabIndex = 2;
this.BackN.Text = "Back";
//
// BackS
//
this.BackS.Location = new System.Drawing.Point(52, 462);
this.BackS.Name = "BackS";
this.BackS.Size = new System.Drawing.Size(56, 23);
this.BackS.TabIndex = 3;
this.BackS.Text = "Back";
//
// FrontN
//
this.FrontN.Location = new System.Drawing.Point(52, 294);
this.FrontN.Name = "FrontN";
this.FrontN.Size = new System.Drawing.Size(56, 23);
this.FrontN.TabIndex = 4;
this.FrontN.Text = "Front";
//
// FrontS
//
this.FrontS.Location = new System.Drawing.Point(52, 630);
this.FrontS.Name = "FrontS";
this.FrontS.Size = new System.Drawing.Size(56, 23);
this.FrontS.TabIndex = 5;
this.FrontS.Text = "Front";
//
// lblNormal
//
this.lblNormal.Location = new System.Drawing.Point(8, 210);
this.lblNormal.Name = "lblNormal";
this.lblNormal.Size = new System.Drawing.Size(100, 23);
this.lblNormal.TabIndex = 6;
this.lblNormal.Text = "Normal";
//
// lblShiny
//
this.lblShiny.Location = new System.Drawing.Point(8, 546);
this.lblShiny.Name = "lblShiny";
this.lblShiny.Size = new System.Drawing.Size(100, 23);
this.lblShiny.TabIndex = 7;
this.lblShiny.Text = "Shiny";
//
// IndexBox
//
this.IndexBox.DropDownWidth = 160;
this.IndexBox.Location = new System.Drawing.Point(172, 8);
this.IndexBox.MaxDropDownItems = 16;
this.IndexBox.Name = "IndexBox";
this.IndexBox.Size = new System.Drawing.Size(160, 21);
this.IndexBox.TabIndex = 6;
this.IndexBox.SelectedIndexChanged += new System.EventHandler(this.IndexBox_SelectedIndexChanged);
//
// BasePalette
//
this.BasePalette.DropDownWidth = 160;
this.BasePalette.Enabled = false;
this.BasePalette.Location = new System.Drawing.Point(138, 728);
this.BasePalette.MaxDropDownItems = 16;
this.BasePalette.Name = "BasePalette";
this.BasePalette.Size = new System.Drawing.Size(160, 21);
this.BasePalette.TabIndex = 6;
this.BasePalette.Visible = false;
this.BasePalette.SelectedIndexChanged += new System.EventHandler(this.BasePalette_SelectedIndexChanged);
//
// ShinyPalette
//
this.ShinyPalette.DropDownWidth = 160;
this.ShinyPalette.Enabled = false;
this.ShinyPalette.Location = new System.Drawing.Point(309, 729);
this.ShinyPalette.MaxDropDownItems = 16;
this.ShinyPalette.Name = "ShinyPalette";
this.ShinyPalette.Size = new System.Drawing.Size(160, 21);
this.ShinyPalette.TabIndex = 6;
this.ShinyPalette.Visible = false;
this.ShinyPalette.SelectedIndexChanged += new System.EventHandler(this.ShinyPalette_SelectedIndexChanged);
//
// SaveBox
//
this.SaveBox.DropDownWidth = 160;
this.SaveBox.Items.AddRange(new object[] {
"Normal Female Backsprite",
"Normal Male Backsprite",
"Normal Female Frontsprite",
"Normal Male Frontprite",
"Shiny Female Backsprite",
"Shiny Male Backsprite",
"Shiny Female Frontsprite",
"Shiny Male Frontprite"});
this.SaveBox.Location = new System.Drawing.Point(512, 728);
this.SaveBox.Name = "SaveBox";
this.SaveBox.Size = new System.Drawing.Size(160, 21);
this.SaveBox.TabIndex = 8;
//
// femaleBackNormalPic
//
this.femaleBackNormalPic.Location = new System.Drawing.Point(96, 64);
this.femaleBackNormalPic.Name = "femaleBackNormalPic";
this.femaleBackNormalPic.Size = new System.Drawing.Size(320, 160);
this.femaleBackNormalPic.TabIndex = 14;
this.femaleBackNormalPic.TabStop = false;
this.femaleBackNormalPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// maleBackNormalPic
//
this.maleBackNormalPic.Location = new System.Drawing.Point(422, 64);
this.maleBackNormalPic.Name = "maleBackNormalPic";
this.maleBackNormalPic.Size = new System.Drawing.Size(320, 160);
this.maleBackNormalPic.TabIndex = 15;
this.maleBackNormalPic.TabStop = false;
this.maleBackNormalPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// femaleFrontNormalPic
//
this.femaleFrontNormalPic.Location = new System.Drawing.Point(96, 230);
this.femaleFrontNormalPic.Name = "femaleFrontNormalPic";
this.femaleFrontNormalPic.Size = new System.Drawing.Size(320, 160);
this.femaleFrontNormalPic.TabIndex = 16;
this.femaleFrontNormalPic.TabStop = false;
this.femaleFrontNormalPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// maleFrontNormalPic
//
this.maleFrontNormalPic.Location = new System.Drawing.Point(422, 230);
this.maleFrontNormalPic.Name = "maleFrontNormalPic";
this.maleFrontNormalPic.Size = new System.Drawing.Size(320, 160);
this.maleFrontNormalPic.TabIndex = 17;
this.maleFrontNormalPic.TabStop = false;
this.maleFrontNormalPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// maleBackShinyPic
//
this.maleBackShinyPic.Location = new System.Drawing.Point(422, 396);
this.maleBackShinyPic.Name = "maleBackShinyPic";
this.maleBackShinyPic.Size = new System.Drawing.Size(320, 160);
this.maleBackShinyPic.TabIndex = 18;
this.maleBackShinyPic.TabStop = false;
this.maleBackShinyPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// femaleBackShinyPic
//
this.femaleBackShinyPic.Location = new System.Drawing.Point(96, 396);
this.femaleBackShinyPic.Name = "femaleBackShinyPic";
this.femaleBackShinyPic.Size = new System.Drawing.Size(320, 160);
this.femaleBackShinyPic.TabIndex = 19;
this.femaleBackShinyPic.TabStop = false;
this.femaleBackShinyPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// maleFrontShinyPic
//
this.maleFrontShinyPic.Location = new System.Drawing.Point(422, 562);
this.maleFrontShinyPic.Name = "maleFrontShinyPic";
this.maleFrontShinyPic.Size = new System.Drawing.Size(320, 160);
this.maleFrontShinyPic.TabIndex = 20;
this.maleFrontShinyPic.TabStop = false;
this.maleFrontShinyPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// femaleFrontShinyPic
//
this.femaleFrontShinyPic.Location = new System.Drawing.Point(96, 562);
this.femaleFrontShinyPic.Name = "femaleFrontShinyPic";
this.femaleFrontShinyPic.Size = new System.Drawing.Size(320, 160);
this.femaleFrontShinyPic.TabIndex = 21;
this.femaleFrontShinyPic.TabStop = false;
this.femaleFrontShinyPic.Click += new System.EventHandler(this.Picturebox_Click);
//
// PokemonSpriteEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(763, 761);
this.Controls.Add(this.femaleFrontShinyPic);
this.Controls.Add(this.maleFrontShinyPic);
this.Controls.Add(this.femaleBackShinyPic);
this.Controls.Add(this.maleBackShinyPic);
this.Controls.Add(this.maleFrontNormalPic);
this.Controls.Add(this.femaleFrontNormalPic);
this.Controls.Add(this.maleBackNormalPic);
this.Controls.Add(this.femaleBackNormalPic);
this.Controls.Add(this.lblFemale);
this.Controls.Add(this.lblMale);
this.Controls.Add(this.BackN);
this.Controls.Add(this.BackS);
this.Controls.Add(this.FrontN);
this.Controls.Add(this.FrontS);
this.Controls.Add(this.lblNormal);
this.Controls.Add(this.lblShiny);
this.Controls.Add(this.IndexBox);
this.Controls.Add(this.BasePalette);
this.Controls.Add(this.ShinyPalette);
this.Controls.Add(this.SaveBox);
this.Controls.Add(this.OpenPngs);
this.Controls.Add(this.LoadSheet);
this.Controls.Add(this.SaveSingle);
this.Controls.Add(this.MakeShiny);
this.Controls.Add(this.OpenOther);
this.Controls.Add(this.SaveChanges);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "PokemonSpriteEditor";
((System.ComponentModel.ISupportInitialize)(this.femaleBackNormalPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maleBackNormalPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.femaleFrontNormalPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maleFrontNormalPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maleBackShinyPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.femaleBackShinyPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maleFrontShinyPic)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.femaleFrontShinyPic)).EndInit();
this.ResumeLayout(false);
}
private PictureBox femaleBackNormalPic;
private PictureBox maleBackNormalPic;
private PictureBox femaleFrontNormalPic;
private PictureBox maleFrontNormalPic;
private PictureBox maleBackShinyPic;
private PictureBox femaleBackShinyPic;
private PictureBox maleFrontShinyPic;
private PictureBox femaleFrontShinyPic;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,437 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows;
namespace DSPRE.Editors.Utils
{
public class IndexedBitmapHandler
{
public IndexedBitmapHandler()
{
}
public Bitmap Convert(Bitmap source, PixelFormat target)
{
if ((source.PixelFormat == target) || (target == PixelFormat.DontCare))
return source;
Bitmap image = new Bitmap(source.Width, source.Height, target);
if ((source.PixelFormat == PixelFormat.Format4bppIndexed) && (target == PixelFormat.Format8bppIndexed))
{
byte[] array = GetArray(source);
byte[] array2 = new byte[(array.Length * 2)];
byte current;
for (int i = 0; i < array.Length; i++)
{
current = array[i];
array2[2 * i] = (byte)((current & 0xF0) >> 4);
array2[2 * i + 1] = (byte)((current & 0x0F));
}
image = MakeImage(source.Width, source.Height, array2, target);
image.Palette = source.Palette;
}
if (((source.PixelFormat == PixelFormat.Format24bppRgb) || (source.PixelFormat == PixelFormat.Format32bppArgb)) && (target == PixelFormat.Format8bppIndexed))
{
int skip = 3;
if (source.PixelFormat == PixelFormat.Format32bppArgb)
skip = 4;
Color[] newPalette = new Color[256];
byte[] array = new byte[source.Width * source.Height];
byte[] sourceArray = GetArray(source);
Color Pixel = Color.FromArgb(sourceArray[2], sourceArray[1], sourceArray[0]);
newPalette[0] = Pixel;
int index = 1;
array[0] = 0;
byte r = 0;
byte g = 0;
byte b = 0;
bool match = false;
for (int i = 1; i < (source.Width * source.Height); i++)
{
b = sourceArray[(i * skip)];
g = sourceArray[(i * skip + 1)];
r = sourceArray[(i * skip + 2)];
Pixel = Color.FromArgb(r, g, b);
for (int j = 0; j < index; j++)
{
if (Pixel == newPalette[j])
{
array[i] = (byte)j;
match = true;
break;
}
}
if (!match)
{
if (index >= 256)
{
MessageBox.Show("Conversion failed");
return null;
}
newPalette[index] = Pixel;
array[i] = (byte)index;
index++;
}
match = false;
}
image = MakeImage(source.Width, source.Height, array, target);
ColorPalette oldPalette = image.Palette;
for (int i = 0; i < index; i++)
{
oldPalette.Entries[i] = newPalette[i];
}
image.Palette = oldPalette;
}
return image;
}
public Bitmap Resize(Bitmap source, int top, int bottom, int left, int right)
{
int newWidth = source.Width + left + right;
int newHeight = source.Height + top + bottom;
int arraysize = newWidth * newHeight;
ColorPalette palette = source.Palette;
byte[] source_array = GetArray(source);
byte[] byte_array = new byte[arraysize];
byte background = source_array[0];
int source_index = 0;
int index = 0;
for (int j = 0; j < newHeight; j++)
{
for (int i = 0; i < newWidth; i++)
{
if (i < left || i >= (left + source.Width) || j < top || j >= (top + source.Height))
byte_array[index] = background;
else
{
source_index = ((j - top) * source.Width) + i - left;
byte_array[index] = source_array[source_index];
}
index++;
}
}
Bitmap newImage = MakeImage(newWidth, newHeight, byte_array, PixelFormat.Format8bppIndexed);
newImage.Palette = palette;
return newImage;
}
public Bitmap Concat(Bitmap first, Bitmap second)
{
int newWidth = first.Width + second.Width;
int newHeight = first.Height;
if (first.Height < second.Height)
newHeight = second.Height;
int arraysize = newWidth * newHeight;
ColorPalette palette = first.Palette;
byte[] first_array = GetArray(first);
byte[] second_array = GetArray(second);
byte[] byte_array = new byte[arraysize];
byte background = first_array[0];
int source_index = 0;
int index = 0;
for (int j = 0; j < newHeight; j++)
{
for (int i = 0; i < first.Width; i++)
{
if (j > first.Height)
byte_array[index] = background;
else
{
source_index = ((j * first.Width) + i);
byte_array[index] = first_array[source_index];
}
index++;
}
for (int i = 0; i < second.Width; i++)
{
if (j > second.Height)
byte_array[index] = background;
else
{
source_index = ((j * second.Width) + i);
byte_array[index] = second_array[source_index];
}
index++;
}
}
Bitmap newImage = MakeImage(newWidth, newHeight, byte_array, PixelFormat.Format8bppIndexed);
newImage.Palette = palette;
return newImage;
}
public Bitmap[] Split(Bitmap source, int tilewidth, int tileheight)
{
int maxTiles = (source.Width / tilewidth) * (source.Height / tileheight);
Bitmap[] tiles = new Bitmap[maxTiles];
int index = 0;
int x_index = 0;
int y_index = 0;
while (y_index + tileheight <= source.Height)
{
if (x_index + tilewidth <= source.Width)
{
tiles[index] = Resize(source, (y_index * -1), ((source.Height - y_index - tileheight) * -1), (x_index * -1), ((source.Width - x_index - tilewidth) * -1));
index++;
}
x_index += tilewidth;
if (x_index + tilewidth > source.Width)
{
y_index += tileheight;
x_index = 0;
}
}
return tiles;
}
public Bitmap ShrinkImage(Bitmap image, int x_scale, int y_scale)
{
byte[] array = GetArray(image);
ColorPalette palette = image.Palette;
int new_width = image.Width / x_scale;
int new_height = image.Height / y_scale;
byte[] array2 = new byte[new_width * new_height];
for (int j = 0; j < new_height; j++)
{
for (int i = 0; i < new_width; i++)
{
array2[j * new_width + i] = array[y_scale * j * image.Width + i * x_scale];
}
}
Bitmap temp = MakeImage(new_width, new_height, array2, image.PixelFormat);
temp.Palette = palette;
return temp;
}
public ColorPalette AlternatePalette(Bitmap parent, Bitmap child)
{
Bitmap temp = new Bitmap(1, 1, parent.PixelFormat);
ColorPalette newPalette = temp.Palette;
ColorPalette ChildPalette = child.Palette;
byte[] ParentArray = GetArray(parent);
byte[] ChildArray = GetArray(child);
if (ParentArray.Length != ChildArray.Length)
return null;
for (int i = 0; i < ChildPalette.Entries.Length; i++)
{
for (int j = 0; j < ParentArray.Length; j++)
{
if (ParentArray[j] == i)
{
newPalette.Entries[i] = ChildPalette.Entries[ChildArray[j]];
break;
}
}
}
return newPalette;
}
public Bitmap PaletteMatch(ColorPalette parent, Bitmap child, bool[] used = null)
{
if (parent.Entries == child.Palette.Entries)
return child;
if (used == null)
{
used = new bool[parent.Entries.Length];
for (int i = 0; i < parent.Entries.Length; i++)
used[i] = true;
}
Bitmap image = ShrinkPalette(child);
Bitmap temp = new Bitmap(1, 1, child.PixelFormat);
ColorPalette childPalette = image.Palette;
ColorPalette newPalette = temp.Palette;
int size = PaletteSize(image);
byte[] array = GetArray(image);
byte[] indexof = new byte[size];
bool[] NotFound = new bool[size];
for (int i = 0; i < size; i++)
NotFound[i] = true;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < parent.Entries.Length; j++)
{
if (parent.Entries[j] == childPalette.Entries[i])
{
indexof[i] = (byte)j;
NotFound[i] = false;
break;
}
}
}
int maxsize = 0;
for (int i = 0; i < parent.Entries.Length; i++)
{
if (used[i])
{
newPalette.Entries[i] = parent.Entries[i];
maxsize++;
}
}
for (int i = 0; i < size; i++)
{
if (NotFound[i])
maxsize++;
}
for (int i = 0; i < maxsize; i++)
{
if ((i < used.Length) && (used[i]))
continue;
for (int j = 0; j < size; j++)
{
if (NotFound[j])
{
indexof[j] = (byte)i;
newPalette.Entries[i] = childPalette.Entries[j];
NotFound[j] = false;
break;
}
}
}
byte[] newArray = new byte[array.Length];
for (int i = 0; i < array.Length; i++)
{
newArray[i] = indexof[array[i]];
}
image = MakeImage(child.Width, child.Height, newArray, child.PixelFormat);
image.Palette = newPalette;
return image;
}
public Bitmap ShrinkPalette(Bitmap image, bool[] used = null)
{
used = IsUsed(image, used);
byte[] array = GetArray(image);
ColorPalette oldPalette = image.Palette;
Bitmap temp = new Bitmap(image.Width, image.Height, image.PixelFormat);
ColorPalette newPalette = temp.Palette;
int size = oldPalette.Entries.Length;
int index = 0;
int unused = 0;
byte[] indexof = new byte[size];
for (int i = 0; i < size; i++)
{
if (used[i])
{
newPalette.Entries[index] = oldPalette.Entries[i];
indexof[i] = (byte)index;
index++;
}
else
unused++;
}
if (unused == 0 || unused == size)
return image;
byte[] newArray = new byte[array.Length];
for (int i = 0; i < array.Length; i++)
{
newArray[i] = indexof[array[i]];
}
image = MakeImage(image.Width, image.Height, newArray, image.PixelFormat);
image.Palette = newPalette;
return image;
}
public bool[] IsUsed(Bitmap image, bool[] used = null)
{
byte[] array = GetArray(image);
int size = image.Palette.Entries.Length;
if (used == null)
{
used = new bool[size];
for (int i = 0; i < size; i++)
{
used[i] = false;
}
}
if (size > used.Length)
{
bool[] temp = new bool[size];
for (int i = 0; i < size; i++)
{
if (i < used.Length)
temp[i] = used[i];
else
temp[i] = false;
}
used = temp;
}
for (int i = 0; i < array.Length; i++)
{
used[array[i]] = true;
}
return used;
}
public byte PaletteSize(Bitmap image)
{
byte[] array = GetArray(image);
byte max = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] > max)
max = array[i];
}
return (byte)(max + 1);
}
public bool PaletteEquals(ColorPalette parent, Bitmap child)
{
bool Match = true;
int max = PaletteSize(child);
for (int i = 0; i < max; i++)
{
if (parent.Entries[i] != child.Palette.Entries[i])
Match = false;
}
return Match;
}
public ColorPalette CleanPalette(Bitmap image)
{
int used = PaletteSize(image);
ColorPalette temp = image.Palette;
for (int i = used; i < image.Palette.Entries.Length; i++)
temp.Entries[i] = Color.FromArgb(0, 0, 0);
return temp;
}
public byte[] GetArray(Bitmap target)
{
int Width = target.Width;
if (target.PixelFormat == PixelFormat.Format1bppIndexed)
Width = Width / 8;
if (target.PixelFormat == PixelFormat.Format4bppIndexed)
Width = Width / 2;
if ((target.PixelFormat == PixelFormat.Format16bppArgb1555) || (target.PixelFormat == PixelFormat.Format16bppGrayScale) || (target.PixelFormat == PixelFormat.Format16bppRgb555) || (target.PixelFormat == PixelFormat.Format16bppRgb565))
Width = Width * 2;
if (target.PixelFormat == PixelFormat.Format24bppRgb)
Width = Width * 3;
if ((target.PixelFormat == PixelFormat.Format32bppRgb) || (target.PixelFormat == PixelFormat.Format32bppArgb) || (target.PixelFormat == PixelFormat.Format32bppPArgb))
Width = Width * 4;
byte[] array = new byte[Width * target.Height];
Rectangle rect = new Rectangle(0, 0, target.Width, target.Height);
BitmapData sourceData = target.LockBits(rect, ImageLockMode.ReadOnly, target.PixelFormat);
IntPtr scan = sourceData.Scan0;
Marshal.Copy(scan, array, 0, Width * target.Height);
target.UnlockBits(sourceData);
return array;
}
public Bitmap MakeImage(int width, int height, byte[] array, PixelFormat format)
{
Bitmap image = new Bitmap(width, height, format);
Rectangle rect = new Rectangle(0, 0, width, height);
BitmapData imageData = image.LockBits(rect, ImageLockMode.WriteOnly, image.PixelFormat);
IntPtr scan = imageData.Scan0;
Marshal.Copy(array, 0, scan, (width * height));
image.UnlockBits(imageData);
return image;
}
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSPRE.Editors.Utils
{
public class NarcReader
{
public int Entrys;
public FileEntry[] fe;
public FileStream fs;
string m_sFileName;
public long size;
public NarcReader(string strFileName)
{
m_sFileName = strFileName;
fs = new FileStream(strFileName, FileMode.Open, FileAccess.ReadWrite);
BinaryReader binaryReader = new BinaryReader(fs);
byte[] array = new byte[16];
binaryReader.Read(array, 0, 16);
size = BitConverter.ToUInt32(array, 8);
int num = BitConverter.ToInt16(array, 12);
fs.Seek(num, SeekOrigin.Begin);
array = new byte[12];
binaryReader.Read(array, 0, 12);
int num2 = BitConverter.ToInt32(array, 4);
Entrys = BitConverter.ToInt32(array, 8);
fe = new FileEntry[Entrys];
for (int i = 0; i < Entrys; i++)
{
fe[i].Ofs = binaryReader.ReadInt32();
fe[i].Size = binaryReader.ReadInt32() - fe[i].Ofs;
}
fs.Seek(num + num2, SeekOrigin.Begin);
array = new byte[16];
binaryReader.Read(array, 0, 16);
int num3 = BitConverter.ToInt32(array, 4);
num3 = num + num3 + num2 + 8;
for (int j = 0; j < Entrys; j++)
{
fe[j].Ofs += num3;
}
fs.Close();
}
public void Close()
{
fs.Close();
}
public int OpenEntry(int id)
{
fs = new FileStream(m_sFileName, FileMode.Open, FileAccess.ReadWrite);
fs.Seek(fe[id].Ofs, SeekOrigin.Begin);
return 0;
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DSPRE.Editors.Utils
{
public class SpriteSet
{
public Bitmap[] Sprites;
public ColorPalette Normal;
public ColorPalette Shiny;
public SpriteSet()
{
Sprites = new Bitmap[4];
for (int i = 0; i < 4; i++)
{
Sprites[i] = null;
}
Normal = null;
Shiny = null;
}
}
}