public void InitPalette( WorldRenderer wr )
 {
     var info = Rules.Info["player"].Traits.WithInterface<PlayerColorPaletteInfo>()
         .First(p => p.BaseName == Info.PlayerPalette);
     format = info.PaletteFormat;
     wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
 }
Example #2
0
 /// <summary>
 /// Loads palette from a <paramref name="file"/>.
 /// </summary>
 /// <param name="file">Path to a file.</param>
 /// <param name="numcolors">Number of colors in a palette.</param>
 /// <param name="format">Palette format.</param>
 /// <returns>Loaded palette.</returns>
 public static ImagePalette Load(string file, int numcolors, PaletteFormat format)
 {
     using (FileStream stream = new FileStream(file, FileMode.Open))
     {
         return(Load(stream, numcolors, format));
     }
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Palette"/> class from the specified file.
 /// </summary>
 /// <param name="file">The file.</param>
 /// <param name="format">The expected format of the file.</param>
 /// <exception cref="FileNotFoundException">the file could not be found.</exception>
 /// <exception cref="InvalidDataException">the file is not formatted as expected.</exception>
 /// <exception cref="NotSupportedException"><paramref name="format"/> is not supported for loading.</exception>
 public Palette(FileInfo file, PaletteFormat format = PaletteFormat.Default)
 {
     using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         LoadInternal(stream, format);
     }
 }
        public void InitPalette(WorldRenderer wr)
        {
            var info = Rules.Info["player"].Traits.WithInterface <PlayerColorPaletteInfo>()
                       .First(p => p.BaseName == Info.PlayerPalette);

            format = info.PaletteFormat;
            wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
        }
 /// <summary>
 /// Note that this method runs _before_ changes are copied from the baseclass
 /// So if we want to update colors based on the new start point,
 /// Then UpdateColors can't rely on our internal start point
 /// </summary>
 protected override bool TryCopy(PagedElementViewModel other)
 {
     if (!(other is PaletteElementViewModel that))
     {
         return(false);
     }
     format = that.format;
     UpdateColors(other.Start, other.CurrentPage);
     return(true);
 }
Example #6
0
        public PlayerColorRemap(Color c1, Color c2, PaletteFormat fmt)
        {
            var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
            var ramp = (fmt == PaletteFormat.cnc)
                ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 }
                : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

            remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2)))
                .ToDictionary(u => u.First, u => u.Second);
        }
        public PlayerColorRemap(PaletteFormat fmt, ColorRamp c)
        {
            var c1 = c.GetColor(0);
            var c2 = c.GetColor(1); /* temptemp: this can be expressed better */

            var baseIndex = GetRemapBase(fmt);
            var ramp = GetRemapRamp(fmt);

            remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
                .ToDictionary(u => u.First, u => u.Second);
        }
Example #8
0
        public PlayerColorRemap(PaletteFormat fmt, ColorRamp c)
        {
            var c1 = c.GetColor(0);
            var c2 = c.GetColor(1);             /* temptemp: this can be expressed better */

            var baseIndex = GetRemapBase(fmt);
            var ramp      = GetRemapRamp(fmt);

            remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2)))
                          .ToDictionary(u => u.First, u => u.Second);
        }
Example #9
0
 public NesEngine(TvFormat tvFormat, PaletteFormat plFormat)
 {
     AutoSaveSram = true;
     Debug.WriteLine(this, "Initializeing the nes emulation engine...", DebugStatus.None);
     TvFormat = tvFormat;
     //Initialize Engine
     Memory           = new Memory.Memory(this);
     Cpu              = new Cpu(Memory, tvFormat, this);
     Cpu.PauseToggle += CpuPauseToggle;
     Ppu              = new Ppu(tvFormat, plFormat, this);
     Debug.WriteLine(this, "Nes initialized ok.", DebugStatus.Cool);
 }
Example #10
0
        public PlayerColorRemap(ColorRamp c, PaletteFormat fmt)
        {
            var c1 = c.GetColor(0);
            var c2 = c.GetColor(1); /* temptemp: this can be expressed better */

            var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
            var ramp = (fmt == PaletteFormat.cnc)
                ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 }
                : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

            remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2)))
                .ToDictionary(u => u.First, u => u.Second);
        }
Example #11
0
        public PlayerColorRemap(PaletteFormat fmt, ColorRamp c)
        {
            var c1 = c.GetColor(0);
            var c2 = c.GetColor(1);             /* temptemp: this can be expressed better */

            var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
            var ramp      = (fmt == PaletteFormat.cnc)
                                ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 }
                                : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

            remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2)))
                          .ToDictionary(u => u.First, u => u.Second);
        }
Example #12
0
        public static Color[] Load(string filename, PaletteFormat format)
        {
            switch (format)
            {
            case PaletteFormat.ACT:
                return(LoadAct(filename));

            case PaletteFormat.PAL:
                return(LoadPal(filename));

            default:
                throw new NotSupportedException($"Cannot load palettes in {format} format.");
            }
        }
Example #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Palette"/> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="format">The expected format of the stream.</param>
        public Palette(Stream stream, PaletteFormat format = PaletteFormat.Default)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream does not support reading.", nameof(stream));
            }

            LoadInternal(stream, format);
        }
