various fixes

main
cosmonaut 2021-11-29 21:24:39 -08:00
parent c96be2b26b
commit 1713c86afe
4 changed files with 27 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
bin/
obj/
output/

View File

@ -6,5 +6,10 @@ namespace Palettizer
public byte G { get; set; }
public byte B { get; set; }
public byte A { get; set; }
public override string ToString()
{
return $"{{R: {R.ToString()}, G: {G.ToString()}, B: {B.ToString()}, A: {A.ToString()}}}";
}
}
}

View File

@ -40,8 +40,9 @@ namespace Palettizer
}
else
{
System.Console.WriteLine("That color doesn't exist in the grayscale palette!! Bailing!!!");
}
System.Console.WriteLine($"Color {color.ToString()} doesn't exist in the grayscale palette!! Bailing!!!");
return;
}
}
AlternateColorRows.Add(byteArray);

View File

@ -43,7 +43,7 @@ namespace Palettizer
var gmProject = Importer.ImportProject(project);
var projectDir = project.Directory;
console.Out.Write("Parsing: " + gmProject.Name);
console.Out.Write("Parsing: " + gmProject.Name + "\n");
if (Directory.Exists("output"))
{
@ -54,10 +54,11 @@ namespace Palettizer
var palette = new Palette();
var writer = new StbImageWriteSharp.ImageWriter();
// Add all sprite colors to palette
// Add all sprite colors to palette
foreach (var resource in gmProject.Resources)
{
var path = Path.Combine(projectDir.FullName, resource.ID.Path);
var spriteDir = Path.GetDirectoryName(path);
var file = new FileInfo(path);
if (file.Name.StartsWith("pal_")) { continue; }
@ -71,12 +72,14 @@ namespace Palettizer
if (sprite.TextureGroupID.Name == textureGroup)
{
console.Out.Write(sprite.Name + "\n");
foreach (var spriteFrame in sprite.Frames)
{
ImageResult image;
byte[] grayscaleImage;
var spriteImageFilePath = Path.Combine(path, spriteFrame.CompositeImage.FrameID.Name + ".png");
var spriteImageFilePath = Path.Combine(spriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
// Add sprite to palette
using (var stream = File.OpenRead(spriteImageFilePath))
@ -85,14 +88,18 @@ namespace Palettizer
grayscaleImage = AddSpriteToPalette(palette, image, console);
}
// Now write the image to output directory as grayscale
using (var stream = File.OpenWrite(Path.Combine(outputDir.FullName, resource.ID.Path)))
var spriteWriteDir = Path.Combine(outputDir.FullName, Path.GetRelativePath(projectDir.FullName, spriteDir));
Directory.CreateDirectory(spriteWriteDir);
var spriteWritePath = Path.Combine(spriteWriteDir, spriteFrame.CompositeImage.FrameID.Name + ".png");
// Now write the image to output directory as grayscale
using (var stream = File.OpenWrite(spriteWritePath))
{
writer.WritePng(grayscaleImage, image.Width, image.Height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, stream);
}
}
}
}
}
}
var paletteSpriteJSONDir = Path.Combine(projectDir.FullName, "sprites", paletteSpriteName);
@ -115,10 +122,10 @@ namespace Palettizer
{
colorPalette[i] = new Color
{
R = paletteImage.Data[j + i * paletteImage.Width],
G = paletteImage.Data[j + i * paletteImage.Width + 1],
B = paletteImage.Data[j + i * paletteImage.Width + 2],
A = paletteImage.Data[j + i * paletteImage.Width + 3]
R = paletteImage.Data[j * 4 + i * paletteImage.Width * 4],
G = paletteImage.Data[(j * 4 + i * paletteImage.Width * 4) + 1],
B = paletteImage.Data[(j * 4 + i * paletteImage.Width * 4) + 2],
A = paletteImage.Data[(j * 4 + i * paletteImage.Width * 4) + 3]
};
}
@ -127,7 +134,7 @@ namespace Palettizer
}
// Write final palette sprite to PNG
var paletteOutputPath = Path.Combine(outputDir.FullName, textureGroup, "Palette.png");
var paletteOutputPath = Path.Combine(outputDir.FullName, textureGroup + "_Palette.png");
using (var stream = File.OpenWrite(paletteOutputPath))
{
writer.WritePng(palette.CreateIndexedPaletteBitmap(), palette.Width, palette.Height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, stream);