move CWE sprite data format from Multimedia plugin to Chaos Works plugin

This commit is contained in:
Michael Becker 2020-03-16 11:38:15 -04:00
parent 664a4a1fd4
commit 3b8e7fff47
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
7 changed files with 207 additions and 86 deletions

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="Chaos Works Engine sprite">
<FileNameFilters>
<FileNameFilter>*.sph</FileNameFilter>
</FileNameFilters>
<MagicByteSequences>
<MagicByteSequence>
<MagicByte Type="String">CWE sprite</MagicByte>
</MagicByteSequence>
</MagicByteSequences>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.Multimedia.Picture.PictureObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.DataFormats.Multimedia.Picture.ChaosWorks.CWESpriteDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<UniversalEditor Version="4.0">
<Associations>
<Association>
<Filters>
<Filter Title="Chaos Works Engine sprite (low-resolution)">
<FileNameFilters>
<FileNameFilter>*.spl</FileNameFilter>
</FileNameFilters>
</Filter>
<Filter Title="Chaos Works Engine sprite (high-resolution)">
<FileNameFilters>
<FileNameFilter>*.sph</FileNameFilter>
</FileNameFilters>
</Filter>
<Filter Title="Chaos Works Engine sprite (XCOLOR)">
<FileNameFilters>
<FileNameFilter>*.spx</FileNameFilter>
</FileNameFilters>
</Filter>
</Filters>
<ObjectModels>
<ObjectModel TypeName="UniversalEditor.ObjectModels.Multimedia.Picture.Collection.PictureCollectionObjectModel" />
</ObjectModels>
<DataFormats>
<DataFormat TypeName="UniversalEditor.Plugins.ChaosWorks.DataFormats.Multimedia.PictureCollection.CWESpriteDataFormat" />
</DataFormats>
</Association>
</Associations>
</UniversalEditor>

View File

@ -207,7 +207,6 @@
<Content Include="Extensions\GameDeveloper\Associations\Nintendo.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\Picture\AvalancheTBODY.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\Picture\BurikoGeneralInterpreter.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\Picture\ChaosWorksSprite.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\Picture\GIM.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\ReflexiveEntertainment\FRM16.uexml" />
<Content Include="Extensions\GameDeveloper\Associations\SynthesizedAudio\PSF.uexml" />
@ -670,6 +669,7 @@
<Content Include="Extensions\GameDeveloper\Associations\FileSystem\KenSilverman\GRP.uexml" />
<Content Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\FileSystem\ChaosWorksEngine.uexml" />
<Content Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\Multimedia\Palette\SPPDataFormat.uexml" />
<Content Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\Multimedia\PictureCollection\SPXDataFormat.uexml" />
</ItemGroup>
<ItemGroup>
<Content Include="Configuration\Application.upl" />
@ -711,6 +711,7 @@
<Folder Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\FileSystem\" />
<Folder Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\Multimedia\" />
<Folder Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\Multimedia\Palette\" />
<Folder Include="Extensions\GameDeveloper\Extensions\ChaosWorks\Associations\Multimedia\PictureCollection\" />
</ItemGroup>
<ItemGroup>
<Content Include="Extensions\SoftwareDeveloper\Templates\Project\Software Development\Arduino\Images\Blink.xcf" />

View File