Example #14
0
        public PaletteElementViewModel(ViewPort viewPort, ChangeHistory <ModelDelta> history, string runFormat, PaletteFormat format, int itemAddress) : base(viewPort, runFormat, itemAddress)
        {
            this.format = format;

            var table = (ITableRun)viewPort.Model.GetNextRun(itemAddress);

            Colors = new PaletteCollection(viewPort, viewPort.Model, history);
            Colors.RequestPageSet += HandleColorsPageSet;
            TableName              = viewPort.Model.GetAnchorFromAddress(-1, table.Start);
            var destination = Model.ReadPointer(Start);
            var run         = viewPort.Model.GetNextRun(destination) as IPaletteRun;

            Pages = run?.Pages ?? 0;
            UpdateColors(Start, 0);
        }
Example #15
0
        public static PaletteFormats FromGenericPaletteFormat(PaletteFormat Format)
        {
            switch (Format)
            {
            case PaletteFormat.None: return(PaletteFormats.IA8);

            case PaletteFormat.IA8: return(PaletteFormats.IA8);

            case PaletteFormat.RGB565: return(PaletteFormats.RGB565);

            case PaletteFormat.RGB5A3: return(PaletteFormats.RGB5A3);

            default:
                throw new Exception("Unknown Palette Format " + Format);
            }
        }
Example #16
0
        private void Load(Stream stream, PaletteFormat format)
        {
            switch (format)
            {
            case PaletteFormat.Default:
                LoadDefault(stream);
                break;

            case PaletteFormat.PAL:
                LoadPAL(stream);
                break;

            case PaletteFormat.ACT:
                LoadACT(stream);
                break;

            default:
                throw new NotSupportedException($"Palette format {format} is not supported for loading.");
            }
        }
