Exemplo n.º 1
0
        public override bool SaveFile(string path)
        {
            HousePaletteFile hpal = new HousePaletteFile();

            hpal.SetPalettes(_pals);
            hpal.WriteToFile(path);
            _dirty = false;
            _path  = path;
            return(true);
        }
Exemplo n.º 2
0
 public bool LoadHousePaletteFile(string path)
 {
     try
     {
         HousePaletteFile pal = new HousePaletteFile();
         pal.ReadFromFile(path);
         _housePaletteFile = pal;
         return(true);
     }
     catch
     {
         MessageBox.Show("The file is not a valid palette file.");
         return(false);
     }
 }
Exemplo n.º 3
0
 public override bool LoadFile(string path)
 {
     try
     {
         HousePaletteFile hpal = new HousePaletteFile();
         hpal.ReadFromFile(path);
         _pals  = hpal.GetPalettes();
         _dirty = false;
         _path  = path;
         return(true);
     }
     catch
     {
         MessageBox.Show("The file is not a valid resource file.");
         return(false);
     }
 }
Exemplo n.º 4
0
        public void Export(Palette_18Bit basePalette, int key, ResourceElement element, string rootDir, string imagePath, string palettePath, IProgress <int> progress = null)
        {
            if (element.PaletteType == PaletteType.EMPTY_ENTRY)
            {
                return;
            }

            ResourceExportEntry expentry = new ResourceExportEntry();

            expentry.FrameSize     = element.FrameSize;
            expentry.ImageOffset   = element.ImageOffset;
            expentry.Alignment     = element.Alignment;
            expentry.ImageHandle   = element.ImageHandle;
            expentry.PaletteHandle = element.PaletteHandle;
            expentry.UsePalette    = element.BitsPerPixel == 8;
            if (expentry.UsePalette)
            {
                expentry.UseOwnPalette = element.PaletteHandle != 0;
            }
            else
            {
                expentry.UseOwnPalette = null;
            }

            HousePaletteFile dummy = new HousePaletteFile();
            // modify palette to remove unique colors.
            Palette_15Bit opal = element.Palette?.Clone();

            if (element.Palette != null)
            {
                element.Palette.MakeSpecialIndicesUnique(out _);
            }

            Bitmap image = element.GetBitmap(basePalette, dummy, false, false, -1);

            if (!Path.IsPathRooted(imagePath))
            {
                imagePath = Path.Combine(rootDir, imagePath);
            }
            Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
            image.Save(imagePath);
            expentry.ImagePath = WinAPI.GetRelativePath(rootDir + @"\", imagePath);

            if (expentry.UseOwnPalette ?? false)
            {
                PaletteFile palfile = new PaletteFile();
                palfile.Palette.Import(element.Palette);
                if (!Path.IsPathRooted(palettePath))
                {
                    palettePath = Path.Combine(rootDir, palettePath);
                }
                Directory.CreateDirectory(Path.GetDirectoryName(palettePath));
                palfile.WriteToFile(palettePath);
                expentry.PalettePath = WinAPI.GetRelativePath(rootDir + @"\", palettePath);
            }

            // restore the original palette
            element.Palette = opal;

            Entries.Put(key.ToString(), expentry);
            progress?.Report(key);
        }
Exemplo n.º 5
0
        public Bitmap GetBitmap(Palette_18Bit basePalette, HousePaletteFile housePalette, bool includeFrame, bool makeTransparent, int houseIndex)
        {
            if (PaletteType == PaletteType.EMPTY_ENTRY)
            {
                // at least draw something so it does not error out.
                Bitmap empty = new Bitmap(1, 1);
                empty.MakeTransparent();
                return(empty);
            }

            Bitmap bmp = new Bitmap(ImageWidth, ImageHeight);

            if (BitsPerPixel == 8)
            {
                IPalette pal = (PaletteHandle == 0) ? (IPalette)basePalette.Clone() : Palette.Clone();
                if (houseIndex != -1)
                {
                    pal = housePalette.Merge(pal, houseIndex);
                }

                for (int x = 0; x < ImageWidth; x++)
                {
                    for (int y = 0; y < ImageHeight; y++)
                    {
                        int  pos   = x + y * ImageWidth;
                        byte data8 = ImageData[pos];

                        if (makeTransparent && data8 == 0)
                        {
                            bmp.SetPixel(x, y, Color.Transparent);
                        }
                        else if (makeTransparent && data8 == 1)
                        {
                            bmp.SetPixel(x, y, Color.FromArgb(128, 0, 0, 0));
                        }
                        else
                        {
                            bmp.SetPixel(x, y, pal.Get(data8));
                        }
                    }
                }
            }
            else if (BitsPerPixel == 16)
            {
                // doesn't care about palettes, as its image data is direct color
                for (int x = 0; x < ImageWidth; x++)
                {
                    for (int y = 0; y < ImageHeight; y++)
                    {
                        int    pos    = (x + y * ImageWidth) * 2;
                        ushort data16 = BitConverter.ToUInt16(ImageData, pos);
                        bmp.SetPixel(x, y, Palette_15Bit.ConvertColor(data16));
                    }
                }
            }
            else
            {
                throw new InvalidDataException("Unexpected bits per pixel! (Value = {0})".F(BitsPerPixel));
            }

            if (makeTransparent)
            {
                bmp.MakeTransparent(Palette.Get(0));
            }

            if (includeFrame)
            {
                Bitmap bmpFrame = new Bitmap(FrameWidth, FrameHeight);
                bmpFrame.MakeTransparent();
                Graphics g = Graphics.FromImage(bmpFrame);
                g.DrawImageUnscaled(bmp, new Point((FrameWidth - ImageWidth) / 2, (FrameHeight - ImageHeight) / 2));
                return(bmpFrame);
            }
            else
            {
                return(bmp);
            }
        }