@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MBS.Framework.Drawing;
using UniversalEditor.Accessors;
using UniversalEditor.ObjectModels.Multimedia.Palette;
using UniversalEditor.ObjectModels.Multimedia.Picture;
using UniversalEditor.ObjectModels.Multimedia.Picture.Collection;
namespace UniversalEditor.Plugins.ChaosWorks.DataFormats.Multimedia.PictureCollection
{
public class CWESpriteDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(PictureCollectionObjectModel), DataFormatCapabilities.All);
_dfr.ImportOptions.Add(new CustomOptionFile("ExternalPaletteFileName", "External _palette file name"));
}
return _dfr;
}
public string ExternalPaletteFileName { get; set; } = null;
public PaletteObjectModel EmbeddedPalette { get; set; } = null;
protected override void LoadInternal(ref ObjectModel objectModel)
{
PictureCollectionObjectModel coll = (objectModel as PictureCollectionObjectModel);
IO.Reader br = base.Accessor.Reader;
br.Accessor.Position = 0;
string CWE_sprite = br.ReadNullTerminatedString();
if (CWE_sprite != "CWE sprite") throw new InvalidDataFormatException();
uint always36 = br.ReadUInt32(); // always the same?
uint always12 = br.ReadUInt32(); // always the same?
uint key = br.ReadUInt32();
uint unknown1 = br.ReadUInt32();
uint unknown2 = br.ReadUInt32();
uint unknown3 = br.ReadUInt32();
uint unknown4 = br.ReadUInt32();
uint unknown5 = br.ReadUInt32();
uint length = br.ReadUInt32();
uint frameCount = br.ReadUInt32();
br.Accessor.SavePosition();
br.Seek(length + 51, IO.SeekOrigin.Begin);
// frame definition data?
uint m_frameWidth = 0;
for (uint i = 0; i < frameCount; i++)
{
uint a = br.ReadUInt32();
uint b = br.ReadUInt32();
ushort x = br.ReadUInt16();
ushort y = br.ReadUInt16();
ushort frameWidth = br.ReadUInt16();
ushort frameHeight = br.ReadUInt16();
PictureObjectModel pic = new PictureObjectModel();
pic.Width = frameWidth;
pic.Height = frameHeight;
coll.Pictures.Add(pic);
if (m_frameWidth == 0)
m_frameWidth = frameWidth;
Console.WriteLine("cwe-sprite: added picture for sprite frame {0}\t{1}\t({2}, {3})\t{4}x{5}", a, b, x, y, frameWidth, frameHeight);
}
PaletteObjectModel palette = new PaletteObjectModel();
if (ExternalPaletteFileName != null)
{
if (System.IO.File.Exists(ExternalPaletteFileName))
Document.Load(palette, new Palette.SPPDataFormat(), new FileAccessor(ExternalPaletteFileName));
}
// now we're at the embedded palette
if (!br.EndOfStream)// just in case this file doesn't include one; they all seem to have it though
{
EmbeddedPalette = new PaletteObjectModel();
while (!br.EndOfStream)
{
byte r = br.ReadByte();
byte g = br.ReadByte();
byte b = br.ReadByte();
byte a = br.ReadByte();
a = (byte)(255 - a);
Color color = Color.FromRGBAByte(r, g, b, a);
EmbeddedPalette.Entries.Add(color);
palette.Entries.Add(color);
}
}
br.Accessor.LoadPosition();
// now that we've loaded the frame definitions and embedded color palette,
// we can go back and read the pixel data
List<List<byte>> lists = new List<List<byte>>();
for (uint i = 0; i < frameCount; i++)
{
int x = 0, y = 0;
PictureObjectModel pic = coll.Pictures[(int)i];
while (!br.EndOfStream)
{
ushort blockLength = br.ReadUInt16();
if (blockLength == ushort.MaxValue)
break;
if (blockLength == 0)
continue;
long blockEnd = br.Accessor.Position + blockLength;
ushort chunkFrameCount = br.ReadUInt16();
for (ushort j = 0; j < chunkFrameCount; j++)
{
ushort skip_count = br.ReadUInt16();
ushort size_count = br.ReadUInt16();
y += skip_count;
if ((short)size_count < 0)
{
// if it is negative a single byte follows, and is repeated -size_count times
size_count = (ushort)(-(short)size_count);
byte index = br.ReadByte();
Color color = palette.Entries[index].Color;
for (int k = 0; k < size_count; k++)
{
Console.WriteLine("cwe-sprite: setting pixel ({0}, {1}) to color {2}", x, y, color);
pic.SetPixel(color, y, x);
y++;
}
}
else
{
for (int k = 0; k < size_count; k++)
{
byte index = br.ReadByte();
Color color = palette.Entries[index].Color;
Console.WriteLine("cwe-sprite: setting pixel ({0}, {1}) to color {2}", x, y, color);
pic.SetPixel(color, y, x);
y++;
}
}
}
if (br.Accessor.Position != blockEnd)
{
Console.WriteLine("cwe-sprite ERROR: finished reading a block, but not at block end! skipping to end of block anyway...");
}
br.Seek(blockEnd, IO.SeekOrigin.Begin);
x++;
y = 0;
}
}
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -42,6 +42,7 @@
<Compile Include="DataFormats\FileSystem\ChaosWorks\Internal\ChaosWorksVOLV2FileInfo.cs" />
<Compile Include="DataFormats\FileSystem\ChaosWorks\Internal\ChaosWorksVOLV2ChunkInfo.cs" />
<Compile Include="DataFormats\Multimedia\Palette\SPPDataFormat.cs" />
<Compile Include="DataFormats\Multimedia\PictureCollection\CWESpriteDataFormat.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Compression\UniversalEditor.Compression.csproj">
@ -69,6 +70,7 @@
<Folder Include="DataFormats\FileSystem\ChaosWorks\Internal\" />
<Folder Include="DataFormats\Multimedia\" />
<Folder Include="DataFormats\Multimedia\Palette\" />
<Folder Include="DataFormats\Multimedia\PictureCollection\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MBS.Framework.Drawing;
using UniversalEditor.ObjectModels.Multimedia.Picture;
namespace UniversalEditor.DataFormats.Multimedia.Picture.ChaosWorks
{
public class CWESpriteDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
protected override DataFormatReference MakeReferenceInternal()
{
if (_dfr == null)
{
_dfr = base.MakeReferenceInternal();
_dfr.Capabilities.Add(typeof(PictureObjectModel), DataFormatCapabilities.All);
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
PictureObjectModel pic = (objectModel as PictureObjectModel);
IO.Reader br = base.Accessor.Reader;
br.Accessor.Position = 0;
string CWE_sprite = br.ReadNullTerminatedString();
if (CWE_sprite != "CWE sprite") throw new InvalidDataFormatException();
uint unknown1 = br.ReadUInt32(); // always the same?
uint unknown2 = br.ReadUInt32(); // always the same?
// ushort unknown3 = br.ReadUInt16();
pic.Width = br.ReadByte();
pic.Height = br.ReadByte();
br.Accessor.Position = 512;
for (int x = 0; x < pic.Width; x++)
{
for (int y = 0; y < pic.Height; y++)
{
byte r = br.ReadByte();
byte g = br.ReadByte();
byte b = br.ReadByte();
pic.SetPixel(Color.FromRGBAByte(r, g, b), x, y);
}
}
}
protected override void SaveInternal(ObjectModel objectModel)
{
throw new NotImplementedException();
}
}
}

View File

@ -89,7 +89,6 @@
<Compile Include="DataFormats\Multimedia\Picture\Microsoft\Bitmap\BitmapBitsPerPixel.cs" />
<Compile Include="DataFormats\Multimedia\Picture\Microsoft\Bitmap\BitmapCompression.cs" />
<Compile Include="DataFormats\Multimedia\Picture\Microsoft\Bitmap\BitmapInfoHeader.cs" />
<Compile Include="DataFormats\Multimedia\Picture\ChaosWorks\CWESpriteDataFormat.cs" />
<Compile Include="DataFormats\Multimedia\Picture\CompressedBG\CompressedBGDataFormat.cs" />
<Compile Include="DataFormats\Multimedia\Picture\CompressedBG\Internal\NodeCBG.cs" />
<Compile Include="DataFormats\Multimedia\Picture\GIM\GIMDataFormat.cs" />