Example #17
0
        public static void Save(Color[] colors, string filename, PaletteFormat format)
        {
            switch (format)
            {
            case PaletteFormat.PAL:
                SavePal(colors, filename);
                break;

            case PaletteFormat.ACT:
                SaveAct(colors, filename);
                break;

            case PaletteFormat.GPL:
                SaveGpl(colors, filename);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Example #18
0
        /// <summary>
        /// Desereialize color map from <paramref name="input"/> stream, consisting of specified number of
        /// <paramref name="colors"/> stored in specified <paramref name="format"/>.
        /// Default number of colors is 256 and format is 4-byte BGRX (where X is an unsignificant byte).
        /// </summary>
        public static Color[] ReadColorMap(Stream input, int colors = 0x100, PaletteFormat format = PaletteFormat.BgrX)
        {
            int bpp          = PaletteFormat.Rgb == format || PaletteFormat.Bgr == format ? 3 : 4;
            var palette_data = new byte[bpp * colors];

            if (palette_data.Length != input.Read(palette_data, 0, palette_data.Length))
            {
                throw new EndOfStreamException();
            }
            int src       = 0;
            var color_map = new Color[colors];
            Func <int, Color> get_color;

            if (PaletteFormat.Bgr == format || PaletteFormat.BgrX == format)
            {
                get_color = x => Color.FromRgb(palette_data[x + 2], palette_data[x + 1], palette_data[x]);
            }
            else if (PaletteFormat.BgrA == format)
            {
                get_color = x => Color.FromArgb(palette_data[x + 3], palette_data[x + 2], palette_data[x + 1], palette_data[x]);
            }
            else if (PaletteFormat.RgbA == format)
            {
                get_color = x => Color.FromArgb(palette_data[x + 3], palette_data[x], palette_data[x + 1], palette_data[x + 2]);
            }
            else
            {
                get_color = x => Color.FromRgb(palette_data[x], palette_data[x + 1], palette_data[x + 2]);
            }

            for (int i = 0; i < colors; ++i)
            {
                color_map[i] = get_color(src);
                src         += bpp;
            }
            return(color_map);
        }
Example #19
0
        /// <summary>
        /// Loads palette from stream.
        /// </summary>
        /// <param name="sourceStream">Stream containg color data.</param>
        /// <param name="numcolors">Number of colors in a palette.</param>
        /// <param name="format">Palette format.</param>
        /// <returns>Loaded palette.</returns>
        public static ImagePalette Load(Stream sourceStream, int numcolors, PaletteFormat format)
        {
            Color[] colors = new Color[numcolors];
            switch (format)
            {
            case PaletteFormat.Binary:
                BinaryReader binReader = new BinaryReader(sourceStream);
                for (int i = 0; i < numcolors; i++)
                {
                    colors[i] = Color.FromArgb(binReader.ReadByte(), binReader.ReadByte(), binReader.ReadByte());
                }
                break;

            case PaletteFormat.Text:
            case PaletteFormat.TextDOS:
                StreamReader strReader = new StreamReader(sourceStream);
                for (int i = 0; i < numcolors; i++)
                {
                    string   line  = strReader.ReadLine();
                    string[] split = line.Split(' ');
                    if (format == PaletteFormat.Text)
                    {
                        colors[i] = Color.FromArgb(Byte.Parse(split[0]), Byte.Parse(split[1]), Byte.Parse(split[2]));
                    }
                    else
                    {
                        colors[i] = Color.FromArgb(Convert.ToByte(Byte.Parse(split[0]) * Common.ColorConversion), Convert.ToByte(Byte.Parse(split[1]) * Common.ColorConversion), Convert.ToByte(Byte.Parse(split[2]) * Common.ColorConversion));
                    }
                }
                break;

            default:
                throw new NotImplementedException();
            }
            return(new ListPalette(colors));
        }
Example #20
0
        /// <summary>
        /// If the hint is a table name, only match palettes from that table.
        /// </summary>
        private IReadOnlyList <short> GetDesiredPalette(int start, string hint, int page, bool exitEarly, out PaletteFormat paletteFormat)
        {
            paletteFormat = default;
            hint          = format.PaletteHint ?? hint; // if there's a paletteHint, that takes precendence
            var destination = Model.ReadPointer(Start);

            if (Model.GetNextRun(destination) is ISpriteRun sRun)
            {
                var palette = sRun.FindRelatedPalettes(Model, Start, hint).FirstOrDefault();
                if (palette != null)
                {
                    paletteFormat = palette.PaletteFormat;
                    return(palette.AllColors(Model));
                }
            }
            return(TileViewModel.CreateDefaultPalette(0x10));
        }
 public virtual void SetPaletteData(byte[] data, PaletteFormat format)
 {
     paletteData   = data;
     PaletteFormat = format;
 }
Example #22
0
 internal PaletteData(PaletteFormat pFormat, PaletteOrder pOrder)
 {
     palFormat = pFormat;
     palOrder = pOrder;
 }
Example #23
0
 private static void UnpackPixelFromPalette(int paletteIndex, ref byte[] dest, int offset, byte[] paletteData, PaletteFormat format)
 {
     switch (format)
     {
         case PaletteFormat.IA8:
             dest[0] = paletteData[2 * paletteIndex + 1];
             dest[1] = paletteData[2 * paletteIndex + 0];
             break;
         case PaletteFormat.RGB565:
             RGB565ToRGBA8((ushort)FSHelpers.Read16(paletteData, 2 * paletteIndex), ref dest, offset);
             break;
         case PaletteFormat.RGB5A3:
             RGB5A3ToRGBA8((ushort)FSHelpers.Read16(paletteData, 2 * paletteIndex), ref dest, offset);
             break;
     }
 }
Example #24
0
        private static byte[] DecodeC4(byte[] fileData, uint dataOffset, uint width, uint height, Palette imagePalette, PaletteFormat paletteFormat)
        {
            //4 bpp, 8 block width/height, block size 32 bytes, possible palettes (IA8, RGB565, RGB5A3)
            uint numBlocksW = width / 8;
            uint numBlocksH = height / 8;

            byte[] decodedData = new byte[width * height * 8];

            //Read the indexes from the file
            for (int yBlock = 0; yBlock < numBlocksH; yBlock++)
            {
                for (int xBlock = 0; xBlock < numBlocksW; xBlock++)
                {
                    //Inner Loop for pixels
                    for (int pY = 0; pY < 8; pY++)
                    {
                        for (int pX = 0; pX < 8; pX += 2)
                        {
                            //Ensure we're not reading past the end of the image.
                            if ((xBlock * 8 + pX >= width) || (yBlock * 8 + pY >= height))
                            {
                                continue;
                            }

                            byte t  = (byte)(fileData[dataOffset] & 0xF0);
                            byte t2 = (byte)(fileData[dataOffset] & 0x0F);

                            decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 0] = (byte)(t >> 4);
                            decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 1] = t2;

                            dataOffset += 1;
                        }
                    }
                }
            }

            //Now look them up in the palette and turn them into actual colors.
            byte[] finalDest = new byte[decodedData.Length / 2];

            int pixelSize  = paletteFormat == PaletteFormat.IA8 ? 2 : 4;
            int destOffset = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    UnpackPixelFromPalette(decodedData[y * width + x], ref finalDest, destOffset, imagePalette.GetBytes(), paletteFormat);
                    destOffset += pixelSize;
                }
            }

            return(finalDest);
        }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Palette"/> class from the specified file.
 /// </summary>
 /// <param name="filename">The file name and path of the palette.</param>
 /// <param name="format">The expected format of the file.</param>
 /// <exception cref="FileNotFoundException">the file could not be found.</exception>
 /// <exception cref="InvalidDataException">the file is not formatted as expected.</exception>
 /// <exception cref="NotSupportedException"><paramref name="format"/> is not supported for loading.</exception>
 public Palette(string filename, PaletteFormat format = PaletteFormat.Default)
     : this(new FileInfo(filename), format)
 {
 }
Example #26
0
 static int[] GetRemapRamp(PaletteFormat fmt)
 {
     return((fmt == PaletteFormat.cnc) ? CncRemapRamp : NormalRemapRamp);
 }
