Page 1 of 1

Westwood PAL to photoshop ACT converter

Posted: Sat Jan 13, 2018 5:31 pm
by katzsmile
Westwood PAL palette to photoshop ACT palette converter.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace westwoodPALtoACT
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Westwood PAL to Photoshop ACT converter\n");
                Console.WriteLine("Usage: westwoodPALtoACT.exe westwood.pal\n");
                Console.WriteLine("westwoodPALtoACT.exe westwood.pal");
                return;
            }
            if (args != null && args.Length > 0)
            {
                if (File.Exists(args[0]))
                {
                    string ACTfile = Path.GetFileNameWithoutExtension(args[0])+ ".act";
                    Console.WriteLine("Output file: " + ACTfile);
                    using (MemoryStream palette = new MemoryStream(File.ReadAllBytes(args[0])))
                    {

                        using (BinaryReader reader = new BinaryReader(palette))
                        {
                            FileStream act = File.Create(ACTfile, 768, FileOptions.None);
                            using (BinaryWriter writer = new BinaryWriter(act))
                            {
                                for (int i = 0; i < 256; i++)
                                {
                                    byte r = (byte)(reader.ReadByte() << 2);
                                    byte g = (byte)(reader.ReadByte() << 2);
                                    byte b = (byte)(reader.ReadByte() << 2);
                                    byte[] color = new byte[3] {r,g,b};
                                    writer.Write(color);
                                }
                                writer.Close();
                            }
                            reader.Close();
                        }
                    }
                }
            }
        }
    }
}

Posted: Thu Jan 18, 2018 10:50 am
by Matt
Looks similar to the PaintShop and GIMP palette file formats. I tried to add support for them in: https://github.com/OpenRA/OpenRA/pull/13913