private void SetTransFromImage(Color color) { int pal_index = sprite.Banks[comboBank.SelectedIndex].oams[0].obj2.index_palette; // How can I know that? yeah, I'm too lazy to do a new windows ;) Color[] pal = palette.Palette[pal_index]; byte[] tiles = image.Tiles; int index = -1; for (int i = 0; i < pal.Length; i++) { if (pal[i] == color) { index = i; break; } } Actions.Swap_Color(ref tiles, ref pal, index, 0, image.FormatColor); Color[][] new_pal = palette.Palette; new_pal[pal_index] = pal; if (image.ID > 0) { image.Set_Tiles(tiles); } if (palette.ID > 0) { palette.Set_Palette(new_pal); } Save_Files(); }
private void btnSetTrans_Click(object sender, EventArgs e) { int pal_index = (int)numPal.Value; Color[] pal = palette.Palette[pal_index]; byte[] tiles = image.Tiles; int index = -1; if ((palette.Depth == ColorFormat.colors256 && palette.NumberOfColors == 256) || (palette.Depth == ColorFormat.colors16 && palette.NumberOfColors == 16)) { index = Actions.Remove_DuplicatedColors(ref pal, ref tiles); if (index == -1) { index = Actions.Remove_NotUsedColors(ref pal, ref tiles); } } else { index = palette.NumberOfColors; // First empty place Color[] newPal = new Color[pal.Length + 1]; Array.Copy(pal, newPal, pal.Length); pal = newPal; } if (index == -1) { MessageBox.Show("No space in the palette found"); return; } pal[index] = Color.FromArgb(248, 0, 248); // Usually used as transparent color Actions.Swap_Color(ref tiles, ref pal, index, 0, image.FormatColor); Color[][] new_pal = palette.Palette; new_pal[pal_index] = pal; if (image.ID > 0) { image.Set_Tiles(tiles); } if (palette.ID > 0) { palette.Set_Palette(new_pal); } Save_Files(); }
private void btnImport_Click(object sender, EventArgs e) { OpenFileDialog o = new OpenFileDialog(); o.CheckFileExists = true; o.Filter = "All supported formats|*.pal;*.aco;*.png;*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.gif;*.ico;*.icon|" + "Windows Palette (*.pal)|*.pal|" + "Adobe COlor (*.aco)|*.aco|" + "Palette from image|*.png;*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.gif;*.ico;*.icon"; if (o.ShowDialog() != DialogResult.OK) { return; } string ext = Path.GetExtension(o.FileName).ToLower(); if (string.IsNullOrEmpty(ext) || ext.Length == 0) { MessageBox.Show("File without extension... Aborting"); return; } if (ext.Contains(".")) { ext = ext.Substring(ext.LastIndexOf(".") + 1); } Console.WriteLine("File extension:" + ext); PaletteBase newpal; if (ext == "pal") { newpal = new Formats.PaletteWin(o.FileName); } else if (ext == "aco") { newpal = new Formats.ACO(o.FileName); } else { byte[] tiles; Color[] newcol; Actions.Indexed_Image((Bitmap)Image.FromFile(o.FileName), palette.Depth, out tiles, out newcol); newpal = new RawPalette(newcol, palette.CanEdit, palette.Depth); } if (newpal != null) { palette.Set_Palette(newpal); } // Write the file Write_File(); o.Dispose(); o = null; }
private void btnImport_Click(object sender, EventArgs e) { SaveFileDialog o = new SaveFileDialog(); o.CheckFileExists = true; o.Filter = "All supported formats|*.pal;*.aco;*.png;*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.gif;*.ico;*.icon|" + "Windows Palette (*.pal)|*.pal|" + "Adobe COlor (*.aco)|*.aco|" + "Palette from image|*.png;*.bmp;*.jpg;*.jpeg;*.tif;*.tiff;*.gif;*.ico;*.icon"; if (o.ShowDialog() != DialogResult.OK) { return; } string ext = Path.GetExtension(o.FileName).ToLower(); PaletteBase newpal; if (ext == "pal") { newpal = new Formats.PaletteWin(o.FileName); } else if (ext == "aco") { newpal = new Formats.ACO(o.FileName); } else { byte[] tiles; Color[] newcol; Actions.Indexed_Image((Bitmap)Image.FromFile(o.FileName), palette.Depth, out tiles, out newcol); newpal = new RawPalette(newcol, palette.CanEdit, palette.Depth); } if (newpal != null) { palette.Set_Palette(newpal); } // Write the file Write_File(); o.Dispose(); o = null; }