Beispiel #1
0
        void SwapChannels(int a, int b, int c)
        {
            var selections = PaletteImage.GetSelectedIndices();

            foreach (var selectedIndex in selections)
            {
                var paletteEntry = PaletteImage.Palette[selectedIndex];
                PaletteImage.Palette[selectedIndex] = new byte[] { paletteEntry[a], paletteEntry[b], paletteEntry[c], byte.MaxValue };
            }
            PaletteImage.Update(selections);
        }
Beispiel #2
0
        private void PaletteImageMouseMove(object sender, MouseEventArgs e)
        {
            if (!(sender as Control).ClientRectangle.Contains(e.Location))
            {
                return;
            }
            PaletteImage paletteImage  = sender as PaletteImage;
            int          selectedColor = paletteImage.getSelectedColor(e);

            if (e.Button != MouseButtons.None && paletteImage.NumberOfSelectedColors > 0)
            {
                paletteImage.Moved(sender, e);
                ButtonNearestColors.Enabled = (paletteImage == RemappingPalette && paletteImage.NumberOfSelectedColors > 0);
            }
            else
            {
                PaletteImage otherPaletteImage          = GetOtherPalette(paletteImage);
                int[]        otherPaletteSelectedColors = otherPaletteImage.GetSelectedIndices();
                if (otherPaletteSelectedColors.Length > 0)
                {
                    SetMatchingSelectedColorsBasedOnOtherPaletteImage(paletteImage, selectedColor, ref otherPaletteSelectedColors);
                    paletteImage.Update(PaletteImage.AllPaletteColors);
                    paletteImage.SetSelected(otherPaletteSelectedColors, true); //visual change only, to be undone below
                    foreach (var selected in otherPaletteSelectedColors)
                    {
                        paletteImage.ColorsSelected[selected] = false;
                    }
                }
            }

            Text = "Remap Image Palette \u2013 " + selectedColor;
        }
Beispiel #3
0
        private void ButtonNearestColor_Click(object sender, EventArgs e)
        {
            int[] selectedColors = RemappingPalette.GetSelectedIndices();
            for (int i = 0; i < selectedColors.Length; ++i)
            {
                int colorIndex    = selectedColors[i];
                var remappedColor = LevelPalette.Palette[ColorRemappings[colorIndex] = LevelPalette.Palette.FindNearestColor(OriginalPalette[colorIndex])];
                RemappingPalette.Palette[colorIndex]    = remappedColor;
                ImageWorkingPalette.Entries[colorIndex] = Palette.Convert(remappedColor);
            }
            pictureBox1.Image.Palette = ImageWorkingPalette;
            pictureBox1.Refresh();

            RemappingPalette.SetSelected(selectedColors, false);
            ButtonNearestColors.Enabled = false;
        }
Beispiel #4
0
        private void PaletteImageMouseDown(object sender, MouseEventArgs e)
        {
            PaletteImage paletteImage      = sender as PaletteImage;
            PaletteImage otherPaletteImage = GetOtherPalette(paletteImage);

            if (otherPaletteImage.NumberOfSelectedColors == 0)
            {
                paletteImage.Clicked(sender, e);
                ButtonNearestColors.Enabled = (paletteImage == RemappingPalette && paletteImage.NumberOfSelectedColors > 0);
            }
            else
            {
                int[] otherPaletteSelectedColors = otherPaletteImage.GetSelectedIndices();
                int[] thisPaletteSelectedColors  = otherPaletteSelectedColors.Clone() as int[];
                SetMatchingSelectedColorsBasedOnOtherPaletteImage(paletteImage, paletteImage.getSelectedColor(e), ref thisPaletteSelectedColors);

                if (paletteImage == RemappingPalette)
                {
                    for (int i = 0; i < thisPaletteSelectedColors.Length; ++i)
                    {
                        ColorRemappings[thisPaletteSelectedColors[i]] = (byte)otherPaletteSelectedColors[i];
                    }
                }
                else
                {
                    for (int i = 0; i < thisPaletteSelectedColors.Length; ++i)
                    {
                        ColorRemappings[otherPaletteSelectedColors[i]] = (byte)thisPaletteSelectedColors[i];
                    }
                }

                for (int i = 0; i < Palette.PaletteSize; ++i)
                {
                    var remappedColor = LevelPalette.Palette[ColorRemappings[i]];
                    RemappingPalette.Palette[i]    = remappedColor;
                    ImageWorkingPalette.Entries[i] = Palette.Convert(remappedColor);
                }
                pictureBox1.Image.Palette = ImageWorkingPalette;
                pictureBox1.Refresh();

                LevelPalette.SetSelected(PaletteImage.AllPaletteColors, false);
                RemappingPalette.SetSelected(PaletteImage.AllPaletteColors, false);

                paletteImage.CurrentlySelectingColors = false;
                ButtonNearestColors.Enabled           = false;
            }
        }