private void RedrawImage() { if (_bitmap == null) { return; } pbPreview.Preview?.Dispose(); pbPreview.BoundingBox = new Rectangle(0, 0, _bitmap.Width, _bitmap.Height); pbPreview.Offset = new Primrose.Primitives.ValueTypes.int2(); pbPreview.Preview = ResourceElement.GetBitmap(BasePalette, HousePaletteFile, false, cbTransparency.Checked, cboxHousePal.Checked ? cbHouse.SelectedIndex : -1); if (cb8Bit.Checked) { switch (_choice) { case PaletteChoice.BASE: pbPalette.Palette = BasePalette; break; case PaletteChoice.USER: pbPalette.Palette = UserPalette; break; case PaletteChoice.EXISTING: pbPalette.Palette = PrevPalette; break; } } else { pbPalette.Palette = default; } }
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); }