Example #27
0
 public static BitmapPalette ReadPalette(ArcView file, long offset, int colors = 0x100, PaletteFormat format = PaletteFormat.BgrX)
 {
     using (var input = file.CreateStream(offset, (uint)(4 * colors)))  // largest possible size for palette
         return(ReadPalette(input, colors, format));
 }
        public static unsafe Bitmap ToBitmap(byte[] TexData, int TexOffset, byte[] PalData, int PalOffset, int Width, int Height, ImageFormat Format, PaletteFormat PalFormat, bool ExactSize = false)
        {
            Bitmap     bitm   = new Bitmap(Width, Height);
            BitmapData d      = bitm.LockBits(new Rectangle(0, 0, bitm.Width, bitm.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            uint *     res    = (uint *)d.Scan0;
            int        offs   = TexOffset;
            int        stride = d.Stride / 4;

            switch (Format)
            {
            case ImageFormat.I4:
            {
                for (int y = 0; y < Height; y += 8)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 2)
                            {
                                byte I1 = (byte)((TexData[offs] >> 4) * 0x11);
                                byte I2 = (byte)((TexData[offs] & 0xF) * 0x11);
                                res[(y + y2) * stride + x + x2]     = GFXUtil.ToColorFormat(I1, I1, I1, ColorFormat.ARGB8888);
                                res[(y + y2) * stride + x + x2 + 1] = GFXUtil.ToColorFormat(I2, I2, I2, ColorFormat.ARGB8888);
                                offs++;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.I8:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte I = TexData[offs];
                                res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(I, I, I, ColorFormat.ARGB8888);
                                offs++;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.IA4:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte I = (byte)((TexData[offs] & 0xF) * 0x11);
                                byte A = (byte)((TexData[offs] >> 4) * 0x11);
                                res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(A, I, I, I, ColorFormat.ARGB8888);
                                offs++;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.IA8:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                byte I = TexData[offs + 1];
                                byte A = TexData[offs];
                                res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(A, I, I, I, ColorFormat.ARGB8888);
                                offs += 2;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.RGB565:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                res[(y + y2) * stride + x + x2] =
                                    GFXUtil.ConvertColorFormat(
                                        IOUtil.ReadU16BE(TexData, offs),
                                        ColorFormat.RGB565,
                                        ColorFormat.ARGB8888);
                                //GFXUtil.RGB565ToArgb(IOUtil.ReadU16BE(TexData, offs));
                                offs += 2;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.RGB5A3:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 4)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 4; x2++)
                            {
                                ushort data = IOUtil.ReadU16BE(TexData, offs);
                                if ((data & 0x8000) != 0)
                                {
                                    res[(y + y2) * stride + x + x2] =
                                        GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                }
                                else
                                {
                                    res[(y + y2) * stride + x + x2] =
                                        GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                }
                                offs += 2;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.CI4:
            {
                for (int y = 0; y < Height; y += 8)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 2)
                            {
                                byte index1 = (byte)(TexData[offs] >> 4);
                                byte index2 = (byte)(TexData[offs] & 0xF);
                                switch (PalFormat)
                                {
                                case PaletteFormat.RGB5A3:
                                {
                                    ushort data = IOUtil.ReadU16BE(PalData, PalOffset + index1 * 2);
                                    if ((data & 0x8000) != 0)
                                    {
                                        res[(y + y2) * stride + x + x2] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                    }
                                    else
                                    {
                                        res[(y + y2) * stride + x + x2] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                    }
                                    data = IOUtil.ReadU16BE(PalData, PalOffset + index2 * 2);
                                    if ((data & 0x8000) != 0)
                                    {
                                        res[(y + y2) * stride + x + x2 + 1] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                    }
                                    else
                                    {
                                        res[(y + y2) * stride + x + x2 + 1] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                    }
                                    break;
                                }
                                }
                                offs++;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.CI8:
            {
                for (int y = 0; y < Height; y += 4)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 4; y2++)
                        {
                            for (int x2 = 0; x2 < 8; x2++)
                            {
                                byte index = TexData[offs];
                                switch (PalFormat)
                                {
                                case PaletteFormat.RGB5A3:
                                {
                                    ushort data = IOUtil.ReadU16BE(PalData, PalOffset + index * 2);
                                    if ((data & 0x8000) != 0)
                                    {
                                        res[(y + y2) * stride + x + x2] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                    }
                                    else
                                    {
                                        res[(y + y2) * stride + x + x2] =
                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                    }
                                    break;
                                }
                                }
                                offs++;
                            }
                        }
                    }
                }
                break;
            }

            case ImageFormat.CMP:
                for (int y = 0; y < Height; y += 8)
                {
                    for (int x = 0; x < Width; x += 8)
                    {
                        for (int y2 = 0; y2 < 8; y2 += 4)
                        {
                            for (int x2 = 0; x2 < 8; x2 += 4)
                            {
                                ushort color0  = IOUtil.ReadU16BE(TexData, offs);
                                ushort color1  = IOUtil.ReadU16BE(TexData, offs + 2);
                                uint   data    = IOUtil.ReadU32BE(TexData, offs + 4);
                                uint[] Palette = new uint[4];
                                Palette[0] = GFXUtil.ConvertColorFormat(color0, ColorFormat.RGB565, ColorFormat.ARGB8888);
                                Palette[1] = GFXUtil.ConvertColorFormat(color1, ColorFormat.RGB565, ColorFormat.ARGB8888);
                                Color a = Color.FromArgb((int)Palette[0]);
                                Color b = Color.FromArgb((int)Palette[1]);
                                if (color0 > color1)                                        //1/3 and 2/3
                                {
                                    Palette[2] = GFXUtil.ToColorFormat((a.R * 2 + b.R * 1) / 3, (a.G * 2 + b.G * 1) / 3, (a.B * 2 + b.B * 1) / 3, ColorFormat.ARGB8888);
                                    Palette[3] = GFXUtil.ToColorFormat((a.R * 1 + b.R * 2) / 3, (a.G * 1 + b.G * 2) / 3, (a.B * 1 + b.B * 2) / 3, ColorFormat.ARGB8888);
                                }
                                else                                        //1/2 and transparent
                                {
                                    Palette[2] = GFXUtil.ToColorFormat((a.R + b.R) / 2, (a.G + b.G) / 2, (a.B + b.B) / 2, ColorFormat.ARGB8888);
                                    Palette[3] = 0;
                                }

                                int q = 30;
                                for (int y3 = 0; y3 < 4; y3++)
                                {
                                    for (int x3 = 0; x3 < 4; x3++)
                                    {
                                        res[(y + y2 + y3) * stride + x + x2 + x3] = Palette[(data >> q) & 3];
                                        q -= 2;
                                    }
                                }
                                offs += 8;
                            }
                        }
                    }
                }
                break;
            }
            bitm.UnlockBits(d);
            return(bitm);
        }
