Beispiel #1
0
        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();
        }
Beispiel #2
0
        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();
        }