Example #29
0
 static int GetRemapBase(PaletteFormat fmt)
 {
     return((fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80);
 }
 public static int GetRemapIndex(PaletteFormat fmt, int i)
 {
     return GetRemapBase(fmt) + GetRemapRamp(fmt)[i];
 }
Example #31
0
        public static unsafe Bitmap ToBitmap(byte[] TexData, int TexOffset, byte[] PalData, int PalOffset, int Width, int Height, ImageFormat Format, PaletteFormat PalFormat, bool ExactSize = false)
        {
            Bitmap bitm = new Bitmap(Width, Height);
            BitmapData d = bitm.LockBits(new Rectangle(0, 0, bitm.Width, bitm.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            uint* res = (uint*)d.Scan0;
            int offs = TexOffset;
            int stride = d.Stride / 4;
            switch (Format)
            {
                case ImageFormat.I4:
                    {
                        for (int y = 0; y < Height; y += 8)
                        {
                            for (int x = 0; x < Width; x += 8)
                            {
                                for (int y2 = 0; y2 < 8; y2++)
                                {
                                    for (int x2 = 0; x2 < 8; x2 += 2)
                                    {
                                        byte I1 = (byte)((TexData[offs] >> 4) * 0x11);
                                        byte I2 = (byte)((TexData[offs] & 0xF) * 0x11);
                                        res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(I1, I1, I1, ColorFormat.ARGB8888);
                                        res[(y + y2) * stride + x + x2 + 1] = GFXUtil.ToColorFormat(I2, I2, I2, ColorFormat.ARGB8888);
                                        offs++;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.I8:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 8)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 8; x2++)
                                    {
                                        byte I = TexData[offs];
                                        res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(I, I, I, ColorFormat.ARGB8888);
                                        offs++;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.IA4:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 8)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 8; x2++)
                                    {
                                        byte I = (byte)((TexData[offs] & 0xF) * 0x11);
                                        byte A = (byte)((TexData[offs] >> 4) * 0x11);
                                        res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(A, I, I, I, ColorFormat.ARGB8888);
                                        offs++;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.IA8:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 4)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 4; x2++)
                                    {
                                        byte I = TexData[offs + 1];
                                        byte A = TexData[offs];
                                        res[(y + y2) * stride + x + x2] = GFXUtil.ToColorFormat(A, I, I, I, ColorFormat.ARGB8888);
                                        offs += 2;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.RGB565:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 4)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 4; x2++)
                                    {
                                        res[(y + y2) * stride + x + x2] =
                                            GFXUtil.ConvertColorFormat(
                                                IOUtil.ReadU16BE(TexData, offs),
                                                ColorFormat.RGB565,
                                                ColorFormat.ARGB8888);
                                        //GFXUtil.RGB565ToArgb(IOUtil.ReadU16BE(TexData, offs));
                                        offs += 2;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.RGB5A3:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 4)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 4; x2++)
                                    {
                                        ushort data = IOUtil.ReadU16BE(TexData, offs);
                                        if ((data & 0x8000) != 0)
                                            res[(y + y2) * stride + x + x2] =
                                                GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                        else
                                            res[(y + y2) * stride + x + x2] =
                                                GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                        offs += 2;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.CI4:
                    {
                        for (int y = 0; y < Height; y += 8)
                        {
                            for (int x = 0; x < Width; x += 8)
                            {
                                for (int y2 = 0; y2 < 8; y2++)
                                {
                                    for (int x2 = 0; x2 < 8; x2 += 2)
                                    {
                                        byte index1 = (byte)(TexData[offs] >> 4);
                                        byte index2 = (byte)(TexData[offs] & 0xF);
                                        switch (PalFormat)
                                        {
                                            case PaletteFormat.RGB5A3:
                                                {
                                                    ushort data = IOUtil.ReadU16BE(PalData, PalOffset + index1 * 2);
                                                    if ((data & 0x8000) != 0)
                                                        res[(y + y2) * stride + x + x2] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                                    else
                                                        res[(y + y2) * stride + x + x2] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                                    data = IOUtil.ReadU16BE(PalData, PalOffset + index2 * 2);
                                                    if ((data & 0x8000) != 0)
                                                        res[(y + y2) * stride + x + x2 + 1] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                                    else
                                                        res[(y + y2) * stride + x + x2 + 1] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                                    break;
                                                }
                                        }
                                        offs++;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.CI8:
                    {
                        for (int y = 0; y < Height; y += 4)
                        {
                            for (int x = 0; x < Width; x += 8)
                            {
                                for (int y2 = 0; y2 < 4; y2++)
                                {
                                    for (int x2 = 0; x2 < 8; x2++)
                                    {
                                        byte index = TexData[offs];
                                        switch (PalFormat)
                                        {
                                            case PaletteFormat.RGB5A3:
                                                {
                                                    ushort data = IOUtil.ReadU16BE(PalData, PalOffset + index * 2);
                                                    if ((data & 0x8000) != 0)
                                                        res[(y + y2) * stride + x + x2] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.XRGB1555, ColorFormat.ARGB8888);
                                                    else
                                                        res[(y + y2) * stride + x + x2] =
                                                            GFXUtil.ConvertColorFormat(data, ColorFormat.ARGB3444, ColorFormat.ARGB8888);
                                                    break;
                                                }
                                        }
                                        offs++;
                                    }
                                }
                            }
                        }
                        break;
                    }
                case ImageFormat.CMP:
                    for (int y = 0; y < Height; y += 8)
                    {
                        for (int x = 0; x < Width; x += 8)
                        {
                            for (int y2 = 0; y2 < 8; y2 += 4)
                            {
                                for (int x2 = 0; x2 < 8; x2 += 4)
                                {
                                    ushort color0 = IOUtil.ReadU16BE(TexData, offs);
                                    ushort color1 = IOUtil.ReadU16BE(TexData, offs + 2);
                                    uint data = IOUtil.ReadU32BE(TexData, offs + 4);
                                    uint[] Palette = new uint[4];
                                    Palette[0] = GFXUtil.ConvertColorFormat(color0, ColorFormat.RGB565, ColorFormat.ARGB8888);
                                    Palette[1] = GFXUtil.ConvertColorFormat(color1, ColorFormat.RGB565, ColorFormat.ARGB8888);
                                    Color a = Color.FromArgb((int)Palette[0]);
                                    Color b = Color.FromArgb((int)Palette[1]);
                                    if (color0 > color1)//1/3 and 2/3
                                    {
                                        Palette[2] = GFXUtil.ToColorFormat((a.R * 2 + b.R * 1) / 3, (a.G * 2 + b.G * 1) / 3, (a.B * 2 + b.B * 1) / 3, ColorFormat.ARGB8888);
                                        Palette[3] = GFXUtil.ToColorFormat((a.R * 1 + b.R * 2) / 3, (a.G * 1 + b.G * 2) / 3, (a.B * 1 + b.B * 2) / 3, ColorFormat.ARGB8888);
                                    }
                                    else//1/2 and transparent
                                    {
                                        Palette[2] = GFXUtil.ToColorFormat((a.R + b.R) / 2, (a.G + b.G) / 2, (a.B + b.B) / 2, ColorFormat.ARGB8888);
                                        Palette[3] = 0;
                                    }

                                    int q = 30;
                                    for (int y3 = 0; y3 < 4; y3++)
                                    {
                                        for (int x3 = 0; x3 < 4; x3++)
                                        {
                                            res[(y + y2 + y3) * stride + x + x2 + x3] = Palette[(data >> q) & 3];
                                            q -= 2;
                                        }
                                    }
                                    offs += 8;
                                }
                            }
                        }
                    }
                    break;
            }
            bitm.UnlockBits(d);
            return bitm;
        }
Example #32
0
 public PaletteRunContentStrategy(PaletteFormat paletteFormat) => this.paletteFormat = paletteFormat;
Example #33
0
        private static void UnpackPixelFromPalette(int paletteIndex, ref byte[] dest, int offset, byte[] paletteData, PaletteFormat format)
        {
            switch (format)
            {
            case PaletteFormat.IA8:
                dest[0] = paletteData[2 * paletteIndex + 1];
                dest[1] = paletteData[2 * paletteIndex + 0];
                break;

            case PaletteFormat.RGB565:
                RGB565ToRGBA8((ushort)FSHelpers.Read16(paletteData, 2 * paletteIndex), ref dest, offset);
                break;

            case PaletteFormat.RGB5A3:
                RGB5A3ToRGBA8((ushort)FSHelpers.Read16(paletteData, 2 * paletteIndex), ref dest, offset);
                break;
            }
        }
Example #34
0
 public static int GetRemapIndex(PaletteFormat fmt, int i)
 {
     return(GetRemapBase(fmt) + GetRemapRamp(fmt)[i]);
 }
Example #35
0
 public static BitmapPalette ReadPalette(Stream input, int colors = 0x100, PaletteFormat format = PaletteFormat.BgrX)
 {
     return(new BitmapPalette(ReadColorMap(input, colors, format)));
 }
 static int[] GetRemapRamp(PaletteFormat fmt)
 {
     return (fmt == PaletteFormat.cnc) ? CncRemapRamp : NormalRemapRamp;
 }
 static int GetRemapBase(PaletteFormat fmt)
 {
     return (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80;
 }
Example #38
0
        private static byte[] DecodeData(byte[] data, uint width, uint height, uint dataOffset, TextureFormat format, Palette imagePalette, PaletteFormat paletteFormat)
        {
            switch (format)
            {
                case TextureFormat.RGBA32:
                    return DecodeRgba32(data, dataOffset, width, height);

                case TextureFormat.C4:
                    return DecodeC4(data, dataOffset, width, height, imagePalette, paletteFormat);

                case TextureFormat.RGB565:
                    return DecodeRgb565(data, dataOffset, width, height);

                case TextureFormat.CMPR:
                    return DecodeCmpr(data, dataOffset, width, height);

                case TextureFormat.IA8:
                    return DecodeIA8(data, dataOffset, width, height);

                case TextureFormat.I4:
                    return DecodeI4(data, dataOffset, width, height);

                case TextureFormat.RGB5A3:
                    return DecodeRgb5A3(data, dataOffset, width, height);

                default:
                    Console.WriteLine("Unknown BTI Format {0}, unable to decode!", format);
                    return new byte[0];
            }
        }
Example #39
0
        ///// <summary>
        ///// Initializes a new instance of the <see cref="Palette"/> class from an indexed <see cref="Image"/>.
        ///// </summary>
        ///// <param name="image">The source image.</param>
        ///// <exception cref="FormatException"><paramref name="image"/> is not indexed.</exception>
        //public Palette(Image image)
        //{
        //    // Initialize colors based on image bit depth
        //    switch (image.PixelFormat)
        //    {
        //        case PixelFormat.Format1bppIndexed:
        //            colors = new Color[1 << 1];
        //            break;

        //        case PixelFormat.Format4bppIndexed:
        //            colors = new Color[1 << 4];
        //            break;

        //        case PixelFormat.Format8bppIndexed:
        //            colors = new Color[1 << 8];
        //            break;

        //        default:
        //            throw new FormatException();
        //    }

        //    // Copy colors from image palette
        //    image.Palette.Entries.CopyTo(colors, 0);
        //}

        private void LoadInternal(Stream stream, PaletteFormat format)
        {
            switch (format)
            {
            case PaletteFormat.Default:
                using (var br = new BinaryReader(stream))
                {
                    var p = br.ReadByte();
                    var l = br.ReadByte();
                    var t = br.ReadByte();

                    if (p != 'P' ||
                        l != 'L' ||
                        t != 'T')
                    {
                        throw new InvalidDataException("This is not a palette file.");
                    }

                    var length = br.ReadInt32();

                    colors = new Bgr555[length];
                    for (int i = 0; i < length; i++)
                    {
                        colors[i] = new Bgr555(br.ReadUInt16());
                    }
                }
                break;

            case PaletteFormat.PAL:
                using (var sr = new StreamReader(stream))
                {
                    if (sr.ReadLine() != "JASC-PAL")
                    {
                        throw new InvalidDataException("This is not a PAL file.");
                    }
                    if (sr.ReadLine() != "0100")
                    {
                        throw new InvalidDataException("Unsupported PAL version.");
                    }

                    var length = 0;
                    if (!int.TryParse(sr.ReadLine(), out length))
                    {
                        throw new InvalidDataException("Invalid palette length.");
                    }

                    colors = new Bgr555[length];
                    for (int i = 0; i < length; i++)
                    {
                        try
                        {
                            var color = sr.ReadLine().Split(' ');

                            var r = byte.Parse(color[0]);
                            var g = byte.Parse(color[1]);
                            var b = byte.Parse(color[2]);

                            colors[i] = Bgr555.FromRgb(r, g, b);
                        }
                        catch (Exception ex)
                        {
                            throw new InvalidDataException($"Invalid color on line {i + 4}.", ex);
                        }
                    }
                }
                break;

            case PaletteFormat.ACT:
                using (var br = new BinaryReader(stream))
                {
                    // NOTE: An Adobe Color Table must always contain 256 colors.
                    // http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1070626
                    try
                    {
                        colors = new Bgr555[256];
                        for (int i = 0; i < 256; i++)
                        {
                            var r = br.ReadByte();
                            var g = br.ReadByte();
                            var b = br.ReadByte();

                            colors[i] = Bgr555.FromRgb(r, g, b);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException("Invalid color table.", ex);
                    }
                }
                break;

            default:
                throw new NotSupportedException($"Palette format {format} is not supported for loading.");
            }
        }
Example #40
0
        private static byte[] DecodeC4(byte[] fileData, uint dataOffset, uint width, uint height, Palette imagePalette, PaletteFormat paletteFormat)
        {
            //4 bpp, 8 block width/height, block size 32 bytes, possible palettes (IA8, RGB565, RGB5A3)
            uint numBlocksW = width / 8;
            uint numBlocksH = height / 8;

            byte[] decodedData = new byte[width * height * 8];

            //Read the indexes from the file
            for (int yBlock = 0; yBlock < numBlocksH; yBlock++)
            {
                for (int xBlock = 0; xBlock < numBlocksW; xBlock++)
                {
                    //Inner Loop for pixels
                    for (int pY = 0; pY < 8; pY++)
                    {
                        for (int pX = 0; pX < 8; pX += 2)
                        {
                            //Ensure we're not reading past the end of the image.
                            if ((xBlock * 8 + pX >= width) || (yBlock * 8 + pY >= height))
                                continue;

                            byte t = (byte)(fileData[dataOffset] & 0xF0);
                            byte t2 = (byte)(fileData[dataOffset] & 0x0F);

                            decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 0] = (byte)(t >> 4);
                            decodedData[width * ((yBlock * 8) + pY) + (xBlock * 8) + pX + 1] = t2;

                            dataOffset += 1;
                        }
                    }
                }
            }

            //Now look them up in the palette and turn them into actual colors.
            byte[] finalDest = new byte[decodedData.Length / 2];

            int pixelSize = paletteFormat == PaletteFormat.IA8 ? 2 : 4;
            int destOffset = 0;
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    UnpackPixelFromPalette(decodedData[y * width + x], ref finalDest, destOffset, imagePalette.GetBytes(), paletteFormat);
                    destOffset += pixelSize;
                }
            }

            return finalDest;
        }
Example #41
0
 private void dune2000ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     palf = PaletteFormat.d2k;
     if (bLoaded)
     {
         if (!bPNG)
             ApplyNewPalette(lastpal);
         else
             ApplyNewPalettePNG(lastpal);
     }
     Prefs.ShpViewer.PaletteFormat = palf;
 }
Example #42
0
 public void SetupTv(TvFormat tvFormat, PaletteFormat palleteFormat)
 {
     Pause();
     Cpu.SetTvFormat(tvFormat);
     Ppu.SetTvFormat(tvFormat, palleteFormat);
 }
Example #43
0
 internal PaletteData(PaletteFormat pFormat, PaletteOrder pOrder)
 {
     palFormat = pFormat;
     palOrder  = pOrder;
 }
Example #44
0
        public frmMain(string args)
        {
            InitializeComponent();
            initpath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            initpath = Path.Combine(initpath, "assets");

            DirectoryInfo directory = new DirectoryInfo(initpath);
            DirectoryInfo[] directories = directory.GetDirectories();
            int k = 0;
            foreach (DirectoryInfo subDirectory in directories)
            {
                k = k+1;
                subdir = subDirectory.Name;
                ToolStripMenuItem tsmMain = new ToolStripMenuItem(subdir);
                paletteToolStripMenuItem.DropDownItems.Add(subdir);

                foreach (ToolStripMenuItem c in paletteToolStripMenuItem.DropDownItems) //assuming this is a Form
                {
                    if (c.Text == subdir)
                    {
                        string[] palettes = Directory.GetFiles(Path.Combine(initpath, subdir), "*.pal");
                            foreach (string palette in palettes)
                            {

                                ToolStripMenuItem tsmPal = new ToolStripMenuItem(Path.GetFileName(palette));
                                tsmPal.Tag = palette;
                                tsmPal.Click += (_, d) =>
                                {
                                    if (bLoaded)
                                    {
                                        if (!bPNG)
                                            ApplyNewPalette(Convert.ToString(tsmPal.Tag));
                                        else
                                            ApplyNewPalettePNG(Convert.ToString(tsmPal.Tag));
                                    }
                                    Prefs.ShpViewer.LastPalette = Convert.ToString(tsmPal.Tag);
                                };
                                c.DropDownItems.Add(tsmPal);
                            }
                                //tsmMain.DropDownItems.Add(tsmPal);
                     }
                }
            }

            string strFilter = "*.jpg;*.png;*.gif;*.bmp";
            string[] m_arExt = strFilter.Split(';');
            foreach (string filter in m_arExt)
            {
                backgrounds = Directory.GetFiles(initpath, filter);
                foreach (string background in backgrounds)
                {

                    ToolStripMenuItem tsmBack = new ToolStripMenuItem(Path.GetFileName(background));
                    tsmBack.Tag = background;
                    tsmBack.Click += (_, d) =>
                    {
                        pbFrame.BackgroundImage = Image.FromFile(Convert.ToString(tsmBack.Tag));
                        Prefs.ShpViewer.BackgroundFile = Convert.ToString(tsmBack.Tag);

                    };
                    backgroundToolStripMenuItem.DropDownItems.Add(tsmBack);
                }
            }

            //Reading settings
            Prefs = new Preferences(Path.Combine(initpath, "prefs.yaml"));

            lastpal += Prefs.ShpViewer.LastPalette;

            if (lastpal == "") { lastpal = Path.Combine(initpath,"unittem.pal"); }
            //lastpal = Path.Combine(initpath, lastpal);

            if (Prefs.ShpViewer.BackgroundFile == "null")
            {
                pbFrame.BackgroundImage = null;
            }
            else
            {
                pbFrame.BackgroundImage = Image.FromFile(Prefs.ShpViewer.BackgroundFile);
            }

            pbFrame.BackgroundImageLayout = Prefs.ShpViewer.BackgroundLayout;
            transparentColorsToolStripMenuItem.Checked = Prefs.ShpViewer.TransparentColors;
            mnuRemap.Checked = Prefs.ShpViewer.RemapableColors;
            shadowToolStripMenuItem.Checked = Prefs.ShpViewer.UseShadow;
            turretToolStripMenuItem.Checked = Prefs.ShpViewer.UseTurret;
            pbColor.BackColor = Prefs.ShpViewer.RemapColor;
            cbLoop.Checked = Prefs.ShpViewer.ContinousPlaying;
            numTurretOffsetX.Value = Prefs.ShpViewer.TurretOffsetX;
            numTurretOffsetY.Value = Prefs.ShpViewer.TurretOffsetY;
            palf = Prefs.ShpViewer.PaletteFormat;
            remapmain = pbColor.BackColor;
            //Finish Reading Settings;

            Text = "SHP viewer " + sver;
            if (args.Length != 0)
            {
                OpenSHP(args);
            }
        }